Replace Lisp calls to delete-backward-char by delete-char.
[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
5eabfe72
KH
4696 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4697 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
3dcb36b7
JB
4698 (unless vhdl-emacs-21
4699 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4700 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4701 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4702; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4703 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4704; (turn-on-font-lock)
d2ddb974
KH
4705
4706 ;; variables for source file compilation
3dcb36b7
JB
4707 (when vhdl-compile-use-local-error-regexp
4708 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4709 (set (make-local-variable 'compilation-file-regexp-alist) nil))
5eabfe72
KH
4710
4711 ;; add index menu
4712 (vhdl-index-menu-init)
4713 ;; add source file menu
d2ddb974 4714 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
5eabfe72
KH
4715 ;; add VHDL menu
4716 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4717 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4718 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4719 ;; initialize hideshow and add menu
5eabfe72 4720 (vhdl-hideshow-init)
d2ddb974
KH
4721 (run-hooks 'menu-bar-update-hook)
4722
5eabfe72
KH
4723 ;; miscellaneous
4724 (vhdl-ps-print-init)
3dcb36b7 4725 (vhdl-write-file-hooks-init)
3dcb36b7
JB
4726 (message "VHDL Mode %s.%s" vhdl-version
4727 (if noninteractive "" " See menu for documentation and release notes."))
5eabfe72
KH
4728
4729 ;; run hooks
0a2e512a
RF
4730 (if vhdl-emacs-22
4731 (run-mode-hooks 'vhdl-mode-hook)
4732 (run-hooks 'vhdl-mode-hook)))
5eabfe72
KH
4733
4734(defun vhdl-activate-customizations ()
4735 "Activate all customizations on local variables."
4736 (interactive)
4737 (vhdl-mode-map-init)
4738 (use-local-map vhdl-mode-map)
4739 (set-syntax-table vhdl-mode-syntax-table)
4740 (setq comment-column vhdl-inline-comment-column)
4741 (setq end-comment-column vhdl-end-comment-column)
3dcb36b7 4742 (vhdl-write-file-hooks-init)
5eabfe72
KH
4743 (vhdl-update-mode-menu)
4744 (vhdl-hideshow-init)
56eb0904 4745 (run-hooks 'menu-bar-update-hook))
5eabfe72 4746
3dcb36b7
JB
4747(defun vhdl-write-file-hooks-init ()
4748 "Add/remove hooks when buffer is saved."
5eabfe72
KH
4749 (if vhdl-modify-date-on-saving
4750 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
3dcb36b7
JB
4751 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4752 (make-local-variable 'after-save-hook)
4753 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4754
4755(defun vhdl-process-command-line-option (option)
4756 "Process command line options for VHDL Mode."
4757 (cond
4758 ;; set compiler
4759 ((equal option "-compiler")
4760 (vhdl-set-compiler (car command-line-args-left))
4761 (setq command-line-args-left (cdr command-line-args-left)))
4762 ;; set project
4763 ((equal option "-project")
4764 (vhdl-set-project (car command-line-args-left))
4765 (setq command-line-args-left (cdr command-line-args-left)))))
4766
4767;; make Emacs process VHDL Mode options
4768(setq command-switch-alist
4769 (append command-switch-alist
4770 '(("-compiler" . vhdl-process-command-line-option)
4771 ("-project" . vhdl-process-command-line-option))))
5eabfe72
KH
4772
4773
4774;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4775;;; Keywords and standardized words
5eabfe72
KH
4776;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4777
3dcb36b7
JB
4778(defconst vhdl-93-keywords
4779 '(
4780 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4781 "assert" "attribute"
4782 "begin" "block" "body" "buffer" "bus"
4783 "case" "component" "configuration" "constant"
4784 "disconnect" "downto"
4785 "else" "elsif" "end" "entity" "exit"
4786 "file" "for" "function"
4787 "generate" "generic" "group" "guarded"
4788 "if" "impure" "in" "inertial" "inout" "is"
4789 "label" "library" "linkage" "literal" "loop"
4790 "map" "mod"
4791 "nand" "new" "next" "nor" "not" "null"
4792 "of" "on" "open" "or" "others" "out"
4793 "package" "port" "postponed" "procedure" "process" "pure"
4794 "range" "record" "register" "reject" "rem" "report" "return"
4795 "rol" "ror"
4796 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4797 "then" "to" "transport" "type"
4798 "unaffected" "units" "until" "use"
4799 "variable"
4800 "wait" "when" "while" "with"
4801 "xnor" "xor"
4802 )
4803 "List of VHDL'93 keywords.")
d2ddb974 4804
5eabfe72
KH
4805(defconst vhdl-ams-keywords
4806 '(
4807 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4808 "reference" "spectrum" "subnature" "terminal" "through"
4809 "tolerance"
4810 )
4811 "List of VHDL-AMS keywords.")
d2ddb974 4812
5eabfe72
KH
4813(defconst vhdl-verilog-keywords
4814 '(
4815 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4816 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4817 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4818 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4819 "endprimitive" "endspecify" "endtable" "endtask" "event"
4820 "for" "force" "forever" "fork" "function"
4821 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4822 "macromodule" "makefile" "medium" "module"
4823 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4824 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4825 "pullup"
4826 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4827 "rtranif0" "rtranif1"
4828 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4829 "strong1" "supply" "supply0" "supply1"
4830 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4831 "triand" "trior" "trireg"
4832 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4833 )
4834 "List of Verilog keywords as candidate for additional reserved words.")
d2ddb974 4835
5eabfe72
KH
4836(defconst vhdl-93-types
4837 '(
4838 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4839 "real" "time" "natural" "positive" "string" "line" "text" "side"
4840 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4841 "std_logic" "std_logic_vector"
4842 "std_ulogic" "std_ulogic_vector"
4843 )
4844 "List of VHDL'93 standardized types.")
d2ddb974 4845
5eabfe72
KH
4846(defconst vhdl-ams-types
4847 '(
4848 "domain_type" "real_vector"
3dcb36b7
JB
4849 ;; from `nature_pkg' package
4850 "voltage" "current" "electrical" "position" "velocity" "force"
4851 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4852 "pressure" "flowrate" "fluid"
4853 )
5eabfe72 4854 "List of VHDL-AMS standardized types.")
d2ddb974 4855
5eabfe72
KH
4856(defconst vhdl-math-types
4857 '(
4858 "complex" "complex_polar"
4859 )
4860 "List of Math Packages standardized types.")
d2ddb974 4861
5eabfe72
KH
4862(defconst vhdl-93-attributes
4863 '(
4864 "base" "left" "right" "high" "low" "pos" "val" "succ"
4865 "pred" "leftof" "rightof" "range" "reverse_range"
4866 "length" "delayed" "stable" "quiet" "transaction"
4867 "event" "active" "last_event" "last_active" "last_value"
4868 "driving" "driving_value" "ascending" "value" "image"
4869 "simple_name" "instance_name" "path_name"
4870 "foreign"
4871 )
4872 "List of VHDL'93 standardized attributes.")
d2ddb974 4873
5eabfe72
KH
4874(defconst vhdl-ams-attributes
4875 '(
4876 "across" "through"
4877 "reference" "contribution" "tolerance"
4878 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4879 "ramp" "slew"
4880 )
4881 "List of VHDL-AMS standardized attributes.")
d2ddb974 4882
5eabfe72
KH
4883(defconst vhdl-93-enum-values
4884 '(
4885 "true" "false"
4886 "note" "warning" "error" "failure"
4887 "read_mode" "write_mode" "append_mode"
4888 "open_ok" "status_error" "name_error" "mode_error"
4889 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4890 "right" "left"
4891 )
4892 "List of VHDL'93 standardized enumeration values.")
d2ddb974 4893
5eabfe72
KH
4894(defconst vhdl-ams-enum-values
4895 '(
4896 "quiescent_domain" "time_domain" "frequency_domain"
3dcb36b7
JB
4897 ;; from `nature_pkg' package
4898 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5eabfe72
KH
4899 )
4900 "List of VHDL-AMS standardized enumeration values.")
4901
4902(defconst vhdl-math-constants
4903 '(
4904 "math_e" "math_1_over_e"
4905 "math_pi" "math_two_pi" "math_1_over_pi"
4906 "math_half_pi" "math_q_pi" "math_3_half_pi"
4907 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4908 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4909 "math_deg_to_rad" "math_rad_to_deg"
4910 "cbase_1" "cbase_j" "czero"
4911 )
4912 "List of Math Packages standardized constants.")
4913
4914(defconst vhdl-93-functions
4915 '(
4916 "now" "resolved" "rising_edge" "falling_edge"
4917 "read" "readline" "write" "writeline" "endfile"
4918 "resize" "is_X" "std_match"
4919 "shift_left" "shift_right" "rotate_left" "rotate_right"
4920 "to_unsigned" "to_signed" "to_integer"
4921 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4922 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4923 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4924 "shl" "shr" "ext" "sxt"
3dcb36b7 4925 "deallocate"
5eabfe72
KH
4926 )
4927 "List of VHDL'93 standardized functions.")
4928
4929(defconst vhdl-ams-functions
4930 '(
4931 "frequency"
4932 )
4933 "List of VHDL-AMS standardized functions.")
4934
4935(defconst vhdl-math-functions
4936 '(
4937 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4938 "sqrt" "cbrt" "exp" "log"
4939 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4940 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4941 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4942 )
4943 "List of Math Packages standardized functions.")
4944
4945(defconst vhdl-93-packages
4946 '(
4947 "std_logic_1164" "numeric_std" "numeric_bit"
4948 "standard" "textio"
4949 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4950 "std_logic_misc" "std_logic_textio"
4951 "ieee" "std" "work"
4952 )
4953 "List of VHDL'93 standardized packages and libraries.")
4954
3dcb36b7
JB
4955(defconst vhdl-ams-packages
4956 '(
4957 ;; from `nature_pkg' package
4958 "nature_pkg"
4959 )
4960 "List of VHDL-AMS standardized packages and libraries.")
4961
5eabfe72
KH
4962(defconst vhdl-math-packages
4963 '(
4964 "math_real" "math_complex"
4965 )
4966 "List of Math Packages standardized packages and libraries.")
4967
4968(defvar vhdl-keywords nil
4969 "List of VHDL keywords.")
4970
4971(defvar vhdl-types nil
4972 "List of VHDL standardized types.")
4973
4974(defvar vhdl-attributes nil
4975 "List of VHDL standardized attributes.")
4976
4977(defvar vhdl-enum-values nil
4978 "List of VHDL standardized enumeration values.")
4979
4980(defvar vhdl-constants nil
4981 "List of VHDL standardized constants.")
4982
4983(defvar vhdl-functions nil
4984 "List of VHDL standardized functions.")
4985
4986(defvar vhdl-packages nil
4987 "List of VHDL standardized packages and libraries.")
4988
4989(defvar vhdl-reserved-words nil
4990 "List of additional reserved words.")
4991
4992(defvar vhdl-keywords-regexp nil
4993 "Regexp for VHDL keywords.")
4994
4995(defvar vhdl-types-regexp nil
4996 "Regexp for VHDL standardized types.")
4997
4998(defvar vhdl-attributes-regexp nil
4999 "Regexp for VHDL standardized attributes.")
5000
5001(defvar vhdl-enum-values-regexp nil
5002 "Regexp for VHDL standardized enumeration values.")
5003
5004(defvar vhdl-functions-regexp nil
5005 "Regexp for VHDL standardized functions.")
5006
5007(defvar vhdl-packages-regexp nil
5008 "Regexp for VHDL standardized packages and libraries.")
5009
5010(defvar vhdl-reserved-words-regexp nil
5011 "Regexp for additional reserved words.")
5012
3dcb36b7
JB
5013(defvar vhdl-directive-keywords-regexp nil
5014 "Regexp for compiler directive keywords.")
5015
5eabfe72
KH
5016(defun vhdl-words-init ()
5017 "Initialize reserved words."
5018 (setq vhdl-keywords
5019 (append vhdl-93-keywords
5020 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5021 (setq vhdl-types
5022 (append vhdl-93-types
5023 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5024 (when (vhdl-standard-p 'math) vhdl-math-types)))
5025 (setq vhdl-attributes
5026 (append vhdl-93-attributes
5027 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5028 (setq vhdl-enum-values
5029 (append vhdl-93-enum-values
5030 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5031 (setq vhdl-constants
5032 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5033 (setq vhdl-functions
5034 (append vhdl-93-functions
5035 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5036 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5037 (setq vhdl-packages
5038 (append vhdl-93-packages
3dcb36b7 5039 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5eabfe72
KH
5040 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5041 (setq vhdl-reserved-words
5042 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5043 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5044 '("")))
5045 (setq vhdl-keywords-regexp
5046 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5047 (setq vhdl-types-regexp
5048 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5049 (setq vhdl-attributes-regexp
5050 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5051 (setq vhdl-enum-values-regexp
5052 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5053 (setq vhdl-functions-regexp
5054 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5055 (setq vhdl-packages-regexp
5056 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5057 (setq vhdl-reserved-words-regexp
5058 (concat "\\<\\("
5059 (unless (equal vhdl-forbidden-syntax "")
5060 (concat vhdl-forbidden-syntax "\\|"))
5061 (regexp-opt vhdl-reserved-words)
5062 "\\)\\>"))
3dcb36b7
JB
5063 (setq vhdl-directive-keywords-regexp
5064 (concat "\\<\\(" (mapconcat 'regexp-quote
5065 vhdl-directive-keywords "\\|") "\\)\\>"))
5eabfe72
KH
5066 (vhdl-abbrev-list-init))
5067
5068;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5069;; Words to expand
5070
5071(defvar vhdl-abbrev-list nil
5072 "Predefined abbreviations for VHDL.")
5073
5074(defun vhdl-abbrev-list-init ()
5075 (setq vhdl-abbrev-list
5076 (append
5077 (list vhdl-upper-case-keywords) vhdl-keywords
5078 (list vhdl-upper-case-types) vhdl-types
5079 (list vhdl-upper-case-attributes) vhdl-attributes
5080 (list vhdl-upper-case-enum-values) vhdl-enum-values
5081 (list vhdl-upper-case-constants) vhdl-constants
5082 (list nil) vhdl-functions
5083 (list nil) vhdl-packages)))
5084
5085;; initialize reserved words for VHDL Mode
5086(vhdl-words-init)
5087
5088
5089;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 5090;;; Indentation
5eabfe72
KH
5091;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5092
5093;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
5094;; Syntax analysis
5095
5096;; constant regular expressions for looking at various constructs
5097
5098(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5099 "Regexp describing a VHDL symbol.
5100We cannot use just `word' syntax class since `_' cannot be in word
5101class. Putting underscore in word class breaks forward word movement
5102behavior that users are familiar with.")
5103
5104(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5105 "Regexp describing a case statement header key.")
5106
5107(defconst vhdl-label-key
5108 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5109 "Regexp describing a VHDL label.")
5110
5111;; Macro definitions:
5112
5113(defmacro vhdl-point (position)
5eabfe72
KH
5114 "Return the value of point at certain commonly referenced POSITIONs.
5115POSITION can be one of the following symbols:
5116
5117bol -- beginning of line
5118eol -- end of line
5119bod -- beginning of defun
5120boi -- back to indentation
5121eoi -- last whitespace on line
5122ionl -- indentation of next line
5123iopl -- indentation of previous line
5124bonl -- beginning of next line
5125bopl -- beginning of previous line
5126
5127This function does not modify point or mark."
d2ddb974 5128 (or (and (eq 'quote (car-safe position))
3dcb36b7
JB
5129 (null (cddr position)))
5130 (error "ERROR: Bad buffer position requested: %s" position))
d2ddb974 5131 (setq position (nth 1 position))
d4a5b644
GM
5132 `(let ((here (point)))
5133 ,@(cond
5134 ((eq position 'bol) '((beginning-of-line)))
5135 ((eq position 'eol) '((end-of-line)))
5136 ((eq position 'bod) '((save-match-data
5137 (vhdl-beginning-of-defun))))
5138 ((eq position 'boi) '((back-to-indentation)))
3dcb36b7 5139 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
d4a5b644
GM
5140 ((eq position 'bonl) '((forward-line 1)))
5141 ((eq position 'bopl) '((forward-line -1)))
5142 ((eq position 'iopl)
5143 '((forward-line -1)
5144 (back-to-indentation)))
5145 ((eq position 'ionl)
5146 '((forward-line 1)
5147 (back-to-indentation)))
3dcb36b7 5148 (t (error "ERROR: Unknown buffer position requested: %s" position))
d4a5b644
GM
5149 )
5150 (prog1
5151 (point)
5152 (goto-char here))
5153 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5154 ;; doesn't hurt for v19
5155 ,@nil
5156 ))
d2ddb974
KH
5157
5158(defmacro vhdl-safe (&rest body)
5eabfe72 5159 "Safely execute BODY, return nil if an error occurred."
d4a5b644
GM
5160 `(condition-case nil
5161 (progn ,@body)
5162 (error nil)))
d2ddb974
KH
5163
5164(defmacro vhdl-add-syntax (symbol &optional relpos)
5eabfe72
KH
5165 "A simple macro to append the syntax in SYMBOL to the syntax list.
5166Try to increase performance by using this macro."
d4a5b644
GM
5167 `(setq vhdl-syntactic-context
5168 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
d2ddb974
KH
5169
5170(defmacro vhdl-has-syntax (symbol)
5eabfe72
KH
5171 "A simple macro to return check the syntax list.
5172Try to increase performance by using this macro."
d4a5b644 5173 `(assoc ,symbol vhdl-syntactic-context))
d2ddb974
KH
5174
5175;; Syntactic element offset manipulation:
5176
5177(defun vhdl-read-offset (langelem)
5eabfe72 5178 "Read new offset value for LANGELEM from minibuffer.
2e8b9c7d 5179Return a valid value only."
d2ddb974
KH
5180 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5181 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5182 (prompt "Offset: ")
5183 offset input interned)
5184 (while (not offset)
5185 (setq input (read-string prompt oldoff)
5186 offset (cond ((string-equal "+" input) '+)
5187 ((string-equal "-" input) '-)
5188 ((string-equal "++" input) '++)
5189 ((string-equal "--" input) '--)
5190 ((string-match "^-?[0-9]+$" input)
027a4b6b 5191 (string-to-number input))
d2ddb974
KH
5192 ((fboundp (setq interned (intern input)))
5193 interned)
5194 ((boundp interned) interned)
5195 ;; error, but don't signal one, keep trying
5196 ;; to read an input value
5197 (t (ding)
5198 (setq prompt errmsg)
5199 nil))))
5200 offset))
5201
5202(defun vhdl-set-offset (symbol offset &optional add-p)
5203 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5204SYMBOL is the syntactic element symbol to change and OFFSET is the new
a4c6cfad 5205offset for that syntactic element. Optional ADD-P says to add SYMBOL to
d2ddb974
KH
5206`vhdl-offsets-alist' if it doesn't already appear there."
5207 (interactive
5208 (let* ((langelem
5209 (intern (completing-read
5210 (concat "Syntactic symbol to change"
5211 (if current-prefix-arg " or add" "")
5212 ": ")
5213 (mapcar
5214 (function
5215 (lambda (langelem)
5216 (cons (format "%s" (car langelem)) nil)))
5217 vhdl-offsets-alist)
5218 nil (not current-prefix-arg)
5219 ;; initial contents tries to be the last element
5220 ;; on the syntactic analysis list for the current
5221 ;; line
5222 (let* ((syntax (vhdl-get-syntactic-context))
5223 (len (length syntax))
5224 (ic (format "%s" (car (nth (1- len) syntax)))))
5eabfe72 5225 ic)
d2ddb974
KH
5226 )))
5227 (offset (vhdl-read-offset langelem)))
5228 (list langelem offset current-prefix-arg)))
5229 ;; sanity check offset
5230 (or (eq offset '+)
5231 (eq offset '-)
5232 (eq offset '++)
5233 (eq offset '--)
5234 (integerp offset)
5235 (fboundp offset)
5236 (boundp offset)
3dcb36b7 5237 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
d2ddb974
KH
5238 offset))
5239 (let ((entry (assq symbol vhdl-offsets-alist)))
5240 (if entry
5241 (setcdr entry offset)
5242 (if add-p
5eabfe72
KH
5243 (setq vhdl-offsets-alist
5244 (cons (cons symbol offset) vhdl-offsets-alist))
3dcb36b7 5245 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
d2ddb974
KH
5246 (vhdl-keep-region-active))
5247
5248(defun vhdl-set-style (style &optional local)
5eabfe72 5249 "Set `vhdl-mode' variables to use one of several different indentation styles.
d2ddb974
KH
5250STYLE is a string representing the desired style and optional LOCAL is
5251a flag which, if non-nil, means to make the style variables being
5252changed buffer local, instead of the default, which is to set the
5253global variables. Interactively, the flag comes from the prefix
5254argument. The styles are chosen from the `vhdl-style-alist' variable."
5255 (interactive (list (completing-read "Use which VHDL indentation style? "
5eabfe72 5256 vhdl-style-alist nil t)
d2ddb974
KH
5257 current-prefix-arg))
5258 (let ((vars (cdr (assoc style vhdl-style-alist))))
5259 (or vars
3dcb36b7 5260 (error "ERROR: Invalid VHDL indentation style `%s'" style))
d2ddb974 5261 ;; set all the variables
51b5ad57 5262 (mapc
d2ddb974
KH
5263 (function
5264 (lambda (varentry)
5265 (let ((var (car varentry))
5266 (val (cdr varentry)))
5267 (and local
5268 (make-local-variable var))
5269 ;; special case for vhdl-offsets-alist
5270 (if (not (eq var 'vhdl-offsets-alist))
5271 (set var val)
5272 ;; reset vhdl-offsets-alist to the default value first
5273 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5274 ;; now set the langelems that are different
5275 (mapcar
5276 (function
5277 (lambda (langentry)
5278 (let ((langelem (car langentry))
5279 (offset (cdr langentry)))
5280 (vhdl-set-offset langelem offset)
5281 )))
5282 val))
5283 )))
5284 vars))
5285 (vhdl-keep-region-active))
5286
5287(defun vhdl-get-offset (langelem)
5eabfe72
KH
5288 "Get offset from LANGELEM which is a cons cell of the form:
5289\(SYMBOL . RELPOS). The symbol is matched against
5290vhdl-offsets-alist and the offset found there is either returned,
5291or added to the indentation at RELPOS. If RELPOS is nil, then
5292the offset is simply returned."
d2ddb974
KH
5293 (let* ((symbol (car langelem))
5294 (relpos (cdr langelem))
5295 (match (assq symbol vhdl-offsets-alist))
5296 (offset (cdr-safe match)))
5297 ;; offset can be a number, a function, a variable, or one of the
5298 ;; symbols + or -
5299 (cond
5300 ((not match)
5301 (if vhdl-strict-syntax-p
3dcb36b7 5302 (error "ERROR: Don't know how to indent a %s" symbol)
d2ddb974
KH
5303 (setq offset 0
5304 relpos 0)))
5305 ((eq offset '+) (setq offset vhdl-basic-offset))
5306 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5307 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5308 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5309 ((and (not (numberp offset))
5310 (fboundp offset))
5311 (setq offset (funcall offset langelem)))
5312 ((not (numberp offset))
5313 (setq offset (eval offset)))
5314 )
5315 (+ (if (and relpos
5316 (< relpos (vhdl-point 'bol)))
5317 (save-excursion
5318 (goto-char relpos)
5319 (current-column))
5320 0)
5321 offset)))
5322
5323;; Syntactic support functions:
5324
3dcb36b7
JB
5325(defun vhdl-in-comment-p ()
5326 "Check if point is in a comment."
5327 (eq (vhdl-in-literal) 'comment))
5328
5329(defun vhdl-in-string-p ()
5330 "Check if point is in a string."
5331 (eq (vhdl-in-literal) 'string))
d2ddb974 5332
3dcb36b7 5333(defun vhdl-in-literal ()
5eabfe72 5334 "Determine if point is in a VHDL literal."
d2ddb974 5335 (save-excursion
5eabfe72 5336 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
d2ddb974
KH
5337 (cond
5338 ((nth 3 state) 'string)
5339 ((nth 4 state) 'comment)
0a2e512a 5340 ((vhdl-beginning-of-macro) 'pound)
5eabfe72 5341 (t nil)))))
d2ddb974 5342
3dcb36b7
JB
5343(defun vhdl-forward-comment (&optional direction)
5344 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5345negative, skip forward otherwise."
5346 (interactive "p")
5347 (if (and direction (< direction 0))
5348 ;; skip backwards
5349 (progn
5350 (skip-chars-backward " \t\n")
5351 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5352 (goto-char (match-beginning 3))
5353 (skip-chars-backward " \t\n")))
5354 ;; skip forwards
5355 (skip-chars-forward " \t\n")
5356 (while (looking-at "--.*")
5357 (goto-char (match-end 0))
5358 (skip-chars-forward " \t\n"))))
5359
5360;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
f8246027 5361(unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
3dcb36b7
JB
5362 (defalias 'vhdl-forward-comment 'forward-comment))
5363
d2ddb974
KH
5364;; This is the best we can do in Win-Emacs.
5365(defun vhdl-win-il (&optional lim)
5eabfe72 5366 "Determine if point is in a VHDL literal."
d2ddb974
KH
5367 (save-excursion
5368 (let* ((here (point))
5369 (state nil)
5370 (match nil)
5371 (lim (or lim (vhdl-point 'bod))))
5372 (goto-char lim )
5373 (while (< (point) here)
5374 (setq match
5375 (and (re-search-forward "--\\|[\"']"
5376 here 'move)
5377 (buffer-substring (match-beginning 0) (match-end 0))))
5378 (setq state
5379 (cond
5380 ;; no match
5381 ((null match) nil)
5382 ;; looking at the opening of a VHDL style comment
5383 ((string= "--" match)
5384 (if (<= here (progn (end-of-line) (point))) 'comment))
5385 ;; looking at the opening of a double quote string
5386 ((string= "\"" match)
5387 (if (not (save-restriction
5388 ;; this seems to be necessary since the
5389 ;; re-search-forward will not work without it
5390 (narrow-to-region (point) here)
5391 (re-search-forward
5392 ;; this regexp matches a double quote
5393 ;; which is preceded by an even number
5394 ;; of backslashes, including zero
5395 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5396 'string))
5397 ;; looking at the opening of a single quote string
5398 ((string= "'" match)
5399 (if (not (save-restriction
5400 ;; see comments from above
5401 (narrow-to-region (point) here)
5402 (re-search-forward
5403 ;; this matches a single quote which is
5404 ;; preceded by zero or two backslashes.
5405 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5406 here 'move)))
5407 'string))
5408 (t nil)))
5409 ) ; end-while
5410 state)))
5411
5eabfe72 5412(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5413 (fset 'vhdl-in-literal 'vhdl-win-il))
5414
5415;; Skipping of "syntactic whitespace". Syntactic whitespace is
5416;; defined as lexical whitespace or comments. Search no farther back
5417;; or forward than optional LIM. If LIM is omitted, (point-min) is
5418;; used for backward skipping, (point-max) is used for forward
5419;; skipping.
5420
5421(defun vhdl-forward-syntactic-ws (&optional lim)
5eabfe72 5422 "Forward skip of syntactic whitespace."
0a2e512a
RF
5423 (let* ((here (point-max))
5424 (hugenum (point-max)))
5425 (while (/= here (point))
5426 (setq here (point))
5427 (vhdl-forward-comment hugenum)
5428 ;; skip preprocessor directives
5429 (when (and (eq (char-after) ?#)
5430 (= (vhdl-point 'boi) (point)))
5431 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5432 (= (forward-line 1) 0)))
5433 (end-of-line)))
5434 (if lim (goto-char (min (point) lim)))))
5435
d2ddb974
KH
5436
5437;; This is the best we can do in Win-Emacs.
5438(defun vhdl-win-fsws (&optional lim)
5eabfe72 5439 "Forward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5440 (let ((lim (or lim (point-max)))
5441 stop)
5442 (while (not stop)
5443 (skip-chars-forward " \t\n\r\f" lim)
5444 (cond
5445 ;; vhdl comment
5446 ((looking-at "--") (end-of-line))
5447 ;; none of the above
3dcb36b7 5448 (t (setq stop t))))))
d2ddb974 5449
5eabfe72 5450(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5451 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5452
0a2e512a
RF
5453(defun vhdl-beginning-of-macro (&optional lim)
5454 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5455 (let ((here (point)))
5456 (beginning-of-line)
5457 (while (eq (char-before (1- (point))) ?\\)
5458 (forward-line -1))
5459 (back-to-indentation)
5460 (if (and (<= (point) here)
5461 (eq (char-after) ?#))
5462 t
5463 (goto-char here)
5464 nil)))
5465
d2ddb974 5466(defun vhdl-backward-syntactic-ws (&optional lim)
5eabfe72 5467 "Backward skip over syntactic whitespace."
0a2e512a
RF
5468 (let* ((here (point-min))
5469 (hugenum (- (point-max))))
5470 (while (/= here (point))
5471 (setq here (point))
5472 (vhdl-forward-comment hugenum)
5473 (vhdl-beginning-of-macro))
5474 (if lim (goto-char (max (point) lim)))))
d2ddb974
KH
5475
5476;; This is the best we can do in Win-Emacs.
5477(defun vhdl-win-bsws (&optional lim)
5eabfe72 5478 "Backward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5479 (let ((lim (or lim (vhdl-point 'bod)))
5480 stop)
5481 (while (not stop)
5482 (skip-chars-backward " \t\n\r\f" lim)
5483 (cond
5484 ;; vhdl comment
3dcb36b7 5485 ((eq (vhdl-in-literal) 'comment)
d2ddb974
KH
5486 (skip-chars-backward "^-" lim)
5487 (skip-chars-backward "-" lim)
5488 (while (not (or (and (= (following-char) ?-)
5489 (= (char-after (1+ (point))) ?-))
5490 (<= (point) lim)))
5491 (skip-chars-backward "^-" lim)
5492 (skip-chars-backward "-" lim)))
5493 ;; none of the above
3dcb36b7 5494 (t (setq stop t))))))
d2ddb974 5495
5eabfe72 5496(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5497 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5498
5499;; Functions to help finding the correct indentation column:
5500
5501(defun vhdl-first-word (point)
5502 "If the keyword at POINT is at boi, then return (current-column) at
5503that point, else nil."
5504 (save-excursion
5505 (and (goto-char point)
5506 (eq (point) (vhdl-point 'boi))
5507 (current-column))))
5508
5509(defun vhdl-last-word (point)
5510 "If the keyword at POINT is at eoi, then return (current-column) at
5511that point, else nil."
5512 (save-excursion
5513 (and (goto-char point)
5514 (save-excursion (or (eq (progn (forward-sexp) (point))
5515 (vhdl-point 'eoi))
5516 (looking-at "\\s-*\\(--\\)?")))
5517 (current-column))))
5518
5519;; Core syntactic evaluation functions:
5520
5521(defconst vhdl-libunit-re
5522 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5523
5524(defun vhdl-libunit-p ()
5525 (and
5526 (save-excursion
5527 (forward-sexp)
5528 (skip-chars-forward " \t\n")
5529 (not (looking-at "is\\b[^_]")))
5530 (save-excursion
5531 (backward-sexp)
5532 (and (not (looking-at "use\\b[^_]"))
5533 (progn
5534 (forward-sexp)
5535 (vhdl-forward-syntactic-ws)
5536 (/= (following-char) ?:))))
5537 ))
5538
5539(defconst vhdl-defun-re
5eabfe72 5540 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
d2ddb974
KH
5541
5542(defun vhdl-defun-p ()
5543 (save-excursion
5eabfe72
KH
5544 (if (looking-at "block\\|process\\|procedural")
5545 ;; "block", "process", "procedural":
d2ddb974
KH
5546 (save-excursion
5547 (backward-sexp)
5548 (not (looking-at "end\\s-+\\w")))
5549 ;; "architecture", "configuration", "entity",
5550 ;; "package", "procedure", "function":
5551 t)))
5552
5553(defun vhdl-corresponding-defun ()
5554 "If the word at the current position corresponds to a \"defun\"
5555keyword, then return a string that can be used to find the
5556corresponding \"begin\" keyword, else return nil."
5557 (save-excursion
5558 (and (looking-at vhdl-defun-re)
5559 (vhdl-defun-p)
5eabfe72
KH
5560 (if (looking-at "block\\|process\\|procedural")
5561 ;; "block", "process". "procedural:
d2ddb974
KH
5562 (buffer-substring (match-beginning 0) (match-end 0))
5563 ;; "architecture", "configuration", "entity", "package",
5564 ;; "procedure", "function":
5565 "is"))))
5566
5567(defconst vhdl-begin-fwd-re
5eabfe72 5568 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
d2ddb974
KH
5569 "A regular expression for searching forward that matches all known
5570\"begin\" keywords.")
5571
5572(defconst vhdl-begin-bwd-re
5eabfe72 5573 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
d2ddb974
KH
5574 "A regular expression for searching backward that matches all known
5575\"begin\" keywords.")
5576
5577(defun vhdl-begin-p (&optional lim)
5578 "Return t if we are looking at a real \"begin\" keyword.
5579Assumes that the caller will make sure that we are looking at
5580vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5581the middle of an identifier that just happens to contain a \"begin\"
5582keyword."
5583 (cond
5584 ;; "[architecture|case|configuration|entity|package|
5585 ;; procedure|function] ... is":
5586 ((and (looking-at "i")
5587 (save-excursion
5588 ;; Skip backward over first sexp (needed to skip over a
5589 ;; procedure interface list, and is harmless in other
5590 ;; situations). Note that we need "return" in the
5591 ;; following search list so that we don't run into
5592 ;; semicolons in the function interface list.
5593 (backward-sexp)
5594 (let (foundp)
5595 (while (and (not foundp)
5596 (re-search-backward
5eabfe72 5597 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
d2ddb974
KH
5598 lim 'move))
5599 (if (or (= (preceding-char) ?_)
3dcb36b7 5600 (vhdl-in-literal))
d2ddb974
KH
5601 (backward-char)
5602 (setq foundp t))))
5603 (and (/= (following-char) ?\;)
5eabfe72 5604 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
d2ddb974
KH
5605 t)
5606 ;; "begin", "then":
5607 ((looking-at "be\\|t")
5608 t)
5609 ;; "else":
5610 ((and (looking-at "e")
5611 ;; make sure that the "else" isn't inside a
5612 ;; conditional signal assignment.
5613 (save-excursion
5614 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5615 (or (eq (following-char) ?\;)
5616 (eq (point) lim))))
5617 t)
5eabfe72 5618 ;; "block", "generate", "loop", "process", "procedural",
d2ddb974
KH
5619 ;; "units", "record":
5620 ((and (looking-at "bl\\|[glpur]")
5621 (save-excursion
5622 (backward-sexp)
5623 (not (looking-at "end\\s-+\\w"))))
5624 t)
5625 ;; "component":
5626 ((and (looking-at "c")
5627 (save-excursion
5628 (backward-sexp)
5629 (not (looking-at "end\\s-+\\w")))
5630 ;; look out for the dreaded entity class in an attribute
5631 (save-excursion
5632 (vhdl-backward-syntactic-ws lim)
5633 (/= (preceding-char) ?:)))
5634 t)
5635 ;; "for" (inside configuration declaration):
5636 ((and (looking-at "f")
5637 (save-excursion
5638 (backward-sexp)
5639 (not (looking-at "end\\s-+\\w")))
5640 (vhdl-has-syntax 'configuration))
5641 t)
5642 ))
5643
5644(defun vhdl-corresponding-mid (&optional lim)
5645 (cond
5eabfe72 5646 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
d2ddb974
KH
5647 "begin")
5648 ((looking-at "then")
5649 "<else>")
5650 (t
5651 "end")))
5652
5653(defun vhdl-corresponding-end (&optional lim)
5654 "If the word at the current position corresponds to a \"begin\"
5655keyword, then return a vector containing enough information to find
5656the corresponding \"end\" keyword, else return nil. The keyword to
5657search forward for is aref 0. The column in which the keyword must
5658appear is aref 1 or nil if any column is suitable.
5659Assumes that the caller will make sure that we are not in the middle
5660of an identifier that just happens to contain a \"begin\" keyword."
5661 (save-excursion
5662 (and (looking-at vhdl-begin-fwd-re)
5663 (/= (preceding-char) ?_)
3dcb36b7 5664 (not (vhdl-in-literal))
d2ddb974
KH
5665 (vhdl-begin-p lim)
5666 (cond
5667 ;; "is", "generate", "loop":
5668 ((looking-at "[igl]")
5669 (vector "end"
5670 (and (vhdl-last-word (point))
5671 (or (vhdl-first-word (point))
5672 (save-excursion
5673 (vhdl-beginning-of-statement-1 lim)
5674 (vhdl-backward-skip-label lim)
5675 (vhdl-first-word (point)))))))
5676 ;; "begin", "else", "for":
5677 ((looking-at "be\\|[ef]")
5678 (vector "end"
5679 (and (vhdl-last-word (point))
5680 (or (vhdl-first-word (point))
5681 (save-excursion
5682 (vhdl-beginning-of-statement-1 lim)
5683 (vhdl-backward-skip-label lim)
5684 (vhdl-first-word (point)))))))
5685 ;; "component", "units", "record":
5686 ((looking-at "[cur]")
5687 ;; The first end found will close the block
5688 (vector "end" nil))
5eabfe72 5689 ;; "block", "process", "procedural":
d2ddb974
KH
5690 ((looking-at "bl\\|p")
5691 (vector "end"
5692 (or (vhdl-first-word (point))
5693 (save-excursion
5694 (vhdl-beginning-of-statement-1 lim)
5695 (vhdl-backward-skip-label lim)
5696 (vhdl-first-word (point))))))
5697 ;; "then":
5698 ((looking-at "t")
5699 (vector "elsif\\|else\\|end\\s-+if"
5700 (and (vhdl-last-word (point))
5701 (or (vhdl-first-word (point))
5702 (save-excursion
5703 (vhdl-beginning-of-statement-1 lim)
5704 (vhdl-backward-skip-label lim)
5705 (vhdl-first-word (point)))))))
5706 ))))
5707
5708(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5709
5710(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5711
5712(defun vhdl-end-p (&optional lim)
5713 "Return t if we are looking at a real \"end\" keyword.
5714Assumes that the caller will make sure that we are looking at
5715vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5716the middle of an identifier that just happens to contain an \"end\"
5717keyword."
5718 (or (not (looking-at "else"))
5719 ;; make sure that the "else" isn't inside a conditional signal
5720 ;; assignment.
5721 (save-excursion
5722 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5723 (or (eq (following-char) ?\;)
0a2e512a
RF
5724 (eq (point) lim)
5725 (vhdl-in-literal)))))
d2ddb974
KH
5726
5727(defun vhdl-corresponding-begin (&optional lim)
5728 "If the word at the current position corresponds to an \"end\"
5729keyword, then return a vector containing enough information to find
5730the corresponding \"begin\" keyword, else return nil. The keyword to
a4c6cfad 5731search backward for is aref 0. The column in which the keyword must
d2ddb974
KH
5732appear is aref 1 or nil if any column is suitable. The supplementary
5733keyword to search forward for is aref 2 or nil if this is not
5734required. If aref 3 is t, then the \"begin\" keyword may be found in
5735the middle of a statement.
5736Assumes that the caller will make sure that we are not in the middle
5737of an identifier that just happens to contain an \"end\" keyword."
5738 (save-excursion
5739 (let (pos)
5740 (if (and (looking-at vhdl-end-fwd-re)
3dcb36b7 5741 (not (vhdl-in-literal))
d2ddb974
KH
5742 (vhdl-end-p lim))
5743 (if (looking-at "el")
5744 ;; "else", "elsif":
5745 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5746 ;; "end ...":
5747 (setq pos (point))
5748 (forward-sexp)
5749 (skip-chars-forward " \t\n")
5750 (cond
5751 ;; "end if":
5752 ((looking-at "if\\b[^_]")
5753 (vector "else\\|elsif\\|if"
5754 (vhdl-first-word pos)
5755 "else\\|then" nil))
5756 ;; "end component":
5757 ((looking-at "component\\b[^_]")
5758 (vector (buffer-substring (match-beginning 1)
5759 (match-end 1))
5760 (vhdl-first-word pos)
5761 nil nil))
5762 ;; "end units", "end record":
5763 ((looking-at "\\(units\\|record\\)\\b[^_]")
5764 (vector (buffer-substring (match-beginning 1)
5765 (match-end 1))
5766 (vhdl-first-word pos)
5767 nil t))
5eabfe72
KH
5768 ;; "end block", "end process", "end procedural":
5769 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
d2ddb974
KH
5770 (vector "begin" (vhdl-first-word pos) nil nil))
5771 ;; "end case":
5772 ((looking-at "case\\b[^_]")
5773 (vector "case" (vhdl-first-word pos) "is" nil))
5774 ;; "end generate":
5775 ((looking-at "generate\\b[^_]")
5776 (vector "generate\\|for\\|if"
5777 (vhdl-first-word pos)
5778 "generate" nil))
5779 ;; "end loop":
5780 ((looking-at "loop\\b[^_]")
5781 (vector "loop\\|while\\|for"
5782 (vhdl-first-word pos)
5783 "loop" nil))
5784 ;; "end for" (inside configuration declaration):
5785 ((looking-at "for\\b[^_]")
5786 (vector "for" (vhdl-first-word pos) nil nil))
5787 ;; "end [id]":
5788 (t
5789 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5790 (vhdl-first-word pos)
5791 ;; return an alist of (statement . keyword) mappings
5792 '(
5793 ;; "begin ... end [id]":
0a2e512a 5794 ("begin" . nil)
d2ddb974 5795 ;; "architecture ... is ... begin ... end [id]":
0a2e512a 5796 ("architecture" . "is")
d2ddb974
KH
5797 ;; "configuration ... is ... end [id]":
5798 ("configuration" . "is")
5799 ;; "entity ... is ... end [id]":
0a2e512a 5800 ("entity" . "is")
d2ddb974 5801 ;; "package ... is ... end [id]":
0a2e512a 5802 ("package" . "is")
d2ddb974
KH
5803 ;; "procedure ... is ... begin ... end [id]":
5804 ("procedure" . "is")
5805 ;; "function ... is ... begin ... end [id]":
5806 ("function" . "is")
5807 )
5808 nil))
5809 ))) ; "end ..."
5810 )))
5811
5812(defconst vhdl-leader-re
5eabfe72 5813 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
d2ddb974
KH
5814
5815(defun vhdl-end-of-leader ()
5816 (save-excursion
5eabfe72 5817 (cond ((looking-at "block\\|process\\|procedural")
d2ddb974
KH
5818 (if (save-excursion
5819 (forward-sexp)
5820 (skip-chars-forward " \t\n")
5821 (= (following-char) ?\())
5822 (forward-sexp 2)
5823 (forward-sexp))
3dcb36b7
JB
5824 (when (looking-at "[ \t\n]*is")
5825 (goto-char (match-end 0)))
d2ddb974
KH
5826 (point))
5827 ((looking-at "component")
5828 (forward-sexp 2)
3dcb36b7
JB
5829 (when (looking-at "[ \t\n]*is")
5830 (goto-char (match-end 0)))
d2ddb974
KH
5831 (point))
5832 ((looking-at "for")
5833 (forward-sexp 2)
5834 (skip-chars-forward " \t\n")
5835 (while (looking-at "[,:(]")
5836 (forward-sexp)
5837 (skip-chars-forward " \t\n"))
5838 (point))
5839 (t nil)
5840 )))
5841
5842(defconst vhdl-trailer-re
0a2e512a 5843 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
d2ddb974
KH
5844
5845(defconst vhdl-statement-fwd-re
5846 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5847 "A regular expression for searching forward that matches all known
5848\"statement\" keywords.")
5849
5850(defconst vhdl-statement-bwd-re
5851 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5852 "A regular expression for searching backward that matches all known
5853\"statement\" keywords.")
5854
5855(defun vhdl-statement-p (&optional lim)
5856 "Return t if we are looking at a real \"statement\" keyword.
5857Assumes that the caller will make sure that we are looking at
5eabfe72
KH
5858vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5859in the middle of an identifier that just happens to contain a
5860\"statement\" keyword."
d2ddb974
KH
5861 (cond
5862 ;; "for" ... "generate":
5863 ((and (looking-at "f")
5864 ;; Make sure it's the start of a parameter specification.
5865 (save-excursion
5866 (forward-sexp 2)
5867 (skip-chars-forward " \t\n")
5868 (looking-at "in\\b[^_]"))
5869 ;; Make sure it's not an "end for".
5870 (save-excursion
5871 (backward-sexp)
5872 (not (looking-at "end\\s-+\\w"))))
5873 t)
5874 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5875 ((and (looking-at "i")
5876 ;; Make sure it's not an "end if".
5877 (save-excursion
5878 (backward-sexp)
5879 (not (looking-at "end\\s-+\\w"))))
5880 t)
5881 ;; "while" ... "loop":
5882 ((looking-at "w")
5883 t)
5884 ))
5885
5886(defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5887 "Regexp describing a case statement alternative key.")
5888
5889(defun vhdl-case-alternative-p (&optional lim)
5890 "Return t if we are looking at a real case alternative.
5891Assumes that the caller will make sure that we are looking at
5892vhdl-case-alternative-re, and are not inside a literal, and that
5893we are not in the middle of an identifier that just happens to
5894contain a \"when\" keyword."
5895 (save-excursion
5896 (let (foundp)
5897 (while (and (not foundp)
5898 (re-search-backward ";\\|<=" lim 'move))
5899 (if (or (= (preceding-char) ?_)
3dcb36b7 5900 (vhdl-in-literal))
d2ddb974
KH
5901 (backward-char)
5902 (setq foundp t)))
5903 (or (eq (following-char) ?\;)
5904 (eq (point) lim)))
5905 ))
5906
5907;; Core syntactic movement functions:
5908
5909(defconst vhdl-b-t-b-re
5910 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5911
5912(defun vhdl-backward-to-block (&optional lim)
5913 "Move backward to the previous \"begin\" or \"end\" keyword."
5914 (let (foundp)
5915 (while (and (not foundp)
5916 (re-search-backward vhdl-b-t-b-re lim 'move))
5917 (if (or (= (preceding-char) ?_)
3dcb36b7 5918 (vhdl-in-literal))
d2ddb974
KH
5919 (backward-char)
5920 (cond
5921 ;; "begin" keyword:
5922 ((and (looking-at vhdl-begin-fwd-re)
5923 (/= (preceding-char) ?_)
5924 (vhdl-begin-p lim))
5925 (setq foundp 'begin))
5926 ;; "end" keyword:
5927 ((and (looking-at vhdl-end-fwd-re)
5928 (/= (preceding-char) ?_)
5929 (vhdl-end-p lim))
5930 (setq foundp 'end))
5931 ))
5932 )
5933 foundp
5934 ))
5935
5936(defun vhdl-forward-sexp (&optional count lim)
5937 "Move forward across one balanced expression (sexp).
5938With COUNT, do it that many times."
5939 (interactive "p")
5940 (let ((count (or count 1))
5941 (case-fold-search t)
5942 end-vec target)
5943 (save-excursion
5944 (while (> count 0)
5945 ;; skip whitespace
5946 (skip-chars-forward " \t\n")
5947 ;; Check for an unbalanced "end" keyword
5948 (if (and (looking-at vhdl-end-fwd-re)
5949 (/= (preceding-char) ?_)
3dcb36b7 5950 (not (vhdl-in-literal))
d2ddb974
KH
5951 (vhdl-end-p lim)
5952 (not (looking-at "else")))
5953 (error
3dcb36b7 5954 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
d2ddb974
KH
5955 ;; If the current keyword is a "begin" keyword, then find the
5956 ;; corresponding "end" keyword.
5957 (if (setq end-vec (vhdl-corresponding-end lim))
5958 (let (
5959 ;; end-re is the statement keyword to search for
5960 (end-re
5961 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5962 ;; column is either the statement keyword target column
5963 ;; or nil
5964 (column (aref end-vec 1))
5965 (eol (vhdl-point 'eol))
5966 foundp literal placeholder)
5967 ;; Look for the statement keyword.
5968 (while (and (not foundp)
5969 (re-search-forward end-re nil t)
5970 (setq placeholder (match-end 1))
5971 (goto-char (match-beginning 0)))
5972 ;; If we are in a literal, or not in the right target
5973 ;; column and not on the same line as the begin, then
5974 ;; try again.
5975 (if (or (and column
5976 (/= (current-indentation) column)
5977 (> (point) eol))
5978 (= (preceding-char) ?_)
3dcb36b7 5979 (setq literal (vhdl-in-literal)))
d2ddb974
KH
5980 (if (eq literal 'comment)
5981 (end-of-line)
5982 (forward-char))
5983 ;; An "else" keyword corresponds to both the opening brace
5984 ;; of the following sexp and the closing brace of the
5985 ;; previous sexp.
5986 (if (not (looking-at "else"))
5987 (goto-char placeholder))
5988 (setq foundp t))
5989 )
5990 (if (not foundp)
3dcb36b7 5991 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
d2ddb974
KH
5992 )
5993 ;; If the current keyword is not a "begin" keyword, then just
5994 ;; perform the normal forward-sexp.
5995 (forward-sexp)
5996 )
5997 (setq count (1- count))
5998 )
5999 (setq target (point)))
6000 (goto-char target)
6001 nil))
6002
6003(defun vhdl-backward-sexp (&optional count lim)
6004 "Move backward across one balanced expression (sexp).
6005With COUNT, do it that many times. LIM bounds any required backward
6006searches."
6007 (interactive "p")
6008 (let ((count (or count 1))
6009 (case-fold-search t)
6010 begin-vec target)
6011 (save-excursion
6012 (while (> count 0)
6013 ;; Perform the normal backward-sexp, unless we are looking at
6014 ;; "else" - an "else" keyword corresponds to both the opening brace
6015 ;; of the following sexp and the closing brace of the previous sexp.
6016 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6017 (/= (preceding-char) ?_)
3dcb36b7 6018 (not (vhdl-in-literal)))
d2ddb974
KH
6019 nil
6020 (backward-sexp)
6021 (if (and (looking-at vhdl-begin-fwd-re)
6022 (/= (preceding-char) ?_)
3dcb36b7 6023 (not (vhdl-in-literal))
d2ddb974 6024 (vhdl-begin-p lim))
3dcb36b7 6025 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
d2ddb974
KH
6026 ;; If the current keyword is an "end" keyword, then find the
6027 ;; corresponding "begin" keyword.
6028 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6029 (/= (preceding-char) ?_))
6030 (let (
6031 ;; begin-re is the statement keyword to search for
6032 (begin-re
6033 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6034 ;; column is either the statement keyword target column
6035 ;; or nil
6036 (column (aref begin-vec 1))
6037 ;; internal-p controls where the statement keyword can
6038 ;; be found.
6039 (internal-p (aref begin-vec 3))
6040 (last-backward (point)) last-forward
6041 foundp literal keyword)
6042 ;; Look for the statement keyword.
6043 (while (and (not foundp)
6044 (re-search-backward begin-re lim t)
6045 (setq keyword
6046 (buffer-substring (match-beginning 1)
6047 (match-end 1))))
6048 ;; If we are in a literal or in the wrong column,
6049 ;; then try again.
6050 (if (or (and column
6051 (and (/= (current-indentation) column)
6052 ;; possibly accept current-column as
6053 ;; well as current-indentation.
6054 (or (not internal-p)
6055 (/= (current-column) column))))
6056 (= (preceding-char) ?_)
3dcb36b7 6057 (vhdl-in-literal))
d2ddb974
KH
6058 (backward-char)
6059 ;; If there is a supplementary keyword, then
6060 ;; search forward for it.
6061 (if (and (setq begin-re (aref begin-vec 2))
6062 (or (not (listp begin-re))
6063 ;; If begin-re is an alist, then find the
6064 ;; element corresponding to the actual
6065 ;; keyword that we found.
6066 (progn
6067 (setq begin-re
6068 (assoc keyword begin-re))
6069 (and begin-re
6070 (setq begin-re (cdr begin-re))))))
6071 (and
6072 (setq begin-re
6073 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6074 (save-excursion
6075 (setq last-forward (point))
6076 ;; Look for the supplementary keyword
6077 ;; (bounded by the backward search start
6078 ;; point).
6079 (while (and (not foundp)
6080 (re-search-forward begin-re
6081 last-backward t)
6082 (goto-char (match-beginning 1)))
6083 ;; If we are in a literal, then try again.
6084 (if (or (= (preceding-char) ?_)
6085 (setq literal
3dcb36b7 6086 (vhdl-in-literal)))
d2ddb974
KH
6087 (if (eq literal 'comment)
6088 (goto-char
6089 (min (vhdl-point 'eol) last-backward))
6090 (forward-char))
6091 ;; We have found the supplementary keyword.
6092 ;; Save the position of the keyword in foundp.
6093 (setq foundp (point)))
6094 )
6095 foundp)
6096 ;; If the supplementary keyword was found, then
6097 ;; move point to the supplementary keyword.
6098 (goto-char foundp))
6099 ;; If there was no supplementary keyword, then
6100 ;; point is already at the statement keyword.
6101 (setq foundp t)))
6102 ) ; end of the search for the statement keyword
6103 (if (not foundp)
3dcb36b7 6104 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
d2ddb974
KH
6105 ))
6106 (setq count (1- count))
6107 )
6108 (setq target (point)))
6109 (goto-char target)
6110 nil))
6111
6112(defun vhdl-backward-up-list (&optional count limit)
6113 "Move backward out of one level of blocks.
6114With argument, do this that many times."
6115 (interactive "p")
6116 (let ((count (or count 1))
6117 target)
6118 (save-excursion
6119 (while (> count 0)
6120 (if (looking-at vhdl-defun-re)
3dcb36b7 6121 (error "ERROR: Unbalanced blocks"))
d2ddb974
KH
6122 (vhdl-backward-to-block limit)
6123 (setq count (1- count)))
6124 (setq target (point)))
6125 (goto-char target)))
6126
6127(defun vhdl-end-of-defun (&optional count)
6128 "Move forward to the end of a VHDL defun."
6129 (interactive)
6130 (let ((case-fold-search t))
6131 (vhdl-beginning-of-defun)
5eabfe72 6132 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6133 (re-search-forward "\\bis\\b"))
6134 (vhdl-forward-sexp)))
6135
6136(defun vhdl-mark-defun ()
6137 "Put mark at end of this \"defun\", point at beginning."
6138 (interactive)
6139 (let ((case-fold-search t))
6140 (push-mark)
6141 (vhdl-beginning-of-defun)
6142 (push-mark)
5eabfe72 6143 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6144 (re-search-forward "\\bis\\b"))
6145 (vhdl-forward-sexp)
6146 (exchange-point-and-mark)))
6147
6148(defun vhdl-beginning-of-libunit ()
6149 "Move backward to the beginning of a VHDL library unit.
6150Returns the location of the corresponding begin keyword, unless search
5eabfe72
KH
6151stops due to beginning or end of buffer.
6152Note that if point is between the \"libunit\" keyword and the
6153corresponding \"begin\" keyword, then that libunit will not be
a3dd3c0e
JB
6154recognized, and the search will continue backwards. If point is
6155at the \"begin\" keyword, then the defun will be recognized. The
5eabfe72 6156returned point is at the first character of the \"libunit\" keyword."
d2ddb974
KH
6157 (let ((last-forward (point))
6158 (last-backward
6159 ;; Just in case we are actually sitting on the "begin"
6160 ;; keyword, allow for the keyword and an extra character,
6161 ;; as this will be used when looking forward for the
6162 ;; "begin" keyword.
6163 (save-excursion (forward-word 1) (1+ (point))))
6164 foundp literal placeholder)
6165 ;; Find the "libunit" keyword.
6166 (while (and (not foundp)
6167 (re-search-backward vhdl-libunit-re nil 'move))
6168 ;; If we are in a literal, or not at a real libunit, then try again.
6169 (if (or (= (preceding-char) ?_)
3dcb36b7 6170 (vhdl-in-literal)
d2ddb974
KH
6171 (not (vhdl-libunit-p)))
6172 (backward-char)
6173 ;; Find the corresponding "begin" keyword.
6174 (setq last-forward (point))
6175 (while (and (not foundp)
6176 (re-search-forward "\\bis\\b[^_]" last-backward t)
6177 (setq placeholder (match-beginning 0)))
6178 (if (or (= (preceding-char) ?_)
3dcb36b7 6179 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6180 ;; It wasn't a real keyword, so keep searching.
6181 (if (eq literal 'comment)
6182 (goto-char
6183 (min (vhdl-point 'eol) last-backward))
6184 (forward-char))
6185 ;; We have found the begin keyword, loop will exit.
6186 (setq foundp placeholder)))
6187 ;; Go back to the libunit keyword
6188 (goto-char last-forward)))
6189 foundp))
6190
6191(defun vhdl-beginning-of-defun (&optional count)
6192 "Move backward to the beginning of a VHDL defun.
6193With argument, do it that many times.
6194Returns the location of the corresponding begin keyword, unless search
6195stops due to beginning or end of buffer."
6196 ;; Note that if point is between the "defun" keyword and the
6197 ;; corresponding "begin" keyword, then that defun will not be
0a2e512a
RF
6198 ;; recognized, and the search will continue backwards. If point is
6199 ;; at the "begin" keyword, then the defun will be recognized. The
d2ddb974
KH
6200 ;; returned point is at the first character of the "defun" keyword.
6201 (interactive "p")
6202 (let ((count (or count 1))
6203 (case-fold-search t)
6204 (last-forward (point))
6205 foundp)
6206 (while (> count 0)
6207 (setq foundp nil)
6208 (goto-char last-forward)
6209 (let ((last-backward
6210 ;; Just in case we are actually sitting on the "begin"
6211 ;; keyword, allow for the keyword and an extra character,
6212 ;; as this will be used when looking forward for the
6213 ;; "begin" keyword.
6214 (save-excursion (forward-word 1) (1+ (point))))
6215 begin-string literal)
6216 (while (and (not foundp)
6217 (re-search-backward vhdl-defun-re nil 'move))
6218 ;; If we are in a literal, then try again.
6219 (if (or (= (preceding-char) ?_)
3dcb36b7 6220 (vhdl-in-literal))
d2ddb974
KH
6221 (backward-char)
6222 (if (setq begin-string (vhdl-corresponding-defun))
6223 ;; This is a real defun keyword.
6224 ;; Find the corresponding "begin" keyword.
6225 ;; Look for the begin keyword.
6226 (progn
6227 ;; Save the search start point.
6228 (setq last-forward (point))
6229 (while (and (not foundp)
6230 (search-forward begin-string last-backward t))
6231 (if (or (= (preceding-char) ?_)
6232 (save-match-data
3dcb36b7 6233 (setq literal (vhdl-in-literal))))
d2ddb974
KH
6234 ;; It wasn't a real keyword, so keep searching.
6235 (if (eq literal 'comment)
6236 (goto-char
6237 (min (vhdl-point 'eol) last-backward))
6238 (forward-char))
6239 ;; We have found the begin keyword, loop will exit.
6240 (setq foundp (match-beginning 0)))
6241 )
6242 ;; Go back to the defun keyword
6243 (goto-char last-forward)) ; end search for begin keyword
6244 ))
6245 ) ; end of the search for the defun keyword
6246 )
6247 (setq count (1- count))
6248 )
6249 (vhdl-keep-region-active)
6250 foundp))
6251
8d422bd5 6252(defun vhdl-beginning-of-statement (&optional count lim interactive)
d2ddb974
KH
6253 "Go to the beginning of the innermost VHDL statement.
6254With prefix arg, go back N - 1 statements. If already at the
6255beginning of a statement then go to the beginning of the preceding
6256one. If within a string or comment, or next to a comment (only
6257whitespace between), move by sentences instead of statements.
6258
8d422bd5 6259When called from a program, this function takes 3 optional args: the
0a2e512a
RF
6260prefix arg, a buffer position limit which is the farthest back to
6261search, and an argument indicating an interactive call."
8d422bd5 6262 (interactive "p\np")
d2ddb974
KH
6263 (let ((count (or count 1))
6264 (case-fold-search t)
6265 (lim (or lim (point-min)))
6266 (here (point))
6267 state)
6268 (save-excursion
6269 (goto-char lim)
6270 (setq state (parse-partial-sexp (point) here nil nil)))
8d422bd5 6271 (if (and interactive
d2ddb974
KH
6272 (or (nth 3 state)
6273 (nth 4 state)
6274 (looking-at (concat "[ \t]*" comment-start-skip))))
6275 (forward-sentence (- count))
6276 (while (> count 0)
6277 (vhdl-beginning-of-statement-1 lim)
6278 (setq count (1- count))))
6279 ;; its possible we've been left up-buf of lim
6280 (goto-char (max (point) lim))
6281 )
6282 (vhdl-keep-region-active))
6283
6284(defconst vhdl-e-o-s-re
6285 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6286
6287(defun vhdl-end-of-statement ()
6288 "Very simple implementation."
6289 (interactive)
6290 (re-search-forward vhdl-e-o-s-re))
6291
6292(defconst vhdl-b-o-s-re
6293 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6294 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6295
6296(defun vhdl-beginning-of-statement-1 (&optional lim)
5eabfe72
KH
6297 "Move to the start of the current statement, or the previous
6298statement if already at the beginning of one."
d2ddb974
KH
6299 (let ((lim (or lim (point-min)))
6300 (here (point))
6301 (pos (point))
6302 donep)
6303 ;; go backwards one balanced expression, but be careful of
6304 ;; unbalanced paren being reached
6305 (if (not (vhdl-safe (progn (backward-sexp) t)))
6306 (progn
6307 (backward-up-list 1)
6308 (forward-char)
6309 (vhdl-forward-syntactic-ws here)
6310 (setq donep t)))
6311 (while (and (not donep)
6312 (not (bobp))
6313 ;; look backwards for a statement boundary
6314 (re-search-backward vhdl-b-o-s-re lim 'move))
6315 (if (or (= (preceding-char) ?_)
3dcb36b7 6316 (vhdl-in-literal))
d2ddb974
KH
6317 (backward-char)
6318 (cond
6319 ;; If we are looking at an open paren, then stop after it
6320 ((eq (following-char) ?\()
6321 (forward-char)
6322 (vhdl-forward-syntactic-ws here)
6323 (setq donep t))
6324 ;; If we are looking at a close paren, then skip it
6325 ((eq (following-char) ?\))
6326 (forward-char)
6327 (setq pos (point))
6328 (backward-sexp)
6329 (if (< (point) lim)
6330 (progn (goto-char pos)
6331 (vhdl-forward-syntactic-ws here)
6332 (setq donep t))))
6333 ;; If we are looking at a semicolon, then stop
6334 ((eq (following-char) ?\;)
6335 (progn
6336 (forward-char)
6337 (vhdl-forward-syntactic-ws here)
6338 (setq donep t)))
6339 ;; If we are looking at a "begin", then stop
6340 ((and (looking-at vhdl-begin-fwd-re)
6341 (/= (preceding-char) ?_)
6342 (vhdl-begin-p nil))
6343 ;; If it's a leader "begin", then find the
6344 ;; right place
6345 (if (looking-at vhdl-leader-re)
6346 (save-excursion
6347 ;; set a default stop point at the begin
6348 (setq pos (point))
6349 ;; is the start point inside the leader area ?
6350 (goto-char (vhdl-end-of-leader))
6351 (vhdl-forward-syntactic-ws here)
6352 (if (< (point) here)
6353 ;; start point was not inside leader area
6354 ;; set stop point at word after leader
6355 (setq pos (point))))
6356 (forward-word 1)
6357 (vhdl-forward-syntactic-ws here)
6358 (setq pos (point)))
6359 (goto-char pos)
6360 (setq donep t))
6361 ;; If we are looking at a "statement", then stop
6362 ((and (looking-at vhdl-statement-fwd-re)
6363 (/= (preceding-char) ?_)
6364 (vhdl-statement-p nil))
6365 (setq donep t))
6366 ;; If we are looking at a case alternative key, then stop
5eabfe72
KH
6367 ((and (looking-at vhdl-case-alternative-re)
6368 (vhdl-case-alternative-p lim))
d2ddb974
KH
6369 (save-excursion
6370 ;; set a default stop point at the when
6371 (setq pos (point))
6372 ;; is the start point inside the case alternative key ?
6373 (looking-at vhdl-case-alternative-re)
6374 (goto-char (match-end 0))
6375 (vhdl-forward-syntactic-ws here)
6376 (if (< (point) here)
6377 ;; start point was not inside the case alternative key
6378 ;; set stop point at word after case alternative keyleader
6379 (setq pos (point))))
6380 (goto-char pos)
6381 (setq donep t))
6382 ;; Bogus find, continue
6383 (t
6384 (backward-char)))))
6385 ))
6386
6387;; Defuns for calculating the current syntactic state:
6388
6389(defun vhdl-get-library-unit (bod placeholder)
a4c6cfad
JB
6390 "If there is an enclosing library unit at BOD, with its \"begin\"
6391keyword at PLACEHOLDER, then return the library unit type."
d2ddb974
KH
6392 (let ((here (vhdl-point 'bol)))
6393 (if (save-excursion
6394 (goto-char placeholder)
6395 (vhdl-safe (vhdl-forward-sexp 1 bod))
6396 (<= here (point)))
6397 (save-excursion
6398 (goto-char bod)
6399 (cond
6400 ((looking-at "e") 'entity)
6401 ((looking-at "a") 'architecture)
6402 ((looking-at "c") 'configuration)
6403 ((looking-at "p")
6404 (save-excursion
6405 (goto-char bod)
6406 (forward-sexp)
6407 (vhdl-forward-syntactic-ws here)
6408 (if (looking-at "body\\b[^_]")
6409 'package-body 'package))))))
6410 ))
6411
6412(defun vhdl-get-block-state (&optional lim)
5eabfe72 6413 "Finds and records all the closest opens.
a4c6cfad 6414LIM is the furthest back we need to search (it should be the
5eabfe72 6415previous libunit keyword)."
d2ddb974
KH
6416 (let ((here (point))
6417 (lim (or lim (point-min)))
6418 keyword sexp-start sexp-mid sexp-end
6419 preceding-sexp containing-sexp
6420 containing-begin containing-mid containing-paren)
6421 (save-excursion
6422 ;; Find the containing-paren, and use that as the limit
6423 (if (setq containing-paren
6424 (save-restriction
6425 (narrow-to-region lim (point))
6426 (vhdl-safe (scan-lists (point) -1 1))))
6427 (setq lim containing-paren))
6428 ;; Look backwards for "begin" and "end" keywords.
6429 (while (and (> (point) lim)
6430 (not containing-sexp))
6431 (setq keyword (vhdl-backward-to-block lim))
6432 (cond
6433 ((eq keyword 'begin)
6434 ;; Found a "begin" keyword
6435 (setq sexp-start (point))
6436 (setq sexp-mid (vhdl-corresponding-mid lim))
6437 (setq sexp-end (vhdl-safe
6438 (save-excursion
6439 (vhdl-forward-sexp 1 lim) (point))))
6440 (if (and sexp-end (<= sexp-end here))
6441 ;; we want to record this sexp, but we only want to
6442 ;; record the last-most of any of them before here
6443 (or preceding-sexp
6444 (setq preceding-sexp sexp-start))
6445 ;; we're contained in this sexp so put sexp-start on
6446 ;; front of list
6447 (setq containing-sexp sexp-start)
6448 (setq containing-mid sexp-mid)
6449 (setq containing-begin t)))
6450 ((eq keyword 'end)
6451 ;; Found an "end" keyword
6452 (forward-sexp)
6453 (setq sexp-end (point))
6454 (setq sexp-mid nil)
6455 (setq sexp-start
6456 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6457 (progn (backward-sexp) (point))))
6458 ;; we want to record this sexp, but we only want to
6459 ;; record the last-most of any of them before here
6460 (or preceding-sexp
6461 (setq preceding-sexp sexp-start)))
6462 )))
6463 ;; Check if the containing-paren should be the containing-sexp
6464 (if (and containing-paren
6465 (or (null containing-sexp)
6466 (< containing-sexp containing-paren)))
6467 (setq containing-sexp containing-paren
6468 preceding-sexp nil
6469 containing-begin nil
6470 containing-mid nil))
6471 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6472 ))
6473
6474
6475(defconst vhdl-s-c-a-re
6476 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6477
6478(defun vhdl-skip-case-alternative (&optional lim)
5eabfe72 6479 "Skip forward over case/when bodies, with optional maximal
a4c6cfad
JB
6480limit. If no next case alternative is found, nil is returned and
6481point is not moved."
d2ddb974
KH
6482 (let ((lim (or lim (point-max)))
6483 (here (point))
6484 donep foundp)
6485 (while (and (< (point) lim)
6486 (not donep))
6487 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6488 (save-match-data
6489 (not (vhdl-in-literal)))
6490 (/= (match-beginning 0) here))
6491 (progn
6492 (goto-char (match-beginning 0))
6493 (cond
6494 ((and (looking-at "case")
6495 (re-search-forward "\\bis[^_]" lim t))
6496 (backward-sexp)
6497 (vhdl-forward-sexp))
6498 (t
6499 (setq donep t
6500 foundp t))))))
6501 (if (not foundp)
6502 (goto-char here))
6503 foundp))
6504
6505(defun vhdl-backward-skip-label (&optional lim)
5eabfe72 6506 "Skip backward over a label, with optional maximal
a4c6cfad 6507limit. If label is not found, nil is returned and point
5eabfe72 6508is not moved."
d2ddb974
KH
6509 (let ((lim (or lim (point-min)))
6510 placeholder)
6511 (if (save-excursion
6512 (vhdl-backward-syntactic-ws lim)
6513 (and (eq (preceding-char) ?:)
6514 (progn
6515 (backward-sexp)
6516 (setq placeholder (point))
6517 (looking-at vhdl-label-key))))
6518 (goto-char placeholder))
6519 ))
6520
6521(defun vhdl-forward-skip-label (&optional lim)
5eabfe72
KH
6522 "Skip forward over a label, with optional maximal
6523limit. If label is not found, nil is returned and point
6524is not moved."
d2ddb974
KH
6525 (let ((lim (or lim (point-max))))
6526 (if (looking-at vhdl-label-key)
6527 (progn
6528 (goto-char (match-end 0))
6529 (vhdl-forward-syntactic-ws lim)))
6530 ))
6531
6532(defun vhdl-get-syntactic-context ()
5eabfe72 6533 "Guess the syntactic description of the current line of VHDL code."
d2ddb974
KH
6534 (save-excursion
6535 (save-restriction
6536 (beginning-of-line)
6537 (let* ((indent-point (point))
6538 (case-fold-search t)
6539 vec literal containing-sexp preceding-sexp
6540 containing-begin containing-mid containing-leader
6541 char-before-ip char-after-ip begin-after-ip end-after-ip
6542 placeholder lim library-unit
6543 )
6544
6545 ;; Reset the syntactic context
6546 (setq vhdl-syntactic-context nil)
6547
6548 (save-excursion
6549 ;; Move to the start of the previous library unit, and
6550 ;; record the position of the "begin" keyword.
6551 (setq placeholder (vhdl-beginning-of-libunit))
6552 ;; The position of the "libunit" keyword gives us a gross
6553 ;; limit point.
6554 (setq lim (point))
6555 )
6556
6557 ;; If there is a previous library unit, and we are enclosed by
6558 ;; it, then set the syntax accordingly.
6559 (and placeholder
6560 (setq library-unit (vhdl-get-library-unit lim placeholder))
6561 (vhdl-add-syntax library-unit lim))
6562
6563 ;; Find the surrounding state.
6564 (if (setq vec (vhdl-get-block-state lim))
6565 (progn
6566 (setq containing-sexp (aref vec 0))
6567 (setq preceding-sexp (aref vec 1))
6568 (setq containing-begin (aref vec 2))
6569 (setq containing-mid (aref vec 3))
6570 ))
6571
6572 ;; set the limit on the farthest back we need to search
6573 (setq lim (if containing-sexp
6574 (save-excursion
6575 (goto-char containing-sexp)
6576 ;; set containing-leader if required
6577 (if (looking-at vhdl-leader-re)
6578 (setq containing-leader (vhdl-end-of-leader)))
6579 (vhdl-point 'bol))
6580 (point-min)))
6581
6582 ;; cache char before and after indent point, and move point to
6583 ;; the most likely position to perform the majority of tests
6584 (goto-char indent-point)
6585 (skip-chars-forward " \t")
3dcb36b7 6586 (setq literal (vhdl-in-literal))
d2ddb974
KH
6587 (setq char-after-ip (following-char))
6588 (setq begin-after-ip (and
6589 (not literal)
6590 (looking-at vhdl-begin-fwd-re)
6591 (vhdl-begin-p)))
6592 (setq end-after-ip (and
6593 (not literal)
6594 (looking-at vhdl-end-fwd-re)
6595 (vhdl-end-p)))
6596 (vhdl-backward-syntactic-ws lim)
6597 (setq char-before-ip (preceding-char))
6598 (goto-char indent-point)
6599 (skip-chars-forward " \t")
6600
6601 ;; now figure out syntactic qualities of the current line
6602 (cond
6603 ;; CASE 1: in a string or comment.
6604 ((memq literal '(string comment))
6605 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6606 ;; CASE 2: Line is at top level.
6607 ((null containing-sexp)
6608 ;; Find the point to which indentation will be relative
6609 (save-excursion
6610 (if (null preceding-sexp)
6611 ;; CASE 2X.1
6612 ;; no preceding-sexp -> use the preceding statement
6613 (vhdl-beginning-of-statement-1 lim)
6614 ;; CASE 2X.2
6615 ;; if there is a preceding-sexp then indent relative to it
6616 (goto-char preceding-sexp)
6617 ;; if not at boi, then the block-opening keyword is
6618 ;; probably following a label, so we need a different
6619 ;; relpos
6620 (if (/= (point) (vhdl-point 'boi))
6621 ;; CASE 2X.3
6622 (vhdl-beginning-of-statement-1 lim)))
6623 ;; v-b-o-s could have left us at point-min
6624 (and (bobp)
6625 ;; CASE 2X.4
6626 (vhdl-forward-syntactic-ws indent-point))
6627 (setq placeholder (point)))
6628 (cond
6629 ;; CASE 2A : we are looking at a block-open
6630 (begin-after-ip
6631 (vhdl-add-syntax 'block-open placeholder))
6632 ;; CASE 2B: we are looking at a block-close
6633 (end-after-ip
6634 (vhdl-add-syntax 'block-close placeholder))
6635 ;; CASE 2C: we are looking at a top-level statement
6636 ((progn
6637 (vhdl-backward-syntactic-ws lim)
6638 (or (bobp)
6639 (= (preceding-char) ?\;)))
6640 (vhdl-add-syntax 'statement placeholder))
6641 ;; CASE 2D: we are looking at a top-level statement-cont
6642 (t
6643 (vhdl-beginning-of-statement-1 lim)
6644 ;; v-b-o-s could have left us at point-min
6645 (and (bobp)
6646 ;; CASE 2D.1
6647 (vhdl-forward-syntactic-ws indent-point))
6648 (vhdl-add-syntax 'statement-cont (point)))
6649 )) ; end CASE 2
6650 ;; CASE 3: line is inside parentheses. Most likely we are
6651 ;; either in a subprogram argument (interface) list, or a
6652 ;; continued expression containing parentheses.
6653 ((null containing-begin)
6654 (vhdl-backward-syntactic-ws containing-sexp)
6655 (cond
6656 ;; CASE 3A: we are looking at the arglist closing paren
6657 ((eq char-after-ip ?\))
6658 (goto-char containing-sexp)
6659 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6660 ;; CASE 3B: we are looking at the first argument in an empty
6661 ;; argument list.
6662 ((eq char-before-ip ?\()
6663 (goto-char containing-sexp)
6664 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6665 ;; CASE 3C: we are looking at an arglist continuation line,
6666 ;; but the preceding argument is on the same line as the
6667 ;; opening paren. This case includes multi-line
6668 ;; expression paren groupings.
6669 ((and (save-excursion
6670 (goto-char (1+ containing-sexp))
6671 (skip-chars-forward " \t")
6672 (not (eolp))
6673 (not (looking-at "--")))
6674 (save-excursion
6675 (vhdl-beginning-of-statement-1 containing-sexp)
6676 (skip-chars-backward " \t(")
6677 (<= (point) containing-sexp)))
6678 (goto-char containing-sexp)
6679 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6680 ;; CASE 3D: we are looking at just a normal arglist
6681 ;; continuation line
6682 (t (vhdl-beginning-of-statement-1 containing-sexp)
6683 (vhdl-forward-syntactic-ws indent-point)
6684 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6685 ))
6686 ;; CASE 4: A block mid open
6687 ((and begin-after-ip
6688 (looking-at containing-mid))
6689 (goto-char containing-sexp)
6690 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6691 (if (looking-at vhdl-trailer-re)
6692 ;; CASE 4.1
6693 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6694 (vhdl-backward-skip-label (vhdl-point 'boi))
6695 (vhdl-add-syntax 'block-open (point)))
6696 ;; CASE 5: block close brace
6697 (end-after-ip
6698 (goto-char containing-sexp)
6699 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6700 (if (looking-at vhdl-trailer-re)
6701 ;; CASE 5.1
6702 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6703 (vhdl-backward-skip-label (vhdl-point 'boi))
6704 (vhdl-add-syntax 'block-close (point)))
6705 ;; CASE 6: A continued statement
6706 ((and (/= char-before-ip ?\;)
6707 ;; check it's not a trailer begin keyword, or a begin
6708 ;; keyword immediately following a label.
6709 (not (and begin-after-ip
6710 (or (looking-at vhdl-trailer-re)
6711 (save-excursion
6712 (vhdl-backward-skip-label containing-sexp)))))
6713 ;; check it's not a statement keyword
6714 (not (and (looking-at vhdl-statement-fwd-re)
6715 (vhdl-statement-p)))
6716 ;; see if the b-o-s is before the indent point
6717 (> indent-point
6718 (save-excursion
6719 (vhdl-beginning-of-statement-1 containing-sexp)
6720 ;; If we ended up after a leader, then this will
6721 ;; move us forward to the start of the first
6722 ;; statement. Note that a containing sexp here is
6723 ;; always a keyword, not a paren, so this will
6724 ;; have no effect if we hit the containing-sexp.
6725 (vhdl-forward-syntactic-ws indent-point)
6726 (setq placeholder (point))))
6727 ;; check it's not a block-intro
6728 (/= placeholder containing-sexp)
6729 ;; check it's not a case block-intro
6730 (save-excursion
6731 (goto-char placeholder)
6732 (or (not (looking-at vhdl-case-alternative-re))
6733 (> (match-end 0) indent-point))))
6734 ;; Make placeholder skip a label, but only if it puts us
6735 ;; before the indent point at the start of a line.
6736 (let ((new placeholder))
6737 (if (and (> indent-point
6738 (save-excursion
6739 (goto-char placeholder)
6740 (vhdl-forward-skip-label indent-point)
6741 (setq new (point))))
6742 (save-excursion
6743 (goto-char new)
6744 (eq new (progn (back-to-indentation) (point)))))
6745 (setq placeholder new)))
6746 (vhdl-add-syntax 'statement-cont placeholder)
6747 (if begin-after-ip
6748 (vhdl-add-syntax 'block-open)))
6749 ;; Statement. But what kind?
6750 ;; CASE 7: A case alternative key
6751 ((and (looking-at vhdl-case-alternative-re)
6752 (vhdl-case-alternative-p containing-sexp))
6753 ;; for a case alternative key, we set relpos to the first
6754 ;; non-whitespace char on the line containing the "case"
6755 ;; keyword.
6756 (goto-char containing-sexp)
6757 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6758 (if (looking-at vhdl-trailer-re)
6759 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6760 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6761 ;; CASE 8: statement catchall
6762 (t
6763 ;; we know its a statement, but we need to find out if it is
6764 ;; the first statement in a block
6765 (if containing-leader
6766 (goto-char containing-leader)
6767 (goto-char containing-sexp)
6768 ;; Note that a containing sexp here is always a keyword,
6769 ;; not a paren, so skip over the keyword.
6770 (forward-sexp))
6771 ;; move to the start of the first statement
6772 (vhdl-forward-syntactic-ws indent-point)
6773 (setq placeholder (point))
6774 ;; we want to ignore case alternatives keys when skipping forward
6775 (let (incase-p)
6776 (while (looking-at vhdl-case-alternative-re)
6777 (setq incase-p (point))
6778 ;; we also want to skip over the body of the
6779 ;; case/when statement if that doesn't put us at
6780 ;; after the indent-point
6781 (while (vhdl-skip-case-alternative indent-point))
6782 ;; set up the match end
6783 (looking-at vhdl-case-alternative-re)
6784 (goto-char (match-end 0))
6785 ;; move to the start of the first case alternative statement
6786 (vhdl-forward-syntactic-ws indent-point)
6787 (setq placeholder (point)))
6788 (cond
6789 ;; CASE 8A: we saw a case/when statement so we must be
6790 ;; in a switch statement. find out if we are at the
6791 ;; statement just after a case alternative key
6792 ((and incase-p
6793 (= (point) indent-point))
6794 ;; relpos is the "when" keyword
6795 (vhdl-add-syntax 'statement-case-intro incase-p))
6796 ;; CASE 8B: any old statement
6797 ((< (point) indent-point)
6798 ;; relpos is the first statement of the block
6799 (vhdl-add-syntax 'statement placeholder)
6800 (if begin-after-ip
6801 (vhdl-add-syntax 'block-open)))
6802 ;; CASE 8C: first statement in a block
6803 (t
6804 (goto-char containing-sexp)
6805 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6806 (if (looking-at vhdl-trailer-re)
6807 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6808 (vhdl-backward-skip-label (vhdl-point 'boi))
6809 (vhdl-add-syntax 'statement-block-intro (point))
6810 (if begin-after-ip
6811 (vhdl-add-syntax 'block-open)))
6812 )))
6813 )
6814
6815 ;; now we need to look at any modifiers
6816 (goto-char indent-point)
6817 (skip-chars-forward " \t")
6818 (if (looking-at "--")
6819 (vhdl-add-syntax 'comment))
0a2e512a
RF
6820 (if (eq literal 'pound)
6821 (vhdl-add-syntax 'cpp-macro))
d2ddb974
KH
6822 ;; return the syntax
6823 vhdl-syntactic-context))))
6824
6825;; Standard indentation line-ups:
6826
6827(defun vhdl-lineup-arglist (langelem)
5eabfe72
KH
6828 "Lineup the current arglist line with the arglist appearing just
6829after the containing paren which starts the arglist."
d2ddb974
KH
6830 (save-excursion
6831 (let* ((containing-sexp
6832 (save-excursion
6833 ;; arglist-cont-nonempty gives relpos ==
6834 ;; to boi of containing-sexp paren. This
6835 ;; is good when offset is +, but bad
6836 ;; when it is vhdl-lineup-arglist, so we
6837 ;; have to special case a kludge here.
6838 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6839 (progn
6840 (beginning-of-line)
6841 (backward-up-list 1)
6842 (skip-chars-forward " \t" (vhdl-point 'eol)))
6843 (goto-char (cdr langelem)))
6844 (point)))
6845 (cs-curcol (save-excursion
6846 (goto-char (cdr langelem))
6847 (current-column))))
6848 (if (save-excursion
6849 (beginning-of-line)
6850 (looking-at "[ \t]*)"))
6851 (progn (goto-char (match-end 0))
6852 (backward-sexp)
6853 (forward-char)
6854 (vhdl-forward-syntactic-ws)
6855 (- (current-column) cs-curcol))
6856 (goto-char containing-sexp)
6857 (or (eolp)
6858 (let ((eol (vhdl-point 'eol))
6859 (here (progn
6860 (forward-char)
6861 (skip-chars-forward " \t")
6862 (point))))
6863 (vhdl-forward-syntactic-ws)
6864 (if (< (point) eol)
6865 (goto-char here))))
6866 (- (current-column) cs-curcol)
6867 ))))
6868
6869(defun vhdl-lineup-arglist-intro (langelem)
5eabfe72 6870 "Lineup an arglist-intro line to just after the open paren."
d2ddb974
KH
6871 (save-excursion
6872 (let ((cs-curcol (save-excursion
6873 (goto-char (cdr langelem))
6874 (current-column)))
6875 (ce-curcol (save-excursion
6876 (beginning-of-line)
6877 (backward-up-list 1)
6878 (skip-chars-forward " \t" (vhdl-point 'eol))
6879 (current-column))))
6880 (- ce-curcol cs-curcol -1))))
6881
6882(defun vhdl-lineup-comment (langelem)
5eabfe72
KH
6883 "Support old behavior for comment indentation. We look at
6884vhdl-comment-only-line-offset to decide how to indent comment
6885only-lines."
d2ddb974
KH
6886 (save-excursion
6887 (back-to-indentation)
6888 ;; at or to the right of comment-column
6889 (if (>= (current-column) comment-column)
6890 (vhdl-comment-indent)
6891 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6892 (if (not (bolp))
6893 (or (car-safe vhdl-comment-only-line-offset)
6894 vhdl-comment-only-line-offset)
6895 (or (cdr-safe vhdl-comment-only-line-offset)
6896 (car-safe vhdl-comment-only-line-offset)
0a2e512a 6897 -1000 ;jam it against the left side
d2ddb974
KH
6898 )))))
6899
6900(defun vhdl-lineup-statement-cont (langelem)
5eabfe72 6901 "Line up statement-cont after the assignment operator."
d2ddb974
KH
6902 (save-excursion
6903 (let* ((relpos (cdr langelem))
6904 (assignp (save-excursion
6905 (goto-char (vhdl-point 'boi))
6906 (and (re-search-forward "\\(<\\|:\\)="
6907 (vhdl-point 'eol) t)
6908 (- (point) (vhdl-point 'boi)))))
6909 (curcol (progn
6910 (goto-char relpos)
6911 (current-column)))
6912 foundp)
6913 (while (and (not foundp)
6914 (< (point) (vhdl-point 'eol)))
6915 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
3dcb36b7 6916 (if (vhdl-in-literal)
d2ddb974
KH
6917 (forward-char)
6918 (if (= (preceding-char) ?\()
6919 ;; skip over any parenthesized expressions
6920 (goto-char (min (vhdl-point 'eol)
6921 (scan-lists (point) 1 1)))
6922 ;; found an assignment operator (not at eol)
6923 (setq foundp (not (looking-at "\\s-*$"))))))
6924 (if (not foundp)
6925 ;; there's no assignment operator on the line
6926 vhdl-basic-offset
6927 ;; calculate indentation column after assign and ws, unless
6928 ;; our line contains an assignment operator
6929 (if (not assignp)
6930 (progn
6931 (forward-char)
6932 (skip-chars-forward " \t")
6933 (setq assignp 0)))
6934 (- (current-column) assignp curcol))
6935 )))
6936
5eabfe72 6937;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 6938;; Progress reporting
d2ddb974 6939
3dcb36b7
JB
6940(defvar vhdl-progress-info nil
6941 "Array variable for progress information: 0 begin, 1 end, 2 time.")
5eabfe72 6942
3dcb36b7
JB
6943(defun vhdl-update-progress-info (string pos)
6944 "Update progress information."
6945 (when (and vhdl-progress-info (not noninteractive)
6946 (< vhdl-progress-interval
6947 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
b0cf7916
JB
6948 (let ((delta (- (aref vhdl-progress-info 1)
6949 (aref vhdl-progress-info 0))))
6950 (if (= 0 delta)
6951 (message (concat string "... (100%s)") "%")
6952 (message (concat string "... (%2d%s)")
6953 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6954 delta) "%")))
3dcb36b7 6955 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
5eabfe72 6956
3dcb36b7
JB
6957;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6958;; Indentation commands
5eabfe72
KH
6959
6960(defun vhdl-electric-tab (&optional prefix-arg)
6961 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7
JB
6962else if right of non whitespace on line then insert tab,
6963else if last command was a tab or return then dedent one step or if a comment
6964toggle between normal indent and inline comment indent,
d2ddb974
KH
6965else indent `correctly'."
6966 (interactive "*P")
3dcb36b7
JB
6967 (vhdl-prepare-search-2
6968 (cond
75e0af77
DN
6969 ;; indent region if region is active
6970 ((and (not (featurep 'xemacs)) (use-region-p))
6971 (vhdl-indent-region (region-beginning) (region-end) nil))
3dcb36b7
JB
6972 ;; expand word
6973 ((= (char-syntax (preceding-char)) ?w)
6974 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6975 (case-replace nil)
6976 (hippie-expand-only-buffers
6977 (or (and (boundp 'hippie-expand-only-buffers)
6978 hippie-expand-only-buffers)
6979 '(vhdl-mode))))
6980 (vhdl-expand-abbrev prefix-arg)))
6981 ;; expand parenthesis
6982 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6983 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6984 (case-replace nil))
6985 (vhdl-expand-paren prefix-arg)))
6986 ;; insert tab
6987 ((> (current-column) (current-indentation))
6988 (insert-tab))
6989 ;; toggle comment indent
6990 ((and (looking-at "--")
6991 (or (eq last-command 'vhdl-electric-tab)
6992 (eq last-command 'vhdl-electric-return)))
6993 (cond ((= (current-indentation) 0) ; no indent
6994 (indent-to 1)
6995 (indent-according-to-mode))
6996 ((< (current-indentation) comment-column) ; normal indent
6997 (indent-to comment-column)
6998 (indent-according-to-mode))
6999 (t ; inline comment indent
453cfeb3 7000 (delete-region (line-beginning-position) (point)))))
3dcb36b7
JB
7001 ;; dedent
7002 ((and (>= (current-indentation) vhdl-basic-offset)
7003 (or (eq last-command 'vhdl-electric-tab)
7004 (eq last-command 'vhdl-electric-return)))
7005 (backward-delete-char-untabify vhdl-basic-offset nil))
7006 ;; indent line
7007 (t (indent-according-to-mode)))
5eabfe72
KH
7008 (setq this-command 'vhdl-electric-tab)))
7009
7010(defun vhdl-electric-return ()
d2ddb974
KH
7011 "newline-and-indent or indent-new-comment-line if in comment and preceding
7012character is a space."
7013 (interactive)
7014 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7015 (indent-new-comment-line)
3dcb36b7
JB
7016 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7017 (vhdl-fix-case-word -1))
5eabfe72
KH
7018 (newline-and-indent)))
7019
d2ddb974 7020(defun vhdl-indent-line ()
5eabfe72 7021 "Indent the current line as VHDL code. Returns the amount of
d2ddb974
KH
7022indentation change."
7023 (interactive)
3dcb36b7 7024 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
d2ddb974 7025 (pos (- (point-max) (point)))
3dcb36b7
JB
7026 (indent
7027 (if syntax
7028 ;; indent syntax-based
7029 (if (and (eq (caar syntax) 'comment)
7030 (>= (vhdl-get-offset (car syntax)) comment-column))
7031 ;; special case: comments at or right of comment-column
7032 (vhdl-get-offset (car syntax))
7033 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7034 ;; indent like previous nonblank line
7035 (save-excursion (beginning-of-line)
7036 (re-search-backward "^[^\n]" nil t)
7037 (current-indentation))))
5eabfe72 7038 (shift-amt (- indent (current-indentation))))
d2ddb974
KH
7039 (and vhdl-echo-syntactic-information-p
7040 (message "syntax: %s, indent= %d" syntax indent))
5eabfe72 7041 (unless (zerop shift-amt)
d2ddb974
KH
7042 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7043 (beginning-of-line)
7044 (indent-to indent))
7045 (if (< (point) (vhdl-point 'boi))
7046 (back-to-indentation)
7047 ;; If initial point was within line's indentation, position after
7048 ;; the indentation. Else stay at same point in text.
5eabfe72
KH
7049 (when (> (- (point-max) pos) (point))
7050 (goto-char (- (point-max) pos))))
d2ddb974 7051 (run-hooks 'vhdl-special-indent-hook)
3dcb36b7 7052 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
d2ddb974
KH
7053 shift-amt))
7054
3dcb36b7 7055(defun vhdl-indent-region (beg end column)
5eabfe72
KH
7056 "Indent region as VHDL code.
7057Adds progress reporting to `indent-region'."
7058 (interactive "r\nP")
3dcb36b7
JB
7059 (when vhdl-progress-interval
7060 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7061 (count-lines (point-min) end) 0)))
7062 (indent-region beg end column)
5eabfe72
KH
7063 (when vhdl-progress-interval (message "Indenting...done"))
7064 (setq vhdl-progress-info nil))
d2ddb974 7065
3dcb36b7
JB
7066(defun vhdl-indent-buffer ()
7067 "Indent whole buffer as VHDL code.
7068Calls `indent-region' for whole buffer and adds progress reporting."
7069 (interactive)
7070 (vhdl-indent-region (point-min) (point-max) nil))
7071
7072(defun vhdl-indent-group ()
7073 "Indent group of lines between empty lines."
7074 (interactive)
7075 (let ((beg (save-excursion
7076 (if (re-search-backward vhdl-align-group-separate nil t)
7077 (point-marker)
7078 (point-min-marker))))
7079 (end (save-excursion
7080 (if (re-search-forward vhdl-align-group-separate nil t)
7081 (point-marker)
7082 (point-max-marker)))))
7083 (vhdl-indent-region beg end nil)))
7084
d2ddb974
KH
7085(defun vhdl-indent-sexp (&optional endpos)
7086 "Indent each line of the list starting just after point.
7087If optional arg ENDPOS is given, indent each line, stopping when
7088ENDPOS is encountered."
7089 (interactive)
7090 (save-excursion
7091 (let ((beg (point))
5eabfe72 7092 (end (progn (vhdl-forward-sexp nil endpos) (point))))
d2ddb974
KH
7093 (indent-region beg end nil))))
7094
5eabfe72 7095;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
7096;; Miscellaneous commands
7097
7098(defun vhdl-show-syntactic-information ()
7099 "Show syntactic information for current line."
7100 (interactive)
3dcb36b7 7101 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
d2ddb974
KH
7102 (vhdl-keep-region-active))
7103
7104;; Verification and regression functions:
7105
7106(defun vhdl-regress-line (&optional arg)
7107 "Check syntactic information for current line."
7108 (interactive "P")
7109 (let ((expected (save-excursion
7110 (end-of-line)
5eabfe72
KH
7111 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7112 (forward-char 4)
7113 (read (current-buffer)))))
d2ddb974
KH
7114 (actual (vhdl-get-syntactic-context))
7115 (expurgated))
7116 ;; remove the library unit symbols
51b5ad57 7117 (mapc
d2ddb974
KH
7118 (function
7119 (lambda (elt)
7120 (if (memq (car elt) '(entity configuration package
7121 package-body architecture))
7122 nil
7123 (setq expurgated (append expurgated (list elt))))))
7124 actual)
7125 (if (and (not arg) expected (listp expected))
7126 (if (not (equal expected expurgated))
3dcb36b7 7127 (error "ERROR: Should be: %s, is: %s" expected expurgated))
d2ddb974
KH
7128 (save-excursion
7129 (beginning-of-line)
5eabfe72
KH
7130 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7131 (end-of-line)
7132 (if (search-backward " -- ((" (vhdl-point 'bol) t)
453cfeb3 7133 (delete-region (point) (line-end-position)))
5eabfe72
KH
7134 (insert " -- ")
7135 (insert (format "%s" expurgated))))))
d2ddb974
KH
7136 (vhdl-keep-region-active))
7137
7138
5eabfe72
KH
7139;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7140;;; Alignment, whitespace fixup, beautifying
7141;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7142
3dcb36b7 7143(defconst vhdl-align-alist
d2ddb974
KH
7144 '(
7145 ;; after some keywords
3dcb36b7
JB
7146 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7147 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
d2ddb974 7148 ;; before ':'
5eabfe72 7149 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
d2ddb974 7150 ;; after direction specifications
5eabfe72
KH
7151 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7152 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7153 ;; before "==", ":=", "=>", and "<="
3dcb36b7 7154 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
5eabfe72 7155 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
3dcb36b7 7156 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
d2ddb974
KH
7157 ;; before some keywords
7158 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
d2ddb974
KH
7159 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7160 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
3dcb36b7
JB
7161 ;; before "=>" since "when/else ... =>" can occur
7162 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
d2ddb974 7163 )
5eabfe72 7164 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
d2ddb974
KH
7165It is searched in order. If REGEXP is found anywhere in the first
7166line of a region to be aligned, ALIGN-PATTERN will be used for that
7167region. ALIGN-PATTERN must include the whitespace to be expanded or
5eabfe72
KH
7168contracted. It may also provide regexps for the text surrounding the
7169whitespace. SUBEXP specifies which sub-expression of
d2ddb974
KH
7170ALIGN-PATTERN matches the white space to be expanded/contracted.")
7171
3dcb36b7
JB
7172;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7173;; Align code
7174
d2ddb974
KH
7175(defvar vhdl-align-try-all-clauses t
7176 "If REGEXP is not found on the first line of the region that clause
5eabfe72 7177is ignored. If this variable is non-nil, then the clause is tried anyway.")
d2ddb974 7178
3dcb36b7
JB
7179(defun vhdl-do-group (function &optional spacing)
7180 "Apply FUNCTION on group of lines between empty lines."
7181 (let
7182 ;; search for group beginning
7183 ((beg (save-excursion
7184 (if (re-search-backward vhdl-align-group-separate nil t)
7185 (progn (beginning-of-line 2) (back-to-indentation) (point))
7186 (point-min))))
7187 ;; search for group end
7188 (end (save-excursion
7189 (if (re-search-forward vhdl-align-group-separate nil t)
7190 (progn (beginning-of-line) (point))
7191 (point-max)))))
7192 ;; run FUNCTION
7193 (funcall function beg end spacing)))
7194
7195(defun vhdl-do-list (function &optional spacing)
7196 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7197parentheses."
7198 (let (beg end)
7199 (save-excursion
7200 ;; search for beginning of balanced group of parentheses
7201 (setq beg (vhdl-re-search-backward "[()]" nil t))
7202 (while (looking-at ")")
7203 (forward-char) (backward-sexp)
7204 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7205 ;; search for end of balanced group of parentheses
7206 (when beg
7207 (forward-list)
7208 (setq end (point))
7209 (goto-char (1+ beg))
7210 (skip-chars-forward " \t\n")
7211 (setq beg (point))))
7212 ;; run FUNCTION
7213 (if beg
7214 (funcall function beg end spacing)
7215 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7216
7217(defun vhdl-do-same-indent (function &optional spacing)
7218 "Apply FUNCTION to block of lines with same indent."
7219 (let ((indent (current-indentation))
7220 beg end)
7221 ;; search for first line with same indent
7222 (save-excursion
7223 (while (and (not (bobp))
7224 (or (looking-at "^\\s-*\\(--.*\\)?$")
7225 (= (current-indentation) indent)))
7226 (unless (looking-at "^\\s-*$")
7227 (back-to-indentation) (setq beg (point)))
7228 (beginning-of-line -0)))
7229 ;; search for last line with same indent
7230 (save-excursion
7231 (while (and (not (eobp))
7232 (or (looking-at "^\\s-*\\(--.*\\)?$")
7233 (= (current-indentation) indent)))
7234 (if (looking-at "^\\s-*$")
7235 (beginning-of-line 2)
7236 (beginning-of-line 2)
7237 (setq end (point)))))
7238 ;; run FUNCTION
7239 (funcall function beg end spacing)))
7240
7241(defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
d2ddb974 7242 "Attempt to align a range of lines based on the content of the
5eabfe72
KH
7243lines. The definition of `alignment-list' determines the matching
7244order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7245is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
d2ddb974
KH
7246indentation is done before aligning."
7247 (interactive "r\np")
5eabfe72
KH
7248 (setq alignment-list (or alignment-list vhdl-align-alist))
7249 (setq spacing (or spacing 1))
d2ddb974
KH
7250 (save-excursion
7251 (let (bol indent)
7252 (goto-char end)
7253 (setq end (point-marker))
7254 (goto-char begin)
5eabfe72 7255 (setq bol (setq begin (progn (beginning-of-line) (point))))
3dcb36b7 7256; (untabify bol end)
5eabfe72
KH
7257 (when indent
7258 (indent-region bol end nil))))
3dcb36b7
JB
7259 (let ((copy (copy-alist alignment-list)))
7260 (vhdl-prepare-search-2
5eabfe72
KH
7261 (while copy
7262 (save-excursion
7263 (goto-char begin)
7264 (let (element
7265 (eol (save-excursion (progn (end-of-line) (point)))))
7266 (setq element (nth 0 copy))
7267 (when (and (or (and (listp (car element))
7268 (memq major-mode (car element)))
7269 (eq major-mode (car element)))
7270 (or vhdl-align-try-all-clauses
7271 (re-search-forward (car (cdr element)) eol t)))
3dcb36b7 7272 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
5eabfe72
KH
7273 (car (cdr (cdr (cdr element)))) spacing))
7274 (setq copy (cdr copy))))))))
7275
3dcb36b7 7276(defun vhdl-align-region-2 (begin end match &optional substr spacing)
d2ddb974 7277 "Align a range of lines from BEGIN to END. The regular expression
a4c6cfad 7278MATCH must match exactly one field: the whitespace to be
d2ddb974 7279contracted/expanded. The alignment column will equal the
a4c6cfad 7280rightmost column of the widest whitespace block. SPACING is
d2ddb974
KH
7281the amount of extra spaces to add to the calculated maximum required.
7282SPACING defaults to 1 so that at least one space is inserted after
7283the token in MATCH."
5eabfe72
KH
7284 (setq spacing (or spacing 1))
7285 (setq substr (or substr 1))
d2ddb974
KH
7286 (save-excursion
7287 (let (distance (max 0) (lines 0) bol eol width)
7288 ;; Determine the greatest whitespace distance to the alignment
7289 ;; character
7290 (goto-char begin)
7291 (setq eol (progn (end-of-line) (point))
5eabfe72 7292 bol (setq begin (progn (beginning-of-line) (point))))
d2ddb974 7293 (while (< bol end)
5eabfe72
KH
7294 (save-excursion
7295 (when (and (re-search-forward match eol t)
3dcb36b7 7296 (not (vhdl-in-literal)))
5eabfe72
KH
7297 (setq distance (- (match-beginning substr) bol))
7298 (when (> distance max)
7299 (setq max distance))))
7300 (forward-line)
7301 (setq bol (point)
7302 eol (save-excursion (end-of-line) (point)))
7303 (setq lines (1+ lines)))
d2ddb974
KH
7304 ;; Now insert enough maxs to push each assignment operator to
7305 ;; the same column. We need to use 'lines' as a counter, since
7306 ;; the location of the mark may change
7307 (goto-char (setq bol begin))
5eabfe72 7308 (setq eol (save-excursion (end-of-line) (point)))
d2ddb974 7309 (while (> lines 0)
5eabfe72 7310 (when (and (re-search-forward match eol t)
3dcb36b7 7311 (not (vhdl-in-literal)))
5eabfe72
KH
7312 (setq width (- (match-end substr) (match-beginning substr)))
7313 (setq distance (- (match-beginning substr) bol))
7314 (goto-char (match-beginning substr))
7315 (delete-char width)
7316 (insert-char ? (+ (- max distance) spacing)))
7317 (beginning-of-line)
7318 (forward-line)
7319 (setq bol (point)
7320 eol (save-excursion (end-of-line) (point)))
7321 (setq lines (1- lines))))))
7322
3dcb36b7
JB
7323(defun vhdl-align-region-groups (beg end &optional spacing
7324 no-message no-comments)
7325 "Align region, treat groups of lines separately."
d2ddb974 7326 (interactive "r\nP")
5eabfe72 7327 (save-excursion
3dcb36b7 7328 (let (orig pos)
5eabfe72
KH
7329 (goto-char beg)
7330 (beginning-of-line)
3dcb36b7 7331 (setq orig (point-marker))
5eabfe72
KH
7332 (setq beg (point))
7333 (goto-char end)
7334 (setq end (point-marker))
7335 (untabify beg end)
3dcb36b7
JB
7336 (unless no-message
7337 (when vhdl-progress-interval
7338 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7339 (count-lines (point-min) end) 0))))
5eabfe72
KH
7340 (vhdl-fixup-whitespace-region beg end t)
7341 (goto-char beg)
7342 (if (not vhdl-align-groups)
7343 ;; align entire region
3dcb36b7
JB
7344 (progn (vhdl-align-region-1 beg end spacing)
7345 (unless no-comments
7346 (vhdl-align-inline-comment-region-1 beg end)))
5eabfe72
KH
7347 ;; align groups
7348 (while (and (< beg end)
3dcb36b7 7349 (re-search-forward vhdl-align-group-separate end t))
5eabfe72 7350 (setq pos (point-marker))
3dcb36b7
JB
7351 (vhdl-align-region-1 beg pos spacing)
7352 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7353 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
5eabfe72
KH
7354 (setq beg (1+ pos))
7355 (goto-char beg))
7356 ;; align last group
7357 (when (< beg end)
3dcb36b7
JB
7358 (vhdl-align-region-1 beg end spacing)
7359 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7360 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7361 (when vhdl-indent-tabs-mode
7362 (tabify orig end))
7363 (unless no-message
7364 (when vhdl-progress-interval (message "Aligning...done"))
7365 (setq vhdl-progress-info nil)))))
7366
7367(defun vhdl-align-region (beg end &optional spacing)
7368 "Align region, treat blocks with same indent and argument lists separately."
7369 (interactive "r\nP")
7370 (if (not vhdl-align-same-indent)
7371 ;; align entire region
7372 (vhdl-align-region-groups beg end spacing)
7373 ;; align blocks with same indent and argument lists
7374 (save-excursion
7375 (let ((cur-beg beg)
7376 indent cur-end)
7377 (when vhdl-progress-interval
7378 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7379 (count-lines (point-min) end) 0)))
7380 (goto-char end)
7381 (setq end (point-marker))
7382 (goto-char cur-beg)
7383 (while (< (point) end)
7384 ;; is argument list opening?
7385 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7386 (point) (vhdl-point 'eol)))))
7387 ;; determine region for argument list
7388 (progn (goto-char cur-beg)
7389 (forward-sexp)
7390 (setq cur-end (point))
7391 (beginning-of-line 2))
7392 ;; determine region with same indent
7393 (setq indent (current-indentation))
7394 (setq cur-beg (point))
7395 (setq cur-end (vhdl-point 'bonl))
7396 (beginning-of-line 2)
7397 (while (and (< (point) end)
7398 (or (looking-at "^\\s-*\\(--.*\\)?$")
7399 (= (current-indentation) indent))
7400 (<= (save-excursion
7401 (nth 0 (parse-partial-sexp
7402 (point) (vhdl-point 'eol)))) 0))
7403 (unless (looking-at "^\\s-*$")
7404 (setq cur-end (vhdl-point 'bonl)))
7405 (beginning-of-line 2)))
7406 ;; align region
7407 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7408 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7409 (when vhdl-progress-interval (message "Aligning...done"))
7410 (setq vhdl-progress-info nil)))))
5eabfe72
KH
7411
7412(defun vhdl-align-group (&optional spacing)
7413 "Align group of lines between empty lines."
7414 (interactive)
3dcb36b7 7415 (vhdl-do-group 'vhdl-align-region spacing))
5eabfe72 7416
3dcb36b7
JB
7417(defun vhdl-align-list (&optional spacing)
7418 "Align the lines of a list surrounded by a balanced group of parentheses."
5eabfe72 7419 (interactive)
3dcb36b7
JB
7420 (vhdl-do-list 'vhdl-align-region-groups spacing))
7421
7422(defun vhdl-align-same-indent (&optional spacing)
7423 "Align block of lines with same indent."
7424 (interactive)
7425 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7426
7427(defun vhdl-align-declarations (&optional spacing)
7428 "Align the lines within the declarative part of a design unit."
7429 (interactive)
7430 (let (beg end)
7431 (vhdl-prepare-search-2
7432 (save-excursion
7433 ;; search for declarative part
7434 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7435 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7436 (setq beg (point))
7437 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7438 (setq end (point)))))
7439 (if beg
7440 (vhdl-align-region-groups beg end spacing)
7441 (error "ERROR: Not within the declarative part of a design unit"))))
7442
7443(defun vhdl-align-buffer ()
7444 "Align buffer."
7445 (interactive)
7446 (vhdl-align-region (point-min) (point-max)))
7447
7448;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7449;; Align inline comments
7450
7451(defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7452 "Align inline comments in region."
7453 (save-excursion
7454 (let ((start-max comment-column)
7455 (length-max 0)
7456 comment-list start-list tmp-list start length
7457 cur-start prev-start no-code)
7458 (setq spacing (or spacing 2))
7459 (vhdl-prepare-search-2
7460 (goto-char beg)
7461 ;; search for comment start positions and lengths
7462 (while (< (point) end)
7463 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7464 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7465 (not (save-excursion (goto-char (match-beginning 2))
7466 (vhdl-in-literal))))
7467 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7468 (setq length (- (match-end 2) (match-beginning 2)))
7469 (setq start-max (max start start-max))
7470 (setq length-max (max length length-max))
7471 (setq comment-list (cons (cons start length) comment-list)))
7472 (beginning-of-line 2))
7473 (setq comment-list
7474 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7475 ;; reduce start positions
7476 (setq start-list (list (caar comment-list)))
7477 (setq comment-list (cdr comment-list))
7478 (while comment-list
7479 (unless (or (= (caar comment-list) (car start-list))
7480 (<= (+ (car start-list) (cdar comment-list))
7481 end-comment-column))
7482 (setq start-list (cons (caar comment-list) start-list)))
7483 (setq comment-list (cdr comment-list)))
7484 ;; align lines as nicely as possible
7485 (goto-char beg)
7486 (while (< (point) end)
7487 (setq cur-start nil)
7488 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7489 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7490 (not (save-excursion
7491 (goto-char (match-beginning 3))
7492 (vhdl-in-literal))))
7493 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7494 (>= (- (match-end 2) (match-beginning 2))
7495 comment-column))))
7496 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7497 (setq length (- (match-end 3) (match-beginning 3)))
7498 (setq no-code (= (match-beginning 1) (match-end 1)))
7499 ;; insert minimum whitespace
7500 (goto-char (match-end 2))
7501 (delete-region (match-beginning 2) (match-end 2))
7502 (insert-char ?\ spacing)
7503 (setq tmp-list start-list)
7504 ;; insert additional whitespace to align
7505 (setq cur-start
7506 (cond
7507 ;; align comment-only line to inline comment of previous line
7508 ((and no-code prev-start
7509 (<= length (- end-comment-column prev-start)))
7510 prev-start)
7511 ;; align all comments at `start-max' if this is possible
7512 ((<= (+ start-max length-max) end-comment-column)
7513 start-max)
7514 ;; align at `comment-column' if possible
7515 ((and (<= start comment-column)
7516 (<= length (- end-comment-column comment-column)))
7517 comment-column)
7518 ;; align at left-most possible start position otherwise
7519 (t
7520 (while (and tmp-list (< (car tmp-list) start))
7521 (setq tmp-list (cdr tmp-list)))
7522 (car tmp-list))))
7523 (indent-to cur-start))
7524 (setq prev-start cur-start)
7525 (beginning-of-line 2))))))
d2ddb974 7526
5eabfe72
KH
7527(defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7528 "Align inline comments within a region. Groups of code lines separated by
7529empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
d2ddb974 7530 (interactive "r\nP")
5eabfe72 7531 (save-excursion
3dcb36b7 7532 (let (orig pos)
5eabfe72
KH
7533 (goto-char beg)
7534 (beginning-of-line)
3dcb36b7 7535 (setq orig (point-marker))
5eabfe72
KH
7536 (setq beg (point))
7537 (goto-char end)
7538 (setq end (point-marker))
7539 (untabify beg end)
7540 (unless no-message (message "Aligning inline comments..."))
7541 (goto-char beg)
7542 (if (not vhdl-align-groups)
7543 ;; align entire region
7544 (vhdl-align-inline-comment-region-1 beg end spacing)
7545 ;; align groups
3dcb36b7
JB
7546 (while (and (< beg end)
7547 (re-search-forward vhdl-align-group-separate end t))
5eabfe72
KH
7548 (setq pos (point-marker))
7549 (vhdl-align-inline-comment-region-1 beg pos spacing)
7550 (setq beg (1+ pos))
7551 (goto-char beg))
7552 ;; align last group
7553 (when (< beg end)
3dcb36b7
JB
7554 (vhdl-align-inline-comment-region-1 beg end spacing)))
7555 (when vhdl-indent-tabs-mode
7556 (tabify orig end))
7557 (unless no-message (message "Aligning inline comments...done")))))
5eabfe72
KH
7558
7559(defun vhdl-align-inline-comment-group (&optional spacing)
7560 "Align inline comments within a group of lines between empty lines."
7561 (interactive)
7562 (save-excursion
7563 (let ((start (point))
7564 beg end)
3dcb36b7 7565 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
5eabfe72
KH
7566 (point-marker) (point-max)))
7567 (goto-char start)
3dcb36b7
JB
7568 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7569 (point) (point-min)))
5eabfe72
KH
7570 (untabify beg end)
7571 (message "Aligning inline comments...")
7572 (vhdl-align-inline-comment-region-1 beg end)
3dcb36b7
JB
7573 (when vhdl-indent-tabs-mode
7574 (tabify beg end))
5eabfe72
KH
7575 (message "Aligning inline comments...done"))))
7576
7577(defun vhdl-align-inline-comment-buffer ()
7578 "Align inline comments within buffer. Groups of code lines separated by
7579empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7580 (interactive)
7581 (vhdl-align-inline-comment-region (point-min) (point-max)))
7582
3dcb36b7
JB
7583;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7584;; Fixup whitespace
7585
5eabfe72
KH
7586(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7587 "Fixup whitespace in region. Surround operator symbols by one space,
7588eliminate multiple spaces (except at beginning of line), eliminate spaces at
3dcb36b7 7589end of line, do nothing in comments and strings."
5eabfe72
KH
7590 (interactive "r")
7591 (unless no-message (message "Fixing up whitespace..."))
7592 (save-excursion
7593 (goto-char end)
7594 (setq end (point-marker))
5eabfe72
KH
7595 ;; have no space before and one space after `,' and ';'
7596 (goto-char beg)
0a2e512a 7597 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
3dcb36b7
JB
7598 (if (match-string 1)
7599 (goto-char (match-end 1))
7600 (replace-match "\\3 " nil nil nil 3)))
7601 ;; have no space after `('
7602 (goto-char beg)
0a2e512a 7603 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
3dcb36b7
JB
7604 (if (match-string 1)
7605 (goto-char (match-end 1))
7606 (replace-match "\\2")))
7607 ;; have no space before `)'
7608 (goto-char beg)
0a2e512a 7609 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
3dcb36b7
JB
7610 (if (match-string 1)
7611 (goto-char (match-end 1))
7612 (replace-match "\\2")))
7613 ;; surround operator symbols by one space
7614 (goto-char beg)
0a2e512a 7615 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
3dcb36b7
JB
7616 (if (match-string 1)
7617 (goto-char (match-end 1))
0a2e512a
RF
7618 (replace-match "\\3 \\4 \\5")
7619 (goto-char (match-end 2))))
5eabfe72
KH
7620 ;; eliminate multiple spaces and spaces at end of line
7621 (goto-char beg)
7622 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
3dcb36b7 7623 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
5eabfe72
KH
7624 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7625 (progn (replace-match "" nil nil) t))
7626 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7627 (progn (replace-match ";" nil nil) t))
7628 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7629 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
3dcb36b7 7630 (progn (replace-match " " nil nil) t))
5eabfe72 7631 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
3dcb36b7 7632 (progn (replace-match " " nil nil) t))
0a2e512a
RF
7633; (re-search-forward "[^ \t-]+" end t))))
7634 (re-search-forward "[^ \t\"-]+" end t))))
5eabfe72
KH
7635 (unless no-message (message "Fixing up whitespace...done")))
7636
7637(defun vhdl-fixup-whitespace-buffer ()
7638 "Fixup whitespace in buffer. Surround operator symbols by one space,
7639eliminate multiple spaces (except at beginning of line), eliminate spaces at
7640end of line, do nothing in comments."
7641 (interactive)
7642 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7643
3dcb36b7
JB
7644;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7645;; Beautify
7646
5eabfe72
KH
7647(defun vhdl-beautify-region (beg end)
7648 "Beautify region by applying indentation, whitespace fixup, alignment, and
3dcb36b7
JB
7649case fixing to a region. Calls functions `vhdl-indent-buffer',
7650`vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
5eabfe72
KH
7651`vhdl-fix-case-buffer'."
7652 (interactive "r")
3dcb36b7 7653 (setq end (save-excursion (goto-char end) (point-marker)))
5eabfe72
KH
7654 (vhdl-indent-region beg end nil)
7655 (let ((vhdl-align-groups t))
3dcb36b7 7656 (vhdl-align-region beg end))
5eabfe72
KH
7657 (vhdl-fix-case-region beg end))
7658
7659(defun vhdl-beautify-buffer ()
7660 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7661case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7662buffer."
7663 (interactive)
3dcb36b7
JB
7664 (vhdl-beautify-region (point-min) (point-max))
7665 (when noninteractive (save-buffer)))
7666
7667;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7668;; Code filling
7669
7670(defun vhdl-fill-region (beg end &optional arg)
7671 "Fill lines for a region of code."
8d422bd5 7672 (interactive "r\np")
3dcb36b7
JB
7673 (save-excursion
7674 (goto-char beg)
f35aff82 7675 (let ((margin (if arg (current-indentation) (current-column))))
3dcb36b7
JB
7676 (goto-char end)
7677 (setq end (point-marker))
7678 ;; remove inline comments, newlines and whitespace
7679 (vhdl-comment-kill-region beg end)
7680 (vhdl-comment-kill-inline-region beg end)
7681 (subst-char-in-region beg (1- end) ?\n ?\ )
7682 (vhdl-fixup-whitespace-region beg end)
7683 ;; wrap and end-comment-column
7684 (goto-char beg)
7685 (while (re-search-forward "\\s-" end t)
7686 (when(> (current-column) vhdl-end-comment-column)
7687 (backward-char)
7688 (when (re-search-backward "\\s-" beg t)
7689 (replace-match "\n")
7690 (indent-to margin)))))))
7691
7692(defun vhdl-fill-group ()
7693 "Fill group of lines between empty lines."
7694 (interactive)
7695 (vhdl-do-group 'vhdl-fill-region))
7696
7697(defun vhdl-fill-list ()
7698 "Fill the lines of a list surrounded by a balanced group of parentheses."
7699 (interactive)
7700 (vhdl-do-list 'vhdl-fill-region))
7701
7702(defun vhdl-fill-same-indent ()
7703 "Fill the lines of block of lines with same indent."
7704 (interactive)
7705 (vhdl-do-same-indent 'vhdl-fill-region))
7706
7707
7708;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7709;;; Code updating/fixing
7710;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7711
7712;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7713;; Sensitivity list update
7714
7715;; Strategy:
7716;; - no sensitivity list is generated for processes with wait statements
7717;; - otherwise, do the following:
7718;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7719;; 2. scan for all signals already in the sensitivity list (in order to catch
7720;; manually entered global signals)
7721;; 3. signals from 1. and 2. form the list of visible signals
7722;; 4. search for if/elsif conditions containing an event (sequential code)
7723;; 5. scan for strings that are within syntactical regions where signals are
7724;; read but not within sequential code, and that correspond to visible
7725;; signals
7726;; 6. replace sensitivity list by list of signals from 5.
7727
7728(defun vhdl-update-sensitivity-list-process ()
7729 "Update sensitivity list of current process."
7730 (interactive)
7731 (save-excursion
7732 (vhdl-prepare-search-2
7733 (end-of-line)
7734 ;; look whether in process
7735 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7736 (equal (upcase (match-string 2)) "PROCESS")
7737 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7738 (error "ERROR: Not within a process")
7739 (message "Updating sensitivity list...")
7740 (vhdl-update-sensitivity-list)
7741 (message "Updating sensitivity list...done")))))
7742
7743(defun vhdl-update-sensitivity-list-buffer ()
7744 "Update sensitivity list of all processes in current buffer."
7745 (interactive)
7746 (save-excursion
7747 (vhdl-prepare-search-2
7748 (goto-char (point-min))
7749 (message "Updating sensitivity lists...")
7750 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7751 (goto-char (match-beginning 0))
0a2e512a 7752 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
3dcb36b7
JB
7753 (message "Updating sensitivity lists...done"))))
7754
7755(defun vhdl-update-sensitivity-list ()
7756 "Update sensitivity list."
7757 (let ((proc-beg (point))
7758 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7759 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7760 seq-region-list)
7761 (cond
7762 ;; search for wait statement (no sensitivity list allowed)
7763 ((progn (goto-char proc-mid)
7764 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7765 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7766 ;; combinational process (update sensitivity list)
7767 (t
7768 (let
7769 ;; scan for visible signals
7770 ((visible-list (vhdl-get-visible-signals))
7771 ;; define syntactic regions where signals are read
7772 (scan-regions-list
7773 '(;; right-hand side of signal/variable assignment
7774 ;; (special case: "<=" is relational operator in a condition)
7775 ((re-search-forward "[<:]=" proc-end t)
7776 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7777 ;; if condition
7778 ((re-search-forward "^\\s-*if\\>" proc-end t)
7779 (re-search-forward "\\<then\\>" proc-end t))
7780 ;; elsif condition
7781 ((re-search-forward "\\<elsif\\>" proc-end t)
7782 (re-search-forward "\\<then\\>" proc-end t))
7783 ;; while loop condition
7784 ((re-search-forward "^\\s-*while\\>" proc-end t)
7785 (re-search-forward "\\<loop\\>" proc-end t))
7786 ;; exit/next condition
7787 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7788 (re-search-forward ";" proc-end t))
7789 ;; assert condition
7790 ((re-search-forward "\\<assert\\>" proc-end t)
7791 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7792 ;; case expression
7793 ((re-search-forward "^\\s-*case\\>" proc-end t)
7794 (re-search-forward "\\<is\\>" proc-end t))
7795 ;; parameter list of procedure call
0a2e512a
RF
7796 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7797 (1- (point)))
7798 (progn (backward-char) (forward-sexp)
7799 (while (looking-at "(") (forward-sexp)) (point)))))
3dcb36b7
JB
7800 name read-list sens-list signal-list
7801 sens-beg sens-end beg end margin)
7802 ;; scan for signals in old sensitivity list
7803 (goto-char proc-beg)
7804 (re-search-forward "\\<process\\>" proc-mid t)
7805 (if (not (looking-at "[ \t\n]*("))
7806 (setq sens-beg (point))
7807 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7808 (goto-char (match-end 1))
7809 (forward-sexp)
7810 (setq sens-end (1- (point)))
7811 (goto-char sens-beg)
7812 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7813 (setq sens-list
7814 (cons (downcase (match-string 0)) sens-list))
7815 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7816 (setq signal-list (append visible-list sens-list))
7817 ;; search for sequential parts
7818 (goto-char proc-mid)
7819 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7820 (setq end (re-search-forward "\\<then\\>" proc-end t))
7821 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7822 (goto-char end)
7823 (backward-word 1)
7824 (vhdl-forward-sexp)
7825 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7826 (beginning-of-line)))
7827 ;; scan for signals read in process
7828 (while scan-regions-list
7829 (goto-char proc-mid)
7830 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7831 (setq end (eval (nth 1 (car scan-regions-list)))))
7832 (goto-char beg)
7833 (unless (or (vhdl-in-literal)
7834 (and seq-region-list
7835 (let ((tmp-list seq-region-list))
7836 (while (and tmp-list
7837 (< (point) (caar tmp-list)))
7838 (setq tmp-list (cdr tmp-list)))
7839 (and tmp-list (< (point) (cdar tmp-list))))))
0a2e512a 7840 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
3dcb36b7 7841 (setq name (match-string 1))
0a2e512a
RF
7842 (when (and (not (match-string 4)) ; not when formal parameter
7843 (not (and (match-string 3) ; not event attribute
7844 (not (member (downcase (match-string 3))
7845 '("event" "last_event" "transaction")))))
7846 (member (downcase name) signal-list))
7847 (unless (member-ignore-case name read-list)
7848 (setq read-list (cons name read-list))))
7849 (goto-char (match-end 1)))))
3dcb36b7
JB
7850 (setq scan-regions-list (cdr scan-regions-list)))
7851 ;; update sensitivity list
7852 (goto-char sens-beg)
7853 (if sens-end
7854 (delete-region sens-beg sens-end)
7855 (when read-list
7856 (insert " ()") (backward-char)))
7857 (setq read-list (sort read-list 'string<))
7858 (when read-list
7859 (setq margin (current-column))
7860 (insert (car read-list))
7861 (setq read-list (cdr read-list))
7862 (while read-list
7863 (insert ",")
7864 (if (<= (+ (current-column) (length (car read-list)) 2)
7865 end-comment-column)
7866 (insert " ")
7867 (insert "\n") (indent-to margin))
7868 (insert (car read-list))
7869 (setq read-list (cdr read-list)))))))))
7870
7871(defun vhdl-get-visible-signals ()
7872 "Get all signals visible in the current block."
0a2e512a
RF
7873 (let (beg end signal-list entity-name file-name)
7874 (vhdl-prepare-search-2
7875 ;; get entity name
7876 (save-excursion
7877 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
3dcb36b7 7878 (not (equal "END" (upcase (match-string 1))))
0a2e512a
RF
7879 (setq entity-name (match-string 2)))
7880 (error "ERROR: Not within an architecture")))
7881 ;; search for signals declared in entity port clause
7882 (save-excursion
7883 (goto-char (point-min))
7884 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7885 (setq file-name
7886 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7887 "." (file-name-extension (buffer-file-name)))))
7888 (vhdl-visit-file
7889 file-name t
7890 (vhdl-prepare-search-2
7891 (goto-char (point-min))
7892 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7893 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7894 (when (setq beg (re-search-forward
7895 "^\\s-*port[ \t\n]*("
7896 (save-excursion
7897 (re-search-forward "^end\\>" nil t)) t))
7898 (setq end (save-excursion
7899 (backward-char) (forward-sexp) (point)))
7900 (vhdl-forward-syntactic-ws)
7901 (while (< (point) end)
7902 (when (looking-at "signal[ \t\n]+")
7903 (goto-char (match-end 0)))
7904 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7905 (setq signal-list
7906 (cons (downcase (match-string 1)) signal-list))
7907 (goto-char (match-end 0))
7908 (vhdl-forward-syntactic-ws))
7909 (re-search-forward ";" end 1)
7910 (vhdl-forward-syntactic-ws)))))))
7911 ;; search for signals declared in architecture declarative part
7912 (save-excursion
7913 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7914 (not (equal "END" (upcase (match-string 1))))
7915 (setq end (re-search-forward "^begin\\>" nil t))))
7916 (error "ERROR: No architecture declarative part found")
7917 ;; scan for all declared signal and alias names
7918 (goto-char beg)
7919 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7920 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7921 (if (match-string 2)
7922 ;; scan signal name
7923 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7924 (setq signal-list
7925 (cons (downcase (match-string 1)) signal-list))
7926 (goto-char (match-end 0)))
7927 ;; scan alias name, check is alias of (declared) signal
7928 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7929 (member (downcase (match-string 2)) signal-list))
7930 (setq signal-list
7931 (cons (downcase (match-string 1)) signal-list))
7932 (goto-char (match-end 0))))
7933 (setq beg (point))))))
7934 ;; search for signals declared in surrounding block declarative parts
7935 (save-excursion
7936 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7937 (match-string 2))
7938 (goto-char (match-end 2))
7939 (vhdl-backward-sexp)
7940 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7941 beg)
7942 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7943 ;; scan for all declared signal names
7944 (goto-char beg)
7945 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7946 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7947 (if (match-string 2)
7948 ;; scan signal name
7949 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7950 (setq signal-list
7951 (cons (downcase (match-string 1)) signal-list))
7952 (goto-char (match-end 0)))
7953 ;; scan alias name, check is alias of (declared) signal
7954 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7955 (member (downcase (match-string 2)) signal-list))
7956 (setq signal-list
7957 (cons (downcase (match-string 1)) signal-list))
7958 (goto-char (match-end 0))))))
7959 (goto-char beg)))
7960 signal-list)))
3dcb36b7
JB
7961
7962;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7963;; Generic/port clause fixing
7964
7965(defun vhdl-fix-clause ()
7966 "Fix closing parenthesis within generic/port clause."
7967 (interactive)
7968 (save-excursion
7969 (vhdl-prepare-search-2
7970 (let ((pos (point))
7971 beg end)
7972 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7973 (error "ERROR: Not within a generic/port clause")
7974 ;; search for end of clause
7975 (goto-char (match-end 0))
7976 (setq beg (1- (point)))
7977 (vhdl-forward-syntactic-ws)
7978 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7979 (goto-char (1- (match-end 0)))
7980 (setq end (point-marker))
7981 (forward-char)
7982 (vhdl-forward-syntactic-ws))
7983 (goto-char end)
7984 (when (> pos (save-excursion (end-of-line) (point)))
7985 (error "ERROR: Not within a generic/port clause"))
7986 ;; delete closing parenthesis on separate line (not supported style)
7987 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7988 (vhdl-line-kill)
7989 (vhdl-backward-syntactic-ws)
7990 (setq end (point-marker))
7991 (insert ";"))
7992 ;; delete superfluous parentheses
7993 (while (progn (goto-char beg)
7994 (condition-case () (forward-sexp)
7995 (error (goto-char (point-max))))
7996 (< (point) end))
d355a0b7 7997 (delete-char -1))
3dcb36b7
JB
7998 ;; add closing parenthesis
7999 (when (> (point) end)
8000 (goto-char end)
8001 (insert ")")))))))
8002
8003;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8004;; Miscellaneous
8005
8006(defun vhdl-remove-trailing-spaces ()
8007 "Remove trailing spaces in the whole buffer."
8008 (interactive)
8009 (save-match-data
8010 (save-excursion
8011 (goto-char (point-min))
8012 (while (re-search-forward "[ \t]+$" (point-max) t)
8013 (unless (vhdl-in-literal)
8014 (replace-match "" nil nil))))))
d2ddb974
KH
8015
8016
5eabfe72
KH
8017;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8018;;; Electrification
8019;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 8020
5eabfe72
KH
8021(defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8022 "Syntax of prompt inserted by template generators.")
8023
8024(defvar vhdl-template-invoked-by-hook nil
8025 "Indicates whether a template has been invoked by a hook or by key or menu.
8026Used for undoing after template abortion.")
8027
8028;; correct different behavior of function `unread-command-events' in XEmacs
3dcb36b7 8029(defun vhdl-character-to-event (arg))
5eabfe72 8030(defalias 'vhdl-character-to-event
4bcb9c95 8031 (if (fboundp 'character-to-event) 'character-to-event 'identity))
3dcb36b7
JB
8032
8033(defun vhdl-work-library ()
8034 "Return the working library name of the current project or \"work\" if no
8035project is defined."
8036 (vhdl-resolve-env-variable
8037 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
5eabfe72
KH
8038
8039;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8040;; Enabling/disabling
8041
56eb0904 8042(define-minor-mode vhdl-electric-mode
5eabfe72
KH
8043 "Toggle VHDL electric mode.
8044Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
56eb0904 8045 :global t)
5eabfe72 8046
56eb0904 8047(define-minor-mode vhdl-stutter-mode
5eabfe72
KH
8048 "Toggle VHDL stuttering mode.
8049Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
56eb0904 8050 :global t)
5eabfe72
KH
8051
8052;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8053;; Stuttering
d2ddb974 8054
5eabfe72
KH
8055(defun vhdl-electric-dash (count)
8056 "-- starts a comment, --- draws a horizontal line,
a4c6cfad 8057---- starts a display comment."
d2ddb974 8058 (interactive "p")
3dcb36b7 8059 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
5eabfe72
KH
8060 (cond
8061 ((and abbrev-start-location (= abbrev-start-location (point)))
8062 (setq abbrev-start-location nil)
8063 (goto-char last-abbrev-location)
8064 (beginning-of-line nil)
8065 (vhdl-comment-display))
8066 ((/= (preceding-char) ?-) ; standard dash (minus)
d2ddb974 8067 (self-insert-command count))
5eabfe72
KH
8068 (t (self-insert-command count)
8069 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8070 (let ((next-input (read-char)))
8071 (if (= next-input ?-) ; triple dash
8072 (progn
8073 (vhdl-comment-display-line)
8074 (message
8075 "Enter '-' for display comment, else continue coding")
8076 (let ((next-input (read-char)))
8077 (if (= next-input ?-) ; four dashes
8078 (vhdl-comment-display t)
8079 (setq unread-command-events ; pushback the char
8080 (list (vhdl-character-to-event next-input))))))
8081 (setq unread-command-events ; pushback the char
8082 (list (vhdl-character-to-event next-input)))
8083 (vhdl-comment-insert)))))
8084 (self-insert-command count)))
8085
8086(defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
d2ddb974 8087 (interactive "p")
3dcb36b7 8088 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8089 (if (= (preceding-char) ?\()
8090 (progn (delete-char -1) (insert-char ?\[ 1))
8091 (insert-char ?\( 1))
8092 (self-insert-command count)))
d2ddb974 8093
5eabfe72 8094(defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
d2ddb974 8095 (interactive "p")
3dcb36b7 8096 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974 8097 (progn
5eabfe72
KH
8098 (if (= (preceding-char) ?\))
8099 (progn (delete-char -1) (insert-char ?\] 1))
8100 (insert-char ?\) 1))
8101 (blink-matching-open))
8102 (self-insert-command count)))
d2ddb974 8103
5eabfe72 8104(defun vhdl-electric-quote (count) "'' --> \""
d2ddb974 8105 (interactive "p")
3dcb36b7 8106 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8107 (if (= (preceding-char) last-input-event)
d355a0b7 8108 (progn (delete-char -1) (insert-char ?\" 1))
5eabfe72
KH
8109 (insert-char ?\' 1))
8110 (self-insert-command count)))
d2ddb974 8111
5eabfe72 8112(defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
d2ddb974 8113 (interactive "p")
3dcb36b7 8114 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8115 (cond ((= (preceding-char) last-input-event)
5eabfe72 8116 (progn (delete-char -1)
3dcb36b7 8117 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8118 (insert ": ")
8119 (setq this-command 'vhdl-electric-colon)))
8120 ((and
8121 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8122 (progn (delete-char -1) (insert "= ")))
8123 (t (insert-char ?\; 1)))
8124 (self-insert-command count)))
8125
8126(defun vhdl-electric-comma (count) "',,' --> ' <= '"
d2ddb974 8127 (interactive "p")
3dcb36b7 8128 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8129 (cond ((= (preceding-char) last-input-event)
d2ddb974 8130 (progn (delete-char -1)
3dcb36b7 8131 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8132 (insert "<= ")))
5eabfe72
KH
8133 (t (insert-char ?\, 1)))
8134 (self-insert-command count)))
d2ddb974 8135
5eabfe72 8136(defun vhdl-electric-period (count) "'..' --> ' => '"
d2ddb974 8137 (interactive "p")
3dcb36b7 8138 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8139 (cond ((= (preceding-char) last-input-event)
d2ddb974 8140 (progn (delete-char -1)
3dcb36b7 8141 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8142 (insert "=> ")))
5eabfe72
KH
8143 (t (insert-char ?\. 1)))
8144 (self-insert-command count)))
d2ddb974 8145
5eabfe72 8146(defun vhdl-electric-equal (count) "'==' --> ' == '"
d2ddb974 8147 (interactive "p")
3dcb36b7 8148 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8149 (cond ((= (preceding-char) last-input-event)
5eabfe72 8150 (progn (delete-char -1)
3dcb36b7 8151 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8152 (insert "== ")))
8153 (t (insert-char ?\= 1)))
8154 (self-insert-command count)))
d2ddb974 8155
5eabfe72 8156;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
8157;; VHDL templates
8158
5eabfe72
KH
8159(defun vhdl-template-paired-parens ()
8160 "Insert a pair of round parentheses, placing point between them."
d2ddb974 8161 (interactive)
5eabfe72
KH
8162 (insert "()")
8163 (backward-char))
d2ddb974 8164
5eabfe72
KH
8165(defun vhdl-template-alias ()
8166 "Insert alias declaration."
d2ddb974 8167 (interactive)
5eabfe72
KH
8168 (let ((start (point)))
8169 (vhdl-insert-keyword "ALIAS ")
8170 (when (vhdl-template-field "name" nil t start (point))
8171 (insert " : ")
8172 (unless (vhdl-template-field
8173 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8174 nil t)
d355a0b7 8175 (delete-char -3))
5eabfe72
KH
8176 (vhdl-insert-keyword " IS ")
8177 (vhdl-template-field "name" ";")
8178 (vhdl-comment-insert-inline))))
8179
8180(defun vhdl-template-architecture ()
8181 "Insert architecture."
8182 (interactive)
8183 (let ((margin (current-indentation))
8184 (start (point))
3dcb36b7 8185 arch-name)
d2ddb974 8186 (vhdl-insert-keyword "ARCHITECTURE ")
5eabfe72
KH
8187 (when (setq arch-name
8188 (vhdl-template-field "name" nil t start (point)))
d2ddb974 8189 (vhdl-insert-keyword " OF ")
3dcb36b7
JB
8190 (if (save-excursion
8191 (vhdl-prepare-search-1
8192 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8193 (insert (match-string 1))
5eabfe72 8194 (vhdl-template-field "entity name"))
3dcb36b7 8195 (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8196 (vhdl-template-begin-end
8197 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8198 (memq vhdl-insert-empty-lines '(unit all))))))
d2ddb974 8199
5eabfe72 8200(defun vhdl-template-array (kind &optional secondary)
d2ddb974
KH
8201 "Insert array type definition."
8202 (interactive)
5eabfe72
KH
8203 (let ((start (point)))
8204 (vhdl-insert-keyword "ARRAY (")
8205 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8206 secondary)
8207 (vhdl-insert-keyword ") OF ")
8208 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8209 (vhdl-insert-keyword ";"))))
8210
8211(defun vhdl-template-assert ()
8212 "Insert an assertion statement."
8213 (interactive)
8214 (let ((start (point)))
8215 (vhdl-insert-keyword "ASSERT ")
8216 (when vhdl-conditions-in-parenthesis (insert "("))
8217 (when (vhdl-template-field "condition (negated)" nil t start (point))
8218 (when vhdl-conditions-in-parenthesis (insert ")"))
8219 (setq start (point))
8220 (vhdl-insert-keyword " REPORT ")
8221 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8222 (delete-region start (point)))
8223 (setq start (point))
8224 (vhdl-insert-keyword " SEVERITY ")
8225 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8226 (delete-region start (point)))
8227 (insert ";"))))
8228
8229(defun vhdl-template-attribute ()
8230 "Insert an attribute declaration or specification."
8231 (interactive)
8232 (if (eq (vhdl-decision-query
8233 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8234 (vhdl-template-attribute-spec)
8235 (vhdl-template-attribute-decl)))
d2ddb974 8236
5eabfe72
KH
8237(defun vhdl-template-attribute-decl ()
8238 "Insert an attribute declaration."
d2ddb974 8239 (interactive)
5eabfe72
KH
8240 (let ((start (point)))
8241 (vhdl-insert-keyword "ATTRIBUTE ")
8242 (when (vhdl-template-field "name" " : " t start (point))
8243 (vhdl-template-field "type" ";")
8244 (vhdl-comment-insert-inline))))
8245
8246(defun vhdl-template-attribute-spec ()
8247 "Insert an attribute specification."
8248 (interactive)
8249 (let ((start (point)))
8250 (vhdl-insert-keyword "ATTRIBUTE ")
8251 (when (vhdl-template-field "name" nil t start (point))
8252 (vhdl-insert-keyword " OF ")
8253 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8254 (vhdl-template-field "entity class")
8255 (vhdl-insert-keyword " IS ")
8256 (vhdl-template-field "expression" ";"))))
d2ddb974 8257
5eabfe72
KH
8258(defun vhdl-template-block ()
8259 "Insert a block."
d2ddb974 8260 (interactive)
5eabfe72
KH
8261 (let ((margin (current-indentation))
8262 (start (point))
8263 label)
8264 (vhdl-insert-keyword ": BLOCK ")
8265 (goto-char start)
8266 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8267 (forward-word 1)
8268 (forward-char 1)
d2ddb974 8269 (insert "(")
5eabfe72
KH
8270 (if (vhdl-template-field "[guard expression]" nil t)
8271 (insert ")")
8272 (delete-char -2))
8273 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 8274 (insert "\n")
5eabfe72
KH
8275 (vhdl-template-begin-end "BLOCK" label margin)
8276 (vhdl-comment-block))))
d2ddb974 8277
5eabfe72 8278(defun vhdl-template-block-configuration ()
d2ddb974
KH
8279 "Insert a block configuration statement."
8280 (interactive)
5eabfe72
KH
8281 (let ((margin (current-indentation))
8282 (start (point)))
d2ddb974 8283 (vhdl-insert-keyword "FOR ")
5eabfe72 8284 (when (vhdl-template-field "block name" nil t start (point))
d2ddb974
KH
8285 (vhdl-insert-keyword "\n\n")
8286 (indent-to margin)
8287 (vhdl-insert-keyword "END FOR;")
8288 (end-of-line 0)
5eabfe72 8289 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8290
5eabfe72
KH
8291(defun vhdl-template-break ()
8292 "Insert a break statement."
d2ddb974 8293 (interactive)
5eabfe72
KH
8294 (let (position)
8295 (vhdl-insert-keyword "BREAK")
8296 (setq position (point))
8297 (insert " ")
8298 (while (or
8299 (progn (vhdl-insert-keyword "FOR ")
8300 (if (vhdl-template-field "[quantity name]" " USE " t)
8301 (progn (vhdl-template-field "quantity name" " => ") t)
453cfeb3
CY
8302 (delete-region (point)
8303 (progn (forward-word -1) (point)))
8304 nil))
5eabfe72
KH
8305 (vhdl-template-field "[quantity name]" " => " t))
8306 (vhdl-template-field "expression")
8307 (setq position (point))
8308 (insert ", "))
8309 (delete-region position (point))
8310 (unless (vhdl-sequential-statement-p)
8311 (vhdl-insert-keyword " ON ")
8312 (if (vhdl-template-field "[sensitivity list]" nil t)
8313 (setq position (point))
8314 (delete-region position (point))))
8315 (vhdl-insert-keyword " WHEN ")
8316 (when vhdl-conditions-in-parenthesis (insert "("))
8317 (if (vhdl-template-field "[condition]" nil t)
8318 (when vhdl-conditions-in-parenthesis (insert ")"))
8319 (delete-region position (point)))
8320 (insert ";")))
8321
8322(defun vhdl-template-case (&optional kind)
8323 "Insert a case statement."
8324 (interactive)
8325 (let ((margin (current-indentation))
8326 (start (point))
8327 label)
8328 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8329 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8330 (vhdl-insert-keyword "CASE ")
8331 (vhdl-insert-keyword ": CASE ")
8332 (goto-char start)
8333 (setq label (vhdl-template-field "[label]" nil t))
8334 (unless label (delete-char 2))
8335 (forward-word 1)
8336 (forward-char 1))
8337 (when (vhdl-template-field "expression" nil t start (point))
8338 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
d2ddb974 8339 (indent-to margin)
5eabfe72
KH
8340 (vhdl-insert-keyword "END CASE")
8341 (when label (insert " " label))
8342 (insert ";")
d2ddb974
KH
8343 (forward-line -1)
8344 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8345 (vhdl-insert-keyword "WHEN ")
8346 (let ((position (point)))
8347 (insert " => ;\n")
8348 (indent-to (+ margin vhdl-basic-offset))
8349 (vhdl-insert-keyword "WHEN OTHERS => null;")
8350 (goto-char position)))))
d2ddb974 8351
5eabfe72
KH
8352(defun vhdl-template-case-is ()
8353 "Insert a sequential case statement."
d2ddb974 8354 (interactive)
5eabfe72
KH
8355 (vhdl-template-case 'is))
8356
8357(defun vhdl-template-case-use ()
8358 "Insert a simultaneous case statement."
8359 (interactive)
8360 (vhdl-template-case 'use))
8361
8362(defun vhdl-template-component ()
8363 "Insert a component declaration."
8364 (interactive)
8365 (vhdl-template-component-decl))
8366
8367(defun vhdl-template-component-conf ()
8368 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8369since these are almost equivalent)."
8370 (interactive)
8371 (let ((margin (current-indentation))
8372 (result (vhdl-template-configuration-spec t)))
8373 (when result
8374 (insert "\n")
8375 (indent-to margin)
8376 (vhdl-insert-keyword "END FOR;")
8377 (when (eq result 'no-use)
8378 (end-of-line -0)))))
8379
8380(defun vhdl-template-component-decl ()
8381 "Insert a component declaration."
8382 (interactive)
8383 (let ((margin (current-indentation))
8384 (start (point))
8385 name end-column)
d2ddb974 8386 (vhdl-insert-keyword "COMPONENT ")
5eabfe72 8387 (when (setq name (vhdl-template-field "name" nil t start (point)))
3dcb36b7 8388 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
d2ddb974
KH
8389 (insert "\n\n")
8390 (indent-to margin)
5eabfe72
KH
8391 (vhdl-insert-keyword "END COMPONENT")
8392 (unless (vhdl-standard-p '87) (insert " " name))
8393 (insert ";")
8394 (setq end-column (current-column))
d2ddb974
KH
8395 (end-of-line -0)
8396 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 8397 (vhdl-template-generic-list t t)
d2ddb974
KH
8398 (insert "\n")
8399 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8400 (vhdl-template-port-list t)
8401 (beginning-of-line 2)
8402 (forward-char end-column))))
d2ddb974 8403
5eabfe72
KH
8404(defun vhdl-template-component-inst ()
8405 "Insert a component instantiation statement."
d2ddb974 8406 (interactive)
5eabfe72
KH
8407 (let ((margin (current-indentation))
8408 (start (point))
8409 unit position)
8410 (when (vhdl-template-field "instance label" nil t start (point))
8411 (insert ": ")
3dcb36b7 8412 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
8413 (vhdl-template-field "component name")
8414 ;; direct instantiation
8415 (setq unit (vhdl-template-field
8416 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8417 (setq unit (upcase (or unit "")))
8418 (cond ((equal unit "ENTITY")
3dcb36b7
JB
8419 (vhdl-template-field "library name" "." nil nil nil nil
8420 (vhdl-work-library))
5eabfe72
KH
8421 (vhdl-template-field "entity name" "(")
8422 (if (vhdl-template-field "[architecture name]" nil t)
8423 (insert ")")
8424 (delete-char -1)))
8425 ((equal unit "CONFIGURATION")
3dcb36b7
JB
8426 (vhdl-template-field "library name" "." nil nil nil nil
8427 (vhdl-work-library))
5eabfe72
KH
8428 (vhdl-template-field "configuration name"))
8429 (t (vhdl-template-field "component name"))))
8430 (insert "\n")
d2ddb974 8431 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8432 (setq position (point))
8433 (vhdl-insert-keyword "GENERIC ")
8434 (when (vhdl-template-map position t t)
8435 (insert "\n")
8436 (indent-to (+ margin vhdl-basic-offset)))
8437 (setq position (point))
8438 (vhdl-insert-keyword "PORT ")
8439 (unless (vhdl-template-map position t t)
453cfeb3 8440 (delete-region (line-beginning-position) (point))
5eabfe72
KH
8441 (delete-char -1))
8442 (insert ";"))))
d2ddb974 8443
5eabfe72
KH
8444(defun vhdl-template-conditional-signal-asst ()
8445 "Insert a conditional signal assignment."
d2ddb974 8446 (interactive)
5eabfe72 8447 (when (vhdl-template-field "target signal")
d2ddb974 8448 (insert " <= ")
5eabfe72
KH
8449; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8450; (insert " "))
d2ddb974 8451 (let ((margin (current-column))
5eabfe72
KH
8452 (start (point))
8453 position)
8454 (vhdl-template-field "waveform")
8455 (setq position (point))
d2ddb974 8456 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8457 (when vhdl-conditions-in-parenthesis (insert "("))
8458 (while (and (vhdl-template-field "[condition]" nil t)
8459 (progn
8460 (when vhdl-conditions-in-parenthesis (insert ")"))
8461 (setq position (point))
8462 (vhdl-insert-keyword " ELSE")
8463 (insert "\n")
8464 (indent-to margin)
8465 (vhdl-template-field "[waveform]" nil t)))
8466 (setq position (point))
d2ddb974 8467 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8468 (when vhdl-conditions-in-parenthesis (insert "(")))
8469 (delete-region position (point))
d2ddb974 8470 (insert ";")
3dcb36b7 8471 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 8472
5eabfe72
KH
8473(defun vhdl-template-configuration ()
8474 "Insert a configuration specification if within an architecture,
d2ddb974
KH
8475a block or component configuration if within a configuration declaration,
8476a configuration declaration if not within a design unit."
8477 (interactive)
3dcb36b7
JB
8478 (vhdl-prepare-search-1
8479 (cond
8480 ((and (save-excursion ; architecture body
8481 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8482 (equal "ARCHITECTURE" (upcase (match-string 1))))
8483 (vhdl-template-configuration-spec))
8484 ((and (save-excursion ; configuration declaration
8485 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8486 (equal "CONFIGURATION" (upcase (match-string 1))))
8487 (if (eq (vhdl-decision-query
8488 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8489 (vhdl-template-component-conf)
8490 (vhdl-template-block-configuration)))
8491 (t (vhdl-template-configuration-decl))))) ; otherwise
5eabfe72
KH
8492
8493(defun vhdl-template-configuration-spec (&optional optional-use)
8494 "Insert a configuration specification."
d2ddb974 8495 (interactive)
5eabfe72
KH
8496 (let ((margin (current-indentation))
8497 (start (point))
8498 aspect position)
d2ddb974 8499 (vhdl-insert-keyword "FOR ")
3dcb36b7 8500 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
5eabfe72 8501 t start (point))
3dcb36b7 8502 (vhdl-template-field "component name" "\n")
d2ddb974 8503 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8504 (setq start (point))
8505 (vhdl-insert-keyword "USE ")
8506 (if (and optional-use
8507 (not (setq aspect (vhdl-template-field
8508 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8509 (progn (delete-region start (point)) 'no-use)
8510 (unless optional-use
8511 (setq aspect (vhdl-template-field
8512 "ENTITY | CONFIGURATION | OPEN" " ")))
8513 (setq aspect (upcase (or aspect "")))
8514 (cond ((equal aspect "ENTITY")
3dcb36b7
JB
8515 (vhdl-template-field "library name" "." nil nil nil nil
8516 (vhdl-work-library))
5eabfe72
KH
8517 (vhdl-template-field "entity name" "(")
8518 (if (vhdl-template-field "[architecture name]" nil t)
8519 (insert ")")
d2ddb974 8520 (delete-char -1))
5eabfe72
KH
8521 (insert "\n")
8522 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8523 (setq position (point))
8524 (vhdl-insert-keyword "GENERIC ")
8525 (when (vhdl-template-map position t t)
8526 (insert "\n")
8527 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8528 (setq position (point))
8529 (vhdl-insert-keyword "PORT ")
8530 (unless (vhdl-template-map position t t)
453cfeb3 8531 (delete-region (line-beginning-position) (point))
5eabfe72
KH
8532 (delete-char -1))
8533 (insert ";")
8534 t)
8535 ((equal aspect "CONFIGURATION")
3dcb36b7
JB
8536 (vhdl-template-field "library name" "." nil nil nil nil
8537 (vhdl-work-library))
5eabfe72 8538 (vhdl-template-field "configuration name" ";"))
d355a0b7 8539 (t (delete-char -1) (insert ";") t))))))
5eabfe72 8540
d2ddb974 8541
5eabfe72
KH
8542(defun vhdl-template-configuration-decl ()
8543 "Insert a configuration declaration."
d2ddb974 8544 (interactive)
5eabfe72
KH
8545 (let ((margin (current-indentation))
8546 (start (point))
5eabfe72 8547 entity-exists string name position)
d2ddb974 8548 (vhdl-insert-keyword "CONFIGURATION ")
5eabfe72 8549 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974 8550 (vhdl-insert-keyword " OF ")
5eabfe72 8551 (save-excursion
3dcb36b7
JB
8552 (vhdl-prepare-search-1
8553 (setq entity-exists (vhdl-re-search-backward
5eabfe72
KH
8554 "\\<entity \\(\\w*\\) is\\>" nil t))
8555 (setq string (match-string 1))))
d2ddb974 8556 (if (and entity-exists (not (equal string "")))
5eabfe72
KH
8557 (insert string)
8558 (vhdl-template-field "entity name"))
8559 (vhdl-insert-keyword " IS\n")
8560 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8561 (indent-to (+ margin vhdl-basic-offset))
8562 (setq position (point))
8563 (insert "\n")
8564 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
d2ddb974
KH
8565 (indent-to margin)
8566 (vhdl-insert-keyword "END ")
5eabfe72
KH
8567 (unless (vhdl-standard-p '87)
8568 (vhdl-insert-keyword "CONFIGURATION "))
d2ddb974 8569 (insert name ";")
5eabfe72 8570 (goto-char position))))
d2ddb974 8571
5eabfe72
KH
8572(defun vhdl-template-constant ()
8573 "Insert a constant declaration."
8574 (interactive)
8575 (let ((start (point))
8576 (in-arglist (vhdl-in-argument-list-p)))
8577 (vhdl-insert-keyword "CONSTANT ")
8578 (when (vhdl-template-field "name" nil t start (point))
d2ddb974 8579 (insert " : ")
5eabfe72
KH
8580 (when in-arglist (vhdl-insert-keyword "IN "))
8581 (vhdl-template-field "type")
d2ddb974 8582 (if in-arglist
5eabfe72
KH
8583 (progn (insert ";")
8584 (vhdl-comment-insert-inline))
d2ddb974
KH
8585 (let ((position (point)))
8586 (insert " := ")
5eabfe72
KH
8587 (unless (vhdl-template-field "[initialization]" nil t)
8588 (delete-region position (point)))
8589 (insert ";")
8590 (vhdl-comment-insert-inline))))))
d2ddb974 8591
5eabfe72 8592(defun vhdl-template-default ()
d2ddb974
KH
8593 "Insert nothing."
8594 (interactive)
8595 (insert " ")
8596 (unexpand-abbrev)
8597 (backward-word 1)
8598 (vhdl-case-word 1)
5eabfe72 8599 (forward-char 1))
d2ddb974 8600
5eabfe72 8601(defun vhdl-template-default-indent ()
d2ddb974
KH
8602 "Insert nothing and indent."
8603 (interactive)
8604 (insert " ")
8605 (unexpand-abbrev)
8606 (backward-word 1)
8607 (vhdl-case-word 1)
8608 (forward-char 1)
3dcb36b7 8609 (indent-according-to-mode))
d2ddb974 8610
5eabfe72 8611(defun vhdl-template-disconnect ()
d2ddb974
KH
8612 "Insert a disconnect statement."
8613 (interactive)
5eabfe72
KH
8614 (let ((start (point)))
8615 (vhdl-insert-keyword "DISCONNECT ")
8616 (when (vhdl-template-field "signal names | OTHERS | ALL"
8617 " : " t start (point))
8618 (vhdl-template-field "type")
8619 (vhdl-insert-keyword " AFTER ")
8620 (vhdl-template-field "time expression" ";"))))
8621
8622(defun vhdl-template-else ()
d2ddb974
KH
8623 "Insert an else statement."
8624 (interactive)
3dcb36b7
JB
8625 (let (margin)
8626 (vhdl-prepare-search-1
5eabfe72 8627 (vhdl-insert-keyword "ELSE")
3dcb36b7
JB
8628 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8629 (equal "WHEN" (upcase (match-string 1))))
5eabfe72 8630 (insert " ")
3dcb36b7 8631 (indent-according-to-mode)
5eabfe72
KH
8632 (setq margin (current-indentation))
8633 (insert "\n")
8634 (indent-to (+ margin vhdl-basic-offset))))))
8635
8636(defun vhdl-template-elsif ()
d2ddb974
KH
8637 "Insert an elsif statement."
8638 (interactive)
5eabfe72
KH
8639 (let ((start (point))
8640 margin)
d2ddb974 8641 (vhdl-insert-keyword "ELSIF ")
3dcb36b7
JB
8642 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8643 (when vhdl-conditions-in-parenthesis (insert "("))
8644 (when (vhdl-template-field "condition" nil t start (point))
8645 (when vhdl-conditions-in-parenthesis (insert ")"))
8646 (indent-according-to-mode)
8647 (setq margin (current-indentation))
8648 (vhdl-insert-keyword
8649 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8650 (indent-to (+ margin vhdl-basic-offset))))))
d2ddb974 8651
5eabfe72
KH
8652(defun vhdl-template-entity ()
8653 "Insert an entity."
d2ddb974 8654 (interactive)
5eabfe72
KH
8655 (let ((margin (current-indentation))
8656 (start (point))
8657 name end-column)
d2ddb974 8658 (vhdl-insert-keyword "ENTITY ")
5eabfe72 8659 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974
KH
8660 (vhdl-insert-keyword " IS\n\n")
8661 (indent-to margin)
8662 (vhdl-insert-keyword "END ")
5eabfe72
KH
8663 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8664 (insert name ";")
8665 (setq end-column (current-column))
d2ddb974
KH
8666 (end-of-line -0)
8667 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8668 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8669 (indent-to (+ margin vhdl-basic-offset))
8670 (when (vhdl-template-generic-list t)
8671 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8672 (insert "\n")
8673 (indent-to (+ margin vhdl-basic-offset))
8674 (when (vhdl-template-port-list t)
8675 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8676 (beginning-of-line 2)
8677 (forward-char end-column))))
d2ddb974 8678
5eabfe72 8679(defun vhdl-template-exit ()
d2ddb974
KH
8680 "Insert an exit statement."
8681 (interactive)
5eabfe72
KH
8682 (let ((start (point)))
8683 (vhdl-insert-keyword "EXIT ")
3dcb36b7
JB
8684 (if (vhdl-template-field "[loop label]" nil t start (point))
8685 (let ((position (point)))
8686 (vhdl-insert-keyword " WHEN ")
8687 (when vhdl-conditions-in-parenthesis (insert "("))
8688 (if (vhdl-template-field "[condition]" nil t)
8689 (when vhdl-conditions-in-parenthesis (insert ")"))
8690 (delete-region position (point))))
d2ddb974 8691 (delete-char -1))
5eabfe72
KH
8692 (insert ";")))
8693
8694(defun vhdl-template-file ()
8695 "Insert a file declaration."
8696 (interactive)
8697 (let ((start (point)))
8698 (vhdl-insert-keyword "FILE ")
8699 (when (vhdl-template-field "name" nil t start (point))
8700 (insert " : ")
8701 (vhdl-template-field "type")
8702 (unless (vhdl-standard-p '87)
8703 (vhdl-insert-keyword " OPEN ")
8704 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8705 nil t)
d355a0b7 8706 (delete-char -6)))
5eabfe72
KH
8707 (vhdl-insert-keyword " IS ")
8708 (when (vhdl-standard-p '87)
8709 (vhdl-template-field "[IN | OUT]" " " t))
8710 (vhdl-template-field "filename-string" nil nil nil nil t)
8711 (insert ";")
8712 (vhdl-comment-insert-inline))))
d2ddb974 8713
5eabfe72
KH
8714(defun vhdl-template-for ()
8715 "Insert a block or component configuration if within a configuration
8716declaration, a configuration specification if within an architecture
3dcb36b7
JB
8717declarative part (and not within a subprogram), a for-loop if within a
8718sequential statement part (subprogram or process), and a for-generate
8719otherwise."
5eabfe72 8720 (interactive)
3dcb36b7
JB
8721 (vhdl-prepare-search-1
8722 (cond
8723 ((vhdl-sequential-statement-p) ; sequential statement
8724 (vhdl-template-for-loop))
8725 ((and (save-excursion ; configuration declaration
8726 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8727 (equal "CONFIGURATION" (upcase (match-string 1))))
8728 (if (eq (vhdl-decision-query
8729 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8730 (vhdl-template-component-conf)
8731 (vhdl-template-block-configuration)))
8732 ((and (save-excursion
8733 (re-search-backward ; architecture declarative part
8734 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8735 (equal "ARCHITECTURE" (upcase (match-string 1))))
8736 (vhdl-template-configuration-spec))
8737 (t (vhdl-template-for-generate))))) ; concurrent statement
5eabfe72
KH
8738
8739(defun vhdl-template-for-generate ()
8740 "Insert a for-generate."
d2ddb974 8741 (interactive)
5eabfe72
KH
8742 (let ((margin (current-indentation))
8743 (start (point))
3dcb36b7 8744 label position)
5eabfe72
KH
8745 (vhdl-insert-keyword ": FOR ")
8746 (setq position (point-marker))
8747 (goto-char start)
8748 (when (setq label (vhdl-template-field "label" nil t start position))
8749 (goto-char position)
8750 (vhdl-template-field "loop variable")
8751 (vhdl-insert-keyword " IN ")
8752 (vhdl-template-field "range")
8753 (vhdl-template-generate-body margin label))))
d2ddb974 8754
5eabfe72
KH
8755(defun vhdl-template-for-loop ()
8756 "Insert a for loop."
d2ddb974 8757 (interactive)
5eabfe72
KH
8758 (let ((margin (current-indentation))
8759 (start (point))
8760 label index)
8761 (if (not (eq vhdl-optional-labels 'all))
8762 (vhdl-insert-keyword "FOR ")
8763 (vhdl-insert-keyword ": FOR ")
8764 (goto-char start)
8765 (setq label (vhdl-template-field "[label]" nil t))
8766 (unless label (delete-char 2))
8767 (forward-word 1)
8768 (forward-char 1))
8769 (when (setq index (vhdl-template-field "loop variable"
8770 nil t start (point)))
d2ddb974 8771 (vhdl-insert-keyword " IN ")
5eabfe72 8772 (vhdl-template-field "range")
d2ddb974
KH
8773 (vhdl-insert-keyword " LOOP\n\n")
8774 (indent-to margin)
8775 (vhdl-insert-keyword "END LOOP")
5eabfe72
KH
8776 (if label
8777 (insert " " label ";")
d2ddb974 8778 (insert ";")
5eabfe72 8779 (when vhdl-self-insert-comments (insert " -- " index)))
d2ddb974 8780 (forward-line -1)
5eabfe72 8781 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8782
5eabfe72
KH
8783(defun vhdl-template-function (&optional kind)
8784 "Insert a function declaration or body."
d2ddb974 8785 (interactive)
5eabfe72
KH
8786 (let ((margin (current-indentation))
8787 (start (point))
8788 name)
8789 (vhdl-insert-keyword "FUNCTION ")
8790 (when (setq name (vhdl-template-field "name" nil t start (point)))
8791 (vhdl-template-argument-list t)
3dcb36b7 8792 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
d2ddb974 8793 (end-of-line)
5eabfe72 8794 (insert "\n")
d2ddb974 8795 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8796 (vhdl-insert-keyword "RETURN ")
8797 (vhdl-template-field "type")
8798 (if (if kind (eq kind 'body)
8799 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
3dcb36b7 8800 (progn (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8801 (vhdl-template-begin-end
8802 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8803 (vhdl-comment-block))
8804 (insert ";")))))
8805
8806(defun vhdl-template-function-decl ()
8807 "Insert a function declaration."
8808 (interactive)
8809 (vhdl-template-function 'decl))
d2ddb974 8810
5eabfe72
KH
8811(defun vhdl-template-function-body ()
8812 "Insert a function declaration."
d2ddb974 8813 (interactive)
5eabfe72
KH
8814 (vhdl-template-function 'body))
8815
8816(defun vhdl-template-generate ()
8817 "Insert a generation scheme."
8818 (interactive)
8819 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8820 (vhdl-template-if-generate)
8821 (vhdl-template-for-generate)))
d2ddb974 8822
5eabfe72
KH
8823(defun vhdl-template-generic ()
8824 "Insert generic declaration, or generic map in instantiation statements."
8825 (interactive)
3dcb36b7
JB
8826 (let ((start (point)))
8827 (vhdl-prepare-search-1
5eabfe72
KH
8828 (cond
8829 ((and (save-excursion ; entity declaration
8830 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8831 (equal "ENTITY" (upcase (match-string 1))))
8832 (vhdl-template-generic-list nil))
8833 ((or (save-excursion
8834 (or (beginning-of-line)
8835 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 8836 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
8837 (vhdl-insert-keyword "GENERIC ")
8838 (vhdl-template-map start))
8839 (t (vhdl-template-generic-list nil t))))))
8840
8841(defun vhdl-template-group ()
8842 "Insert group or group template declaration."
8843 (interactive)
8844 (let ((start (point)))
8845 (if (eq (vhdl-decision-query
8846 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8847 (vhdl-template-group-template)
8848 (vhdl-template-group-decl))))
8849
8850(defun vhdl-template-group-decl ()
8851 "Insert group declaration."
8852 (interactive)
8853 (let ((start (point)))
8854 (vhdl-insert-keyword "GROUP ")
8855 (when (vhdl-template-field "name" " : " t start (point))
8856 (vhdl-template-field "template name" " (")
8857 (vhdl-template-field "constituent list" ");")
8858 (vhdl-comment-insert-inline))))
8859
8860(defun vhdl-template-group-template ()
8861 "Insert group template declaration."
8862 (interactive)
8863 (let ((start (point)))
8864 (vhdl-insert-keyword "GROUP ")
8865 (when (vhdl-template-field "template name" nil t start (point))
8866 (vhdl-insert-keyword " IS (")
8867 (vhdl-template-field "entity class list" ");")
8868 (vhdl-comment-insert-inline))))
8869
5eabfe72
KH
8870(defun vhdl-template-if ()
8871 "Insert a sequential if statement or an if-generate statement."
8872 (interactive)
8873 (if (vhdl-sequential-statement-p)
8874 (vhdl-template-if-then)
8875 (if (and (vhdl-standard-p 'ams)
8876 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8877 (vhdl-template-if-use)
8878 (vhdl-template-if-generate))))
8879
8880(defun vhdl-template-if-generate ()
8881 "Insert an if-generate."
8882 (interactive)
8883 (let ((margin (current-indentation))
8884 (start (point))
3dcb36b7 8885 label position)
5eabfe72
KH
8886 (vhdl-insert-keyword ": IF ")
8887 (setq position (point-marker))
8888 (goto-char start)
8889 (when (setq label (vhdl-template-field "label" nil t start position))
8890 (goto-char position)
8891 (when vhdl-conditions-in-parenthesis (insert "("))
8892 (vhdl-template-field "condition")
8893 (when vhdl-conditions-in-parenthesis (insert ")"))
8894 (vhdl-template-generate-body margin label))))
d2ddb974 8895
5eabfe72
KH
8896(defun vhdl-template-if-then-use (kind)
8897 "Insert a sequential if statement."
8898 (interactive)
8899 (let ((margin (current-indentation))
8900 (start (point))
8901 label)
8902 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8903 (vhdl-insert-keyword "IF ")
8904 (vhdl-insert-keyword ": IF ")
8905 (goto-char start)
8906 (setq label (vhdl-template-field "[label]" nil t))
8907 (unless label (delete-char 2))
8908 (forward-word 1)
8909 (forward-char 1))
8910 (when vhdl-conditions-in-parenthesis (insert "("))
8911 (when (vhdl-template-field "condition" nil t start (point))
8912 (when vhdl-conditions-in-parenthesis (insert ")"))
8913 (vhdl-insert-keyword
8914 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
d2ddb974 8915 (indent-to margin)
5eabfe72
KH
8916 (vhdl-insert-keyword "END IF")
8917 (when label (insert " " label))
8918 (insert ";")
d2ddb974 8919 (forward-line -1)
5eabfe72
KH
8920 (indent-to (+ margin vhdl-basic-offset)))))
8921
8922(defun vhdl-template-if-then ()
8923 "Insert a sequential if statement."
8924 (interactive)
8925 (vhdl-template-if-then-use 'then))
8926
8927(defun vhdl-template-if-use ()
8928 "Insert a simultaneous if statement."
8929 (interactive)
8930 (vhdl-template-if-then-use 'use))
8931
8932(defun vhdl-template-instance ()
8933 "Insert a component instantiation statement."
8934 (interactive)
8935 (vhdl-template-component-inst))
d2ddb974 8936
5eabfe72 8937(defun vhdl-template-library ()
d2ddb974
KH
8938 "Insert a library specification."
8939 (interactive)
5eabfe72
KH
8940 (let ((margin (current-indentation))
8941 (start (point))
8942 name end-pos)
d2ddb974 8943 (vhdl-insert-keyword "LIBRARY ")
5eabfe72
KH
8944 (when (setq name (vhdl-template-field "names" nil t start (point)))
8945 (insert ";")
8946 (unless (string-match "," name)
8947 (setq end-pos (point))
8948 (insert "\n")
8949 (indent-to margin)
8950 (vhdl-insert-keyword "USE ")
8951 (insert name)
8952 (vhdl-insert-keyword "..ALL;")
8953 (backward-char 5)
8954 (if (vhdl-template-field "package name")
8955 (forward-char 5)
8956 (delete-region end-pos (+ (point) 5)))))))
8957
8958(defun vhdl-template-limit ()
8959 "Insert a limit."
d2ddb974 8960 (interactive)
5eabfe72
KH
8961 (let ((start (point)))
8962 (vhdl-insert-keyword "LIMIT ")
8963 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8964 t start (point))
8965 (vhdl-template-field "type")
8966 (vhdl-insert-keyword " WITH ")
8967 (vhdl-template-field "real expression" ";"))))
8968
8969(defun vhdl-template-loop ()
8970 "Insert a loop."
8971 (interactive)
8972 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8973 (cond ((eq char ?w)
8974 (vhdl-template-while-loop))
8975 ((eq char ?f)
8976 (vhdl-template-for-loop))
8977 (t (vhdl-template-bare-loop)))))
8978
8979(defun vhdl-template-bare-loop ()
8980 "Insert a loop."
8981 (interactive)
8982 (let ((margin (current-indentation))
8983 (start (point))
8984 label)
8985 (if (not (eq vhdl-optional-labels 'all))
8986 (vhdl-insert-keyword "LOOP ")
8987 (vhdl-insert-keyword ": LOOP ")
8988 (goto-char start)
8989 (setq label (vhdl-template-field "[label]" nil t))
8990 (unless label (delete-char 2))
8991 (forward-word 1)
8992 (delete-char 1))
d2ddb974
KH
8993 (insert "\n\n")
8994 (indent-to margin)
8995 (vhdl-insert-keyword "END LOOP")
5eabfe72 8996 (insert (if label (concat " " label ";") ";"))
d2ddb974 8997 (forward-line -1)
5eabfe72 8998 (indent-to (+ margin vhdl-basic-offset))))
d2ddb974 8999
5eabfe72
KH
9000(defun vhdl-template-map (&optional start optional secondary)
9001 "Insert a map specification with association list."
d2ddb974 9002 (interactive)
5eabfe72
KH
9003 (let ((start (or start (point)))
9004 margin end-pos)
9005 (vhdl-insert-keyword "MAP (")
9006 (if (not vhdl-association-list-with-formals)
9007 (if (vhdl-template-field
9008 (concat (and optional "[") "association list" (and optional "]"))
9009 ")" (or (not secondary) optional)
9010 (and (not secondary) start) (point))
9011 t
9012 (if (and optional secondary) (delete-region start (point)))
9013 nil)
9014 (if vhdl-argument-list-indent
9015 (setq margin (current-column))
9016 (setq margin (+ (current-indentation) vhdl-basic-offset))
9017 (insert "\n")
9018 (indent-to margin))
9019 (if (vhdl-template-field
9020 (concat (and optional "[") "formal" (and optional "]"))
9021 " => " (or (not secondary) optional)
9022 (and (not secondary) start) (point))
9023 (progn
9024 (vhdl-template-field "actual" ",")
9025 (setq end-pos (point))
9026 (insert "\n")
9027 (indent-to margin)
9028 (while (vhdl-template-field "[formal]" " => " t)
9029 (vhdl-template-field "actual" ",")
9030 (setq end-pos (point))
9031 (insert "\n")
9032 (indent-to margin))
9033 (delete-region end-pos (point))
d355a0b7 9034 (delete-char -1)
5eabfe72 9035 (insert ")")
3dcb36b7 9036 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9037 t)
9038 (when (and optional secondary) (delete-region start (point)))
9039 nil))))
d2ddb974 9040
5eabfe72 9041(defun vhdl-template-modify (&optional noerror)
d2ddb974
KH
9042 "Actualize modification date."
9043 (interactive)
3dcb36b7
JB
9044 (vhdl-prepare-search-2
9045 (save-excursion
9046 (goto-char (point-min))
9047 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9048 (progn (delete-region (point) (progn (end-of-line) (point)))
9049 (vhdl-template-insert-date))
9050 (unless noerror
a867ead0
DG
9051 (error "ERROR: Modification date prefix string \"%s\" not found"
9052 vhdl-modify-date-prefix-string))))))
9053
5eabfe72
KH
9054
9055(defun vhdl-template-modify-noerror ()
9056 "Call `vhdl-template-modify' with NOERROR non-nil."
9057 (vhdl-template-modify t))
9058
9059(defun vhdl-template-nature ()
9060 "Insert a nature declaration."
9061 (interactive)
9062 (let ((start (point))
9063 name mid-pos end-pos)
9064 (vhdl-insert-keyword "NATURE ")
9065 (when (setq name (vhdl-template-field "name" nil t start (point)))
9066 (vhdl-insert-keyword " IS ")
9067 (let ((definition
9068 (upcase
9069 (or (vhdl-template-field
9070 "across type | ARRAY | RECORD")
9071 ""))))
9072 (cond ((equal definition "")
9073 (insert ";"))
9074 ((equal definition "ARRAY")
453cfeb3 9075 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9076 (vhdl-template-array 'nature t))
9077 ((equal definition "RECORD")
9078 (setq mid-pos (point-marker))
453cfeb3 9079 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9080 (vhdl-template-record 'nature name t))
9081 (t
9082 (vhdl-insert-keyword " ACROSS ")
9083 (vhdl-template-field "through type")
9084 (vhdl-insert-keyword " THROUGH ")
9085 (vhdl-template-field "reference name")
9086 (vhdl-insert-keyword " REFERENCE;")))
9087 (when mid-pos
9088 (setq end-pos (point-marker))
9089 (goto-char mid-pos)
9090 (end-of-line))
9091 (vhdl-comment-insert-inline)
9092 (when end-pos (goto-char end-pos))))))
9093
9094(defun vhdl-template-next ()
9095 "Insert a next statement."
d2ddb974 9096 (interactive)
3dcb36b7
JB
9097 (let ((start (point)))
9098 (vhdl-insert-keyword "NEXT ")
9099 (if (vhdl-template-field "[loop label]" nil t start (point))
9100 (let ((position (point)))
9101 (vhdl-insert-keyword " WHEN ")
9102 (when vhdl-conditions-in-parenthesis (insert "("))
9103 (if (vhdl-template-field "[condition]" nil t)
9104 (when vhdl-conditions-in-parenthesis (insert ")"))
9105 (delete-region position (point))))
9106 (delete-char -1))
5eabfe72
KH
9107 (insert ";")))
9108
9109(defun vhdl-template-others ()
9110 "Insert an others aggregate."
9111 (interactive)
3dcb36b7
JB
9112 (let ((start (point)))
9113 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9114 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9115 (vhdl-insert-keyword "OTHERS => '")
9116 (when (vhdl-template-field "value" nil t start (point))
9117 (insert "')")))
9118 (vhdl-insert-keyword "OTHERS "))))
d2ddb974 9119
5eabfe72 9120(defun vhdl-template-package (&optional kind)
d2ddb974
KH
9121 "Insert a package specification or body."
9122 (interactive)
5eabfe72
KH
9123 (let ((margin (current-indentation))
9124 (start (point))
9125 name body position)
d2ddb974 9126 (vhdl-insert-keyword "PACKAGE ")
5eabfe72
KH
9127 (setq body (if kind (eq kind 'body)
9128 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
3dcb36b7
JB
9129 (when body
9130 (vhdl-insert-keyword "BODY ")
9131 (when (save-excursion
9132 (vhdl-prepare-search-1
9133 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9134 (insert (setq name (match-string 1)))))
9135 (when (or name
9136 (setq name (vhdl-template-field "name" nil t start (point))))
5eabfe72
KH
9137 (vhdl-insert-keyword " IS\n")
9138 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9139 (indent-to (+ margin vhdl-basic-offset))
9140 (setq position (point))
9141 (insert "\n")
9142 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9143 (indent-to margin)
9144 (vhdl-insert-keyword "END ")
9145 (unless (vhdl-standard-p '87)
9146 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9147 (insert (or name "") ";")
9148 (goto-char position))))
d2ddb974 9149
5eabfe72
KH
9150(defun vhdl-template-package-decl ()
9151 "Insert a package specification."
d2ddb974 9152 (interactive)
5eabfe72 9153 (vhdl-template-package 'decl))
d2ddb974 9154
5eabfe72
KH
9155(defun vhdl-template-package-body ()
9156 "Insert a package body."
d2ddb974 9157 (interactive)
5eabfe72 9158 (vhdl-template-package 'body))
d2ddb974 9159
5eabfe72
KH
9160(defun vhdl-template-port ()
9161 "Insert a port declaration, or port map in instantiation statements."
d2ddb974 9162 (interactive)
3dcb36b7
JB
9163 (let ((start (point)))
9164 (vhdl-prepare-search-1
5eabfe72
KH
9165 (cond
9166 ((and (save-excursion ; entity declaration
9167 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9168 (equal "ENTITY" (upcase (match-string 1))))
9169 (vhdl-template-port-list nil))
9170 ((or (save-excursion
9171 (or (beginning-of-line)
9172 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 9173 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
9174 (vhdl-insert-keyword "PORT ")
9175 (vhdl-template-map start))
9176 (t (vhdl-template-port-list nil))))))
9177
9178(defun vhdl-template-procedural ()
9179 "Insert a procedural."
9180 (interactive)
9181 (let ((margin (current-indentation))
9182 (start (point))
9183 (case-fold-search t)
9184 label)
9185 (vhdl-insert-keyword "PROCEDURAL ")
9186 (when (memq vhdl-optional-labels '(process all))
9187 (goto-char start)
9188 (insert ": ")
9189 (goto-char start)
9190 (setq label (vhdl-template-field "[label]" nil t))
9191 (unless label (delete-char 2))
9192 (forward-word 1)
9193 (forward-char 1))
9194 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
3dcb36b7 9195 (insert "\n")
5eabfe72
KH
9196 (vhdl-template-begin-end "PROCEDURAL" label margin)
9197 (vhdl-comment-block)))
9198
9199(defun vhdl-template-procedure (&optional kind)
9200 "Insert a procedure declaration or body."
9201 (interactive)
9202 (let ((margin (current-indentation))
9203 (start (point))
9204 name)
9205 (vhdl-insert-keyword "PROCEDURE ")
9206 (when (setq name (vhdl-template-field "name" nil t start (point)))
9207 (vhdl-template-argument-list)
9208 (if (if kind (eq kind 'body)
9209 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9210 (progn (vhdl-insert-keyword " IS")
9211 (when vhdl-auto-align
3dcb36b7
JB
9212 (vhdl-align-region-groups start (point) 1))
9213 (end-of-line) (insert "\n")
5eabfe72
KH
9214 (vhdl-template-begin-end
9215 (unless (vhdl-standard-p '87) "PROCEDURE")
9216 name margin)
9217 (vhdl-comment-block))
9218 (insert ";")
3dcb36b7 9219 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9220 (end-of-line)))))
9221
9222(defun vhdl-template-procedure-decl ()
9223 "Insert a procedure declaration."
9224 (interactive)
9225 (vhdl-template-procedure 'decl))
d2ddb974 9226
5eabfe72
KH
9227(defun vhdl-template-procedure-body ()
9228 "Insert a procedure body."
9229 (interactive)
9230 (vhdl-template-procedure 'body))
9231
9232(defun vhdl-template-process (&optional kind)
9233 "Insert a process."
9234 (interactive)
9235 (let ((margin (current-indentation))
9236 (start (point))
5eabfe72
KH
9237 label seq input-signals clock reset final-pos)
9238 (setq seq (if kind (eq kind 'seq)
9239 (eq (vhdl-decision-query
9240 "process" "(c)ombinational or (s)equential?" t) ?s)))
9241 (vhdl-insert-keyword "PROCESS ")
9242 (when (memq vhdl-optional-labels '(process all))
9243 (goto-char start)
9244 (insert ": ")
9245 (goto-char start)
9246 (setq label (vhdl-template-field "[label]" nil t))
9247 (unless label (delete-char 2))
9248 (forward-word 1)
9249 (forward-char 1))
9250 (insert "(")
9251 (if (not seq)
9252 (unless (setq input-signals
9253 (vhdl-template-field "[sensitivity list]" ")" t))
9254 (setq input-signals "")
9255 (delete-char -2))
9256 (setq clock (or (and (not (equal "" vhdl-clock-name))
9257 (progn (insert vhdl-clock-name) vhdl-clock-name))
9258 (vhdl-template-field "clock name") "<clock>"))
9259 (when (eq vhdl-reset-kind 'async)
9260 (insert ", ")
9261 (setq reset (or (and (not (equal "" vhdl-reset-name))
9262 (progn (insert vhdl-reset-name) vhdl-reset-name))
9263 (vhdl-template-field "reset name") "<reset>")))
9264 (insert ")"))
9265 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 9266 (insert "\n")
5eabfe72
KH
9267 (vhdl-template-begin-end "PROCESS" label margin)
9268 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9269 (when vhdl-prompt-for-comments
9270 (setq final-pos (point-marker))
3dcb36b7
JB
9271 (vhdl-prepare-search-2
9272 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9273 (vhdl-re-search-backward "\\<process\\>" nil t))
5eabfe72
KH
9274 (end-of-line -0)
9275 (if (bobp)
9276 (progn (insert "\n") (forward-line -1))
9277 (insert "\n"))
9278 (indent-to margin)
9279 (insert "-- purpose: ")
9280 (if (not (vhdl-template-field "[description]" nil t))
9281 (vhdl-line-kill-entire)
9282 (insert "\n")
9283 (indent-to margin)
9284 (insert "-- type : ")
9285 (insert (if seq "sequential" "combinational") "\n")
9286 (indent-to margin)
9287 (insert "-- inputs : ")
9288 (if (not seq)
9289 (insert input-signals)
9290 (insert clock ", ")
9291 (when reset (insert reset ", "))
9292 (unless (vhdl-template-field "[signal names]" nil t)
9293 (delete-char -2)))
9294 (insert "\n")
9295 (indent-to margin)
9296 (insert "-- outputs: ")
9297 (vhdl-template-field "[signal names]" nil t))))
9298 (goto-char final-pos))))
9299
9300(defun vhdl-template-process-comb ()
9301 "Insert a combinational process."
9302 (interactive)
9303 (vhdl-template-process 'comb))
9304
9305(defun vhdl-template-process-seq ()
9306 "Insert a sequential process."
9307 (interactive)
9308 (vhdl-template-process 'seq))
9309
9310(defun vhdl-template-quantity ()
9311 "Insert a quantity declaration."
9312 (interactive)
9313 (if (vhdl-in-argument-list-p)
9314 (let ((start (point)))
9315 (vhdl-insert-keyword "QUANTITY ")
9316 (when (vhdl-template-field "names" nil t start (point))
9317 (insert " : ")
9318 (vhdl-template-field "[IN | OUT]" " " t)
9319 (vhdl-template-field "type")
9320 (insert ";")
9321 (vhdl-comment-insert-inline)))
9322 (let ((char (vhdl-decision-query
9323 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9324 (cond ((eq char ?f) (vhdl-template-quantity-free))
9325 ((eq char ?b) (vhdl-template-quantity-branch))
9326 ((eq char ?s) (vhdl-template-quantity-source))
9327 (t (vhdl-template-undo (point) (point)))))))
9328
9329(defun vhdl-template-quantity-free ()
9330 "Insert a free quantity declaration."
9331 (interactive)
9332 (vhdl-insert-keyword "QUANTITY ")
9333 (vhdl-template-field "names")
9334 (insert " : ")
9335 (vhdl-template-field "type")
9336 (let ((position (point)))
9337 (insert " := ")
9338 (unless (vhdl-template-field "[initialization]" nil t)
9339 (delete-region position (point)))
9340 (insert ";")
9341 (vhdl-comment-insert-inline)))
9342
9343(defun vhdl-template-quantity-branch ()
9344 "Insert a branch quantity declaration."
9345 (interactive)
9346 (let (position)
9347 (vhdl-insert-keyword "QUANTITY ")
9348 (when (vhdl-template-field "[across names]" " " t)
9349 (vhdl-insert-keyword "ACROSS "))
9350 (when (vhdl-template-field "[through names]" " " t)
9351 (vhdl-insert-keyword "THROUGH "))
9352 (vhdl-template-field "plus terminal name")
9353 (setq position (point))
9354 (vhdl-insert-keyword " TO ")
9355 (unless (vhdl-template-field "[minus terminal name]" nil t)
9356 (delete-region position (point)))
9357 (insert ";")
9358 (vhdl-comment-insert-inline)))
9359
9360(defun vhdl-template-quantity-source ()
9361 "Insert a source quantity declaration."
9362 (interactive)
9363 (vhdl-insert-keyword "QUANTITY ")
9364 (vhdl-template-field "names")
9365 (insert " : ")
9366 (vhdl-template-field "type" " ")
9367 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9368 (progn (vhdl-insert-keyword "NOISE ")
9369 (vhdl-template-field "power expression"))
9370 (vhdl-insert-keyword "SPECTRUM ")
9371 (vhdl-template-field "magnitude expression" ", ")
9372 (vhdl-template-field "phase expression"))
9373 (insert ";")
9374 (vhdl-comment-insert-inline))
9375
9376(defun vhdl-template-record (kind &optional name secondary)
d2ddb974
KH
9377 "Insert a record type declaration."
9378 (interactive)
9379 (let ((margin (current-column))
9380 (start (point))
9381 (first t))
9382 (vhdl-insert-keyword "RECORD\n")
9383 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9384 (when (or (vhdl-template-field "element names"
9385 nil (not secondary) start (point))
9386 secondary)
9387 (while (or first (vhdl-template-field "[element names]" nil t))
9388 (insert " : ")
9389 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9390 (vhdl-comment-insert-inline)
9391 (insert "\n")
d2ddb974 9392 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 9393 (setq first nil))
453cfeb3 9394 (delete-region (line-beginning-position) (point))
d2ddb974 9395 (indent-to margin)
5eabfe72
KH
9396 (vhdl-insert-keyword "END RECORD")
9397 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9398 (insert ";")
3dcb36b7 9399 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9400
5eabfe72
KH
9401(defun vhdl-template-report ()
9402 "Insert a report statement."
9403 (interactive)
9404 (let ((start (point)))
9405 (vhdl-insert-keyword "REPORT ")
9406 (if (equal "\"\"" (vhdl-template-field
9407 "string expression" nil t start (point) t))
d355a0b7 9408 (delete-char -2)
5eabfe72
KH
9409 (setq start (point))
9410 (vhdl-insert-keyword " SEVERITY ")
9411 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9412 (delete-region start (point)))
9413 (insert ";"))))
9414
9415(defun vhdl-template-return ()
d2ddb974
KH
9416 "Insert a return statement."
9417 (interactive)
3dcb36b7
JB
9418 (let ((start (point)))
9419 (vhdl-insert-keyword "RETURN ")
9420 (unless (vhdl-template-field "[expression]" nil t start (point))
9421 (delete-char -1))
9422 (insert ";")))
d2ddb974 9423
5eabfe72 9424(defun vhdl-template-selected-signal-asst ()
d2ddb974
KH
9425 "Insert a selected signal assignment."
9426 (interactive)
5eabfe72
KH
9427 (let ((margin (current-indentation))
9428 (start (point))
9429 (choices t))
d2ddb974 9430 (let ((position (point)))
5eabfe72 9431 (vhdl-insert-keyword " SELECT ")
d2ddb974
KH
9432 (goto-char position))
9433 (vhdl-insert-keyword "WITH ")
5eabfe72
KH
9434 (when (vhdl-template-field "selector expression"
9435 nil t start (+ (point) 7))
9436 (forward-word 1)
9437 (delete-char 1)
d2ddb974
KH
9438 (insert "\n")
9439 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9440 (vhdl-template-field "target signal" " <= ")
9441; (vhdl-template-field "[GUARDED] [TRANSPORT]")
d2ddb974
KH
9442 (insert "\n")
9443 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9444 (vhdl-template-field "waveform")
9445 (vhdl-insert-keyword " WHEN ")
9446 (vhdl-template-field "choices" ",")
9447 (insert "\n")
9448 (indent-to (+ margin vhdl-basic-offset))
9449 (while (and choices (vhdl-template-field "[waveform]" nil t))
d2ddb974 9450 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
9451 (if (setq choices (vhdl-template-field "[choices]" "," t))
9452 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9453 (vhdl-insert-keyword "OTHERS")))
9454 (when choices
d2ddb974
KH
9455 (fixup-whitespace)
9456 (delete-char -2))
9457 (insert ";")
3dcb36b7 9458 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9459
5eabfe72 9460(defun vhdl-template-signal ()
d2ddb974
KH
9461 "Insert a signal declaration."
9462 (interactive)
5eabfe72
KH
9463 (let ((start (point))
9464 (in-arglist (vhdl-in-argument-list-p)))
9465 (vhdl-insert-keyword "SIGNAL ")
9466 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9467 (insert " : ")
5eabfe72
KH
9468 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9469 (vhdl-template-field "type")
d2ddb974 9470 (if in-arglist
5eabfe72
KH
9471 (progn (insert ";")
9472 (vhdl-comment-insert-inline))
d2ddb974
KH
9473 (let ((position (point)))
9474 (insert " := ")
5eabfe72
KH
9475 (unless (vhdl-template-field "[initialization]" nil t)
9476 (delete-region position (point)))
9477 (insert ";")
9478 (vhdl-comment-insert-inline))))))
9479
9480(defun vhdl-template-subnature ()
9481 "Insert a subnature declaration."
9482 (interactive)
9483 (let ((start (point))
9484 position)
9485 (vhdl-insert-keyword "SUBNATURE ")
9486 (when (vhdl-template-field "name" nil t start (point))
9487 (vhdl-insert-keyword " IS ")
9488 (vhdl-template-field "nature" " (")
9489 (if (vhdl-template-field "[index range]" nil t)
9490 (insert ")")
9491 (delete-char -2))
9492 (setq position (point))
9493 (vhdl-insert-keyword " TOLERANCE ")
9494 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9495 nil t nil nil t))
9496 (delete-region position (point))
9497 (vhdl-insert-keyword " ACROSS ")
9498 (vhdl-template-field "string expression" nil nil nil nil t)
9499 (vhdl-insert-keyword " THROUGH"))
9500 (insert ";")
9501 (vhdl-comment-insert-inline))))
9502
9503(defun vhdl-template-subprogram-body ()
9504 "Insert a subprogram body."
9505 (interactive)
9506 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9507 (vhdl-template-function-body)
9508 (vhdl-template-procedure-body)))
d2ddb974 9509
5eabfe72
KH
9510(defun vhdl-template-subprogram-decl ()
9511 "Insert a subprogram declaration."
9512 (interactive)
9513 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9514 (vhdl-template-function-decl)
9515 (vhdl-template-procedure-decl)))
9516
9517(defun vhdl-template-subtype ()
d2ddb974
KH
9518 "Insert a subtype declaration."
9519 (interactive)
5eabfe72
KH
9520 (let ((start (point)))
9521 (vhdl-insert-keyword "SUBTYPE ")
9522 (when (vhdl-template-field "name" nil t start (point))
9523 (vhdl-insert-keyword " IS ")
9524 (vhdl-template-field "type" " ")
9525 (unless
9526 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
d2ddb974 9527 (delete-char -1))
5eabfe72
KH
9528 (insert ";")
9529 (vhdl-comment-insert-inline))))
d2ddb974 9530
5eabfe72
KH
9531(defun vhdl-template-terminal ()
9532 "Insert a terminal declaration."
d2ddb974 9533 (interactive)
5eabfe72
KH
9534 (let ((start (point)))
9535 (vhdl-insert-keyword "TERMINAL ")
9536 (when (vhdl-template-field "names" nil t start (point))
9537 (insert " : ")
9538 (vhdl-template-field "nature")
9539 (insert ";")
9540 (vhdl-comment-insert-inline))))
d2ddb974 9541
5eabfe72
KH
9542(defun vhdl-template-type ()
9543 "Insert a type declaration."
9544 (interactive)
9545 (let ((start (point))
9546 name mid-pos end-pos)
9547 (vhdl-insert-keyword "TYPE ")
9548 (when (setq name (vhdl-template-field "name" nil t start (point)))
9549 (vhdl-insert-keyword " IS ")
9550 (let ((definition
9551 (upcase
9552 (or (vhdl-template-field
9553 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9554 ""))))
9555 (cond ((equal definition "")
d355a0b7 9556 (delete-char -4)
5eabfe72
KH
9557 (insert ";"))
9558 ((equal definition "ARRAY")
453cfeb3 9559 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9560 (vhdl-template-array 'type t))
9561 ((equal definition "RECORD")
9562 (setq mid-pos (point-marker))
453cfeb3 9563 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9564 (vhdl-template-record 'type name t))
9565 ((equal definition "ACCESS")
9566 (insert " ")
9567 (vhdl-template-field "type" ";"))
9568 ((equal definition "FILE")
9569 (vhdl-insert-keyword " OF ")
9570 (vhdl-template-field "type" ";"))
9571 (t (insert ";")))
9572 (when mid-pos
9573 (setq end-pos (point-marker))
9574 (goto-char mid-pos)
9575 (end-of-line))
9576 (vhdl-comment-insert-inline)
9577 (when end-pos (goto-char end-pos))))))
9578
9579(defun vhdl-template-use ()
d2ddb974
KH
9580 "Insert a use clause."
9581 (interactive)
3dcb36b7
JB
9582 (let ((start (point)))
9583 (vhdl-prepare-search-1
5eabfe72
KH
9584 (vhdl-insert-keyword "USE ")
9585 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9586 (vhdl-insert-keyword "..ALL;")
9587 (backward-char 6)
9588 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9589 (forward-char 1)
9590 (vhdl-template-field "package name")
9591 (forward-char 5))))))
9592
9593(defun vhdl-template-variable ()
d2ddb974
KH
9594 "Insert a variable declaration."
9595 (interactive)
5eabfe72 9596 (let ((start (point))
5eabfe72 9597 (in-arglist (vhdl-in-argument-list-p)))
3dcb36b7 9598 (vhdl-prepare-search-2
5eabfe72 9599 (if (or (save-excursion
3dcb36b7 9600 (and (vhdl-re-search-backward
5eabfe72
KH
9601 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9602 nil t)
9603 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9604 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9605 (vhdl-insert-keyword "VARIABLE ")
9606 (vhdl-insert-keyword "SHARED VARIABLE ")))
9607 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9608 (insert " : ")
5eabfe72
KH
9609 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9610 (vhdl-template-field "type")
d2ddb974 9611 (if in-arglist
5eabfe72
KH
9612 (progn (insert ";")
9613 (vhdl-comment-insert-inline))
d2ddb974
KH
9614 (let ((position (point)))
9615 (insert " := ")
5eabfe72
KH
9616 (unless (vhdl-template-field "[initialization]" nil t)
9617 (delete-region position (point)))
9618 (insert ";")
9619 (vhdl-comment-insert-inline))))))
d2ddb974 9620
5eabfe72 9621(defun vhdl-template-wait ()
d2ddb974
KH
9622 "Insert a wait statement."
9623 (interactive)
9624 (vhdl-insert-keyword "WAIT ")
5eabfe72
KH
9625 (unless (vhdl-template-field
9626 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9627 nil t)
9628 (delete-char -1))
9629 (insert ";"))
d2ddb974 9630
5eabfe72 9631(defun vhdl-template-when ()
d2ddb974
KH
9632 "Indent correctly if within a case statement."
9633 (interactive)
9634 (let ((position (point))
5eabfe72 9635 margin)
3dcb36b7 9636 (vhdl-prepare-search-2
5eabfe72 9637 (if (and (= (current-column) (current-indentation))
3dcb36b7 9638 (vhdl-re-search-forward "\\<end\\>" nil t)
5eabfe72
KH
9639 (looking-at "\\s-*\\<case\\>"))
9640 (progn
9641 (setq margin (current-indentation))
9642 (goto-char position)
9643 (delete-horizontal-space)
9644 (indent-to (+ margin vhdl-basic-offset)))
9645 (goto-char position)))
9646 (vhdl-insert-keyword "WHEN ")))
9647
9648(defun vhdl-template-while-loop ()
9649 "Insert a while loop."
d2ddb974 9650 (interactive)
5eabfe72
KH
9651 (let* ((margin (current-indentation))
9652 (start (point))
9653 label)
9654 (if (not (eq vhdl-optional-labels 'all))
9655 (vhdl-insert-keyword "WHILE ")
9656 (vhdl-insert-keyword ": WHILE ")
9657 (goto-char start)
9658 (setq label (vhdl-template-field "[label]" nil t))
9659 (unless label (delete-char 2))
9660 (forward-word 1)
9661 (forward-char 1))
9662 (when vhdl-conditions-in-parenthesis (insert "("))
9663 (when (vhdl-template-field "condition" nil t start (point))
9664 (when vhdl-conditions-in-parenthesis (insert ")"))
d2ddb974
KH
9665 (vhdl-insert-keyword " LOOP\n\n")
9666 (indent-to margin)
9667 (vhdl-insert-keyword "END LOOP")
5eabfe72 9668 (insert (if label (concat " " label ";") ";"))
d2ddb974 9669 (forward-line -1)
5eabfe72 9670 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 9671
5eabfe72 9672(defun vhdl-template-with ()
d2ddb974
KH
9673 "Insert a with statement (i.e. selected signal assignment)."
9674 (interactive)
3dcb36b7
JB
9675 (vhdl-prepare-search-1
9676 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9677 (equal ";" (match-string 1)))
9678 (vhdl-template-selected-signal-asst)
9679 (vhdl-insert-keyword "WITH "))))
5eabfe72
KH
9680
9681;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9682;; Special templates
9683
9684(defun vhdl-template-clocked-wait ()
9685 "Insert a wait statement for rising/falling clock edge."
9686 (interactive)
9687 (let ((start (point))
9688 clock)
9689 (vhdl-insert-keyword "WAIT UNTIL ")
9690 (when (setq clock
9691 (or (and (not (equal "" vhdl-clock-name))
9692 (progn (insert vhdl-clock-name) vhdl-clock-name))
9693 (vhdl-template-field "clock name" nil t start (point))))
9694 (insert "'event")
9695 (vhdl-insert-keyword " AND ")
9696 (insert clock)
9697 (insert
9698 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9699 (vhdl-comment-insert-inline
9700 (concat (if vhdl-clock-rising-edge "rising" "falling")
9701 " clock edge")))))
9702
9703(defun vhdl-template-seq-process (clock reset)
9704 "Insert a template for the body of a sequential process."
9705 (let ((margin (current-indentation))
9706 position)
d2ddb974 9707 (vhdl-insert-keyword "IF ")
5eabfe72
KH
9708 (when (eq vhdl-reset-kind 'async)
9709 (insert reset " = "
9710 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9711 (vhdl-insert-keyword " THEN")
9712 (vhdl-comment-insert-inline
9713 (concat "asynchronous reset (active "
9714 (if vhdl-reset-active-high "high" "low") ")"))
9715 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9716 (setq position (point))
9717 (insert "\n") (indent-to margin)
9718 (vhdl-insert-keyword "ELSIF "))
9719 (if (eq vhdl-clock-edge-condition 'function)
9720 (insert (if vhdl-clock-rising-edge "rising" "falling")
9721 "_edge(" clock ")")
9722 (insert clock "'event")
9723 (vhdl-insert-keyword " AND ")
9724 (insert clock " = "
9725 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9726 (vhdl-insert-keyword " THEN")
9727 (vhdl-comment-insert-inline
9728 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9729 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9730 (when (eq vhdl-reset-kind 'sync)
9731 (vhdl-insert-keyword "IF ")
9732 (setq reset (or (and (not (equal "" vhdl-reset-name))
9733 (progn (insert vhdl-reset-name) vhdl-reset-name))
9734 (vhdl-template-field "reset name") "<reset>"))
9735 (insert " = "
9736 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9737 (vhdl-insert-keyword " THEN")
9738 (vhdl-comment-insert-inline
9739 (concat "synchronous reset (active "
9740 (if vhdl-reset-active-high "high" "low") ")"))
9741 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9742 (setq position (point))
9743 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9744 (vhdl-insert-keyword "ELSE")
9745 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9746 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9747 (vhdl-insert-keyword "END IF;"))
9748 (when (eq vhdl-reset-kind 'none)
9749 (setq position (point)))
9750 (insert "\n") (indent-to margin)
d2ddb974 9751 (vhdl-insert-keyword "END IF;")
5eabfe72
KH
9752 (goto-char position)
9753 reset))
d2ddb974 9754
5eabfe72
KH
9755(defun vhdl-template-standard-package (library package)
9756 "Insert specification of a standard package. Include a library
9757specification, if not already there."
3dcb36b7
JB
9758 (let ((margin (current-indentation)))
9759 (unless (equal library "std")
9760 (unless (or (save-excursion
9761 (vhdl-prepare-search-1
9762 (and (not (bobp))
9763 (re-search-backward
9764 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9765 library "\\|end\\)\\>") nil t)
9766 (match-string 2))))
9767 (equal (downcase library) "work"))
9768 (vhdl-insert-keyword "LIBRARY ")
0a2e512a
RF
9769 (insert library ";")
9770 (when package
9771 (insert "\n")
9772 (indent-to margin)))
9773 (when package
9774 (vhdl-insert-keyword "USE ")
9775 (insert library "." package)
9776 (vhdl-insert-keyword ".ALL;")))))
d2ddb974 9777
5eabfe72
KH
9778(defun vhdl-template-package-math-complex ()
9779 "Insert specification of `math_complex' package."
d2ddb974 9780 (interactive)
5eabfe72 9781 (vhdl-template-standard-package "ieee" "math_complex"))
d2ddb974 9782
5eabfe72
KH
9783(defun vhdl-template-package-math-real ()
9784 "Insert specification of `math_real' package."
d2ddb974 9785 (interactive)
5eabfe72 9786 (vhdl-template-standard-package "ieee" "math_real"))
d2ddb974 9787
5eabfe72
KH
9788(defun vhdl-template-package-numeric-bit ()
9789 "Insert specification of `numeric_bit' package."
d2ddb974 9790 (interactive)
5eabfe72 9791 (vhdl-template-standard-package "ieee" "numeric_bit"))
d2ddb974 9792
5eabfe72
KH
9793(defun vhdl-template-package-numeric-std ()
9794 "Insert specification of `numeric_std' package."
d2ddb974 9795 (interactive)
5eabfe72 9796 (vhdl-template-standard-package "ieee" "numeric_std"))
d2ddb974 9797
5eabfe72
KH
9798(defun vhdl-template-package-std-logic-1164 ()
9799 "Insert specification of `std_logic_1164' package."
9800 (interactive)
9801 (vhdl-template-standard-package "ieee" "std_logic_1164"))
d2ddb974 9802
5eabfe72
KH
9803(defun vhdl-template-package-std-logic-arith ()
9804 "Insert specification of `std_logic_arith' package."
9805 (interactive)
9806 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9807
9808(defun vhdl-template-package-std-logic-misc ()
9809 "Insert specification of `std_logic_misc' package."
9810 (interactive)
9811 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9812
9813(defun vhdl-template-package-std-logic-signed ()
9814 "Insert specification of `std_logic_signed' package."
9815 (interactive)
9816 (vhdl-template-standard-package "ieee" "std_logic_signed"))
d2ddb974 9817
5eabfe72
KH
9818(defun vhdl-template-package-std-logic-textio ()
9819 "Insert specification of `std_logic_textio' package."
9820 (interactive)
9821 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9822
9823(defun vhdl-template-package-std-logic-unsigned ()
9824 "Insert specification of `std_logic_unsigned' package."
9825 (interactive)
9826 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9827
9828(defun vhdl-template-package-textio ()
9829 "Insert specification of `textio' package."
9830 (interactive)
9831 (vhdl-template-standard-package "std" "textio"))
9832
9833(defun vhdl-template-directive (directive)
9834 "Insert directive."
9835 (unless (= (current-indentation) (current-column))
9836 (delete-horizontal-space)
9837 (insert " "))
9838 (insert "-- pragma " directive))
9839
9840(defun vhdl-template-directive-translate-on ()
9841 "Insert directive 'translate_on'."
9842 (interactive)
9843 (vhdl-template-directive "translate_on"))
9844
9845(defun vhdl-template-directive-translate-off ()
9846 "Insert directive 'translate_off'."
9847 (interactive)
9848 (vhdl-template-directive "translate_off"))
9849
9850(defun vhdl-template-directive-synthesis-on ()
9851 "Insert directive 'synthesis_on'."
9852 (interactive)
9853 (vhdl-template-directive "synthesis_on"))
9854
9855(defun vhdl-template-directive-synthesis-off ()
9856 "Insert directive 'synthesis_off'."
9857 (interactive)
9858 (vhdl-template-directive "synthesis_off"))
9859
3dcb36b7
JB
9860;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9861;; Header and footer templates
9862
9863(defun vhdl-template-header (&optional file-title)
9864 "Insert a VHDL file header."
9865 (interactive)
9866 (unless (equal vhdl-file-header "")
9867 (let (pos)
9868 (save-excursion
9869 (goto-char (point-min))
9870 (vhdl-insert-string-or-file vhdl-file-header)
9871 (setq pos (point-marker)))
9872 (vhdl-template-replace-header-keywords
9873 (point-min-marker) pos file-title))))
9874
9875(defun vhdl-template-footer ()
9876 "Insert a VHDL file footer."
9877 (interactive)
9878 (unless (equal vhdl-file-footer "")
9879 (let (pos)
9880 (save-excursion
9881 (goto-char (point-max))
9882 (setq pos (point-marker))
9883 (vhdl-insert-string-or-file vhdl-file-footer)
9884 (unless (= (preceding-char) ?\n)
9885 (insert "\n")))
9886 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9887
9888(defun vhdl-template-replace-header-keywords (beg end &optional file-title
9889 is-model)
9890 "Replace keywords in header and footer."
9891 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9892 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9893 pos)
9894 (vhdl-prepare-search-2
9895 (save-excursion
9896 (goto-char beg)
9897 (while (search-forward "<projectdesc>" end t)
9898 (replace-match project-desc t t))
9899 (goto-char beg)
9900 (while (search-forward "<filename>" end t)
9901 (replace-match (buffer-name) t t))
9902 (goto-char beg)
9903 (while (search-forward "<copyright>" end t)
9904 (replace-match vhdl-copyright-string t t))
9905 (goto-char beg)
9906 (while (search-forward "<author>" end t)
9907 (replace-match "" t t)
9908 (insert (user-full-name))
9909 (when user-mail-address (insert " <" user-mail-address ">")))
9910 (goto-char beg)
9911 (while (search-forward "<login>" end t)
9912 (replace-match (user-login-name) t t))
9913 (goto-char beg)
9914 (while (search-forward "<project>" end t)
9915 (replace-match project-title t t))
9916 (goto-char beg)
9917 (while (search-forward "<company>" end t)
9918 (replace-match vhdl-company-name t t))
9919 (goto-char beg)
9920 (while (search-forward "<platform>" end t)
9921 (replace-match vhdl-platform-spec t t))
9922 (goto-char beg)
9923 (while (search-forward "<standard>" end t)
9924 (replace-match
9925 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9926 ((vhdl-standard-p '93) "'93"))
9927 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9928 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9929 (goto-char beg)
9930 ;; Replace <RCS> with $, so that RCS for the source is
9931 ;; not over-enthusiastic with replacements
9932 (while (search-forward "<RCS>" end t)
9933 (replace-match "$" nil t))
9934 (goto-char beg)
9935 (while (search-forward "<date>" end t)
9936 (replace-match "" t t)
9937 (vhdl-template-insert-date))
9938 (goto-char beg)
9939 (while (search-forward "<year>" end t)
9940 (replace-match (format-time-string "%Y" nil) t t))
9941 (goto-char beg)
9942 (when file-title
9943 (while (search-forward "<title string>" end t)
9944 (replace-match file-title t t))
9945 (goto-char beg))
9946 (let (string)
9947 (while
9948 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9949 (setq string (read-string (concat (match-string 1) ": ")))
9950 (replace-match string t t)))
9951 (goto-char beg)
9952 (when (and (not is-model) (search-forward "<cursor>" end t))
9953 (replace-match "" t t)
9954 (setq pos (point))))
9955 (when pos (goto-char pos))
9956 (unless is-model
9957 (when (or (not project-title) (equal project-title ""))
9958 (message "You can specify a project title in user option `vhdl-project-alist'"))
9959 (when (or (not project-desc) (equal project-desc ""))
9960 (message "You can specify a project description in user option `vhdl-project-alist'"))
9961 (when (equal vhdl-platform-spec "")
9962 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9963 (when (equal vhdl-company-name "")
9964 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9965
5eabfe72
KH
9966;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9967;; Comment templates and functions
9968
9969(defun vhdl-comment-indent ()
9970 "Indent comments."
9971 (let* ((position (point))
9972 (col
9973 (progn
9974 (forward-line -1)
9975 (if (re-search-forward "--" position t)
9976 (- (current-column) 2) ; existing comment at bol stays there
9977 (goto-char position)
9978 (skip-chars-backward " \t")
9979 (max comment-column ; else indent to comment column
9980 (1+ (current-column))))))) ; except leave at least one space
9981 (goto-char position)
9982 col))
9983
9984(defun vhdl-comment-insert ()
d2ddb974 9985 "Start a comment at the end of the line.
5eabfe72
KH
9986If on line with code, indent at least `comment-column'.
9987If starting after end-comment-column, start a new line."
d2ddb974 9988 (interactive)
5eabfe72
KH
9989 (when (> (current-column) end-comment-column) (newline-and-indent))
9990 (if (or (looking-at "\\s-*$") ; end of line
d2ddb974
KH
9991 (and (not unread-command-events) ; called with key binding or menu
9992 (not (end-of-line))))
5eabfe72
KH
9993 (let (margin)
9994 (while (= (preceding-char) ?-) (delete-char -1))
d2ddb974 9995 (setq margin (current-column))
5eabfe72
KH
9996 (delete-horizontal-space)
9997 (if (bolp)
9998 (progn (indent-to margin) (insert "--"))
d2ddb974 9999 (insert " ")
5eabfe72
KH
10000 (indent-to comment-column)
10001 (insert "--"))
d2ddb974 10002 (if (not unread-command-events) (insert " ")))
5eabfe72 10003 ;; else code following current point implies commenting out code
d2ddb974
KH
10004 (let (next-input code)
10005 (while (= (preceding-char) ?-) (delete-char -2))
10006 (while (= (setq next-input (read-char)) 13) ; CR
5eabfe72 10007 (insert "--") ; or have a space after it?
d2ddb974
KH
10008 (forward-char -2)
10009 (forward-line 1)
10010 (message "Enter CR if commenting out a line of code.")
5eabfe72 10011 (setq code t))
3dcb36b7 10012 (unless code
5eabfe72 10013 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
d2ddb974 10014 (setq unread-command-events
5eabfe72 10015 (list (vhdl-character-to-event next-input)))))) ; pushback the char
d2ddb974 10016
5eabfe72 10017(defun vhdl-comment-display (&optional line-exists)
d2ddb974
KH
10018 "Add 2 comment lines at the current indent, making a display comment."
10019 (interactive)
5eabfe72 10020 (let ((margin (current-indentation)))
3dcb36b7 10021 (unless line-exists (vhdl-comment-display-line))
5eabfe72
KH
10022 (insert "\n") (indent-to margin)
10023 (insert "\n") (indent-to margin)
10024 (vhdl-comment-display-line)
10025 (end-of-line -0)
10026 (insert "-- ")))
10027
10028(defun vhdl-comment-display-line ()
d2ddb974
KH
10029 "Displays one line of dashes."
10030 (interactive)
10031 (while (= (preceding-char) ?-) (delete-char -2))
10032 (let* ((col (current-column))
10033 (len (- end-comment-column col)))
5eabfe72 10034 (insert-char ?- len)))
d2ddb974 10035
5eabfe72
KH
10036(defun vhdl-comment-append-inline ()
10037 "Append empty inline comment to current line."
10038 (interactive)
10039 (end-of-line)
10040 (delete-horizontal-space)
10041 (insert " ")
10042 (indent-to comment-column)
10043 (insert "-- "))
10044
10045(defun vhdl-comment-insert-inline (&optional string always-insert)
10046 "Insert inline comment."
10047 (when (or (and string (or vhdl-self-insert-comments always-insert))
10048 (and (not string) vhdl-prompt-for-comments))
10049 (let ((position (point)))
10050 (insert " ")
10051 (indent-to comment-column)
10052 (insert "-- ")
3dcb36b7
JB
10053 (if (not (or (and string (progn (insert string) t))
10054 (vhdl-template-field "[comment]" nil t)))
10055 (delete-region position (point))
d355a0b7
SM
10056 (while (= (preceding-char) ?\ ) (delete-char -1))
10057 ;; (when (> (current-column) end-comment-column)
10058 ;; (setq position (point-marker))
10059 ;; (re-search-backward "-- ")
10060 ;; (insert "\n")
10061 ;; (indent-to comment-column)
10062 ;; (goto-char position))
3dcb36b7 10063 ))))
5eabfe72
KH
10064
10065(defun vhdl-comment-block ()
10066 "Insert comment for code block."
10067 (when vhdl-prompt-for-comments
3dcb36b7
JB
10068 (let ((final-pos (point-marker)))
10069 (vhdl-prepare-search-2
5eabfe72 10070 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
3dcb36b7 10071 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
5eabfe72
KH
10072 (let (margin)
10073 (back-to-indentation)
10074 (setq margin (current-column))
10075 (end-of-line -0)
10076 (if (bobp)
10077 (progn (insert "\n") (forward-line -1))
10078 (insert "\n"))
10079 (indent-to margin)
10080 (insert "-- purpose: ")
10081 (unless (vhdl-template-field "[description]" nil t)
10082 (vhdl-line-kill-entire)))))
10083 (goto-char final-pos))))
d2ddb974
KH
10084
10085(defun vhdl-comment-uncomment-region (beg end &optional arg)
5eabfe72 10086 "Comment out region if not commented out, uncomment otherwise."
d2ddb974 10087 (interactive "r\nP")
5eabfe72
KH
10088 (save-excursion
10089 (goto-char (1- end))
10090 (end-of-line)
10091 (setq end (point-marker))
10092 (goto-char beg)
10093 (beginning-of-line)
10094 (setq beg (point))
10095 (if (looking-at comment-start)
3dcb36b7 10096 (comment-region beg end '(4))
5eabfe72
KH
10097 (comment-region beg end))))
10098
10099(defun vhdl-comment-uncomment-line (&optional arg)
10100 "Comment out line if not commented out, uncomment otherwise."
d2ddb974 10101 (interactive "p")
5eabfe72
KH
10102 (save-excursion
10103 (beginning-of-line)
10104 (let ((position (point)))
10105 (forward-line (or arg 1))
10106 (vhdl-comment-uncomment-region position (point)))))
d2ddb974 10107
5eabfe72
KH
10108(defun vhdl-comment-kill-region (beg end)
10109 "Kill comments in region."
10110 (interactive "r")
10111 (save-excursion
10112 (goto-char end)
10113 (setq end (point-marker))
10114 (goto-char beg)
10115 (beginning-of-line)
10116 (while (< (point) end)
10117 (if (looking-at "^\\(\\s-*--.*\n\\)")
10118 (progn (delete-region (match-beginning 1) (match-end 1)))
10119 (beginning-of-line 2)))))
10120
10121(defun vhdl-comment-kill-inline-region (beg end)
10122 "Kill inline comments in region."
10123 (interactive "r")
10124 (save-excursion
10125 (goto-char end)
10126 (setq end (point-marker))
10127 (goto-char beg)
10128 (beginning-of-line)
10129 (while (< (point) end)
10130 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10131 (delete-region (match-beginning 1) (match-end 1)))
10132 (beginning-of-line 2))))
10133
10134;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10135;; Subtemplates
10136
10137(defun vhdl-template-begin-end (construct name margin &optional empty-lines)
d2ddb974
KH
10138 "Insert a begin ... end pair with optional name after the end.
10139Point is left between them."
5eabfe72 10140 (let (position)
5eabfe72 10141 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10142 (indent-to margin)
10143 (vhdl-insert-keyword "BEGIN")
5eabfe72
KH
10144 (when (and (or construct name) vhdl-self-insert-comments)
10145 (insert " --")
10146 (when construct (insert " ") (vhdl-insert-keyword construct))
10147 (when name (insert " " name)))
d2ddb974 10148 (insert "\n")
5eabfe72 10149 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974 10150 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
10151 (setq position (point))
10152 (insert "\n")
10153 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10154 (indent-to margin)
10155 (vhdl-insert-keyword "END")
5eabfe72
KH
10156 (when construct (insert " ") (vhdl-insert-keyword construct))
10157 (insert (if name (concat " " name) "") ";")
10158 (goto-char position)))
d2ddb974 10159
5eabfe72 10160(defun vhdl-template-argument-list (&optional is-function)
d2ddb974
KH
10161 "Read from user a procedure or function argument list."
10162 (insert " (")
d2ddb974 10163 (let ((margin (current-column))
5eabfe72
KH
10164 (start (point))
10165 (end-pos (point))
10166 not-empty interface semicolon-pos)
3dcb36b7 10167 (unless vhdl-argument-list-indent
5eabfe72
KH
10168 (setq margin (+ (current-indentation) vhdl-basic-offset))
10169 (insert "\n")
10170 (indent-to margin))
10171 (setq interface (vhdl-template-field
10172 (concat "[CONSTANT | SIGNAL"
10173 (unless is-function " | VARIABLE") "]") " " t))
10174 (while (vhdl-template-field "[names]" nil t)
10175 (setq not-empty t)
10176 (insert " : ")
3dcb36b7 10177 (unless is-function
5eabfe72
KH
10178 (if (and interface (equal (upcase interface) "CONSTANT"))
10179 (vhdl-insert-keyword "IN ")
10180 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10181 (vhdl-template-field "type")
10182 (setq semicolon-pos (point))
10183 (insert ";")
10184 (vhdl-comment-insert-inline)
10185 (setq end-pos (point))
10186 (insert "\n")
10187 (indent-to margin)
10188 (setq interface (vhdl-template-field
10189 (concat "[CONSTANT | SIGNAL"
10190 (unless is-function " | VARIABLE") "]") " " t)))
10191 (delete-region end-pos (point))
10192 (when semicolon-pos (goto-char semicolon-pos))
10193 (if not-empty
10194 (progn (delete-char 1) (insert ")"))
d355a0b7 10195 (delete-char -2))))
5eabfe72
KH
10196
10197(defun vhdl-template-generic-list (optional &optional no-value)
d2ddb974 10198 "Read from user a generic spec argument list."
5eabfe72 10199 (let (margin
d2ddb974 10200 (start (point)))
5eabfe72
KH
10201 (vhdl-insert-keyword "GENERIC (")
10202 (setq margin (current-column))
3dcb36b7 10203 (unless vhdl-argument-list-indent
5eabfe72
KH
10204 (let ((position (point)))
10205 (back-to-indentation)
10206 (setq margin (+ (current-column) vhdl-basic-offset))
10207 (goto-char position)
10208 (insert "\n")
10209 (indent-to margin)))
10210 (let ((vhdl-generics (vhdl-template-field
10211 (concat (and optional "[") "name"
10212 (and no-value "s") (and optional "]"))
10213 nil optional)))
10214 (if (not vhdl-generics)
d2ddb974 10215 (if optional
5eabfe72 10216 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10217 (unless vhdl-argument-list-indent
5eabfe72
KH
10218 (vhdl-line-kill-entire) (end-of-line -0)))
10219 (vhdl-template-undo start (point))
d2ddb974
KH
10220 nil )
10221 (insert " : ")
5eabfe72
KH
10222 (let (semicolon-pos end-pos)
10223 (while vhdl-generics
10224 (vhdl-template-field "type")
10225 (if no-value
10226 (progn (setq semicolon-pos (point))
10227 (insert ";"))
10228 (insert " := ")
10229 (unless (vhdl-template-field "[value]" nil t)
10230 (delete-char -4))
10231 (setq semicolon-pos (point))
10232 (insert ";"))
10233 (vhdl-comment-insert-inline)
10234 (setq end-pos (point))
10235 (insert "\n")
10236 (indent-to margin)
10237 (setq vhdl-generics (vhdl-template-field
10238 (concat "[name" (and no-value "s") "]")
10239 " : " t)))
10240 (delete-region end-pos (point))
10241 (goto-char semicolon-pos)
10242 (insert ")")
10243 (end-of-line)
3dcb36b7 10244 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
10245 t)))))
10246
10247(defun vhdl-template-port-list (optional)
10248 "Read from user a port spec argument list."
10249 (let ((start (point))
10250 margin vhdl-ports object)
10251 (vhdl-insert-keyword "PORT (")
10252 (setq margin (current-column))
3dcb36b7 10253 (unless vhdl-argument-list-indent
5eabfe72
KH
10254 (let ((position (point)))
10255 (back-to-indentation)
10256 (setq margin (+ (current-column) vhdl-basic-offset))
10257 (goto-char position)
10258 (insert "\n")
10259 (indent-to margin)))
10260 (when (vhdl-standard-p 'ams)
10261 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10262 " " t)))
10263 (setq vhdl-ports (vhdl-template-field
10264 (concat (and optional "[") "names" (and optional "]"))
10265 nil optional))
10266 (if (not vhdl-ports)
10267 (if optional
10268 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10269 (unless vhdl-argument-list-indent
5eabfe72
KH
10270 (vhdl-line-kill-entire) (end-of-line -0)))
10271 (vhdl-template-undo start (point))
10272 nil)
10273 (insert " : ")
10274 (let (semicolon-pos end-pos)
10275 (while vhdl-ports
10276 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10277 (vhdl-template-field "IN | OUT | INOUT" " "))
10278 ((equal "QUANTITY" (upcase object))
10279 (vhdl-template-field "[IN | OUT]" " " t)))
10280 (vhdl-template-field
10281 (if (and object (equal "TERMINAL" (upcase object)))
10282 "nature" "type"))
10283 (setq semicolon-pos (point))
10284 (insert ";")
10285 (vhdl-comment-insert-inline)
10286 (setq end-pos (point))
10287 (insert "\n")
10288 (indent-to margin)
10289 (when (vhdl-standard-p 'ams)
10290 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10291 " " t)))
10292 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10293 (delete-region end-pos (point))
10294 (goto-char semicolon-pos)
10295 (insert ")")
10296 (end-of-line)
3dcb36b7 10297 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
5eabfe72
KH
10298 t))))
10299
10300(defun vhdl-template-generate-body (margin label)
10301 "Insert body for generate template."
10302 (vhdl-insert-keyword " GENERATE")
3dcb36b7
JB
10303; (if (not (vhdl-standard-p '87))
10304; (vhdl-template-begin-end "GENERATE" label margin)
10305 (insert "\n\n")
10306 (indent-to margin)
10307 (vhdl-insert-keyword "END GENERATE ")
10308 (insert label ";")
10309 (end-of-line 0)
10310 (indent-to (+ margin vhdl-basic-offset)))
5eabfe72
KH
10311
10312(defun vhdl-template-insert-date ()
d2ddb974
KH
10313 "Insert date in appropriate format."
10314 (interactive)
5eabfe72
KH
10315 (insert
10316 (cond
3dcb36b7 10317 ;; 'american, 'european, 'scientific kept for backward compatibility
5eabfe72
KH
10318 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10319 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10320 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10321 (t (format-time-string vhdl-date-format nil)))))
10322
10323;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10324;; Help functions
10325
10326(defun vhdl-electric-space (count)
10327 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10328if in comment and past end-comment-column."
10329 (interactive "p")
10330 (cond ((vhdl-in-comment-p)
10331 (self-insert-command count)
10332 (cond ((>= (current-column) (+ 2 end-comment-column))
3dcb36b7
JB
10333 (backward-char 1)
10334 (skip-chars-backward "^ \t\n")
5eabfe72 10335 (indent-new-comment-line)
3dcb36b7 10336 (skip-chars-forward "^ \t\n")
5eabfe72
KH
10337 (forward-char 1))
10338 ((>= (current-column) end-comment-column)
10339 (indent-new-comment-line))
10340 (t nil)))
10341 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10342 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
3dcb36b7
JB
10343 (vhdl-prepare-search-1
10344 (or (expand-abbrev) (vhdl-fix-case-word -1)))
5eabfe72
KH
10345 (self-insert-command count))
10346 (t (self-insert-command count))))
10347
10348(defun vhdl-template-field (prompt &optional follow-string optional
10349 begin end is-string default)
10350 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10351If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10352an empty string is inserted, return nil and call `vhdl-template-undo' for
10353the region between BEGIN and END. IS-STRING indicates whether a string
10354with double-quotes is to be inserted. DEFAULT specifies a default string."
10355 (let ((position (point))
10356 string)
10357 (insert "<" prompt ">")
10358 (setq string
10359 (condition-case ()
10360 (read-from-minibuffer (concat prompt ": ")
10361 (or (and is-string '("\"\"" . 2)) default)
10362 vhdl-minibuffer-local-map)
10363 (quit (if (and optional begin end)
10364 (progn (beep) "")
10365 (keyboard-quit)))))
10366 (when (or (not (equal string "")) optional)
10367 (delete-region position (point)))
10368 (when (and (equal string "") optional begin end)
10369 (vhdl-template-undo begin end)
10370 (message "Template aborted"))
3dcb36b7 10371 (unless (equal string "")
5eabfe72
KH
10372 (insert string)
10373 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
3dcb36b7
JB
10374 vhdl-keywords-regexp)
10375 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10376 vhdl-types-regexp)
10377 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10378 (concat "'" vhdl-attributes-regexp))
10379 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10380 vhdl-enum-values-regexp))
5eabfe72
KH
10381 (when (or (not (equal string "")) (not optional))
10382 (insert (or follow-string "")))
10383 (if (equal string "") nil string)))
10384
10385(defun vhdl-decision-query (string prompt &optional optional)
10386 "Query a decision from the user."
10387 (let ((start (point)))
10388 (when string (vhdl-insert-keyword (concat string " ")))
274f1353 10389 (message "%s" (or prompt ""))
5eabfe72
KH
10390 (let ((char (read-char)))
10391 (delete-region start (point))
10392 (if (and optional (eq char ?\r))
10393 (progn (insert " ")
10394 (unexpand-abbrev)
3dcb36b7 10395 (throw 'abort "ERROR: Template aborted"))
5eabfe72 10396 char))))
d2ddb974
KH
10397
10398(defun vhdl-insert-keyword (keyword)
5eabfe72
KH
10399 "Insert KEYWORD and adjust case."
10400 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
d2ddb974
KH
10401
10402(defun vhdl-case-keyword (keyword)
5eabfe72
KH
10403 "Adjust case of KEYWORD."
10404 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
d2ddb974
KH
10405
10406(defun vhdl-case-word (num)
a4c6cfad 10407 "Adjust case of following NUM words."
5eabfe72
KH
10408 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10409
10410(defun vhdl-minibuffer-tab (&optional prefix-arg)
10411 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7 10412else insert tab (used for word completion in VHDL minibuffer)."
5eabfe72 10413 (interactive "P")
3dcb36b7
JB
10414 (cond
10415 ;; expand word
10416 ((= (char-syntax (preceding-char)) ?w)
10417 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10418 (case-replace nil)
10419 (hippie-expand-only-buffers
10420 (or (and (boundp 'hippie-expand-only-buffers)
10421 hippie-expand-only-buffers)
10422 '(vhdl-mode))))
10423 (vhdl-expand-abbrev prefix-arg)))
10424 ;; expand parenthesis
10425 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10426 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10427 (case-replace nil))
10428 (vhdl-expand-paren prefix-arg)))
10429 ;; insert tab
10430 (t (insert-tab))))
5eabfe72
KH
10431
10432(defun vhdl-template-search-prompt ()
10433 "Search for left out template prompts and query again."
10434 (interactive)
3dcb36b7
JB
10435 (vhdl-prepare-search-2
10436 (when (or (re-search-forward
10437 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10438 (re-search-backward
10439 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10440 (let ((string (match-string 1)))
10441 (replace-match "")
10442 (vhdl-template-field string)))))
5eabfe72
KH
10443
10444(defun vhdl-template-undo (begin end)
10445 "Undo aborted template by deleting region and unexpanding the keyword."
10446 (cond (vhdl-template-invoked-by-hook
10447 (goto-char end)
10448 (insert " ")
10449 (delete-region begin end)
10450 (unexpand-abbrev))
10451 (t (delete-region begin end))))
10452
10453(defun vhdl-insert-string-or-file (string)
10454 "Insert STRING or file contents if STRING is an existing file name."
10455 (unless (equal string "")
3dcb36b7
JB
10456 (let ((file-name
10457 (progn (string-match "^\\([^\n]+\\)" string)
10458 (vhdl-resolve-env-variable (match-string 1 string)))))
10459 (if (file-exists-p file-name)
10460 (forward-char (cadr (insert-file-contents file-name)))
10461 (insert string)))))
10462
10463(defun vhdl-beginning-of-block ()
10464 "Move cursor to the beginning of the enclosing block."
10465 (let (pos)
10466 (save-excursion
10467 (beginning-of-line)
10468 ;; search backward for block beginning or end
10469 (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))
10470 ;; not consider subprogram declarations
10471 (or (and (match-string 5)
10472 (save-match-data
10473 (save-excursion
10474 (goto-char (match-end 5))
0a2e512a
RF
10475 (forward-word 1)
10476 (vhdl-forward-syntactic-ws)
10477 (when (looking-at "(")
10478 (forward-sexp))
3dcb36b7
JB
10479 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10480 (match-string 1)))
10481 ;; not consider configuration specifications
10482 (and (match-string 6)
10483 (save-match-data
10484 (save-excursion
10485 (vhdl-end-of-block)
10486 (beginning-of-line)
10487 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10488 (match-string 2))
10489 ;; skip subblock if block end found
10490 (vhdl-beginning-of-block)))
10491 (when pos (goto-char pos))))
10492
10493(defun vhdl-end-of-block ()
10494 "Move cursor to the end of the enclosing block."
10495 (let (pos)
10496 (save-excursion
10497 (end-of-line)
10498 ;; search forward for block beginning or end
10499 (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))
10500 ;; not consider subprogram declarations
10501 (or (and (match-string 5)
10502 (save-match-data
10503 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10504 (match-string 1)))
10505 ;; not consider configuration specifications
10506 (and (match-string 6)
10507 (save-match-data
10508 (save-excursion
10509 (vhdl-end-of-block)
10510 (beginning-of-line)
10511 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10512 (not (match-string 2)))
10513 ;; skip subblock if block beginning found
10514 (vhdl-end-of-block)))
10515 (when pos (goto-char pos))))
5eabfe72
KH
10516
10517(defun vhdl-sequential-statement-p ()
10518 "Check if point is within sequential statement part."
3dcb36b7
JB
10519 (let ((start (point)))
10520 (save-excursion
10521 (vhdl-prepare-search-2
10522 ;; is sequential statement if ...
10523 (and (re-search-backward "^\\s-*begin\\>" nil t)
10524 ;; ... point is between "begin" and "end" of ...
10525 (progn (vhdl-end-of-block)
10526 (< start (point)))
10527 ;; ... a sequential block
10528 (progn (vhdl-beginning-of-block)
10529 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
5eabfe72
KH
10530
10531(defun vhdl-in-argument-list-p ()
10532 "Check if within an argument list."
10533 (save-excursion
3dcb36b7
JB
10534 (vhdl-prepare-search-2
10535 (or (string-match "arglist"
10536 (format "%s" (caar (vhdl-get-syntactic-context))))
10537 (progn (beginning-of-line)
10538 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
5eabfe72
KH
10539
10540;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10541;; Abbrev hooks
10542
10543(defun vhdl-hooked-abbrev (func)
10544 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
a4c6cfad 10545but not if inside a comment or quote."
3dcb36b7 10546 (if (or (vhdl-in-literal)
5eabfe72
KH
10547 (save-excursion
10548 (forward-word -1)
10549 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10550 (progn
10551 (insert " ")
10552 (unexpand-abbrev)
10553 (delete-char -1))
10554 (if (not vhdl-electric-mode)
10555 (progn
10556 (insert " ")
10557 (unexpand-abbrev)
10558 (backward-word 1)
10559 (vhdl-case-word 1)
10560 (delete-char 1))
1ba983e8 10561 (let ((invoke-char last-command-event)
5eabfe72
KH
10562 (abbrev-mode -1)
10563 (vhdl-template-invoked-by-hook t))
10564 (let ((caught (catch 'abort
10565 (funcall func))))
29a4e67d 10566 (when (stringp caught) (message "%s" caught)))
5eabfe72
KH
10567 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10568 ;; delete CR which is still in event queue
4bcb9c95 10569 (if (fboundp 'enqueue-eval-event)
5eabfe72
KH
10570 (enqueue-eval-event 'delete-char -1)
10571 (setq unread-command-events ; push back a delete char
10572 (list (vhdl-character-to-event ?\177))))))))
10573
10574(defun vhdl-template-alias-hook ()
10575 (vhdl-hooked-abbrev 'vhdl-template-alias))
10576(defun vhdl-template-architecture-hook ()
10577 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10578(defun vhdl-template-assert-hook ()
10579 (vhdl-hooked-abbrev 'vhdl-template-assert))
10580(defun vhdl-template-attribute-hook ()
10581 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10582(defun vhdl-template-block-hook ()
10583 (vhdl-hooked-abbrev 'vhdl-template-block))
10584(defun vhdl-template-break-hook ()
10585 (vhdl-hooked-abbrev 'vhdl-template-break))
10586(defun vhdl-template-case-hook ()
10587 (vhdl-hooked-abbrev 'vhdl-template-case))
10588(defun vhdl-template-component-hook ()
10589 (vhdl-hooked-abbrev 'vhdl-template-component))
10590(defun vhdl-template-instance-hook ()
10591 (vhdl-hooked-abbrev 'vhdl-template-instance))
10592(defun vhdl-template-conditional-signal-asst-hook ()
10593 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10594(defun vhdl-template-configuration-hook ()
10595 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10596(defun vhdl-template-constant-hook ()
10597 (vhdl-hooked-abbrev 'vhdl-template-constant))
10598(defun vhdl-template-disconnect-hook ()
10599 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10600(defun vhdl-template-display-comment-hook ()
10601 (vhdl-hooked-abbrev 'vhdl-comment-display))
10602(defun vhdl-template-else-hook ()
10603 (vhdl-hooked-abbrev 'vhdl-template-else))
10604(defun vhdl-template-elsif-hook ()
10605 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10606(defun vhdl-template-entity-hook ()
10607 (vhdl-hooked-abbrev 'vhdl-template-entity))
10608(defun vhdl-template-exit-hook ()
10609 (vhdl-hooked-abbrev 'vhdl-template-exit))
10610(defun vhdl-template-file-hook ()
10611 (vhdl-hooked-abbrev 'vhdl-template-file))
10612(defun vhdl-template-for-hook ()
10613 (vhdl-hooked-abbrev 'vhdl-template-for))
10614(defun vhdl-template-function-hook ()
10615 (vhdl-hooked-abbrev 'vhdl-template-function))
10616(defun vhdl-template-generic-hook ()
10617 (vhdl-hooked-abbrev 'vhdl-template-generic))
10618(defun vhdl-template-group-hook ()
10619 (vhdl-hooked-abbrev 'vhdl-template-group))
10620(defun vhdl-template-library-hook ()
10621 (vhdl-hooked-abbrev 'vhdl-template-library))
10622(defun vhdl-template-limit-hook ()
10623 (vhdl-hooked-abbrev 'vhdl-template-limit))
10624(defun vhdl-template-if-hook ()
10625 (vhdl-hooked-abbrev 'vhdl-template-if))
10626(defun vhdl-template-bare-loop-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10628(defun vhdl-template-map-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-map))
10630(defun vhdl-template-nature-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-nature))
10632(defun vhdl-template-next-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-template-next))
3dcb36b7
JB
10634(defun vhdl-template-others-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-others))
5eabfe72
KH
10636(defun vhdl-template-package-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-package))
10638(defun vhdl-template-port-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-port))
10640(defun vhdl-template-procedural-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10642(defun vhdl-template-procedure-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10644(defun vhdl-template-process-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-process))
10646(defun vhdl-template-quantity-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10648(defun vhdl-template-report-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-report))
10650(defun vhdl-template-return-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-return))
10652(defun vhdl-template-selected-signal-asst-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10654(defun vhdl-template-signal-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-signal))
10656(defun vhdl-template-subnature-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10658(defun vhdl-template-subtype-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10660(defun vhdl-template-terminal-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10662(defun vhdl-template-type-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-type))
10664(defun vhdl-template-use-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-use))
10666(defun vhdl-template-variable-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-variable))
10668(defun vhdl-template-wait-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-wait))
10670(defun vhdl-template-when-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-when))
10672(defun vhdl-template-while-loop-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10674(defun vhdl-template-with-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-with))
10676(defun vhdl-template-and-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-and))
10678(defun vhdl-template-or-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-or))
10680(defun vhdl-template-nand-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-nand))
10682(defun vhdl-template-nor-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-nor))
10684(defun vhdl-template-xor-hook ()
10685 (vhdl-hooked-abbrev 'vhdl-template-xor))
10686(defun vhdl-template-xnor-hook ()
10687 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10688(defun vhdl-template-not-hook ()
10689 (vhdl-hooked-abbrev 'vhdl-template-not))
10690
10691(defun vhdl-template-default-hook ()
10692 (vhdl-hooked-abbrev 'vhdl-template-default))
10693(defun vhdl-template-default-indent-hook ()
10694 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10695
10696;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10697;; Template insertion from completion list
10698
10699(defun vhdl-template-insert-construct (name)
10700 "Insert the built-in construct template with NAME."
10701 (interactive
10702 (list (let ((completion-ignore-case t))
10703 (completing-read "Construct name: "
10704 vhdl-template-construct-alist nil t))))
10705 (vhdl-template-insert-fun
3dcb36b7 10706 (cadr (assoc name vhdl-template-construct-alist))))
5eabfe72
KH
10707
10708(defun vhdl-template-insert-package (name)
10709 "Insert the built-in package template with NAME."
10710 (interactive
10711 (list (let ((completion-ignore-case t))
10712 (completing-read "Package name: "
10713 vhdl-template-package-alist nil t))))
10714 (vhdl-template-insert-fun
3dcb36b7 10715 (cadr (assoc name vhdl-template-package-alist))))
5eabfe72
KH
10716
10717(defun vhdl-template-insert-directive (name)
10718 "Insert the built-in directive template with NAME."
10719 (interactive
10720 (list (let ((completion-ignore-case t))
10721 (completing-read "Directive name: "
10722 vhdl-template-directive-alist nil t))))
10723 (vhdl-template-insert-fun
3dcb36b7 10724 (cadr (assoc name vhdl-template-directive-alist))))
5eabfe72
KH
10725
10726(defun vhdl-template-insert-fun (fun)
10727 "Call FUN to insert a built-in template."
10728 (let ((caught (catch 'abort (when fun (funcall fun)))))
29a4e67d 10729 (when (stringp caught) (message "%s" caught))))
5eabfe72
KH
10730
10731
10732;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10733;;; Models
10734;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10735
10736(defun vhdl-model-insert (model-name)
10737 "Insert the user model with name MODEL-NAME."
10738 (interactive
10739 (let ((completion-ignore-case t))
10740 (list (completing-read "Model name: " vhdl-model-alist))))
3dcb36b7 10741 (indent-according-to-mode)
5eabfe72
KH
10742 (let ((start (point-marker))
10743 (margin (current-indentation))
5eabfe72 10744 model position prompt string end)
3dcb36b7 10745 (vhdl-prepare-search-2
5eabfe72
KH
10746 (when (setq model (assoc model-name vhdl-model-alist))
10747 ;; insert model
10748 (beginning-of-line)
10749 (delete-horizontal-space)
10750 (goto-char start)
10751 (vhdl-insert-string-or-file (nth 1 model))
10752 (setq end (point-marker))
10753 ;; indent code
10754 (goto-char start)
10755 (beginning-of-line)
10756 (while (< (point) end)
10757 (unless (looking-at "^$")
10758 (insert-char ? margin))
10759 (beginning-of-line 2))
10760 (goto-char start)
10761 ;; insert clock
10762 (unless (equal "" vhdl-clock-name)
10763 (while (re-search-forward "<clock>" end t)
10764 (replace-match vhdl-clock-name)))
10765 (goto-char start)
10766 ;; insert reset
10767 (unless (equal "" vhdl-reset-name)
10768 (while (re-search-forward "<reset>" end t)
10769 (replace-match vhdl-reset-name)))
3dcb36b7
JB
10770 ;; replace header prompts
10771 (vhdl-template-replace-header-keywords start end nil t)
5eabfe72 10772 (goto-char start)
3dcb36b7 10773 ;; query other prompts
5eabfe72
KH
10774 (while (re-search-forward
10775 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10776 (unless (equal "cursor" (match-string 1))
10777 (setq position (match-beginning 1))
10778 (setq prompt (match-string 1))
10779 (replace-match "")
10780 (setq string (vhdl-template-field prompt nil t))
a5a08b1f 10781 ;; replace occurrences of same prompt
5eabfe72
KH
10782 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10783 (replace-match (or string "")))
10784 (goto-char position)))
10785 (goto-char start)
10786 ;; goto final position
10787 (if (re-search-forward "<cursor>" end t)
10788 (replace-match "")
10789 (goto-char end))))))
10790
10791(defun vhdl-model-defun ()
10792 "Define help and hook functions for user models."
10793 (let ((model-alist vhdl-model-alist)
10794 model-name model-keyword)
10795 (while model-alist
10796 ;; define functions for user models that can be invoked from menu and key
10797 ;; bindings and which themselves call `vhdl-model-insert' with the model
10798 ;; name as argument
10799 (setq model-name (nth 0 (car model-alist)))
d4a5b644
GM
10800 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10801 ,(concat "Insert model for \"" model-name "\".")
10802 (interactive)
10803 (vhdl-model-insert ,model-name)))
5eabfe72
KH
10804 ;; define hooks for user models that are invoked from keyword abbrevs
10805 (setq model-keyword (nth 3 (car model-alist)))
10806 (unless (equal model-keyword "")
d4a5b644
GM
10807 (eval `(defun
10808 ,(vhdl-function-name
10809 "vhdl-model" model-name "hook") ()
10810 (vhdl-hooked-abbrev
10811 ',(vhdl-function-name "vhdl-model" model-name)))))
5eabfe72
KH
10812 (setq model-alist (cdr model-alist)))))
10813
10814(vhdl-model-defun)
10815
10816
10817;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10818;;; Port translation
10819;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10820
10821(defvar vhdl-port-list nil
3dcb36b7 10822 "Variable to hold last port map parsed.")
5eabfe72 10823;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
10824;; (ent-name
10825;; ((generic-names) generic-type generic-init generic-comment group-comment)
10826;; ((port-names) port-object port-direct port-type port-comment group-comment)
10827;; (lib-name pack-key))
5eabfe72
KH
10828
10829(defun vhdl-parse-string (string &optional optional)
3dcb36b7 10830 "Check that the text following point matches the regexp in STRING."
5eabfe72 10831 (if (looking-at string)
3dcb36b7 10832 (goto-char (match-end 0))
5eabfe72 10833 (unless optional
3dcb36b7
JB
10834 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10835 (vhdl-current-line) string)))
5eabfe72
KH
10836 nil))
10837
0a2e512a 10838(defun vhdl-replace-string (regexp-cons string &optional adjust-case)
5eabfe72 10839 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
3dcb36b7 10840 (vhdl-prepare-search-1
5eabfe72 10841 (if (string-match (car regexp-cons) string)
0a2e512a
RF
10842 (if adjust-case
10843 (funcall vhdl-file-name-case
10844 (replace-match (cdr regexp-cons) t nil string))
10845 (replace-match (cdr regexp-cons) t nil string))
5eabfe72
KH
10846 string)))
10847
3dcb36b7
JB
10848(defun vhdl-parse-group-comment ()
10849 "Parse comment and empty lines between groups of lines."
10850 (let ((start (point))
10851 string)
10852 (vhdl-forward-comment (point-max))
10853 (setq string (buffer-substring-no-properties start (point)))
0a2e512a 10854 (vhdl-forward-syntactic-ws)
3dcb36b7
JB
10855 ;; strip off leading blanks and first newline
10856 (while (string-match "^\\(\\s-+\\)" string)
10857 (setq string (concat (substring string 0 (match-beginning 1))
10858 (substring string (match-end 1)))))
10859 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10860 (substring string 1)
10861 string)))
10862
10863(defun vhdl-paste-group-comment (string indent)
10864 "Paste comment and empty lines from STRING between groups of lines
10865with INDENT."
10866 (let ((pos (point-marker)))
10867 (when (> indent 0)
10868 (while (string-match "^\\(--\\)" string)
10869 (setq string (concat (substring string 0 (match-beginning 1))
10870 (make-string indent ? )
10871 (substring string (match-beginning 1))))))
10872 (beginning-of-line)
10873 (insert string)
10874 (goto-char pos)))
10875
10876(defvar vhdl-port-flattened nil
10877 "Indicates whether a port has been flattened.")
10878
10879(defun vhdl-port-flatten (&optional as-alist)
0a2e512a
RF
10880 "Flatten port list so that only one generic/port exists per line.
10881This operation is performed on an internally stored port and is only
10882reflected in a subsequent paste operation."
5eabfe72
KH
10883 (interactive)
10884 (if (not vhdl-port-list)
3dcb36b7 10885 (error "ERROR: No port has been read")
0a2e512a 10886 (message "Flattening port for next paste...")
5eabfe72
KH
10887 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10888 (old-vhdl-port-list (cdr vhdl-port-list))
10889 old-port-list new-port-list old-port new-port names)
10890 ;; traverse port list and flatten entries
3dcb36b7 10891 (while (cdr old-vhdl-port-list)
5eabfe72
KH
10892 (setq old-port-list (car old-vhdl-port-list))
10893 (setq new-port-list nil)
10894 (while old-port-list
10895 (setq old-port (car old-port-list))
10896 (setq names (car old-port))
10897 (while names
3dcb36b7
JB
10898 (setq new-port (cons (if as-alist (car names) (list (car names)))
10899 (cdr old-port)))
5eabfe72
KH
10900 (setq new-port-list (append new-port-list (list new-port)))
10901 (setq names (cdr names)))
10902 (setq old-port-list (cdr old-port-list)))
10903 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10904 (setq new-vhdl-port-list (append new-vhdl-port-list
10905 (list new-port-list))))
3dcb36b7
JB
10906 (setq vhdl-port-list
10907 (append new-vhdl-port-list (list old-vhdl-port-list))
10908 vhdl-port-flattened t)
0a2e512a 10909 (message "Flattening port for next paste...done"))))
5eabfe72 10910
3dcb36b7
JB
10911(defvar vhdl-port-reversed-direction nil
10912 "Indicates whether port directions are reversed.")
10913
10914(defun vhdl-port-reverse-direction ()
0a2e512a
RF
10915 "Reverse direction for all ports (useful in testbenches).
10916This operation is performed on an internally stored port and is only
10917reflected in a subsequent paste operation."
3dcb36b7
JB
10918 (interactive)
10919 (if (not vhdl-port-list)
10920 (error "ERROR: No port has been read")
0a2e512a 10921 (message "Reversing port directions for next paste...")
3dcb36b7
JB
10922 (let ((port-list (nth 2 vhdl-port-list))
10923 port-dir-car port-dir)
10924 ;; traverse port list and reverse directions
10925 (while port-list
10926 (setq port-dir-car (cddr (car port-list))
10927 port-dir (car port-dir-car))
10928 (setcar port-dir-car
10929 (cond ((equal port-dir "in") "out")
10930 ((equal port-dir "out") "in")
10931 (t port-dir)))
10932 (setq port-list (cdr port-list)))
10933 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
0a2e512a 10934 (message "Reversing port directions for next paste...done"))))
3dcb36b7 10935
5eabfe72
KH
10936(defun vhdl-port-copy ()
10937 "Get generic and port information from an entity or component declaration."
10938 (interactive)
5eabfe72 10939 (save-excursion
3dcb36b7
JB
10940 (let (parse-error end-of-list
10941 decl-type name generic-list port-list context-clause
10942 object names direct type init comment group-comment)
10943 (vhdl-prepare-search-2
5eabfe72
KH
10944 (setq
10945 parse-error
10946 (catch 'parse
10947 ;; check if within entity or component declaration
3dcb36b7 10948 (end-of-line)
5eabfe72
KH
10949 (when (or (not (re-search-backward
10950 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
3dcb36b7
JB
10951 (equal "END" (upcase (match-string 1))))
10952 (throw 'parse "ERROR: Not within an entity or component declaration"))
10953 (setq decl-type (downcase (match-string-no-properties 1)))
5eabfe72 10954 (forward-word 1)
3dcb36b7
JB
10955 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10956 (setq name (match-string-no-properties 1))
10957 (message "Reading port of %s \"%s\"..." decl-type name)
5eabfe72
KH
10958 (vhdl-forward-syntactic-ws)
10959 ;; parse generic clause
10960 (when (vhdl-parse-string "generic[ \t\n]*(" t)
3dcb36b7
JB
10961 ;; parse group comment and spacing
10962 (setq group-comment (vhdl-parse-group-comment))
10963 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72 10964 (while (not end-of-list)
0a2e512a
RF
10965 ;; parse names (accept extended identifiers)
10966 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
3dcb36b7 10967 (setq names (list (match-string-no-properties 1)))
5eabfe72 10968 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
3dcb36b7
JB
10969 (setq names
10970 (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10971 ;; parse type
10972 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
3dcb36b7 10973 (setq type (match-string-no-properties 1))
5eabfe72
KH
10974 (setq comment nil)
10975 (while (looking-at "(")
10976 (setq type
10977 (concat type
3dcb36b7 10978 (buffer-substring-no-properties
5eabfe72
KH
10979 (point) (progn (forward-sexp) (point)))
10980 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
3dcb36b7 10981 (match-string-no-properties 1)))))
5eabfe72
KH
10982 ;; special case: closing parenthesis is on separate line
10983 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10984 (setq comment (substring type (match-beginning 2)))
10985 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10986 ;; strip of trailing group-comment
5eabfe72
KH
10987 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10988 (setq type (substring type 0 (match-end 1)))
10989 ;; parse initialization expression
10990 (setq init nil)
10991 (when (vhdl-parse-string ":=[ \t\n]*" t)
10992 (vhdl-parse-string "\\([^();\n]*\\)")
3dcb36b7 10993 (setq init (match-string-no-properties 1))
5eabfe72
KH
10994 (while (looking-at "(")
10995 (setq init
10996 (concat init
3dcb36b7 10997 (buffer-substring-no-properties
5eabfe72
KH
10998 (point) (progn (forward-sexp) (point)))
10999 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11000 (match-string-no-properties 1))))))
5eabfe72
KH
11001 ;; special case: closing parenthesis is on separate line
11002 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11003 (setq comment (substring init (match-beginning 2)))
11004 (setq init (substring init 0 (match-beginning 1)))
11005 (vhdl-forward-syntactic-ws))
11006 (skip-chars-forward " \t")
11007 ;; parse inline comment, special case: as above, no initial.
11008 (unless comment
11009 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11010 (match-string-no-properties 1))))
5eabfe72
KH
11011 (vhdl-forward-syntactic-ws)
11012 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11013 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11014 ;; parse inline comment
11015 (unless comment
11016 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11017 (match-string-no-properties 1))))
5eabfe72 11018 ;; save everything in list
3dcb36b7
JB
11019 (setq generic-list (append generic-list
11020 (list (list names type init
11021 comment group-comment))))
11022 ;; parse group comment and spacing
11023 (setq group-comment (vhdl-parse-group-comment))))
5eabfe72
KH
11024 ;; parse port clause
11025 (when (vhdl-parse-string "port[ \t\n]*(" t)
3dcb36b7
JB
11026 ;; parse group comment and spacing
11027 (setq group-comment (vhdl-parse-group-comment))
11028 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
11029 (while (not end-of-list)
11030 ;; parse object
11031 (setq object
0a2e512a 11032 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
3dcb36b7
JB
11033 (match-string-no-properties 1)))
11034 ;; parse names (accept extended identifiers)
11035 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11036 (setq names (list (match-string-no-properties 1)))
11037 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11038 (setq names (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
11039 ;; parse direction
11040 (vhdl-parse-string ":[ \t\n]*")
11041 (setq direct
0a2e512a 11042 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
3dcb36b7 11043 (match-string-no-properties 1)))
5eabfe72
KH
11044 ;; parse type
11045 (vhdl-parse-string "\\([^();\n]+\\)")
3dcb36b7 11046 (setq type (match-string-no-properties 1))
5eabfe72
KH
11047 (setq comment nil)
11048 (while (looking-at "(")
11049 (setq type (concat type
3dcb36b7 11050 (buffer-substring-no-properties
5eabfe72
KH
11051 (point) (progn (forward-sexp) (point)))
11052 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11053 (match-string-no-properties 1)))))
5eabfe72 11054 ;; special case: closing parenthesis is on separate line
3dcb36b7 11055 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
5eabfe72
KH
11056 (setq comment (substring type (match-beginning 2)))
11057 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 11058 ;; strip of trailing group-comment
5eabfe72
KH
11059 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11060 (setq type (substring type 0 (match-end 1)))
11061 (vhdl-forward-syntactic-ws)
11062 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11063 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11064 ;; parse inline comment
11065 (unless comment
11066 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11067 (match-string-no-properties 1))))
5eabfe72 11068 ;; save everything in list
3dcb36b7
JB
11069 (setq port-list (append port-list
11070 (list (list names object direct type
11071 comment group-comment))))
11072 ;; parse group comment and spacing
11073 (setq group-comment (vhdl-parse-group-comment))))
11074; (vhdl-parse-string "end\\>")
11075 ;; parse context clause
11076 (setq context-clause (vhdl-scan-context-clause))
11077; ;; add surrounding package to context clause
11078; (when (and (equal decl-type "component")
11079; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11080; (setq context-clause
11081; (append context-clause
11082; (list (cons (vhdl-work-library)
11083; (match-string-no-properties 1))))))
11084 (message "Reading port of %s \"%s\"...done" decl-type name)
5eabfe72
KH
11085 nil)))
11086 ;; finish parsing
11087 (if parse-error
11088 (error parse-error)
3dcb36b7
JB
11089 (setq vhdl-port-list (list name generic-list port-list context-clause)
11090 vhdl-port-reversed-direction nil
11091 vhdl-port-flattened nil)))))
11092
11093(defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11094 "Paste a context clause."
11095 (let ((margin (current-indentation))
11096 (clause-list (nth 3 vhdl-port-list))
11097 clause)
11098 (while clause-list
11099 (setq clause (car clause-list))
11100 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11101 (downcase exclude-pack-name)))
11102 (save-excursion
11103 (re-search-backward
11104 (concat "^\\s-*use\\s-+" (car clause)
11105 "\." (cdr clause) "\\>") nil t)))
11106 (vhdl-template-standard-package (car clause) (cdr clause))
11107 (insert "\n"))
11108 (setq clause-list (cdr clause-list)))))
5eabfe72
KH
11109
11110(defun vhdl-port-paste-generic (&optional no-init)
11111 "Paste a generic clause."
11112 (let ((margin (current-indentation))
3dcb36b7
JB
11113 (generic-list (nth 1 vhdl-port-list))
11114 list-margin start names generic)
5eabfe72 11115 ;; paste generic clause
3dcb36b7 11116 (when generic-list
5eabfe72
KH
11117 (setq start (point))
11118 (vhdl-insert-keyword "GENERIC (")
11119 (unless vhdl-argument-list-indent
11120 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11121 (setq list-margin (current-column))
3dcb36b7
JB
11122 (while generic-list
11123 (setq generic (car generic-list))
11124 ;; paste group comment and spacing
11125 (when (memq vhdl-include-group-comments '(decl always))
11126 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72 11127 ;; paste names
5eabfe72
KH
11128 (setq names (nth 0 generic))
11129 (while names
11130 (insert (car names))
11131 (setq names (cdr names))
11132 (when names (insert ", ")))
11133 ;; paste type
11134 (insert " : " (nth 1 generic))
11135 ;; paste initialization
11136 (when (and (not no-init) (nth 2 generic))
11137 (insert " := " (nth 2 generic)))
3dcb36b7 11138 (unless (cdr generic-list) (insert ")"))
5eabfe72
KH
11139 (insert ";")
11140 ;; paste comment
11141 (when (and vhdl-include-port-comments (nth 3 generic))
11142 (vhdl-comment-insert-inline (nth 3 generic) t))
3dcb36b7
JB
11143 (setq generic-list (cdr generic-list))
11144 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72 11145 ;; align generic clause
3dcb36b7 11146 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
5eabfe72
KH
11147
11148(defun vhdl-port-paste-port ()
11149 "Paste a port clause."
11150 (let ((margin (current-indentation))
3dcb36b7
JB
11151 (port-list (nth 2 vhdl-port-list))
11152 list-margin start names port)
5eabfe72 11153 ;; paste port clause
3dcb36b7 11154 (when port-list
5eabfe72
KH
11155 (setq start (point))
11156 (vhdl-insert-keyword "PORT (")
11157 (unless vhdl-argument-list-indent
11158 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11159 (setq list-margin (current-column))
3dcb36b7
JB
11160 (while port-list
11161 (setq port (car port-list))
11162 ;; paste group comment and spacing
11163 (when (memq vhdl-include-group-comments '(decl always))
11164 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11165 ;; paste object
11166 (when (nth 1 port) (insert (nth 1 port) " "))
11167 ;; paste names
11168 (setq names (nth 0 port))
11169 (while names
11170 (insert (car names))
11171 (setq names (cdr names))
11172 (when names (insert ", ")))
11173 ;; paste direction
11174 (insert " : ")
11175 (when (nth 2 port) (insert (nth 2 port) " "))
11176 ;; paste type
11177 (insert (nth 3 port))
3dcb36b7 11178 (unless (cdr port-list) (insert ")"))
5eabfe72
KH
11179 (insert ";")
11180 ;; paste comment
11181 (when (and vhdl-include-port-comments (nth 4 port))
11182 (vhdl-comment-insert-inline (nth 4 port) t))
3dcb36b7
JB
11183 (setq port-list (cdr port-list))
11184 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72 11185 ;; align port clause
3dcb36b7 11186 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
5eabfe72 11187
3dcb36b7 11188(defun vhdl-port-paste-declaration (kind &optional no-indent)
5eabfe72 11189 "Paste as an entity or component declaration."
3dcb36b7 11190 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11191 (let ((margin (current-indentation))
11192 (name (nth 0 vhdl-port-list)))
11193 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11194 (insert name)
3dcb36b7
JB
11195 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11196 (vhdl-insert-keyword " IS"))
11197 ;; paste generic and port clause
5eabfe72
KH
11198 (when (nth 1 vhdl-port-list)
11199 (insert "\n")
11200 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11201 (insert "\n"))
11202 (indent-to (+ margin vhdl-basic-offset))
11203 (vhdl-port-paste-generic (eq kind 'component)))
11204 (when (nth 2 vhdl-port-list)
11205 (insert "\n")
11206 (when (and (memq vhdl-insert-empty-lines '(unit all))
11207 (eq kind 'entity))
11208 (insert "\n"))
11209 (indent-to (+ margin vhdl-basic-offset)))
11210 (vhdl-port-paste-port)
11211 (insert "\n")
11212 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11213 (insert "\n"))
11214 (indent-to margin)
11215 (vhdl-insert-keyword "END")
11216 (if (eq kind 'entity)
11217 (progn
11218 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11219 (insert " " name))
11220 (vhdl-insert-keyword " COMPONENT")
11221 (unless (vhdl-standard-p '87) (insert " " name)))
11222 (insert ";")))
11223
3dcb36b7 11224(defun vhdl-port-paste-entity (&optional no-indent)
5eabfe72
KH
11225 "Paste as an entity declaration."
11226 (interactive)
11227 (if (not vhdl-port-list)
3dcb36b7
JB
11228 (error "ERROR: No port read")
11229 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11230 (vhdl-port-paste-declaration 'entity no-indent)
11231 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
5eabfe72 11232
3dcb36b7 11233(defun vhdl-port-paste-component (&optional no-indent)
5eabfe72
KH
11234 "Paste as a component declaration."
11235 (interactive)
11236 (if (not vhdl-port-list)
3dcb36b7
JB
11237 (error "ERROR: No port read")
11238 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11239 (vhdl-port-paste-declaration 'component no-indent)
11240 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
5eabfe72
KH
11241
11242(defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11243 "Paste as a generic map."
11244 (interactive)
3dcb36b7 11245 (unless secondary (indent-according-to-mode))
5eabfe72
KH
11246 (let ((margin (current-indentation))
11247 list-margin start generic
3dcb36b7
JB
11248 (generic-list (nth 1 vhdl-port-list)))
11249 (when generic-list
5eabfe72
KH
11250 (setq start (point))
11251 (vhdl-insert-keyword "GENERIC MAP (")
11252 (if (not vhdl-association-list-with-formals)
11253 ;; paste list of actual generics
3dcb36b7
JB
11254 (while generic-list
11255 (insert (if no-constants
11256 (car (nth 0 (car generic-list)))
11257 (or (nth 2 (car generic-list)) " ")))
11258 (setq generic-list (cdr generic-list))
0a2e512a
RF
11259 (insert (if generic-list ", " ")"))
11260 (when (and (not generic-list) secondary
11261 (null (nth 2 vhdl-port-list)))
11262 (insert ";")))
5eabfe72 11263 (unless vhdl-argument-list-indent
3dcb36b7 11264 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11265 (setq list-margin (current-column))
3dcb36b7
JB
11266 (while generic-list
11267 (setq generic (car generic-list))
11268 ;; paste group comment and spacing
11269 (when (eq vhdl-include-group-comments 'always)
11270 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72
KH
11271 ;; paste formal and actual generic
11272 (insert (car (nth 0 generic)) " => "
11273 (if no-constants
11274 (car (nth 0 generic))
11275 (or (nth 2 generic) "")))
3dcb36b7
JB
11276 (setq generic-list (cdr generic-list))
11277 (insert (if generic-list "," ")"))
0a2e512a
RF
11278 (when (and (not generic-list) secondary
11279 (null (nth 2 vhdl-port-list)))
11280 (insert ";"))
5eabfe72 11281 ;; paste comment
3dcb36b7
JB
11282 (when (or vhdl-include-type-comments
11283 (and vhdl-include-port-comments (nth 3 generic)))
11284 (vhdl-comment-insert-inline
11285 (concat
11286 (when vhdl-include-type-comments
11287 (concat "[" (nth 1 generic) "] "))
11288 (when vhdl-include-port-comments (nth 3 generic))) t))
11289 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11290 ;; align generic map
11291 (when vhdl-auto-align
3dcb36b7 11292 (vhdl-align-region-groups start (point) 1 t))))))
5eabfe72
KH
11293
11294(defun vhdl-port-paste-port-map ()
11295 "Paste as a port map."
11296 (let ((margin (current-indentation))
11297 list-margin start port
3dcb36b7
JB
11298 (port-list (nth 2 vhdl-port-list)))
11299 (when port-list
5eabfe72
KH
11300 (setq start (point))
11301 (vhdl-insert-keyword "PORT MAP (")
11302 (if (not vhdl-association-list-with-formals)
11303 ;; paste list of actual ports
3dcb36b7 11304 (while port-list
5eabfe72 11305 (insert (vhdl-replace-string vhdl-actual-port-name
3dcb36b7
JB
11306 (car (nth 0 (car port-list)))))
11307 (setq port-list (cdr port-list))
0a2e512a 11308 (insert (if port-list ", " ")")))
5eabfe72 11309 (unless vhdl-argument-list-indent
3dcb36b7 11310 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11311 (setq list-margin (current-column))
3dcb36b7
JB
11312 (while port-list
11313 (setq port (car port-list))
11314 ;; paste group comment and spacing
11315 (when (eq vhdl-include-group-comments 'always)
11316 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11317 ;; paste formal and actual port
11318 (insert (car (nth 0 port)) " => ")
11319 (insert (vhdl-replace-string vhdl-actual-port-name
11320 (car (nth 0 port))))
3dcb36b7
JB
11321 (setq port-list (cdr port-list))
11322 (insert (if port-list "," ");"))
5eabfe72
KH
11323 ;; paste comment
11324 (when (or vhdl-include-direction-comments
3dcb36b7 11325 vhdl-include-type-comments
5eabfe72
KH
11326 (and vhdl-include-port-comments (nth 4 port)))
11327 (vhdl-comment-insert-inline
11328 (concat
3dcb36b7
JB
11329 (cond ((and vhdl-include-direction-comments
11330 vhdl-include-type-comments)
11331 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11332 (nth 3 port) "] "))
11333 ((and vhdl-include-direction-comments (nth 2 port))
11334 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11335 (vhdl-include-direction-comments " ")
11336 (vhdl-include-type-comments
11337 (concat "[" (nth 3 port) "] ")))
11338 (when vhdl-include-port-comments (nth 4 port))) t))
11339 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11340 ;; align port clause
11341 (when vhdl-auto-align
3dcb36b7 11342 (vhdl-align-region-groups start (point) 1))))))
5eabfe72 11343
3dcb36b7 11344(defun vhdl-port-paste-instance (&optional name no-indent title)
5eabfe72
KH
11345 "Paste as an instantiation."
11346 (interactive)
11347 (if (not vhdl-port-list)
3dcb36b7 11348 (error "ERROR: No port read")
5eabfe72
KH
11349 (let ((orig-vhdl-port-list vhdl-port-list))
11350 ;; flatten local copy of port list (must be flat for port mapping)
11351 (vhdl-port-flatten)
3dcb36b7
JB
11352 (unless no-indent (indent-according-to-mode))
11353 (let ((margin (current-indentation)))
5eabfe72 11354 ;; paste instantiation
3dcb36b7
JB
11355 (cond (name
11356 (insert name))
11357 ((equal (cdr vhdl-instance-name) "")
11358 (setq name (vhdl-template-field "instance name")))
11359 ((string-match "\%d" (cdr vhdl-instance-name))
11360 (let ((n 1))
11361 (while (save-excursion
11362 (setq name (format (vhdl-replace-string
11363 vhdl-instance-name
11364 (nth 0 vhdl-port-list)) n))
11365 (goto-char (point-min))
11366 (vhdl-re-search-forward name nil t))
11367 (setq n (1+ n)))
11368 (insert name)))
11369 (t (insert (vhdl-replace-string vhdl-instance-name
11370 (nth 0 vhdl-port-list)))))
11371 (message "Pasting port as instantiation \"%s\"..." name)
11372 (insert ": ")
11373 (when title
11374 (save-excursion
11375 (beginning-of-line)
11376 (indent-to vhdl-basic-offset)
11377 (insert "-- instance \"" name "\"\n")))
11378 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
11379 (insert (nth 0 vhdl-port-list))
11380 (vhdl-insert-keyword "ENTITY ")
3dcb36b7 11381 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
5eabfe72
KH
11382 (when (nth 1 vhdl-port-list)
11383 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11384 (vhdl-port-paste-generic-map t t))
11385 (when (nth 2 vhdl-port-list)
11386 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11387 (vhdl-port-paste-port-map))
0a2e512a
RF
11388 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11389 (insert ";"))
3dcb36b7
JB
11390 (message "Pasting port as instantiation \"%s\"...done" name))
11391 (setq vhdl-port-list orig-vhdl-port-list))))
11392
11393(defun vhdl-port-paste-constants (&optional no-indent)
11394 "Paste generics as constants."
11395 (interactive)
11396 (if (not vhdl-port-list)
11397 (error "ERROR: No port read")
11398 (let ((orig-vhdl-port-list vhdl-port-list))
11399 (message "Pasting port as constants...")
11400 ;; flatten local copy of port list (must be flat for constant initial.)
11401 (vhdl-port-flatten)
11402 (unless no-indent (indent-according-to-mode))
11403 (let ((margin (current-indentation))
11404 start generic name
11405 (generic-list (nth 1 vhdl-port-list)))
11406 (when generic-list
11407 (setq start (point))
11408 (while generic-list
11409 (setq generic (car generic-list))
11410 ;; paste group comment and spacing
11411 (when (memq vhdl-include-group-comments '(decl always))
11412 (vhdl-paste-group-comment (nth 4 generic) margin))
11413 (vhdl-insert-keyword "CONSTANT ")
11414 ;; paste generic constants
11415 (setq name (nth 0 generic))
11416 (when name
11417 (insert (car name))
11418 ;; paste type
11419 (insert " : " (nth 1 generic))
11420 ;; paste initialization
11421 (when (nth 2 generic)
11422 (insert " := " (nth 2 generic)))
11423 (insert ";")
11424 ;; paste comment
11425 (when (and vhdl-include-port-comments (nth 3 generic))
11426 (vhdl-comment-insert-inline (nth 3 generic) t))
11427 (setq generic-list (cdr generic-list))
11428 (when generic-list (insert "\n") (indent-to margin))))
11429 ;; align signal list
11430 (when vhdl-auto-align
11431 (vhdl-align-region-groups start (point) 1))))
11432 (message "Pasting port as constants...done")
5eabfe72
KH
11433 (setq vhdl-port-list orig-vhdl-port-list))))
11434
3dcb36b7 11435(defun vhdl-port-paste-signals (&optional initialize no-indent)
5eabfe72
KH
11436 "Paste ports as internal signals."
11437 (interactive)
11438 (if (not vhdl-port-list)
3dcb36b7 11439 (error "ERROR: No port read")
5eabfe72 11440 (message "Pasting port as signals...")
3dcb36b7 11441 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11442 (let ((margin (current-indentation))
11443 start port names
3dcb36b7
JB
11444 (port-list (nth 2 vhdl-port-list)))
11445 (when port-list
5eabfe72 11446 (setq start (point))
3dcb36b7
JB
11447 (while port-list
11448 (setq port (car port-list))
11449 ;; paste group comment and spacing
11450 (when (memq vhdl-include-group-comments '(decl always))
11451 (vhdl-paste-group-comment (nth 5 port) margin))
5eabfe72
KH
11452 ;; paste object
11453 (if (nth 1 port)
11454 (insert (nth 1 port) " ")
11455 (vhdl-insert-keyword "SIGNAL "))
11456 ;; paste actual port signals
11457 (setq names (nth 0 port))
11458 (while names
11459 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11460 (setq names (cdr names))
11461 (when names (insert ", ")))
11462 ;; paste type
11463 (insert " : " (nth 3 port))
11464 ;; paste initialization (inputs only)
3dcb36b7
JB
11465 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11466 (insert " := " (if (string-match "(.+)" (nth 3 port))
11467 "(others => '0')" "'0'")))
5eabfe72
KH
11468 (insert ";")
11469 ;; paste comment
3dcb36b7
JB
11470 (when (or vhdl-include-direction-comments
11471 (and vhdl-include-port-comments (nth 4 port)))
11472 (vhdl-comment-insert-inline
11473 (concat
11474 (cond ((and vhdl-include-direction-comments (nth 2 port))
11475 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11476 (vhdl-include-direction-comments " "))
11477 (when vhdl-include-port-comments (nth 4 port))) t))
11478 (setq port-list (cdr port-list))
11479 (when port-list (insert "\n") (indent-to margin)))
5eabfe72 11480 ;; align signal list
3dcb36b7 11481 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
5eabfe72
KH
11482 (message "Pasting port as signals...done")))
11483
3dcb36b7
JB
11484(defun vhdl-port-paste-initializations (&optional no-indent)
11485 "Paste ports as signal initializations."
5eabfe72
KH
11486 (interactive)
11487 (if (not vhdl-port-list)
3dcb36b7 11488 (error "ERROR: No port read")
5eabfe72 11489 (let ((orig-vhdl-port-list vhdl-port-list))
3dcb36b7
JB
11490 (message "Pasting port as initializations...")
11491 ;; flatten local copy of port list (must be flat for signal initial.)
5eabfe72 11492 (vhdl-port-flatten)
3dcb36b7 11493 (unless no-indent (indent-according-to-mode))
5eabfe72 11494 (let ((margin (current-indentation))
3dcb36b7
JB
11495 start port name
11496 (port-list (nth 2 vhdl-port-list)))
11497 (when port-list
5eabfe72 11498 (setq start (point))
3dcb36b7
JB
11499 (while port-list
11500 (setq port (car port-list))
11501 ;; paste actual port signal (inputs only)
11502 (when (equal "IN" (upcase (nth 2 port)))
11503 (setq name (car (nth 0 port)))
11504 (insert (vhdl-replace-string vhdl-actual-port-name name))
5eabfe72 11505 ;; paste initialization
3dcb36b7
JB
11506 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11507 "(others => '0')" "'0'") ";"))
11508 (setq port-list (cdr port-list))
11509 (when (and port-list
11510 (equal "IN" (upcase (nth 2 (car port-list)))))
11511 (insert "\n") (indent-to margin)))
11512 ;; align signal list
11513 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11514 (message "Pasting port as initializations...done")
5eabfe72
KH
11515 (setq vhdl-port-list orig-vhdl-port-list))))
11516
11517(defun vhdl-port-paste-testbench ()
3dcb36b7 11518 "Paste as a bare-bones testbench."
5eabfe72
KH
11519 (interactive)
11520 (if (not vhdl-port-list)
3dcb36b7 11521 (error "ERROR: No port read")
5eabfe72
KH
11522 (let ((case-fold-search t)
11523 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11524 (nth 0 vhdl-port-list)))
11525 (source-buffer (current-buffer))
3dcb36b7
JB
11526 arch-name config-name ent-file-name arch-file-name
11527 ent-buffer arch-buffer position)
5eabfe72 11528 ;; open entity file
3dcb36b7 11529 (unless (eq vhdl-testbench-create-files 'none)
5eabfe72 11530 (setq ent-file-name
0a2e512a
RF
11531 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11532 ent-name t)
11533 "." (file-name-extension (buffer-file-name))))
3dcb36b7 11534 (if (file-exists-p ent-file-name)
5eabfe72 11535 (if (y-or-n-p
3dcb36b7
JB
11536 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11537 (progn (find-file ent-file-name)
11538 (erase-buffer)
11539 (set-buffer-modified-p nil))
11540 (if (eq vhdl-testbench-create-files 'separate)
11541 (setq ent-file-name nil)
11542 (error "ERROR: Pasting port as testbench...aborted")))
11543 (find-file ent-file-name)))
11544 (unless (and (eq vhdl-testbench-create-files 'separate)
11545 (null ent-file-name))
11546 ;; paste entity header
11547 (if vhdl-testbench-include-header
11548 (progn (vhdl-template-header
11549 (concat "Testbench for design \""
11550 (nth 0 vhdl-port-list) "\""))
11551 (goto-char (point-max)))
11552 (vhdl-comment-display-line) (insert "\n\n"))
11553 ;; paste std_logic_1164 package
11554 (when vhdl-testbench-include-library
11555 (vhdl-template-package-std-logic-1164)
11556 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11557 ;; paste entity declaration
11558 (vhdl-insert-keyword "ENTITY ")
5eabfe72
KH
11559 (insert ent-name)
11560 (vhdl-insert-keyword " IS")
3dcb36b7 11561 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
5eabfe72 11562 (insert "\n")
3dcb36b7
JB
11563 (vhdl-insert-keyword "END ")
11564 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11565 (insert ent-name ";")
11566 (insert "\n\n")
11567 (vhdl-comment-display-line) (insert "\n"))
11568 ;; get architecture name
11569 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11570 (read-from-minibuffer "architecture name: "
11571 nil vhdl-minibuffer-local-map)
11572 (vhdl-replace-string vhdl-testbench-architecture-name
11573 (nth 0 vhdl-port-list))))
11574 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11575 ;; open architecture file
11576 (if (not (eq vhdl-testbench-create-files 'separate))
5eabfe72 11577 (insert "\n")
3dcb36b7
JB
11578 (setq ent-buffer (current-buffer))
11579 (setq arch-file-name
0a2e512a
RF
11580 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11581 (concat ent-name " " arch-name) t)
11582 "." (file-name-extension (buffer-file-name))))
3dcb36b7
JB
11583 (when (and (file-exists-p arch-file-name)
11584 (not (y-or-n-p (concat "File \"" arch-file-name
11585 "\" exists; overwrite? "))))
11586 (error "ERROR: Pasting port as testbench...aborted"))
11587 (find-file arch-file-name)
11588 (erase-buffer)
11589 (set-buffer-modified-p nil)
11590 ;; paste architecture header
11591 (if vhdl-testbench-include-header
11592 (progn (vhdl-template-header
11593 (concat "Testbench architecture for design \""
11594 (nth 0 vhdl-port-list) "\""))
11595 (goto-char (point-max)))
11596 (vhdl-comment-display-line) (insert "\n\n")))
11597 ;; paste architecture body
11598 (vhdl-insert-keyword "ARCHITECTURE ")
11599 (insert arch-name)
11600 (vhdl-insert-keyword " OF ")
11601 (insert ent-name)
11602 (vhdl-insert-keyword " IS")
11603 (insert "\n\n") (indent-to vhdl-basic-offset)
11604 ;; paste component declaration
11605 (unless (vhdl-use-direct-instantiation)
11606 (vhdl-port-paste-component t)
11607 (insert "\n\n") (indent-to vhdl-basic-offset))
11608 ;; paste constants
11609 (when (nth 1 vhdl-port-list)
11610 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11611 (vhdl-port-paste-constants t)
11612 (insert "\n\n") (indent-to vhdl-basic-offset))
11613 ;; paste internal signals
11614 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11615 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11616 (insert "\n")
11617 ;; paste custom declarations
11618 (unless (equal "" vhdl-testbench-declarations)
5eabfe72 11619 (insert "\n")
3dcb36b7
JB
11620 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11621 (setq position (point))
11622 (insert "\n\n")
11623 (vhdl-comment-display-line) (insert "\n")
11624 (when vhdl-testbench-include-configuration
11625 (setq config-name (vhdl-replace-string
11626 vhdl-testbench-configuration-name
11627 (concat ent-name " " arch-name)))
11628 (insert "\n")
11629 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11630 (vhdl-insert-keyword " OF ") (insert ent-name)
11631 (vhdl-insert-keyword " IS\n")
11632 (indent-to vhdl-basic-offset)
11633 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11634 (indent-to vhdl-basic-offset)
11635 (vhdl-insert-keyword "END FOR;\n")
11636 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11637 (vhdl-comment-display-line) (insert "\n"))
11638 (goto-char position)
11639 (vhdl-template-begin-end
11640 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11641 ;; paste instantiation
11642 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11643 (vhdl-port-paste-instance
11644 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11645 (insert "\n")
11646 ;; paste custom statements
11647 (unless (equal "" vhdl-testbench-statements)
11648 (insert "\n")
11649 (vhdl-insert-string-or-file vhdl-testbench-statements))
11650 (insert "\n")
11651 (indent-to vhdl-basic-offset)
11652 (unless (eq vhdl-testbench-create-files 'none)
11653 (setq arch-buffer (current-buffer))
11654 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11655 (set-buffer arch-buffer) (save-buffer))
29a4e67d 11656 (message "%s"
3dcb36b7
JB
11657 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11658 ent-name arch-name)
11659 (and ent-file-name
11660 (format "\n File created: \"%s\"" ent-file-name))
11661 (and arch-file-name
11662 (format "\n File created: \"%s\"" arch-file-name)))))))
5eabfe72
KH
11663
11664
11665;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11666;;; Subprogram interface translation
5eabfe72
KH
11667;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11668
3dcb36b7
JB
11669(defvar vhdl-subprog-list nil
11670 "Variable to hold last subprogram interface parsed.")
11671;; structure: (parenthesised expression means list of such entries)
11672;; (subprog-name kind
11673;; ((names) object direct type init comment group-comment)
11674;; return-type return-comment group-comment)
5eabfe72 11675
3dcb36b7
JB
11676(defvar vhdl-subprog-flattened nil
11677 "Indicates whether an subprogram interface has been flattened.")
5eabfe72 11678
3dcb36b7
JB
11679(defun vhdl-subprog-flatten ()
11680 "Flatten interface list so that only one parameter exists per line."
11681 (interactive)
11682 (if (not vhdl-subprog-list)
11683 (error "ERROR: No subprogram interface has been read")
11684 (message "Flattening subprogram interface...")
11685 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11686 new-subprog-list old-subprog new-subprog names)
11687 ;; traverse parameter list and flatten entries
11688 (while old-subprog-list
11689 (setq old-subprog (car old-subprog-list))
11690 (setq names (car old-subprog))
11691 (while names
11692 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11693 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11694 (setq names (cdr names)))
11695 (setq old-subprog-list (cdr old-subprog-list)))
11696 (setq vhdl-subprog-list
11697 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11698 new-subprog-list (nth 3 vhdl-subprog-list)
11699 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11700 vhdl-subprog-flattened t)
11701 (message "Flattening subprogram interface...done"))))
11702
11703(defun vhdl-subprog-copy ()
11704 "Get interface information from a subprogram specification."
11705 (interactive)
11706 (save-excursion
11707 (let (parse-error pos end-of-list
11708 name kind param-list object names direct type init
11709 comment group-comment
11710 return-type return-comment return-group-comment)
11711 (vhdl-prepare-search-2
11712 (setq
11713 parse-error
11714 (catch 'parse
11715 ;; check if within function declaration
11716 (setq pos (point))
11717 (end-of-line)
11718 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11719 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11720 (goto-char (match-end 0))
11721 (save-excursion (backward-char)
11722 (forward-sexp)
11723 (<= pos (point))))
11724 (throw 'parse "ERROR: Not within a subprogram specification"))
11725 (setq name (match-string-no-properties 5))
11726 (setq kind (if (match-string 2) 'procedure 'function))
11727 (setq end-of-list (not (match-string 7)))
11728 (message "Reading interface of subprogram \"%s\"..." name)
11729 ;; parse parameter list
11730 (setq group-comment (vhdl-parse-group-comment))
11731 (setq end-of-list (or end-of-list
11732 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11733 (while (not end-of-list)
11734 ;; parse object
11735 (setq object
11736 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11737 (match-string-no-properties 1)))
11738 ;; parse names (accept extended identifiers)
11739 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11740 (setq names (list (match-string-no-properties 1)))
11741 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11742 (setq names (append names (list (match-string-no-properties 1)))))
11743 ;; parse direction
11744 (vhdl-parse-string ":[ \t\n]*")
11745 (setq direct
11746 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11747 (match-string-no-properties 1)))
11748 ;; parse type
11749 (vhdl-parse-string "\\([^():;\n]+\\)")
11750 (setq type (match-string-no-properties 1))
11751 (setq comment nil)
11752 (while (looking-at "(")
11753 (setq type
11754 (concat type
11755 (buffer-substring-no-properties
11756 (point) (progn (forward-sexp) (point)))
11757 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11758 (match-string-no-properties 1)))))
11759 ;; special case: closing parenthesis is on separate line
11760 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11761 (setq comment (substring type (match-beginning 2)))
11762 (setq type (substring type 0 (match-beginning 1))))
11763 ;; strip off trailing group-comment
11764 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11765 (setq type (substring type 0 (match-end 1)))
11766 ;; parse initialization expression
11767 (setq init nil)
11768 (when (vhdl-parse-string ":=[ \t\n]*" t)
11769 (vhdl-parse-string "\\([^();\n]*\\)")
11770 (setq init (match-string-no-properties 1))
11771 (while (looking-at "(")
11772 (setq init
11773 (concat init
11774 (buffer-substring-no-properties
11775 (point) (progn (forward-sexp) (point)))
11776 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11777 (match-string-no-properties 1))))))
11778 ;; special case: closing parenthesis is on separate line
11779 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11780 (setq comment (substring init (match-beginning 2)))
11781 (setq init (substring init 0 (match-beginning 1)))
11782 (vhdl-forward-syntactic-ws))
11783 (skip-chars-forward " \t")
11784 ;; parse inline comment, special case: as above, no initial.
11785 (unless comment
11786 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11787 (match-string-no-properties 1))))
11788 (vhdl-forward-syntactic-ws)
11789 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11790 ;; parse inline comment
11791 (unless comment
11792 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11793 (match-string-no-properties 1))))
11794 (setq return-group-comment (vhdl-parse-group-comment))
11795 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11796 ;; parse return type
11797 (when (match-string 3)
11798 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11799 (setq return-type (match-string-no-properties 1))
11800 (when (and return-type
11801 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11802 (setq return-comment (substring return-type (match-beginning 2)))
11803 (setq return-type (substring return-type 0 (match-beginning 1))))
11804 ;; strip of trailing group-comment
11805 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11806 (setq return-type (substring return-type 0 (match-end 1)))
11807 ;; parse return comment
11808 (unless return-comment
11809 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11810 (match-string-no-properties 1)))))
11811 ;; parse inline comment
11812 (unless comment
11813 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11814 (match-string-no-properties 1))))
11815 ;; save everything in list
11816 (setq param-list (append param-list
11817 (list (list names object direct type init
11818 comment group-comment))))
11819 ;; parse group comment and spacing
11820 (setq group-comment (vhdl-parse-group-comment)))
11821 (message "Reading interface of subprogram \"%s\"...done" name)
11822 nil)))
11823 ;; finish parsing
11824 (if parse-error
11825 (error parse-error)
11826 (setq vhdl-subprog-list
11827 (list name kind param-list return-type return-comment
11828 return-group-comment)
11829 vhdl-subprog-flattened nil)))))
11830
11831(defun vhdl-subprog-paste-specification (kind)
11832 "Paste as a subprogram specification."
11833 (indent-according-to-mode)
11834 (let ((margin (current-column))
11835 (param-list (nth 2 vhdl-subprog-list))
11836 list-margin start names param)
11837 ;; paste keyword and name
11838 (vhdl-insert-keyword
11839 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11840 (insert (nth 0 vhdl-subprog-list))
11841 (if (not param-list)
11842 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11843 (setq start (point))
11844 ;; paste parameter list
11845 (insert " (")
11846 (unless vhdl-argument-list-indent
11847 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11848 (setq list-margin (current-column))
11849 (while param-list
11850 (setq param (car param-list))
11851 ;; paste group comment and spacing
11852 (when (memq vhdl-include-group-comments (list kind 'always))
11853 (vhdl-paste-group-comment (nth 6 param) list-margin))
11854 ;; paste object
11855 (when (nth 1 param) (insert (nth 1 param) " "))
11856 ;; paste names
11857 (setq names (nth 0 param))
11858 (while names
11859 (insert (car names))
11860 (setq names (cdr names))
11861 (when names (insert ", ")))
11862 ;; paste direction
11863 (insert " : ")
11864 (when (nth 2 param) (insert (nth 2 param) " "))
11865 ;; paste type
11866 (insert (nth 3 param))
11867 ;; paste initialization
11868 (when (nth 4 param) (insert " := " (nth 4 param)))
11869 ;; terminate line
11870 (if (cdr param-list)
11871 (insert ";")
11872 (insert ")")
11873 (when (null (nth 3 vhdl-subprog-list))
11874 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11875 ;; paste comment
11876 (when (and vhdl-include-port-comments (nth 5 param))
11877 (vhdl-comment-insert-inline (nth 5 param) t))
11878 (setq param-list (cdr param-list))
11879 (when param-list (insert "\n") (indent-to list-margin)))
11880 (when (nth 3 vhdl-subprog-list)
11881 (insert "\n") (indent-to list-margin)
11882 ;; paste group comment and spacing
11883 (when (memq vhdl-include-group-comments (list kind 'always))
11884 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11885 ;; paste return type
11886 (insert "return " (nth 3 vhdl-subprog-list))
0a2e512a 11887 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
3dcb36b7
JB
11888 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11889 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11890 ;; align parameter list
11891 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11892 ;; paste body
11893 (when (eq kind 'body)
11894 (insert "\n")
11895 (vhdl-template-begin-end
11896 (unless (vhdl-standard-p '87)
11897 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11898 (nth 0 vhdl-subprog-list) margin))))
11899
11900(defun vhdl-subprog-paste-declaration ()
11901 "Paste as a subprogram declaration."
11902 (interactive)
11903 (if (not vhdl-subprog-list)
11904 (error "ERROR: No subprogram interface read")
11905 (message "Pasting interface as subprogram declaration \"%s\"..."
11906 (car vhdl-subprog-list))
11907 ;; paste specification
11908 (vhdl-subprog-paste-specification 'decl)
11909 (message "Pasting interface as subprogram declaration \"%s\"...done"
11910 (car vhdl-subprog-list))))
11911
11912(defun vhdl-subprog-paste-body ()
11913 "Paste as a subprogram body."
11914 (interactive)
11915 (if (not vhdl-subprog-list)
11916 (error "ERROR: No subprogram interface read")
11917 (message "Pasting interface as subprogram body \"%s\"..."
11918 (car vhdl-subprog-list))
11919 ;; paste specification and body
11920 (vhdl-subprog-paste-specification 'body)
11921 (message "Pasting interface as subprogram body \"%s\"...done"
11922 (car vhdl-subprog-list))))
11923
11924(defun vhdl-subprog-paste-call ()
11925 "Paste as a subprogram call."
11926 (interactive)
11927 (if (not vhdl-subprog-list)
11928 (error "ERROR: No subprogram interface read")
11929 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11930 param-list margin list-margin param start)
11931 ;; flatten local copy of interface list (must be flat for parameter mapping)
11932 (vhdl-subprog-flatten)
11933 (setq param-list (nth 2 vhdl-subprog-list))
11934 (indent-according-to-mode)
11935 (setq margin (current-indentation))
11936 (message "Pasting interface as subprogram call \"%s\"..."
11937 (car vhdl-subprog-list))
11938 ;; paste name
11939 (insert (nth 0 vhdl-subprog-list))
11940 (if (not param-list)
11941 (insert ";")
11942 (setq start (point))
11943 ;; paste parameter list
11944 (insert " (")
11945 (unless vhdl-argument-list-indent
11946 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11947 (setq list-margin (current-column))
11948 (while param-list
11949 (setq param (car param-list))
11950 ;; paste group comment and spacing
11951 (when (eq vhdl-include-group-comments 'always)
11952 (vhdl-paste-group-comment (nth 6 param) list-margin))
11953 ;; paste formal port
11954 (insert (car (nth 0 param)) " => ")
11955 (setq param-list (cdr param-list))
11956 (insert (if param-list "," ");"))
11957 ;; paste comment
11958 (when (and vhdl-include-port-comments (nth 5 param))
11959 (vhdl-comment-insert-inline (nth 5 param)))
11960 (when param-list (insert "\n") (indent-to list-margin)))
11961 ;; align parameter list
11962 (when vhdl-auto-align
11963 (vhdl-align-region-groups start (point) 1)))
11964 (message "Pasting interface as subprogram call \"%s\"...done"
11965 (car vhdl-subprog-list))
11966 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11967
11968
11969;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11970;;; Miscellaneous
11971;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11972
11973;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11974;; Hippie expand customization
11975
11976(defvar vhdl-expand-upper-case nil)
11977
11978(defun vhdl-try-expand-abbrev (old)
11979 "Try expanding abbreviations from `vhdl-abbrev-list'."
11980 (unless old
11981 (he-init-string (he-dabbrev-beg) (point))
5eabfe72
KH
11982 (setq he-expand-list
11983 (let ((abbrev-list vhdl-abbrev-list)
11984 (sel-abbrev-list '()))
11985 (while abbrev-list
11986 (when (or (not (stringp (car abbrev-list)))
11987 (string-match
11988 (concat "^" he-search-string) (car abbrev-list)))
11989 (setq sel-abbrev-list
11990 (cons (car abbrev-list) sel-abbrev-list)))
11991 (setq abbrev-list (cdr abbrev-list)))
11992 (nreverse sel-abbrev-list))))
11993 (while (and he-expand-list
11994 (or (not (stringp (car he-expand-list)))
11995 (he-string-member (car he-expand-list) he-tried-table t)))
11996; (equal (car he-expand-list) he-search-string)))
11997 (unless (stringp (car he-expand-list))
11998 (setq vhdl-expand-upper-case (car he-expand-list)))
11999 (setq he-expand-list (cdr he-expand-list)))
12000 (if (null he-expand-list)
12001 (progn (when old (he-reset-string))
12002 nil)
12003 (he-substitute-string
12004 (if vhdl-expand-upper-case
12005 (upcase (car he-expand-list))
12006 (car he-expand-list))
12007 t)
12008 (setq he-expand-list (cdr he-expand-list))
12009 t))
12010
12011(defun vhdl-he-list-beg ()
12012 "Also looks at the word before `(' in order to better match parenthesized
12013expressions (e.g. for index ranges of types and signals)."
12014 (save-excursion
12015 (condition-case ()
12016 (progn (backward-up-list 1)
12017 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12018 (error ()))
12019 (point)))
12020
12021;; override `he-list-beg' from `hippie-exp'
12022(unless (and (boundp 'viper-mode) viper-mode)
5eabfe72
KH
12023 (defalias 'he-list-beg 'vhdl-he-list-beg))
12024
12025;; function for expanding abbrevs and dabbrevs
3dcb36b7 12026(defun vhdl-expand-abbrev (arg))
5eabfe72
KH
12027(fset 'vhdl-expand-abbrev (make-hippie-expand-function
12028 '(try-expand-dabbrev
12029 try-expand-dabbrev-all-buffers
12030 vhdl-try-expand-abbrev)))
12031
12032;; function for expanding parenthesis
3dcb36b7 12033(defun vhdl-expand-paren (arg))
5eabfe72
KH
12034(fset 'vhdl-expand-paren (make-hippie-expand-function
12035 '(try-expand-list
12036 try-expand-list-all-buffers)))
12037
12038;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12039;; Case fixing
d2ddb974
KH
12040
12041(defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
a4c6cfad
JB
12042 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12043depending on parameter UPPER-CASE."
3dcb36b7 12044 (let ((case-replace nil)
5eabfe72 12045 (last-update 0))
3dcb36b7 12046 (vhdl-prepare-search-2
5eabfe72
KH
12047 (save-excursion
12048 (goto-char end)
12049 (setq end (point-marker))
12050 (goto-char beg)
12051 (while (re-search-forward word-regexp end t)
3dcb36b7 12052 (or (vhdl-in-literal)
5eabfe72
KH
12053 (if upper-case
12054 (upcase-word -1)
12055 (downcase-word -1)))
3dcb36b7 12056 (when (and count vhdl-progress-interval (not noninteractive)
5eabfe72
KH
12057 (< vhdl-progress-interval
12058 (- (nth 1 (current-time)) last-update)))
12059 (message "Fixing case... (%2d%s)"
12060 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12061 "%")
12062 (setq last-update (nth 1 (current-time)))))
3dcb36b7 12063 (goto-char end)))))
d2ddb974
KH
12064
12065(defun vhdl-fix-case-region (beg end &optional arg)
12066 "Convert all VHDL words in region to lower or upper case, depending on
3dcb36b7 12067options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974
KH
12068 (interactive "r\nP")
12069 (vhdl-fix-case-region-1
5eabfe72 12070 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
d2ddb974 12071 (vhdl-fix-case-region-1
5eabfe72 12072 beg end vhdl-upper-case-types vhdl-types-regexp 1)
d2ddb974 12073 (vhdl-fix-case-region-1
5eabfe72
KH
12074 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12075 (vhdl-fix-case-region-1
3dcb36b7
JB
12076 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12077 (when vhdl-progress-interval (message "Fixing case...done")))
d2ddb974 12078
5eabfe72
KH
12079(defun vhdl-fix-case-buffer ()
12080 "Convert all VHDL words in buffer to lower or upper case, depending on
3dcb36b7 12081options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974 12082 (interactive)
5eabfe72
KH
12083 (vhdl-fix-case-region (point-min) (point-max)))
12084
3dcb36b7
JB
12085(defun vhdl-fix-case-word (&optional arg)
12086 "Convert word after cursor to upper case if necessary."
12087 (interactive "p")
12088 (save-excursion
12089 (when arg (backward-word 1))
12090 (vhdl-prepare-search-1
12091 (when (and vhdl-upper-case-keywords
12092 (looking-at vhdl-keywords-regexp))
12093 (upcase-word 1))
12094 (when (and vhdl-upper-case-types
12095 (looking-at vhdl-types-regexp))
12096 (upcase-word 1))
12097 (when (and vhdl-upper-case-attributes
12098 (looking-at vhdl-attributes-regexp))
12099 (upcase-word 1))
12100 (when (and vhdl-upper-case-enum-values
12101 (looking-at vhdl-enum-values-regexp))
12102 (upcase-word 1)))))
12103
5eabfe72
KH
12104;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12105;; Line handling functions
d2ddb974
KH
12106
12107(defun vhdl-current-line ()
12108 "Return the line number of the line containing point."
12109 (save-restriction
12110 (widen)
0a2e512a
RF
12111 (save-excursion
12112 (beginning-of-line)
958a2b4c 12113 (1+ (count-lines (point-min) (point))))))
d2ddb974 12114
5eabfe72 12115(defun vhdl-line-kill-entire (&optional arg)
d2ddb974 12116 "Delete entire line."
5eabfe72
KH
12117 (interactive "p")
12118 (beginning-of-line)
12119 (kill-line (or arg 1)))
12120
12121(defun vhdl-line-kill (&optional arg)
12122 "Kill current line."
12123 (interactive "p")
12124 (vhdl-line-kill-entire arg))
12125
12126(defun vhdl-line-copy (&optional arg)
12127 "Copy current line."
12128 (interactive "p")
12129 (save-excursion
12130 (beginning-of-line)
12131 (let ((position (point)))
12132 (forward-line (or arg 1))
12133 (copy-region-as-kill position (point)))))
12134
12135(defun vhdl-line-yank ()
12136 "Yank entire line."
d2ddb974 12137 (interactive)
5eabfe72
KH
12138 (beginning-of-line)
12139 (yank))
d2ddb974 12140
5eabfe72
KH
12141(defun vhdl-line-expand (&optional prefix-arg)
12142 "Hippie-expand current line."
12143 (interactive "P")
12144 (let ((case-fold-search t) (case-replace nil)
12145 (hippie-expand-try-functions-list
12146 '(try-expand-line try-expand-line-all-buffers)))
12147 (hippie-expand prefix-arg)))
12148
12149(defun vhdl-line-transpose-next (&optional arg)
12150 "Interchange this line with next line."
12151 (interactive "p")
12152 (forward-line 1)
12153 (transpose-lines (or arg 1))
12154 (forward-line -1))
12155
12156(defun vhdl-line-transpose-previous (&optional arg)
12157 "Interchange this line with previous line."
12158 (interactive "p")
12159 (forward-line 1)
12160 (transpose-lines (- 0 (or arg 0)))
12161 (forward-line -1))
12162
12163(defun vhdl-line-open ()
d2ddb974
KH
12164 "Open a new line and indent."
12165 (interactive)
5eabfe72
KH
12166 (end-of-line -0)
12167 (newline-and-indent))
d2ddb974 12168
3dcb36b7
JB
12169(defun vhdl-delete-indentation ()
12170 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12171it works within comments too."
12172 (interactive)
12173 (let ((fill-prefix "-- "))
12174 (delete-indentation)))
d2ddb974 12175
5eabfe72 12176;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12177;; Move functions
d2ddb974 12178
3dcb36b7
JB
12179(defun vhdl-forward-same-indent ()
12180 "Move forward to next line with same indent."
12181 (interactive)
12182 (let ((pos (point))
12183 (indent (current-indentation)))
12184 (beginning-of-line 2)
12185 (while (and (not (eobp))
12186 (or (looking-at "^\\s-*\\(--.*\\)?$")
12187 (> (current-indentation) indent)))
12188 (beginning-of-line 2))
12189 (if (= (current-indentation) indent)
12190 (back-to-indentation)
12191 (message "No following line with same indent found in this block")
12192 (goto-char pos)
12193 nil)))
5eabfe72 12194
3dcb36b7
JB
12195(defun vhdl-backward-same-indent ()
12196 "Move backward to previous line with same indent."
12197 (interactive)
12198 (let ((pos (point))
12199 (indent (current-indentation)))
12200 (beginning-of-line -0)
12201 (while (and (not (bobp))
12202 (or (looking-at "^\\s-*\\(--.*\\)?$")
12203 (> (current-indentation) indent)))
12204 (beginning-of-line -0))
12205 (if (= (current-indentation) indent)
12206 (back-to-indentation)
12207 (message "No preceding line with same indent found in this block")
12208 (goto-char pos)
12209 nil)))
5eabfe72
KH
12210
12211;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
12212;; Statistics
12213
12214(defun vhdl-statistics-buffer ()
12215 "Get some file statistics."
12216 (interactive)
12217 (let ((no-stats 0)
12218 (no-code-lines 0)
12219 (no-lines (count-lines (point-min) (point-max))))
12220 (save-excursion
12221 ;; count statements
12222 (goto-char (point-min))
12223 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12224 (if (match-string 1)
12225 (goto-char (match-end 1))
12226 (setq no-stats (1+ no-stats))))
12227 ;; count code lines
12228 (goto-char (point-min))
12229 (while (not (eobp))
12230 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12231 (setq no-code-lines (1+ no-code-lines)))
12232 (beginning-of-line 2)))
12233 ;; print results
12234 (message "\n\
12235File statistics: \"%s\"\n\
12236---------------------\n\
12237# statements : %5d\n\
12238# code lines : %5d\n\
12239# total lines : %5d\n\ "
0a2e512a
RF
12240 (buffer-file-name) no-stats no-code-lines no-lines)
12241 (unless vhdl-emacs-21 (vhdl-show-messages))))
3dcb36b7 12242
5eabfe72 12243;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12244;; Help functions
d2ddb974 12245
3dcb36b7
JB
12246(defun vhdl-re-search-forward (regexp &optional bound noerror count)
12247 "Like `re-search-forward', but does not match within literals."
12248 (let (pos)
12249 (save-excursion
12250 (while (and (setq pos (re-search-forward regexp bound noerror count))
12251 (vhdl-in-literal))))
12252 (when pos (goto-char pos))
12253 pos))
12254
12255(defun vhdl-re-search-backward (regexp &optional bound noerror count)
12256 "Like `re-search-backward', but does not match within literals."
12257 (let (pos)
12258 (save-excursion
12259 (while (and (setq pos (re-search-backward regexp bound noerror count))
12260 (vhdl-in-literal))))
12261 (when pos (goto-char pos))
12262 pos))
5eabfe72 12263
d2ddb974 12264
3dcb36b7
JB
12265;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12266;;; Project
12267;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12268
12269(defun vhdl-set-project (name)
12270 "Set current project to NAME."
12271 (interactive
12272 (list (let ((completion-ignore-case t))
12273 (completing-read "Project name: " vhdl-project-alist nil t))))
12274 (cond ((equal name "")
12275 (setq vhdl-project nil)
12276 (message "Current VHDL project: None"))
12277 ((assoc name vhdl-project-alist)
12278 (setq vhdl-project name)
12279 (message "Current VHDL project: \"%s\"" name))
12280 (t
12281 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12282 (vhdl-speedbar-update-current-project))
12283
0a2e512a
RF
12284(defun vhdl-set-default-project ()
12285 "Set current project as default on startup."
12286 (interactive)
12287 (customize-set-variable 'vhdl-project vhdl-project)
12288 (customize-save-customized))
12289
3dcb36b7
JB
12290(defun vhdl-toggle-project (name token indent)
12291 "Set current project to NAME or unset if NAME is current project."
12292 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12293
12294(defun vhdl-export-project (file-name)
12295 "Write project setup for current project."
12296 (interactive
12297 (let ((name (vhdl-resolve-env-variable
12298 (vhdl-replace-string
12299 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12300 (concat (subst-char-in-string
12301 ? ?_ (or (vhdl-project-p)
12302 (error "ERROR: No current project")))
12303 " " (user-login-name))))))
12304 (list (read-file-name
12305 "Write project file: "
12306 (when (file-name-absolute-p name) "") nil nil name))))
12307 (setq file-name (abbreviate-file-name file-name))
12308 (let ((orig-buffer (current-buffer)))
12309 (unless (file-exists-p (file-name-directory file-name))
12310 (make-directory (file-name-directory file-name) t))
12311 (if (not (file-writable-p file-name))
12312 (error "ERROR: File not writable: \"%s\"" file-name)
12313 (set-buffer (find-file-noselect file-name t t))
12314 (erase-buffer)
12315 (insert ";; -*- Emacs-Lisp -*-\n\n"
12316 ";;; " (file-name-nondirectory file-name)
12317 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12318 ";; Project : " vhdl-project "\n"
12319 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12320 (user-login-name) "\n\n\n"
12321 ";; project name\n"
12322 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12323 ";; project setup\n"
12324 "(aput 'vhdl-project-alist vhdl-project\n'")
12325 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12326 (insert ")\n")
12327 (save-buffer)
12328 (kill-buffer (current-buffer))
12329 (set-buffer orig-buffer))))
12330
12331(defun vhdl-import-project (file-name &optional auto not-make-current)
12332 "Read project setup and set current project."
12333 (interactive
12334 (let ((name (vhdl-resolve-env-variable
12335 (vhdl-replace-string
12336 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12337 (concat "" " " (user-login-name))))))
12338 (list (read-file-name
12339 "Read project file: " (when (file-name-absolute-p name) "") nil t
12340 (file-name-directory name)))))
12341 (when (file-exists-p file-name)
12342 (condition-case ()
12343 (let ((current-project vhdl-project))
12344 (load-file file-name)
12345 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12346 (adelete 'vhdl-project-alist vhdl-project)
0a2e512a 12347 (error ""))
3dcb36b7
JB
12348 (when not-make-current
12349 (setq vhdl-project current-project))
12350 (vhdl-update-mode-menu)
12351 (vhdl-speedbar-refresh)
12352 (unless not-make-current
12353 (message "Current VHDL project: \"%s\"%s"
12354 vhdl-project (if auto " (auto-loaded)" ""))))
12355 (error (vhdl-warning
12356 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12357
12358(defun vhdl-duplicate-project ()
12359 "Duplicate setup of current project."
5eabfe72 12360 (interactive)
3dcb36b7
JB
12361 (let ((new-name (read-from-minibuffer "New project name: "))
12362 (project-entry (aget vhdl-project-alist vhdl-project t)))
12363 (setq vhdl-project-alist
12364 (append vhdl-project-alist
12365 (list (cons new-name project-entry))))
12366 (vhdl-update-mode-menu)))
12367
12368(defun vhdl-auto-load-project ()
12369 "Automatically load project setup at startup."
12370 (let ((file-name-list vhdl-project-file-name)
12371 file-list list-length)
12372 (while file-name-list
12373 (setq file-list
12374 (append file-list
12375 (file-expand-wildcards
12376 (vhdl-resolve-env-variable
12377 (vhdl-replace-string
12378 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12379 (concat "\*" " " (user-login-name)))))))
12380 (setq list-length (or list-length (length file-list)))
12381 (setq file-name-list (cdr file-name-list)))
12382 (while file-list
12383 (vhdl-import-project (expand-file-name (car file-list)) t
12384 (not (> list-length 0)))
12385 (setq list-length (1- list-length))
12386 (setq file-list (cdr file-list)))))
12387
12388;; automatically load project setup when idle after startup
12389(when (memq 'startup vhdl-project-auto-load)
12390 (if noninteractive
12391 (vhdl-auto-load-project)
12392 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
5eabfe72
KH
12393
12394
12395;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12396;;; Hideshow
12397;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12398;; (using `hideshow.el')
d2ddb974 12399
3dcb36b7
JB
12400(defconst vhdl-hs-start-regexp
12401 (concat
12402 "\\(^\\)\\s-*\\("
12403 ;; generic/port clause
12404 "\\(generic\\|port\\)[ \t\n]*(\\|"
12405 ;; component
12406 "component\\>\\|"
12407 ;; component instantiation
12408 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12409 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12410 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12411 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12412 ;; subprogram
12413 "\\(function\\|procedure\\)\\>\\|"
12414 ;; process, block
12415 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12416 ;; configuration declaration
12417 "configuration\\>"
12418 "\\)")
12419 "Regexp to match start of construct to hide.")
12420
12421(defun vhdl-hs-forward-sexp-func (count)
a4c6cfad 12422 "Find end of construct to hide (for hideshow). Only searches forward."
3dcb36b7
JB
12423 (let ((pos (point)))
12424 (vhdl-prepare-search-2
12425 (beginning-of-line)
12426 (cond
12427 ;; generic/port clause
12428 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12429 (goto-char (match-end 0))
12430 (backward-char)
12431 (forward-sexp))
12432 ;; component declaration
12433 ((looking-at "^\\s-*component\\>")
12434 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12435 ;; component instantiation
12436 ((looking-at
12437 (concat
12438 "^\\s-*\\w+\\s-*:[ \t\n]*"
12439 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12440 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12441 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12442 (goto-char (match-end 0))
12443 (backward-char)
12444 (forward-sexp)
12445 (setq pos (point))
12446 (vhdl-forward-syntactic-ws)
12447 (when (looking-at "port\\s-+map[ \t\n]*(")
12448 (goto-char (match-end 0))
12449 (backward-char)
12450 (forward-sexp)
12451 (setq pos (point)))
12452 (goto-char pos))
12453 ;; subprogram declaration/body
12454 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12455 (goto-char (match-end 0))
12456 (vhdl-forward-syntactic-ws)
12457 (when (looking-at "(")
12458 (forward-sexp))
12459 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12460 (vhdl-in-literal)))
12461 ;; subprogram body
12462 (when (match-string 2)
12463 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12464 (backward-word 1)
12465 (vhdl-forward-sexp)))
12466 ;; block (recursive)
12467 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12468 (goto-char (match-end 0))
12469 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12470 (match-beginning 2))
12471 (vhdl-hs-forward-sexp-func count)))
12472 ;; process
12473 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12474 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12475 ;; configuration declaration
12476 ((looking-at "^\\s-*configuration\\>")
12477 (forward-word 4)
12478 (vhdl-forward-sexp))
12479 (t (goto-char pos))))))
5eabfe72
KH
12480
12481(defun vhdl-hideshow-init ()
12482 "Initialize `hideshow'."
3dcb36b7
JB
12483 (when vhdl-hideshow-menu
12484 (vhdl-hs-minor-mode 1)))
12485
12486(defun vhdl-hs-minor-mode (&optional arg)
12487 "Toggle hideshow minor mode and update menu bar."
12488 (interactive "P")
12489 (require 'hideshow)
12490 ;; check for hideshow version 5.x
12491 (if (not (boundp 'hs-block-start-mdata-select))
12492 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12493 ;; initialize hideshow
12494 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12495 (setq hs-special-modes-alist
12496 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12497 'vhdl-hs-forward-sexp-func nil)
12498 hs-special-modes-alist)))
12499 (make-local-variable 'hs-minor-mode-hook)
12500 (if vhdl-hide-all-init
12501 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12502 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12503 (hs-minor-mode arg)
56eb0904 12504 (force-mode-line-update))) ; hack to update menu bar
5eabfe72
KH
12505
12506
12507;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12508;;; Font locking
12509;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12510;; (using `font-lock.el')
12511
5eabfe72 12512;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12513;; Help functions
5eabfe72
KH
12514
12515(defun vhdl-within-translate-off ()
12516 "Return point if within translate-off region, else nil."
12517 (and (save-excursion
12518 (re-search-backward
12519 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12520 (equal "off" (match-string 1))
12521 (point)))
12522
12523(defun vhdl-start-translate-off (limit)
12524 "Return point before translate-off pragma if before LIMIT, else nil."
12525 (when (re-search-forward
12526 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12527 (match-beginning 0)))
12528
12529(defun vhdl-end-translate-off (limit)
12530 "Return point after translate-on pragma if before LIMIT, else nil."
12531 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12532
12533(defun vhdl-match-translate-off (limit)
12534 "Match a translate-off block, setting match-data and returning t, else nil."
12535 (when (< (point) limit)
12536 (let ((start (or (vhdl-within-translate-off)
12537 (vhdl-start-translate-off limit)))
12538 (case-fold-search t))
12539 (when start
12540 (let ((end (or (vhdl-end-translate-off limit) limit)))
12541 (set-match-data (list start end))
12542 (goto-char end))))))
12543
12544(defun vhdl-font-lock-match-item (limit)
a4c6cfad 12545 "Match, and move over, any declaration item after point. Adapted from
5eabfe72
KH
12546`font-lock-match-c-style-declaration-item-and-skip-to-next'."
12547 (condition-case nil
12548 (save-restriction
12549 (narrow-to-region (point-min) limit)
12550 ;; match item
3dcb36b7 12551 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5eabfe72
KH
12552 (save-match-data
12553 (goto-char (match-end 1))
12554 ;; move to next item
0a2e512a
RF
12555 (if (looking-at "\\(\\s-*,\\)")
12556 (goto-char (match-end 1))
5eabfe72
KH
12557 (end-of-line) t))))
12558 (error t)))
12559
12560;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12561;; Syntax definitions
12562
5eabfe72
KH
12563(defconst vhdl-font-lock-syntactic-keywords
12564 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12565 "Mark single quotes as having string quote syntax in 'c' instances.")
12566
d2ddb974
KH
12567(defvar vhdl-font-lock-keywords nil
12568 "Regular expressions to highlight in VHDL Mode.")
12569
3dcb36b7
JB
12570(defvar vhdl-font-lock-keywords-0
12571 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12572 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12573This does highlighting of template prompts and directives (pragmas).")
d2ddb974 12574
5eabfe72 12575(defvar vhdl-font-lock-keywords-1 nil
3dcb36b7 12576 ;; set in `vhdl-font-lock-init' because dependent on user options
5eabfe72
KH
12577 "For consideration as a value of `vhdl-font-lock-keywords'.
12578This does highlighting of keywords and standard identifiers.")
12579
12580(defconst vhdl-font-lock-keywords-2
d2ddb974
KH
12581 (list
12582 ;; highlight names of units, subprograms, and components when declared
12583 (list
12584 (concat
12585 "^\\s-*\\("
3dcb36b7
JB
12586 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12587 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
d2ddb974 12588 "\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12589 5 'font-lock-function-name-face)
12590
12591 ;; highlight entity names of architectures and configurations
12592 (list
12593 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12594 2 'font-lock-function-name-face)
d2ddb974
KH
12595
12596 ;; highlight labels of common constructs
12597 (list
12598 (concat
3dcb36b7
JB
12599 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12600 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12601 "postponed\\|process\\|"
5eabfe72
KH
12602 (when (vhdl-standard-p 'ams) "procedural\\|")
12603 "with\\|while"
0a2e512a 12604 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
d2ddb974
KH
12605 1 'font-lock-function-name-face)
12606
5eabfe72 12607 ;; highlight label and component name of component instantiations
d2ddb974 12608 (list
5eabfe72 12609 (concat
3dcb36b7
JB
12610 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12611 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12612 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12613
12614 ;; highlight label and instantiated unit of component instantiations
12615 (list
12616 (concat
12617 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12618 "\\(component\\|configuration\\|entity\\)\\s-+"
12619 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12620 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12621 '(5 font-lock-function-name-face nil t)
12622 '(7 font-lock-function-name-face nil t))
d2ddb974
KH
12623
12624 ;; highlight names and labels at end of constructs
12625 (list
12626 (concat
5eabfe72
KH
12627 "^\\s-*end\\s-+\\(\\("
12628 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
3dcb36b7
JB
12629 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12630 "procedure\\|\\(postponed\\s-+\\)?process\\|"
5eabfe72
KH
12631 (when (vhdl-standard-p 'ams) "procedural\\|")
12632 "units"
3dcb36b7 12633 "\\)\\s-+\\)?\\(\\w*\\)")
5eabfe72
KH
12634 5 'font-lock-function-name-face)
12635
12636 ;; highlight labels in exit and next statements
12637 (list
12638 (concat
12639 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12640 3 'font-lock-function-name-face)
12641
12642 ;; highlight entity name in attribute specifications
12643 (list
12644 (concat
12645 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12646 1 'font-lock-function-name-face)
12647
3dcb36b7
JB
12648 ;; highlight labels in block and component specifications
12649 (list
12650 (concat
12651 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12652 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12653 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12654
12655 ;; highlight names in library clauses
12656 (list "^\\s-*library\\>"
12657 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12658
12659 ;; highlight names in use clauses
5eabfe72
KH
12660 (list
12661 (concat
3dcb36b7
JB
12662 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12663 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12664 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12665 '(7 font-lock-function-name-face nil t))
5eabfe72
KH
12666
12667 ;; highlight attribute name in attribute declarations/specifications
12668 (list
12669 (concat
12670 "^\\s-*attribute\\s-+\\(\\w+\\)")
0a2e512a 12671 1 'vhdl-font-lock-attribute-face)
5eabfe72
KH
12672
12673 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12674 (list
12675 (concat
3dcb36b7 12676 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12677 3 'font-lock-type-face)
12678
12679 ;; highlight signal/variable/constant declaration names
12680 (list "\\(:[^=]\\)"
12681 '(vhdl-font-lock-match-item
12682 (progn (goto-char (match-beginning 1))
12683 (skip-syntax-backward " ")
12684 (skip-syntax-backward "w_")
12685 (skip-syntax-backward " ")
12686 (while (= (preceding-char) ?,)
12687 (backward-char 1)
12688 (skip-syntax-backward " ")
12689 (skip-syntax-backward "w_")
12690 (skip-syntax-backward " ")))
12691; (skip-chars-backward "^-(\n\";")
12692 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12693
3dcb36b7
JB
12694 ;; highlight formal parameters in component instantiations and subprogram
12695 ;; calls
12696 (list "\\(=>\\)"
12697 '(vhdl-font-lock-match-item
12698 (progn (goto-char (match-beginning 1))
12699 (skip-syntax-backward " ")
12700 (while (= (preceding-char) ?\)) (backward-sexp))
12701 (skip-syntax-backward "w_")
12702 (skip-syntax-backward " ")
0a2e512a 12703 (when (memq (preceding-char) '(?n ?N ?|))
3dcb36b7
JB
12704 (goto-char (point-max))))
12705 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12706
12707 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12708 ;; variables
12709 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
5eabfe72
KH
12710 '(vhdl-font-lock-match-item
12711 (progn (goto-char (match-end 1)) (match-beginning 2))
12712 nil (1 font-lock-variable-name-face)))
d2ddb974 12713 )
5eabfe72
KH
12714 "For consideration as a value of `vhdl-font-lock-keywords'.
12715This does context sensitive highlighting of names and labels.")
d2ddb974 12716
5eabfe72 12717(defvar vhdl-font-lock-keywords-3 nil
3dcb36b7 12718 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12719 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72
KH
12720This does highlighting of words with special syntax.")
12721
12722(defvar vhdl-font-lock-keywords-4 nil
3dcb36b7 12723 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12724 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12725This does highlighting of additional reserved words.")
d2ddb974 12726
5eabfe72
KH
12727(defconst vhdl-font-lock-keywords-5
12728 ;; background highlight translate-off regions
0a2e512a 12729 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
5eabfe72
KH
12730 "For consideration as a value of `vhdl-font-lock-keywords'.
12731This does background highlighting of translate-off regions.")
12732
12733;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12734;; Font and color definitions
12735
0a2e512a 12736(defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
d2ddb974
KH
12737 "Face name to use for prompts.")
12738
0a2e512a 12739(defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
5eabfe72
KH
12740 "Face name to use for standardized attributes.")
12741
0a2e512a 12742(defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
5eabfe72 12743 "Face name to use for standardized enumeration values.")
d2ddb974 12744
0a2e512a 12745(defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
5eabfe72 12746 "Face name to use for standardized functions and packages.")
d2ddb974 12747
0a2e512a 12748(defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
5eabfe72 12749 "Face name to use for directives.")
d2ddb974 12750
0a2e512a 12751(defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
5eabfe72 12752 "Face name to use for additional reserved words.")
d2ddb974 12753
0a2e512a 12754(defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
5eabfe72 12755 "Face name to use for translate-off regions.")
d2ddb974 12756
5eabfe72
KH
12757;; face names to use for words with special syntax.
12758(let ((syntax-alist vhdl-special-syntax-alist)
12759 name)
12760 (while syntax-alist
0a2e512a
RF
12761 (setq name (vhdl-function-name
12762 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
d4a5b644
GM
12763 (eval `(defvar ,name ',name
12764 ,(concat "Face name to use for "
12765 (nth 0 (car syntax-alist)) ".")))
5eabfe72
KH
12766 (setq syntax-alist (cdr syntax-alist))))
12767
3dcb36b7 12768(defgroup vhdl-highlight-faces nil
5eabfe72
KH
12769 "Faces for highlighting."
12770 :group 'vhdl-highlight)
d2ddb974 12771
3dcb36b7
JB
12772;; add faces used from `font-lock'
12773(custom-add-to-group
12774 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12775(custom-add-to-group
12776 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12777(custom-add-to-group
12778 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12779(custom-add-to-group
12780 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12781(custom-add-to-group
12782 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12783(custom-add-to-group
12784 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12785
0a2e512a 12786(defface vhdl-font-lock-prompt-face
f47877ee 12787 '((((min-colors 88) (class color) (background light))
ea81d57e 12788 (:foreground "Red1" :bold t))
f47877ee 12789 (((class color) (background light)) (:foreground "Red" :bold t))
3dcb36b7 12790 (((class color) (background dark)) (:foreground "Pink" :bold t))
d2ddb974 12791 (t (:inverse-video t)))
5eabfe72 12792 "Font lock mode face used to highlight prompts."
fa6674e3 12793 :group 'vhdl-highlight-faces)
d2ddb974 12794
0a2e512a 12795(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12796 '((((class color) (background light)) (:foreground "Orchid"))
12797 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12798 (t (:italic t :bold t)))
5eabfe72 12799 "Font lock mode face used to highlight standardized attributes."
fa6674e3 12800 :group 'vhdl-highlight-faces)
d2ddb974 12801
0a2e512a 12802(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12803 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12804 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12805 (t (:italic t :bold t)))
5eabfe72 12806 "Font lock mode face used to highlight standardized enumeration values."
fa6674e3 12807 :group 'vhdl-highlight-faces)
d2ddb974 12808
0a2e512a 12809(defface vhdl-font-lock-function-face
3dcb36b7 12810 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12811 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12812 (t (:italic t :bold t)))
5eabfe72 12813 "Font lock mode face used to highlight standardized functions and packages."
fa6674e3 12814 :group 'vhdl-highlight-faces)
d2ddb974 12815
0a2e512a 12816(defface vhdl-font-lock-directive-face
5eabfe72
KH
12817 '((((class color) (background light)) (:foreground "CadetBlue"))
12818 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12819 (t (:italic t :bold t)))
5eabfe72 12820 "Font lock mode face used to highlight directives."
fa6674e3 12821 :group 'vhdl-highlight-faces)
d2ddb974 12822
0a2e512a 12823(defface vhdl-font-lock-reserved-words-face
3dcb36b7 12824 '((((class color) (background light)) (:foreground "Orange" :bold t))
5bb5087f 12825 (((min-colors 88) (class color) (background dark))
ea81d57e 12826 (:foreground "Yellow1" :bold t))
3dcb36b7 12827 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12828 (t ()))
5eabfe72 12829 "Font lock mode face used to highlight additional reserved words."
fa6674e3 12830 :group 'vhdl-highlight-faces)
d2ddb974 12831
0a2e512a 12832(defface vhdl-font-lock-translate-off-face
5eabfe72
KH
12833 '((((class color) (background light)) (:background "LightGray"))
12834 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12835 (t ()))
5eabfe72 12836 "Font lock mode face used to background highlight translate-off regions."
fa6674e3 12837 :group 'vhdl-highlight-faces)
d2ddb974 12838
5eabfe72
KH
12839;; font lock mode faces used to highlight words with special syntax.
12840(let ((syntax-alist vhdl-special-syntax-alist))
12841 (while syntax-alist
0a2e512a
RF
12842 (eval `(defface ,(vhdl-function-name
12843 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12844 '((((class color) (background light))
12845 (:foreground ,(nth 2 (car syntax-alist))))
12846 (((class color) (background dark))
12847 (:foreground ,(nth 3 (car syntax-alist))))
12848 (t ()))
12849 ,(concat "Font lock mode face used to highlight "
12850 (nth 0 (car syntax-alist)) ".")
fa6674e3 12851 :group 'vhdl-highlight-faces))
5eabfe72
KH
12852 (setq syntax-alist (cdr syntax-alist))))
12853
12854;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12855;; Font lock initialization
12856
12857(defun vhdl-font-lock-init ()
5eabfe72 12858 "Initialize fontification."
0a2e512a 12859 ;; highlight template prompts and directives
3dcb36b7
JB
12860 (setq vhdl-font-lock-keywords-0
12861 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12862 vhdl-template-prompt-syntax ">\\)")
0a2e512a 12863 2 'vhdl-font-lock-prompt-face t)
3dcb36b7
JB
12864 (list (concat "--\\s-*"
12865 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
0a2e512a
RF
12866 2 'vhdl-font-lock-directive-face t)
12867 ;; highlight c-preprocessor directives
12868 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12869 '(1 font-lock-builtin-face)
12870 '(3 font-lock-variable-name-face nil t))))
5eabfe72
KH
12871 ;; highlight keywords and standardized types, attributes, enumeration
12872 ;; values, and subprograms
12873 (setq vhdl-font-lock-keywords-1
12874 (list
0a2e512a
RF
12875 (list (concat "'" vhdl-attributes-regexp)
12876 1 'vhdl-font-lock-attribute-face)
5eabfe72 12877 (list vhdl-types-regexp 1 'font-lock-type-face)
0a2e512a
RF
12878 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12879 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12880 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
5eabfe72
KH
12881 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12882 ;; highlight words with special syntax.
12883 (setq vhdl-font-lock-keywords-3
12884 (let ((syntax-alist vhdl-special-syntax-alist)
12885 keywords)
12886 (while syntax-alist
12887 (setq keywords
12888 (cons
12889 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12890 (vhdl-function-name
0a2e512a 12891 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
5eabfe72
KH
12892 keywords))
12893 (setq syntax-alist (cdr syntax-alist)))
12894 keywords))
12895 ;; highlight additional reserved words
12896 (setq vhdl-font-lock-keywords-4
0a2e512a
RF
12897 (list (list vhdl-reserved-words-regexp 1
12898 'vhdl-font-lock-reserved-words-face)))
5eabfe72 12899 ;; highlight everything together
d2ddb974 12900 (setq vhdl-font-lock-keywords
5eabfe72
KH
12901 (append
12902 vhdl-font-lock-keywords-0
12903 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12904 (when (or vhdl-highlight-forbidden-words
12905 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12906 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12907 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12908 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12909
12910;; initialize fontification for VHDL Mode
12911(vhdl-font-lock-init)
12912
12913(defun vhdl-fontify-buffer ()
12914 "Re-initialize fontification and fontify buffer."
12915 (interactive)
12916 (setq font-lock-defaults
12917 (list
12918 'vhdl-font-lock-keywords nil
12919 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12920 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12921 (when (fboundp 'font-lock-unset-defaults)
12922 (font-lock-unset-defaults)) ; not implemented in XEmacs
0a2e512a 12923 (font-lock-set-defaults)
3dcb36b7
JB
12924 (font-lock-mode nil)
12925 (font-lock-mode t))
5eabfe72
KH
12926
12927;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12928;; Initialization for postscript printing
12929
12930(defun vhdl-ps-print-settings ()
12931 "Initialize custom face and page settings for postscript printing."
12932 ;; define custom face settings
12933 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12934 ps-print-color-p)
12935 (set (make-local-variable 'ps-bold-faces)
0a2e512a
RF
12936 '(font-lock-keyword-face
12937 font-lock-type-face
12938 vhdl-font-lock-attribute-face
12939 vhdl-font-lock-enumvalue-face
12940 vhdl-font-lock-directive-face))
d2ddb974
KH
12941 (set (make-local-variable 'ps-italic-faces)
12942 '(font-lock-comment-face
0a2e512a
RF
12943 font-lock-function-name-face
12944 font-lock-type-face
12945 vhdl-font-lock-attribute-face
12946 vhdl-font-lock-enumvalue-face
12947 vhdl-font-lock-directive-face))
d2ddb974
KH
12948 (set (make-local-variable 'ps-underlined-faces)
12949 '(font-lock-string-face))
5eabfe72 12950 (setq ps-always-build-face-reference t))
d2ddb974
KH
12951 ;; define page settings, so that a line containing 79 characters (default)
12952 ;; fits into one column
5eabfe72
KH
12953 (when vhdl-print-two-column
12954 (set (make-local-variable 'ps-landscape-mode) t)
12955 (set (make-local-variable 'ps-number-of-columns) 2)
12956 (set (make-local-variable 'ps-font-size) 7.0)
12957 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12958 (set (make-local-variable 'ps-header-font-size) 9.0)
12959 (set (make-local-variable 'ps-header-offset) 12.0)
12960 (when (eq ps-paper-type 'letter)
12961 (set (make-local-variable 'ps-inter-column) 40.0)
12962 (set (make-local-variable 'ps-left-margin) 40.0)
12963 (set (make-local-variable 'ps-right-margin) 40.0))))
12964
12965(defun vhdl-ps-print-init ()
12966 "Initialize postscript printing."
f8246027 12967 (if (featurep 'xemacs)
3dcb36b7
JB
12968 (when (boundp 'ps-print-color-p)
12969 (vhdl-ps-print-settings))
5eabfe72
KH
12970 (make-local-variable 'ps-print-hook)
12971 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12972
12973
12974;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12975;;; Hierarchy browser (using `speedbar.el')
12976;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12977;; Allows displaying the hierarchy of all VHDL design units contained in a
12978;; directory by using the speedbar.
12979
12980;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12981;; Variables
12982
12983(defvar vhdl-entity-alist nil
3dcb36b7
JB
12984 "Cache with entities and corresponding architectures for each
12985project/directory.")
5eabfe72 12986;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12987;; (cache-key
12988;; (ent-key ent-name ent-file ent-line
12989;; (arch-key arch-name arch-file arch-line
12990;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
0a2e512a
RF
12991;; inst-arch-key inst-conf-key inst-lib-key inst-path)
12992;; (lib-name pack-key))
12993;; mra-key (lib-name pack-key))
3dcb36b7
JB
12994
12995(defvar vhdl-config-alist nil
12996 "Cache with configurations for each project/directory.")
12997;; structure: (parenthesised expression means list of such entries)
12998;; (cache-key
12999;; (conf-key conf-name conf-file conf-line ent-key arch-key
13000;; (inst-key inst-comp-name inst-ent-key inst-arch-key
0a2e512a 13001;; inst-conf-key inst-lib-key)
3dcb36b7 13002;; (lib-name pack-key)))
5eabfe72
KH
13003
13004(defvar vhdl-package-alist nil
3dcb36b7 13005 "Cache with packages for each project/directory.")
5eabfe72 13006;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
13007;; (cache-key
13008;; (pack-key pack-name pack-file pack-line
13009;; (comp-key comp-name comp-file comp-line)
13010;; (func-key func-name func-file func-line)
13011;; (lib-name pack-key)
13012;; pack-body-file pack-body-line
13013;; (func-key func-name func-body-file func-body-line)
13014;; (lib-name pack-key)))
5eabfe72
KH
13015
13016(defvar vhdl-ent-inst-alist nil
3dcb36b7 13017 "Cache with instantiated entities for each project/directory.")
5eabfe72 13018;; structure: (parenthesised expression means list of such entries)
3dcb36b7 13019;; (cache-key (inst-ent-key))
5eabfe72 13020
3dcb36b7
JB
13021(defvar vhdl-file-alist nil
13022 "Cache with design units in each file for each project/directory.")
13023;; structure: (parenthesised expression means list of such entries)
13024;; (cache-key
13025;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
0a2e512a 13026;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 13027
3dcb36b7
JB
13028(defvar vhdl-directory-alist nil
13029 "Cache with source directories for each project.")
13030;; structure: (parenthesised expression means list of such entries)
13031;; (cache-key (directory))
5eabfe72 13032
3dcb36b7 13033(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
13034 "Alist of design units simultaneously open in the current speedbar for each
13035directory and project.")
13036
3dcb36b7
JB
13037(defvar vhdl-speedbar-shown-project-list nil
13038 "List of projects simultaneously open in the current speedbar.")
5eabfe72 13039
3dcb36b7
JB
13040(defvar vhdl-updated-project-list nil
13041 "List of projects and directories with updated files.")
13042
13043(defvar vhdl-modified-file-list nil
13044 "List of modified files to be rescanned for hierarchy updating.")
13045
13046(defvar vhdl-speedbar-hierarchy-depth 0
13047 "Depth of instantiation hierarchy to display.")
13048
13049(defvar vhdl-speedbar-show-projects nil
13050 "Non-nil means project hierarchy is displayed in speedbar, directory
13051hierarchy otherwise.")
13052
13053(defun vhdl-get-end-of-unit ()
13054 "Return position of end of current unit."
13055 (let ((pos (point)))
13056 (save-excursion
13057 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13058 (save-excursion
13059 (goto-char (match-beginning 0))
13060 (vhdl-backward-syntactic-ws)
13061 (and (/= (preceding-char) ?\;) (not (bobp))))))
13062 (re-search-backward "^[ \t]*end\\>" pos 1)
13063 (point))))
13064
13065(defun vhdl-match-string-downcase (num &optional string)
13066 "Like `match-string-no-properties' with down-casing."
13067 (let ((match (match-string-no-properties num string)))
13068 (and match (downcase match))))
5eabfe72 13069
5eabfe72
KH
13070
13071;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13072;; Scan functions
13073
3dcb36b7
JB
13074(defun vhdl-scan-context-clause ()
13075 "Scan the context clause that preceeds a design unit."
13076 (let (lib-alist)
13077 (save-excursion
13078 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13079 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13080 (equal "USE" (upcase (match-string 1))))
13081 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13082 (setq lib-alist (cons (cons (match-string-no-properties 1)
13083 (vhdl-match-string-downcase 2))
13084 lib-alist))))))
13085 lib-alist))
13086
13087(defun vhdl-scan-directory-contents (name &optional project update num-string
13088 non-final)
a4c6cfad 13089 "Scan contents of VHDL files in directory or file pattern NAME."
3dcb36b7 13090 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
13091; (unless (file-directory-p (match-string 1 name))
13092; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
13093 (let* ((dir-name (match-string 1 name))
13094 (file-pattern (match-string 2 name))
13095 (is-directory (= 0 (length file-pattern)))
5eabfe72 13096 (file-list
3dcb36b7
JB
13097 (if update
13098 (list name)
13099 (if is-directory
13100 (vhdl-get-source-files t dir-name)
13101 (vhdl-directory-files
13102 dir-name t (wildcard-to-regexp file-pattern)))))
13103 (key (or project dir-name))
13104 (file-exclude-regexp
13105 (or (nth 3 (aget vhdl-project-alist project)) ""))
13106 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13107 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13108 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13109 ent-alist conf-alist pack-alist ent-inst-list file-alist
13110 tmp-list tmp-entry no-files files-exist big-files)
13111 (when (or project update)
13112 (setq ent-alist (aget vhdl-entity-alist key t)
13113 conf-alist (aget vhdl-config-alist key t)
13114 pack-alist (aget vhdl-package-alist key t)
13115 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13116 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
13117 (when (and (not is-directory) (null file-list))
13118 (message "No such file: \"%s\"" name))
3dcb36b7
JB
13119 (setq files-exist file-list)
13120 (when file-list
13121 (setq no-files (length file-list))
13122 (message "Scanning %s %s\"%s\"..."
13123 (if is-directory "directory" "files") (or num-string "") name)
13124 ;; exclude files
13125 (unless (equal file-exclude-regexp "")
13126 (let ((case-fold-search nil)
13127 file-tmp-list)
13128 (while file-list
13129 (unless (string-match file-exclude-regexp (car file-list))
13130 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13131 (setq file-list (cdr file-list)))
13132 (setq file-list (nreverse file-tmp-list))))
13133 ;; do for all files
13134 (while file-list
13135 (unless noninteractive
5eabfe72
KH
13136 (message "Scanning %s %s\"%s\"... (%2d%s)"
13137 (if is-directory "directory" "files")
13138 (or num-string "") name
3dcb36b7
JB
13139 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13140 (let ((file-name (abbreviate-file-name (car file-list)))
13141 ent-list arch-list arch-ent-list conf-list
13142 pack-list pack-body-list inst-list inst-ent-list)
13143 ;; scan file
13144 (vhdl-visit-file
13145 file-name nil
13146 (vhdl-prepare-search-2
13147 (save-excursion
13148 ;; scan for design units
13149 (if (and limit-design-file-size
13150 (< limit-design-file-size (buffer-size)))
13151 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13152 (setq big-files t))
13153 ;; scan for entities
13154 (goto-char (point-min))
13155 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13156 (let* ((ent-name (match-string-no-properties 1))
13157 (ent-key (downcase ent-name))
13158 (ent-entry (aget ent-alist ent-key t))
3dcb36b7
JB
13159 (lib-alist (vhdl-scan-context-clause)))
13160 (if (nth 1 ent-entry)
13161 (vhdl-warning-when-idle
13162 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13163 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13164 file-name (vhdl-current-line))
13165 (setq ent-list (cons ent-key ent-list))
13166 (aput 'ent-alist ent-key
13167 (list ent-name file-name (vhdl-current-line)
0a2e512a
RF
13168 (nth 3 ent-entry) (nth 4 ent-entry)
13169 lib-alist)))))
3dcb36b7
JB
13170 ;; scan for architectures
13171 (goto-char (point-min))
0a2e512a 13172 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
3dcb36b7
JB
13173 (let* ((arch-name (match-string-no-properties 1))
13174 (arch-key (downcase arch-name))
13175 (ent-name (match-string-no-properties 2))
13176 (ent-key (downcase ent-name))
13177 (ent-entry (aget ent-alist ent-key t))
13178 (arch-alist (nth 3 ent-entry))
13179 (arch-entry (aget arch-alist arch-key t))
13180 (lib-arch-alist (vhdl-scan-context-clause)))
13181 (if arch-entry
13182 (vhdl-warning-when-idle
13183 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13184 arch-name ent-name (nth 1 arch-entry)
13185 (nth 2 arch-entry) file-name (vhdl-current-line))
13186 (setq arch-list (cons arch-key arch-list)
13187 arch-ent-list (cons ent-key arch-ent-list))
13188 (aput 'arch-alist arch-key
13189 (list arch-name file-name (vhdl-current-line) nil
13190 lib-arch-alist))
13191 (aput 'ent-alist ent-key
13192 (list (or (nth 0 ent-entry) ent-name)
13193 (nth 1 ent-entry) (nth 2 ent-entry)
13194 (vhdl-sort-alist arch-alist)
0a2e512a 13195 arch-key (nth 5 ent-entry))))))
3dcb36b7
JB
13196 ;; scan for configurations
13197 (goto-char (point-min))
13198 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13199 (let* ((conf-name (match-string-no-properties 1))
13200 (conf-key (downcase conf-name))
13201 (conf-entry (aget conf-alist conf-key t))
13202 (ent-name (match-string-no-properties 2))
13203 (ent-key (downcase ent-name))
13204 (lib-alist (vhdl-scan-context-clause))
13205 (conf-line (vhdl-current-line))
13206 (end-of-unit (vhdl-get-end-of-unit))
13207 arch-key comp-conf-list inst-key-list
13208 inst-comp-key inst-ent-key inst-arch-key
13209 inst-conf-key inst-lib-key)
13210 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13211 (setq arch-key (vhdl-match-string-downcase 1)))
13212 (if conf-entry
13213 (vhdl-warning-when-idle
13214 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13215 conf-name ent-name (nth 1 conf-entry)
13216 (nth 2 conf-entry) file-name conf-line)
13217 (setq conf-list (cons conf-key conf-list))
13218 ;; scan for subconfigurations and subentities
13219 (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)
13220 (setq inst-comp-key (vhdl-match-string-downcase 3)
13221 inst-key-list (split-string
13222 (vhdl-match-string-downcase 1)
13223 "[ \t\n]*,[ \t\n]*"))
13224 (vhdl-forward-syntactic-ws)
13225 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13226 (setq
13227 inst-lib-key (vhdl-match-string-downcase 3)
13228 inst-ent-key (and (match-string 2)
13229 (vhdl-match-string-downcase 4))
13230 inst-arch-key (and (match-string 2)
13231 (vhdl-match-string-downcase 6))
13232 inst-conf-key (and (not (match-string 2))
13233 (vhdl-match-string-downcase 4)))
13234 (while inst-key-list
13235 (setq comp-conf-list
13236 (cons (list (car inst-key-list)
13237 inst-comp-key inst-ent-key
13238 inst-arch-key inst-conf-key
13239 inst-lib-key)
13240 comp-conf-list))
13241 (setq inst-key-list (cdr inst-key-list)))))
13242 (aput 'conf-alist conf-key
13243 (list conf-name file-name conf-line ent-key
13244 arch-key comp-conf-list lib-alist)))))
13245 ;; scan for packages
13246 (goto-char (point-min))
13247 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13248 (let* ((pack-name (match-string-no-properties 2))
13249 (pack-key (downcase pack-name))
13250 (is-body (match-string-no-properties 1))
13251 (pack-entry (aget pack-alist pack-key t))
13252 (pack-line (vhdl-current-line))
13253 (end-of-unit (vhdl-get-end-of-unit))
13254 comp-name func-name comp-alist func-alist lib-alist)
13255 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13256 (vhdl-warning-when-idle
13257 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13258 (if is-body " body" "") pack-name
13259 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13260 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13261 file-name (vhdl-current-line))
13262 ;; scan for context clauses
13263 (setq lib-alist (vhdl-scan-context-clause))
13264 ;; scan for component and subprogram declarations/bodies
13265 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13266 (if (equal (upcase (match-string 1)) "COMPONENT")
13267 (setq comp-name (match-string-no-properties 2)
13268 comp-alist
13269 (cons (list (downcase comp-name) comp-name
13270 file-name (vhdl-current-line))
13271 comp-alist))
13272 (setq func-name (match-string-no-properties 2)
13273 func-alist
13274 (cons (list (downcase func-name) func-name
13275 file-name (vhdl-current-line))
13276 func-alist))))
13277 (setq func-alist (nreverse func-alist))
13278 (setq comp-alist (nreverse comp-alist))
13279 (if is-body
13280 (setq pack-body-list (cons pack-key pack-body-list))
13281 (setq pack-list (cons pack-key pack-list)))
13282 (aput
13283 'pack-alist pack-key
13284 (if is-body
13285 (list (or (nth 0 pack-entry) pack-name)
13286 (nth 1 pack-entry) (nth 2 pack-entry)
13287 (nth 3 pack-entry) (nth 4 pack-entry)
13288 (nth 5 pack-entry)
13289 file-name pack-line func-alist lib-alist)
13290 (list pack-name file-name pack-line
13291 comp-alist func-alist lib-alist
13292 (nth 6 pack-entry) (nth 7 pack-entry)
13293 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13294 ;; scan for hierarchy
13295 (if (and limit-hier-file-size
13296 (< limit-hier-file-size (buffer-size)))
13297 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13298 (setq big-files t))
13299 ;; scan for architectures
13300 (goto-char (point-min))
13301 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13302 (let* ((ent-name (match-string-no-properties 2))
13303 (ent-key (downcase ent-name))
13304 (arch-name (match-string-no-properties 1))
13305 (arch-key (downcase arch-name))
13306 (ent-entry (aget ent-alist ent-key t))
13307 (arch-alist (nth 3 ent-entry))
13308 (arch-entry (aget arch-alist arch-key t))
13309 (beg-of-unit (point))
13310 (end-of-unit (vhdl-get-end-of-unit))
13311 (inst-no 0)
0a2e512a 13312 inst-alist inst-path)
3dcb36b7
JB
13313 ;; scan for contained instantiations
13314 (while (and (re-search-forward
13315 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13316 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13317 "component[ \t\n]+\\(\\w+\\)\\|"
0a2e512a
RF
13318 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13319 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13320 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
3dcb36b7
JB
13321 (or (not limit-hier-inst-no)
13322 (<= (setq inst-no (1+ inst-no))
13323 limit-hier-inst-no)))
0a2e512a
RF
13324 (cond
13325 ;; block/generate beginning found
13326 ((match-string 14)
13327 (setq inst-path
13328 (cons (match-string-no-properties 1) inst-path)))
13329 ;; block/generate end found
13330 ((match-string 16)
13331 (setq inst-path (cdr inst-path)))
13332 ;; instantiation found
13333 (t
13334 (let* ((inst-name (match-string-no-properties 1))
13335 (inst-key (downcase inst-name))
13336 (inst-comp-name
13337 (or (match-string-no-properties 3)
13338 (match-string-no-properties 6)))
13339 (inst-ent-key
13340 (or (and (match-string 8)
13341 (vhdl-match-string-downcase 11))
13342 (and inst-comp-name
13343 (downcase inst-comp-name))))
13344 (inst-arch-key (vhdl-match-string-downcase 13))
13345 (inst-conf-key
13346 (and (not (match-string 8))
13347 (vhdl-match-string-downcase 11)))
13348 (inst-lib-key (vhdl-match-string-downcase 10)))
13349 (goto-char (match-end 1))
13350 (setq inst-list (cons inst-key inst-list)
13351 inst-ent-list
13352 (cons inst-ent-key inst-ent-list))
13353 (setq inst-alist
13354 (append
13355 inst-alist
13356 (list (list inst-key inst-name file-name
13357 (vhdl-current-line) inst-comp-name
13358 inst-ent-key inst-arch-key
13359 inst-conf-key inst-lib-key
13360 (reverse inst-path)))))))))
3dcb36b7
JB
13361 ;; scan for contained configuration specifications
13362 (goto-char beg-of-unit)
13363 (while (re-search-forward
13364 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13365 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
0a2e512a 13366 (let* ((inst-comp-name (match-string-no-properties 3))
3dcb36b7
JB
13367 (inst-ent-key
13368 (and (match-string 6)
13369 (vhdl-match-string-downcase 9)))
13370 (inst-arch-key (vhdl-match-string-downcase 11))
13371 (inst-conf-key
13372 (and (not (match-string 6))
13373 (vhdl-match-string-downcase 9)))
13374 (inst-lib-key (vhdl-match-string-downcase 8))
13375 (inst-key-list
13376 (split-string (vhdl-match-string-downcase 1)
13377 "[ \t\n]*,[ \t\n]*"))
13378 (tmp-inst-alist inst-alist)
13379 inst-entry)
13380 (while tmp-inst-alist
13381 (when (and (or (equal "all" (car inst-key-list))
13382 (member (nth 0 (car tmp-inst-alist))
13383 inst-key-list))
13384 (equal
13385 (downcase
13386 (or (nth 4 (car tmp-inst-alist)) ""))
13387 (downcase inst-comp-name)))
13388 (setq inst-entry (car tmp-inst-alist))
13389 (setq inst-ent-list
13390 (cons (or inst-ent-key (nth 5 inst-entry))
13391 (vhdl-delete
13392 (nth 5 inst-entry) inst-ent-list)))
13393 (setq inst-entry
13394 (list (nth 0 inst-entry) (nth 1 inst-entry)
13395 (nth 2 inst-entry) (nth 3 inst-entry)
13396 (nth 4 inst-entry)
13397 (or inst-ent-key (nth 5 inst-entry))
13398 (or inst-arch-key (nth 6 inst-entry))
13399 inst-conf-key inst-lib-key))
13400 (setcar tmp-inst-alist inst-entry))
13401 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13402 ;; save in cache
13403 (aput 'arch-alist arch-key
13404 (list (nth 0 arch-entry) (nth 1 arch-entry)
13405 (nth 2 arch-entry) inst-alist
13406 (nth 4 arch-entry)))
13407 (aput 'ent-alist ent-key
13408 (list (nth 0 ent-entry) (nth 1 ent-entry)
13409 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
0a2e512a 13410 (nth 4 ent-entry) (nth 5 ent-entry)))
3dcb36b7
JB
13411 (when (and limit-hier-inst-no
13412 (> inst-no limit-hier-inst-no))
13413 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13414 (setq big-files t))
13415 (goto-char end-of-unit))))
13416 ;; remember design units for this file
13417 (aput 'file-alist file-name
13418 (list ent-list arch-list arch-ent-list conf-list
13419 pack-list pack-body-list inst-list inst-ent-list))
13420 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13421 (setq file-list (cdr file-list))))
13422 (when (or (and (not project) files-exist)
13423 (and project (not non-final)))
13424 ;; consistency checks:
13425 ;; check whether each architecture has a corresponding entity
13426 (setq tmp-list ent-alist)
13427 (while tmp-list
13428 (when (null (nth 2 (car tmp-list)))
13429 (setq tmp-entry (car (nth 4 (car tmp-list))))
13430 (vhdl-warning-when-idle
13431 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13432 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13433 (nth 3 tmp-entry)))
13434 (setq tmp-list (cdr tmp-list)))
13435 ;; check whether configuration has a corresponding entity/architecture
13436 (setq tmp-list conf-alist)
13437 (while tmp-list
13438 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13439 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13440 (setq tmp-entry (car tmp-list))
13441 (vhdl-warning-when-idle
13442 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13443 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13444 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13445 (setq tmp-entry (car tmp-list))
13446 (vhdl-warning-when-idle
13447 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13448 (nth 1 tmp-entry) (nth 4 tmp-entry)
13449 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13450 (setq tmp-list (cdr tmp-list)))
13451 ;; check whether each package body has a package declaration
13452 (setq tmp-list pack-alist)
13453 (while tmp-list
13454 (when (null (nth 2 (car tmp-list)))
13455 (setq tmp-entry (car tmp-list))
13456 (vhdl-warning-when-idle
13457 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13458 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13459 (setq tmp-list (cdr tmp-list)))
13460 ;; sort lists
13461 (setq ent-alist (vhdl-sort-alist ent-alist))
13462 (setq conf-alist (vhdl-sort-alist conf-alist))
13463 (setq pack-alist (vhdl-sort-alist pack-alist))
13464 ;; remember updated directory/project
13465 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13466 ;; clear directory alists
13467 (unless project
13468 (adelete 'vhdl-entity-alist key)
13469 (adelete 'vhdl-config-alist key)
13470 (adelete 'vhdl-package-alist key)
13471 (adelete 'vhdl-ent-inst-alist key)
13472 (adelete 'vhdl-file-alist key))
13473 ;; put directory contents into cache
13474 (aput 'vhdl-entity-alist key ent-alist)
13475 (aput 'vhdl-config-alist key conf-alist)
13476 (aput 'vhdl-package-alist key pack-alist)
13477 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13478 (aput 'vhdl-file-alist key file-alist)
13479 ;; final messages
13480 (message "Scanning %s %s\"%s\"...done"
13481 (if is-directory "directory" "files") (or num-string "") name)
13482 (unless project (message "Scanning directory...done"))
13483 (when big-files
13484 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13485 ;; save cache when scanned non-interactively
13486 (when (or (not project) (not non-final))
13487 (when (and noninteractive vhdl-speedbar-save-cache)
13488 (vhdl-save-cache key)))
13489 t))
5eabfe72 13490
3dcb36b7 13491(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13492 "Scan the contents of all VHDL files found in the directories and files
13493of PROJECT."
3dcb36b7
JB
13494 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13495 (default-dir (vhdl-resolve-env-variable
13496 (nth 1 (aget vhdl-project-alist project))))
13497 (file-exclude-regexp
13498 (or (nth 3 (aget vhdl-project-alist project)) ""))
13499 dir-list-tmp dir dir-name num-dir act-dir recursive)
13500 ;; clear project alists
13501 (adelete 'vhdl-entity-alist project)
13502 (adelete 'vhdl-config-alist project)
13503 (adelete 'vhdl-package-alist project)
13504 (adelete 'vhdl-ent-inst-alist project)
13505 (adelete 'vhdl-file-alist project)
13506 ;; expand directory names by default-directory
13507 (message "Collecting source files...")
13508 (while dir-list
13509 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13510 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13511 (setq recursive (match-string 1 dir)
13512 dir-name (match-string 3 dir))
13513 (setq dir-list-tmp
13514 (cons (concat recursive
13515 (if (file-name-absolute-p dir-name) "" default-dir)
13516 dir-name)
13517 dir-list-tmp))
13518 (setq dir-list (cdr dir-list)))
13519 ;; resolve path wildcards
5eabfe72
KH
13520 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13521 ;; expand directories
13522 (while dir-list-tmp
13523 (setq dir (car dir-list-tmp))
13524 ;; get subdirectories
3dcb36b7 13525 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13526 (setq dir-list (append dir-list (vhdl-get-subdirs
13527 (match-string 1 dir))))
13528 (setq dir-list (append dir-list (list dir))))
13529 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13530 ;; exclude files
13531 (unless (equal file-exclude-regexp "")
13532 (let ((case-fold-search nil))
13533 (while dir-list
13534 (unless (string-match file-exclude-regexp (car dir-list))
13535 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13536 (setq dir-list (cdr dir-list)))
13537 (setq dir-list (nreverse dir-list-tmp))))
13538 (message "Collecting source files...done")
13539 ;; scan for design units for each directory in DIR-LIST
13540 (setq dir-list-tmp nil
13541 num-dir (length dir-list)
5eabfe72
KH
13542 act-dir 1)
13543 (while dir-list
3dcb36b7
JB
13544 (setq dir-name (abbreviate-file-name
13545 (expand-file-name (car dir-list))))
13546 (vhdl-scan-directory-contents dir-name project nil
13547 (format "(%s/%s) " act-dir num-dir)
13548 (cdr dir-list))
13549 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13550 (setq dir-list (cdr dir-list)
13551 act-dir (1+ act-dir)))
3dcb36b7
JB
13552 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13553 (message "Scanning project \"%s\"...done" project)))
13554
13555(defun vhdl-update-file-contents (file-name)
13556 "Update hierarchy information by contents of current buffer."
13557 (setq file-name (abbreviate-file-name file-name))
13558 (let* ((dir-name (file-name-directory file-name))
13559 (directory-alist vhdl-directory-alist)
13560 updated)
13561 (while directory-alist
13562 (when (member dir-name (nth 1 (car directory-alist)))
13563 (let* ((vhdl-project (nth 0 (car directory-alist)))
13564 (project (vhdl-project-p))
13565 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13566 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13567 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13568 (ent-inst-list (car (aget vhdl-ent-inst-alist
13569 (or project dir-name) t)))
13570 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13571 (file-entry (aget file-alist file-name t))
13572 (ent-list (nth 0 file-entry))
13573 (arch-list (nth 1 file-entry))
13574 (arch-ent-list (nth 2 file-entry))
13575 (conf-list (nth 3 file-entry))
13576 (pack-list (nth 4 file-entry))
13577 (pack-body-list (nth 5 file-entry))
13578 (inst-ent-list (nth 7 file-entry))
13579 (cache-key (or project dir-name))
13580 arch-alist key ent-key entry)
13581 ;; delete design units previously contained in this file:
13582 ;; entities
13583 (while ent-list
13584 (setq key (car ent-list)
13585 entry (aget ent-alist key t))
13586 (when (equal file-name (nth 1 entry))
13587 (if (nth 3 entry)
13588 (aput 'ent-alist key
13589 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13590 (adelete 'ent-alist key)))
13591 (setq ent-list (cdr ent-list)))
13592 ;; architectures
13593 (while arch-list
13594 (setq key (car arch-list)
13595 ent-key (car arch-ent-list)
13596 entry (aget ent-alist ent-key t)
13597 arch-alist (nth 3 entry))
13598 (when (equal file-name (nth 1 (aget arch-alist key t)))
13599 (adelete 'arch-alist key)
13600 (if (or (nth 1 entry) arch-alist)
13601 (aput 'ent-alist ent-key
13602 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
0a2e512a 13603 arch-alist (nth 4 entry) (nth 5 entry)))
3dcb36b7
JB
13604 (adelete 'ent-alist ent-key)))
13605 (setq arch-list (cdr arch-list)
13606 arch-ent-list (cdr arch-ent-list)))
13607 ;; configurations
13608 (while conf-list
13609 (setq key (car conf-list))
13610 (when (equal file-name (nth 1 (aget conf-alist key t)))
13611 (adelete 'conf-alist key))
13612 (setq conf-list (cdr conf-list)))
13613 ;; package declarations
13614 (while pack-list
13615 (setq key (car pack-list)
13616 entry (aget pack-alist key t))
13617 (when (equal file-name (nth 1 entry))
13618 (if (nth 6 entry)
13619 (aput 'pack-alist key
13620 (list (nth 0 entry) nil nil nil nil nil
13621 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13622 (nth 9 entry)))
13623 (adelete 'pack-alist key)))
13624 (setq pack-list (cdr pack-list)))
13625 ;; package bodies
13626 (while pack-body-list
13627 (setq key (car pack-body-list)
13628 entry (aget pack-alist key t))
13629 (when (equal file-name (nth 6 entry))
13630 (if (nth 1 entry)
13631 (aput 'pack-alist key
13632 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13633 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13634 nil nil nil nil))
13635 (adelete 'pack-alist key)))
13636 (setq pack-body-list (cdr pack-body-list)))
13637 ;; instantiated entities
13638 (while inst-ent-list
13639 (setq ent-inst-list
13640 (vhdl-delete (car inst-ent-list) ent-inst-list))
13641 (setq inst-ent-list (cdr inst-ent-list)))
13642 ;; update caches
13643 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13644 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13645 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13646 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13647 ;; scan file
13648 (vhdl-scan-directory-contents file-name project t)
13649 (when (or (and vhdl-speedbar-show-projects project)
13650 (and (not vhdl-speedbar-show-projects) (not project)))
13651 (vhdl-speedbar-refresh project))
13652 (setq updated t)))
13653 (setq directory-alist (cdr directory-alist)))
13654 updated))
13655
13656(defun vhdl-update-hierarchy ()
13657 "Update directory and hierarchy information in speedbar."
13658 (let ((file-list (reverse vhdl-modified-file-list))
13659 updated)
13660 (when (and vhdl-speedbar-update-on-saving file-list)
13661 (while file-list
13662 (setq updated
13663 (or (vhdl-update-file-contents (car file-list))
13664 updated))
13665 (setq file-list (cdr file-list)))
13666 (setq vhdl-modified-file-list nil)
0a2e512a 13667 (vhdl-speedbar-update-current-unit)
3dcb36b7
JB
13668 (when updated (message "Updating hierarchy...done")))))
13669
13670;; structure (parenthesised expression means list of such entries)
13671;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13672;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13673;; comp-lib-name level)
13674(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13675 conf-inst-alist level indent
13676 &optional include-top ent-hier)
13677 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13678entity ENT-KEY."
13679 (let* ((ent-entry (aget ent-alist ent-key t))
13680 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13681 (cdar (last (nth 3 ent-entry)))))
13682 (inst-alist (nth 3 arch-entry))
13683 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13684 hier-list subcomp-list tmp-list inst-key inst-comp-name
13685 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13686 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13687 (when include-top
13688 (setq level (1+ level)))
13689 (when (member ent-key ent-hier)
13690 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13691 ;; check configured architecture (already checked during scanning)
13692; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13693; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13694 ;; process all instances
13695 (while inst-alist
13696 (setq inst-entry (car inst-alist)
13697 inst-key (nth 0 inst-entry)
13698 inst-comp-name (nth 4 inst-entry)
13699 inst-conf-key (nth 7 inst-entry))
13700 ;; search entry in configuration's instantiations list
13701 (setq tmp-list conf-inst-alist)
13702 (while (and tmp-list
13703 (not (and (member (nth 0 (car tmp-list))
13704 (list "all" inst-key))
13705 (equal (nth 1 (car tmp-list))
13706 (downcase (or inst-comp-name ""))))))
13707 (setq tmp-list (cdr tmp-list)))
13708 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13709 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13710 (when (and inst-conf-key (not inst-conf-entry))
13711 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13712 ;; determine entity
13713 (setq inst-ent-key
13714 (or (nth 2 (car tmp-list)) ; from configuration
13715 (nth 3 inst-conf-entry) ; from subconfiguration
13716 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13717 ; from configuration spec.
13718 (nth 5 inst-entry))) ; from direct instantiation
13719 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13720 ;; determine architecture
13721 (setq inst-arch-key
0a2e512a
RF
13722 (or (nth 3 (car tmp-list)) ; from configuration
13723 (nth 4 inst-conf-entry) ; from subconfiguration
13724 (nth 6 inst-entry) ; from direct instantiation
3dcb36b7 13725 (nth 4 (aget conf-alist (nth 7 inst-entry)))
0a2e512a
RF
13726 ; from configuration spec.
13727 (nth 4 inst-ent-entry) ; MRA
13728 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
3dcb36b7
JB
13729 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13730 ;; set library
13731 (setq inst-lib-key
0a2e512a
RF
13732 (or (nth 5 (car tmp-list)) ; from configuration
13733 (nth 8 inst-entry))) ; from direct instantiation
3dcb36b7
JB
13734 ;; gather information for this instance
13735 (setq comp-entry
13736 (list (nth 1 inst-entry)
13737 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13738 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13739 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13740 (or (nth 0 inst-arch-entry) inst-arch-key)
13741 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13742 (or (nth 0 inst-conf-entry) inst-conf-key)
13743 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13744 inst-lib-key level))
13745 ;; get subcomponent hierarchy
13746 (setq subcomp-list (vhdl-get-hierarchy
13747 ent-alist conf-alist
13748 inst-ent-key inst-arch-key inst-conf-key
13749 (nth 5 inst-conf-entry)
13750 (1+ level) indent nil (cons ent-key ent-hier)))
13751 ;; add to list
13752 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13753 (setq inst-alist (cdr inst-alist)))
13754 (when include-top
5eabfe72 13755 (setq hier-list
3dcb36b7
JB
13756 (cons (list nil nil (nth 0 ent-entry)
13757 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13758 (nth 0 arch-entry)
13759 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13760 nil nil
13761 nil (1- level))
13762 hier-list)))
13763 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13764 hier-list))
13765
3dcb36b7
JB
13766(defun vhdl-get-instantiations (ent-key indent)
13767 "Get all instantiations of entity ENT-KEY."
13768 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13769 arch-alist inst-alist ent-inst-list
13770 ent-entry arch-entry inst-entry)
13771 (while ent-alist
13772 (setq ent-entry (car ent-alist))
3dcb36b7 13773 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13774 (while arch-alist
13775 (setq arch-entry (car arch-alist))
3dcb36b7 13776 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13777 (while inst-alist
13778 (setq inst-entry (car inst-alist))
3dcb36b7 13779 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13780 (setq ent-inst-list
3dcb36b7
JB
13781 (cons (list (nth 1 inst-entry)
13782 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13783 (nth 1 ent-entry)
13784 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13785 (nth 1 arch-entry)
13786 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13787 ent-inst-list)))
5eabfe72
KH
13788 (setq inst-alist (cdr inst-alist)))
13789 (setq arch-alist (cdr arch-alist)))
13790 (setq ent-alist (cdr ent-alist)))
13791 (nreverse ent-inst-list)))
13792
13793;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13794;; Caching in file
13795
13796(defun vhdl-save-caches ()
13797 "Save all updated hierarchy caches to file."
13798 (interactive)
13799 (condition-case nil
13800 (when vhdl-speedbar-save-cache
13801 ;; update hierarchy
13802 (vhdl-update-hierarchy)
13803 (let ((project-list vhdl-updated-project-list))
13804 (message "Saving hierarchy caches...")
13805 ;; write updated project caches
13806 (while project-list
13807 (vhdl-save-cache (car project-list))
13808 (setq project-list (cdr project-list)))
13809 (message "Saving hierarchy caches...done")))
b65d82ca 13810 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
3dcb36b7
JB
13811 (sit-for 2)))))
13812
13813(defun vhdl-save-cache (key)
13814 "Save current hierarchy cache to file."
13815 (let* ((orig-buffer (current-buffer))
13816 (vhdl-project key)
13817 (project (vhdl-project-p))
13818 (default-directory key)
13819 (directory (abbreviate-file-name (vhdl-default-directory)))
13820 (file-name (vhdl-resolve-env-variable
13821 (vhdl-replace-string
13822 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13823 (concat
13824 (subst-char-in-string ? ?_ (or project "dir"))
13825 " " (user-login-name)))))
13826 (file-dir-name (expand-file-name file-name directory))
13827 (cache-key (or project directory))
13828 (key (if project "project" "directory")))
13829 (unless (file-exists-p (file-name-directory file-dir-name))
13830 (make-directory (file-name-directory file-dir-name) t))
13831 (if (not (file-writable-p file-dir-name))
13832 (progn (vhdl-warning (format "File not writable: \"%s\""
13833 (abbreviate-file-name file-dir-name)))
13834 (sit-for 2))
13835 (message "Saving cache: \"%s\"" file-dir-name)
13836 (set-buffer (find-file-noselect file-dir-name t t))
13837 (erase-buffer)
13838 (insert ";; -*- Emacs-Lisp -*-\n\n"
13839 ";;; " (file-name-nondirectory file-name)
13840 " - design hierarchy cache file for Emacs VHDL Mode "
13841 vhdl-version "\n")
13842 (insert "\n;; " (if project "Project " "Directory") " : ")
13843 (if project (insert project) (prin1 directory (current-buffer)))
13844 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13845 (user-login-name) "\n\n"
13846 "\n;; version number\n"
13847 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13848 "\n;; " (if project "project" "directory") " name"
13849 "\n(setq " key " ")
13850 (prin1 (or project directory) (current-buffer))
13851 (insert ")\n")
13852 (when (member 'hierarchy vhdl-speedbar-save-cache)
13853 (insert "\n;; entity and architecture cache\n"
13854 "(aput 'vhdl-entity-alist " key " '")
13855 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13856 (insert ")\n\n;; configuration cache\n"
13857 "(aput 'vhdl-config-alist " key " '")
13858 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13859 (insert ")\n\n;; package cache\n"
13860 "(aput 'vhdl-package-alist " key " '")
13861 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13862 (insert ")\n\n;; instantiated entities cache\n"
13863 "(aput 'vhdl-ent-inst-alist " key " '")
13864 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13865 (insert ")\n\n;; design units per file cache\n"
13866 "(aput 'vhdl-file-alist " key " '")
13867 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13868 (when project
13869 (insert ")\n\n;; source directories in project cache\n"
13870 "(aput 'vhdl-directory-alist " key " '")
13871 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13872 (insert ")\n"))
13873 (when (member 'display vhdl-speedbar-save-cache)
13874 (insert "\n;; shown design units cache\n"
13875 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13876 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13877 (current-buffer))
13878 (insert ")\n"))
13879 (setq vhdl-updated-project-list
13880 (delete cache-key vhdl-updated-project-list))
13881 (save-buffer)
13882 (kill-buffer (current-buffer))
13883 (set-buffer orig-buffer))))
13884
13885(defun vhdl-load-cache (key)
13886 "Load hierarchy cache information from file."
13887 (let* ((vhdl-project key)
13888 (default-directory key)
13889 (directory (vhdl-default-directory))
13890 (file-name (vhdl-resolve-env-variable
13891 (vhdl-replace-string
13892 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13893 (concat
13894 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13895 " " (user-login-name)))))
13896 (file-dir-name (expand-file-name file-name directory))
13897 vhdl-cache-version)
13898 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13899 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13900 (when (file-exists-p file-dir-name)
13901 (condition-case ()
13902 (progn (load-file file-dir-name)
13903 (string< (mapconcat
027a4b6b 13904 (lambda (a) (format "%3d" (string-to-number a)))
0a2e512a 13905 (split-string "3.33" "\\.") "")
3dcb36b7 13906 (mapconcat
027a4b6b 13907 (lambda (a) (format "%3d" (string-to-number a)))
3dcb36b7
JB
13908 (split-string vhdl-cache-version "\\.") "")))
13909 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13910 nil))))))
13911
13912(defun vhdl-require-hierarchy-info ()
13913 "Make sure that hierarchy information is available. Load cache or scan files
13914if required."
13915 (if (vhdl-project-p)
13916 (unless (or (assoc vhdl-project vhdl-file-alist)
13917 (vhdl-load-cache vhdl-project))
13918 (vhdl-scan-project-contents vhdl-project))
13919 (let ((directory (abbreviate-file-name default-directory)))
13920 (unless (or (assoc directory vhdl-file-alist)
13921 (vhdl-load-cache directory))
13922 (vhdl-scan-directory-contents directory)))))
13923
13924;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13925;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13926
13927(defvar vhdl-speedbar-key-map nil
13928 "Keymap used when in the VHDL hierarchy browser mode.")
13929
3dcb36b7 13930(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13931 "Additional menu-items to add to speedbar frame.")
13932
13933(defun vhdl-speedbar-initialize ()
13934 "Initialize speedbar."
13935 ;; general settings
13936; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13937 ;; VHDL file extensions (extracted from `auto-mode-alist')
13938 (let ((mode-alist auto-mode-alist))
13939 (while mode-alist
3dcb36b7
JB
13940 (when (eq (cdar mode-alist) 'vhdl-mode)
13941 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13942 (setq mode-alist (cdr mode-alist))))
13943 ;; hierarchy browser settings
13944 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13945 ;; special functions
5eabfe72 13946 (speedbar-add-mode-functions-list
3dcb36b7 13947 '("vhdl directory"
5eabfe72 13948 (speedbar-item-info . vhdl-speedbar-item-info)
7752250e 13949 (speedbar-line-directory . speedbar-files-line-path)))
3dcb36b7
JB
13950 (speedbar-add-mode-functions-list
13951 '("vhdl project"
13952 (speedbar-item-info . vhdl-speedbar-item-info)
7752250e 13953 (speedbar-line-directory . vhdl-speedbar-line-project)))
3dcb36b7 13954 ;; keymap
5eabfe72
KH
13955 (unless vhdl-speedbar-key-map
13956 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13957 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13958 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13959 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
13960 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13961 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13962 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13963 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13964 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
0a2e512a
RF
13965 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13966 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
3dcb36b7
JB
13967 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13968 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13969 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13970 (let ((key 0))
13971 (while (<= key 9)
13972 (define-key vhdl-speedbar-key-map (int-to-string key)
13973 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13974 (setq key (1+ key)))))
5eabfe72
KH
13975 (define-key speedbar-key-map "h"
13976 (lambda () (interactive)
3dcb36b7
JB
13977 (speedbar-change-initial-expansion-list "vhdl directory")))
13978 (define-key speedbar-key-map "H"
13979 (lambda () (interactive)
13980 (speedbar-change-initial-expansion-list "vhdl project")))
13981 ;; menu
13982 (unless vhdl-speedbar-menu-items
13983 (setq
13984 vhdl-speedbar-menu-items
13985 `(["Edit" speedbar-edit-line t]
13986 ["Expand" speedbar-expand-line
13987 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13988 ["Contract" vhdl-speedbar-contract-level t]
13989 ["Expand All" vhdl-speedbar-expand-all t]
13990 ["Contract All" vhdl-speedbar-contract-all t]
13991 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13992 (while (<= key 9)
13993 (setq menu-list
13994 (cons `[,(if (= key 0) "All" (int-to-string key))
13995 (vhdl-speedbar-set-depth ,key)
13996 :style radio
13997 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13998 :keys ,(int-to-string key)]
13999 menu-list))
14000 (setq key (1+ key)))
14001 (nreverse menu-list))
14002 "--"
14003 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14004 (or (vhdl-speedbar-check-unit 'entity)
14005 (vhdl-speedbar-check-unit 'subprogram))]
14006 ["Place Component" vhdl-speedbar-place-component
14007 (vhdl-speedbar-check-unit 'entity)]
0a2e512a
RF
14008 ["Generate Configuration" vhdl-speedbar-configuration
14009 (vhdl-speedbar-check-unit 'architecture)]
14010 ["Select as MRA" vhdl-speedbar-select-mra
14011 (vhdl-speedbar-check-unit 'architecture)]
3dcb36b7
JB
14012 ["Make" vhdl-speedbar-make-design
14013 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14014 ["Generate Makefile" vhdl-speedbar-generate-makefile
14015 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14016 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14017 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
f8246027 14018 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
3dcb36b7
JB
14019 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14020 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
f8246027 14021 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
3dcb36b7
JB
14022 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14023 ;; hook-ups
14024 (speedbar-add-expansion-list
14025 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14026 vhdl-speedbar-display-directory))
14027 (speedbar-add-expansion-list
14028 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14029 vhdl-speedbar-display-projects))
5eabfe72 14030 (setq speedbar-stealthy-function-list
3dcb36b7
JB
14031 (append
14032 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14033 ("vhdl project" vhdl-speedbar-update-current-project
14034 vhdl-speedbar-update-current-unit)
14035; ("files" (lambda () (setq speedbar-ignored-path-regexp
14036; (speedbar-extension-list-to-regex
14037; speedbar-ignored-path-expressions))))
14038 )
14039 speedbar-stealthy-function-list))
14040 (when (eq vhdl-speedbar-display-mode 'directory)
14041 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14042 (when (eq vhdl-speedbar-display-mode 'project)
14043 (setq speedbar-initial-expansion-list-name "vhdl project"))
14044 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
14045
14046(defun vhdl-speedbar (&optional arg)
14047 "Open/close speedbar."
d2ddb974 14048 (interactive)
5eabfe72 14049 (if (not (fboundp 'speedbar))
3dcb36b7
JB
14050 (error "WARNING: Speedbar is not available or not installed")
14051 (condition-case ()
5eabfe72 14052 (speedbar-frame-mode arg)
3dcb36b7 14053 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
14054
14055;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14056;; Display functions
14057
3dcb36b7
JB
14058(defvar vhdl-speedbar-last-selected-project nil
14059 "Name of last selected project.")
14060
5eabfe72
KH
14061;; macros must be defined in the file they are used (copied from `speedbar.el')
14062(defmacro speedbar-with-writable (&rest forms)
14063 "Allow the buffer to be writable and evaluate FORMS."
14064 (list 'let '((inhibit-read-only t))
14065 (cons 'progn forms)))
14066(put 'speedbar-with-writable 'lisp-indent-function 0)
14067
3dcb36b7 14068(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 14069 "Display directory and hierarchy information in speedbar."
3dcb36b7 14070 (setq vhdl-speedbar-show-projects nil)
f8262222
RS
14071 (setq speedbar-ignored-directory-regexp
14072 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
5eabfe72
KH
14073 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14074 (setq speedbar-last-selected-file nil)
14075 (speedbar-with-writable
3dcb36b7
JB
14076 (condition-case nil
14077 (progn
14078 ;; insert directory path
14079 (speedbar-directory-buttons directory depth)
14080 ;; insert subdirectories
14081 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14082 ;; scan and insert hierarchy of current directory
14083 (vhdl-speedbar-insert-dir-hierarchy directory depth
14084 speedbar-power-click)
14085 ;; expand subdirectories
14086 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14087 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14088
14089(defun vhdl-speedbar-display-projects (project depth &optional rescan)
14090 "Display projects and hierarchy information in speedbar."
14091 (setq vhdl-speedbar-show-projects t)
f8262222 14092 (setq speedbar-ignored-directory-regexp ".")
3dcb36b7
JB
14093 (setq speedbar-last-selected-file nil)
14094 (setq vhdl-speedbar-last-selected-project nil)
14095 (speedbar-with-writable
14096 (condition-case nil
14097 ;; insert projects
14098 (vhdl-speedbar-insert-projects)
14099 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14100 (setq speedbar-full-text-cache nil)) ; prevent caching
14101
14102(defun vhdl-speedbar-insert-projects ()
14103 "Insert all projects in speedbar."
14104 (vhdl-speedbar-make-title-line "Projects:")
14105 (let ((project-alist (if vhdl-project-sort
14106 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14107 vhdl-project-alist))
14108 (vhdl-speedbar-update-current-unit nil))
14109 ;; insert projects
14110 (while project-alist
14111 (speedbar-make-tag-line
14112 'angle ?+ 'vhdl-speedbar-expand-project
14113 (caar project-alist) (caar project-alist)
14114 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14115 (setq project-alist (cdr project-alist)))
14116 (setq project-alist vhdl-project-alist)
14117 ;; expand projects
14118 (while project-alist
14119 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14120 (goto-char (point-min))
14121 (when (re-search-forward
14122 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14123 (goto-char (match-end 1))
14124 (speedbar-do-function-pointer)))
14125 (setq project-alist (cdr project-alist))))
14126; (vhdl-speedbar-update-current-project)
14127; (vhdl-speedbar-update-current-unit nil t)
14128 )
14129
14130(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
a4c6cfad 14131 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
3dcb36b7
JB
14132otherwise use cached data."
14133 (when (or rescan (and (not (assoc project vhdl-file-alist))
14134 (not (vhdl-load-cache project))))
14135 (vhdl-scan-project-contents project))
14136 ;; insert design hierarchy
14137 (vhdl-speedbar-insert-hierarchy
14138 (aget vhdl-entity-alist project t)
14139 (aget vhdl-config-alist project t)
14140 (aget vhdl-package-alist project t)
14141 (car (aget vhdl-ent-inst-alist project t)) indent)
14142 (insert (int-to-string indent) ":\n")
14143 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14144 (put-text-property (1- (point)) (point) 'invisible nil)
14145 ;; expand design units
14146 (vhdl-speedbar-expand-units project))
14147
14148(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14149 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14150otherwise use cached data."
14151 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14152 (not (vhdl-load-cache directory))))
14153 (vhdl-scan-directory-contents directory))
14154 ;; insert design hierarchy
14155 (vhdl-speedbar-insert-hierarchy
14156 (aget vhdl-entity-alist directory t)
14157 (aget vhdl-config-alist directory t)
14158 (aget vhdl-package-alist directory t)
14159 (car (aget vhdl-ent-inst-alist directory t)) depth)
14160 ;; expand design units
14161 (vhdl-speedbar-expand-units directory)
14162 (aput 'vhdl-directory-alist directory (list (list directory))))
14163
14164(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 14165 ent-inst-list depth)
3dcb36b7
JB
14166 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14167 (if (not (or ent-alist conf-alist pack-alist))
14168 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14169 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
14170 ;; insert entities
14171 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14172 (while ent-alist
14173 (setq ent-entry (car ent-alist))
14174 (speedbar-make-tag-line
14175 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
14176 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14177 (cons (nth 2 ent-entry) (nth 3 ent-entry))
0a2e512a 14178 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
14179 (unless (nth 2 ent-entry)
14180 (end-of-line 0) (insert "!") (forward-char 1))
14181 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
14182 (end-of-line 0) (insert " (top)") (forward-char 1))
14183 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
14184 ;; insert configurations
14185 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14186 (while conf-alist
14187 (setq conf-entry (car conf-alist))
14188 (speedbar-make-tag-line
14189 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14190 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14191 (cons (nth 2 conf-entry) (nth 3 conf-entry))
0a2e512a 14192 'vhdl-speedbar-configuration-face depth)
3dcb36b7 14193 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
14194 ;; insert packages
14195 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14196 (while pack-alist
14197 (setq pack-entry (car pack-alist))
14198 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
14199 (nth 0 pack-entry) (nth 1 pack-entry)
14200 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14201 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
14202 depth)
14203 (setq pack-alist (cdr pack-alist))))))
14204
5eabfe72 14205(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 14206 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 14207 (interactive)
3dcb36b7
JB
14208 (let (key path)
14209 (cond
14210 ;; current project
14211 (vhdl-speedbar-show-projects
14212 (setq key (vhdl-speedbar-line-project))
14213 (vhdl-scan-project-contents key))
14214 ;; top-level directory
14215 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14216 (re-search-forward "[0-9]+:" nil t)
14217 (vhdl-scan-directory-contents
7752250e 14218 (abbreviate-file-name (speedbar-line-directory))))
3dcb36b7 14219 ;; current directory
7752250e 14220 (t (setq path (speedbar-line-directory))
3dcb36b7
JB
14221 (string-match "^\\(.+[/\\]\\)" path)
14222 (vhdl-scan-directory-contents
14223 (abbreviate-file-name (match-string 1 path)))))
14224 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14225
14226(defun vhdl-speedbar-expand-dirs (directory)
14227 "Expand subdirectories in DIRECTORY according to
14228 `speedbar-shown-directories'."
14229 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14230 (let ((sf (cdr (reverse speedbar-shown-directories)))
14231 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14232 (setq speedbar-shown-directories
14233 (list (expand-file-name default-directory)))
14234 (while sf
14235 (when (speedbar-goto-this-file (car sf))
14236 (beginning-of-line)
14237 (when (looking-at "[0-9]+:\\s-*<")
14238 (goto-char (match-end 0))
3dcb36b7
JB
14239 (speedbar-do-function-pointer)))
14240 (setq sf (cdr sf))))
14241 (vhdl-speedbar-update-current-unit nil t))
14242
14243(defun vhdl-speedbar-expand-units (key)
14244 "Expand design units in directory/project KEY according to
14245`vhdl-speedbar-shown-unit-alist'."
14246 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14247 (vhdl-speedbar-update-current-unit nil)
14248 vhdl-updated-project-list)
14249 (adelete 'vhdl-speedbar-shown-unit-alist key)
14250 (vhdl-prepare-search-1
14251 (while unit-alist ; expand units
14252 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14253 (beginning-of-line)
14254 (let ((arch-alist (nth 1 (car unit-alist)))
14255 position)
14256 (when (looking-at "^[0-9]+:\\s-*\\[")
14257 (goto-char (match-end 0))
14258 (setq position (point))
14259 (speedbar-do-function-pointer)
14260 (select-frame speedbar-frame)
14261 (while arch-alist ; expand architectures
14262 (goto-char position)
14263 (when (re-search-forward
14264 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14265 (car arch-alist) "\\>\\)") nil t)
14266 (beginning-of-line)
14267 (when (looking-at "^[0-9]+:\\s-*{")
14268 (goto-char (match-end 0))
14269 (speedbar-do-function-pointer)
14270 (select-frame speedbar-frame)))
14271 (setq arch-alist (cdr arch-alist))))
14272 (setq unit-alist (cdr unit-alist))))))
14273 (vhdl-speedbar-update-current-unit nil t))
14274
14275(defun vhdl-speedbar-contract-level ()
14276 "Contract current level in current directory/project."
14277 (interactive)
14278 (when (or (save-excursion
14279 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14280 (and (save-excursion
14281 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14282 (re-search-backward
14283 (format "^[0-%d]:\\s-*[[{<]-"
027a4b6b 14284 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
3dcb36b7
JB
14285 (goto-char (match-end 0))
14286 (speedbar-do-function-pointer)
14287 (speedbar-center-buffer-smartly)))
14288
14289(defun vhdl-speedbar-contract-all ()
14290 "Contract all expanded design units in current directory/project."
14291 (interactive)
14292 (if (and vhdl-speedbar-show-projects
14293 (save-excursion (beginning-of-line) (looking-at "^0:")))
14294 (progn (setq vhdl-speedbar-shown-project-list nil)
14295 (vhdl-speedbar-refresh))
14296 (let ((key (vhdl-speedbar-line-key)))
14297 (adelete 'vhdl-speedbar-shown-unit-alist key)
14298 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14299 (when (memq 'display vhdl-speedbar-save-cache)
14300 (add-to-list 'vhdl-updated-project-list key)))))
14301
14302(defun vhdl-speedbar-expand-all ()
14303 "Expand all design units in current directory/project."
14304 (interactive)
14305 (let* ((key (vhdl-speedbar-line-key))
14306 (ent-alist (aget vhdl-entity-alist key t))
14307 (conf-alist (aget vhdl-config-alist key t))
14308 (pack-alist (aget vhdl-package-alist key t))
14309 arch-alist unit-alist subunit-alist)
14310 (add-to-list 'vhdl-speedbar-shown-project-list key)
14311 (while ent-alist
14312 (setq arch-alist (nth 4 (car ent-alist)))
14313 (setq subunit-alist nil)
14314 (while arch-alist
14315 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14316 (setq arch-alist (cdr arch-alist)))
14317 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14318 (setq ent-alist (cdr ent-alist)))
14319 (while conf-alist
14320 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14321 (setq conf-alist (cdr conf-alist)))
14322 (while pack-alist
14323 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14324 (setq pack-alist (cdr pack-alist)))
14325 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14326 (vhdl-speedbar-refresh)
14327 (when (memq 'display vhdl-speedbar-save-cache)
14328 (add-to-list 'vhdl-updated-project-list key))))
14329
14330(defun vhdl-speedbar-expand-project (text token indent)
14331 "Expand/contract the project under the cursor."
14332 (cond
14333 ((string-match "+" text) ; expand project
14334 (speedbar-change-expand-button-char ?-)
14335 (unless (member token vhdl-speedbar-shown-project-list)
14336 (setq vhdl-speedbar-shown-project-list
14337 (cons token vhdl-speedbar-shown-project-list)))
14338 (speedbar-with-writable
14339 (save-excursion
14340 (end-of-line) (forward-char 1)
14341 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14342 speedbar-power-click))))
14343 ((string-match "-" text) ; contract project
14344 (speedbar-change-expand-button-char ?+)
14345 (setq vhdl-speedbar-shown-project-list
14346 (delete token vhdl-speedbar-shown-project-list))
14347 (speedbar-delete-subblock indent))
14348 (t (error "Nothing to display")))
14349 (when (equal (selected-frame) speedbar-frame)
14350 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14351
14352(defun vhdl-speedbar-expand-entity (text token indent)
14353 "Expand/contract the entity under the cursor."
14354 (cond
14355 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14356 (let* ((key (vhdl-speedbar-line-key indent))
14357 (ent-alist (aget vhdl-entity-alist key t))
14358 (ent-entry (aget ent-alist token t))
14359 (arch-alist (nth 3 ent-entry))
5eabfe72 14360 (inst-alist (vhdl-get-instantiations token indent))
0a2e512a
RF
14361 (subpack-alist (nth 5 ent-entry))
14362 (multiple-arch (> (length arch-alist) 1))
3dcb36b7
JB
14363 arch-entry inst-entry)
14364 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14365 (speedbar-change-expand-button-char ??)
14366 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14367 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14368 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14369 (aput 'unit-alist token nil)
14370 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14371 (speedbar-with-writable
3dcb36b7
JB
14372 (save-excursion
14373 (end-of-line) (forward-char 1)
14374 ;; insert architectures
14375 (when arch-alist
14376 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14377 (while arch-alist
14378 (setq arch-entry (car arch-alist))
14379 (speedbar-make-tag-line
14380 'curly ?+ 'vhdl-speedbar-expand-architecture
14381 (cons token (nth 0 arch-entry))
14382 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14383 (cons (nth 2 arch-entry) (nth 3 arch-entry))
0a2e512a
RF
14384 'vhdl-speedbar-architecture-face (1+ indent))
14385 (when (and multiple-arch
14386 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14387 (end-of-line 0) (insert " (mra)") (forward-char 1))
3dcb36b7
JB
14388 (setq arch-alist (cdr arch-alist)))
14389 ;; insert instantiations
14390 (when inst-alist
14391 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14392 (while inst-alist
14393 (setq inst-entry (car inst-alist))
14394 (vhdl-speedbar-make-inst-line
14395 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14396 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14397 nil nil nil (1+ indent) 0 " in ")
14398 (setq inst-alist (cdr inst-alist)))
14399 ;; insert required packages
14400 (vhdl-speedbar-insert-subpackages
14401 subpack-alist (1+ indent) indent)))
14402 (when (memq 'display vhdl-speedbar-save-cache)
14403 (add-to-list 'vhdl-updated-project-list key))
14404 (vhdl-speedbar-update-current-unit t t))))
5eabfe72
KH
14405 ((string-match "-" text) ; contract entity
14406 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14407 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14408 (let* ((key (vhdl-speedbar-line-key indent))
14409 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14410 (adelete 'unit-alist token)
14411 (if unit-alist
14412 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14413 (adelete 'vhdl-speedbar-shown-unit-alist key))
14414 (speedbar-delete-subblock indent)
14415 (when (memq 'display vhdl-speedbar-save-cache)
14416 (add-to-list 'vhdl-updated-project-list key))))
14417 (t (error "Nothing to display")))
14418 (when (equal (selected-frame) speedbar-frame)
14419 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14420
14421(defun vhdl-speedbar-expand-architecture (text token indent)
14422 "Expand/contract the architecture under the cursor."
14423 (cond
14424 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14425 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14426 (ent-alist (aget vhdl-entity-alist key t))
14427 (conf-alist (aget vhdl-config-alist key t))
14428 (hier-alist (vhdl-get-hierarchy
14429 ent-alist conf-alist (car token) (cdr token) nil nil
14430 0 (1- indent)))
14431 (ent-entry (aget ent-alist (car token) t))
14432 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14433 (subpack-alist (nth 4 arch-entry))
14434 entry)
14435 (if (not (or hier-alist subpack-alist))
14436 (speedbar-change-expand-button-char ??)
14437 (speedbar-change-expand-button-char ?-)
14438 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14439 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14440 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14441 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14442 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14443 (speedbar-with-writable
14444 (save-excursion
14445 (end-of-line) (forward-char 1)
14446 ;; insert instance hierarchy
14447 (when hier-alist
14448 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14449 (1+ indent)))
14450 (while hier-alist
14451 (setq entry (car hier-alist))
14452 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14453 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14454 (vhdl-speedbar-make-inst-line
14455 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14456 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14457 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14458 (setq hier-alist (cdr hier-alist)))
14459 ;; insert required packages
14460 (vhdl-speedbar-insert-subpackages
14461 subpack-alist (1+ indent) (1- indent))))
14462 (when (memq 'display vhdl-speedbar-save-cache)
14463 (add-to-list 'vhdl-updated-project-list key))
14464 (vhdl-speedbar-update-current-unit t t))))
14465 ((string-match "-" text) ; contract architecture
14466 (speedbar-change-expand-button-char ?+)
14467 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14468 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14469 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14470 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14471 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14472 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14473 (speedbar-delete-subblock indent)
14474 (when (memq 'display vhdl-speedbar-save-cache)
14475 (add-to-list 'vhdl-updated-project-list key))))
14476 (t (error "Nothing to display")))
14477 (when (equal (selected-frame) speedbar-frame)
14478 (speedbar-center-buffer-smartly)))
14479
14480(defun vhdl-speedbar-expand-config (text token indent)
14481 "Expand/contract the configuration under the cursor."
14482 (cond
14483 ((string-match "+" text) ; expand configuration
14484 (let* ((key (vhdl-speedbar-line-key indent))
14485 (conf-alist (aget vhdl-config-alist key t))
14486 (conf-entry (aget conf-alist token))
14487 (ent-alist (aget vhdl-entity-alist key t))
14488 (hier-alist (vhdl-get-hierarchy
14489 ent-alist conf-alist (nth 3 conf-entry)
14490 (nth 4 conf-entry) token (nth 5 conf-entry)
14491 0 indent t))
14492 (subpack-alist (nth 6 conf-entry))
14493 entry)
14494 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14495 (speedbar-change-expand-button-char ??)
14496 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14497 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14498 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14499 (aput 'unit-alist token nil)
14500 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14501 (speedbar-with-writable
14502 (save-excursion
14503 (end-of-line) (forward-char 1)
14504 ;; insert instance hierarchy
14505 (when hier-alist
3dcb36b7 14506 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14507 (while hier-alist
3dcb36b7
JB
14508 (setq entry (car hier-alist))
14509 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14510 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14511 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14512 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14513 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14514 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14515 (setq hier-alist (cdr hier-alist)))
14516 ;; insert required packages
14517 (vhdl-speedbar-insert-subpackages
14518 subpack-alist (1+ indent) indent)))
14519 (when (memq 'display vhdl-speedbar-save-cache)
14520 (add-to-list 'vhdl-updated-project-list key))
14521 (vhdl-speedbar-update-current-unit t t))))
14522 ((string-match "-" text) ; contract configuration
5eabfe72 14523 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14524 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14525 (let* ((key (vhdl-speedbar-line-key indent))
14526 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14527 (adelete 'unit-alist token)
14528 (if unit-alist
14529 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14530 (adelete 'vhdl-speedbar-shown-unit-alist key))
14531 (speedbar-delete-subblock indent)
14532 (when (memq 'display vhdl-speedbar-save-cache)
14533 (add-to-list 'vhdl-updated-project-list key))))
14534 (t (error "Nothing to display")))
14535 (when (equal (selected-frame) speedbar-frame)
14536 (speedbar-center-buffer-smartly)))
14537
14538(defun vhdl-speedbar-expand-package (text token indent)
14539 "Expand/contract the package under the cursor."
14540 (cond
14541 ((string-match "+" text) ; expand package
14542 (let* ((key (vhdl-speedbar-line-key indent))
14543 (pack-alist (aget vhdl-package-alist key t))
14544 (pack-entry (aget pack-alist token t))
14545 (comp-alist (nth 3 pack-entry))
14546 (func-alist (nth 4 pack-entry))
14547 (func-body-alist (nth 8 pack-entry))
14548 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14549 comp-entry func-entry func-body-entry)
14550 (if (not (or comp-alist func-alist subpack-alist))
14551 (speedbar-change-expand-button-char ??)
14552 (speedbar-change-expand-button-char ?-)
14553 ;; add package to `vhdl-speedbar-shown-unit-alist'
14554 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14555 (aput 'unit-alist token nil)
14556 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14557 (speedbar-with-writable
14558 (save-excursion
14559 (end-of-line) (forward-char 1)
14560 ;; insert components
14561 (when comp-alist
14562 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14563 (while comp-alist
14564 (setq comp-entry (car comp-alist))
14565 (speedbar-make-tag-line
14566 nil nil nil
14567 (cons token (nth 0 comp-entry))
14568 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14569 (cons (nth 2 comp-entry) (nth 3 comp-entry))
0a2e512a 14570 'vhdl-speedbar-entity-face (1+ indent))
3dcb36b7
JB
14571 (setq comp-alist (cdr comp-alist)))
14572 ;; insert subprograms
14573 (when func-alist
14574 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14575 (while func-alist
14576 (setq func-entry (car func-alist)
14577 func-body-entry (aget func-body-alist (car func-entry) t))
14578 (when (nth 2 func-entry)
14579 (vhdl-speedbar-make-subprogram-line
14580 (nth 1 func-entry)
14581 (cons (nth 2 func-entry) (nth 3 func-entry))
14582 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14583 (1+ indent)))
14584 (setq func-alist (cdr func-alist)))
14585 ;; insert required packages
14586 (vhdl-speedbar-insert-subpackages
14587 subpack-alist (1+ indent) indent)))
14588 (when (memq 'display vhdl-speedbar-save-cache)
14589 (add-to-list 'vhdl-updated-project-list key))
14590 (vhdl-speedbar-update-current-unit t t))))
14591 ((string-match "-" text) ; contract package
14592 (speedbar-change-expand-button-char ?+)
14593 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14594 (let* ((key (vhdl-speedbar-line-key indent))
14595 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14596 (adelete 'unit-alist token)
14597 (if unit-alist
14598 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14599 (adelete 'vhdl-speedbar-shown-unit-alist key))
14600 (speedbar-delete-subblock indent)
14601 (when (memq 'display vhdl-speedbar-save-cache)
14602 (add-to-list 'vhdl-updated-project-list key))))
14603 (t (error "Nothing to display")))
14604 (when (equal (selected-frame) speedbar-frame)
14605 (speedbar-center-buffer-smartly)))
14606
14607(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14608 "Insert required packages."
14609 (let* ((pack-alist (aget vhdl-package-alist
14610 (vhdl-speedbar-line-key dir-indent) t))
14611 pack-key lib-name pack-entry)
14612 (when subpack-alist
14613 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14614 (while subpack-alist
14615 (setq pack-key (cdar subpack-alist)
14616 lib-name (caar subpack-alist))
14617 (setq pack-entry (aget pack-alist pack-key t))
14618 (vhdl-speedbar-make-subpack-line
14619 (or (nth 0 pack-entry) pack-key) lib-name
0a2e512a
RF
14620 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14621 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
3dcb36b7 14622 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14623
14624;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14625;; Display help functions
14626
3dcb36b7
JB
14627(defvar vhdl-speedbar-update-current-unit t
14628 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14629
14630(defun vhdl-speedbar-update-current-project ()
14631 "Highlight project that is currently active."
14632 (when (and vhdl-speedbar-show-projects
14633 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14634 (and (boundp 'speedbar-frame)
14635 (frame-live-p speedbar-frame)))
14636 (let ((last-frame (selected-frame))
14637 (project-alist vhdl-project-alist)
14638 pos)
14639 (select-frame speedbar-frame)
14640 (speedbar-with-writable
14641 (save-excursion
14642 (while project-alist
14643 (goto-char (point-min))
14644 (when (re-search-forward
14645 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14646 (put-text-property (match-beginning 1) (match-end 1) 'face
14647 (if (equal (caar project-alist) vhdl-project)
14648 'speedbar-selected-face
14649 'speedbar-directory-face))
14650 (when (equal (caar project-alist) vhdl-project)
14651 (setq pos (1- (match-beginning 1)))))
14652 (setq project-alist (cdr project-alist))))
14653 (when pos (goto-char pos)))
14654 (select-frame last-frame)
14655 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14656 t)
14657
14658(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14659 "Highlight all design units that are contained in the current file.
14660NO-POSITION non-nil means do not re-position cursor."
14661 (let ((last-frame (selected-frame))
3dcb36b7
JB
14662 (project-list vhdl-speedbar-shown-project-list)
14663 file-alist pos file-name)
5eabfe72 14664 ;; get current file name
3dcb36b7
JB
14665 (if (fboundp 'speedbar-select-attached-frame)
14666 (speedbar-select-attached-frame)
14667 (select-frame speedbar-attached-frame))
5eabfe72 14668 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14669 (when (and vhdl-speedbar-update-current-unit
14670 (or always (not (equal file-name speedbar-last-selected-file))))
14671 (if vhdl-speedbar-show-projects
14672 (while project-list
14673 (setq file-alist (append file-alist (aget vhdl-file-alist
14674 (car project-list) t)))
14675 (setq project-list (cdr project-list)))
14676 (setq file-alist (aget vhdl-file-alist
14677 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14678 (select-frame speedbar-frame)
14679 (set-buffer speedbar-buffer)
14680 (speedbar-with-writable
3dcb36b7 14681 (vhdl-prepare-search-1
5eabfe72
KH
14682 (save-excursion
14683 ;; unhighlight last units
3dcb36b7 14684 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14685 (vhdl-speedbar-update-units
3dcb36b7 14686 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14687 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
5eabfe72 14688 (vhdl-speedbar-update-units
3dcb36b7 14689 "{.} " (nth 1 file-entry)
0a2e512a 14690 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
5eabfe72 14691 (vhdl-speedbar-update-units
3dcb36b7 14692 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14693 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
5eabfe72 14694 (vhdl-speedbar-update-units
3dcb36b7 14695 "[]>] " (nth 4 file-entry)
0a2e512a 14696 speedbar-last-selected-file 'vhdl-speedbar-package-face)
5eabfe72 14697 (vhdl-speedbar-update-units
3dcb36b7 14698 "\\[.\\].+(" '("body")
0a2e512a 14699 speedbar-last-selected-file 'vhdl-speedbar-package-face)
3dcb36b7
JB
14700 (vhdl-speedbar-update-units
14701 "> " (nth 6 file-entry)
0a2e512a 14702 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
5eabfe72 14703 ;; highlight current units
3dcb36b7
JB
14704 (let* ((file-entry (aget file-alist file-name t)))
14705 (setq
14706 pos (vhdl-speedbar-update-units
14707 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14708 file-name 'vhdl-speedbar-entity-selected-face pos)
3dcb36b7
JB
14709 pos (vhdl-speedbar-update-units
14710 "{.} " (nth 1 file-entry)
0a2e512a 14711 file-name 'vhdl-speedbar-architecture-selected-face pos)
3dcb36b7
JB
14712 pos (vhdl-speedbar-update-units
14713 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14714 file-name 'vhdl-speedbar-configuration-selected-face pos)
3dcb36b7
JB
14715 pos (vhdl-speedbar-update-units
14716 "[]>] " (nth 4 file-entry)
0a2e512a 14717 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14718 pos (vhdl-speedbar-update-units
14719 "\\[.\\].+(" '("body")
0a2e512a 14720 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14721 pos (vhdl-speedbar-update-units
14722 "> " (nth 6 file-entry)
0a2e512a 14723 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14724 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14725 (when (and pos (not no-position))
14726 (goto-char pos)
14727 (speedbar-center-buffer-smartly)
5eabfe72
KH
14728 (speedbar-position-cursor-on-line))
14729 (setq speedbar-last-selected-file file-name))
14730 (select-frame last-frame)
14731 t))
14732
3dcb36b7
JB
14733(defun vhdl-speedbar-update-units (text unit-list file-name face
14734 &optional pos)
5eabfe72 14735 "Help function to highlight design units."
3dcb36b7
JB
14736 (while unit-list
14737 (goto-char (point-min))
14738 (while (re-search-forward
14739 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14740 (when (equal file-name (car (get-text-property
14741 (match-beginning 1) 'speedbar-token)))
14742 (setq pos (or pos (point-marker)))
14743 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14744 (setq unit-list (cdr unit-list)))
14745 pos)
5eabfe72
KH
14746
14747(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14748 ent-name ent-file-marker
14749 arch-name arch-file-marker
14750 conf-name conf-file-marker
14751 lib-name depth offset delimiter)
5eabfe72 14752 "Insert instantiation entry."
3dcb36b7
JB
14753 (let ((start (point))
14754 visible-start)
5eabfe72
KH
14755 (insert (int-to-string depth) ":")
14756 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14757 (setq visible-start (point))
14758 (insert-char ? (* depth speedbar-indentation-width))
14759 (while (> offset 0)
14760 (insert "|")
14761 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14762 (setq offset (1- offset)))
14763 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14764 (setq start (point))
3dcb36b7
JB
14765 (insert ">")
14766 (speedbar-make-button start (point) nil nil nil)
14767 (setq visible-start (point))
14768 (insert " ")
5eabfe72 14769 (setq start (point))
3dcb36b7
JB
14770 (if (not inst-name)
14771 (insert "(top)")
14772 (insert inst-name)
14773 (speedbar-make-button
0a2e512a 14774 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
3dcb36b7
JB
14775 'vhdl-speedbar-find-file inst-file-marker))
14776 (insert delimiter)
14777 (when ent-name
5eabfe72 14778 (setq start (point))
3dcb36b7 14779 (insert ent-name)
5eabfe72 14780 (speedbar-make-button
0a2e512a 14781 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
3dcb36b7
JB
14782 'vhdl-speedbar-find-file ent-file-marker)
14783 (when arch-name
14784 (insert " (")
14785 (setq start (point))
14786 (insert arch-name)
14787 (speedbar-make-button
0a2e512a 14788 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
3dcb36b7
JB
14789 'vhdl-speedbar-find-file arch-file-marker)
14790 (insert ")"))
14791 (when conf-name
14792 (insert " (")
14793 (setq start (point))
14794 (insert conf-name)
14795 (speedbar-make-button
0a2e512a 14796 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
3dcb36b7
JB
14797 'vhdl-speedbar-find-file conf-file-marker)
14798 (insert ")")))
14799 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14800 (setq start (point))
3dcb36b7
JB
14801 (insert " (" lib-name ")")
14802 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14803 'vhdl-speedbar-library-face))
5eabfe72 14804 (insert-char ?\n 1)
3dcb36b7 14805 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14806
3dcb36b7
JB
14807(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14808 body-file-marker depth)
5eabfe72 14809 "Insert package entry."
3dcb36b7
JB
14810 (let ((start (point))
14811 visible-start)
5eabfe72
KH
14812 (insert (int-to-string depth) ":")
14813 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14814 (setq visible-start (point))
14815 (insert-char ? (* depth speedbar-indentation-width))
14816 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14817 (setq start (point))
3dcb36b7
JB
14818 (insert "[+]")
14819 (speedbar-make-button
14820 start (point) 'speedbar-button-face 'speedbar-highlight-face
14821 'vhdl-speedbar-expand-package pack-key)
14822 (setq visible-start (point))
14823 (insert-char ? 1 nil)
5eabfe72
KH
14824 (setq start (point))
14825 (insert pack-name)
14826 (speedbar-make-button
0a2e512a 14827 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14828 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14829 (unless (car pack-file-marker)
14830 (insert "!"))
5eabfe72 14831 (when (car body-file-marker)
5eabfe72 14832 (insert " (")
5eabfe72
KH
14833 (setq start (point))
14834 (insert "body")
14835 (speedbar-make-button
0a2e512a 14836 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14837 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14838 (insert ")"))
5eabfe72 14839 (insert-char ?\n 1)
3dcb36b7 14840 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14841
3dcb36b7 14842(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
0a2e512a 14843 pack-body-file-marker depth)
3dcb36b7
JB
14844 "Insert used package entry."
14845 (let ((start (point))
14846 visible-start)
14847 (insert (int-to-string depth) ":")
14848 (put-text-property start (point) 'invisible t)
14849 (setq visible-start (point))
14850 (insert-char ? (* depth speedbar-indentation-width))
14851 (put-text-property visible-start (point) 'invisible nil)
14852 (setq start (point))
14853 (insert ">")
14854 (speedbar-make-button start (point) nil nil nil)
14855 (setq visible-start (point))
14856 (insert " ")
14857 (setq start (point))
14858 (insert pack-name)
14859 (speedbar-make-button
0a2e512a 14860 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
3dcb36b7 14861 'vhdl-speedbar-find-file pack-file-marker)
0a2e512a
RF
14862 (when (car pack-body-file-marker)
14863 (insert " (")
14864 (setq start (point))
14865 (insert "body")
14866 (speedbar-make-button
14867 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14868 'vhdl-speedbar-find-file pack-body-file-marker)
14869 (insert ")"))
3dcb36b7
JB
14870 (setq start (point))
14871 (insert " (" lib-name ")")
14872 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14873 'vhdl-speedbar-library-face)
3dcb36b7
JB
14874 (insert-char ?\n 1)
14875 (put-text-property visible-start (point) 'invisible nil)))
14876
14877(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14878 func-body-file-marker
14879 depth)
14880 "Insert subprogram entry."
14881 (let ((start (point))
14882 visible-start)
5eabfe72
KH
14883 (insert (int-to-string depth) ":")
14884 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14885 (setq visible-start (point))
14886 (insert-char ? (* depth speedbar-indentation-width))
14887 (put-text-property visible-start (point) 'invisible nil)
14888 (setq start (point))
14889 (insert ">")
14890 (speedbar-make-button start (point) nil nil nil)
14891 (setq visible-start (point))
14892 (insert " ")
5eabfe72 14893 (setq start (point))
3dcb36b7
JB
14894 (insert func-name)
14895 (speedbar-make-button
0a2e512a 14896 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14897 'vhdl-speedbar-find-file func-file-marker)
14898 (when (car func-body-file-marker)
14899 (insert " (")
14900 (setq start (point))
14901 (insert "body")
14902 (speedbar-make-button
0a2e512a 14903 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14904 'vhdl-speedbar-find-file func-body-file-marker)
14905 (insert ")"))
14906 (insert-char ?\n 1)
14907 (put-text-property visible-start (point) 'invisible nil)))
14908
14909(defun vhdl-speedbar-make-title-line (text &optional depth)
14910 "Insert design unit title entry."
14911 (let ((start (point))
14912 visible-start)
14913 (when depth
14914 (insert (int-to-string depth) ":")
14915 (put-text-property start (point) 'invisible t))
14916 (setq visible-start (point))
14917 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14918 (setq start (point))
14919 (insert text)
14920 (speedbar-make-button start (point) nil nil nil nil)
14921 (insert-char ?\n 1)
3dcb36b7 14922 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14923
14924(defun vhdl-speedbar-insert-dirs (files level)
14925 "Insert subdirectories."
14926 (let ((dirs (car files)))
14927 (while dirs
14928 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14929 (car dirs) 'speedbar-dir-follow nil
14930 'speedbar-directory-face level)
14931 (setq dirs (cdr dirs)))))
14932
14933(defun vhdl-speedbar-dired (text token indent)
14934 "Speedbar click handler for directory expand button in hierarchy mode."
14935 (cond ((string-match "+" text) ; we have to expand this dir
14936 (setq speedbar-shown-directories
14937 (cons (expand-file-name
7752250e 14938 (concat (speedbar-line-directory indent) token "/"))
5eabfe72
KH
14939 speedbar-shown-directories))
14940 (speedbar-change-expand-button-char ?-)
14941 (speedbar-reset-scanners)
14942 (speedbar-with-writable
14943 (save-excursion
14944 (end-of-line) (forward-char 1)
14945 (vhdl-speedbar-insert-dirs
14946 (speedbar-file-lists
7752250e 14947 (concat (speedbar-line-directory indent) token "/"))
5eabfe72
KH
14948 (1+ indent))
14949 (speedbar-reset-scanners)
14950 (vhdl-speedbar-insert-dir-hierarchy
14951 (abbreviate-file-name
7752250e 14952 (concat (speedbar-line-directory indent) token "/"))
5eabfe72 14953 (1+ indent) speedbar-power-click)))
3dcb36b7 14954 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
14955 ((string-match "-" text) ; we have to contract this node
14956 (speedbar-reset-scanners)
14957 (let ((oldl speedbar-shown-directories)
14958 (newl nil)
14959 (td (expand-file-name
7752250e 14960 (concat (speedbar-line-directory indent) token))))
5eabfe72
KH
14961 (while oldl
14962 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14963 (setq newl (cons (car oldl) newl)))
14964 (setq oldl (cdr oldl)))
14965 (setq speedbar-shown-directories (nreverse newl)))
14966 (speedbar-change-expand-button-char ?+)
14967 (speedbar-delete-subblock indent))
3dcb36b7
JB
14968 (t (error "Nothing to display")))
14969 (when (equal (selected-frame) speedbar-frame)
14970 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14971
14972(defun vhdl-speedbar-item-info ()
14973 "Derive and display information about this line item."
14974 (save-excursion
14975 (beginning-of-line)
14976 ;; skip invisible number info
3dcb36b7 14977 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 14978 (cond
3dcb36b7
JB
14979 ;; project/directory entry
14980 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14981 (if vhdl-speedbar-show-projects
14982 (message "Project \"%s\"" (match-string-no-properties 1))
14983 (speedbar-files-item-info)))
5eabfe72 14984 ;; design unit entry
3dcb36b7
JB
14985 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14986 (goto-char (match-end 1))
5eabfe72
KH
14987 (let ((face (get-text-property (point) 'face)))
14988 (message
14989 "%s \"%s\" in \"%s\""
14990 ;; design unit kind
0a2e512a
RF
14991 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14992 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 14993 (if (equal (match-string 2) ">") "Component" "Entity"))
0a2e512a
RF
14994 ((or (eq face 'vhdl-speedbar-architecture-face)
14995 (eq face 'vhdl-speedbar-architecture-selected-face))
5eabfe72 14996 "Architecture")
0a2e512a
RF
14997 ((or (eq face 'vhdl-speedbar-configuration-face)
14998 (eq face 'vhdl-speedbar-configuration-selected-face))
5eabfe72 14999 "Configuration")
0a2e512a
RF
15000 ((or (eq face 'vhdl-speedbar-package-face)
15001 (eq face 'vhdl-speedbar-package-selected-face))
5eabfe72 15002 "Package")
0a2e512a
RF
15003 ((or (eq face 'vhdl-speedbar-instantiation-face)
15004 (eq face 'vhdl-speedbar-instantiation-selected-face))
5eabfe72 15005 "Instantiation")
0a2e512a 15006 ((eq face 'vhdl-speedbar-subprogram-face)
3dcb36b7 15007 "Subprogram")
5eabfe72
KH
15008 (t ""))
15009 ;; design unit name
15010 (buffer-substring-no-properties
3dcb36b7
JB
15011 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15012 (match-end 1))
5eabfe72 15013 ;; file name
3dcb36b7
JB
15014 (file-relative-name
15015 (or (car (get-text-property (point) 'speedbar-token))
15016 "?")
15017 (vhdl-default-directory)))))
15018 (t (message "")))))
15019
15020(defun vhdl-speedbar-line-text ()
15021 "Calls `speedbar-line-text' and removes text properties."
15022 (let ((string (speedbar-line-text)))
15023 (set-text-properties 0 (length string) nil string)
15024 string))
5eabfe72 15025
0a2e512a
RF
15026(defun vhdl-speedbar-higher-text ()
15027 "Get speedbar-line-text of higher level."
15028 (let (depth string)
15029 (save-excursion
15030 (beginning-of-line)
15031 (looking-at "^\\([0-9]+\\):")
15032 (setq depth (string-to-number (match-string 1)))
15033 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15034 (setq string (match-string 1))
15035 (set-text-properties 0 (length string) nil string)
15036 string))))
15037
5eabfe72
KH
15038;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15039;; Help functions
d2ddb974 15040
3dcb36b7
JB
15041(defun vhdl-speedbar-line-key (&optional indent)
15042 "Get currently displayed directory of project name."
15043 (if vhdl-speedbar-show-projects
15044 (vhdl-speedbar-line-project)
15045 (abbreviate-file-name
7752250e 15046 (file-name-as-directory (speedbar-line-directory indent)))))
3dcb36b7
JB
15047
15048(defun vhdl-speedbar-line-project (&optional indent)
15049 "Get currently displayed project name."
15050 (and vhdl-speedbar-show-projects
15051 (save-excursion
15052 (end-of-line)
15053 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15054 (match-string-no-properties 1))))
15055
15056(defun vhdl-add-modified-file ()
15057 "Add file to `vhdl-modified-file-list'."
15058 (when vhdl-file-alist
15059 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15060 nil)
5eabfe72
KH
15061
15062(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
15063 "Resolve path wildcards in PATH-LIST."
15064 (let (path-list-1 path-list-2 path-beg path-end dir)
15065 ;; eliminate non-existent directories
5eabfe72
KH
15066 (while path-list
15067 (setq dir (car path-list))
3dcb36b7
JB
15068 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15069 (if (file-directory-p (match-string 2 dir))
15070 (setq path-list-1 (cons dir path-list-1))
15071 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 15072 (setq path-list (cdr path-list)))
3dcb36b7 15073 ;; resolve path wildcards
5eabfe72
KH
15074 (while path-list-1
15075 (setq dir (car path-list-1))
3dcb36b7 15076 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
15077 (progn
15078 (setq path-beg (match-string 1 dir)
15079 path-end (match-string 5 dir))
3dcb36b7 15080 (setq path-list-1
5eabfe72
KH
15081 (append
15082 (mapcar
15083 (function
15084 (lambda (var) (concat path-beg var path-end)))
15085 (let ((all-list (vhdl-directory-files
15086 (match-string 2 dir) t
15087 (concat "\\<" (wildcard-to-regexp
15088 (match-string 4 dir)))))
15089 dir-list)
15090 (while all-list
15091 (when (file-directory-p (car all-list))
15092 (setq dir-list (cons (car all-list) dir-list)))
15093 (setq all-list (cdr all-list)))
15094 dir-list))
3dcb36b7
JB
15095 (cdr path-list-1))))
15096 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 15097 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
15098 (setq path-list-2 (cons dir path-list-2)))
15099 (setq path-list-1 (cdr path-list-1))))
15100 (nreverse path-list-2)))
5eabfe72
KH
15101
15102(defun vhdl-speedbar-goto-this-unit (directory unit)
15103 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15104 (let ((dest (point)))
3dcb36b7 15105 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
15106 (progn (goto-char (point-min)) t)
15107 (speedbar-goto-this-file directory))
15108 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15109 (progn (speedbar-position-cursor-on-line)
15110 t)
15111 (goto-char dest)
15112 nil)))
15113
15114(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
15115 "When user clicks on TEXT, load file with name and position in TOKEN.
15116Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15117is already shown in a buffer."
5eabfe72 15118 (if (not (car token))
3dcb36b7
JB
15119 (error "ERROR: File cannot be found")
15120 (let ((buffer (get-file-buffer (car token))))
15121 (speedbar-find-file-in-frame (car token))
15122 (when (or vhdl-speedbar-jump-to-unit buffer)
e6ce8c42
GM
15123 (goto-char (point-min))
15124 (forward-line (1- (cdr token)))
3dcb36b7
JB
15125 (recenter))
15126 (vhdl-speedbar-update-current-unit t t)
051897ff 15127 (speedbar-set-timer dframe-update-speed)
3dcb36b7 15128 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
15129
15130(defun vhdl-speedbar-port-copy ()
3dcb36b7 15131 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 15132 (interactive)
3dcb36b7
JB
15133 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15134 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15135 (error "ERROR: No entity/component or subprogram under cursor")
15136 (beginning-of-line)
15137 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15138 (condition-case info
15139 (let ((token (get-text-property
15140 (match-beginning 3) 'speedbar-token)))
15141 (vhdl-visit-file (car token) t
e6ce8c42
GM
15142 (progn (goto-char (point-min))
15143 (forward-line (1- (cdr token)))
3dcb36b7
JB
15144 (end-of-line)
15145 (if is-entity
15146 (vhdl-port-copy)
15147 (vhdl-subprog-copy)))))
15148 (error (error "ERROR: %s not scanned successfully\n (%s)"
15149 (if is-entity "Port" "Interface") (cadr info))))
15150 (error "ERROR: No entity/component or subprogram on current line")))))
15151
15152(defun vhdl-speedbar-place-component ()
15153 "Place the entity/component under the cursor as component."
15154 (interactive)
15155 (if (not (vhdl-speedbar-check-unit 'entity))
5bb5087f 15156 (error "ERROR: No entity/component under cursor")
3dcb36b7
JB
15157 (vhdl-speedbar-port-copy)
15158 (if (fboundp 'speedbar-select-attached-frame)
15159 (speedbar-select-attached-frame)
15160 (select-frame speedbar-attached-frame))
15161 (vhdl-compose-place-component)
15162 (select-frame speedbar-frame)))
15163
0a2e512a
RF
15164(defun vhdl-speedbar-configuration ()
15165 "Generate configuration for the architecture under the cursor."
15166 (interactive)
15167 (if (not (vhdl-speedbar-check-unit 'architecture))
15168 (error "ERROR: No architecture under cursor")
15169 (let ((arch-name (vhdl-speedbar-line-text))
15170 (ent-name (vhdl-speedbar-higher-text)))
15171 (if (fboundp 'speedbar-select-attached-frame)
15172 (speedbar-select-attached-frame)
15173 (select-frame speedbar-attached-frame))
15174 (vhdl-compose-configuration ent-name arch-name))))
15175
15176(defun vhdl-speedbar-select-mra ()
15177 "Select the architecture under the cursor as MRA."
15178 (interactive)
15179 (if (not (vhdl-speedbar-check-unit 'architecture))
15180 (error "ERROR: No architecture under cursor")
15181 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15182 (ent-key (downcase (vhdl-speedbar-higher-text)))
15183 (ent-alist (aget vhdl-entity-alist
15184 (or (vhdl-project-p) default-directory) t))
15185 (ent-entry (aget ent-alist ent-key t)))
15186 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15187 (speedbar-refresh))))
15188
3dcb36b7
JB
15189(defun vhdl-speedbar-make-design ()
15190 "Make (compile) design unit or directory/project under the cursor."
15191 (interactive)
15192 (if (not (save-excursion (beginning-of-line)
15193 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15194 (error "ERROR: No primary design unit or directory/project under cursor")
15195 (let ((is-unit (match-string 2))
15196 (unit-name (vhdl-speedbar-line-text))
15197 (vhdl-project (vhdl-speedbar-line-project))
15198 (directory (file-name-as-directory
7752250e 15199 (or (speedbar-line-file) (speedbar-line-directory)))))
3dcb36b7
JB
15200 (if (fboundp 'speedbar-select-attached-frame)
15201 (speedbar-select-attached-frame)
15202 (select-frame speedbar-attached-frame))
15203 (let ((default-directory directory))
15204 (vhdl-make (and is-unit unit-name))))))
15205
15206(defun vhdl-speedbar-generate-makefile ()
15207 "Generate Makefile for directory/project under the cursor."
15208 (interactive)
15209 (let ((vhdl-project (vhdl-speedbar-line-project))
15210 (default-directory (file-name-as-directory
7752250e 15211 (or (speedbar-line-file) (speedbar-line-directory)))))
3dcb36b7
JB
15212 (vhdl-generate-makefile)))
15213
15214(defun vhdl-speedbar-check-unit (design-unit)
15215 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15216expansion function)."
15217 (save-excursion
15218 (speedbar-position-cursor-on-line)
15219 (cond ((eq design-unit 'entity)
15220 (memq (get-text-property (match-end 0) 'face)
0a2e512a
RF
15221 '(vhdl-speedbar-entity-face
15222 vhdl-speedbar-entity-selected-face)))
15223 ((eq design-unit 'architecture)
15224 (memq (get-text-property (match-end 0) 'face)
15225 '(vhdl-speedbar-architecture-face
15226 vhdl-speedbar-architecture-selected-face)))
3dcb36b7
JB
15227 ((eq design-unit 'subprogram)
15228 (eq (get-text-property (match-end 0) 'face)
0a2e512a 15229 'vhdl-speedbar-subprogram-face))
3dcb36b7
JB
15230 (t nil))))
15231
15232(defun vhdl-speedbar-set-depth (depth)
15233 "Set hierarchy display depth to DEPTH and refresh speedbar."
15234 (setq vhdl-speedbar-hierarchy-depth depth)
15235 (speedbar-refresh))
5eabfe72
KH
15236
15237;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15238;; Fontification
15239
0a2e512a 15240(defface vhdl-speedbar-entity-face
5eabfe72
KH
15241 '((((class color) (background light)) (:foreground "ForestGreen"))
15242 (((class color) (background dark)) (:foreground "PaleGreen")))
15243 "Face used for displaying entity names."
15244 :group 'speedbar-faces)
15245
0a2e512a 15246(defface vhdl-speedbar-architecture-face
f47877ee
DN
15247 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15248 (((class color) (background light)) (:foreground "Blue"))
84c98ace 15249
5eabfe72
KH
15250 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15251 "Face used for displaying architecture names."
15252 :group 'speedbar-faces)
d2ddb974 15253
0a2e512a 15254(defface vhdl-speedbar-configuration-face
5eabfe72
KH
15255 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15256 (((class color) (background dark)) (:foreground "Salmon")))
15257 "Face used for displaying configuration names."
15258 :group 'speedbar-faces)
15259
0a2e512a 15260(defface vhdl-speedbar-package-face
5eabfe72
KH
15261 '((((class color) (background light)) (:foreground "Grey50"))
15262 (((class color) (background dark)) (:foreground "Grey80")))
15263 "Face used for displaying package names."
15264 :group 'speedbar-faces)
15265
0a2e512a 15266(defface vhdl-speedbar-library-face
3dcb36b7
JB
15267 '((((class color) (background light)) (:foreground "Purple"))
15268 (((class color) (background dark)) (:foreground "Orchid1")))
15269 "Face used for displaying library names."
15270 :group 'speedbar-faces)
15271
0a2e512a 15272(defface vhdl-speedbar-instantiation-face
5eabfe72 15273 '((((class color) (background light)) (:foreground "Brown"))
ea81d57e 15274 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
5eabfe72
KH
15275 (((class color) (background dark)) (:foreground "Yellow")))
15276 "Face used for displaying instantiation names."
15277 :group 'speedbar-faces)
15278
0a2e512a 15279(defface vhdl-speedbar-subprogram-face
3dcb36b7
JB
15280 '((((class color) (background light)) (:foreground "Orchid4"))
15281 (((class color) (background dark)) (:foreground "BurlyWood2")))
15282 "Face used for displaying subprogram names."
15283 :group 'speedbar-faces)
15284
0a2e512a 15285(defface vhdl-speedbar-entity-selected-face
5eabfe72
KH
15286 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15287 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15288 "Face used for displaying entity names."
15289 :group 'speedbar-faces)
15290
0a2e512a 15291(defface vhdl-speedbar-architecture-selected-face
f47877ee
DN
15292 '((((min-colors 88) (class color) (background light)) (:foreground
15293 "Blue1" :underline t))
15294 (((class color) (background light)) (:foreground "Blue" :underline t))
5eabfe72
KH
15295 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15296 "Face used for displaying architecture names."
15297 :group 'speedbar-faces)
15298
0a2e512a 15299(defface vhdl-speedbar-configuration-selected-face
5eabfe72
KH
15300 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15301 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15302 "Face used for displaying configuration names."
15303 :group 'speedbar-faces)
15304
0a2e512a 15305(defface vhdl-speedbar-package-selected-face
5eabfe72
KH
15306 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15307 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15308 "Face used for displaying package names."
15309 :group 'speedbar-faces)
15310
0a2e512a 15311(defface vhdl-speedbar-instantiation-selected-face
5eabfe72
KH
15312 '((((class color) (background light)) (:foreground "Brown" :underline t))
15313 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15314 "Face used for displaying instantiation names."
15315 :group 'speedbar-faces)
15316
3dcb36b7
JB
15317;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15318;; Initialization
15319
15320;; add speedbar
15321(when (fboundp 'speedbar)
15322 (condition-case ()
15323 (when (and vhdl-speedbar-auto-open
15324 (not (and (boundp 'speedbar-frame)
15325 (frame-live-p speedbar-frame))))
15326 (speedbar-frame-mode 1)
15327 (if (fboundp 'speedbar-select-attached-frame)
15328 (speedbar-select-attached-frame)
15329 (select-frame speedbar-attached-frame)))
15330 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15331
15332;; initialize speedbar
15333(if (not (boundp 'speedbar-frame))
15334 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15335 (vhdl-speedbar-initialize)
15336 (when speedbar-frame (vhdl-speedbar-refresh)))
15337
15338
15339;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15340;;; Structural composition
15341;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15342
15343(defun vhdl-get-components-package-name ()
15344 "Return the name of the components package."
15345 (let ((project (vhdl-project-p)))
15346 (if project
15347 (vhdl-replace-string (car vhdl-components-package-name)
15348 (subst-char-in-string ? ?_ project))
15349 (cdr vhdl-components-package-name))))
15350
15351(defun vhdl-compose-new-component ()
15352 "Create entity and architecture for new component."
15353 (interactive)
15354 (let* ((case-fold-search t)
15355 (ent-name (read-from-minibuffer "entity name: "
15356 nil vhdl-minibuffer-local-map))
15357 (arch-name
15358 (if (equal (cdr vhdl-compose-architecture-name) "")
15359 (read-from-minibuffer "architecture name: "
15360 nil vhdl-minibuffer-local-map)
15361 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15362 ent-file-name arch-file-name ent-buffer arch-buffer project)
15363 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15364 ;; open entity file
15365 (unless (eq vhdl-compose-create-files 'none)
15366 (setq ent-file-name
0a2e512a 15367 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15368 "." (file-name-extension (buffer-file-name))))
15369 (when (and (file-exists-p ent-file-name)
15370 (not (y-or-n-p (concat "File \"" ent-file-name
15371 "\" exists; overwrite? "))))
15372 (error "ERROR: Creating component...aborted"))
15373 (find-file ent-file-name)
15374 (erase-buffer)
15375 (set-buffer-modified-p nil))
15376 ;; insert header
15377 (if vhdl-compose-include-header
15378 (progn (vhdl-template-header)
15379 (goto-char (point-max)))
15380 (vhdl-comment-display-line) (insert "\n\n"))
15381 ;; insert library clause
15382 (vhdl-template-package-std-logic-1164)
15383 (when vhdl-use-components-package
15384 (insert "\n")
15385 (vhdl-template-standard-package (vhdl-work-library)
15386 (vhdl-get-components-package-name)))
15387 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15388 ;; insert entity declaration
15389 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15390 (vhdl-insert-keyword " IS\n")
15391 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15392 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15393 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15394 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15395 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15396 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15397 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15398 (vhdl-insert-keyword "END ")
15399 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15400 (insert ent-name ";\n\n")
15401 (vhdl-comment-display-line) (insert "\n")
15402 ;; open architecture file
15403 (if (not (eq vhdl-compose-create-files 'separate))
15404 (insert "\n")
15405 (setq ent-buffer (current-buffer))
15406 (setq arch-file-name
15407 (concat (vhdl-replace-string vhdl-architecture-file-name
0a2e512a 15408 (concat ent-name " " arch-name) t)
3dcb36b7
JB
15409 "." (file-name-extension (buffer-file-name))))
15410 (when (and (file-exists-p arch-file-name)
15411 (not (y-or-n-p (concat "File \"" arch-file-name
15412 "\" exists; overwrite? "))))
15413 (error "ERROR: Creating component...aborted"))
15414 (find-file arch-file-name)
15415 (erase-buffer)
15416 (set-buffer-modified-p nil)
15417 ;; insert header
15418 (if vhdl-compose-include-header
15419 (progn (vhdl-template-header)
15420 (goto-char (point-max)))
15421 (vhdl-comment-display-line) (insert "\n\n")))
15422 ;; insert architecture body
15423 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15424 (vhdl-insert-keyword " OF ") (insert ent-name)
15425 (vhdl-insert-keyword " IS\n\n")
15426 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15427 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15428 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15429 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15430 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15431 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15432 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15433 (vhdl-insert-keyword "BEGIN")
15434 (when vhdl-self-insert-comments
15435 (insert " -- ")
15436 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15437 (insert arch-name))
15438 (insert "\n\n")
15439 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15440 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15441 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15442 (vhdl-insert-keyword "END ")
15443 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15444 (insert arch-name ";\n\n")
0a2e512a 15445 ;; insert footer and save
3dcb36b7
JB
15446 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15447 (vhdl-template-footer)
15448 (vhdl-comment-display-line) (insert "\n"))
15449 (goto-char (point-min))
15450 (setq arch-buffer (current-buffer))
15451 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15452 (set-buffer arch-buffer) (save-buffer)
29a4e67d 15453 (message "%s"
3dcb36b7
JB
15454 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15455 (and ent-file-name
15456 (format "\n File created: \"%s\"" ent-file-name))
15457 (and arch-file-name
15458 (format "\n File created: \"%s\"" arch-file-name))))))
15459
15460(defun vhdl-compose-place-component ()
15461 "Place new component by pasting current port as component declaration and
15462component instantiation."
15463 (interactive)
15464 (if (not vhdl-port-list)
15465 (error "ERROR: No port has been read")
15466 (save-excursion
15467 (vhdl-prepare-search-2
15468 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15469 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15470 (error "ERROR: No architecture found"))
15471 (let* ((ent-name (match-string 1))
15472 (ent-file-name
0a2e512a 15473 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15474 "." (file-name-extension (buffer-file-name))))
15475 (orig-buffer (current-buffer)))
15476 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15477 ;; place component declaration
15478 (unless (or vhdl-use-components-package
15479 (vhdl-use-direct-instantiation)
15480 (save-excursion
15481 (re-search-forward
15482 (concat "^\\s-*component\\s-+"
15483 (car vhdl-port-list) "\\>") nil t)))
15484 (re-search-forward "^begin\\>" nil)
15485 (beginning-of-line)
15486 (skip-chars-backward " \t\n")
15487 (insert "\n\n") (indent-to vhdl-basic-offset)
15488 (vhdl-port-paste-component t))
15489 ;; place component instantiation
15490 (re-search-forward "^end\\>" nil)
15491 (beginning-of-line)
15492 (skip-chars-backward " \t\n")
15493 (insert "\n\n") (indent-to vhdl-basic-offset)
15494 (vhdl-port-paste-instance nil t t)
15495 ;; place use clause for used packages
15496 (when (nth 3 vhdl-port-list)
15497 ;; open entity file
15498 (when (file-exists-p ent-file-name)
15499 (find-file ent-file-name))
15500 (goto-char (point-min))
15501 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15502 (error "ERROR: Entity not found: \"%s\"" ent-name))
15503 (goto-char (match-beginning 0))
15504 (if (and (save-excursion
15505 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15506 (match-string 1))
15507 (progn (goto-char (match-end 0))
15508 (beginning-of-line 2))
15509 (insert "\n")
15510 (backward-char))
15511 (vhdl-port-paste-context-clause)
15512 (switch-to-buffer orig-buffer))
15513 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15514
15515(defun vhdl-compose-wire-components ()
15516 "Connect components."
15517 (interactive)
15518 (save-excursion
15519 (vhdl-prepare-search-2
15520 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15521 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15522 (error "ERROR: No architecture found"))
15523 (let* ((ent-name (match-string 1))
15524 (ent-file-name
0a2e512a 15525 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15526 "." (file-name-extension (buffer-file-name))))
15527 (arch-decl-pos (point-marker))
15528 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15529 (arch-end-pos (re-search-forward "^end\\>" nil))
15530 (pack-name (vhdl-get-components-package-name))
15531 (pack-file-name
0a2e512a 15532 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15533 "." (file-name-extension (buffer-file-name))))
15534 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15535 port-alist generic-alist inst-alist
15536 signal-name signal-entry signal-alist local-list written-list
15537 single-in-list multi-in-list single-out-list multi-out-list
15538 constant-name constant-entry constant-alist single-list multi-list
15539 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15540 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15541 signal-beg-pos signal-pos
15542 constant-temp-pos port-temp-pos signal-temp-pos)
15543 (message "Wiring components...")
15544 ;; process all instances
15545 (goto-char arch-stat-pos)
15546 (while (re-search-forward
15547 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15548 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15549 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15550 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15551 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15552 (setq inst-name (match-string-no-properties 1)
15553 comp-name (match-string-no-properties 4)
15554 comp-ent-name (match-string-no-properties 12)
15555 has-generic (or (match-string 7) (match-string 17)))
15556 ;; get port ...
15557 (if comp-name
15558 ;; ... from component declaration
15559 (vhdl-visit-file
15560 (when vhdl-use-components-package pack-file-name) t
15561 (save-excursion
15562 (goto-char (point-min))
15563 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15564 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15565 (vhdl-port-copy)))
15566 ;; ... from entity declaration (direct instantiation)
15567 (setq comp-ent-file-name
0a2e512a 15568 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
3dcb36b7
JB
15569 "." (file-name-extension (buffer-file-name))))
15570 (vhdl-visit-file
15571 comp-ent-file-name t
15572 (save-excursion
15573 (goto-char (point-min))
15574 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15575 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15576 (vhdl-port-copy))))
15577 (vhdl-port-flatten t)
15578 (setq generic-alist (nth 1 vhdl-port-list)
0a2e512a
RF
15579 port-alist (nth 2 vhdl-port-list)
15580 vhdl-port-list nil)
3dcb36b7
JB
15581 (setq constant-alist nil
15582 signal-alist nil)
15583 (when has-generic
15584 ;; process all constants in generic map
15585 (vhdl-forward-syntactic-ws)
15586 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15587 (setq constant-name (match-string-no-properties 3))
15588 (setq constant-entry
15589 (cons constant-name
15590 (if (match-string 1)
15591 (or (aget generic-alist (match-string 2) t)
ec3ec9cc 15592 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15593 (cdar generic-alist))))
15594 (setq constant-alist (cons constant-entry constant-alist))
15595 (setq constant-name (downcase constant-name))
15596 (if (or (member constant-name single-list)
15597 (member constant-name multi-list))
15598 (progn (setq single-list (delete constant-name single-list))
15599 (add-to-list 'multi-list constant-name))
15600 (add-to-list 'single-list constant-name))
15601 (unless (match-string 1)
15602 (setq generic-alist (cdr generic-alist)))
15603 (vhdl-forward-syntactic-ws))
15604 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15605 ;; process all signals in port map
15606 (vhdl-forward-syntactic-ws)
15607 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15608 (setq signal-name (match-string-no-properties 3))
15609 (setq signal-entry (cons signal-name
15610 (if (match-string 1)
15611 (or (aget port-alist (match-string 2) t)
ec3ec9cc 15612 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15613 (cdar port-alist))))
15614 (setq signal-alist (cons signal-entry signal-alist))
15615 (setq signal-name (downcase signal-name))
15616 (if (equal (upcase (nth 2 signal-entry)) "IN")
15617 ;; input signal
15618 (cond
15619 ((member signal-name local-list)
15620 nil)
15621 ((or (member signal-name single-out-list)
15622 (member signal-name multi-out-list))
15623 (setq single-out-list (delete signal-name single-out-list))
15624 (setq multi-out-list (delete signal-name multi-out-list))
15625 (add-to-list 'local-list signal-name))
15626 ((member signal-name single-in-list)
15627 (setq single-in-list (delete signal-name single-in-list))
15628 (add-to-list 'multi-in-list signal-name))
15629 ((not (member signal-name multi-in-list))
15630 (add-to-list 'single-in-list signal-name)))
15631 ;; output signal
15632 (cond
15633 ((member signal-name local-list)
15634 nil)
15635 ((or (member signal-name single-in-list)
15636 (member signal-name multi-in-list))
15637 (setq single-in-list (delete signal-name single-in-list))
15638 (setq multi-in-list (delete signal-name multi-in-list))
15639 (add-to-list 'local-list signal-name))
15640 ((member signal-name single-out-list)
15641 (setq single-out-list (delete signal-name single-out-list))
15642 (add-to-list 'multi-out-list signal-name))
15643 ((not (member signal-name multi-out-list))
15644 (add-to-list 'single-out-list signal-name))))
15645 (unless (match-string 1)
15646 (setq port-alist (cdr port-alist)))
15647 (vhdl-forward-syntactic-ws))
15648 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15649 (nreverse signal-alist)) inst-alist)))
15650 ;; prepare signal insertion
15651 (vhdl-goto-marker arch-decl-pos)
15652 (forward-line 1)
15653 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15654 (setq signal-pos (point-marker))
15655 (while (progn (vhdl-forward-syntactic-ws)
15656 (looking-at "signal\\>"))
15657 (beginning-of-line 2)
15658 (delete-region signal-pos (point)))
15659 (setq signal-beg-pos signal-pos)
15660 ;; open entity file
15661 (when (file-exists-p ent-file-name)
15662 (find-file ent-file-name))
15663 (goto-char (point-min))
15664 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15665 (error "ERROR: Entity not found: \"%s\"" ent-name))
15666 ;; prepare generic clause insertion
15667 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15668 (match-string 1))
15669 (goto-char (match-beginning 0))
15670 (indent-to vhdl-basic-offset)
15671 (insert "generic ();\n\n")
15672 (backward-char 4))
15673 (backward-char)
15674 (setq generic-pos (point-marker))
15675 (forward-sexp) (end-of-line)
15676 (delete-region generic-pos (point)) (delete-char 1)
15677 (insert "(\n")
15678 (when multi-list
15679 (insert "\n")
15680 (indent-to (* 2 vhdl-basic-offset))
15681 (insert "-- global generics\n"))
15682 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15683 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15684 ;; prepare port clause insertion
15685 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15686 (match-string 1))
15687 (goto-char (match-beginning 0))
15688 (indent-to vhdl-basic-offset)
15689 (insert "port ();\n\n")
15690 (backward-char 4))
15691 (backward-char)
15692 (setq port-in-pos (point-marker))
15693 (forward-sexp) (end-of-line)
15694 (delete-region port-in-pos (point)) (delete-char 1)
15695 (insert "(\n")
15696 (when (or multi-in-list multi-out-list)
15697 (insert "\n")
15698 (indent-to (* 2 vhdl-basic-offset))
15699 (insert "-- global ports\n"))
15700 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15701 port-out-pos (point-marker) port-inst-pos (point-marker)
15702 port-end-pos (point-marker))
15703 ;; insert generics, ports and signals
15704 (setq inst-alist (nreverse inst-alist))
15705 (while inst-alist
15706 (setq inst-name (nth 0 (car inst-alist))
15707 constant-alist (nth 1 (car inst-alist))
15708 signal-alist (nth 2 (car inst-alist))
15709 constant-temp-pos generic-inst-pos
15710 port-temp-pos port-inst-pos
15711 signal-temp-pos signal-pos)
15712 ;; generics
15713 (while constant-alist
15714 (setq constant-name (downcase (caar constant-alist))
15715 constant-entry (car constant-alist))
15716 (cond ((member constant-name written-list)
15717 nil)
15718 ((member constant-name multi-list)
15719 (vhdl-goto-marker generic-pos)
15720 (setq generic-end-pos
15721 (vhdl-max-marker
15722 generic-end-pos
15723 (vhdl-compose-insert-generic constant-entry)))
15724 (setq generic-pos (point-marker))
15725 (add-to-list 'written-list constant-name))
15726 (t
15727 (vhdl-goto-marker
15728 (vhdl-max-marker generic-inst-pos generic-pos))
15729 (setq generic-end-pos
15730 (vhdl-compose-insert-generic constant-entry))
15731 (setq generic-inst-pos (point-marker))
15732 (add-to-list 'written-list constant-name)))
15733 (setq constant-alist (cdr constant-alist)))
15734 (when (/= constant-temp-pos generic-inst-pos)
15735 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15736 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15737 (insert "-- generics for \"" inst-name "\"\n")
15738 (vhdl-goto-marker generic-inst-pos))
15739 ;; ports and signals
15740 (while signal-alist
15741 (setq signal-name (downcase (caar signal-alist))
15742 signal-entry (car signal-alist))
15743 (cond ((member signal-name written-list)
15744 nil)
15745 ((member signal-name multi-in-list)
15746 (vhdl-goto-marker port-in-pos)
15747 (setq port-end-pos
15748 (vhdl-max-marker
15749 port-end-pos (vhdl-compose-insert-port signal-entry)))
15750 (setq port-in-pos (point-marker))
15751 (add-to-list 'written-list signal-name))
15752 ((member signal-name multi-out-list)
15753 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15754 (setq port-end-pos
15755 (vhdl-max-marker
15756 port-end-pos (vhdl-compose-insert-port signal-entry)))
15757 (setq port-out-pos (point-marker))
15758 (add-to-list 'written-list signal-name))
15759 ((or (member signal-name single-in-list)
15760 (member signal-name single-out-list))
15761 (vhdl-goto-marker
15762 (vhdl-max-marker
15763 port-inst-pos
15764 (vhdl-max-marker port-out-pos port-in-pos)))
15765 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15766 (setq port-inst-pos (point-marker))
15767 (add-to-list 'written-list signal-name))
15768 ((equal (upcase (nth 2 signal-entry)) "OUT")
15769 (vhdl-goto-marker signal-pos)
15770 (vhdl-compose-insert-signal signal-entry)
15771 (setq signal-pos (point-marker))
15772 (add-to-list 'written-list signal-name)))
15773 (setq signal-alist (cdr signal-alist)))
15774 (when (/= port-temp-pos port-inst-pos)
15775 (vhdl-goto-marker
15776 (vhdl-max-marker port-temp-pos
15777 (vhdl-max-marker port-in-pos port-out-pos)))
15778 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15779 (insert "-- ports to \"" inst-name "\"\n")
15780 (vhdl-goto-marker port-inst-pos))
15781 (when (/= signal-temp-pos signal-pos)
15782 (vhdl-goto-marker signal-temp-pos)
15783 (insert "\n") (indent-to vhdl-basic-offset)
15784 (insert "-- outputs of \"" inst-name "\"\n")
15785 (vhdl-goto-marker signal-pos))
15786 (setq inst-alist (cdr inst-alist)))
15787 ;; finalize generic/port clause
15788 (vhdl-goto-marker generic-end-pos) (backward-char)
15789 (when (= generic-beg-pos generic-end-pos)
15790 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15791 (insert ";") (backward-char))
15792 (insert ")")
15793 (vhdl-goto-marker port-end-pos) (backward-char)
15794 (when (= port-beg-pos port-end-pos)
15795 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15796 (insert ";") (backward-char))
15797 (insert ")")
15798 ;; align everything
15799 (when vhdl-auto-align
15800 (vhdl-goto-marker generic-beg-pos)
15801 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15802 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15803 (vhdl-goto-marker signal-beg-pos)
15804 (vhdl-align-region-groups signal-beg-pos signal-pos))
15805 (switch-to-buffer (marker-buffer signal-beg-pos))
15806 (message "Wiring components...done")))))
15807
15808(defun vhdl-compose-insert-generic (entry)
15809 "Insert ENTRY as generic declaration."
15810 (let (pos)
15811 (indent-to (* 2 vhdl-basic-offset))
15812 (insert (nth 0 entry) " : " (nth 1 entry))
15813 (when (nth 2 entry)
15814 (insert " := " (nth 2 entry)))
15815 (insert ";")
15816 (setq pos (point-marker))
15817 (when (and vhdl-include-port-comments (nth 3 entry))
15818 (vhdl-comment-insert-inline (nth 3 entry) t))
15819 (insert "\n")
15820 pos))
15821
15822(defun vhdl-compose-insert-port (entry)
15823 "Insert ENTRY as port declaration."
15824 (let (pos)
15825 (indent-to (* 2 vhdl-basic-offset))
15826 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15827 (setq pos (point-marker))
15828 (when (and vhdl-include-port-comments (nth 4 entry))
15829 (vhdl-comment-insert-inline (nth 4 entry) t))
15830 (insert "\n")
15831 pos))
15832
15833(defun vhdl-compose-insert-signal (entry)
15834 "Insert ENTRY as signal declaration."
15835 (indent-to vhdl-basic-offset)
15836 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15837 (when (and vhdl-include-port-comments (nth 4 entry))
15838 (vhdl-comment-insert-inline (nth 4 entry) t))
15839 (insert "\n"))
15840
15841(defun vhdl-compose-components-package ()
15842 "Generate a package containing component declarations for all entities in the
15843current project/directory."
15844 (interactive)
15845 (vhdl-require-hierarchy-info)
15846 (let* ((project (vhdl-project-p))
15847 (pack-name (vhdl-get-components-package-name))
15848 (pack-file-name
0a2e512a 15849 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15850 "." (file-name-extension (buffer-file-name))))
15851 (ent-alist (aget vhdl-entity-alist
15852 (or project default-directory) t))
15853 (lazy-lock-minimum-size 0)
15854 clause-pos component-pos)
15855 (message "Generating components package \"%s\"..." pack-name)
15856 ;; open package file
15857 (when (and (file-exists-p pack-file-name)
15858 (not (y-or-n-p (concat "File \"" pack-file-name
15859 "\" exists; overwrite? "))))
15860 (error "ERROR: Generating components package...aborted"))
15861 (find-file pack-file-name)
15862 (erase-buffer)
15863 ;; insert header
15864 (if vhdl-compose-include-header
15865 (progn (vhdl-template-header
15866 (concat "Components package (generated by Emacs VHDL Mode "
15867 vhdl-version ")"))
15868 (goto-char (point-max)))
15869 (vhdl-comment-display-line) (insert "\n\n"))
15870 ;; insert std_logic_1164 package
15871 (vhdl-template-package-std-logic-1164)
15872 (insert "\n") (setq clause-pos (point-marker))
15873 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15874 ;; insert package declaration
15875 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15876 (vhdl-insert-keyword " IS\n\n")
15877 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15878 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15879 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15880 (indent-to vhdl-basic-offset)
15881 (setq component-pos (point-marker))
15882 (insert "\n\n") (vhdl-insert-keyword "END ")
15883 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15884 (insert pack-name ";\n\n")
15885 ;; insert footer
15886 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15887 (vhdl-template-footer)
15888 (vhdl-comment-display-line) (insert "\n"))
15889 ;; insert component declarations
15890 (while ent-alist
15891 (vhdl-visit-file (nth 2 (car ent-alist)) nil
e6ce8c42
GM
15892 (progn (goto-char (point-min))
15893 (forward-line (1- (nth 3 (car ent-alist))))
3dcb36b7
JB
15894 (end-of-line)
15895 (vhdl-port-copy)))
15896 (goto-char component-pos)
15897 (vhdl-port-paste-component t)
15898 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15899 (setq component-pos (point-marker))
15900 (goto-char clause-pos)
15901 (vhdl-port-paste-context-clause pack-name)
15902 (setq clause-pos (point-marker))
15903 (setq ent-alist (cdr ent-alist)))
15904 (goto-char (point-min))
15905 (save-buffer)
15906 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15907 pack-name pack-file-name)))
15908
0a2e512a
RF
15909(defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15910 &optional insert-conf)
15911 "Generate block configuration for architecture."
15912 (let ((margin (current-indentation))
15913 (beg (save-excursion (beginning-of-line) (point)))
15914 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15915 ;; insert block configuration (for architecture)
15916 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15917 (setq margin (+ margin vhdl-basic-offset))
15918 ;; process all instances
15919 (while inst-alist
15920 (setq inst-entry (car inst-alist))
15921 ;; is component?
15922 (when (nth 4 inst-entry)
15923 (setq insert-conf t)
15924 (setq inst-path (nth 9 inst-entry))
15925 ;; skip common path with previous instance
15926 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15927 (setq inst-path (cdr inst-path)
15928 inst-prev-path (cdr inst-prev-path)))
15929 ;; insert block configuration end (for previous block/generate)
15930 (while inst-prev-path
15931 (setq margin (- margin vhdl-basic-offset))
15932 (indent-to margin)
15933 (vhdl-insert-keyword "END FOR;\n")
15934 (setq inst-prev-path (cdr inst-prev-path)))
15935 ;; insert block configuration beginning (for current block/generate)
15936 (indent-to margin)
15937 (while inst-path
15938 (setq margin (+ margin vhdl-basic-offset))
15939 (vhdl-insert-keyword "FOR ")
15940 (insert (car inst-path) "\n")
15941 (indent-to margin)
15942 (setq inst-path (cdr inst-path)))
15943 ;; insert component configuration beginning
15944 (vhdl-insert-keyword "FOR ")
15945 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15946 ;; find subconfiguration
15947 (setq conf-key (nth 7 inst-entry))
15948 (setq tmp-alist conf-alist)
15949 ;; use first configuration found for instance's entity
15950 (while (and tmp-alist (null conf-key))
15951 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15952 (setq conf-key (nth 0 (car tmp-alist))))
15953 (setq tmp-alist (cdr tmp-alist)))
15954 (setq conf-entry (aget conf-alist conf-key t))
15955 ;; insert binding indication ...
15956 ;; ... with subconfiguration (if exists)
15957 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15958 (progn
15959 (indent-to (+ margin vhdl-basic-offset))
15960 (vhdl-insert-keyword "USE CONFIGURATION ")
15961 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15962 (insert ";\n"))
15963 ;; ... with entity (if exists)
15964 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15965 (when ent-entry
15966 (indent-to (+ margin vhdl-basic-offset))
15967 (vhdl-insert-keyword "USE ENTITY ")
15968 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15969 ;; insert architecture name (if architecture exists)
15970 (when (nth 3 ent-entry)
15971 (setq arch-name
15972 ;; choose architecture name a) from configuration,
15973 ;; b) from mra, or c) from first architecture
15974 (or (nth 0 (aget (nth 3 ent-entry)
15975 (or (nth 6 inst-entry)
15976 (nth 4 ent-entry)) t))
15977 (nth 1 (car (nth 3 ent-entry)))))
15978 (insert "(" arch-name ")"))
15979 (insert ";\n")
15980 ;; insert block configuration (for architecture of subcomponent)
15981 (when (and vhdl-compose-configuration-hierarchical
15982 (nth 3 ent-entry))
15983 (indent-to (+ margin vhdl-basic-offset))
15984 (vhdl-compose-configuration-architecture
15985 (nth 0 ent-entry) arch-name
15986 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
15987 ;; insert component configuration end
15988 (indent-to margin)
15989 (vhdl-insert-keyword "END FOR;\n")
15990 (setq inst-prev-path (nth 9 inst-entry)))
15991 (setq inst-alist (cdr inst-alist)))
15992 ;; insert block configuration end (for block/generate)
15993 (while inst-prev-path
15994 (setq margin (- margin vhdl-basic-offset))
15995 (indent-to margin)
15996 (vhdl-insert-keyword "END FOR;\n")
15997 (setq inst-prev-path (cdr inst-prev-path)))
15998 (indent-to (- margin vhdl-basic-offset))
15999 ;; insert block configuration end or remove beginning (for architecture)
16000 (if insert-conf
16001 (vhdl-insert-keyword "END FOR;\n")
16002 (delete-region beg (point)))))
16003
16004(defun vhdl-compose-configuration (&optional ent-name arch-name)
16005 "Generate configuration declaration."
16006 (interactive)
16007 (vhdl-require-hierarchy-info)
16008 (let ((ent-alist (aget vhdl-entity-alist
16009 (or (vhdl-project-p) default-directory) t))
16010 (conf-alist (aget vhdl-config-alist
16011 (or (vhdl-project-p) default-directory) t))
16012 (from-speedbar ent-name)
16013 inst-alist conf-name conf-file-name pos)
16014 (vhdl-prepare-search-2
16015 ;; get entity and architecture name
16016 (unless ent-name
16017 (save-excursion
16018 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16019 (not (equal "END" (upcase (match-string 1))))
16020 (setq ent-name (match-string-no-properties 3))
16021 (setq arch-name (match-string-no-properties 2)))
16022 (error "ERROR: Not within an architecture"))))
16023 (setq conf-name (vhdl-replace-string
16024 vhdl-compose-configuration-name
16025 (concat ent-name " " arch-name)))
16026 (setq inst-alist
16027 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16028 (downcase arch-name) t))))
16029 (message "Generating configuration \"%s\"..." conf-name)
16030 (if vhdl-compose-configuration-create-file
16031 ;; open configuration file
16032 (progn
16033 (setq conf-file-name
16034 (concat (vhdl-replace-string vhdl-configuration-file-name
16035 conf-name t)
16036 "." (file-name-extension (buffer-file-name))))
16037 (when (and (file-exists-p conf-file-name)
16038 (not (y-or-n-p (concat "File \"" conf-file-name
16039 "\" exists; overwrite? "))))
16040 (error "ERROR: Creating configuration...aborted"))
16041 (find-file conf-file-name)
16042 (erase-buffer)
16043 (set-buffer-modified-p nil)
16044 ;; insert header
16045 (if vhdl-compose-include-header
16046 (progn (vhdl-template-header
16047 (concat "Configuration declaration for design \""
16048 ent-name "(" arch-name ")\""))
16049 (goto-char (point-max)))
16050 (vhdl-comment-display-line) (insert "\n\n")))
16051 ;; goto end of architecture
16052 (unless from-speedbar
16053 (re-search-forward "^end\\>" nil)
16054 (end-of-line) (insert "\n\n")
16055 (vhdl-comment-display-line) (insert "\n\n")))
16056 ;; insert library clause
16057 (setq pos (point))
16058 (vhdl-template-standard-package (vhdl-work-library) nil)
16059 (when (/= pos (point))
16060 (insert "\n\n"))
16061 ;; insert configuration
16062 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16063 (vhdl-insert-keyword " OF ") (insert ent-name)
16064 (vhdl-insert-keyword " IS\n")
16065 (indent-to vhdl-basic-offset)
16066 ;; insert block configuration (for architecture)
16067 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16068 (vhdl-insert-keyword "END ") (insert conf-name ";")
16069 (when conf-file-name
16070 ;; insert footer and save
16071 (insert "\n\n")
16072 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16073 (vhdl-template-footer)
16074 (vhdl-comment-display-line) (insert "\n"))
16075 (save-buffer))
29a4e67d 16076 (message "%s"
0a2e512a
RF
16077 (concat (format "Generating configuration \"%s\"...done" conf-name)
16078 (and conf-file-name
16079 (format "\n File created: \"%s\"" conf-file-name))))))
16080
3dcb36b7
JB
16081
16082;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16083;;; Compilation / Makefile generation
16084;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16085;; (using `compile.el')
16086
16087(defun vhdl-makefile-name ()
16088 "Return the Makefile name of the current project or the current compiler if
16089no project is defined."
16090 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16091 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16092 (vhdl-replace-string
16093 (cons "\\(.*\\)\n\\(.*\\)"
16094 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16095 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16096
16097(defun vhdl-compile-directory ()
16098 "Return the directory where compilation/make should be run."
16099 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16100 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16101 (directory (vhdl-resolve-env-variable
16102 (if project
16103 (vhdl-replace-string
16104 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16105 (nth 6 compiler)))))
16106 (file-name-as-directory
16107 (if (file-name-absolute-p directory)
16108 directory
16109 (expand-file-name directory (vhdl-default-directory))))))
16110
16111(defun vhdl-uniquify (in-list)
16112 "Remove duplicate elements from IN-LIST."
16113 (let (out-list)
16114 (while in-list
16115 (add-to-list 'out-list (car in-list))
16116 (setq in-list (cdr in-list)))
16117 out-list))
16118
16119(defun vhdl-set-compiler (name)
16120 "Set current compiler to NAME."
16121 (interactive
16122 (list (let ((completion-ignore-case t))
16123 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16124 (if (assoc name vhdl-compiler-alist)
16125 (progn (setq vhdl-compiler name)
16126 (message "Current compiler: \"%s\"" vhdl-compiler))
16127 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16128
16129;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16130;; Compilation
16131
16132(defun vhdl-compile-init ()
16133 "Initialize for compilation."
16134 (when (or (null compilation-error-regexp-alist)
16135 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16136 compilation-error-regexp-alist)))
16137 ;; `compilation-error-regexp-alist'
16138 (let ((commands-alist vhdl-compiler-alist)
16139 regexp-alist sublist)
16140 (while commands-alist
16141 (setq sublist (nth 11 (car commands-alist)))
16142 (unless (or (equal "" (car sublist))
16143 (assoc (car sublist) regexp-alist))
16144 (setq regexp-alist (cons (list (nth 0 sublist)
16145 (if (= 0 (nth 1 sublist))
f8246027 16146 (if (featurep 'xemacs) 9 nil)
3dcb36b7
JB
16147 (nth 1 sublist))
16148 (nth 2 sublist) (nth 3 sublist))
16149 regexp-alist)))
16150 (setq commands-alist (cdr commands-alist)))
16151 (setq compilation-error-regexp-alist
16152 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16153 ;; `compilation-file-regexp-alist'
16154 (let ((commands-alist vhdl-compiler-alist)
16155 regexp-alist sublist)
16156 ;; matches vhdl-mode file name output
16157 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16158 (while commands-alist
16159 (setq sublist (nth 12 (car commands-alist)))
16160 (unless (or (equal "" (car sublist))
16161 (assoc (car sublist) regexp-alist))
16162 (setq regexp-alist (cons sublist regexp-alist)))
16163 (setq commands-alist (cdr commands-alist)))
16164 (setq compilation-file-regexp-alist
16165 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16166
16167(defvar vhdl-compile-file-name nil
16168 "Name of file to be compiled.")
16169
16170(defun vhdl-compile-print-file-name ()
16171 "Function called within `compile' to print out file name for compilers that
16172do not print any file names."
16173 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16174
16175(defun vhdl-get-compile-options (project compiler file-name
16176 &optional file-options-only)
16177 "Get compiler options. Returning nil means do not compile this file."
16178 (let* ((compiler-options (nth 1 compiler))
16179 (project-entry (aget (nth 4 project) vhdl-compiler))
16180 (project-options (nth 0 project-entry))
16181 (exception-list (and file-name (nth 2 project-entry)))
16182 (work-library (vhdl-work-library))
16183 (case-fold-search nil)
16184 file-options)
16185 (while (and exception-list
16186 (not (string-match (caar exception-list) file-name)))
16187 (setq exception-list (cdr exception-list)))
16188 (if (and exception-list (not (cdar exception-list)))
16189 nil
16190 (if (and file-options-only (not exception-list))
16191 'default
16192 (setq file-options (cdar exception-list))
16193 ;; insert library name in compiler-specific options
16194 (setq compiler-options
16195 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16196 work-library))
16197 ;; insert compiler-specific options in project-specific options
16198 (when project-options
16199 (setq project-options
16200 (vhdl-replace-string
16201 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16202 (concat work-library "\n" compiler-options))))
16203 ;; insert project-specific options in file-specific options
16204 (when file-options
16205 (setq file-options
16206 (vhdl-replace-string
16207 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16208 (concat work-library "\n" compiler-options "\n"
16209 project-options))))
16210 ;; return options
16211 (or file-options project-options compiler-options)))))
16212
16213(defun vhdl-get-make-options (project compiler)
16214 "Get make options."
16215 (let* ((compiler-options (nth 3 compiler))
16216 (project-entry (aget (nth 4 project) vhdl-compiler))
16217 (project-options (nth 1 project-entry))
16218 (makefile-name (vhdl-makefile-name)))
16219 ;; insert Makefile name in compiler-specific options
16220 (setq compiler-options
16221 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16222 makefile-name))
16223 ;; insert compiler-specific options in project-specific options
16224 (when project-options
16225 (setq project-options
16226 (vhdl-replace-string
16227 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16228 (concat makefile-name "\n" compiler-options))))
16229 ;; return options
16230 (or project-options compiler-options)))
16231
16232(defun vhdl-compile ()
16233 "Compile current buffer using the VHDL compiler specified in
16234`vhdl-compiler'."
16235 (interactive)
16236 (vhdl-compile-init)
16237 (let* ((project (aget vhdl-project-alist vhdl-project))
16238 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16239 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16240 (command (nth 0 compiler))
16241 (file-name (buffer-file-name))
16242 (options (vhdl-get-compile-options project compiler file-name))
16243 (default-directory (vhdl-compile-directory))
16244 compilation-process-setup-function)
16245 (unless (file-directory-p default-directory)
16246 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16247 ;; put file name into quotes if it contains spaces
16248 (when (string-match " " file-name)
16249 (setq file-name (concat "\"" file-name "\"")))
16250 ;; print out file name if compiler does not
16251 (setq vhdl-compile-file-name (buffer-file-name))
16252 (when (and (= 0 (nth 1 (nth 10 compiler)))
16253 (= 0 (nth 1 (nth 11 compiler))))
16254 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16255 ;; run compilation
16256 (if options
16257 (when command
16258 (compile (concat command " " options " " file-name)))
16259 (vhdl-warning "Your project settings tell me not to compile this file"))))
16260
0a2e512a
RF
16261(defvar vhdl-make-target "all"
16262 "Default target for `vhdl-make' command.")
16263
3dcb36b7
JB
16264(defun vhdl-make (&optional target)
16265 "Call make command for compilation of all updated source files (requires
16266`Makefile'). Optional argument TARGET allows to compile the design
16267specified by a target."
16268 (interactive)
0a2e512a
RF
16269 (setq vhdl-make-target
16270 (or target (read-from-minibuffer "Target: " vhdl-make-target
16271 vhdl-minibuffer-local-map)))
3dcb36b7
JB
16272 (vhdl-compile-init)
16273 (let* ((project (aget vhdl-project-alist vhdl-project))
16274 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16275 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16276 (command (nth 2 compiler))
16277 (options (vhdl-get-make-options project compiler))
16278 (default-directory (vhdl-compile-directory)))
16279 (unless (file-directory-p default-directory)
16280 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16281 ;; run make
16282 (compile (concat (if (equal command "") "make" command)
0a2e512a 16283 " " options " " vhdl-make-target))))
3dcb36b7
JB
16284
16285;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16286;; Makefile generation
16287
16288(defun vhdl-generate-makefile ()
16289 "Generate `Makefile'."
16290 (interactive)
16291 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16292 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16293 (command (nth 4 compiler)))
16294 ;; generate makefile
16295 (if command
16296 (let ((default-directory (vhdl-compile-directory)))
16297 (compile (vhdl-replace-string
16298 (cons "\\(.*\\) \\(.*\\)" command)
16299 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16300 (vhdl-generate-makefile-1))))
16301
16302(defun vhdl-get-packages (lib-alist work-library)
16303 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16304 (let (pack-list)
16305 (while lib-alist
16306 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16307 (setq pack-list (cons (cdar lib-alist) pack-list)))
16308 (setq lib-alist (cdr lib-alist)))
16309 pack-list))
16310
16311(defun vhdl-generate-makefile-1 ()
16312 "Generate Makefile for current project or directory."
16313 ;; scan hierarchy if required
16314 (if (vhdl-project-p)
16315 (unless (or (assoc vhdl-project vhdl-file-alist)
16316 (vhdl-load-cache vhdl-project))
16317 (vhdl-scan-project-contents vhdl-project))
16318 (let ((directory (abbreviate-file-name default-directory)))
16319 (unless (or (assoc directory vhdl-file-alist)
16320 (vhdl-load-cache directory))
16321 (vhdl-scan-directory-contents directory))))
16322 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16323 (project (vhdl-project-p))
16324 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16325 (conf-alist (aget vhdl-config-alist (or project directory) t))
16326 (pack-alist (aget vhdl-package-alist (or project directory) t))
16327 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16328 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16329 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16330 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16331 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16332 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16333 (adjust-case (nth 5 regexp-list))
16334 (work-library (downcase (vhdl-work-library)))
16335 (compile-directory (expand-file-name (vhdl-compile-directory)
16336 default-directory))
16337 (makefile-name (vhdl-makefile-name))
16338 rule-alist arch-alist inst-alist
16339 target-list depend-list unit-list prim-list second-list subcomp-list
16340 lib-alist lib-body-alist pack-list all-pack-list
16341 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16342 conf-key conf-file-name pack-key pack-file-name
16343 ent-entry arch-entry conf-entry pack-entry inst-entry
16344 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16345 tmp-key tmp-list rule)
16346 ;; check prerequisites
16347 (unless (file-exists-p compile-directory)
16348 (make-directory compile-directory t))
16349 (unless regexp-list
16350 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16351 vhdl-compiler))
16352 (message "Generating makefile \"%s\"..." makefile-name)
16353 ;; rules for all entities
16354 (setq tmp-list ent-alist)
16355 (while ent-alist
16356 (setq ent-entry (car ent-alist)
16357 ent-key (nth 0 ent-entry))
16358 (when (nth 2 ent-entry)
16359 (setq ent-file-name (file-relative-name
16360 (nth 2 ent-entry) compile-directory)
16361 arch-alist (nth 4 ent-entry)
0a2e512a 16362 lib-alist (nth 6 ent-entry)
3dcb36b7
JB
16363 rule (aget rule-alist ent-file-name)
16364 target-list (nth 0 rule)
16365 depend-list (nth 1 rule)
16366 second-list nil
16367 subcomp-list nil)
16368 (setq tmp-key (vhdl-replace-string
16369 ent-regexp (funcall adjust-case ent-key)))
16370 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16371 ;; rule target for this entity
16372 (setq target-list (cons ent-key target-list))
16373 ;; rule dependencies for all used packages
16374 (setq pack-list (vhdl-get-packages lib-alist work-library))
16375 (setq depend-list (append depend-list pack-list))
16376 (setq all-pack-list pack-list)
16377 ;; add rule
16378 (aput 'rule-alist ent-file-name (list target-list depend-list))
16379 ;; rules for all corresponding architectures
16380 (while arch-alist
16381 (setq arch-entry (car arch-alist)
16382 arch-key (nth 0 arch-entry)
16383 ent-arch-key (concat ent-key "-" arch-key)
16384 arch-file-name (file-relative-name (nth 2 arch-entry)
16385 compile-directory)
16386 inst-alist (nth 4 arch-entry)
16387 lib-alist (nth 5 arch-entry)
16388 rule (aget rule-alist arch-file-name)
16389 target-list (nth 0 rule)
16390 depend-list (nth 1 rule))
16391 (setq tmp-key (vhdl-replace-string
16392 arch-regexp
16393 (funcall adjust-case (concat arch-key " " ent-key))))
16394 (setq unit-list
16395 (cons (cons ent-arch-key tmp-key) unit-list))
16396 (setq second-list (cons ent-arch-key second-list))
16397 ;; rule target for this architecture
16398 (setq target-list (cons ent-arch-key target-list))
16399 ;; rule dependency for corresponding entity
16400 (setq depend-list (cons ent-key depend-list))
16401 ;; rule dependencies for contained component instantiations
16402 (while inst-alist
16403 (setq inst-entry (car inst-alist))
16404 (when (or (null (nth 8 inst-entry))
16405 (equal (downcase (nth 8 inst-entry)) work-library))
16406 (setq inst-ent-key (or (nth 7 inst-entry)
16407 (nth 5 inst-entry)))
16408 (setq depend-list (cons inst-ent-key depend-list)
16409 subcomp-list (cons inst-ent-key subcomp-list)))
16410 (setq inst-alist (cdr inst-alist)))
16411 ;; rule dependencies for all used packages
16412 (setq pack-list (vhdl-get-packages lib-alist work-library))
16413 (setq depend-list (append depend-list pack-list))
16414 (setq all-pack-list (append all-pack-list pack-list))
16415 ;; add rule
16416 (aput 'rule-alist arch-file-name (list target-list depend-list))
16417 (setq arch-alist (cdr arch-alist)))
16418 (setq prim-list (cons (list ent-key second-list
16419 (append subcomp-list all-pack-list))
16420 prim-list)))
16421 (setq ent-alist (cdr ent-alist)))
16422 (setq ent-alist tmp-list)
16423 ;; rules for all configurations
16424 (setq tmp-list conf-alist)
16425 (while conf-alist
16426 (setq conf-entry (car conf-alist)
16427 conf-key (nth 0 conf-entry)
16428 conf-file-name (file-relative-name
16429 (nth 2 conf-entry) compile-directory)
16430 ent-key (nth 4 conf-entry)
16431 arch-key (nth 5 conf-entry)
16432 inst-alist (nth 6 conf-entry)
16433 lib-alist (nth 7 conf-entry)
16434 rule (aget rule-alist conf-file-name)
16435 target-list (nth 0 rule)
16436 depend-list (nth 1 rule)
16437 subcomp-list (list ent-key))
16438 (setq tmp-key (vhdl-replace-string
16439 conf-regexp (funcall adjust-case conf-key)))
16440 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16441 ;; rule target for this configuration
16442 (setq target-list (cons conf-key target-list))
16443 ;; rule dependency for corresponding entity and architecture
16444 (setq depend-list
16445 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16446 ;; rule dependencies for used packages
16447 (setq pack-list (vhdl-get-packages lib-alist work-library))
16448 (setq depend-list (append depend-list pack-list))
16449 ;; rule dependencies for contained component configurations
16450 (while inst-alist
16451 (setq inst-entry (car inst-alist))
16452 (setq inst-ent-key (nth 2 inst-entry)
16453; comp-arch-key (nth 2 inst-entry))
16454 inst-conf-key (nth 4 inst-entry))
16455 (when (equal (downcase (nth 5 inst-entry)) work-library)
16456 (when inst-ent-key
16457 (setq depend-list (cons inst-ent-key depend-list)
16458 subcomp-list (cons inst-ent-key subcomp-list)))
16459; (when comp-arch-key
16460; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16461; depend-list)))
16462 (when inst-conf-key
16463 (setq depend-list (cons inst-conf-key depend-list)
16464 subcomp-list (cons inst-conf-key subcomp-list))))
16465 (setq inst-alist (cdr inst-alist)))
16466 ;; add rule
16467 (aput 'rule-alist conf-file-name (list target-list depend-list))
16468 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16469 prim-list))
16470 (setq conf-alist (cdr conf-alist)))
16471 (setq conf-alist tmp-list)
16472 ;; rules for all packages
16473 (setq tmp-list pack-alist)
16474 (while pack-alist
16475 (setq pack-entry (car pack-alist)
16476 pack-key (nth 0 pack-entry)
16477 pack-body-key nil)
16478 (when (nth 2 pack-entry)
16479 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16480 compile-directory)
16481 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16482 rule (aget rule-alist pack-file-name)
16483 target-list (nth 0 rule) depend-list (nth 1 rule))
16484 (setq tmp-key (vhdl-replace-string
16485 pack-regexp (funcall adjust-case pack-key)))
16486 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16487 ;; rule target for this package
16488 (setq target-list (cons pack-key target-list))
16489 ;; rule dependencies for all used packages
16490 (setq pack-list (vhdl-get-packages lib-alist work-library))
16491 (setq depend-list (append depend-list pack-list))
16492 (setq all-pack-list pack-list)
16493 ;; add rule
16494 (aput 'rule-alist pack-file-name (list target-list depend-list))
16495 ;; rules for this package's body
16496 (when (nth 7 pack-entry)
16497 (setq pack-body-key (concat pack-key "-body")
16498 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16499 compile-directory)
16500 rule (aget rule-alist pack-body-file-name)
16501 target-list (nth 0 rule)
16502 depend-list (nth 1 rule))
16503 (setq tmp-key (vhdl-replace-string
16504 pack-body-regexp (funcall adjust-case pack-key)))
16505 (setq unit-list
16506 (cons (cons pack-body-key tmp-key) unit-list))
16507 ;; rule target for this package's body
16508 (setq target-list (cons pack-body-key target-list))
16509 ;; rule dependency for corresponding package declaration
16510 (setq depend-list (cons pack-key depend-list))
16511 ;; rule dependencies for all used packages
16512 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16513 (setq depend-list (append depend-list pack-list))
16514 (setq all-pack-list (append all-pack-list pack-list))
16515 ;; add rule
16516 (aput 'rule-alist pack-body-file-name
16517 (list target-list depend-list)))
16518 (setq prim-list
16519 (cons (list pack-key (when pack-body-key (list pack-body-key))
16520 all-pack-list)
16521 prim-list)))
16522 (setq pack-alist (cdr pack-alist)))
16523 (setq pack-alist tmp-list)
16524 ;; generate Makefile
16525 (let* ((project (aget vhdl-project-alist project))
16526 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16527 (compiler-id (nth 9 compiler))
16528 (library-directory
16529 (vhdl-resolve-env-variable
16530 (vhdl-replace-string
16531 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16532 compiler-id)))
16533 (makefile-path-name (expand-file-name
16534 makefile-name compile-directory))
16535 (orig-buffer (current-buffer))
16536 cell second-list subcomp-list options unit-key unit-name)
16537 ;; sort lists
16538 (setq unit-list (vhdl-sort-alist unit-list))
16539 (setq prim-list (vhdl-sort-alist prim-list))
16540 (setq tmp-list rule-alist)
16541 (while tmp-list ; pre-sort rule targets
16542 (setq cell (cdar tmp-list))
16543 (setcar cell (sort (car cell) 'string<))
16544 (setq tmp-list (cdr tmp-list)))
16545 (setq rule-alist ; sort by first rule target
16546 (sort rule-alist
16547 (function (lambda (a b)
16548 (string< (car (cadr a)) (car (cadr b)))))))
16549 ;; open and clear Makefile
16550 (set-buffer (find-file-noselect makefile-path-name t t))
16551 (erase-buffer)
16552 (insert "# -*- Makefile -*-\n"
16553 "### " (file-name-nondirectory makefile-name)
16554 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16555 "\n")
16556 (if project
16557 (insert "\n# Project : " (nth 0 project))
16558 (insert "\n# Directory : \"" directory "\""))
16559 (insert "\n# Platform : " vhdl-compiler
16560 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16561 (user-login-name) "\n")
16562 ;; insert compile and option variable settings
16563 (insert "\n\n# Define compilation command and options\n"
16564 "\nCOMPILE = " (nth 0 compiler)
16565 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16566 "\n")
16567 ;; insert library paths
16568 (setq library-directory
16569 (directory-file-name
16570 (if (file-name-absolute-p library-directory)
16571 library-directory
16572 (file-relative-name
16573 (expand-file-name library-directory directory)
16574 compile-directory))))
16575 (insert "\n\n# Define library paths\n"
16576 "\nLIBRARY-" work-library " = " library-directory "\n")
16577 ;; insert variable definitions for all library unit files
16578 (insert "\n\n# Define library unit files\n")
16579 (setq tmp-list unit-list)
16580 (while unit-list
16581 (insert "\nUNIT-" work-library "-" (caar unit-list)
16582 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16583 (setq unit-list (cdr unit-list)))
16584 ;; insert variable definition for list of all library unit files
16585 (insert "\n\n\n# Define list of all library unit files\n"
16586 "\nALL_UNITS =")
16587 (setq unit-list tmp-list)
16588 (while unit-list
16589 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16590 (setq unit-list (cdr unit-list)))
16591 (insert "\n")
16592 (setq unit-list tmp-list)
16593 ;; insert `make all' rule
16594 (insert "\n\n\n# Rule for compiling entire design\n"
16595 "\nall :"
16596 " \\\n\t\tlibrary"
16597 " \\\n\t\t$(ALL_UNITS)\n")
16598 ;; insert `make clean' rule
16599 (insert "\n\n# Rule for cleaning entire design\n"
16600 "\nclean : "
16601 "\n\t-rm -f $(ALL_UNITS)\n")
16602 ;; insert `make library' rule
16603 (insert "\n\n# Rule for creating library directory\n"
16604 "\nlibrary :"
16605 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16606 "\n$(LIBRARY-" work-library ") :"
16607 "\n\t"
16608 (vhdl-replace-string
16609 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16610 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16611 "\n")
16612 ;; insert rule for each library unit
16613 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16614 (while prim-list
16615 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16616 (setq subcomp-list
16617 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16618 (setq unit-key (caar prim-list)
16619 unit-name (or (nth 0 (aget ent-alist unit-key t))
16620 (nth 0 (aget conf-alist unit-key t))
16621 (nth 0 (aget pack-alist unit-key t))))
16622 (insert "\n" unit-key)
16623 (unless (equal unit-key unit-name)
16624 (insert " \\\n" unit-name))
16625 (insert " :"
16626 " \\\n\t\tlibrary"
16627 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16628 (while second-list
16629 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16630 (setq second-list (cdr second-list)))
16631 (while subcomp-list
0a2e512a
RF
16632 (when (and (assoc (car subcomp-list) unit-list)
16633 (not (equal unit-key (car subcomp-list))))
3dcb36b7
JB
16634 (insert " \\\n\t\t" (car subcomp-list)))
16635 (setq subcomp-list (cdr subcomp-list)))
16636 (insert "\n")
16637 (setq prim-list (cdr prim-list)))
16638 ;; insert rule for each library unit file
16639 (insert "\n\n# Rules for compiling single library unit files\n")
16640 (while rule-alist
16641 (setq rule (car rule-alist))
16642 ;; get compiler options for this file
16643 (setq options
16644 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16645 ;; insert rule if file is supposed to be compiled
16646 (setq target-list (nth 1 rule)
16647 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16648 ;; insert targets
16649 (setq tmp-list target-list)
16650 (while target-list
16651 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16652 (if (cdr target-list) " \\" " :"))
16653 (setq target-list (cdr target-list)))
16654 (setq target-list tmp-list)
16655 ;; insert file name as first dependency
16656 (insert " \\\n\t\t" (nth 0 rule))
16657 ;; insert dependencies (except if also target or unit does not exist)
16658 (while depend-list
16659 (when (and (not (member (car depend-list) target-list))
16660 (assoc (car depend-list) unit-list))
16661 (insert " \\\n\t\t"
16662 "$(UNIT-" work-library "-" (car depend-list) ")"))
16663 (setq depend-list (cdr depend-list)))
16664 ;; insert compile command
16665 (if options
16666 (insert "\n\t$(COMPILE) "
16667 (if (eq options 'default) "$(OPTIONS)" options) " "
16668 (nth 0 rule) "\n")
16669 (setq tmp-list target-list)
16670 (while target-list
16671 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16672 (if (cdr target-list) " \\" "\n"))
16673 (setq target-list (cdr target-list)))
16674 (setq target-list tmp-list))
16675 (setq rule-alist (cdr rule-alist)))
16676 (insert "\n\n### " makefile-name " ends here\n")
16677 ;; run Makefile generation hook
16678 (run-hooks 'vhdl-makefile-generation-hook)
16679 (message "Generating makefile \"%s\"...done" makefile-name)
16680 ;; save and close file
16681 (if (file-writable-p makefile-path-name)
16682 (progn (save-buffer)
16683 (kill-buffer (current-buffer))
16684 (set-buffer orig-buffer)
7cd80673 16685 (add-to-history 'file-name-history makefile-path-name))
3dcb36b7
JB
16686 (vhdl-warning-when-idle
16687 (format "File not writable: \"%s\""
16688 (abbreviate-file-name makefile-path-name)))
16689 (switch-to-buffer (current-buffer))))))
16690
5eabfe72
KH
16691
16692;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16693;;; Bug reports
16694;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16695;; (using `reporter.el')
16696
3dcb36b7
JB
16697(defconst vhdl-mode-help-address
16698 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16699 "Address for VHDL Mode bug reports.")
16700
3dcb36b7
JB
16701(defun vhdl-submit-bug-report ()
16702 "Submit via mail a bug report on VHDL Mode."
16703 (interactive)
16704 ;; load in reporter
16705 (and
16706 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16707 (let ((reporter-prompt-for-summary-p t))
16708 (reporter-submit-bug-report
16709 vhdl-mode-help-address
16710 (concat "VHDL Mode " vhdl-version)
16711 (list
16712 ;; report all important user options
16713 'vhdl-offsets-alist
16714 'vhdl-comment-only-line-offset
16715 'tab-width
16716 'vhdl-electric-mode
16717 'vhdl-stutter-mode
16718 'vhdl-indent-tabs-mode
16719 'vhdl-project-alist
16720 'vhdl-project
16721 'vhdl-project-file-name
16722 'vhdl-project-auto-load
16723 'vhdl-project-sort
16724 'vhdl-compiler-alist
16725 'vhdl-compiler
16726 'vhdl-compile-use-local-error-regexp
16727 'vhdl-makefile-generation-hook
16728 'vhdl-default-library
16729 'vhdl-standard
16730 'vhdl-basic-offset
16731 'vhdl-upper-case-keywords
16732 'vhdl-upper-case-types
16733 'vhdl-upper-case-attributes
16734 'vhdl-upper-case-enum-values
16735 'vhdl-upper-case-constants
16736 'vhdl-use-direct-instantiation
0a2e512a 16737 'vhdl-compose-configuration-name
3dcb36b7
JB
16738 'vhdl-entity-file-name
16739 'vhdl-architecture-file-name
0a2e512a 16740 'vhdl-configuration-file-name
3dcb36b7
JB
16741 'vhdl-package-file-name
16742 'vhdl-file-name-case
16743 'vhdl-electric-keywords
16744 'vhdl-optional-labels
16745 'vhdl-insert-empty-lines
16746 'vhdl-argument-list-indent
16747 'vhdl-association-list-with-formals
16748 'vhdl-conditions-in-parenthesis
16749 'vhdl-zero-string
16750 'vhdl-one-string
16751 'vhdl-file-header
16752 'vhdl-file-footer
16753 'vhdl-company-name
16754 'vhdl-copyright-string
16755 'vhdl-platform-spec
16756 'vhdl-date-format
16757 'vhdl-modify-date-prefix-string
16758 'vhdl-modify-date-on-saving
16759 'vhdl-reset-kind
16760 'vhdl-reset-active-high
16761 'vhdl-clock-rising-edge
16762 'vhdl-clock-edge-condition
16763 'vhdl-clock-name
16764 'vhdl-reset-name
16765 'vhdl-model-alist
16766 'vhdl-include-port-comments
16767 'vhdl-include-direction-comments
16768 'vhdl-include-type-comments
16769 'vhdl-include-group-comments
16770 'vhdl-actual-port-name
16771 'vhdl-instance-name
16772 'vhdl-testbench-entity-name
16773 'vhdl-testbench-architecture-name
16774 'vhdl-testbench-configuration-name
16775 'vhdl-testbench-dut-name
16776 'vhdl-testbench-include-header
16777 'vhdl-testbench-declarations
16778 'vhdl-testbench-statements
16779 'vhdl-testbench-initialize-signals
16780 'vhdl-testbench-include-library
16781 'vhdl-testbench-include-configuration
16782 'vhdl-testbench-create-files
0a2e512a
RF
16783 'vhdl-testbench-entity-file-name
16784 'vhdl-testbench-architecture-file-name
3dcb36b7 16785 'vhdl-compose-create-files
0a2e512a
RF
16786 'vhdl-compose-configuration-create-file
16787 'vhdl-compose-configuration-hierarchical
16788 'vhdl-compose-configuration-use-subconfiguration
3dcb36b7
JB
16789 'vhdl-compose-include-header
16790 'vhdl-compose-architecture-name
16791 'vhdl-components-package-name
16792 'vhdl-use-components-package
16793 'vhdl-self-insert-comments
16794 'vhdl-prompt-for-comments
16795 'vhdl-inline-comment-column
16796 'vhdl-end-comment-column
16797 'vhdl-auto-align
16798 'vhdl-align-groups
16799 'vhdl-align-group-separate
16800 'vhdl-align-same-indent
16801 'vhdl-highlight-keywords
16802 'vhdl-highlight-names
16803 'vhdl-highlight-special-words
16804 'vhdl-highlight-forbidden-words
16805 'vhdl-highlight-verilog-keywords
16806 'vhdl-highlight-translate-off
16807 'vhdl-highlight-case-sensitive
16808 'vhdl-special-syntax-alist
16809 'vhdl-forbidden-words
16810 'vhdl-forbidden-syntax
16811 'vhdl-directive-keywords
16812 'vhdl-speedbar-auto-open
16813 'vhdl-speedbar-display-mode
16814 'vhdl-speedbar-scan-limit
16815 'vhdl-speedbar-jump-to-unit
16816 'vhdl-speedbar-update-on-saving
16817 'vhdl-speedbar-save-cache
16818 'vhdl-speedbar-cache-file-name
16819 'vhdl-index-menu
16820 'vhdl-source-file-menu
16821 'vhdl-hideshow-menu
16822 'vhdl-hide-all-init
16823 'vhdl-print-two-column
16824 'vhdl-print-customize-faces
16825 'vhdl-intelligent-tab
16826 'vhdl-indent-syntax-based
16827 'vhdl-word-completion-case-sensitive
16828 'vhdl-word-completion-in-minibuffer
16829 'vhdl-underscore-is-part-of-word
16830 'vhdl-mode-hook)
16831 (function
16832 (lambda ()
16833 (insert
16834 (if vhdl-special-indent-hook
16835 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16836 "vhdl-special-indent-hook is set to '"
16837 (format "%s" vhdl-special-indent-hook)
16838 ".\nPerhaps this is your problem?\n"
16839 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16840 "\n"))))
16841 nil
16842 "Hi Reto,"))))
16843
16844
16845;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16846;;; Documentation
16847;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16848
16849(defconst vhdl-doc-release-notes nil
16850 "\
0a2e512a 16851Release Notes for VHDL Mode 3.33
3dcb36b7
JB
16852================================
16853
16854 - New Features
3dcb36b7 16855 - User Options
3dcb36b7
JB
16856
16857
16858New Features
16859------------
16860
0a2e512a
RF
16861CONFIGURATION DECLARATION GENERATION:
16862 - Automatic generation of a configuration declaration for a design.
16863 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
3dcb36b7
JB
16864
16865
16866User Options
16867------------
16868
0a2e512a
RF
16869`vhdl-configuration-file-name': (new)
16870 Specify how the configuration file name is obtained.
16871`vhdl-compose-configuration-name': (new)
16872 Specify how the configuration name is optained.
16873`vhdl-compose-configuration-create-file': (new)
16874 Specify whether a new file should be created for a configuration.
16875`vhdl-compose-configuration-hierarchical': (new)
16876 Specify whether hierarchical configurations should be created.
16877`vhdl-compose-configuration-use-subconfiguration': (new)
16878 Specify whether subconfigurations should be used inside configurations.
3dcb36b7
JB
16879")
16880
16881
16882(defconst vhdl-doc-keywords nil
16883 "\
16884Reserved words in VHDL
16885----------------------
16886
16887VHDL'93 (IEEE Std 1076-1993):
16888 `vhdl-93-keywords' : keywords
16889 `vhdl-93-types' : standardized types
16890 `vhdl-93-attributes' : standardized attributes
16891 `vhdl-93-enum-values' : standardized enumeration values
16892 `vhdl-93-functions' : standardized functions
16893 `vhdl-93-packages' : standardized packages and libraries
16894
16895VHDL-AMS (IEEE Std 1076.1):
16896 `vhdl-ams-keywords' : keywords
16897 `vhdl-ams-types' : standardized types
16898 `vhdl-ams-attributes' : standardized attributes
16899 `vhdl-ams-enum-values' : standardized enumeration values
16900 `vhdl-ams-functions' : standardized functions
16901
16902Math Packages (IEEE Std 1076.2):
16903 `vhdl-math-types' : standardized types
16904 `vhdl-math-constants' : standardized constants
16905 `vhdl-math-functions' : standardized functions
16906 `vhdl-math-packages' : standardized packages
16907
16908Forbidden words:
16909 `vhdl-verilog-keywords' : Verilog reserved words
16910
16911NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16912
16913
16914(defconst vhdl-doc-coding-style nil
16915 "\
16916For VHDL coding style and naming convention guidelines, see the following
16917references:
16918
16919\[1] Ben Cohen.
16920 \"VHDL Coding Styles and Methodologies\".
16921 Kluwer Academic Publishers, 1999.
16922 http://members.aol.com/vhdlcohen/vhdl/
16923
16924\[2] Michael Keating and Pierre Bricaud.
16925 \"Reuse Methodology Manual, Second Edition\".
16926 Kluwer Academic Publishers, 1999.
16927 http://www.openmore.com/openmore/rmm2.html
16928
16929\[3] European Space Agency.
16930 \"VHDL Modelling Guidelines\".
16931 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16932
16933Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16934to visually support naming conventions.")
16935
16936
d2ddb974
KH
16937(defun vhdl-version ()
16938 "Echo the current version of VHDL Mode in the minibuffer."
16939 (interactive)
3dcb36b7 16940 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16941 (vhdl-keep-region-active))
16942
3dcb36b7
JB
16943(defun vhdl-doc-variable (variable)
16944 "Display VARIABLE's documentation in *Help* buffer."
16945 (interactive)
f8246027 16946 (unless (featurep 'xemacs)
4bcb9c95 16947 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
0a2e512a
RF
16948 (with-output-to-temp-buffer
16949 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7 16950 (princ (documentation-property variable 'variable-documentation))
4bcb9c95 16951 (with-current-buffer standard-output
3dcb36b7 16952 (help-mode))
d5d105e8 16953 (help-print-return-message)))
d2ddb974 16954
3dcb36b7
JB
16955(defun vhdl-doc-mode ()
16956 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 16957 (interactive)
f8246027 16958 (unless (featurep 'xemacs)
4bcb9c95 16959 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
0a2e512a
RF
16960 (with-output-to-temp-buffer
16961 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7
JB
16962 (princ mode-name)
16963 (princ " mode:\n")
16964 (princ (documentation 'vhdl-mode))
4bcb9c95 16965 (with-current-buffer standard-output
3dcb36b7 16966 (help-mode))
d5d105e8 16967 (help-print-return-message)))
d2ddb974
KH
16968
16969
5eabfe72 16970;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16971
16972(provide 'vhdl-mode)
16973
4bcb9c95 16974;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
d2ddb974 16975;;; vhdl-mode.el ends here