Refill some long/short copyright headers.
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
CommitLineData
d2ddb974
KH
1;;; vhdl-mode.el --- major mode for editing VHDL code
2
95df8112 3;; Copyright (C) 1992-2011 Free Software Foundation, Inc.
3dcb36b7
JB
4
5;; Authors: Reto Zimmermann <reto@gnu.org>
6;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
0a2e512a 7;; Maintainer: Reto Zimmermann <reto@gnu.org>
5eabfe72 8;; Keywords: languages vhdl
c9c18440 9;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
3dcb36b7 10
241760a3
SM
11;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
12;; file on 18/3/2008, and the maintainer agreed that when a bug is
13;; filed in the Emacs bug reporting system against this file, a copy
14;; of the bug report be sent to the maintainer's email address.
15
0a2e512a 16(defconst vhdl-version "3.33.6"
3dcb36b7
JB
17 "VHDL Mode version number.")
18
0a2e512a 19(defconst vhdl-time-stamp "2005-08-30"
3dcb36b7 20 "VHDL Mode time stamp for last update.")
d2ddb974
KH
21
22;; This file is part of GNU Emacs.
23
b1fc2b50 24;; GNU Emacs is free software: you can redistribute it and/or modify
d2ddb974 25;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
26;; the Free Software Foundation, either version 3 of the License, or
27;; (at your option) any later version.
d2ddb974
KH
28
29;; GNU Emacs is distributed in the hope that it will be useful,
30;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32;; GNU General Public License for more details.
33
34;; You should have received a copy of the GNU General Public License
b1fc2b50 35;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
d2ddb974 36
5eabfe72 37;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 38;;; Commentary:
5eabfe72 39;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
40
41;; This package provides an Emacs major mode for editing VHDL code.
42;; It includes the following features:
43
3dcb36b7
JB
44;; - Syntax highlighting
45;; - Indentation
46;; - Template insertion (electrification)
47;; - Insertion of file headers
5eabfe72 48;; - Insertion of user-specified models
3dcb36b7 49;; - Port translation / testbench generation
0a2e512a
RF
50;; - Structural composition
51;; - Configuration generation
3dcb36b7
JB
52;; - Sensitivity list updating
53;; - File browser
54;; - Design hierarchy browser
d2ddb974 55;; - Source file compilation (syntax analysis)
3dcb36b7
JB
56;; - Makefile generation
57;; - Code hiding
58;; - Word/keyword completion
59;; - Block commenting
60;; - Code fixing/alignment/beautification
61;; - Postscript printing
5eabfe72 62;; - VHDL'87/'93 and VHDL-AMS supported
3dcb36b7 63;; - Comprehensive menu
5eabfe72 64;; - Fully customizable
3dcb36b7 65;; - Works under GNU Emacs (recommended) and XEmacs
5eabfe72
KH
66
67;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 68;; Documentation
d2ddb974 69
3dcb36b7 70;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
d2ddb974 71
5eabfe72 72;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 73;; Emacs Versions
3dcb36b7 74
9e5538bc 75;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
3dcb36b7
JB
76;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
77
5eabfe72 78;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
79;; Installation
80
9e5538bc 81;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
3dcb36b7
JB
82
83;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
84;; or into an arbitrary directory that is added to the load path by the
85;; following line in your Emacs start-up file `.emacs':
86
87;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
d2ddb974 88
3dcb36b7
JB
89;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
90;; directory. Otherwise, byte-compile the source file:
91;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
92;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
93
94;; Add the following lines to the `site-start.el' file in the `site-lisp'
95;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
96;; (not required in Emacs 20.X):
97
98;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
99;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
100
101;; More detailed installation instructions are included in the official
102;; VHDL Mode distribution.
d2ddb974 103
5eabfe72 104;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 105;; Acknowledgements
d2ddb974
KH
106
107;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
5eabfe72 108;; and Steve Grout.
d2ddb974 109
5eabfe72 110;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
3dcb36b7 111;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
d2ddb974
KH
112
113;; Many thanks to all the users who sent me bug reports and enhancement
3dcb36b7
JB
114;; requests.
115;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
116;; enhancement suggestions and the fruitful discussions.
5eabfe72
KH
117;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
118;; Thanks to Ulf Klaperski for the indentation speedup hint.
119
120;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
121;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
122;; giving me the opportunity to develop this code.
123;; This work has been funded in part by MICROSWISS, a Microelectronics Program
124;; of the Swiss Government.
125
3dcb36b7 126;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
127
128;;; Code:
129
9e5538bc 130;; Emacs 21+ handling
f8246027 131(defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
0a2e512a 132 "Non-nil if GNU Emacs 21, 22, ... is used.")
f8246027 133(defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
0a2e512a 134 "Non-nil if GNU Emacs 22, ... is used.")
3dcb36b7 135
354617b5 136(defvar compilation-file-regexp-alist)
84c98ace
JB
137(defvar conf-alist)
138(defvar conf-entry)
139(defvar conf-key)
140(defvar ent-alist)
354617b5
JB
141(defvar itimer-version)
142(defvar lazy-lock-defer-contextually)
143(defvar lazy-lock-defer-on-scrolling)
144(defvar lazy-lock-defer-on-the-fly)
7bf42457
JB
145(defvar speedbar-attached-frame)
146
354617b5 147
5eabfe72
KH
148;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149;;; Variables
150;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 151
3dcb36b7 152;; help function for user options
5eabfe72
KH
153(defun vhdl-custom-set (variable value &rest functions)
154 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
155 (if (fboundp 'custom-set-default)
156 (custom-set-default variable value)
157 (set-default variable value))
158 (while functions
159 (when (fboundp (car functions)) (funcall (car functions)))
160 (setq functions (cdr functions))))
161
3dcb36b7
JB
162(defun vhdl-widget-directory-validate (widget)
163 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
164'/' or is empty)."
165 (let ((val (widget-value widget)))
166 (unless (string-match "^\\(\\|.*/\\)$" val)
167 (widget-put widget :error "Invalid directory entry: must end with '/'")
168 widget)))
169
170;; help string for user options
171(defconst vhdl-name-doc-string "
172
173FROM REGEXP is a regular expression matching the original name:
174 \".*\" matches the entire string
175 \"\\(...\\)\" matches a substring
176TO STRING specifies the string to be inserted as new name:
177 \"\\&\" means substitute entire matched text
178 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
179Examples:
180 \".*\" \"\\&\" inserts original string
181 \".*\" \"\\&_i\" attaches \"_i\" to original string
182 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
183 \".*\" \"foo\" inserts constant string \"foo\"
184 \".*\" \"\" inserts empty string")
185
5eabfe72
KH
186;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187;; User variables
d2ddb974
KH
188
189(defgroup vhdl nil
190 "Customizations for VHDL Mode."
191 :prefix "vhdl-"
42dfe0ad 192 :group 'languages
0a2e512a 193; :version "21.2" ; comment out for XEmacs
5eabfe72 194 )
d2ddb974
KH
195
196(defgroup vhdl-mode nil
197 "Customizations for modes."
198 :group 'vhdl)
199
5eabfe72
KH
200(defcustom vhdl-indent-tabs-mode nil
201 "*Non-nil means indentation can insert tabs.
d2ddb974
KH
202Overrides local variable `indent-tabs-mode'."
203 :type 'boolean
204 :group 'vhdl-mode)
205
206
207(defgroup vhdl-compile nil
208 "Customizations for compilation."
209 :group 'vhdl)
210
5eabfe72
KH
211(defcustom vhdl-compiler-alist
212 '(
3dcb36b7 213 ;; Cadence Leapfrog: cv -file test.vhd
5eabfe72 214 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
3dcb36b7
JB
215 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
216 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
217 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
218 ("\\1/entity" "\\2/\\1" "\\1/configuration"
219 "\\1/package" "\\1/body" downcase))
220 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
221 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
222 ;; (PLL_400X_TOP) is not declared [10.3].
223 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
224 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
225 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
0a2e512a
RF
226 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
227 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
5eabfe72 228 ;; Ikos Voyager: analyze test.vhd
3dcb36b7 229 ;; analyze test.vhd
5eabfe72 230 ;; E L4/C5: this library unit is inaccessible
3dcb36b7
JB
231 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
232 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
233 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
234 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
235 nil)
5eabfe72
KH
236 ;; ModelSim, Model Technology: vcom test.vhd
237 ;; ERROR: test.vhd(14): Unknown identifier: positiv
238 ;; WARNING[2]: test.vhd(85): Possible infinite loop
3dcb36b7
JB
239 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
240 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
241 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
242 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
243 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
244 "\\1/_primary.dat" "\\1/body.dat" downcase))
245 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
246 ;; test.vhd:34: error message
247 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
248 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
249 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
250 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
251 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
5eabfe72
KH
252 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
253 ;; ERROR: test.vhd(24): near "dnd": expecting: END
254 ;; WARNING[4]: test.vhd(30): A space is required between ...
3dcb36b7
JB
255 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
256 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
257 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
258 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
259 "\\1/_primary.dat" "\\1/body.dat" downcase))
260 ;; Savant: scram -publish-cc test.vhd
261 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
262 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
263 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
264 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
265 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
266 "\\1_config.vhdl" "\\1_package.vhdl"
267 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
268 ;; Simili: vhdlp -work test.vhd
269 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
270 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
271 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
272 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
273 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
274 "\\1/prim.var" "\\1/_body.var" downcase))
275 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
276 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
277 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
278 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
279 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
280 nil)
281 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
5eabfe72 282 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
3dcb36b7
JB
283 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
284 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
285 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
286 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
287 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
288 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
289 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
290 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
291 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
292 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
293 ;; Synplify:
294 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
295 ("Synplify" "n/a" "n/a" "make" "-f \\1"
296 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
297 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
298 nil)
5eabfe72 299 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
300 ;; Compiling "test.vhd" line 1...
301 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
302 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
303 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
304 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
305 ("^ *Compiling \"\\(.+\\)\" " 1)
306 nil)
307 ;; VeriBest: vc vhdl test.vhd
308 ;; (no file name printed out!)
309 ;; 32: Z <= A and BitA ;
310 ;; ^^^^
311 ;; [Error] Name BITA is unknown
312 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
313 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
314 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
315 nil)
5eabfe72 316 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
317 ;; Compiling "test.vhd" line 1...
318 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
319 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
320 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
321 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
322 ("^ *Compiling \"\\(.+\\)\" " 1)
323 nil)
5eabfe72
KH
324 )
325 "*List of available VHDL compilers and their properties.
326Each list entry specifies the following items for a compiler:
327Compiler:
3dcb36b7
JB
328 Compiler name : name used in option `vhdl-compiler' to choose compiler
329 Compile command : command used for source file compilation
330 Compile options : compile options (\"\\1\" inserts library name)
331 Make command : command used for compilation using a Makefile
332 Make options : make options (\"\\1\" inserts Makefile name)
333 Generate Makefile: use built-in function or command to generate a Makefile
334 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
335 Library command : command to create library directory \(\"\\1\" inserts
336 library directory, \"\\2\" inserts library name)
337 Compile directory: where compilation is run and the Makefile is placed
338 Library directory: directory of default library
339 Makefile name : name of Makefile (default is \"Makefile\")
340 ID string : compiler identification string (see `vhdl-project-alist')
341Error message:
0a2e512a 342 Regexp : regular expression to match error messages (*)
3dcb36b7
JB
343 File subexp index: index of subexpression that matches the file name
344 Line subexp index: index of subexpression that matches the line number
345 Column subexp idx: index of subexpression that matches the column number
346File message:
5eabfe72 347 Regexp : regular expression to match a file name message
3dcb36b7
JB
348 File subexp index: index of subexpression that matches the file name
349Unit-to-file name mapping: mapping of library unit names to names of files
350 generated by the compiler (used for Makefile generation)
351 To string : string a name is mapped to (\"\\1\" inserts the unit name,
352 \"\\2\" inserts the entity name for architectures)
353 Case adjustment : adjust case of inserted unit names
354
0a2e512a 355\(*) The regular expression must match the error message starting from the
84c98ace 356 beginning of the line (but not necessarily to the end of the line).
0a2e512a 357
3dcb36b7
JB
358Compile options allows insertion of the library name (see `vhdl-project-alist')
359in order to set the compilers library option (e.g. \"vcom -work my_lib\").
360
361For Makefile generation, the built-in function can be used (requires
362specification of the unit-to-file name mapping). Alternatively, an
363external command can be specified. Work directory allows specification of
364an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
365used for Makefile generation). To use another library name than \"work\",
366customize `vhdl-project-alist'. The library command is inserted in Makefiles
367to automatically create the library directory if not existent.
368
369Compile options, compile directory, library directory, and Makefile name are
370overwritten by the project settings if a project is defined (see
371`vhdl-project-alist'). Directory paths are relative to the source file
372directory.
5eabfe72
KH
373
374Some compilers do not include the file name in the error message, but print
375out a file name message in advance. In this case, set \"File Subexp Index\"
3dcb36b7
JB
376under \"Error Message\" to 0 and fill out the \"File Message\" entries.
377If no file name at all is printed out, set both \"File Message\" entries to 0
378\(a default file name message will be printed out instead, does not work in
379XEmacs).
5eabfe72
KH
380
381A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
3dcb36b7 382assigning its name to option `vhdl-compiler'.
5eabfe72 383
3dcb36b7
JB
384Please send any missing or erroneous compiler properties to the maintainer for
385updating.
386
0a2e512a
RF
387NOTE: Activate new error and file message regexps and reflect the new setting
388 in the choice list of option `vhdl-compiler' by restarting Emacs."
3dcb36b7
JB
389 :type '(repeat
390 (list :tag "Compiler" :indent 2
391 (string :tag "Compiler name ")
392 (string :tag "Compile command ")
393 (string :tag "Compile options " "-work \\1")
394 (string :tag "Make command " "make")
395 (string :tag "Make options " "-f \\1")
396 (choice :tag "Generate Makefile "
397 (const :tag "Built-in function" nil)
398 (string :tag "Command" "vmake \\2 > \\1"))
399 (string :tag "Library command " "mkdir \\1")
400 (directory :tag "Compile directory "
401 :validate vhdl-widget-directory-validate "./")
402 (directory :tag "Library directory "
403 :validate vhdl-widget-directory-validate "work/")
404 (file :tag "Makefile name " "Makefile")
405 (string :tag "ID string ")
406 (list :tag "Error message" :indent 4
407 (regexp :tag "Regexp ")
408 (integer :tag "File subexp index")
409 (integer :tag "Line subexp index")
410 (integer :tag "Column subexp idx"))
411 (list :tag "File message" :indent 4
412 (regexp :tag "Regexp ")
413 (integer :tag "File subexp index"))
414 (choice :tag "Unit-to-file name mapping"
415 :format "%t: %[Value Menu%] %v\n"
416 (const :tag "Not defined" nil)
417 (list :tag "To string" :indent 4
418 (string :tag "Entity " "\\1.vhd")
419 (string :tag "Architecture " "\\2_\\1.vhd")
420 (string :tag "Configuration " "\\1.vhd")
421 (string :tag "Package " "\\1.vhd")
422 (string :tag "Package Body " "\\1_body.vhd")
423 (choice :tag "Case adjustment "
424 (const :tag "None" identity)
425 (const :tag "Upcase" upcase)
426 (const :tag "Downcase" downcase))))))
5eabfe72 427 :set (lambda (variable value)
0a2e512a 428 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
5eabfe72
KH
429 :group 'vhdl-compile)
430
431(defcustom vhdl-compiler "ModelSim"
432 "*Specifies the VHDL compiler to be used for syntax analysis.
3dcb36b7
JB
433Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
434 :type (let ((alist vhdl-compiler-alist) list)
435 (while alist
436 (setq list (cons (list 'const (caar alist)) list))
437 (setq alist (cdr alist)))
438 (append '(choice) (nreverse list)))
439 :group 'vhdl-compile)
440
441(defcustom vhdl-compile-use-local-error-regexp t
442 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
443In this case, only error message regexps for VHDL compilers are active if
444compilation is started from a VHDL buffer. Otherwise, the error message
445regexps are appended to the predefined global regexps, and all regexps are
446active all the time. Note that by doing that, the predefined global regexps
447might result in erroneous parsing of error messages for some VHDL compilers.
448
449NOTE: Activate the new setting by restarting Emacs."
450 :type 'boolean
d2ddb974
KH
451 :group 'vhdl-compile)
452
3dcb36b7
JB
453(defcustom vhdl-makefile-generation-hook nil
454 "*Functions to run at the end of Makefile generation.
455Allows to insert user specific parts into a Makefile.
456
457Example:
458 \(lambda nil
459 \(re-search-backward \"^# Rule for compiling entire design\")
460 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
461 :type 'hook
462 :group 'vhdl-compile)
463
464(defcustom vhdl-default-library "work"
465 "*Name of default library.
466Is overwritten by project settings if a project is active."
d2ddb974
KH
467 :type 'string
468 :group 'vhdl-compile)
469
470
3dcb36b7
JB
471(defgroup vhdl-project nil
472 "Customizations for projects."
d2ddb974
KH
473 :group 'vhdl)
474
3dcb36b7
JB
475(defcustom vhdl-project-alist
476 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
477 "~/example1/" ("src/system/" "src/components/") ""
478 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
479 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
480 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
481 ("Example 2" "Individual source files, multiple compilers in different directories"
482 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
483 nil "\\1/" "work" "\\1/work/" "Makefile" "")
484 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
485 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
486 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
487-------------------------------------------------------------------------------
488-- This is a multi-line project description
489-- that can be used as a project dependent part of the file header.
490"))
491 "*List of projects and their properties.
492 Name : name used in option `vhdl-project' to choose project
493 Title : title of project (single-line string)
494 Default directory: default project directory (absolute path)
495 Sources : a) source files : path + \"/\" + file name
496 b) directory : path + \"/\"
497 c) directory tree: \"-r \" + path + \"/\"
498 Exclude regexp : matches file/directory names to be excluded as sources
499 Compile options : project-specific options for each compiler
500 Compiler name : name of compiler for which these options are valid
501 Compile options: project-specific compiler options
502 (\"\\1\" inserts library name, \"\\2\" default options)
503 Make options: project-specific make options
504 (\"\\1\" inserts Makefile name, \"\\2\" default options)
505 Exceptions : file-specific exceptions
506 File name regexp: matches file names for which exceptions are valid
507 - Options : file-specific compiler options string
508 (\"\\1\" inserts library name, \"\\2\" default options,
509 \"\\3\" project-specific options)
510 - Do not compile: do not compile this file (in Makefile)
511 Compile directory: where compilation is run and the Makefile is placed
512 \(\"\\1\" inserts compiler ID string)
513 Library name : name of library (default is \"work\")
514 Library directory: path to library (\"\\1\" inserts compiler ID string)
515 Makefile name : name of Makefile
516 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
517 Description : description of project (multi-line string)
518
519Project title and description are used to insert into the file header (see
520option `vhdl-file-header').
521
522The default directory must have an absolute path (use `M-TAB' for completion).
523All other paths can be absolute or relative to the default directory. All
524paths must end with '/'.
525
526The design units found in the sources (files and directories) are shown in the
527hierarchy browser. Path and file name can contain wildcards `*' and `?' as
528well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
529Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
530specified, the default directory is taken as source directory. Otherwise,
531the default directory is only taken as source directory if there is a sources
532entry with the empty string or \"./\". Exclude regexp allows to filter out
533specific file and directory names from the list of sources (e.g. CVS
534directories).
535
536Files are compiled in the compile directory. Makefiles are also placed into
537the compile directory. Library directory specifies which directory the
538compiler compiles into (used to generate the Makefile).
539
540Since different compile/library directories and Makefiles may exist for
541different compilers within one project, these paths and names allow the
542insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
543Compile options, compile directory, library directory, and Makefile name
544overwrite the settings of the current compiler.
545
546File-specific compiler options (highest priority) overwrite project-specific
547options which overwrite default options (lowest priority). Lower priority
548options can be inserted in higher priority options. This allows to reuse
549default options (e.g. \"-file\") in project- or file-specific options (e.g.
550\"-93 -file\").
551
552NOTE: Reflect the new setting in the choice list of option `vhdl-project'
553 by restarting Emacs."
554 :type `(repeat
555 (list :tag "Project" :indent 2
556 (string :tag "Name ")
557 (string :tag "Title ")
558 (directory :tag "Default directory"
559 :validate vhdl-widget-directory-validate
560 ,(abbreviate-file-name default-directory))
561 (repeat :tag "Sources " :indent 4
562 (directory :format " %v" "./"))
563 (regexp :tag "Exclude regexp ")
564 (repeat
565 :tag "Compile options " :indent 4
566 (list :tag "Compiler" :indent 6
567 ,(let ((alist vhdl-compiler-alist) list)
568 (while alist
569 (setq list (cons (list 'const (caar alist)) list))
570 (setq alist (cdr alist)))
571 (append '(choice :tag "Compiler name")
572 (nreverse list)))
573 (string :tag "Compile options" "\\2")
574 (string :tag "Make options " "\\2")
575 (repeat
576 :tag "Exceptions " :indent 8
577 (cons :format "%v"
578 (regexp :tag "File name regexp ")
579 (choice :format "%[Value Menu%] %v"
580 (string :tag "Options" "\\3")
581 (const :tag "Do not compile" nil))))))
582 (directory :tag "Compile directory"
583 :validate vhdl-widget-directory-validate "./")
584 (string :tag "Library name " "work")
585 (directory :tag "Library directory"
586 :validate vhdl-widget-directory-validate "work/")
587 (file :tag "Makefile name " "Makefile")
588 (string :tag "Description: (type `C-j' for newline)"
589 :format "%t\n%v\n")))
590 :set (lambda (variable value)
0a2e512a 591 (vhdl-custom-set variable value
3dcb36b7
JB
592 'vhdl-update-mode-menu
593 'vhdl-speedbar-refresh))
594 :group 'vhdl-project)
595
596(defcustom vhdl-project nil
597 "*Specifies the default for the current project.
598Select a project name from the ones defined in option `vhdl-project-alist'.
599Is used to determine the project title and description to be inserted in file
600headers and the source files/directories to be scanned in the hierarchy
601browser. The current project can also be changed temporarily in the menu."
602 :type (let ((alist vhdl-project-alist) list)
603 (while alist
604 (setq list (cons (list 'const (caar alist)) list))
605 (setq alist (cdr alist)))
606 (append '(choice (const :tag "None" nil) (const :tag "--"))
607 (nreverse list)))
608 :group 'vhdl-project)
609
610(defcustom vhdl-project-file-name '("\\1.prj")
611 "*List of file names/paths for importing/exporting project setups.
612\"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
613replaced by the user name (allows to have user-specific project setups).
614The first entry is used as file name to import/export individual project
615setups. All entries are used to automatically import project setups at
616startup (see option `vhdl-project-auto-load'). Projects loaded from the
617first entry are automatically made current. Hint: specify local project
618setups in first entry, global setups in following entries; loading a local
619project setup will make it current, while loading the global setups
620is done without changing the current project.
621Names can also have an absolute path (i.e. project setups can be stored
622in global directories)."
623 :type '(repeat (string :tag "File name" "\\1.prj"))
624 :group 'vhdl-project)
625
626(defcustom vhdl-project-auto-load '(startup)
627 "*Automatically load project setups from files.
628All project setup files that match the file names specified in option
629`vhdl-project-file-name' are automatically loaded. The project of the
630\(alphabetically) last loaded setup of the first `vhdl-project-file-name'
631entry is activated.
632A project setup file can be obtained by exporting a project (see menu).
633 At startup: project setup file is loaded at Emacs startup"
634 :type '(set (const :tag "At startup" startup))
635 :group 'vhdl-project)
636
637(defcustom vhdl-project-sort t
638 "*Non-nil means projects are displayed in alphabetical order."
639 :type 'boolean
640 :group 'vhdl-project)
641
642
643(defgroup vhdl-style nil
644 "Customizations for coding styles."
645 :group 'vhdl
646 :group 'vhdl-template
647 :group 'vhdl-port
648 :group 'vhdl-compose)
649
5eabfe72
KH
650(defcustom vhdl-standard '(87 nil)
651 "*VHDL standards used.
652Basic standard:
653 VHDL'87 : IEEE Std 1076-1987
654 VHDL'93 : IEEE Std 1076-1993
655Additional standards:
656 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
3dcb36b7 657 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
5eabfe72 658
3dcb36b7
JB
659NOTE: Activate the new setting in a VHDL buffer by using the menu entry
660 \"Activate Options\"."
5eabfe72
KH
661 :type '(list (choice :tag "Basic standard"
662 (const :tag "VHDL'87" 87)
663 (const :tag "VHDL'93" 93))
664 (set :tag "Additional standards" :indent 2
665 (const :tag "VHDL-AMS" ams)
3dcb36b7 666 (const :tag "Math packages" math)))
5eabfe72 667 :set (lambda (variable value)
0a2e512a 668 (vhdl-custom-set variable value
5eabfe72
KH
669 'vhdl-template-map-init
670 'vhdl-mode-abbrev-table-init
671 'vhdl-template-construct-alist-init
672 'vhdl-template-package-alist-init
673 'vhdl-update-mode-menu
674 'vhdl-words-init 'vhdl-font-lock-init))
675 :group 'vhdl-style)
676
677(defcustom vhdl-basic-offset 2
d2ddb974
KH
678 "*Amount of basic offset used for indentation.
679This value is used by + and - symbols in `vhdl-offsets-alist'."
680 :type 'integer
681 :group 'vhdl-style)
682
d2ddb974 683(defcustom vhdl-upper-case-keywords nil
5eabfe72
KH
684 "*Non-nil means convert keywords to upper case.
685This is done when typed or expanded or by the fix case functions."
d2ddb974 686 :type 'boolean
5eabfe72 687 :set (lambda (variable value)
0a2e512a 688 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 689 :group 'vhdl-style)
d2ddb974
KH
690
691(defcustom vhdl-upper-case-types nil
5eabfe72
KH
692 "*Non-nil means convert standardized types to upper case.
693This is done when expanded or by the fix case functions."
d2ddb974 694 :type 'boolean
5eabfe72 695 :set (lambda (variable value)
0a2e512a 696 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 697 :group 'vhdl-style)
d2ddb974
KH
698
699(defcustom vhdl-upper-case-attributes nil
5eabfe72
KH
700 "*Non-nil means convert standardized attributes to upper case.
701This is done when expanded or by the fix case functions."
d2ddb974 702 :type 'boolean
5eabfe72 703 :set (lambda (variable value)
0a2e512a 704 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 705 :group 'vhdl-style)
d2ddb974
KH
706
707(defcustom vhdl-upper-case-enum-values nil
5eabfe72
KH
708 "*Non-nil means convert standardized enumeration values to upper case.
709This is done when expanded or by the fix case functions."
d2ddb974 710 :type 'boolean
5eabfe72 711 :set (lambda (variable value)
0a2e512a 712 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72
KH
713 :group 'vhdl-style)
714
715(defcustom vhdl-upper-case-constants t
716 "*Non-nil means convert standardized constants to upper case.
717This is done when expanded."
718 :type 'boolean
719 :set (lambda (variable value)
0a2e512a 720 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 721 :group 'vhdl-style)
d2ddb974 722
3dcb36b7
JB
723(defcustom vhdl-use-direct-instantiation 'standard
724 "*Non-nil means use VHDL'93 direct component instantiation.
725 Never : never
726 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
727 Always : always"
728 :type '(choice (const :tag "Never" never)
729 (const :tag "Standard" standard)
730 (const :tag "Always" always))
731 :group 'vhdl-style)
732
733
734(defgroup vhdl-naming nil
735 "Customizations for naming conventions."
736 :group 'vhdl)
737
738(defcustom vhdl-entity-file-name '(".*" . "\\&")
739 (concat
740 "*Specifies how the entity file name is obtained.
741The entity file name can be obtained by modifying the entity name (e.g.
742attaching or stripping off a substring). The file extension is automatically
743taken from the file name of the current buffer."
744 vhdl-name-doc-string)
745 :type '(cons (regexp :tag "From regexp")
746 (string :tag "To string "))
747 :group 'vhdl-naming
748 :group 'vhdl-compose)
d2ddb974 749
3dcb36b7
JB
750(defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
751 (concat
752 "*Specifies how the architecture file name is obtained.
753The architecture file name can be obtained by modifying the entity
754and/or architecture name (e.g. attaching or stripping off a substring). The
0a2e512a
RF
755file extension is automatically taken from the file name of the current
756buffer. The string that is matched against the regexp is the concatenation
757of the entity and the architecture name separated by a space. This gives
758access to both names (see default setting as example)."
759 vhdl-name-doc-string)
760 :type '(cons (regexp :tag "From regexp")
761 (string :tag "To string "))
762 :group 'vhdl-naming
763 :group 'vhdl-compose)
764
765(defcustom vhdl-configuration-file-name '(".*" . "\\&")
766 (concat
767 "*Specifies how the configuration file name is obtained.
768The configuration file name can be obtained by modifying the configuration
769name (e.g. attaching or stripping off a substring). The file extension is
770automatically taken from the file name of the current buffer."
3dcb36b7
JB
771 vhdl-name-doc-string)
772 :type '(cons (regexp :tag "From regexp")
773 (string :tag "To string "))
774 :group 'vhdl-naming
775 :group 'vhdl-compose)
776
777(defcustom vhdl-package-file-name '(".*" . "\\&")
778 (concat
779 "*Specifies how the package file name is obtained.
780The package file name can be obtained by modifying the package name (e.g.
781attaching or stripping off a substring). The file extension is automatically
0a2e512a
RF
782taken from the file name of the current buffer. Package files can be created
783in a different directory by prepending a relative or absolute path to the
784file name."
3dcb36b7
JB
785 vhdl-name-doc-string)
786 :type '(cons (regexp :tag "From regexp")
787 (string :tag "To string "))
788 :group 'vhdl-naming
789 :group 'vhdl-compose)
790
791(defcustom vhdl-file-name-case 'identity
792 "*Specifies how to change case for obtaining file names.
793When deriving a file name from a VHDL unit name, case can be changed as
794follows:
795 As Is: case is not changed (taken as is)
796 Lower Case: whole name is changed to lower case
797 Upper Case: whole name is changed to upper case
798 Capitalize: first letter of each word in name is capitalized"
799 :type '(choice (const :tag "As Is" identity)
800 (const :tag "Lower Case" downcase)
801 (const :tag "Upper Case" upcase)
802 (const :tag "Capitalize" capitalize))
803 :group 'vhdl-naming
804 :group 'vhdl-compose)
805
806
807(defgroup vhdl-template nil
5eabfe72 808 "Customizations for electrification."
d2ddb974
KH
809 :group 'vhdl)
810
5eabfe72
KH
811(defcustom vhdl-electric-keywords '(vhdl user)
812 "*Type of keywords for which electrification is enabled.
813 VHDL keywords: invoke built-in templates
3dcb36b7 814 User keywords: invoke user models (see option `vhdl-model-alist')"
5eabfe72 815 :type '(set (const :tag "VHDL keywords" vhdl)
3dcb36b7 816 (const :tag "User model keywords" user))
5eabfe72 817 :set (lambda (variable value)
0a2e512a 818 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
3dcb36b7 819 :group 'vhdl-template)
5eabfe72
KH
820
821(defcustom vhdl-optional-labels 'process
822 "*Constructs for which labels are to be queried.
823Template generators prompt for optional labels for:
824 None : no constructs
825 Processes only: processes only (also procedurals in VHDL-AMS)
826 All constructs: all constructs with optional labels and keyword END"
827 :type '(choice (const :tag "None" none)
828 (const :tag "Processes only" process)
829 (const :tag "All constructs" all))
3dcb36b7 830 :group 'vhdl-template)
d2ddb974 831
5eabfe72
KH
832(defcustom vhdl-insert-empty-lines 'unit
833 "*Specifies whether to insert empty lines in some templates.
834This improves readability of code. Empty lines are inserted in:
835 None : no constructs
836 Design units only: entities, architectures, configurations, packages only
837 All constructs : also all constructs with BEGIN...END parts
838
3dcb36b7 839Replaces option `vhdl-additional-empty-lines'."
5eabfe72
KH
840 :type '(choice (const :tag "None" none)
841 (const :tag "Design units only" unit)
842 (const :tag "All constructs" all))
3dcb36b7
JB
843 :group 'vhdl-template
844 :group 'vhdl-port
845 :group 'vhdl-compose)
5eabfe72
KH
846
847(defcustom vhdl-argument-list-indent nil
848 "*Non-nil means indent argument lists relative to opening parenthesis.
849That is, argument, association, and port lists start on the same line as the
850opening parenthesis and subsequent lines are indented accordingly.
851Otherwise, lists start on a new line and are indented as normal code."
d2ddb974 852 :type 'boolean
3dcb36b7
JB
853 :group 'vhdl-template
854 :group 'vhdl-port
855 :group 'vhdl-compose)
d2ddb974 856
5eabfe72
KH
857(defcustom vhdl-association-list-with-formals t
858 "*Non-nil means write association lists with formal parameters.
3dcb36b7
JB
859Templates prompt for formal and actual parameters (ports/generics).
860When pasting component instantiations, formals are included.
5eabfe72 861If nil, only a list of actual parameters is entered."
d2ddb974 862 :type 'boolean
3dcb36b7
JB
863 :group 'vhdl-template
864 :group 'vhdl-port
865 :group 'vhdl-compose)
d2ddb974
KH
866
867(defcustom vhdl-conditions-in-parenthesis nil
5eabfe72 868 "*Non-nil means place parenthesis around condition expressions."
d2ddb974 869 :type 'boolean
3dcb36b7 870 :group 'vhdl-template)
d2ddb974 871
5eabfe72
KH
872(defcustom vhdl-zero-string "'0'"
873 "*String to use for a logic zero."
874 :type 'string
3dcb36b7 875 :group 'vhdl-template)
5eabfe72
KH
876
877(defcustom vhdl-one-string "'1'"
878 "*String to use for a logic one."
879 :type 'string
3dcb36b7 880 :group 'vhdl-template)
5eabfe72
KH
881
882
883(defgroup vhdl-header nil
884 "Customizations for file header."
3dcb36b7
JB
885 :group 'vhdl-template
886 :group 'vhdl-compose)
d2ddb974 887
5eabfe72
KH
888(defcustom vhdl-file-header "\
889-------------------------------------------------------------------------------
890-- Title : <title string>
891-- Project : <project>
892-------------------------------------------------------------------------------
893-- File : <filename>
894-- Author : <author>
895-- Company : <company>
3dcb36b7 896-- Created : <date>
5eabfe72
KH
897-- Last update: <date>
898-- Platform : <platform>
3dcb36b7 899-- Standard : <standard>
5eabfe72
KH
900<projectdesc>-------------------------------------------------------------------------------
901-- Description: <cursor>
3dcb36b7 902<copyright>-------------------------------------------------------------------------------
5eabfe72
KH
903-- Revisions :
904-- Date Version Author Description
905-- <date> 1.0 <login>\tCreated
906-------------------------------------------------------------------------------
907
908"
909 "*String or file to insert as file header.
910If the string specifies an existing file name, the contents of the file is
911inserted, otherwise the string itself is inserted as file header.
912Type `C-j' for newlines.
d2ddb974
KH
913If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
914if the header needs to be version controlled.
915
916The following keywords for template generation are supported:
3dcb36b7
JB
917 <filename> : replaced by the name of the buffer
918 <author> : replaced by the user name and email address
8fc29035 919 \(`user-full-name', `mail-host-address', `user-mail-address')
3dcb36b7
JB
920 <login> : replaced by user login name (`user-login-name')
921 <company> : replaced by contents of option `vhdl-company-name'
922 <date> : replaced by the current date
923 <year> : replaced by the current year
924 <project> : replaced by title of current project (`vhdl-project')
925 <projectdesc> : replaced by description of current project (`vhdl-project')
926 <copyright> : replaced by copyright string (`vhdl-copyright-string')
927 <platform> : replaced by contents of option `vhdl-platform-spec'
928 <standard> : replaced by the VHDL language standard(s) used
929 <... string> : replaced by a queried string (\"...\" is the prompt word)
930 <title string>: replaced by file title in automatically generated files
931 <cursor> : final cursor position
d2ddb974 932
5eabfe72
KH
933The (multi-line) project description <projectdesc> can be used as a project
934dependent part of the file header and can also contain the above keywords."
935 :type 'string
936 :group 'vhdl-header)
937
938(defcustom vhdl-file-footer ""
939 "*String or file to insert as file footer.
940If the string specifies an existing file name, the contents of the file is
941inserted, otherwise the string itself is inserted as file footer (i.e. at
942the end of the file).
3dcb36b7
JB
943Type `C-j' for newlines.
944The same keywords as in option `vhdl-file-header' can be used."
5eabfe72
KH
945 :type 'string
946 :group 'vhdl-header)
947
948(defcustom vhdl-company-name ""
3dcb36b7
JB
949 "*Name of company to insert in file header.
950See option `vhdl-file-header'."
951 :type 'string
952 :group 'vhdl-header)
953
954(defcustom vhdl-copyright-string "\
955-------------------------------------------------------------------------------
956-- Copyright (c) <year> <company>
957"
958 "*Copyright string to insert in file header.
959Can be multi-line string (type `C-j' for newline) and contain other file
960header keywords (see option `vhdl-file-header')."
5eabfe72
KH
961 :type 'string
962 :group 'vhdl-header)
963
964(defcustom vhdl-platform-spec ""
965 "*Specification of VHDL platform to insert in file header.
966The platform specification should contain names and versions of the
3dcb36b7
JB
967simulation and synthesis tools used.
968See option `vhdl-file-header'."
5eabfe72
KH
969 :type 'string
970 :group 'vhdl-header)
971
3dcb36b7 972(defcustom vhdl-date-format "%Y-%m-%d"
5eabfe72
KH
973 "*Specifies the date format to use in the header.
974This string is passed as argument to the command `format-time-string'.
975For more information on format strings, see the documentation for the
976`format-time-string' command (C-h f `format-time-string')."
977 :type 'string
978 :group 'vhdl-header)
d2ddb974 979
5eabfe72 980(defcustom vhdl-modify-date-prefix-string "-- Last update: "
d2ddb974 981 "*Prefix string of modification date in VHDL file header.
5eabfe72
KH
982If actualization of the modification date is called (menu,
983`\\[vhdl-template-modify]'), this string is searched and the rest
984of the line replaced by the current date."
d2ddb974 985 :type 'string
5eabfe72
KH
986 :group 'vhdl-header)
987
988(defcustom vhdl-modify-date-on-saving t
989 "*Non-nil means update the modification date when the buffer is saved.
990Calls function `\\[vhdl-template-modify]').
991
3dcb36b7
JB
992NOTE: Activate the new setting in a VHDL buffer by using the menu entry
993 \"Activate Options\"."
5eabfe72
KH
994 :type 'boolean
995 :group 'vhdl-header)
996
997
998(defgroup vhdl-sequential-process nil
999 "Customizations for sequential processes."
3dcb36b7 1000 :group 'vhdl-template)
d2ddb974 1001
5eabfe72
KH
1002(defcustom vhdl-reset-kind 'async
1003 "*Specifies which kind of reset to use in sequential processes."
1004 :type '(choice (const :tag "None" none)
1005 (const :tag "Synchronous" sync)
1006 (const :tag "Asynchronous" async))
1007 :group 'vhdl-sequential-process)
1008
1009(defcustom vhdl-reset-active-high nil
1010 "*Non-nil means reset in sequential processes is active high.
0404f77e 1011Otherwise, reset is active low."
5eabfe72
KH
1012 :type 'boolean
1013 :group 'vhdl-sequential-process)
1014
1015(defcustom vhdl-clock-rising-edge t
1016 "*Non-nil means rising edge of clock triggers sequential processes.
0404f77e 1017Otherwise, falling edge triggers."
5eabfe72
KH
1018 :type 'boolean
1019 :group 'vhdl-sequential-process)
1020
1021(defcustom vhdl-clock-edge-condition 'standard
1022 "*Syntax of the clock edge condition.
1023 Standard: \"clk'event and clk = '1'\"
1024 Function: \"rising_edge(clk)\""
1025 :type '(choice (const :tag "Standard" standard)
1026 (const :tag "Function" function))
1027 :group 'vhdl-sequential-process)
1028
1029(defcustom vhdl-clock-name ""
1030 "*Name of clock signal to use in templates."
d2ddb974 1031 :type 'string
5eabfe72 1032 :group 'vhdl-sequential-process)
d2ddb974 1033
5eabfe72
KH
1034(defcustom vhdl-reset-name ""
1035 "*Name of reset signal to use in templates."
d2ddb974 1036 :type 'string
5eabfe72
KH
1037 :group 'vhdl-sequential-process)
1038
1039
1040(defgroup vhdl-model nil
1041 "Customizations for user models."
1042 :group 'vhdl)
1043
1044(defcustom vhdl-model-alist
3dcb36b7 1045 '(("Example Model"
5eabfe72
KH
1046 "<label> : process (<clock>, <reset>)
1047begin -- process <label>
1048 if <reset> = '0' then -- asynchronous reset (active low)
1049 <cursor>
1050 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1051 if <enable> = '1' then -- synchronous load
84c98ace 1052
5eabfe72
KH
1053 end if;
1054 end if;
1055end process <label>;"
1056 "e" ""))
1057 "*List of user models.
1058VHDL models (templates) can be specified by the user in this list. They can be
1059invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1060electrification (i.e. overriding existing or creating new keywords, see
3dcb36b7 1061option `vhdl-electric-keywords').
5eabfe72
KH
1062 Name : name of model (string of words and spaces)
1063 String : string or name of file to be inserted as model (newline: `C-j')
1064 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1065 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1066 Keyword : keyword to invoke model
1067
1068The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1069A prompt that appears several times is queried once and replaced throughout
1070the model. Special prompts are:
1071 <clock> : name specified in `vhdl-clock-name' (if not empty)
1072 <reset> : name specified in `vhdl-reset-name' (if not empty)
1073 <cursor>: final cursor position
3dcb36b7
JB
1074File header prompts (see variable `vhdl-file-header') are automatically
1075replaced, so that user models can also be used to insert different types of
1076headers.
5eabfe72
KH
1077
1078If the string specifies an existing file name, the contents of the file is
1079inserted, otherwise the string itself is inserted.
1080The code within the models should be correctly indented.
1081Type `C-j' for newlines.
1082
3dcb36b7
JB
1083NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1084 \"Activate Options\"."
5eabfe72
KH
1085 :type '(repeat (list :tag "Model" :indent 2
1086 (string :tag "Name ")
1087 (string :tag "String : (type `C-j' for newline)"
1088 :format "%t\n%v")
3dcb36b7
JB
1089 (sexp :tag "Key binding" x)
1090 (string :tag "Keyword " :format "%t: %v\n")))
5eabfe72 1091 :set (lambda (variable value)
0a2e512a 1092 (vhdl-custom-set variable value
5eabfe72
KH
1093 'vhdl-model-map-init
1094 'vhdl-model-defun
1095 'vhdl-mode-abbrev-table-init
1096 'vhdl-update-mode-menu))
1097 :group 'vhdl-model)
1098
3dcb36b7 1099
0a2e512a
RF
1100(defgroup vhdl-compose nil
1101 "Customizations for structural composition."
1102 :group 'vhdl)
1103
1104(defcustom vhdl-compose-architecture-name '(".*" . "str")
1105 (concat
1106 "*Specifies how the component architecture name is obtained.
1107The component architecture name can be obtained by modifying the entity name
1108\(e.g. attaching or stripping off a substring).
1109If TO STRING is empty, the architecture name is queried."
1110 vhdl-name-doc-string)
1111 :type '(cons (regexp :tag "From regexp")
1112 (string :tag "To string "))
1113 :group 'vhdl-compose)
1114
1115(defcustom vhdl-compose-configuration-name
1116 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1117 (concat
1118 "*Specifies how the configuration name is obtained.
1119The configuration name can be obtained by modifying the entity and/or
1120architecture name (e.g. attaching or stripping off a substring). The string
1121that is matched against the regexp is the concatenation of the entity and the
1122architecture name separated by a space. This gives access to both names (see
1123default setting as example)."
1124 vhdl-name-doc-string)
1125 :type '(cons (regexp :tag "From regexp")
1126 (string :tag "To string "))
1127 :group 'vhdl-compose)
1128
1129(defcustom vhdl-components-package-name
1130 '((".*" . "\\&_components") . "components")
1131 (concat
1132 "*Specifies how the name for the components package is obtained.
1133The components package is a package containing all component declarations for
a4c6cfad 1134the current design. Its name can be obtained by modifying the project name
0a2e512a
RF
1135\(e.g. attaching or stripping off a substring). If no project is defined, the
1136DIRECTORY entry is chosen."
1137 vhdl-name-doc-string)
1138 :type '(cons (cons :tag "Project" :indent 2
1139 (regexp :tag "From regexp")
1140 (string :tag "To string "))
1141 (string :tag "Directory:\n String "))
1142 :group 'vhdl-compose)
1143
1144(defcustom vhdl-use-components-package nil
1145 "*Non-nil means use a separate components package for component declarations.
1146Otherwise, component declarations are inserted and searched for in the
1147architecture declarative parts."
1148 :type 'boolean
1149 :group 'vhdl-compose)
1150
1151(defcustom vhdl-compose-include-header t
1152 "*Non-nil means include a header in automatically generated files."
1153 :type 'boolean
1154 :group 'vhdl-compose)
1155
1156(defcustom vhdl-compose-create-files 'single
1157 "*Specifies whether new files should be created for the new component.
1158The component's entity and architecture are inserted:
1159 None : in current buffer
1160 Single file : in new single file
1161 Separate files: in two separate files
1162The file names are obtained from variables `vhdl-entity-file-name' and
1163`vhdl-architecture-file-name'."
1164 :type '(choice (const :tag "None" none)
1165 (const :tag "Single file" single)
1166 (const :tag "Separate files" separate))
1167 :group 'vhdl-compose)
1168
1169(defcustom vhdl-compose-configuration-create-file nil
1170 "*Specifies whether a new file should be created for the configuration.
1171If non-nil, a new file is created for the configuration.
1172The file name is obtained from variable `vhdl-configuration-file-name'."
1173 :type 'boolean
1174 :group 'vhdl-compose)
1175
1176(defcustom vhdl-compose-configuration-hierarchical t
1177 "*Specifies whether hierarchical configurations should be created.
1178If non-nil, automatically created configurations are hierarchical and include
1179the whole hierarchy of subcomponents. Otherwise the configuration only
1180includes one level of subcomponents."
1181 :type 'boolean
1182 :group 'vhdl-compose)
1183
1184(defcustom vhdl-compose-configuration-use-subconfiguration t
1185 "*Specifies whether subconfigurations should be used inside configurations.
1186If non-nil, automatically created configurations use configurations in binding
1187indications for subcomponents, if such configurations exist. Otherwise,
1188entities are used in binding indications for subcomponents."
1189 :type 'boolean
1190 :group 'vhdl-compose)
1191
1192
5eabfe72 1193(defgroup vhdl-port nil
3dcb36b7
JB
1194 "Customizations for port translation functions."
1195 :group 'vhdl
1196 :group 'vhdl-compose)
5eabfe72
KH
1197
1198(defcustom vhdl-include-port-comments nil
1199 "*Non-nil means include port comments when a port is pasted."
1200 :type 'boolean
1201 :group 'vhdl-port)
1202
1203(defcustom vhdl-include-direction-comments nil
3dcb36b7 1204 "*Non-nil means include port direction in instantiations as comments."
5eabfe72
KH
1205 :type 'boolean
1206 :group 'vhdl-port)
1207
3dcb36b7
JB
1208(defcustom vhdl-include-type-comments nil
1209 "*Non-nil means include generic/port type in instantiations as comments."
1210 :type 'boolean
1211 :group 'vhdl-port)
5eabfe72 1212
3dcb36b7
JB
1213(defcustom vhdl-include-group-comments 'never
1214 "*Specifies whether to include group comments and spacings.
1215The comments and empty lines between groups of ports are pasted:
1216 Never : never
1217 Declarations: in entity/component/constant/signal declarations only
1218 Always : also in generic/port maps"
1219 :type '(choice (const :tag "Never" never)
1220 (const :tag "Declarations" decl)
1221 (const :tag "Always" always))
1222 :group 'vhdl-port)
5eabfe72 1223
3dcb36b7 1224(defcustom vhdl-actual-port-name '(".*" . "\\&")
5eabfe72
KH
1225 (concat
1226 "*Specifies how actual port names are obtained from formal port names.
1227In a component instantiation, an actual port name can be obtained by
1228modifying the formal port name (e.g. attaching or stripping off a substring)."
1229 vhdl-name-doc-string)
3dcb36b7
JB
1230 :type '(cons (regexp :tag "From regexp")
1231 (string :tag "To string "))
5eabfe72
KH
1232 :group 'vhdl-port)
1233
3dcb36b7 1234(defcustom vhdl-instance-name '(".*" . "\\&_%d")
5eabfe72
KH
1235 (concat
1236 "*Specifies how an instance name is obtained.
1237The instance name can be obtained by modifying the name of the component to be
3dcb36b7
JB
1238instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1239by a unique number (starting with 1).
5eabfe72
KH
1240If TO STRING is empty, the instance name is queried."
1241 vhdl-name-doc-string)
3dcb36b7
JB
1242 :type '(cons (regexp :tag "From regexp")
1243 (string :tag "To string "))
1244 :group 'vhdl-port)
1245
1246
1247(defgroup vhdl-testbench nil
bc25429a 1248 "Customizations for testbench generation."
5eabfe72
KH
1249 :group 'vhdl-port)
1250
1251(defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1252 (concat
3dcb36b7
JB
1253 "*Specifies how the testbench entity name is obtained.
1254The entity name of a testbench can be obtained by modifying the name of
5eabfe72
KH
1255the component to be tested (e.g. attaching or stripping off a substring)."
1256 vhdl-name-doc-string)
3dcb36b7
JB
1257 :type '(cons (regexp :tag "From regexp")
1258 (string :tag "To string "))
1259 :group 'vhdl-testbench)
5eabfe72
KH
1260
1261(defcustom vhdl-testbench-architecture-name '(".*" . "")
1262 (concat
3dcb36b7
JB
1263 "*Specifies how the testbench architecture name is obtained.
1264The testbench architecture name can be obtained by modifying the name of
5eabfe72
KH
1265the component to be tested (e.g. attaching or stripping off a substring).
1266If TO STRING is empty, the architecture name is queried."
1267 vhdl-name-doc-string)
3dcb36b7
JB
1268 :type '(cons (regexp :tag "From regexp")
1269 (string :tag "To string "))
1270 :group 'vhdl-testbench)
1271
0a2e512a 1272(defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
3dcb36b7
JB
1273 (concat
1274 "*Specifies how the testbench configuration name is obtained.
1275The configuration name of a testbench can be obtained by modifying the entity
1276and/or architecture name (e.g. attaching or stripping off a substring). The
1277string that is matched against the regexp is the concatenation of the entity
1278and the architecture name separated by a space. This gives access to both
1279names (see default setting as example)."
1280 vhdl-name-doc-string)
1281 :type '(cons (regexp :tag "From regexp")
1282 (string :tag "To string "))
1283 :group 'vhdl-testbench)
5eabfe72
KH
1284
1285(defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1286 (concat
1287 "*Specifies how a DUT instance name is obtained.
1288The design-under-test instance name (i.e. the component instantiated in the
3dcb36b7 1289testbench) can be obtained by modifying the component name (e.g. attaching
5eabfe72
KH
1290or stripping off a substring)."
1291 vhdl-name-doc-string)
3dcb36b7
JB
1292 :type '(cons (regexp :tag "From regexp")
1293 (string :tag "To string "))
1294 :group 'vhdl-testbench)
5eabfe72 1295
3dcb36b7
JB
1296(defcustom vhdl-testbench-include-header t
1297 "*Non-nil means include a header in automatically generated files."
1298 :type 'boolean
1299 :group 'vhdl-testbench)
5eabfe72 1300
3dcb36b7
JB
1301(defcustom vhdl-testbench-declarations "\
1302 -- clock
1303 signal Clk : std_logic := '1';
1304"
1305 "*String or file to be inserted in the testbench declarative part.
5eabfe72 1306If the string specifies an existing file name, the contents of the file is
3dcb36b7 1307inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1308architecture before the BEGIN keyword.
1309Type `C-j' for newlines."
1310 :type 'string
3dcb36b7
JB
1311 :group 'vhdl-testbench)
1312
1313(defcustom vhdl-testbench-statements "\
1314 -- clock generation
1315 Clk <= not Clk after 10 ns;
5eabfe72 1316
3dcb36b7
JB
1317 -- waveform generation
1318 WaveGen_Proc: process
1319 begin
1320 -- insert signal assignments here
84c98ace 1321
3dcb36b7
JB
1322 wait until Clk = '1';
1323 end process WaveGen_Proc;
1324"
1325 "*String or file to be inserted in the testbench statement part.
5eabfe72 1326If the string specifies an existing file name, the contents of the file is
3dcb36b7 1327inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1328architecture before the END keyword.
1329Type `C-j' for newlines."
1330 :type 'string
3dcb36b7 1331 :group 'vhdl-testbench)
5eabfe72
KH
1332
1333(defcustom vhdl-testbench-initialize-signals nil
3dcb36b7 1334 "*Non-nil means initialize signals with `0' when declared in testbench."
5eabfe72 1335 :type 'boolean
3dcb36b7
JB
1336 :group 'vhdl-testbench)
1337
1338(defcustom vhdl-testbench-include-library t
1339 "*Non-nil means a library/use clause for std_logic_1164 is included."
1340 :type 'boolean
1341 :group 'vhdl-testbench)
1342
1343(defcustom vhdl-testbench-include-configuration t
1344 "*Non-nil means a testbench configuration is attached at the end."
1345 :type 'boolean
1346 :group 'vhdl-testbench)
5eabfe72
KH
1347
1348(defcustom vhdl-testbench-create-files 'single
3dcb36b7
JB
1349 "*Specifies whether new files should be created for the testbench.
1350testbench entity and architecture are inserted:
5eabfe72
KH
1351 None : in current buffer
1352 Single file : in new single file
1353 Separate files: in two separate files
0a2e512a
RF
1354The file names are obtained from variables `vhdl-testbench-entity-file-name'
1355and `vhdl-testbench-architecture-file-name'."
5eabfe72
KH
1356 :type '(choice (const :tag "None" none)
1357 (const :tag "Single file" single)
1358 (const :tag "Separate files" separate))
3dcb36b7
JB
1359 :group 'vhdl-testbench)
1360
0a2e512a 1361(defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
3dcb36b7 1362 (concat
0a2e512a
RF
1363 "*Specifies how the testbench entity file name is obtained.
1364The entity file name can be obtained by modifying the testbench entity name
1365\(e.g. attaching or stripping off a substring). The file extension is
1366automatically taken from the file name of the current buffer. Testbench
1367files can be created in a different directory by prepending a relative or
1368absolute path to the file name."
3dcb36b7
JB
1369 vhdl-name-doc-string)
1370 :type '(cons (regexp :tag "From regexp")
1371 (string :tag "To string "))
0a2e512a 1372 :group 'vhdl-testbench)
3dcb36b7 1373
0a2e512a 1374(defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
3dcb36b7 1375 (concat
0a2e512a
RF
1376 "*Specifies how the testbench architecture file name is obtained.
1377The architecture file name can be obtained by modifying the testbench entity
1378and/or architecture name (e.g. attaching or stripping off a substring). The
1379string that is matched against the regexp is the concatenation of the entity
1380and the architecture name separated by a space. This gives access to both
1381names (see default setting as example). Testbench files can be created in
1382a different directory by prepending a relative or absolute path to the file
1383name."
3dcb36b7 1384 vhdl-name-doc-string)
0a2e512a
RF
1385 :type '(cons (regexp :tag "From regexp")
1386 (string :tag "To string "))
1387 :group 'vhdl-testbench)
d2ddb974
KH
1388
1389
1390(defgroup vhdl-comment nil
1391 "Customizations for comments."
5eabfe72 1392 :group 'vhdl)
d2ddb974
KH
1393
1394(defcustom vhdl-self-insert-comments t
5eabfe72 1395 "*Non-nil means various templates automatically insert help comments."
d2ddb974
KH
1396 :type 'boolean
1397 :group 'vhdl-comment)
1398
1399(defcustom vhdl-prompt-for-comments t
5eabfe72 1400 "*Non-nil means various templates prompt for user definable comments."
d2ddb974
KH
1401 :type 'boolean
1402 :group 'vhdl-comment)
1403
5eabfe72 1404(defcustom vhdl-inline-comment-column 40
3dcb36b7
JB
1405 "*Column to indent and align inline comments to.
1406Overrides local option `comment-column'.
5eabfe72 1407
3dcb36b7
JB
1408NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1409 \"Activate Options\"."
d2ddb974
KH
1410 :type 'integer
1411 :group 'vhdl-comment)
1412
1413(defcustom vhdl-end-comment-column 79
5eabfe72
KH
1414 "*End of comment column.
1415Comments that exceed this column number are wrapped.
1416
3dcb36b7
JB
1417NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1418 \"Activate Options\"."
d2ddb974
KH
1419 :type 'integer
1420 :group 'vhdl-comment)
1421
5eabfe72 1422(defvar end-comment-column)
d2ddb974
KH
1423
1424
5eabfe72
KH
1425(defgroup vhdl-align nil
1426 "Customizations for alignment."
d2ddb974
KH
1427 :group 'vhdl)
1428
5eabfe72
KH
1429(defcustom vhdl-auto-align t
1430 "*Non-nil means align some templates automatically after generation."
d2ddb974 1431 :type 'boolean
5eabfe72
KH
1432 :group 'vhdl-align)
1433
1434(defcustom vhdl-align-groups t
1435 "*Non-nil means align groups of code lines separately.
3dcb36b7
JB
1436A group of code lines is a region of consecutive lines between two lines that
1437match the regexp in option `vhdl-align-group-separate'."
1438 :type 'boolean
1439 :group 'vhdl-align)
1440
1441(defcustom vhdl-align-group-separate "^\\s-*$"
1442 "*Regexp for matching a line that separates groups of lines for alignment.
1443Examples:
1444 \"^\\s-*$\": matches an empty line
1445 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1446 :type 'regexp
1447 :group 'vhdl-align)
1448
1449(defcustom vhdl-align-same-indent t
1450 "*Non-nil means align blocks with same indent separately.
1451When a region or the entire buffer is aligned, the code is divided into
1452blocks of same indent which are aligned separately (except for argument/port
1453lists). This gives nicer alignment in most cases.
1454Option `vhdl-align-groups' still applies within these blocks."
5eabfe72
KH
1455 :type 'boolean
1456 :group 'vhdl-align)
1457
1458
1459(defgroup vhdl-highlight nil
1460 "Customizations for highlighting."
1461 :group 'vhdl)
d2ddb974
KH
1462
1463(defcustom vhdl-highlight-keywords t
5eabfe72
KH
1464 "*Non-nil means highlight VHDL keywords and other standardized words.
1465The following faces are used:
0a2e512a
RF
1466 `font-lock-keyword-face' : keywords
1467 `font-lock-type-face' : standardized types
1468 `vhdl-font-lock-attribute-face': standardized attributes
1469 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1470 `vhdl-font-lock-function-face' : standardized function and package names
5eabfe72
KH
1471
1472NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1473 entry \"Fontify Buffer\")."
d2ddb974 1474 :type 'boolean
5eabfe72 1475 :set (lambda (variable value)
0a2e512a 1476 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1477 :group 'vhdl-highlight)
1478
5eabfe72
KH
1479(defcustom vhdl-highlight-names t
1480 "*Non-nil means highlight declaration names and construct labels.
1481The following faces are used:
3dcb36b7 1482 `font-lock-function-name-face' : names in declarations of units,
5eabfe72 1483 subprograms, components, as well as labels of VHDL constructs
3dcb36b7 1484 `font-lock-type-face' : names in type/nature declarations
0a2e512a 1485 `vhdl-font-lock-attribute-face': names in attribute declarations
3dcb36b7 1486 `font-lock-variable-name-face' : names in declarations of signals,
5eabfe72
KH
1487 variables, constants, subprogram parameters, generics, and ports
1488
1489NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1490 entry \"Fontify Buffer\")."
d2ddb974 1491 :type 'boolean
5eabfe72 1492 :set (lambda (variable value)
0a2e512a 1493 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1494 :group 'vhdl-highlight)
1495
5eabfe72
KH
1496(defcustom vhdl-highlight-special-words nil
1497 "*Non-nil means highlight words with special syntax.
3dcb36b7
JB
1498The words with syntax and color specified in option `vhdl-special-syntax-alist'
1499are highlighted accordingly.
5eabfe72
KH
1500Can be used for visual support of naming conventions.
1501
1502NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1503 entry \"Fontify Buffer\")."
d2ddb974 1504 :type 'boolean
5eabfe72 1505 :set (lambda (variable value)
0a2e512a 1506 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1507 :group 'vhdl-highlight)
1508
5eabfe72
KH
1509(defcustom vhdl-highlight-forbidden-words nil
1510 "*Non-nil means highlight forbidden words.
3dcb36b7
JB
1511The reserved words specified in option `vhdl-forbidden-words' or having the
1512syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
0a2e512a 1513warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
5eabfe72
KH
1514use them.
1515
1516NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1517 entry \"Fontify Buffer\")."
d2ddb974 1518 :type 'boolean
5eabfe72 1519 :set (lambda (variable value)
0a2e512a 1520 (vhdl-custom-set variable value
5eabfe72 1521 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1522 :group 'vhdl-highlight)
1523
5eabfe72
KH
1524(defcustom vhdl-highlight-verilog-keywords nil
1525 "*Non-nil means highlight Verilog keywords as reserved words.
1526Verilog keywords are highlighted in a warning color (face
0a2e512a 1527`vhdl-font-lock-reserved-words-face') to indicate not to use them.
2f402702 1528
5eabfe72 1529NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1530 entry \"Fontify Buffer\")."
d2ddb974 1531 :type 'boolean
5eabfe72 1532 :set (lambda (variable value)
0a2e512a 1533 (vhdl-custom-set variable value
5eabfe72 1534 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1535 :group 'vhdl-highlight)
1536
5eabfe72
KH
1537(defcustom vhdl-highlight-translate-off nil
1538 "*Non-nil means background-highlight code excluded from translation.
1539That is, all code between \"-- pragma translate_off\" and
1540\"-- pragma translate_on\" is highlighted using a different background color
0a2e512a 1541\(face `vhdl-font-lock-translate-off-face').
5eabfe72 1542Note: this might slow down on-the-fly fontification (and thus editing).
d2ddb974 1543
5eabfe72 1544NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1545 entry \"Fontify Buffer\")."
5eabfe72
KH
1546 :type 'boolean
1547 :set (lambda (variable value)
0a2e512a 1548 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1549 :group 'vhdl-highlight)
1550
5eabfe72
KH
1551(defcustom vhdl-highlight-case-sensitive nil
1552 "*Non-nil means consider case for highlighting.
1553Possible trade-off:
1554 non-nil also upper-case VHDL words are highlighted, but case of words with
1555 special syntax is not considered
1556 nil only lower-case VHDL words are highlighted, but case of words with
1557 special syntax is considered
3dcb36b7 1558Overrides local option `font-lock-keywords-case-fold-search'.
5eabfe72
KH
1559
1560NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1561 entry \"Fontify Buffer\")."
5eabfe72
KH
1562 :type 'boolean
1563 :group 'vhdl-highlight)
d2ddb974 1564
3dcb36b7
JB
1565(defcustom vhdl-special-syntax-alist
1566 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1567 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1568 ("variable" "\\w+_v" "Grey50" "Grey80"))
5eabfe72 1569 "*List of special syntax to be highlighted.
3dcb36b7 1570If option `vhdl-highlight-special-words' is non-nil, words with the specified
5eabfe72
KH
1571syntax (as regular expression) are highlighted in the corresponding color.
1572
1573 Name : string of words and spaces
1574 Regexp : regular expression describing word syntax
1575 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1576 Color (light): foreground color for light background
1577 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1578 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1579 Color (dark) : foreground color for dark background
1580 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1581 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1582
1583Can be used for visual support of naming conventions, such as highlighting
3dcb36b7 1584different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
5eabfe72 1585\"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
3dcb36b7 1586common substrings or name suffices.
5eabfe72 1587For each entry, a new face is generated with the specified colors and name
0a2e512a 1588\"vhdl-font-lock-\" + name + \"-face\".
5eabfe72
KH
1589
1590NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1591 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
5eabfe72
KH
1592 :type '(repeat (list :tag "Face" :indent 2
1593 (string :tag "Name ")
1594 (regexp :tag "Regexp " "\\w+_")
1595 (string :tag "Color (light)")
1596 (string :tag "Color (dark) ")))
1597 :set (lambda (variable value)
0a2e512a 1598 (vhdl-custom-set variable value 'vhdl-font-lock-init))
5eabfe72 1599 :group 'vhdl-highlight)
d2ddb974 1600
5eabfe72
KH
1601(defcustom vhdl-forbidden-words '()
1602 "*List of forbidden words to be highlighted.
3dcb36b7 1603If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
5eabfe72
KH
1604words are highlighted in a warning color to indicate not to use them.
1605
1606NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1607 entry \"Fontify Buffer\")."
5eabfe72
KH
1608 :type '(repeat (string :format "%v"))
1609 :set (lambda (variable value)
0a2e512a 1610 (vhdl-custom-set variable value
5eabfe72
KH
1611 'vhdl-words-init 'vhdl-font-lock-init))
1612 :group 'vhdl-highlight)
d2ddb974 1613
5eabfe72
KH
1614(defcustom vhdl-forbidden-syntax ""
1615 "*Syntax of forbidden words to be highlighted.
3dcb36b7 1616If option `vhdl-highlight-forbidden-words' is non-nil, words with this
5eabfe72
KH
1617syntax are highlighted in a warning color to indicate not to use them.
1618Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1619highlights identifiers with 10 or more characters).
d2ddb974 1620
5eabfe72 1621NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1622 entry \"Fontify Buffer\")."
d2ddb974 1623 :type 'regexp
5eabfe72 1624 :set (lambda (variable value)
0a2e512a 1625 (vhdl-custom-set variable value
5eabfe72
KH
1626 'vhdl-words-init 'vhdl-font-lock-init))
1627 :group 'vhdl-highlight)
d2ddb974 1628
3dcb36b7
JB
1629(defcustom vhdl-directive-keywords '("pragma" "synopsys")
1630 "*List of compiler directive keywords recognized for highlighting.
d2ddb974 1631
3dcb36b7
JB
1632NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1633 entry \"Fontify Buffer\")."
1634 :type '(repeat (string :format "%v"))
1635 :set (lambda (variable value)
1636 (vhdl-custom-set variable value
1637 'vhdl-words-init 'vhdl-font-lock-init))
1638 :group 'vhdl-highlight)
1639
1640
1641(defgroup vhdl-speedbar nil
1642 "Customizations for speedbar."
d2ddb974
KH
1643 :group 'vhdl)
1644
3dcb36b7
JB
1645(defcustom vhdl-speedbar-auto-open nil
1646 "*Non-nil means automatically open speedbar at startup.
5eabfe72 1647Alternatively, the speedbar can be opened from the VHDL menu."
d2ddb974 1648 :type 'boolean
3dcb36b7
JB
1649 :group 'vhdl-speedbar)
1650
1651(defcustom vhdl-speedbar-display-mode 'files
1652 "*Specifies the default displaying mode when opening speedbar.
1653Alternatively, the displaying mode can be selected from the speedbar menu or
1654by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1655 :type '(choice (const :tag "Files" files)
1656 (const :tag "Directory hierarchy" directory)
1657 (const :tag "Project hierarchy" project))
1658 :group 'vhdl-speedbar)
1659
1660(defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1661 "*Limits scanning of large files and netlists.
1662Design units: maximum file size to scan for design units
1663Hierarchy (instances of subcomponents):
1664 File size: maximum file size to scan for instances (in bytes)
1665 Instances per arch: maximum number of instances to scan per architecture
1666
1667\"None\" always means that there is no limit.
1668In case of files not or incompletely scanned, a warning message and the file
1669names are printed out.
1670Background: scanning for instances is considerably slower than scanning for
1671design units, especially when there are many instances. These limits should
1672prevent the scanning of large netlists."
1673 :type '(list (choice :tag "Design units"
1674 :format "%t : %[Value Menu%] %v"
1675 (const :tag "None" nil)
1676 (integer :tag "File size"))
1677 (list :tag "Hierarchy" :indent 2
1678 (choice :tag "File size"
1679 :format "%t : %[Value Menu%] %v"
1680 (const :tag "None" nil)
1681 (integer :tag "Size "))
1682 (choice :tag "Instances per arch"
1683 (const :tag "None" nil)
1684 (integer :tag "Number "))))
1685 :group 'vhdl-speedbar)
1686
1687(defcustom vhdl-speedbar-jump-to-unit t
1688 "*Non-nil means jump to the design unit code when opened in a buffer.
1689The buffer cursor position is left unchanged otherwise."
1690 :type 'boolean
1691 :group 'vhdl-speedbar)
d2ddb974 1692
3dcb36b7
JB
1693(defcustom vhdl-speedbar-update-on-saving t
1694 "*Automatically update design hierarchy when buffer is saved."
d2ddb974 1695 :type 'boolean
3dcb36b7
JB
1696 :group 'vhdl-speedbar)
1697
1698(defcustom vhdl-speedbar-save-cache '(hierarchy display)
1699 "*Automatically save modified hierarchy caches when exiting Emacs.
1700 Hierarchy: design hierarchy information
1701 Display: displaying information (which design units to expand)"
1702 :type '(set (const :tag "Hierarchy" hierarchy)
1703 (const :tag "Display" display))
1704 :group 'vhdl-speedbar)
1705
1706(defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1707 "*Name of file for saving hierarchy cache.
1708\"\\1\" is replaced by the project name if a project is specified,
1709\"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1710different users to have cache files in the same directory). Can also have
1711an absolute path (i.e. all caches can be stored in one global directory)."
1712 :type 'string
1713 :group 'vhdl-speedbar)
d2ddb974 1714
3dcb36b7
JB
1715
1716(defgroup vhdl-menu nil
1717 "Customizations for menues."
1718 :group 'vhdl)
5eabfe72
KH
1719
1720(defcustom vhdl-index-menu nil
1721 "*Non-nil means add an index menu for a source file when loading.
1722Alternatively, the speedbar can be used. Note that the index menu scans a file
3dcb36b7 1723when it is opened, while speedbar only scans the file upon request."
5eabfe72
KH
1724 :type 'boolean
1725 :group 'vhdl-menu)
1726
1727(defcustom vhdl-source-file-menu nil
1728 "*Non-nil means add a menu of all source files in current directory.
1729Alternatively, the speedbar can be used."
1730 :type 'boolean
1731 :group 'vhdl-menu)
1732
1733(defcustom vhdl-hideshow-menu nil
3dcb36b7
JB
1734 "*Non-nil means add hideshow menu and functionality at startup.
1735Hideshow can also be enabled from the VHDL Mode menu.
1736Hideshow allows hiding code of various VHDL constructs.
5eabfe72 1737
3dcb36b7
JB
1738NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1739 \"Activate Options\"."
5eabfe72
KH
1740 :type 'boolean
1741 :group 'vhdl-menu)
1742
1743(defcustom vhdl-hide-all-init nil
1744 "*Non-nil means hide all design units initially after a file is loaded."
d2ddb974
KH
1745 :type 'boolean
1746 :group 'vhdl-menu)
1747
1748
1749(defgroup vhdl-print nil
1750 "Customizations for printing."
1751 :group 'vhdl)
1752
1753(defcustom vhdl-print-two-column t
5eabfe72 1754 "*Non-nil means print code in two columns and landscape format.
3dcb36b7
JB
1755Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1756prints VHDL files in a nice two-column landscape style.
5eabfe72
KH
1757
1758NOTE: Activate the new setting by restarting Emacs.
1759 Overrides `ps-print' settings locally."
1760 :type 'boolean
1761 :group 'vhdl-print)
1762
1763(defcustom vhdl-print-customize-faces t
1764 "*Non-nil means use an optimized set of faces for postscript printing.
1765
1766NOTE: Activate the new setting by restarting Emacs.
1767 Overrides `ps-print' settings locally."
d2ddb974
KH
1768 :type 'boolean
1769 :group 'vhdl-print)
1770
1771
1772(defgroup vhdl-misc nil
1773 "Miscellaneous customizations."
1774 :group 'vhdl)
1775
1776(defcustom vhdl-intelligent-tab t
5eabfe72 1777 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
d2ddb974
KH
1778That is, if preceeding character is part of a word then complete word,
1779else if not at beginning of line then insert tab,
1780else if last command was a `TAB' or `RET' then dedent one step,
5eabfe72 1781else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
d2ddb974 1782If nil, TAB always indents current line (i.e. `TAB' is bound to
3dcb36b7
JB
1783`indent-according-to-mode').
1784
1785NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1786 \"Activate Options\"."
1787 :type 'boolean
1788 :group 'vhdl-misc)
5eabfe72 1789
3dcb36b7
JB
1790(defcustom vhdl-indent-syntax-based t
1791 "*Non-nil means indent lines of code based on their syntactic context.
1792Otherwise, a line is indented like the previous nonblank line. This can be
1793useful in large files where syntax-based indentation gets very slow."
d2ddb974
KH
1794 :type 'boolean
1795 :group 'vhdl-misc)
1796
5eabfe72
KH
1797(defcustom vhdl-word-completion-case-sensitive nil
1798 "*Non-nil means word completion using `TAB' is case sensitive.
1799That is, `TAB' completes words that start with the same letters and case.
1800Otherwise, case is ignored."
1801 :type 'boolean
d2ddb974
KH
1802 :group 'vhdl-misc)
1803
1804(defcustom vhdl-word-completion-in-minibuffer t
5eabfe72
KH
1805 "*Non-nil enables word completion in minibuffer (for template prompts).
1806
1807NOTE: Activate the new setting by restarting Emacs."
d2ddb974
KH
1808 :type 'boolean
1809 :group 'vhdl-misc)
1810
1811(defcustom vhdl-underscore-is-part-of-word nil
5eabfe72 1812 "*Non-nil means consider the underscore character `_' as part of word.
d2ddb974 1813An identifier containing underscores is then treated as a single word in
5eabfe72
KH
1814select and move operations. All parts of an identifier separated by underscore
1815are treated as single words otherwise.
1816
3dcb36b7
JB
1817NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1818 \"Activate Options\"."
d2ddb974 1819 :type 'boolean
5eabfe72 1820 :set (lambda (variable value)
0a2e512a 1821 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
d2ddb974
KH
1822 :group 'vhdl-misc)
1823
3dcb36b7
JB
1824
1825(defgroup vhdl-related nil
5eabfe72
KH
1826 "Related general customizations."
1827 :group 'vhdl)
1828
3dcb36b7
JB
1829;; add related general customizations
1830(custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
f8246027 1831(if (featurep 'xemacs)
3dcb36b7
JB
1832 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1833 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1834(custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1835(custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1836(custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
f8246027 1837(unless (featurep 'xemacs)
3dcb36b7
JB
1838 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1839(custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1840(custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1841(custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1842
5eabfe72
KH
1843;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1844;; Internal variables
1845
3dcb36b7
JB
1846(defvar vhdl-menu-max-size 20
1847 "*Specifies the maximum size of a menu before splitting it into submenues.")
5eabfe72
KH
1848
1849(defvar vhdl-progress-interval 1
1850 "*Interval used to update progress status during long operations.
1851If a number, percentage complete gets updated after each interval of
3dcb36b7 1852that many seconds. To inhibit all messages, set this option to nil.")
d2ddb974
KH
1853
1854(defvar vhdl-inhibit-startup-warnings-p nil
1855 "*If non-nil, inhibits start up compatibility warnings.")
1856
1857(defvar vhdl-strict-syntax-p nil
1858 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1859If the syntactic symbol for a particular line does not match a symbol
1860in the offsets alist, an error is generated, otherwise no error is
1861reported and the syntactic symbol is ignored.")
1862
1863(defvar vhdl-echo-syntactic-information-p nil
1864 "*If non-nil, syntactic info is echoed when the line is indented.")
1865
1866(defconst vhdl-offsets-alist-default
0a2e512a
RF
1867 '((string . -1000)
1868 (cpp-macro . -1000)
1869 (block-open . 0)
1870 (block-close . 0)
1871 (statement . 0)
1872 (statement-cont . vhdl-lineup-statement-cont)
d2ddb974
KH
1873 (statement-block-intro . +)
1874 (statement-case-intro . +)
0a2e512a
RF
1875 (case-alternative . +)
1876 (comment . vhdl-lineup-comment)
1877 (arglist-intro . +)
1878 (arglist-cont . 0)
d2ddb974 1879 (arglist-cont-nonempty . vhdl-lineup-arglist)
0a2e512a
RF
1880 (arglist-close . vhdl-lineup-arglist)
1881 (entity . 0)
1882 (configuration . 0)
1883 (package . 0)
1884 (architecture . 0)
1885 (package-body . 0)
d2ddb974
KH
1886 )
1887 "Default settings for offsets of syntactic elements.
1888Do not change this constant! See the variable `vhdl-offsets-alist' for
1889more information.")
1890
1891(defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1892 "*Association list of syntactic element symbols and indentation offsets.
1893As described below, each cons cell in this list has the form:
1894
1895 (SYNTACTIC-SYMBOL . OFFSET)
1896
5eabfe72 1897When a line is indented, `vhdl-mode' first determines the syntactic
d2ddb974
KH
1898context of the line by generating a list of symbols called syntactic
1899elements. This list can contain more than one syntactic element and
1900the global variable `vhdl-syntactic-context' contains the context list
1901for the line being indented. Each element in this list is actually a
1902cons cell of the syntactic symbol and a buffer position. This buffer
1903position is call the relative indent point for the line. Some
1904syntactic symbols may not have a relative indent point associated with
1905them.
1906
5eabfe72 1907After the syntactic context list for a line is generated, `vhdl-mode'
d2ddb974
KH
1908calculates the absolute indentation for the line by looking at each
1909syntactic element in the list. First, it compares the syntactic
1910element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1911finds a match, it adds the OFFSET to the column of the relative indent
1912point. The sum of this calculation for each element in the syntactic
1913list is the absolute offset for line being indented.
1914
1915If the syntactic element does not match any in the `vhdl-offsets-alist',
1916an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1917the element is ignored.
1918
1919Actually, OFFSET can be an integer, a function, a variable, or one of
1920the following symbols: `+', `-', `++', or `--'. These latter
1921designate positive or negative multiples of `vhdl-basic-offset',
5eabfe72 1922respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
d2ddb974
KH
1923called with a single argument containing the cons of the syntactic
1924element symbol and the relative indent point. The function should
1925return an integer offset.
1926
1927Here is the current list of valid syntactic element symbols:
1928
1929 string -- inside multi-line string
1930 block-open -- statement block open
1931 block-close -- statement block close
1932 statement -- a VHDL statement
1933 statement-cont -- a continuation of a VHDL statement
1934 statement-block-intro -- the first line in a new statement block
1935 statement-case-intro -- the first line in a case alternative block
1936 case-alternative -- a case statement alternative clause
1937 comment -- a line containing only a comment
1938 arglist-intro -- the first line in an argument list
1939 arglist-cont -- subsequent argument list lines when no
1940 arguments follow on the same line as the
1941 the arglist opening paren
1942 arglist-cont-nonempty -- subsequent argument list lines when at
1943 least one argument follows on the same
1944 line as the arglist opening paren
1945 arglist-close -- the solo close paren of an argument list
1946 entity -- inside an entity declaration
1947 configuration -- inside a configuration declaration
1948 package -- inside a package declaration
1949 architecture -- inside an architecture body
5eabfe72 1950 package-body -- inside a package body")
d2ddb974
KH
1951
1952(defvar vhdl-comment-only-line-offset 0
1953 "*Extra offset for line which contains only the start of a comment.
1954Can contain an integer or a cons cell of the form:
1955
1956 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1957
1958Where NON-ANCHORED-OFFSET is the amount of offset given to
1959non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1960the amount of offset to give column-zero anchored comment-only lines.
1961Just an integer as value is equivalent to (<val> . 0)")
1962
1963(defvar vhdl-special-indent-hook nil
1964 "*Hook for user defined special indentation adjustments.
1965This hook gets called after a line is indented by the mode.")
1966
1967(defvar vhdl-style-alist
1968 '(("IEEE"
1969 (vhdl-basic-offset . 4)
3dcb36b7 1970 (vhdl-offsets-alist . ())))
d2ddb974
KH
1971 "Styles of Indentation.
1972Elements of this alist are of the form:
1973
1974 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1975
1976where STYLE-STRING is a short descriptive string used to select a
5eabfe72 1977style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
d2ddb974
KH
1978value for that variable when using the selected style.
1979
1980There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1981case, the VALUE is a list containing elements of the form:
1982
1983 (SYNTACTIC-SYMBOL . VALUE)
1984
1985as described in `vhdl-offsets-alist'. These are passed directly to
1986`vhdl-set-offset' so there is no need to set every syntactic symbol in
1987your style, only those that are different from the default.")
1988
1989;; dynamically append the default value of most variables
1990(or (assoc "Default" vhdl-style-alist)
1991 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1992 vhdl-strict-syntax-p
1993 vhdl-echo-syntactic-information-p
1994 vhdl-basic-offset
1995 vhdl-offsets-alist
1996 vhdl-comment-only-line-offset))
1997 (default (cons "Default"
1998 (mapcar
1999 (function
2000 (lambda (var)
5eabfe72 2001 (cons var (symbol-value var))))
d2ddb974
KH
2002 varlist))))
2003 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2004
2005(defvar vhdl-mode-hook nil
2006 "*Hook called by `vhdl-mode'.")
2007
2008
5eabfe72 2009;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2010;;; Required packages
5eabfe72 2011;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5eabfe72 2012
3dcb36b7 2013;; mandatory
5eabfe72 2014(require 'assoc)
3dcb36b7
JB
2015(require 'compile) ; XEmacs
2016(require 'easymenu)
2017(require 'hippie-exp)
2018
2019;; optional (minimize warning messages during compile)
2020(eval-when-compile
2021 (require 'font-lock)
2022 (require 'ps-print)
2023 (require 'speedbar))
5eabfe72
KH
2024
2025
2026;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2027;;; Compatibility
5eabfe72 2028;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 2029
3dcb36b7
JB
2030;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2031;; XEmacs compatibility
d2ddb974 2032
3dcb36b7 2033;; active regions
d2ddb974 2034(defun vhdl-keep-region-active ()
5eabfe72
KH
2035 "Do whatever is necessary to keep the region active in XEmacs.
2036Ignore byte-compiler warnings you might see."
a445370f 2037 (and (featurep 'xemacs)
d2ddb974
KH
2038 (setq zmacs-region-stays t)))
2039
3dcb36b7 2040;; `wildcard-to-regexp' is included only in XEmacs 21
5eabfe72
KH
2041(unless (fboundp 'wildcard-to-regexp)
2042 (defun wildcard-to-regexp (wildcard)
2043 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2044 (let* ((i (string-match "[*?]" wildcard))
2045 (result (substring wildcard 0 i))
2046 (len (length wildcard)))
2047 (when i
2048 (while (< i len)
2049 (let ((ch (aref wildcard i)))
2050 (setq result (concat result
2051 (cond ((eq ch ?*) "[^\000]*")
2052 ((eq ch ??) "[^\000]")
2053 (t (char-to-string ch)))))
2054 (setq i (1+ i)))))
2055 (concat "\\`" result "\\'"))))
2056
3dcb36b7
JB
2057;; `regexp-opt' undefined (`xemacs-devel' not installed)
2058;; `regexp-opt' accelerates fontification by 10-20%
2059(unless (fboundp 'regexp-opt)
2060; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2061 (defun regexp-opt (strings &optional paren)
2062 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2063 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2064
2065;; `match-string-no-properties' undefined (XEmacs, what else?)
2066(unless (fboundp 'match-string-no-properties)
2067 (defalias 'match-string-no-properties 'match-string))
2068
2069;; `subst-char-in-string' undefined (XEmacs)
2070(unless (fboundp 'subst-char-in-string)
2071 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2072 (let ((i (length string))
2073 (newstr (if inplace string (copy-sequence string))))
2074 (while (> i 0)
2075 (setq i (1- i))
2076 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2077 newstr)))
2078
2079;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
f8246027 2080(when (and (featurep 'xemacs) (string< itimer-version "1.09")
3dcb36b7
JB
2081 (not noninteractive))
2082 (load "itimer")
2083 (when (string< itimer-version "1.09")
2084 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2085 (beep) (sit-for 5)))
2086
2087;; `file-expand-wildcards' undefined (XEmacs)
2088(unless (fboundp 'file-expand-wildcards)
2089 (defun file-expand-wildcards (pattern &optional full)
2090 "Taken from Emacs' `files.el'."
2091 (let* ((nondir (file-name-nondirectory pattern))
2092 (dirpart (file-name-directory pattern))
2093 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2094 (mapcar 'file-name-as-directory
2095 (file-expand-wildcards (directory-file-name dirpart)))
2096 (list dirpart)))
2097 contents)
2098 (while dirs
2099 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2100 (file-directory-p (directory-file-name (car dirs))))
2101 (let ((this-dir-contents
2102 (delq nil
2103 (mapcar #'(lambda (name)
2104 (unless (string-match "\\`\\.\\.?\\'"
2105 (file-name-nondirectory name))
2106 name))
2107 (directory-files (or (car dirs) ".") full
2108 (wildcard-to-regexp nondir))))))
2109 (setq contents
2110 (nconc
2111 (if (and (car dirs) (not full))
2112 (mapcar (function (lambda (name) (concat (car dirs) name)))
2113 this-dir-contents)
2114 this-dir-contents)
2115 contents))))
2116 (setq dirs (cdr dirs)))
2117 contents)))
5eabfe72 2118
0a2e512a
RF
2119;; `member-ignore-case' undefined (XEmacs)
2120(unless (fboundp 'member-ignore-case)
2121 (defalias 'member-ignore-case 'member))
2122
5eabfe72 2123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2124;; Compatibility with older VHDL Mode versions
5eabfe72 2125
3dcb36b7
JB
2126(defvar vhdl-warnings nil
2127 "Warnings to tell the user during start up.")
d2ddb974 2128
3dcb36b7
JB
2129(defun vhdl-run-when-idle (secs repeat function)
2130 "Wait until idle, then run FUNCTION."
4bcb9c95 2131 (if (fboundp 'start-itimer)
3dcb36b7
JB
2132 (start-itimer "vhdl-mode" function secs repeat t)
2133; (run-with-idle-timer secs repeat function)))
2134 ;; explicitely activate timer (necessary when Emacs is already idle)
2135 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2136
2137(defun vhdl-warning-when-idle (&rest args)
2138 "Wait until idle, then print out warning STRING and beep."
2139 (if noninteractive
2140 (vhdl-warning (apply 'format args) t)
2141 (unless vhdl-warnings
2142 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2143 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2144
2145(defun vhdl-warning (string &optional nobeep)
2146 "Print out warning STRING and beep."
29a4e67d 2147 (message "WARNING: %s" string)
3dcb36b7 2148 (unless (or nobeep noninteractive) (beep)))
d2ddb974 2149
3dcb36b7
JB
2150(defun vhdl-print-warnings ()
2151 "Print out messages in variable `vhdl-warnings'."
2152 (let ((no-warnings (length vhdl-warnings)))
2153 (setq vhdl-warnings (nreverse vhdl-warnings))
2154 (while vhdl-warnings
29a4e67d 2155 (message "WARNING: %s" (car vhdl-warnings))
3dcb36b7
JB
2156 (setq vhdl-warnings (cdr vhdl-warnings)))
2157 (beep)
2158 (when (> no-warnings 1)
2159 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2160
2161;; Backward compatibility checks and fixes
2162;; option `vhdl-compiler' changed format
2163(unless (stringp vhdl-compiler)
2164 (setq vhdl-compiler "ModelSim")
2165 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2166
2167;; option `vhdl-standard' changed format
2168(unless (listp vhdl-standard)
2169 (setq vhdl-standard '(87 nil))
2170 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2171
2172;; option `vhdl-model-alist' changed format
2173(when (= (length (car vhdl-model-alist)) 3)
2174 (let ((old-alist vhdl-model-alist)
2175 new-alist)
2176 (while old-alist
2177 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2178 (setq old-alist (cdr old-alist)))
2179 (setq vhdl-model-alist (nreverse new-alist)))
2180 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2181
2182;; option `vhdl-project-alist' changed format
2183(when (= (length (car vhdl-project-alist)) 3)
2184 (let ((old-alist vhdl-project-alist)
2185 new-alist)
2186 (while old-alist
2187 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2188 (setq old-alist (cdr old-alist)))
2189 (setq vhdl-project-alist (nreverse new-alist)))
2190 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2191
2192;; option `vhdl-project-alist' changed format (3.31.1)
2193(when (= (length (car vhdl-project-alist)) 4)
2194 (let ((old-alist vhdl-project-alist)
2195 new-alist elem)
2196 (while old-alist
2197 (setq elem (car old-alist))
2198 (setq new-alist
2199 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2200 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2201 new-alist))
2202 (setq old-alist (cdr old-alist)))
2203 (setq vhdl-project-alist (nreverse new-alist)))
2204 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2205
2206;; option `vhdl-project-alist' changed format (3.31.12)
2207(when (= (length (car vhdl-project-alist)) 10)
2208 (let ((tmp-alist vhdl-project-alist))
2209 (while tmp-alist
2210 (setcdr (nthcdr 3 (car tmp-alist))
2211 (cons "" (nthcdr 4 (car tmp-alist))))
2212 (setq tmp-alist (cdr tmp-alist))))
2213 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2214
2215;; option `vhdl-compiler-alist' changed format (3.31.1)
2216(when (= (length (car vhdl-compiler-alist)) 7)
2217 (let ((old-alist vhdl-compiler-alist)
2218 new-alist elem)
2219 (while old-alist
2220 (setq elem (car old-alist))
2221 (setq new-alist
2222 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2223 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2224 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2225 (nth 5 elem) (nth 6 elem) nil)
2226 new-alist))
2227 (setq old-alist (cdr old-alist)))
2228 (setq vhdl-compiler-alist (nreverse new-alist)))
2229 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2230
2231;; option `vhdl-compiler-alist' changed format (3.31.10)
2232(when (= (length (car vhdl-compiler-alist)) 12)
2233 (let ((tmp-alist vhdl-compiler-alist))
2234 (while tmp-alist
2235 (setcdr (nthcdr 4 (car tmp-alist))
2236 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2237 (setq tmp-alist (cdr tmp-alist))))
2238 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2239
2240;; option `vhdl-compiler-alist' changed format (3.31.11)
2241(when (= (length (car vhdl-compiler-alist)) 13)
2242 (let ((tmp-alist vhdl-compiler-alist))
2243 (while tmp-alist
2244 (setcdr (nthcdr 3 (car tmp-alist))
2245 (cons "" (nthcdr 4 (car tmp-alist))))
2246 (setq tmp-alist (cdr tmp-alist))))
2247 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2248
2249;; option `vhdl-compiler-alist' changed format (3.32.7)
2250(when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2251 (let ((tmp-alist vhdl-compiler-alist))
2252 (while tmp-alist
2253 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2254 '(0 . nil))
2255 (setq tmp-alist (cdr tmp-alist))))
2256 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2257
2258;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2259(when (equal vhdl-project "")
2260 (setq vhdl-project nil)
2261 (customize-save-variable 'vhdl-project vhdl-project))
2262
2263;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2264(when (stringp vhdl-project-file-name)
2265 (setq vhdl-project-file-name (list vhdl-project-file-name))
2266 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2267
2268;; option `speedbar-indentation-width': introduced in speedbar 0.10
2269(if (not (boundp 'speedbar-indentation-width))
2270 (defvar speedbar-indentation-width 2)
2271 ;; set default to 2 if not already customized
2272 (unless (get 'speedbar-indentation-width 'saved-value)
2273 (setq speedbar-indentation-width 2)))
2274
2275
2276;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2277;;; Help functions / inline substitutions / macros
2278;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2279
2280(defun vhdl-standard-p (standard)
2281 "Check if STANDARD is specified as used standard."
2282 (or (eq standard (car vhdl-standard))
2283 (memq standard (cadr vhdl-standard))))
2284
2285(defun vhdl-project-p (&optional warning)
2286 "Return non-nil if a project is displayed, i.e. directories or files are
2287specified."
2288 (if (assoc vhdl-project vhdl-project-alist)
2289 vhdl-project
2290 (when (and vhdl-project warning)
2291 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2292 nil))
2293
2294(defun vhdl-resolve-env-variable (string)
2295 "Resolve environment variables in STRING."
2296 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2297 (setq string (concat (match-string 1 string)
2298 (getenv (match-string 2 string))
2299 (match-string 4 string))))
2300 string)
2301
2302(defun vhdl-default-directory ()
2303 "Return the default directory of the current project or the directory of the
2304current buffer if no project is defined."
2305 (if (vhdl-project-p)
2306 (expand-file-name (vhdl-resolve-env-variable
2307 (nth 1 (aget vhdl-project-alist vhdl-project))))
2308 default-directory))
2309
2310(defmacro vhdl-prepare-search-1 (&rest body)
2311 "Enable case insensitive search and switch to syntax table that includes '_',
2312then execute BODY, and finally restore the old environment. Used for
2313consistent searching."
68a47940 2314 `(let ((case-fold-search t)) ; case insensitive search
3dcb36b7 2315 ;; use extended syntax table
68a47940
SM
2316 (with-syntax-table vhdl-mode-ext-syntax-table
2317 ,@body)))
3dcb36b7
JB
2318
2319(defmacro vhdl-prepare-search-2 (&rest body)
2320 "Enable case insensitive search, switch to syntax table that includes '_',
2321and remove `intangible' overlays, then execute BODY, and finally restore the
2322old environment. Used for consistent searching."
68a47940 2323 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
3dcb36b7
JB
2324 `(let ((case-fold-search t) ; case insensitive search
2325 (current-syntax-table (syntax-table))
68a47940 2326 overlay-all-list overlay-intangible-list overlay)
3dcb36b7
JB
2327 ;; use extended syntax table
2328 (set-syntax-table vhdl-mode-ext-syntax-table)
2329 ;; remove `intangible' overlays
2330 (when (fboundp 'overlay-lists)
2331 (setq overlay-all-list (overlay-lists))
2332 (setq overlay-all-list
2333 (append (car overlay-all-list) (cdr overlay-all-list)))
2334 (while overlay-all-list
2335 (setq overlay (car overlay-all-list))
2336 (when (memq 'intangible (overlay-properties overlay))
2337 (setq overlay-intangible-list
2338 (cons overlay overlay-intangible-list))
2339 (overlay-put overlay 'intangible nil))
2340 (setq overlay-all-list (cdr overlay-all-list))))
2341 ;; execute BODY safely
68a47940
SM
2342 (unwind-protect
2343 (progn ,@body)
2344 ;; restore syntax table
2345 (set-syntax-table current-syntax-table)
2346 ;; restore `intangible' overlays
2347 (when (fboundp 'overlay-lists)
2348 (while overlay-intangible-list
2349 (overlay-put (car overlay-intangible-list) 'intangible t)
2350 (setq overlay-intangible-list
2351 (cdr overlay-intangible-list)))))))
3dcb36b7
JB
2352
2353(defmacro vhdl-visit-file (file-name issue-error &rest body)
2354 "Visit file FILE-NAME and execute BODY."
2355 `(if (null ,file-name)
2356 (progn ,@body)
2357 (unless (file-directory-p ,file-name)
2358 (let ((source-buffer (current-buffer))
2359 (visiting-buffer (find-buffer-visiting ,file-name))
2360 file-opened)
2361 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2362 (condition-case ()
2363 (progn (set-buffer (create-file-buffer ,file-name))
2364 (setq file-opened t)
2365 (vhdl-insert-file-contents ,file-name)
2366 (modify-syntax-entry ?\- ". 12" (syntax-table))
2367 (modify-syntax-entry ?\n ">" (syntax-table))
2368 (modify-syntax-entry ?\^M ">" (syntax-table))
2369 (modify-syntax-entry ?_ "w" (syntax-table))
2370 t)
2371 (error
2372 (if ,issue-error
2373 (progn
2374 (when file-opened (kill-buffer (current-buffer)))
2375 (set-buffer source-buffer)
ec3ec9cc 2376 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
3dcb36b7
JB
2377 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2378 nil))))
2379 (condition-case info
2380 (progn ,@body)
2381 (error
2382 (if ,issue-error
2383 (progn
2384 (when file-opened (kill-buffer (current-buffer)))
2385 (set-buffer source-buffer)
2386 (error (cadr info)))
2387 (vhdl-warning (cadr info))))))
2388 (when file-opened (kill-buffer (current-buffer)))
2389 (set-buffer source-buffer)))))
2390
2391(defun vhdl-insert-file-contents (filename)
2392 "Nicked from `insert-file-contents-literally', but allow coding system
2393conversion."
2394 (let ((format-alist nil)
2395 (after-insert-file-functions nil)
2396 (jka-compr-compression-info-list nil))
2397 (insert-file-contents filename t)))
2398
2399(defun vhdl-sort-alist (alist)
a4c6cfad 2400 "Sort ALIST."
3dcb36b7
JB
2401 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2402
2403(defun vhdl-get-subdirs (directory)
2404 "Recursively get subdirectories of DIRECTORY."
2405 (let ((dir-list (list (file-name-as-directory directory)))
2406 file-list)
2407 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2408 (while file-list
2409 (when (file-directory-p (car file-list))
2410 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2411 (setq file-list (cdr file-list)))
2412 dir-list))
2413
2414(defun vhdl-aput (alist-symbol key &optional value)
2415 "As `aput', but delete key-value pair if VALUE is nil."
2416 (if value
2417 (aput alist-symbol key value)
2418 (adelete alist-symbol key)))
2419
2420(defun vhdl-delete (elt list)
2421 "Delete by side effect the first occurrence of ELT as a member of LIST."
2422 (setq list (cons nil list))
2423 (let ((list1 list))
2424 (while (and (cdr list1) (not (equal elt (cadr list1))))
2425 (setq list1 (cdr list1)))
2426 (when list
2427 (setcdr list1 (cddr list1))))
2428 (cdr list))
2429
2430(defun vhdl-speedbar-refresh (&optional key)
2431 "Refresh directory or project with name KEY."
2432 (when (and (boundp 'speedbar-frame)
2433 (frame-live-p speedbar-frame))
2434 (let ((pos (point))
2435 (last-frame (selected-frame)))
2436 (if (null key)
2437 (speedbar-refresh)
2438 (select-frame speedbar-frame)
2439 (when (save-excursion
2440 (goto-char (point-min))
2441 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2442 (goto-char (match-end 1))
2443 (speedbar-do-function-pointer)
2444 (backward-char 2)
2445 (speedbar-do-function-pointer)
2446 (message "Refreshing speedbar...done"))
2447 (select-frame last-frame)))))
2448
2449(defun vhdl-show-messages ()
2450 "Get *Messages* buffer to show recent messages."
2451 (interactive)
f8246027 2452 (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
3dcb36b7
JB
2453
2454(defun vhdl-use-direct-instantiation ()
2455 "Return whether direct instantiation is used."
2456 (or (eq vhdl-use-direct-instantiation 'always)
2457 (and (eq vhdl-use-direct-instantiation 'standard)
2458 (not (vhdl-standard-p '87)))))
2459
2460(defun vhdl-max-marker (marker1 marker2)
2461 "Return larger marker."
2462 (if (> marker1 marker2) marker1 marker2))
2463
2464(defun vhdl-goto-marker (marker)
2465 "Goto marker in appropriate buffer."
2466 (when (markerp marker)
2467 (set-buffer (marker-buffer marker)))
2468 (goto-char marker))
2469
2470(defun vhdl-menu-split (list title)
2471 "Split menu LIST into several submenues, if number of
2472elements > `vhdl-menu-max-size'."
2473 (if (> (length list) vhdl-menu-max-size)
2474 (let ((remain list)
2475 (result '())
2476 (sublist '())
2477 (menuno 1)
2478 (i 0))
2479 (while remain
2480 (setq sublist (cons (car remain) sublist))
2481 (setq remain (cdr remain))
2482 (setq i (+ i 1))
2483 (if (= i vhdl-menu-max-size)
2484 (progn
2485 (setq result (cons (cons (format "%s %s" title menuno)
2486 (nreverse sublist)) result))
2487 (setq i 0)
2488 (setq menuno (+ menuno 1))
2489 (setq sublist '()))))
2490 (and sublist
2491 (setq result (cons (cons (format "%s %s" title menuno)
2492 (nreverse sublist)) result)))
2493 (nreverse result))
2494 list))
2495
2496
2497;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2498;;; Bindings
2499;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2500
2501;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2502;; Key bindings
2503
2504(defvar vhdl-template-map nil
2505 "Keymap for VHDL templates.")
2506
2507(defun vhdl-template-map-init ()
2508 "Initialize `vhdl-template-map'."
2509 (setq vhdl-template-map (make-sparse-keymap))
2510 ;; key bindings for VHDL templates
2511 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2512 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2513 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2514 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2515 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2516 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2517 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2518 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2519 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
5eabfe72
KH
2520 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2521 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2522 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2523 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2524 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2525 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2526 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2527 (define-key vhdl-template-map "el" 'vhdl-template-else)
2528 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2529 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2530 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2531 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2532 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2533 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2534 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2535 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2536 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2537 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2538 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2539 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2540 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2541 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2542 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2543 (define-key vhdl-template-map "li" 'vhdl-template-library)
2544 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2545 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2546 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2547 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2548 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2549 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2550 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2551 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2552 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2553 (define-key vhdl-template-map "po" 'vhdl-template-port)
2554 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2555 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2556 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2557 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2558 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2559 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2560 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2561 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2562 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2563 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2564 (define-key vhdl-template-map "us" 'vhdl-template-use)
2565 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2566 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2567 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2568 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2569 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2570 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2571 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2572 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2573 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2574 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2575 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2576 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2577 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2578 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2579 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2580 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2581 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2582 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2583 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2584 (when (vhdl-standard-p 'ams)
2585 (define-key vhdl-template-map "br" 'vhdl-template-break)
2586 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2587 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2588 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2589 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2590 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2591 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2592 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2593 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2594 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2595 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2596 )
2597 (when (vhdl-standard-p 'math)
2598 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2599 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2600 ))
2601
2602;; initialize template map for VHDL Mode
2603(vhdl-template-map-init)
2604
2605(defun vhdl-function-name (prefix string &optional postfix)
2606 "Generate a Lisp function name.
2607PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2608STRING are replaced by `-' and substrings are converted to lower case."
2609 (let ((name prefix))
2610 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2611 (setq name
2612 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2613 (setq string (substring string (match-beginning 2))))
2614 (when postfix (setq name (concat name "-" postfix)))
2615 (intern name)))
2616
3dcb36b7 2617(defvar vhdl-model-map nil
5eabfe72
KH
2618 "Keymap for VHDL models.")
2619
2620(defun vhdl-model-map-init ()
2621 "Initialize `vhdl-model-map'."
2622 (setq vhdl-model-map (make-sparse-keymap))
2623 ;; key bindings for VHDL models
2624 (let ((model-alist vhdl-model-alist) model)
2625 (while model-alist
2626 (setq model (car model-alist))
2627 (define-key vhdl-model-map (nth 2 model)
2628 (vhdl-function-name "vhdl-model" (nth 0 model)))
2629 (setq model-alist (cdr model-alist)))))
2630
2631;; initialize user model map for VHDL Mode
2632(vhdl-model-map-init)
d2ddb974 2633
3dcb36b7 2634(defvar vhdl-mode-map nil
d2ddb974
KH
2635 "Keymap for VHDL Mode.")
2636
5eabfe72
KH
2637(defun vhdl-mode-map-init ()
2638 "Initialize `vhdl-mode-map'."
d2ddb974 2639 (setq vhdl-mode-map (make-sparse-keymap))
5eabfe72 2640 ;; template key bindings
0a2e512a 2641 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
5eabfe72 2642 ;; model key bindings
0a2e512a 2643 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
d2ddb974 2644 ;; standard key bindings
0a2e512a
RF
2645 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2646 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2647 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2648 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2649 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2650 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2651 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
f8246027 2652 (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
0a2e512a
RF
2653 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2654 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2655 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
5eabfe72 2656 ;; backspace/delete key bindings
0a2e512a 2657 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
3dcb36b7 2658 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
0a2e512a 2659 (define-key vhdl-mode-map [delete] 'delete-char)
3dcb36b7 2660 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
5eabfe72 2661 ;; mode specific key bindings
3dcb36b7
JB
2662 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2663 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2664 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2665 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2666 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2667 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2668 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
0a2e512a 2669 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
5eabfe72 2670 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
3dcb36b7 2671 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
5eabfe72
KH
2672 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2673 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2674 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2675 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2676 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2677 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2678 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
f8246027 2679 (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
5eabfe72
KH
2680 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2681 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
3dcb36b7 2682 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
5eabfe72
KH
2683 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2684 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
3dcb36b7
JB
2685 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2686 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2687 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2688 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2689 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2690 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2691 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
83a38a5a
SM
2692 (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
2693 (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
2694 (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
2695 (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
2696 (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
2697 (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
0a2e512a
RF
2698 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2699 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
3dcb36b7
JB
2700 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2701 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
0a2e512a 2702 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
3dcb36b7
JB
2703 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2704 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2705 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2706 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2707 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2708 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2709 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2710 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2711 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2712 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2713 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2714 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2715 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2716 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2717 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
5eabfe72
KH
2718 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2719 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2720 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2721 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2722 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2723 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2724 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2725 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2726 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
3dcb36b7
JB
2727 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2728 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2729 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2730 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2731 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
0a2e512a
RF
2732 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2733 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
3dcb36b7
JB
2734 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2735 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
83a38a5a
SM
2736 (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
2737 (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
0a2e512a
RF
2738 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2739 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2740 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2741 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
5eabfe72 2742 ;; insert commands bindings
3dcb36b7 2743 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
5eabfe72
KH
2744 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2745 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2746 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2747 ;; electric key bindings
0a2e512a
RF
2748 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2749 (when vhdl-intelligent-tab
2750 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2751 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2752 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2753 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2754 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2755 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2756 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2757 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2758 (define-key vhdl-mode-map "." 'vhdl-electric-period)
5eabfe72 2759 (when (vhdl-standard-p 'ams)
0a2e512a 2760 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
5eabfe72
KH
2761
2762;; initialize mode map for VHDL Mode
2763(vhdl-mode-map-init)
d2ddb974
KH
2764
2765;; define special minibuffer keymap for enabling word completion in minibuffer
2766;; (useful in template generator prompts)
4bcb9c95
SM
2767(defvar vhdl-minibuffer-local-map
2768 (let ((map (make-sparse-keymap)))
2769 (set-keymap-parent map minibuffer-local-map)
2770 (when vhdl-word-completion-in-minibuffer
2771 (define-key map "\t" 'vhdl-minibuffer-tab))
2772 map)
d2ddb974
KH
2773 "Keymap for minibuffer used in VHDL Mode.")
2774
5eabfe72
KH
2775;; set up electric character functions to work with
2776;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
51b5ad57 2777(mapc
5eabfe72
KH
2778 (function
2779 (lambda (sym)
2780 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2781 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2782 '(vhdl-electric-space
2783 vhdl-electric-tab
2784 vhdl-electric-return
2785 vhdl-electric-dash
2786 vhdl-electric-open-bracket
2787 vhdl-electric-close-bracket
2788 vhdl-electric-quote
2789 vhdl-electric-semicolon
2790 vhdl-electric-comma
2791 vhdl-electric-period
2792 vhdl-electric-equal))
2793
3dcb36b7
JB
2794;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2795;; Syntax table
2796
d2ddb974 2797(defvar vhdl-mode-syntax-table nil
5eabfe72 2798 "Syntax table used in `vhdl-mode' buffers.")
d2ddb974 2799
3dcb36b7
JB
2800(defvar vhdl-mode-ext-syntax-table nil
2801 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2802
5eabfe72
KH
2803(defun vhdl-mode-syntax-table-init ()
2804 "Initialize `vhdl-mode-syntax-table'."
d2ddb974 2805 (setq vhdl-mode-syntax-table (make-syntax-table))
5eabfe72
KH
2806 ;; define punctuation
2807 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2808 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
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 ;; define string
2824 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2825 ;; define underscore
2826 (when vhdl-underscore-is-part-of-word
3dcb36b7 2827 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
5eabfe72
KH
2828 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2829 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2830 ;; and \n and \^M end a comment
2831 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2832 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2833 ;; define parentheses to match
2834 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2835 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2836 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2837 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2838 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
3dcb36b7
JB
2839 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2840 ;; extended syntax table including '_' (for simpler search regexps)
2841 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2842 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
5eabfe72
KH
2843
2844;; initialize syntax table for VHDL Mode
2845(vhdl-mode-syntax-table-init)
2846
d2ddb974
KH
2847(defvar vhdl-syntactic-context nil
2848 "Buffer local variable containing syntactic analysis list.")
2849(make-variable-buffer-local 'vhdl-syntactic-context)
2850
5eabfe72 2851;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2852;; Abbrev ook bindings
d2ddb974
KH
2853
2854(defvar vhdl-mode-abbrev-table nil
5eabfe72
KH
2855 "Abbrev table to use in `vhdl-mode' buffers.")
2856
2857(defun vhdl-mode-abbrev-table-init ()
2858 "Initialize `vhdl-mode-abbrev-table'."
5eabfe72
KH
2859 (define-abbrev-table 'vhdl-mode-abbrev-table
2860 (append
2861 (when (memq 'vhdl vhdl-electric-keywords)
2862 ;; VHDL'93 keywords
86905e5b
SM
2863 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2864 '(
2865 ("--" . vhdl-template-display-comment-hook)
2866 ("abs" . vhdl-template-default-hook)
2867 ("access" . vhdl-template-default-hook)
2868 ("after" . vhdl-template-default-hook)
2869 ("alias" . vhdl-template-alias-hook)
2870 ("all" . vhdl-template-default-hook)
2871 ("and" . vhdl-template-default-hook)
2872 ("arch" . vhdl-template-architecture-hook)
2873 ("architecture" . vhdl-template-architecture-hook)
2874 ("array" . vhdl-template-default-hook)
2875 ("assert" . vhdl-template-assert-hook)
2876 ("attr" . vhdl-template-attribute-hook)
2877 ("attribute" . vhdl-template-attribute-hook)
2878 ("begin" . vhdl-template-default-indent-hook)
2879 ("block" . vhdl-template-block-hook)
2880 ("body" . vhdl-template-default-hook)
2881 ("buffer" . vhdl-template-default-hook)
2882 ("bus" . vhdl-template-default-hook)
2883 ("case" . vhdl-template-case-hook)
2884 ("comp" . vhdl-template-component-hook)
2885 ("component" . vhdl-template-component-hook)
2886 ("cond" . vhdl-template-conditional-signal-asst-hook)
2887 ("conditional" . vhdl-template-conditional-signal-asst-hook)
2888 ("conf" . vhdl-template-configuration-hook)
2889 ("configuration" . vhdl-template-configuration-hook)
2890 ("cons" . vhdl-template-constant-hook)
2891 ("constant" . vhdl-template-constant-hook)
2892 ("disconnect" . vhdl-template-disconnect-hook)
2893 ("downto" . vhdl-template-default-hook)
2894 ("else" . vhdl-template-else-hook)
2895 ("elseif" . vhdl-template-elsif-hook)
2896 ("elsif" . vhdl-template-elsif-hook)
2897 ("end" . vhdl-template-default-indent-hook)
2898 ("entity" . vhdl-template-entity-hook)
2899 ("exit" . vhdl-template-exit-hook)
2900 ("file" . vhdl-template-file-hook)
2901 ("for" . vhdl-template-for-hook)
2902 ("func" . vhdl-template-function-hook)
2903 ("function" . vhdl-template-function-hook)
2904 ("generic" . vhdl-template-generic-hook)
2905 ("group" . vhdl-template-group-hook)
2906 ("guarded" . vhdl-template-default-hook)
2907 ("if" . vhdl-template-if-hook)
2908 ("impure" . vhdl-template-default-hook)
2909 ("in" . vhdl-template-default-hook)
2910 ("inertial" . vhdl-template-default-hook)
2911 ("inout" . vhdl-template-default-hook)
2912 ("inst" . vhdl-template-instance-hook)
2913 ("instance" . vhdl-template-instance-hook)
2914 ("is" . vhdl-template-default-hook)
2915 ("label" . vhdl-template-default-hook)
2916 ("library" . vhdl-template-library-hook)
2917 ("linkage" . vhdl-template-default-hook)
2918 ("literal" . vhdl-template-default-hook)
2919 ("loop" . vhdl-template-bare-loop-hook)
2920 ("map" . vhdl-template-map-hook)
2921 ("mod" . vhdl-template-default-hook)
2922 ("nand" . vhdl-template-default-hook)
2923 ("new" . vhdl-template-default-hook)
2924 ("next" . vhdl-template-next-hook)
2925 ("nor" . vhdl-template-default-hook)
2926 ("not" . vhdl-template-default-hook)
2927 ("null" . vhdl-template-default-hook)
2928 ("of" . vhdl-template-default-hook)
2929 ("on" . vhdl-template-default-hook)
2930 ("open" . vhdl-template-default-hook)
2931 ("or" . vhdl-template-default-hook)
2932 ("others" . vhdl-template-others-hook)
2933 ("out" . vhdl-template-default-hook)
2934 ("pack" . vhdl-template-package-hook)
2935 ("package" . vhdl-template-package-hook)
2936 ("port" . vhdl-template-port-hook)
2937 ("postponed" . vhdl-template-default-hook)
2938 ("procedure" . vhdl-template-procedure-hook)
2939 ("process" . vhdl-template-process-hook)
2940 ("pure" . vhdl-template-default-hook)
2941 ("range" . vhdl-template-default-hook)
2942 ("record" . vhdl-template-default-hook)
2943 ("register" . vhdl-template-default-hook)
2944 ("reject" . vhdl-template-default-hook)
2945 ("rem" . vhdl-template-default-hook)
2946 ("report" . vhdl-template-report-hook)
2947 ("return" . vhdl-template-return-hook)
2948 ("rol" . vhdl-template-default-hook)
2949 ("ror" . vhdl-template-default-hook)
2950 ("select" . vhdl-template-selected-signal-asst-hook)
2951 ("severity" . vhdl-template-default-hook)
2952 ("shared" . vhdl-template-default-hook)
2953 ("sig" . vhdl-template-signal-hook)
2954 ("signal" . vhdl-template-signal-hook)
2955 ("sla" . vhdl-template-default-hook)
2956 ("sll" . vhdl-template-default-hook)
2957 ("sra" . vhdl-template-default-hook)
2958 ("srl" . vhdl-template-default-hook)
2959 ("subtype" . vhdl-template-subtype-hook)
2960 ("then" . vhdl-template-default-hook)
2961 ("to" . vhdl-template-default-hook)
2962 ("transport" . vhdl-template-default-hook)
2963 ("type" . vhdl-template-type-hook)
2964 ("unaffected" . vhdl-template-default-hook)
2965 ("units" . vhdl-template-default-hook)
2966 ("until" . vhdl-template-default-hook)
2967 ("use" . vhdl-template-use-hook)
2968 ("var" . vhdl-template-variable-hook)
2969 ("variable" . vhdl-template-variable-hook)
2970 ("wait" . vhdl-template-wait-hook)
2971 ("when" . vhdl-template-when-hook)
2972 ("while" . vhdl-template-while-loop-hook)
2973 ("with" . vhdl-template-with-hook)
2974 ("xnor" . vhdl-template-default-hook)
2975 ("xor" . vhdl-template-default-hook)
2976 )))
5eabfe72
KH
2977 ;; VHDL-AMS keywords
2978 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
86905e5b
SM
2979 (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
2980 '(
2981 ("across" . vhdl-template-default-hook)
2982 ("break" . vhdl-template-break-hook)
2983 ("limit" . vhdl-template-limit-hook)
2984 ("nature" . vhdl-template-nature-hook)
2985 ("noise" . vhdl-template-default-hook)
2986 ("procedural" . vhdl-template-procedural-hook)
2987 ("quantity" . vhdl-template-quantity-hook)
2988 ("reference" . vhdl-template-default-hook)
2989 ("spectrum" . vhdl-template-default-hook)
2990 ("subnature" . vhdl-template-subnature-hook)
2991 ("terminal" . vhdl-template-terminal-hook)
2992 ("through" . vhdl-template-default-hook)
2993 ("tolerance" . vhdl-template-default-hook)
2994 )))
5eabfe72
KH
2995 ;; user model keywords
2996 (when (memq 'user vhdl-electric-keywords)
86905e5b
SM
2997 (let (abbrev-list keyword)
2998 (dolist (elem vhdl-model-alist)
2999 (setq keyword (nth 3 elem))
5eabfe72 3000 (unless (equal keyword "")
86905e5b
SM
3001 (push (list keyword ""
3002 (vhdl-function-name
3003 "vhdl-model" (nth 0 elem) "hook") 0 'system)
3004 abbrev-list)))
5eabfe72
KH
3005 abbrev-list)))))
3006
3007;; initialize abbrev table for VHDL Mode
3008(vhdl-mode-abbrev-table-init)
3009
3010;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3011;; Template completion lists
3012
3013(defvar vhdl-template-construct-alist nil
3014 "List of built-in construct templates.")
3015
3016(defun vhdl-template-construct-alist-init ()
3017 "Initialize `vhdl-template-construct-alist'."
3018 (setq
3019 vhdl-template-construct-alist
3020 (append
3021 '(
3022 ("alias declaration" vhdl-template-alias)
3023 ("architecture body" vhdl-template-architecture)
3024 ("assertion" vhdl-template-assert)
3025 ("attribute declaration" vhdl-template-attribute-decl)
3026 ("attribute specification" vhdl-template-attribute-spec)
3027 ("block configuration" vhdl-template-block-configuration)
3028 ("block statement" vhdl-template-block)
3029 ("case statement" vhdl-template-case-is)
3030 ("component configuration" vhdl-template-component-conf)
3031 ("component declaration" vhdl-template-component-decl)
3032 ("component instantiation statement" vhdl-template-component-inst)
3033 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3034 ("configuration declaration" vhdl-template-configuration-decl)
3035 ("configuration specification" vhdl-template-configuration-spec)
3036 ("constant declaration" vhdl-template-constant)
3037 ("disconnection specification" vhdl-template-disconnect)
3038 ("entity declaration" vhdl-template-entity)
3039 ("exit statement" vhdl-template-exit)
3040 ("file declaration" vhdl-template-file)
3041 ("generate statement" vhdl-template-generate)
3042 ("generic clause" vhdl-template-generic)
3043 ("group declaration" vhdl-template-group-decl)
3044 ("group template declaration" vhdl-template-group-template)
3045 ("if statement" vhdl-template-if-then)
3046 ("library clause" vhdl-template-library)
3047 ("loop statement" vhdl-template-loop)
3048 ("next statement" vhdl-template-next)
3049 ("package declaration" vhdl-template-package-decl)
3050 ("package body" vhdl-template-package-body)
3051 ("port clause" vhdl-template-port)
3052 ("process statement" vhdl-template-process)
3053 ("report statement" vhdl-template-report)
3054 ("return statement" vhdl-template-return)
3055 ("selected signal assignment" vhdl-template-selected-signal-asst)
3056 ("signal declaration" vhdl-template-signal)
3057 ("subprogram declaration" vhdl-template-subprogram-decl)
3058 ("subprogram body" vhdl-template-subprogram-body)
3059 ("subtype declaration" vhdl-template-subtype)
3060 ("type declaration" vhdl-template-type)
3061 ("use clause" vhdl-template-use)
3062 ("variable declaration" vhdl-template-variable)
3063 ("wait statement" vhdl-template-wait)
3064 )
3065 (when (vhdl-standard-p 'ams)
3066 '(
3067 ("break statement" vhdl-template-break)
3068 ("nature declaration" vhdl-template-nature)
3069 ("quantity declaration" vhdl-template-quantity)
3070 ("simultaneous case statement" vhdl-template-case-use)
3071 ("simultaneous if statement" vhdl-template-if-use)
3072 ("simultaneous procedural statement" vhdl-template-procedural)
3073 ("step limit specification" vhdl-template-limit)
3074 ("subnature declaration" vhdl-template-subnature)
3075 ("terminal declaration" vhdl-template-terminal)
3076 )))))
d2ddb974 3077
5eabfe72
KH
3078;; initialize for VHDL Mode
3079(vhdl-template-construct-alist-init)
3080
3081(defvar vhdl-template-package-alist nil
3082 "List of built-in package templates.")
3083
3084(defun vhdl-template-package-alist-init ()
3085 "Initialize `vhdl-template-package-alist'."
3086 (setq
3087 vhdl-template-package-alist
3088 (append
3089 '(
3090 ("numeric_bit" vhdl-template-package-numeric-bit)
3091 ("numeric_std" vhdl-template-package-numeric-std)
3092 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3093 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3094 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3095 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3096 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3097 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3098 ("textio" vhdl-template-package-textio)
3099 )
3100 (when (vhdl-standard-p 'math)
3101 '(
3102 ("math_complex" vhdl-template-package-math-complex)
3103 ("math_real" vhdl-template-package-math-real)
3104 )))))
d2ddb974 3105
5eabfe72
KH
3106;; initialize for VHDL Mode
3107(vhdl-template-package-alist-init)
d2ddb974 3108
5eabfe72 3109(defvar vhdl-template-directive-alist
3dcb36b7
JB
3110 '(
3111 ("translate_on" vhdl-template-directive-translate-on)
3112 ("translate_off" vhdl-template-directive-translate-off)
3113 ("synthesis_on" vhdl-template-directive-synthesis-on)
3114 ("synthesis_off" vhdl-template-directive-synthesis-off)
3115 )
5eabfe72 3116 "List of built-in directive templates.")
d2ddb974 3117
5eabfe72
KH
3118
3119;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3120;;; Menues
3121;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3122
3123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
3124;; VHDL menu (using `easy-menu.el')
3125
5eabfe72
KH
3126(defun vhdl-customize ()
3127 "Call the customize function with `vhdl' as argument."
3128 (interactive)
3129 (customize-browse 'vhdl))
3130
5eabfe72
KH
3131(defun vhdl-create-mode-menu ()
3132 "Create VHDL Mode menu."
3dcb36b7
JB
3133 `("VHDL"
3134 ,(append
3135 '("Project"
3136 ["None" (vhdl-set-project "")
3137 :style radio :selected (null vhdl-project)]
3138 "--")
3139 ;; add menu entries for defined projects
3140 (let ((project-alist vhdl-project-alist) menu-list name)
3141 (while project-alist
3142 (setq name (caar project-alist))
3143 (setq menu-list
3144 (cons `[,name (vhdl-set-project ,name)
3145 :style radio :selected (equal ,name vhdl-project)]
3146 menu-list))
3147 (setq project-alist (cdr project-alist)))
3148 (setq menu-list
3149 (if vhdl-project-sort
3150 (sort menu-list
3151 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3152 (nreverse menu-list)))
3153 (vhdl-menu-split menu-list "Project"))
3154 '("--" "--"
3155 ["Select Project..." vhdl-set-project t]
0a2e512a 3156 ["Set As Default Project" vhdl-set-default-project t]
3dcb36b7
JB
3157 "--"
3158 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3159 ["Import Project..." vhdl-import-project
3160 :keys "C-c C-p C-m" :active t]
3161 ["Export Project" vhdl-export-project vhdl-project]
3162 "--"
3163 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
d2ddb974 3164 "--"
3dcb36b7
JB
3165 ("Compile"
3166 ["Compile Buffer" vhdl-compile t]
3167 ["Stop Compilation" kill-compilation t]
3168 "--"
3169 ["Make" vhdl-make t]
3170 ["Generate Makefile" vhdl-generate-makefile t]
3171 "--"
3172 ["Next Error" next-error t]
3173 ["Previous Error" previous-error t]
3174 ["First Error" first-error t]
3175 "--"
3176 ,(append
3177 '("Compiler")
3178 ;; add menu entries for defined compilers
3179 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3180 (while comp-alist
3181 (setq name (caar comp-alist))
3182 (setq menu-list
3183 (cons `[,name (setq vhdl-compiler ,name)
3184 :style radio :selected (equal ,name vhdl-compiler)]
3185 menu-list))
3186 (setq comp-alist (cdr comp-alist)))
3187 (setq menu-list (nreverse menu-list))
3188 (vhdl-menu-split menu-list "Compiler"))
3189 '("--" "--"
3190 ["Select Compiler..." vhdl-set-compiler t]
3191 "--"
3192 ["Customize Compiler..."
3193 (customize-option 'vhdl-compiler-alist) t])))
5eabfe72 3194 "--"
3dcb36b7
JB
3195 ,(append
3196 '("Template"
3197 ("VHDL Construct 1"
3198 ["Alias" vhdl-template-alias t]
3199 ["Architecture" vhdl-template-architecture t]
3200 ["Assert" vhdl-template-assert t]
3201 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3202 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3203 ["Block" vhdl-template-block t]
3204 ["Case" vhdl-template-case-is t]
3205 ["Component (Decl)" vhdl-template-component-decl t]
3206 ["(Component) Instance" vhdl-template-component-inst t]
3207 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3208 ["Configuration (Block)" vhdl-template-block-configuration t]
3209 ["Configuration (Comp)" vhdl-template-component-conf t]
3210 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3211 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3212 ["Constant" vhdl-template-constant t]
3213 ["Disconnect" vhdl-template-disconnect t]
3214 ["Else" vhdl-template-else t]
3215 ["Elsif" vhdl-template-elsif t]
3216 ["Entity" vhdl-template-entity t]
3217 ["Exit" vhdl-template-exit t]
3218 ["File" vhdl-template-file t]
3219 ["For (Generate)" vhdl-template-for-generate t]
3220 ["For (Loop)" vhdl-template-for-loop t]
3221 ["Function (Body)" vhdl-template-function-body t]
3222 ["Function (Decl)" vhdl-template-function-decl t]
3223 ["Generic" vhdl-template-generic t]
3224 ["Group (Decl)" vhdl-template-group-decl t]
3225 ["Group (Template)" vhdl-template-group-template t])
3226 ("VHDL Construct 2"
3227 ["If (Generate)" vhdl-template-if-generate t]
3228 ["If (Then)" vhdl-template-if-then t]
3229 ["Library" vhdl-template-library t]
3230 ["Loop" vhdl-template-bare-loop t]
3231 ["Map" vhdl-template-map t]
3232 ["Next" vhdl-template-next t]
3233 ["Others (Aggregate)" vhdl-template-others t]
3234 ["Package (Decl)" vhdl-template-package-decl t]
3235 ["Package (Body)" vhdl-template-package-body t]
3236 ["Port" vhdl-template-port t]
3237 ["Procedure (Body)" vhdl-template-procedure-body t]
3238 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3239 ["Process (Comb)" vhdl-template-process-comb t]
3240 ["Process (Seq)" vhdl-template-process-seq t]
3241 ["Report" vhdl-template-report t]
3242 ["Return" vhdl-template-return t]
3243 ["Select" vhdl-template-selected-signal-asst t]
3244 ["Signal" vhdl-template-signal t]
3245 ["Subtype" vhdl-template-subtype t]
3246 ["Type" vhdl-template-type t]
3247 ["Use" vhdl-template-use t]
3248 ["Variable" vhdl-template-variable t]
3249 ["Wait" vhdl-template-wait t]
3250 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3251 ["When" vhdl-template-when t]
3252 ["While (Loop)" vhdl-template-while-loop t]
3253 ["With" vhdl-template-with t]))
3254 (when (vhdl-standard-p 'ams)
3255 '(("VHDL-AMS Construct"
3256 ["Break" vhdl-template-break t]
3257 ["Case (Use)" vhdl-template-case-use t]
3258 ["If (Use)" vhdl-template-if-use t]
3259 ["Limit" vhdl-template-limit t]
3260 ["Nature" vhdl-template-nature t]
3261 ["Procedural" vhdl-template-procedural t]
3262 ["Quantity (Free)" vhdl-template-quantity-free t]
3263 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3264 ["Quantity (Source)" vhdl-template-quantity-source t]
3265 ["Subnature" vhdl-template-subnature t]
3266 ["Terminal" vhdl-template-terminal t])))
3267 '(["Insert Construct..." vhdl-template-insert-construct
3268 :keys "C-c C-i C-t"]
3269 "--")
3270 (list
3271 (append
3272 '("Package")
3273 (when (vhdl-standard-p 'math)
3274 '(["math_complex" vhdl-template-package-math-complex t]
3275 ["math_real" vhdl-template-package-math-real t]))
3276 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3277 ["numeric_std" vhdl-template-package-numeric-std t]
3278 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3279 ["textio" vhdl-template-package-textio t]
3280 "--"
3281 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3282 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3283 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3284 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3285 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3286 "--"
3287 ["Insert Package..." vhdl-template-insert-package
3288 :keys "C-c C-i C-p"])))
3289 '(("Directive"
3290 ["translate_on" vhdl-template-directive-translate-on t]
3291 ["translate_off" vhdl-template-directive-translate-off t]
3292 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3293 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3294 "--"
3295 ["Insert Directive..." vhdl-template-insert-directive
3296 :keys "C-c C-i C-d"])
5eabfe72 3297 "--"
3dcb36b7
JB
3298 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3299 ["Insert Footer" vhdl-template-footer t]
3300 ["Insert Date" vhdl-template-insert-date t]
3301 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
5eabfe72 3302 "--"
3dcb36b7
JB
3303 ["Query Next Prompt" vhdl-template-search-prompt t]))
3304 ,(append
3305 '("Model")
3306 ;; add menu entries for defined models
3307 (let ((model-alist vhdl-model-alist) menu-list model)
3308 (while model-alist
3309 (setq model (car model-alist))
3310 (setq menu-list
3311 (cons
3312 (vector
3313 (nth 0 model)
3314 (vhdl-function-name "vhdl-model" (nth 0 model))
3315 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3316 menu-list))
3317 (setq model-alist (cdr model-alist)))
3318 (setq menu-list (nreverse menu-list))
3319 (vhdl-menu-split menu-list "Model"))
3320 '("--" "--"
3321 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3322 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3323 ("Port"
5eabfe72 3324 ["Copy" vhdl-port-copy t]
d2ddb974 3325 "--"
5eabfe72
KH
3326 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3327 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3328 ["Paste As Instance" vhdl-port-paste-instance
3329 :keys "C-c C-p C-i" :active vhdl-port-list]
3330 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3331 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3332 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3dcb36b7 3333 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
d2ddb974 3334 "--"
3dcb36b7
JB
3335 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3336 "--"
3337 ["Flatten" vhdl-port-flatten
3338 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3339 ["Reverse Direction" vhdl-port-reverse-direction
3340 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3341 ("Compose"
3342 ["New Component" vhdl-compose-new-component t]
0a2e512a 3343 ["Copy Component" vhdl-port-copy t]
3dcb36b7
JB
3344 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3345 ["Wire Components" vhdl-compose-wire-components t]
3346 "--"
0a2e512a 3347 ["Generate Configuration" vhdl-compose-configuration t]
3dcb36b7
JB
3348 ["Generate Components Package" vhdl-compose-components-package t])
3349 ("Subprogram"
3350 ["Copy" vhdl-subprog-copy t]
3351 "--"
3352 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3353 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3354 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3355 "--"
3356 ["Flatten" vhdl-subprog-flatten
3357 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3358 "--"
3359 ("Comment"
5eabfe72
KH
3360 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3361 "--"
3362 ["Insert Inline Comment" vhdl-comment-append-inline t]
3363 ["Insert Horizontal Line" vhdl-comment-display-line t]
3364 ["Insert Display Comment" vhdl-comment-display t]
3365 "--"
3366 ["Fill Comment" fill-paragraph t]
3367 ["Fill Comment Region" fill-region (mark)]
3368 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3dcb36b7
JB
3369 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3370 ("Line"
5eabfe72
KH
3371 ["Kill" vhdl-line-kill t]
3372 ["Copy" vhdl-line-copy t]
3373 ["Yank" vhdl-line-yank t]
3374 ["Expand" vhdl-line-expand t]
3375 "--"
3376 ["Transpose Next" vhdl-line-transpose-next t]
3377 ["Transpose Prev" vhdl-line-transpose-previous t]
3378 ["Open" vhdl-line-open t]
3dcb36b7 3379 ["Join" vhdl-delete-indentation t]
5eabfe72
KH
3380 "--"
3381 ["Goto" goto-line t]
3dcb36b7
JB
3382 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3383 ("Move"
5eabfe72
KH
3384 ["Forward Statement" vhdl-end-of-statement t]
3385 ["Backward Statement" vhdl-beginning-of-statement t]
3386 ["Forward Expression" vhdl-forward-sexp t]
3387 ["Backward Expression" vhdl-backward-sexp t]
3dcb36b7
JB
3388 ["Forward Same Indent" vhdl-forward-same-indent t]
3389 ["Backward Same Indent" vhdl-backward-same-indent t]
5eabfe72
KH
3390 ["Forward Function" vhdl-end-of-defun t]
3391 ["Backward Function" vhdl-beginning-of-defun t]
3dcb36b7
JB
3392 ["Mark Function" vhdl-mark-defun t])
3393 "--"
3394 ("Indent"
3395 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3396 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
5eabfe72 3397 ["Region" vhdl-indent-region (mark)]
3dcb36b7
JB
3398 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3399 ("Align"
5eabfe72 3400 ["Group" vhdl-align-group t]
3dcb36b7
JB
3401 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3402 ["List" vhdl-align-list t]
3403 ["Declarations" vhdl-align-declarations t]
3404 ["Region" vhdl-align-region (mark)]
3405 ["Buffer" vhdl-align-buffer t]
5eabfe72
KH
3406 "--"
3407 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3408 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3dcb36b7
JB
3409 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3410 ("Fill"
3411 ["List" vhdl-fill-list t]
3412 ["Group" vhdl-fill-group t]
3413 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3414 ["Region" vhdl-fill-region (mark)])
3415 ("Beautify"
3416 ["Region" vhdl-beautify-region (mark)]
3417 ["Buffer" vhdl-beautify-buffer t])
3418 ("Fix"
3419 ["Generic/Port Clause" vhdl-fix-clause t]
5eabfe72 3420 "--"
3dcb36b7
JB
3421 ["Case Region" vhdl-fix-case-region (mark)]
3422 ["Case Buffer" vhdl-fix-case-buffer t]
3423 "--"
3424 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3425 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3426 "--"
3427 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3428 ("Update"
3429 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3430 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3431 "--"
3432 ["Fontify Buffer" vhdl-fontify-buffer t]
3433 ["Statistics Buffer" vhdl-statistics-buffer t]
3434 ["Show Messages" vhdl-show-messages t]
3435 ["Syntactic Info" vhdl-show-syntactic-information t]
3436 "--"
3437 ["Speedbar" vhdl-speedbar t]
3438 ["Hide/Show" vhdl-hs-minor-mode t]
3439 "--"
3440 ("Documentation"
5eabfe72 3441 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3dcb36b7 3442 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
5eabfe72 3443 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3dcb36b7
JB
3444 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3445 ["Version" vhdl-version t]
3446 ["Bug Report..." vhdl-submit-bug-report t]
3447 "--"
3448 ("Options"
3449 ("Mode"
3450 ["Electric Mode"
3451 (progn (customize-set-variable 'vhdl-electric-mode
56eb0904 3452 (not vhdl-electric-mode)))
3dcb36b7
JB
3453 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3454 ["Stutter Mode"
3455 (progn (customize-set-variable 'vhdl-stutter-mode
56eb0904 3456 (not vhdl-stutter-mode)))
3dcb36b7
JB
3457 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3458 ["Indent Tabs Mode"
3459 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3460 (not vhdl-indent-tabs-mode))
3461 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3462 :style toggle :selected vhdl-indent-tabs-mode]
3463 "--"
3464 ["Customize Group..." (customize-group 'vhdl-mode) t])
3465 ("Project"
3466 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3467 ,(append
3468 '("Selected Project at Startup"
3469 ["None" (progn (customize-set-variable 'vhdl-project nil)
3470 (vhdl-set-project ""))
3471 :style radio :selected (null vhdl-project)]
3472 "--")
3473 ;; add menu entries for defined projects
3474 (let ((project-alist vhdl-project-alist) menu-list name)
3475 (while project-alist
3476 (setq name (caar project-alist))
3477 (setq menu-list
3478 (cons `[,name (progn (customize-set-variable
3479 'vhdl-project ,name)
3480 (vhdl-set-project ,name))
3481 :style radio :selected (equal ,name vhdl-project)]
3482 menu-list))
3483 (setq project-alist (cdr project-alist)))
3484 (setq menu-list (nreverse menu-list))
3485 (vhdl-menu-split menu-list "Project")))
3486 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3487 ("Auto Load Setup File"
3488 ["At Startup"
3489 (customize-set-variable 'vhdl-project-auto-load
3490 (if (memq 'startup vhdl-project-auto-load)
3491 (delq 'startup vhdl-project-auto-load)
3492 (cons 'startup vhdl-project-auto-load)))
3493 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3494 ["Sort Projects"
3495 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3496 :style toggle :selected vhdl-project-sort]
3497 "--"
3498 ["Customize Group..." (customize-group 'vhdl-project) t])
3499 ("Compiler"
3500 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3501 ,(append
3502 '("Selected Compiler at Startup")
3503 ;; add menu entries for defined compilers
3504 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3505 (while comp-alist
3506 (setq name (caar comp-alist))
3507 (setq menu-list
3508 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3509 :style radio :selected (equal ,name vhdl-compiler)]
3510 menu-list))
3511 (setq comp-alist (cdr comp-alist)))
3512 (setq menu-list (nreverse menu-list))
3513 (vhdl-menu-split menu-list "Compler")))
3514 ["Use Local Error Regexp"
3515 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3516 (not vhdl-compile-use-local-error-regexp))
3517 :style toggle :selected vhdl-compile-use-local-error-regexp]
3518 ["Makefile Generation Hook..."
3519 (customize-option 'vhdl-makefile-generation-hook) t]
3520 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3521 "--"
3522 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3523 ("Style"
3524 ("VHDL Standard"
3525 ["VHDL'87"
3526 (progn (customize-set-variable 'vhdl-standard
3527 (list '87 (cadr vhdl-standard)))
3528 (vhdl-activate-customizations))
3529 :style radio :selected (eq '87 (car vhdl-standard))]
3530 ["VHDL'93"
3531 (progn (customize-set-variable 'vhdl-standard
3532 (list '93 (cadr vhdl-standard)))
3533 (vhdl-activate-customizations))
3534 :style radio :selected (eq '93 (car vhdl-standard))]
3535 "--"
3536 ["VHDL-AMS"
3537 (progn (customize-set-variable
3538 'vhdl-standard (list (car vhdl-standard)
3539 (if (memq 'ams (cadr vhdl-standard))
3540 (delq 'ams (cadr vhdl-standard))
3541 (cons 'ams (cadr vhdl-standard)))))
3542 (vhdl-activate-customizations))
3543 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3544 ["Math Packages"
3545 (progn (customize-set-variable
3546 'vhdl-standard (list (car vhdl-standard)
3547 (if (memq 'math (cadr vhdl-standard))
3548 (delq 'math (cadr vhdl-standard))
3549 (cons 'math (cadr vhdl-standard)))))
3550 (vhdl-activate-customizations))
3551 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3552 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3553 ["Upper Case Keywords"
3554 (customize-set-variable 'vhdl-upper-case-keywords
3555 (not vhdl-upper-case-keywords))
3556 :style toggle :selected vhdl-upper-case-keywords]
3557 ["Upper Case Types"
3558 (customize-set-variable 'vhdl-upper-case-types
3559 (not vhdl-upper-case-types))
3560 :style toggle :selected vhdl-upper-case-types]
3561 ["Upper Case Attributes"
3562 (customize-set-variable 'vhdl-upper-case-attributes
3563 (not vhdl-upper-case-attributes))
3564 :style toggle :selected vhdl-upper-case-attributes]
3565 ["Upper Case Enumeration Values"
3566 (customize-set-variable 'vhdl-upper-case-enum-values
3567 (not vhdl-upper-case-enum-values))
3568 :style toggle :selected vhdl-upper-case-enum-values]
3569 ["Upper Case Constants"
3570 (customize-set-variable 'vhdl-upper-case-constants
3571 (not vhdl-upper-case-constants))
3572 :style toggle :selected vhdl-upper-case-constants]
3573 ("Use Direct Instantiation"
3574 ["Never"
3575 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3576 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3577 ["Standard"
3578 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3579 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3580 ["Always"
3581 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3582 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3583 "--"
3584 ["Customize Group..." (customize-group 'vhdl-style) t])
3585 ("Naming"
3586 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3587 ["Architecture File Name..."
3588 (customize-option 'vhdl-architecture-file-name) t]
0a2e512a
RF
3589 ["Configuration File Name..."
3590 (customize-option 'vhdl-configuration-file-name) t]
3dcb36b7
JB
3591 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3592 ("File Name Case"
3593 ["As Is"
3594 (customize-set-variable 'vhdl-file-name-case 'identity)
3595 :style radio :selected (eq 'identity vhdl-file-name-case)]
3596 ["Lower Case"
3597 (customize-set-variable 'vhdl-file-name-case 'downcase)
3598 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3599 ["Upper Case"
3600 (customize-set-variable 'vhdl-file-name-case 'upcase)
3601 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3602 ["Capitalize"
3603 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3604 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3605 "--"
3606 ["Customize Group..." (customize-group 'vhdl-naming) t])
3607 ("Template"
3608 ("Electric Keywords"
3609 ["VHDL Keywords"
3610 (customize-set-variable 'vhdl-electric-keywords
3611 (if (memq 'vhdl vhdl-electric-keywords)
3612 (delq 'vhdl vhdl-electric-keywords)
3613 (cons 'vhdl vhdl-electric-keywords)))
3614 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3615 ["User Model Keywords"
3616 (customize-set-variable 'vhdl-electric-keywords
3617 (if (memq 'user vhdl-electric-keywords)
3618 (delq 'user vhdl-electric-keywords)
3619 (cons 'user vhdl-electric-keywords)))
3620 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3621 ("Insert Optional Labels"
3622 ["None"
3623 (customize-set-variable 'vhdl-optional-labels 'none)
3624 :style radio :selected (eq 'none vhdl-optional-labels)]
3625 ["Processes Only"
3626 (customize-set-variable 'vhdl-optional-labels 'process)
3627 :style radio :selected (eq 'process vhdl-optional-labels)]
3628 ["All Constructs"
3629 (customize-set-variable 'vhdl-optional-labels 'all)
3630 :style radio :selected (eq 'all vhdl-optional-labels)])
3631 ("Insert Empty Lines"
3632 ["None"
3633 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3634 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3635 ["Design Units Only"
3636 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3637 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3638 ["All Constructs"
3639 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3640 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3641 ["Argument List Indent"
3642 (customize-set-variable 'vhdl-argument-list-indent
3643 (not vhdl-argument-list-indent))
3644 :style toggle :selected vhdl-argument-list-indent]
3645 ["Association List with Formals"
3646 (customize-set-variable 'vhdl-association-list-with-formals
3647 (not vhdl-association-list-with-formals))
3648 :style toggle :selected vhdl-association-list-with-formals]
3649 ["Conditions in Parenthesis"
3650 (customize-set-variable 'vhdl-conditions-in-parenthesis
3651 (not vhdl-conditions-in-parenthesis))
3652 :style toggle :selected vhdl-conditions-in-parenthesis]
3653 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3654 ["One String..." (customize-option 'vhdl-one-string) t]
3655 ("File Header"
3656 ["Header String..." (customize-option 'vhdl-file-header) t]
3657 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3658 ["Company Name..." (customize-option 'vhdl-company-name) t]
3659 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3660 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3661 ["Date Format..." (customize-option 'vhdl-date-format) t]
3662 ["Modify Date Prefix String..."
3663 (customize-option 'vhdl-modify-date-prefix-string) t]
3664 ["Modify Date on Saving"
3665 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3666 (not vhdl-modify-date-on-saving))
3667 (vhdl-activate-customizations))
3668 :style toggle :selected vhdl-modify-date-on-saving])
3669 ("Sequential Process"
3670 ("Kind of Reset"
3671 ["None"
3672 (customize-set-variable 'vhdl-reset-kind 'none)
3673 :style radio :selected (eq 'none vhdl-reset-kind)]
3674 ["Synchronous"
3675 (customize-set-variable 'vhdl-reset-kind 'sync)
3676 :style radio :selected (eq 'sync vhdl-reset-kind)]
3677 ["Asynchronous"
3678 (customize-set-variable 'vhdl-reset-kind 'async)
3679 :style radio :selected (eq 'async vhdl-reset-kind)])
3680 ["Reset is Active High"
3681 (customize-set-variable 'vhdl-reset-active-high
3682 (not vhdl-reset-active-high))
3683 :style toggle :selected vhdl-reset-active-high]
3684 ["Use Rising Clock Edge"
3685 (customize-set-variable 'vhdl-clock-rising-edge
3686 (not vhdl-clock-rising-edge))
3687 :style toggle :selected vhdl-clock-rising-edge]
3688 ("Clock Edge Condition"
3689 ["Standard"
3690 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3691 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3692 ["Function \"rising_edge\""
3693 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3694 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3695 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3696 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3697 "--"
3698 ["Customize Group..." (customize-group 'vhdl-template) t])
3699 ("Model"
3700 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3701 ("Port"
3702 ["Include Port Comments"
3703 (customize-set-variable 'vhdl-include-port-comments
3704 (not vhdl-include-port-comments))
3705 :style toggle :selected vhdl-include-port-comments]
3706 ["Include Direction Comments"
3707 (customize-set-variable 'vhdl-include-direction-comments
3708 (not vhdl-include-direction-comments))
3709 :style toggle :selected vhdl-include-direction-comments]
3710 ["Include Type Comments"
3711 (customize-set-variable 'vhdl-include-type-comments
3712 (not vhdl-include-type-comments))
3713 :style toggle :selected vhdl-include-type-comments]
3714 ("Include Group Comments"
3715 ["Never"
3716 (customize-set-variable 'vhdl-include-group-comments 'never)
3717 :style radio :selected (eq 'never vhdl-include-group-comments)]
3718 ["Declarations"
3719 (customize-set-variable 'vhdl-include-group-comments 'decl)
3720 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3721 ["Always"
3722 (customize-set-variable 'vhdl-include-group-comments 'always)
3723 :style radio :selected (eq 'always vhdl-include-group-comments)])
3724 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3725 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3726 ("Testbench"
3727 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3728 ["Architecture Name..."
3729 (customize-option 'vhdl-testbench-architecture-name) t]
3730 ["Configuration Name..."
3731 (customize-option 'vhdl-testbench-configuration-name) t]
3732 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3733 ["Include Header"
3734 (customize-set-variable 'vhdl-testbench-include-header
3735 (not vhdl-testbench-include-header))
3736 :style toggle :selected vhdl-testbench-include-header]
3737 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3738 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3739 ["Initialize Signals"
3740 (customize-set-variable 'vhdl-testbench-initialize-signals
3741 (not vhdl-testbench-initialize-signals))
3742 :style toggle :selected vhdl-testbench-initialize-signals]
3743 ["Include Library Clause"
3744 (customize-set-variable 'vhdl-testbench-include-library
3745 (not vhdl-testbench-include-library))
3746 :style toggle :selected vhdl-testbench-include-library]
3747 ["Include Configuration"
3748 (customize-set-variable 'vhdl-testbench-include-configuration
3749 (not vhdl-testbench-include-configuration))
3750 :style toggle :selected vhdl-testbench-include-configuration]
3751 ("Create Files"
3752 ["None"
3753 (customize-set-variable 'vhdl-testbench-create-files 'none)
3754 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3755 ["Single"
3756 (customize-set-variable 'vhdl-testbench-create-files 'single)
3757 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3758 ["Separate"
3759 (customize-set-variable 'vhdl-testbench-create-files 'separate)
0a2e512a
RF
3760 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3761 ["Testbench Entity File Name..."
3762 (customize-option 'vhdl-testbench-entity-file-name) t]
3763 ["Testbench Architecture File Name..."
3764 (customize-option 'vhdl-testbench-architecture-file-name) t])
3dcb36b7
JB
3765 "--"
3766 ["Customize Group..." (customize-group 'vhdl-port) t])
3767 ("Compose"
0a2e512a
RF
3768 ["Architecture Name..."
3769 (customize-option 'vhdl-compose-architecture-name) t]
3770 ["Configuration Name..."
3771 (customize-option 'vhdl-compose-configuration-name) t]
3772 ["Components Package Name..."
3773 (customize-option 'vhdl-components-package-name) t]
3774 ["Use Components Package"
3775 (customize-set-variable 'vhdl-use-components-package
3776 (not vhdl-use-components-package))
3777 :style toggle :selected vhdl-use-components-package]
3778 ["Include Header"
3779 (customize-set-variable 'vhdl-compose-include-header
3780 (not vhdl-compose-include-header))
3781 :style toggle :selected vhdl-compose-include-header]
3782 ("Create Entity/Architecture Files"
3dcb36b7
JB
3783 ["None"
3784 (customize-set-variable 'vhdl-compose-create-files 'none)
3785 :style radio :selected (eq 'none vhdl-compose-create-files)]
3786 ["Single"
3787 (customize-set-variable 'vhdl-compose-create-files 'single)
3788 :style radio :selected (eq 'single vhdl-compose-create-files)]
3789 ["Separate"
3790 (customize-set-variable 'vhdl-compose-create-files 'separate)
3791 :style radio :selected (eq 'separate vhdl-compose-create-files)])
0a2e512a
RF
3792 ["Create Configuration File"
3793 (customize-set-variable 'vhdl-compose-configuration-create-file
3794 (not vhdl-compose-configuration-create-file))
3795 :style toggle :selected vhdl-compose-configuration-create-file]
3796 ["Hierarchical Configuration"
3797 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3798 (not vhdl-compose-configuration-hierarchical))
3799 :style toggle :selected vhdl-compose-configuration-hierarchical]
3800 ["Use Subconfiguration"
3801 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3802 (not vhdl-compose-configuration-use-subconfiguration))
3803 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3dcb36b7
JB
3804 "--"
3805 ["Customize Group..." (customize-group 'vhdl-compose) t])
3806 ("Comment"
3807 ["Self Insert Comments"
3808 (customize-set-variable 'vhdl-self-insert-comments
3809 (not vhdl-self-insert-comments))
3810 :style toggle :selected vhdl-self-insert-comments]
3811 ["Prompt for Comments"
3812 (customize-set-variable 'vhdl-prompt-for-comments
3813 (not vhdl-prompt-for-comments))
3814 :style toggle :selected vhdl-prompt-for-comments]
3815 ["Inline Comment Column..."
3816 (customize-option 'vhdl-inline-comment-column) t]
3817 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3818 "--"
3819 ["Customize Group..." (customize-group 'vhdl-comment) t])
3820 ("Align"
3821 ["Auto Align Templates"
3822 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3823 :style toggle :selected vhdl-auto-align]
3824 ["Align Line Groups"
3825 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3826 :style toggle :selected vhdl-align-groups]
3827 ["Group Separation String..."
3828 (customize-set-variable 'vhdl-align-group-separate) t]
3829 ["Align Lines with Same Indent"
3830 (customize-set-variable 'vhdl-align-same-indent
3831 (not vhdl-align-same-indent))
3832 :style toggle :selected vhdl-align-same-indent]
3833 "--"
3834 ["Customize Group..." (customize-group 'vhdl-align) t])
3835 ("Highlight"
3836 ["Highlighting On/Off..."
3837 (customize-option
4bcb9c95
SM
3838 (if (fboundp 'global-font-lock-mode)
3839 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3dcb36b7
JB
3840 ["Highlight Keywords"
3841 (progn (customize-set-variable 'vhdl-highlight-keywords
3842 (not vhdl-highlight-keywords))
3843 (vhdl-fontify-buffer))
3844 :style toggle :selected vhdl-highlight-keywords]
3845 ["Highlight Names"
3846 (progn (customize-set-variable 'vhdl-highlight-names
3847 (not vhdl-highlight-names))
3848 (vhdl-fontify-buffer))
3849 :style toggle :selected vhdl-highlight-names]
3850 ["Highlight Special Words"
3851 (progn (customize-set-variable 'vhdl-highlight-special-words
3852 (not vhdl-highlight-special-words))
3853 (vhdl-fontify-buffer))
3854 :style toggle :selected vhdl-highlight-special-words]
3855 ["Highlight Forbidden Words"
3856 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3857 (not vhdl-highlight-forbidden-words))
3858 (vhdl-fontify-buffer))
3859 :style toggle :selected vhdl-highlight-forbidden-words]
3860 ["Highlight Verilog Keywords"
3861 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3862 (not vhdl-highlight-verilog-keywords))
3863 (vhdl-fontify-buffer))
3864 :style toggle :selected vhdl-highlight-verilog-keywords]
3865 ["Highlight \"translate_off\""
3866 (progn (customize-set-variable 'vhdl-highlight-translate-off
3867 (not vhdl-highlight-translate-off))
3868 (vhdl-fontify-buffer))
3869 :style toggle :selected vhdl-highlight-translate-off]
3870 ["Case Sensitive Highlighting"
3871 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3872 (not vhdl-highlight-case-sensitive))
3873 (vhdl-fontify-buffer))
3874 :style toggle :selected vhdl-highlight-case-sensitive]
3875 ["Special Syntax Definition..."
3876 (customize-option 'vhdl-special-syntax-alist) t]
3877 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3878 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3879 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3880 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3881 "--"
3882 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3883 ("Speedbar"
3884 ["Auto Open at Startup"
3885 (customize-set-variable 'vhdl-speedbar-auto-open
3886 (not vhdl-speedbar-auto-open))
3887 :style toggle :selected vhdl-speedbar-auto-open]
3888 ("Default Displaying Mode"
3889 ["Files"
3890 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3891 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3892 ["Directory Hierarchy"
3893 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3894 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3895 ["Project Hierarchy"
3896 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3897 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3898 ["Indentation Offset..."
3899 (customize-option 'speedbar-indentation-width) t]
3900 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3901 ["Jump to Unit when Opening"
3902 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3903 (not vhdl-speedbar-jump-to-unit))
3904 :style toggle :selected vhdl-speedbar-jump-to-unit]
3905 ["Update Hierarchy on File Saving"
3906 (customize-set-variable 'vhdl-speedbar-update-on-saving
3907 (not vhdl-speedbar-update-on-saving))
3908 :style toggle :selected vhdl-speedbar-update-on-saving]
3909 ("Save in Cache File"
3910 ["Hierarchy Information"
3911 (customize-set-variable 'vhdl-speedbar-save-cache
3912 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3913 (delq 'hierarchy vhdl-speedbar-save-cache)
3914 (cons 'hierarchy vhdl-speedbar-save-cache)))
3915 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3916 ["Displaying Status"
3917 (customize-set-variable 'vhdl-speedbar-save-cache
3918 (if (memq 'display vhdl-speedbar-save-cache)
3919 (delq 'display vhdl-speedbar-save-cache)
3920 (cons 'display vhdl-speedbar-save-cache)))
3921 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3922 ["Cache File Name..."
3923 (customize-option 'vhdl-speedbar-cache-file-name) t]
3924 "--"
3925 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3926 ("Menu"
3927 ["Add Index Menu when Loading File"
3928 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3929 (vhdl-index-menu-init))
3930 :style toggle :selected vhdl-index-menu]
3931 ["Add Source File Menu when Loading File"
3932 (progn (customize-set-variable 'vhdl-source-file-menu
3933 (not vhdl-source-file-menu))
3934 (vhdl-add-source-files-menu))
3935 :style toggle :selected vhdl-source-file-menu]
3936 ["Add Hideshow Menu at Startup"
3937 (progn (customize-set-variable 'vhdl-hideshow-menu
3938 (not vhdl-hideshow-menu))
3939 (vhdl-activate-customizations))
3940 :style toggle :selected vhdl-hideshow-menu]
3941 ["Hide Everything Initially"
3942 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3943 :style toggle :selected vhdl-hide-all-init]
3944 "--"
3945 ["Customize Group..." (customize-group 'vhdl-menu) t])
3946 ("Print"
3947 ["In Two Column Format"
3948 (progn (customize-set-variable 'vhdl-print-two-column
3949 (not vhdl-print-two-column))
3950 (message "Activate new setting by saving options and restarting Emacs"))
3951 :style toggle :selected vhdl-print-two-column]
3952 ["Use Customized Faces"
3953 (progn (customize-set-variable 'vhdl-print-customize-faces
3954 (not vhdl-print-customize-faces))
3955 (message "Activate new setting by saving options and restarting Emacs"))
3956 :style toggle :selected vhdl-print-customize-faces]
3957 "--"
3958 ["Customize Group..." (customize-group 'vhdl-print) t])
3959 ("Miscellaneous"
3960 ["Use Intelligent Tab"
3961 (progn (customize-set-variable 'vhdl-intelligent-tab
3962 (not vhdl-intelligent-tab))
3963 (vhdl-activate-customizations))
3964 :style toggle :selected vhdl-intelligent-tab]
3965 ["Indent Syntax-Based"
3966 (customize-set-variable 'vhdl-indent-syntax-based
3967 (not vhdl-indent-syntax-based))
3968 :style toggle :selected vhdl-indent-syntax-based]
3969 ["Word Completion is Case Sensitive"
3970 (customize-set-variable 'vhdl-word-completion-case-sensitive
3971 (not vhdl-word-completion-case-sensitive))
3972 :style toggle :selected vhdl-word-completion-case-sensitive]
3973 ["Word Completion in Minibuffer"
3974 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3975 (not vhdl-word-completion-in-minibuffer))
3976 (message "Activate new setting by saving options and restarting Emacs"))
3977 :style toggle :selected vhdl-word-completion-in-minibuffer]
3978 ["Underscore is Part of Word"
3979 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3980 (not vhdl-underscore-is-part-of-word))
3981 (vhdl-activate-customizations))
3982 :style toggle :selected vhdl-underscore-is-part-of-word]
3983 "--"
3984 ["Customize Group..." (customize-group 'vhdl-misc) t])
3985 ["Related..." (customize-browse 'vhdl-related) t]
d2ddb974 3986 "--"
3dcb36b7
JB
3987 ["Save Options" customize-save-customized t]
3988 ["Activate Options" vhdl-activate-customizations t]
3989 ["Browse Options..." vhdl-customize t])))
5eabfe72
KH
3990
3991(defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3992 "VHDL Mode menu.")
3993
3994(defun vhdl-update-mode-menu ()
3dcb36b7 3995 "Update VHDL Mode menu."
5eabfe72
KH
3996 (interactive)
3997 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
3998 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
3999 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4000 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4001 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
d2ddb974 4002
5eabfe72
KH
4003;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4004;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
d2ddb974 4005
3dcb36b7 4006(defconst vhdl-imenu-generic-expression
d2ddb974 4007 '(
5eabfe72
KH
4008 ("Subprogram"
4009 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4010 4)
4011 ("Instance"
4012 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4013 1)
4014 ("Component"
4015 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4016 2)
5eabfe72
KH
4017 ("Procedural"
4018 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4019 1)
4020 ("Process"
4021 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4022 1)
4023 ("Block"
4024 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4025 1)
4026 ("Package"
4027 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4028 3)
d2ddb974
KH
4029 ("Configuration"
4030 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4031 2)
5eabfe72
KH
4032 ("Architecture"
4033 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4034 2)
5eabfe72
KH
4035 ("Entity"
4036 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4037 2)
d2ddb974
KH
4038 )
4039 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4040
5eabfe72
KH
4041(defun vhdl-index-menu-init ()
4042 "Initialize index menu."
4043 (set (make-local-variable 'imenu-case-fold-search) t)
4044 (set (make-local-variable 'imenu-generic-expression)
4045 vhdl-imenu-generic-expression)
3dcb36b7 4046 (when (and vhdl-index-menu (fboundp 'imenu))
5eabfe72
KH
4047 (if (or (not (boundp 'font-lock-maximum-size))
4048 (> font-lock-maximum-size (buffer-size)))
4049 (imenu-add-to-menubar "Index")
4050 (message "Scanning buffer for index...buffer too big"))))
d2ddb974 4051
3dcb36b7 4052;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
4053;; Source file menu (using `easy-menu.el')
4054
5eabfe72
KH
4055(defvar vhdl-sources-menu nil)
4056
4057(defun vhdl-directory-files (directory &optional full match)
4058 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4059message."
3dcb36b7
JB
4060 (if (not (file-directory-p directory))
4061 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4062 (let ((dir (directory-files directory full match)))
4063 (setq dir (delete "." dir))
4064 (setq dir (delete ".." dir))
4065 dir)))
5eabfe72
KH
4066
4067(defun vhdl-get-source-files (&optional full directory)
4068 "Get list of VHDL source files in DIRECTORY or current directory."
4069 (let ((mode-alist auto-mode-alist)
4070 filename-regexp)
4071 ;; create regular expressions for matching file names
3dcb36b7 4072 (setq filename-regexp "\\`[^.].*\\(")
5eabfe72 4073 (while mode-alist
3dcb36b7 4074 (when (eq (cdar mode-alist) 'vhdl-mode)
5eabfe72 4075 (setq filename-regexp
3dcb36b7 4076 (concat filename-regexp (caar mode-alist) "\\|")))
5eabfe72
KH
4077 (setq mode-alist (cdr mode-alist)))
4078 (setq filename-regexp
4079 (concat (substring filename-regexp 0
4080 (string-match "\\\\|$" filename-regexp)) "\\)"))
4081 ;; find files
3dcb36b7
JB
4082 (vhdl-directory-files
4083 (or directory default-directory) full filename-regexp)))
d2ddb974
KH
4084
4085(defun vhdl-add-source-files-menu ()
5eabfe72
KH
4086 "Scan directory for all VHDL source files and generate menu.
4087The directory of the current source file is scanned."
d2ddb974
KH
4088 (interactive)
4089 (message "Scanning directory for source files ...")
5eabfe72 4090 (let ((newmap (current-local-map))
5eabfe72
KH
4091 (file-list (vhdl-get-source-files))
4092 menu-list found)
4093 ;; Create list for menu
4094 (setq found nil)
4095 (while file-list
4096 (setq found t)
4097 (setq menu-list (cons (vector (car file-list)
4098 (list 'find-file (car file-list)) t)
4099 menu-list))
4100 (setq file-list (cdr file-list)))
3dcb36b7 4101 (setq menu-list (vhdl-menu-split menu-list "Sources"))
5eabfe72
KH
4102 (when found (setq menu-list (cons "--" menu-list)))
4103 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4104 (setq menu-list (cons "Sources" menu-list))
d2ddb974 4105 ;; Create menu
5eabfe72
KH
4106 (easy-menu-add menu-list)
4107 (easy-menu-define vhdl-sources-menu newmap
4108 "VHDL source files menu" menu-list))
d2ddb974
KH
4109 (message ""))
4110
d2ddb974 4111
5eabfe72 4112;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4113;;; Mode definition
5eabfe72
KH
4114;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4115;; performs all buffer local initializations
4116
1c36bac6 4117;;;###autoload
175069ef
SM
4118(define-derived-mode vhdl-mode prog-mode
4119 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4120 (vhdl-electric-mode "e")
4121 (vhdl-stutter-mode "s"))
d2ddb974
KH
4122 "Major mode for editing VHDL code.
4123
4124Usage:
4125------
4126
3dcb36b7
JB
4127 TEMPLATE INSERTION (electrification):
4128 After typing a VHDL keyword and entering `SPC', you are prompted for
4129 arguments while a template is generated for that VHDL construct. Typing
4130 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4131 template generation. Optional arguments are indicated by square
4132 brackets and removed if the queried string is left empty. Prompts for
4133 mandatory arguments remain in the code if the queried string is left
4134 empty. They can be queried again by `C-c C-t C-q'. Enabled
4135 electrification is indicated by `/e' in the modeline.
4136
4137 Typing `M-SPC' after a keyword inserts a space without calling the
4138 template generator. Automatic template generation (i.e.
4139 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4140 setting option `vhdl-electric-mode' (see OPTIONS).
4141
4142 Template generators can be invoked from the VHDL menu, by key
4143 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4144 the keyword (i.e. first word of menu entry not in parenthesis) and
4145 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4146 conf, comp, cons, func, inst, pack, sig, var.
4147
4148 Template styles can be customized in customization group
4149 `vhdl-template' \(see OPTIONS).
4150
4151
4152 HEADER INSERTION:
4153 A file header can be inserted by `C-c C-t C-h'. A file footer
4154 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4155 See customization group `vhdl-header'.
4156
4157
4158 STUTTERING:
4159 Double striking of some keys inserts cumbersome VHDL syntax elements.
4160 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4161 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4162 the modeline. The stuttering keys and their effects are:
4163
4164 ;; --> \" : \" [ --> ( -- --> comment
4165 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4166 .. --> \" => \" ] --> ) --- --> horizontal line
4167 ,, --> \" <= \" ]] --> ] ---- --> display comment
4168 == --> \" == \" '' --> \\\"
4169
4170
4171 WORD COMPLETION:
4172 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4173 word in the buffer that starts alike, inserts it and adjusts case.
4174 Re-typing `TAB' toggles through alternative word completions. This also
4175 works in the minibuffer (i.e. in template generator prompts).
4176
4177 Typing `TAB' after `(' looks for and inserts complete parenthesized
4178 expressions (e.g. for array index ranges). All keywords as well as
4179 standard types and subprograms of VHDL have predefined abbreviations
4180 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4181 beginning with \"std\").
4182
4183 Typing `TAB' after a non-word character indents the line if at the
4184 beginning of a line (i.e. no preceding non-blank characters), and
4185 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4186 stop.
4187
4188
4189 COMMENTS:
4190 `--' puts a single comment.
4191 `---' draws a horizontal line for separating code segments.
4192 `----' inserts a display comment, i.e. two horizontal lines
4193 with a comment in between.
4194 `--CR' comments out code on that line. Re-hitting CR comments
4195 out following lines.
4196 `C-c c' comments out a region if not commented out,
4197 uncomments a region if already commented out.
4198
4199 You are prompted for comments after object definitions (i.e. signals,
4200 variables, constants, ports) and after subprogram and process
4201 specifications if option `vhdl-prompt-for-comments' is non-nil.
4202 Comments are automatically inserted as additional labels (e.g. after
4203 begin statements) and as help comments if `vhdl-self-insert-comments' is
4204 non-nil.
4205
4206 Inline comments (i.e. comments after a piece of code on the same line)
4207 are indented at least to `vhdl-inline-comment-column'. Comments go at
4208 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4209 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4210 in a comment automatically opens a new comment line. `M-q' re-fills
4211 multi-line comments.
4212
4213
4214 INDENTATION:
4215 `TAB' indents a line if at the beginning of the line. The amount of
4216 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4217 always indents the current line (is bound to `TAB' if option
4218 `vhdl-intelligent-tab' is nil).
4219
4220 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4221 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4222 indented normally (nil) or relative to the opening parenthesis (non-nil)
4223 according to option `vhdl-argument-list-indent'.
4224
4225 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4226 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4227 and vice versa.
4228
4229 Syntax-based indentation can be very slow in large files. Option
4230 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4231
4232
4233 ALIGNMENT:
4234 The alignment functions align operators, keywords, and inline comments
4235 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4236 separated by blank lines, `C-c C-a C-i' a block of lines with same
4237 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4238 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4239 C-a C-d' all lines within the declarative part of a design unit. `C-c
4240 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4241 for a group of lines, and `C-c C-a M-c' for a region.
4242
4243 If option `vhdl-align-groups' is non-nil, groups of code lines
4244 separated by special lines (see option `vhdl-align-group-separate') are
4245 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4246 blocks of lines with same indent are aligned separately. Some templates
4247 are automatically aligned after generation if option `vhdl-auto-align'
4248 is non-nil.
4249
4250 Alignment tries to align inline comments at
4251 `vhdl-inline-comment-column' and tries inline comment not to exceed
4252 `vhdl-end-comment-column'.
4253
4254 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4255 symbols are surrounded by one space, and multiple spaces are eliminated.
4256
4257
0a2e512a
RF
4258 CODE FILLING:
4259 Code filling allows to condense code (e.g. sensitivity lists or port
4260 maps) by removing comments and newlines and re-wrapping so that all
4261 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4262 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4263 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4264 `C-c C-f M-f' an entire region.
3dcb36b7
JB
4265
4266
4267 CODE BEAUTIFICATION:
4268 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4269 buffer respectively. This inludes indentation, alignment, and case
4270 fixing. Code beautification can also be run non-interactively using the
4271 command:
4272
4273 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4274
4275
4276 PORT TRANSLATION:
4277 Generic and port clauses from entity or component declarations can be
4278 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4279 as component instantiations and corresponding internal constants and
4280 signals, as a generic map with constants as actual generics, and as
4281 internal signal initializations (menu).
4282
4283 To include formals in component instantiations, see option
4284 `vhdl-association-list-with-formals'. To include comments in pasting,
4285 see options `vhdl-include-...-comments'.
4286
4287 A clause with several generic/port names on the same line can be
4288 flattened (`C-c C-p C-f') so that only one name per line exists. The
0a2e512a
RF
4289 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4290 outputs and vice versa, which can be useful in testbenches. (This
4291 reversion is done on the internal data structure and is only reflected
4292 in subsequent paste operations.)
3dcb36b7
JB
4293
4294 Names for actual ports, instances, testbenches, and
4295 design-under-test instances can be derived from existing names according
4296 to options `vhdl-...-name'. See customization group `vhdl-port'.
4297
4298
0a2e512a
RF
4299 SUBPROGRAM TRANSLATION:
4300 Similar functionality exists for copying/pasting the interface of
4301 subprograms (function/procedure). A subprogram interface can be copied
4302 and then pasted as a subprogram declaration, body or call (uses
4303 association list with formals).
3dcb36b7
JB
4304
4305
4306 TESTBENCH GENERATION:
4307 A copied port can also be pasted as a testbench. The generated
4308 testbench includes an entity, an architecture, and an optional
4309 configuration. The architecture contains the component declaration and
4310 instantiation of the DUT as well as internal constant and signal
4311 declarations. Additional user-defined templates can be inserted. The
4312 names used for entity/architecture/configuration/DUT as well as the file
4313 structure to be generated can be customized. See customization group
4314 `vhdl-testbench'.
4315
4316
4317 KEY BINDINGS:
4318 Key bindings (`C-c ...') exist for most commands (see in menu).
4319
4320
4321 VHDL MENU:
4322 All commands can be found in the VHDL menu including their key bindings.
4323
4324
4325 FILE BROWSER:
4326 The speedbar allows browsing of directories and file contents. It can
4327 be accessed from the VHDL menu and is automatically opened if option
4328 `vhdl-speedbar-auto-open' is non-nil.
4329
4330 In speedbar, open files and directories with `mouse-2' on the name and
4331 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4332
4333
4334 DESIGN HIERARCHY BROWSER:
4335 The speedbar can also be used for browsing the hierarchy of design units
4336 contained in the source files of the current directory or the specified
4337 projects (see option `vhdl-project-alist').
4338
4339 The speedbar can be switched between file, directory hierarchy and
4340 project hierarchy browsing mode in the speedbar menu or by typing `f',
4341 `h' or `H' in speedbar.
4342
4343 In speedbar, open design units with `mouse-2' on the name and browse
4344 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4345 from entities and components (in packages). Individual design units and
4346 complete designs can directly be compiled (\"Make\" menu entry).
4347
4348 The hierarchy is automatically updated upon saving a modified source
4349 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4350 hierarchy is only updated for projects that have been opened once in the
4351 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4352 options in group `vhdl-speedbar').
4353
4354 Simple design consistency checks are done during scanning, such as
4355 multiple declarations of the same unit or missing primary units that are
4356 required by secondary units.
4357
4358
0a2e512a
RF
4359 STRUCTURAL COMPOSITION:
4360 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4361 for a new component. Subcomponents (i.e. component declaration and
4362 instantiation) can be automatically placed from a previously read port
4363 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4364 all subcomponents can be automatically connected using internal signals
4365 and ports (`C-c C-c C-w') following these rules:
4366 - subcomponent actual ports with same name are considered to be
4367 connected by a signal (internal signal or port)
4368 - signals that are only inputs to subcomponents are considered as
4369 inputs to this component -> input port created
4370 - signals that are only outputs from subcomponents are considered as
4371 outputs from this component -> output port created
4372 - signals that are inputs to AND outputs from subcomponents are
4373 considered as internal connections -> internal signal created
84c98ace 4374
0a2e512a
RF
4375 Purpose: With appropriate naming conventions it is possible to
4376 create higher design levels with only a few mouse clicks or key
4377 strokes. A new design level can be created by simply generating a new
4378 component, placing the required subcomponents from the hierarchy
4379 browser, and wiring everything automatically.
84c98ace 4380
0a2e512a
RF
4381 Note: Automatic wiring only works reliably on templates of new
4382 components and component instantiations that were created by VHDL mode.
84c98ace 4383
0a2e512a
RF
4384 Component declarations can be placed in a components package (option
4385 `vhdl-use-components-package') which can be automatically generated for
4386 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4387 component instantiation is also supported (option
4388 `vhdl-use-direct-instantiation').
4389
4390| Configuration declarations can automatically be generated either from
4391| the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4392| the speedbar menu (for the architecture under the cursor). The
4393| configurations can optionally be hierarchical (i.e. include all
4394| component levels of a hierarchical design, option
4395| `vhdl-compose-configuration-hierarchical') or include subconfigurations
4396| (option `vhdl-compose-configuration-use-subconfiguration'). For
4397| subcomponents in hierarchical configurations, the most-recently-analyzed
4398| (mra) architecture is selected. If another architecture is desired, it
4399| can be marked as most-recently-analyzed (speedbar menu) before
4400| generating the configuration.
3dcb36b7 4401|
0a2e512a
RF
4402| Note: Configurations of subcomponents (i.e. hierarchical configuration
4403| declarations) are currently not considered when displaying
4404| configurations in speedbar.
84c98ace 4405
0a2e512a 4406 See the options group `vhdl-compose' for all relevant user options.
3dcb36b7
JB
4407
4408
4409 SOURCE FILE COMPILATION:
4410 The syntax of the current buffer can be analyzed by calling a VHDL
4411 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4412 option `vhdl-compiler'. The available compilers are listed in option
4413 `vhdl-compiler-alist' including all required compilation command,
4414 command options, compilation directory, and error message syntax
4415 information. New compilers can be added.
4416
4417 All the source files of an entire design can be compiled by the `make'
4418 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4419
4420
4421 MAKEFILE GENERATION:
4422 Makefiles can be generated automatically by an internal generation
4423 routine (`C-c M-k'). The library unit dependency information is
4424 obtained from the hierarchy browser. Makefile generation can be
4425 customized for each compiler in option `vhdl-compiler-alist'.
4426
4427 Makefile generation can also be run non-interactively using the
4428 command:
4429
4430 emacs -batch -l ~/.emacs -l vhdl-mode
4431 [-compiler compilername] [-project projectname]
4432 -f vhdl-generate-makefile
4433
4434 The Makefile's default target \"all\" compiles the entire design, the
4435 target \"clean\" removes it and the target \"library\" creates the
4436 library directory if not existent. The Makefile also includes a target
4437 for each primary library unit which allows selective compilation of this
4438 unit, its secondary units and its subhierarchy (example: compilation of
4439 a design specified by a configuration). User specific parts can be
4440 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4441
4442 Limitations:
4443 - Only library units and dependencies within the current library are
4444 considered. Makefiles for designs that span multiple libraries are
4445 not (yet) supported.
4446 - Only one-level configurations are supported (also hierarchical),
4447 but configurations that go down several levels are not.
4448 - The \"others\" keyword in configurations is not supported.
4449
4450
4451 PROJECTS:
4452 Projects can be defined in option `vhdl-project-alist' and a current
4453 project be selected using option `vhdl-project' (permanently) or from
4454 the menu or speedbar (temporarily). For each project, title and
4455 description strings (for the file headers), source files/directories
4456 (for the hierarchy browser and Makefile generation), library name, and
4457 compiler-dependent options, exceptions and compilation directory can be
4458 specified. Compilation settings overwrite the settings of option
4459 `vhdl-compiler-alist'.
4460
4461 Project setups can be exported (i.e. written to a file) and imported.
4462 Imported setups are not automatically saved in `vhdl-project-alist' but
4463 can be saved afterwards in its customization buffer. When starting
4464 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4465 vhdl-mode\") in a directory with an existing project setup file, it is
4466 automatically loaded and its project activated if option
4467 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4468 files can be specified in option `vhdl-project-file-name'. Multiple
4469 project setups can be automatically loaded from global directories.
4470 This is an alternative to specifying project setups with option
4471 `vhdl-project-alist'.
4472
4473
4474 SPECIAL MENUES:
4475 As an alternative to the speedbar, an index menu can be added (set
4476 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4477 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4478 file) for browsing the file contents (is not populated if buffer is
4479 larger than `font-lock-maximum-size'). Also, a source file menu can be
4480 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4481 current directory for VHDL source files.
4482
4483
4484 VHDL STANDARDS:
4485 The VHDL standards to be used are specified in option `vhdl-standard'.
4486 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4487
4488
4489 KEYWORD CASE:
4490 Lower and upper case for keywords and standardized types, attributes,
4491 and enumeration values is supported. If the option
4492 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4493 lower case and are converted into upper case automatically (not for
4494 types, attributes, and enumeration values). The case of keywords,
4495 types, attributes,and enumeration values can be fixed for an entire
4496 region (menu) or buffer (`C-c C-x C-c') according to the options
4497 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4498
4499
4500 HIGHLIGHTING (fontification):
4501 Keywords and standardized types, attributes, enumeration values, and
4502 function names (controlled by option `vhdl-highlight-keywords'), as well
4503 as comments, strings, and template prompts are highlighted using
4504 different colors. Unit, subprogram, signal, variable, constant,
4505 parameter and generic/port names in declarations as well as labels are
4506 highlighted if option `vhdl-highlight-names' is non-nil.
4507
4508 Additional reserved words or words with a forbidden syntax (e.g. words
4509 that should be avoided) can be specified in option
4510 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4511 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4512 keywords are highlighted as forbidden words if option
4513 `vhdl-highlight-verilog-keywords' is non-nil.
4514
4515 Words with special syntax can be highlighted by specifying their
4516 syntax and color in option `vhdl-special-syntax-alist' and by setting
4517 option `vhdl-highlight-special-words' to non-nil. This allows to
4518 establish some naming conventions (e.g. to distinguish different kinds
4519 of signals or other objects by using name suffices) and to support them
4520 visually.
4521
4522 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4523 to support case-sensitive highlighting. However, keywords are then only
4524 highlighted if written in lower case.
4525
4526 Code between \"translate_off\" and \"translate_on\" pragmas is
4527 highlighted using a different background color if option
4528 `vhdl-highlight-translate-off' is non-nil.
4529
4530 For documentation and customization of the used colors see
4531 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4532 highlighting of matching parenthesis, see customization group
4533 `paren-showing'. Automatic buffer highlighting is turned on/off by
4534 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4535
4536
4537 USER MODELS:
4538 VHDL models (templates) can be specified by the user and made accessible
4539 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4540 electrification. See option `vhdl-model-alist'.
4541
4542
4543 HIDE/SHOW:
4544 The code of blocks, processes, subprograms, component declarations and
4545 instantiations, generic/port clauses, and configuration declarations can
4546 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4547 the code (see customization group `vhdl-menu'). XEmacs: limited
4548 functionality due to old `hideshow.el' package.
4549
4550
4551 CODE UPDATING:
4552 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4553 current process, `C-c C-u M-s' of all processes in the current buffer.
4554 Limitations:
4555 - Only declared local signals (ports, signals declared in
4556 architecture and blocks) are automatically inserted.
4557 - Global signals declared in packages are not automatically inserted.
4558 Insert them once manually (will be kept afterwards).
4559 - Out parameters of procedures are considered to be read.
4560 Use option `vhdl-entity-file-name' to specify the entity file name
4561 \(used to obtain the port names).
4562
4563
4564 CODE FIXING:
4565 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4566 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4567
4568
4569 PRINTING:
4570 Postscript printing with different faces (an optimized set of faces is
4571 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4572 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4573 postscript printing commands. Option `vhdl-print-two-column' defines
4574 appropriate default settings for nice landscape two-column printing.
4575 The paper format can be set by option `ps-paper-type'. Do not forget to
4576 switch `ps-print-color-p' to nil for printing on black-and-white
4577 printers.
4578
4579
4580 OPTIONS:
4581 User options allow customization of VHDL Mode. All options are
4582 accessible from the \"Options\" menu entry. Simple options (switches
4583 and choices) can directly be changed, while for complex options a
4584 customization buffer is opened. Changed options can be saved for future
4585 sessions using the \"Save Options\" menu entry.
4586
4587 Options and their detailed descriptions can also be accessed by using
4588 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4589 customize-group' for groups). Some customizations only take effect
4590 after some action (read the NOTE in the option documentation).
4591 Customization can also be done globally (i.e. site-wide, read the
4592 INSTALL file).
4593
4594 Not all options are described in this documentation, so go and see
4595 what other useful user options there are (`M-x vhdl-customize' or menu)!
4596
4597
4598 FILE EXTENSIONS:
4599 As default, files with extensions \".vhd\" and \".vhdl\" are
4600 automatically recognized as VHDL source files. To add an extension
4601 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4602
4603 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4604
4605
4606 HINTS:
4607 - To start Emacs with open VHDL hierarchy browser without having to load
4608 a VHDL file first, use the command:
4609
4610 emacs -l vhdl-mode -f speedbar-frame-mode
4611
4612 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4613
4614 - Some features only work on properly indented code.
4615
4616
4617 RELEASE NOTES:
4618 See also the release notes (menu) for added features in new releases.
d2ddb974
KH
4619
4620
4621Maintenance:
4622------------
4623
3dcb36b7 4624To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
d2ddb974
KH
4625Add a description of the problem and include a reproducible test case.
4626
3dcb36b7 4627Questions and enhancement requests can be sent to <reto@gnu.org>.
d2ddb974
KH
4628
4629The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
3dcb36b7
JB
4630The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4631releases. You are kindly invited to participate in beta testing. Subscribe
4632to above mailing lists by sending an email to <reto@gnu.org>.
d2ddb974 4633
3dcb36b7 4634VHDL Mode is officially distributed at
855b42a2 4635URL `http://opensource.ethz.ch/emacs/vhdl-mode.html'
3dcb36b7 4636where the latest version can be found.
d2ddb974
KH
4637
4638
3dcb36b7
JB
4639Known problems:
4640---------------
d2ddb974 4641
5eabfe72 4642- Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
3dcb36b7
JB
4643- XEmacs: Incorrect start-up when automatically opening speedbar.
4644- XEmacs: Indentation in XEmacs 21.4 (and higher).
d2ddb974
KH
4645
4646
3dcb36b7
JB
4647 The VHDL Mode Authors
4648 Reto Zimmermann and Rod Whitby
5eabfe72 4649
d2ddb974
KH
4650Key bindings:
4651-------------
4652
4653\\{vhdl-mode-map}"
175069ef 4654 :abbrev-table vhdl-mode-abbrev-table
5eabfe72 4655
3dcb36b7 4656 ;; set local variables
5eabfe72
KH
4657 (set (make-local-variable 'paragraph-start)
4658 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
d2ddb974
KH
4659 (set (make-local-variable 'paragraph-separate) paragraph-start)
4660 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
d2ddb974
KH
4661 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4662 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4663 (set (make-local-variable 'comment-start) "--")
4664 (set (make-local-variable 'comment-end) "")
0a2e512a
RF
4665 (when vhdl-emacs-21
4666 (set (make-local-variable 'comment-padding) ""))
5eabfe72 4667 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
d2ddb974
KH
4668 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4669 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
5eabfe72 4670 (set (make-local-variable 'comment-multi-line) nil)
d2ddb974 4671 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
5eabfe72 4672 (set (make-local-variable 'hippie-expand-verbose) nil)
d2ddb974
KH
4673
4674 ;; setup the comment indent variable in a Emacs version portable way
4675 ;; ignore any byte compiler warnings you might get here
5eabfe72 4676 (when (boundp 'comment-indent-function)
175069ef 4677 (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
d2ddb974
KH
4678
4679 ;; initialize font locking
5eabfe72
KH
4680 (set (make-local-variable 'font-lock-defaults)
4681 (list
3dcb36b7 4682 '(nil vhdl-font-lock-keywords) nil
cf38dd42
SM
4683 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
4684 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
4685 (set (make-local-variable 'syntax-propertize-function)
4686 (syntax-propertize-rules
4687 ;; Mark single quotes as having string quote syntax in
4688 ;; 'c' instances.
4689 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4690 (set (make-local-variable 'font-lock-syntactic-keywords)
4691 vhdl-font-lock-syntactic-keywords))
3dcb36b7
JB
4692 (unless vhdl-emacs-21
4693 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4694 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4695 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4696; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4697 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4698; (turn-on-font-lock)
d2ddb974
KH
4699
4700 ;; variables for source file compilation
3dcb36b7
JB
4701 (when vhdl-compile-use-local-error-regexp
4702 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4703 (set (make-local-variable 'compilation-file-regexp-alist) nil))
5eabfe72
KH
4704
4705 ;; add index menu
4706 (vhdl-index-menu-init)
4707 ;; add source file menu
d2ddb974 4708 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
5eabfe72
KH
4709 ;; add VHDL menu
4710 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4711 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4712 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4713 ;; initialize hideshow and add menu
5eabfe72 4714 (vhdl-hideshow-init)
d2ddb974
KH
4715 (run-hooks 'menu-bar-update-hook)
4716
5eabfe72
KH
4717 ;; miscellaneous
4718 (vhdl-ps-print-init)
3dcb36b7 4719 (vhdl-write-file-hooks-init)
3dcb36b7 4720 (message "VHDL Mode %s.%s" vhdl-version
175069ef 4721 (if noninteractive "" " See menu for documentation and release notes.")))
5eabfe72
KH
4722
4723(defun vhdl-activate-customizations ()
4724 "Activate all customizations on local variables."
4725 (interactive)
4726 (vhdl-mode-map-init)
4727 (use-local-map vhdl-mode-map)
4728 (set-syntax-table vhdl-mode-syntax-table)
4729 (setq comment-column vhdl-inline-comment-column)
4730 (setq end-comment-column vhdl-end-comment-column)
3dcb36b7 4731 (vhdl-write-file-hooks-init)
5eabfe72
KH
4732 (vhdl-update-mode-menu)
4733 (vhdl-hideshow-init)
56eb0904 4734 (run-hooks 'menu-bar-update-hook))
5eabfe72 4735
3dcb36b7
JB
4736(defun vhdl-write-file-hooks-init ()
4737 "Add/remove hooks when buffer is saved."
5eabfe72 4738 (if vhdl-modify-date-on-saving
175069ef
SM
4739 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
4740 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
4741 (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
4742 (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
3dcb36b7
JB
4743
4744(defun vhdl-process-command-line-option (option)
4745 "Process command line options for VHDL Mode."
4746 (cond
4747 ;; set compiler
4748 ((equal option "-compiler")
4749 (vhdl-set-compiler (car command-line-args-left))
4750 (setq command-line-args-left (cdr command-line-args-left)))
4751 ;; set project
4752 ((equal option "-project")
4753 (vhdl-set-project (car command-line-args-left))
4754 (setq command-line-args-left (cdr command-line-args-left)))))
4755
4756;; make Emacs process VHDL Mode options
4757(setq command-switch-alist
4758 (append command-switch-alist
4759 '(("-compiler" . vhdl-process-command-line-option)
4760 ("-project" . vhdl-process-command-line-option))))
5eabfe72
KH
4761
4762
4763;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4764;;; Keywords and standardized words
5eabfe72
KH
4765;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4766
3dcb36b7
JB
4767(defconst vhdl-93-keywords
4768 '(
4769 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4770 "assert" "attribute"
4771 "begin" "block" "body" "buffer" "bus"
4772 "case" "component" "configuration" "constant"
4773 "disconnect" "downto"
4774 "else" "elsif" "end" "entity" "exit"
4775 "file" "for" "function"
4776 "generate" "generic" "group" "guarded"
4777 "if" "impure" "in" "inertial" "inout" "is"
4778 "label" "library" "linkage" "literal" "loop"
4779 "map" "mod"
4780 "nand" "new" "next" "nor" "not" "null"
4781 "of" "on" "open" "or" "others" "out"
4782 "package" "port" "postponed" "procedure" "process" "pure"
4783 "range" "record" "register" "reject" "rem" "report" "return"
4784 "rol" "ror"
4785 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4786 "then" "to" "transport" "type"
4787 "unaffected" "units" "until" "use"
4788 "variable"
4789 "wait" "when" "while" "with"
4790 "xnor" "xor"
4791 )
4792 "List of VHDL'93 keywords.")
d2ddb974 4793
5eabfe72
KH
4794(defconst vhdl-ams-keywords
4795 '(
4796 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4797 "reference" "spectrum" "subnature" "terminal" "through"
4798 "tolerance"
4799 )
4800 "List of VHDL-AMS keywords.")
d2ddb974 4801
5eabfe72
KH
4802(defconst vhdl-verilog-keywords
4803 '(
4804 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4805 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4806 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4807 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4808 "endprimitive" "endspecify" "endtable" "endtask" "event"
4809 "for" "force" "forever" "fork" "function"
4810 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4811 "macromodule" "makefile" "medium" "module"
4812 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4813 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4814 "pullup"
4815 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4816 "rtranif0" "rtranif1"
4817 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4818 "strong1" "supply" "supply0" "supply1"
4819 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4820 "triand" "trior" "trireg"
4821 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4822 )
4823 "List of Verilog keywords as candidate for additional reserved words.")
d2ddb974 4824
5eabfe72
KH
4825(defconst vhdl-93-types
4826 '(
4827 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4828 "real" "time" "natural" "positive" "string" "line" "text" "side"
4829 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4830 "std_logic" "std_logic_vector"
4831 "std_ulogic" "std_ulogic_vector"
4832 )
4833 "List of VHDL'93 standardized types.")
d2ddb974 4834
5eabfe72
KH
4835(defconst vhdl-ams-types
4836 '(
4837 "domain_type" "real_vector"
3dcb36b7
JB
4838 ;; from `nature_pkg' package
4839 "voltage" "current" "electrical" "position" "velocity" "force"
4840 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4841 "pressure" "flowrate" "fluid"
4842 )
5eabfe72 4843 "List of VHDL-AMS standardized types.")
d2ddb974 4844
5eabfe72
KH
4845(defconst vhdl-math-types
4846 '(
4847 "complex" "complex_polar"
4848 )
4849 "List of Math Packages standardized types.")
d2ddb974 4850
5eabfe72
KH
4851(defconst vhdl-93-attributes
4852 '(
4853 "base" "left" "right" "high" "low" "pos" "val" "succ"
4854 "pred" "leftof" "rightof" "range" "reverse_range"
4855 "length" "delayed" "stable" "quiet" "transaction"
4856 "event" "active" "last_event" "last_active" "last_value"
4857 "driving" "driving_value" "ascending" "value" "image"
4858 "simple_name" "instance_name" "path_name"
4859 "foreign"
4860 )
4861 "List of VHDL'93 standardized attributes.")
d2ddb974 4862
5eabfe72
KH
4863(defconst vhdl-ams-attributes
4864 '(
4865 "across" "through"
4866 "reference" "contribution" "tolerance"
4867 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4868 "ramp" "slew"
4869 )
4870 "List of VHDL-AMS standardized attributes.")
d2ddb974 4871
5eabfe72
KH
4872(defconst vhdl-93-enum-values
4873 '(
4874 "true" "false"
4875 "note" "warning" "error" "failure"
4876 "read_mode" "write_mode" "append_mode"
4877 "open_ok" "status_error" "name_error" "mode_error"
4878 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4879 "right" "left"
4880 )
4881 "List of VHDL'93 standardized enumeration values.")
d2ddb974 4882
5eabfe72
KH
4883(defconst vhdl-ams-enum-values
4884 '(
4885 "quiescent_domain" "time_domain" "frequency_domain"
3dcb36b7
JB
4886 ;; from `nature_pkg' package
4887 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5eabfe72
KH
4888 )
4889 "List of VHDL-AMS standardized enumeration values.")
4890
4891(defconst vhdl-math-constants
4892 '(
4893 "math_e" "math_1_over_e"
4894 "math_pi" "math_two_pi" "math_1_over_pi"
4895 "math_half_pi" "math_q_pi" "math_3_half_pi"
4896 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4897 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4898 "math_deg_to_rad" "math_rad_to_deg"
4899 "cbase_1" "cbase_j" "czero"
4900 )
4901 "List of Math Packages standardized constants.")
4902
4903(defconst vhdl-93-functions
4904 '(
4905 "now" "resolved" "rising_edge" "falling_edge"
4906 "read" "readline" "write" "writeline" "endfile"
4907 "resize" "is_X" "std_match"
4908 "shift_left" "shift_right" "rotate_left" "rotate_right"
4909 "to_unsigned" "to_signed" "to_integer"
4910 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4911 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4912 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4913 "shl" "shr" "ext" "sxt"
3dcb36b7 4914 "deallocate"
5eabfe72
KH
4915 )
4916 "List of VHDL'93 standardized functions.")
4917
4918(defconst vhdl-ams-functions
4919 '(
4920 "frequency"
4921 )
4922 "List of VHDL-AMS standardized functions.")
4923
4924(defconst vhdl-math-functions
4925 '(
4926 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4927 "sqrt" "cbrt" "exp" "log"
4928 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4929 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4930 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4931 )
4932 "List of Math Packages standardized functions.")
4933
4934(defconst vhdl-93-packages
4935 '(
4936 "std_logic_1164" "numeric_std" "numeric_bit"
4937 "standard" "textio"
4938 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4939 "std_logic_misc" "std_logic_textio"
4940 "ieee" "std" "work"
4941 )
4942 "List of VHDL'93 standardized packages and libraries.")
4943
3dcb36b7
JB
4944(defconst vhdl-ams-packages
4945 '(
4946 ;; from `nature_pkg' package
4947 "nature_pkg"
4948 )
4949 "List of VHDL-AMS standardized packages and libraries.")
4950
5eabfe72
KH
4951(defconst vhdl-math-packages
4952 '(
4953 "math_real" "math_complex"
4954 )
4955 "List of Math Packages standardized packages and libraries.")
4956
4957(defvar vhdl-keywords nil
4958 "List of VHDL keywords.")
4959
4960(defvar vhdl-types nil
4961 "List of VHDL standardized types.")
4962
4963(defvar vhdl-attributes nil
4964 "List of VHDL standardized attributes.")
4965
4966(defvar vhdl-enum-values nil
4967 "List of VHDL standardized enumeration values.")
4968
4969(defvar vhdl-constants nil
4970 "List of VHDL standardized constants.")
4971
4972(defvar vhdl-functions nil
4973 "List of VHDL standardized functions.")
4974
4975(defvar vhdl-packages nil
4976 "List of VHDL standardized packages and libraries.")
4977
4978(defvar vhdl-reserved-words nil
4979 "List of additional reserved words.")
4980
4981(defvar vhdl-keywords-regexp nil
4982 "Regexp for VHDL keywords.")
4983
4984(defvar vhdl-types-regexp nil
4985 "Regexp for VHDL standardized types.")
4986
4987(defvar vhdl-attributes-regexp nil
4988 "Regexp for VHDL standardized attributes.")
4989
4990(defvar vhdl-enum-values-regexp nil
4991 "Regexp for VHDL standardized enumeration values.")
4992
4993(defvar vhdl-functions-regexp nil
4994 "Regexp for VHDL standardized functions.")
4995
4996(defvar vhdl-packages-regexp nil
4997 "Regexp for VHDL standardized packages and libraries.")
4998
4999(defvar vhdl-reserved-words-regexp nil
5000 "Regexp for additional reserved words.")
5001
3dcb36b7
JB
5002(defvar vhdl-directive-keywords-regexp nil
5003 "Regexp for compiler directive keywords.")
5004
5eabfe72
KH
5005(defun vhdl-words-init ()
5006 "Initialize reserved words."
5007 (setq vhdl-keywords
5008 (append vhdl-93-keywords
5009 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5010 (setq vhdl-types
5011 (append vhdl-93-types
5012 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5013 (when (vhdl-standard-p 'math) vhdl-math-types)))
5014 (setq vhdl-attributes
5015 (append vhdl-93-attributes
5016 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5017 (setq vhdl-enum-values
5018 (append vhdl-93-enum-values
5019 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5020 (setq vhdl-constants
5021 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5022 (setq vhdl-functions
5023 (append vhdl-93-functions
5024 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5025 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5026 (setq vhdl-packages
5027 (append vhdl-93-packages
3dcb36b7 5028 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5eabfe72
KH
5029 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5030 (setq vhdl-reserved-words
5031 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5032 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5033 '("")))
5034 (setq vhdl-keywords-regexp
5035 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5036 (setq vhdl-types-regexp
5037 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5038 (setq vhdl-attributes-regexp
5039 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5040 (setq vhdl-enum-values-regexp
5041 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5042 (setq vhdl-functions-regexp
5043 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5044 (setq vhdl-packages-regexp
5045 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5046 (setq vhdl-reserved-words-regexp
5047 (concat "\\<\\("
5048 (unless (equal vhdl-forbidden-syntax "")
5049 (concat vhdl-forbidden-syntax "\\|"))
5050 (regexp-opt vhdl-reserved-words)
5051 "\\)\\>"))
3dcb36b7
JB
5052 (setq vhdl-directive-keywords-regexp
5053 (concat "\\<\\(" (mapconcat 'regexp-quote
5054 vhdl-directive-keywords "\\|") "\\)\\>"))
5eabfe72
KH
5055 (vhdl-abbrev-list-init))
5056
5057;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5058;; Words to expand
5059
5060(defvar vhdl-abbrev-list nil
5061 "Predefined abbreviations for VHDL.")
5062
5063(defun vhdl-abbrev-list-init ()
5064 (setq vhdl-abbrev-list
5065 (append
5066 (list vhdl-upper-case-keywords) vhdl-keywords
5067 (list vhdl-upper-case-types) vhdl-types
5068 (list vhdl-upper-case-attributes) vhdl-attributes
5069 (list vhdl-upper-case-enum-values) vhdl-enum-values
5070 (list vhdl-upper-case-constants) vhdl-constants
5071 (list nil) vhdl-functions
5072 (list nil) vhdl-packages)))
5073
5074;; initialize reserved words for VHDL Mode
5075(vhdl-words-init)
5076
5077
5078;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 5079;;; Indentation
5eabfe72
KH
5080;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5081
5082;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
5083;; Syntax analysis
5084
5085;; constant regular expressions for looking at various constructs
5086
5087(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5088 "Regexp describing a VHDL symbol.
5089We cannot use just `word' syntax class since `_' cannot be in word
5090class. Putting underscore in word class breaks forward word movement
5091behavior that users are familiar with.")
5092
5093(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5094 "Regexp describing a case statement header key.")
5095
5096(defconst vhdl-label-key
5097 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5098 "Regexp describing a VHDL label.")
5099
5100;; Macro definitions:
5101
5102(defmacro vhdl-point (position)
5eabfe72
KH
5103 "Return the value of point at certain commonly referenced POSITIONs.
5104POSITION can be one of the following symbols:
5105
5106bol -- beginning of line
5107eol -- end of line
5108bod -- beginning of defun
5109boi -- back to indentation
5110eoi -- last whitespace on line
5111ionl -- indentation of next line
5112iopl -- indentation of previous line
5113bonl -- beginning of next line
5114bopl -- beginning of previous line
5115
5116This function does not modify point or mark."
d2ddb974 5117 (or (and (eq 'quote (car-safe position))
3dcb36b7
JB
5118 (null (cddr position)))
5119 (error "ERROR: Bad buffer position requested: %s" position))
d2ddb974 5120 (setq position (nth 1 position))
d4a5b644
GM
5121 `(let ((here (point)))
5122 ,@(cond
5123 ((eq position 'bol) '((beginning-of-line)))
5124 ((eq position 'eol) '((end-of-line)))
5125 ((eq position 'bod) '((save-match-data
5126 (vhdl-beginning-of-defun))))
5127 ((eq position 'boi) '((back-to-indentation)))
3dcb36b7 5128 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
d4a5b644
GM
5129 ((eq position 'bonl) '((forward-line 1)))
5130 ((eq position 'bopl) '((forward-line -1)))
5131 ((eq position 'iopl)
5132 '((forward-line -1)
5133 (back-to-indentation)))
5134 ((eq position 'ionl)
5135 '((forward-line 1)
5136 (back-to-indentation)))
3dcb36b7 5137 (t (error "ERROR: Unknown buffer position requested: %s" position))
d4a5b644
GM
5138 )
5139 (prog1
5140 (point)
5141 (goto-char here))
5142 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5143 ;; doesn't hurt for v19
5144 ,@nil
5145 ))
d2ddb974
KH
5146
5147(defmacro vhdl-safe (&rest body)
5eabfe72 5148 "Safely execute BODY, return nil if an error occurred."
d4a5b644
GM
5149 `(condition-case nil
5150 (progn ,@body)
5151 (error nil)))
d2ddb974
KH
5152
5153(defmacro vhdl-add-syntax (symbol &optional relpos)
5eabfe72
KH
5154 "A simple macro to append the syntax in SYMBOL to the syntax list.
5155Try to increase performance by using this macro."
d4a5b644
GM
5156 `(setq vhdl-syntactic-context
5157 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
d2ddb974
KH
5158
5159(defmacro vhdl-has-syntax (symbol)
5eabfe72
KH
5160 "A simple macro to return check the syntax list.
5161Try to increase performance by using this macro."
d4a5b644 5162 `(assoc ,symbol vhdl-syntactic-context))
d2ddb974
KH
5163
5164;; Syntactic element offset manipulation:
5165
5166(defun vhdl-read-offset (langelem)
5eabfe72 5167 "Read new offset value for LANGELEM from minibuffer.
2e8b9c7d 5168Return a valid value only."
d2ddb974
KH
5169 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5170 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5171 (prompt "Offset: ")
5172 offset input interned)
5173 (while (not offset)
5174 (setq input (read-string prompt oldoff)
5175 offset (cond ((string-equal "+" input) '+)
5176 ((string-equal "-" input) '-)
5177 ((string-equal "++" input) '++)
5178 ((string-equal "--" input) '--)
5179 ((string-match "^-?[0-9]+$" input)
027a4b6b 5180 (string-to-number input))
d2ddb974
KH
5181 ((fboundp (setq interned (intern input)))
5182 interned)
5183 ((boundp interned) interned)
5184 ;; error, but don't signal one, keep trying
5185 ;; to read an input value
5186 (t (ding)
5187 (setq prompt errmsg)
5188 nil))))
5189 offset))
5190
5191(defun vhdl-set-offset (symbol offset &optional add-p)
5192 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5193SYMBOL is the syntactic element symbol to change and OFFSET is the new
a4c6cfad 5194offset for that syntactic element. Optional ADD-P says to add SYMBOL to
d2ddb974
KH
5195`vhdl-offsets-alist' if it doesn't already appear there."
5196 (interactive
5197 (let* ((langelem
5198 (intern (completing-read
5199 (concat "Syntactic symbol to change"
5200 (if current-prefix-arg " or add" "")
5201 ": ")
5202 (mapcar
5203 (function
5204 (lambda (langelem)
5205 (cons (format "%s" (car langelem)) nil)))
5206 vhdl-offsets-alist)
5207 nil (not current-prefix-arg)
5208 ;; initial contents tries to be the last element
5209 ;; on the syntactic analysis list for the current
5210 ;; line
5211 (let* ((syntax (vhdl-get-syntactic-context))
5212 (len (length syntax))
5213 (ic (format "%s" (car (nth (1- len) syntax)))))
5eabfe72 5214 ic)
d2ddb974
KH
5215 )))
5216 (offset (vhdl-read-offset langelem)))
5217 (list langelem offset current-prefix-arg)))
5218 ;; sanity check offset
5219 (or (eq offset '+)
5220 (eq offset '-)
5221 (eq offset '++)
5222 (eq offset '--)
5223 (integerp offset)
5224 (fboundp offset)
5225 (boundp offset)
3dcb36b7 5226 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
d2ddb974
KH
5227 offset))
5228 (let ((entry (assq symbol vhdl-offsets-alist)))
5229 (if entry
5230 (setcdr entry offset)
5231 (if add-p
5eabfe72
KH
5232 (setq vhdl-offsets-alist
5233 (cons (cons symbol offset) vhdl-offsets-alist))
3dcb36b7 5234 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
d2ddb974
KH
5235 (vhdl-keep-region-active))
5236
5237(defun vhdl-set-style (style &optional local)
5eabfe72 5238 "Set `vhdl-mode' variables to use one of several different indentation styles.
d2ddb974
KH
5239STYLE is a string representing the desired style and optional LOCAL is
5240a flag which, if non-nil, means to make the style variables being
5241changed buffer local, instead of the default, which is to set the
5242global variables. Interactively, the flag comes from the prefix
5243argument. The styles are chosen from the `vhdl-style-alist' variable."
5244 (interactive (list (completing-read "Use which VHDL indentation style? "
5eabfe72 5245 vhdl-style-alist nil t)
d2ddb974
KH
5246 current-prefix-arg))
5247 (let ((vars (cdr (assoc style vhdl-style-alist))))
5248 (or vars
3dcb36b7 5249 (error "ERROR: Invalid VHDL indentation style `%s'" style))
d2ddb974 5250 ;; set all the variables
51b5ad57 5251 (mapc
d2ddb974
KH
5252 (function
5253 (lambda (varentry)
5254 (let ((var (car varentry))
5255 (val (cdr varentry)))
d2ddb974
KH
5256 ;; special case for vhdl-offsets-alist
5257 (if (not (eq var 'vhdl-offsets-alist))
175069ef 5258 (set (if local (make-local-variable var) var) val)
d2ddb974 5259 ;; reset vhdl-offsets-alist to the default value first
175069ef
SM
5260 (set (if local (make-local-variable var) var)
5261 (copy-alist vhdl-offsets-alist-default))
d2ddb974
KH
5262 ;; now set the langelems that are different
5263 (mapcar
5264 (function
5265 (lambda (langentry)
5266 (let ((langelem (car langentry))
5267 (offset (cdr langentry)))
5268 (vhdl-set-offset langelem offset)
5269 )))
5270 val))
5271 )))
5272 vars))
5273 (vhdl-keep-region-active))
5274
5275(defun vhdl-get-offset (langelem)
5eabfe72
KH
5276 "Get offset from LANGELEM which is a cons cell of the form:
5277\(SYMBOL . RELPOS). The symbol is matched against
5278vhdl-offsets-alist and the offset found there is either returned,
5279or added to the indentation at RELPOS. If RELPOS is nil, then
5280the offset is simply returned."
d2ddb974
KH
5281 (let* ((symbol (car langelem))
5282 (relpos (cdr langelem))
5283 (match (assq symbol vhdl-offsets-alist))
5284 (offset (cdr-safe match)))
5285 ;; offset can be a number, a function, a variable, or one of the
5286 ;; symbols + or -
5287 (cond
5288 ((not match)
5289 (if vhdl-strict-syntax-p
3dcb36b7 5290 (error "ERROR: Don't know how to indent a %s" symbol)
d2ddb974
KH
5291 (setq offset 0
5292 relpos 0)))
5293 ((eq offset '+) (setq offset vhdl-basic-offset))
5294 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5295 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5296 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5297 ((and (not (numberp offset))
5298 (fboundp offset))
5299 (setq offset (funcall offset langelem)))
5300 ((not (numberp offset))
5301 (setq offset (eval offset)))
5302 )
5303 (+ (if (and relpos
5304 (< relpos (vhdl-point 'bol)))
5305 (save-excursion
5306 (goto-char relpos)
5307 (current-column))
5308 0)
5309 offset)))
5310
5311;; Syntactic support functions:
5312
3dcb36b7
JB
5313(defun vhdl-in-comment-p ()
5314 "Check if point is in a comment."
5315 (eq (vhdl-in-literal) 'comment))
5316
5317(defun vhdl-in-string-p ()
5318 "Check if point is in a string."
5319 (eq (vhdl-in-literal) 'string))
d2ddb974 5320
3dcb36b7 5321(defun vhdl-in-literal ()
5eabfe72 5322 "Determine if point is in a VHDL literal."
d2ddb974 5323 (save-excursion
5eabfe72 5324 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
d2ddb974
KH
5325 (cond
5326 ((nth 3 state) 'string)
5327 ((nth 4 state) 'comment)
0a2e512a 5328 ((vhdl-beginning-of-macro) 'pound)
5eabfe72 5329 (t nil)))))
d2ddb974 5330
3dcb36b7
JB
5331(defun vhdl-forward-comment (&optional direction)
5332 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5333negative, skip forward otherwise."
5334 (interactive "p")
5335 (if (and direction (< direction 0))
5336 ;; skip backwards
5337 (progn
5338 (skip-chars-backward " \t\n")
5339 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5340 (goto-char (match-beginning 3))
5341 (skip-chars-backward " \t\n")))
5342 ;; skip forwards
5343 (skip-chars-forward " \t\n")
5344 (while (looking-at "--.*")
5345 (goto-char (match-end 0))
5346 (skip-chars-forward " \t\n"))))
5347
5348;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
f8246027 5349(unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
3dcb36b7
JB
5350 (defalias 'vhdl-forward-comment 'forward-comment))
5351
d2ddb974
KH
5352;; This is the best we can do in Win-Emacs.
5353(defun vhdl-win-il (&optional lim)
5eabfe72 5354 "Determine if point is in a VHDL literal."
d2ddb974
KH
5355 (save-excursion
5356 (let* ((here (point))
5357 (state nil)
5358 (match nil)
5359 (lim (or lim (vhdl-point 'bod))))
5360 (goto-char lim )
5361 (while (< (point) here)
5362 (setq match
5363 (and (re-search-forward "--\\|[\"']"
5364 here 'move)
5365 (buffer-substring (match-beginning 0) (match-end 0))))
5366 (setq state
5367 (cond
5368 ;; no match
5369 ((null match) nil)
5370 ;; looking at the opening of a VHDL style comment
5371 ((string= "--" match)
5372 (if (<= here (progn (end-of-line) (point))) 'comment))
5373 ;; looking at the opening of a double quote string
5374 ((string= "\"" match)
5375 (if (not (save-restriction
5376 ;; this seems to be necessary since the
5377 ;; re-search-forward will not work without it
5378 (narrow-to-region (point) here)
5379 (re-search-forward
5380 ;; this regexp matches a double quote
5381 ;; which is preceded by an even number
5382 ;; of backslashes, including zero
5383 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5384 'string))
5385 ;; looking at the opening of a single quote string
5386 ((string= "'" match)
5387 (if (not (save-restriction
5388 ;; see comments from above
5389 (narrow-to-region (point) here)
5390 (re-search-forward
5391 ;; this matches a single quote which is
5392 ;; preceded by zero or two backslashes.
5393 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5394 here 'move)))
5395 'string))
5396 (t nil)))
5397 ) ; end-while
5398 state)))
5399
5eabfe72 5400(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5401 (fset 'vhdl-in-literal 'vhdl-win-il))
5402
5403;; Skipping of "syntactic whitespace". Syntactic whitespace is
5404;; defined as lexical whitespace or comments. Search no farther back
5405;; or forward than optional LIM. If LIM is omitted, (point-min) is
5406;; used for backward skipping, (point-max) is used for forward
5407;; skipping.
5408
5409(defun vhdl-forward-syntactic-ws (&optional lim)
5eabfe72 5410 "Forward skip of syntactic whitespace."
0a2e512a
RF
5411 (let* ((here (point-max))
5412 (hugenum (point-max)))
5413 (while (/= here (point))
5414 (setq here (point))
5415 (vhdl-forward-comment hugenum)
5416 ;; skip preprocessor directives
5417 (when (and (eq (char-after) ?#)
5418 (= (vhdl-point 'boi) (point)))
5419 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5420 (= (forward-line 1) 0)))
5421 (end-of-line)))
5422 (if lim (goto-char (min (point) lim)))))
5423
d2ddb974
KH
5424
5425;; This is the best we can do in Win-Emacs.
5426(defun vhdl-win-fsws (&optional lim)
5eabfe72 5427 "Forward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5428 (let ((lim (or lim (point-max)))
5429 stop)
5430 (while (not stop)
5431 (skip-chars-forward " \t\n\r\f" lim)
5432 (cond
5433 ;; vhdl comment
5434 ((looking-at "--") (end-of-line))
5435 ;; none of the above
3dcb36b7 5436 (t (setq stop t))))))
d2ddb974 5437
5eabfe72 5438(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5439 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5440
0a2e512a
RF
5441(defun vhdl-beginning-of-macro (&optional lim)
5442 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5443 (let ((here (point)))
5444 (beginning-of-line)
5445 (while (eq (char-before (1- (point))) ?\\)
5446 (forward-line -1))
5447 (back-to-indentation)
5448 (if (and (<= (point) here)
5449 (eq (char-after) ?#))
5450 t
5451 (goto-char here)
5452 nil)))
5453
d2ddb974 5454(defun vhdl-backward-syntactic-ws (&optional lim)
5eabfe72 5455 "Backward skip over syntactic whitespace."
0a2e512a
RF
5456 (let* ((here (point-min))
5457 (hugenum (- (point-max))))
5458 (while (/= here (point))
5459 (setq here (point))
5460 (vhdl-forward-comment hugenum)
5461 (vhdl-beginning-of-macro))
5462 (if lim (goto-char (max (point) lim)))))
d2ddb974
KH
5463
5464;; This is the best we can do in Win-Emacs.
5465(defun vhdl-win-bsws (&optional lim)
5eabfe72 5466 "Backward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5467 (let ((lim (or lim (vhdl-point 'bod)))
5468 stop)
5469 (while (not stop)
5470 (skip-chars-backward " \t\n\r\f" lim)
5471 (cond
5472 ;; vhdl comment
3dcb36b7 5473 ((eq (vhdl-in-literal) 'comment)
d2ddb974
KH
5474 (skip-chars-backward "^-" lim)
5475 (skip-chars-backward "-" lim)
5476 (while (not (or (and (= (following-char) ?-)
5477 (= (char-after (1+ (point))) ?-))
5478 (<= (point) lim)))
5479 (skip-chars-backward "^-" lim)
5480 (skip-chars-backward "-" lim)))
5481 ;; none of the above
3dcb36b7 5482 (t (setq stop t))))))
d2ddb974 5483
5eabfe72 5484(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5485 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5486
5487;; Functions to help finding the correct indentation column:
5488
5489(defun vhdl-first-word (point)
5490 "If the keyword at POINT is at boi, then return (current-column) at
5491that point, else nil."
5492 (save-excursion
5493 (and (goto-char point)
5494 (eq (point) (vhdl-point 'boi))
5495 (current-column))))
5496
5497(defun vhdl-last-word (point)
5498 "If the keyword at POINT is at eoi, then return (current-column) at
5499that point, else nil."
5500 (save-excursion
5501 (and (goto-char point)
5502 (save-excursion (or (eq (progn (forward-sexp) (point))
5503 (vhdl-point 'eoi))
5504 (looking-at "\\s-*\\(--\\)?")))
5505 (current-column))))
5506
5507;; Core syntactic evaluation functions:
5508
5509(defconst vhdl-libunit-re
5510 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5511
5512(defun vhdl-libunit-p ()
5513 (and
5514 (save-excursion
5515 (forward-sexp)
5516 (skip-chars-forward " \t\n")
5517 (not (looking-at "is\\b[^_]")))
5518 (save-excursion
5519 (backward-sexp)
5520 (and (not (looking-at "use\\b[^_]"))
5521 (progn
5522 (forward-sexp)
5523 (vhdl-forward-syntactic-ws)
5524 (/= (following-char) ?:))))
5525 ))
5526
5527(defconst vhdl-defun-re
5eabfe72 5528 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
d2ddb974
KH
5529
5530(defun vhdl-defun-p ()
5531 (save-excursion
5eabfe72
KH
5532 (if (looking-at "block\\|process\\|procedural")
5533 ;; "block", "process", "procedural":
d2ddb974
KH
5534 (save-excursion
5535 (backward-sexp)
5536 (not (looking-at "end\\s-+\\w")))
5537 ;; "architecture", "configuration", "entity",
5538 ;; "package", "procedure", "function":
5539 t)))
5540
5541(defun vhdl-corresponding-defun ()
5542 "If the word at the current position corresponds to a \"defun\"
5543keyword, then return a string that can be used to find the
5544corresponding \"begin\" keyword, else return nil."
5545 (save-excursion
5546 (and (looking-at vhdl-defun-re)
5547 (vhdl-defun-p)
5eabfe72
KH
5548 (if (looking-at "block\\|process\\|procedural")
5549 ;; "block", "process". "procedural:
d2ddb974
KH
5550 (buffer-substring (match-beginning 0) (match-end 0))
5551 ;; "architecture", "configuration", "entity", "package",
5552 ;; "procedure", "function":
5553 "is"))))
5554
5555(defconst vhdl-begin-fwd-re
5eabfe72 5556 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
d2ddb974
KH
5557 "A regular expression for searching forward that matches all known
5558\"begin\" keywords.")
5559
5560(defconst vhdl-begin-bwd-re
5eabfe72 5561 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
d2ddb974
KH
5562 "A regular expression for searching backward that matches all known
5563\"begin\" keywords.")
5564
5565(defun vhdl-begin-p (&optional lim)
5566 "Return t if we are looking at a real \"begin\" keyword.
5567Assumes that the caller will make sure that we are looking at
5568vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5569the middle of an identifier that just happens to contain a \"begin\"
5570keyword."
5571 (cond
5572 ;; "[architecture|case|configuration|entity|package|
5573 ;; procedure|function] ... is":
5574 ((and (looking-at "i")
5575 (save-excursion
5576 ;; Skip backward over first sexp (needed to skip over a
5577 ;; procedure interface list, and is harmless in other
5578 ;; situations). Note that we need "return" in the
5579 ;; following search list so that we don't run into
5580 ;; semicolons in the function interface list.
5581 (backward-sexp)
5582 (let (foundp)
5583 (while (and (not foundp)
5584 (re-search-backward
5eabfe72 5585 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
d2ddb974
KH
5586 lim 'move))
5587 (if (or (= (preceding-char) ?_)
3dcb36b7 5588 (vhdl-in-literal))
d2ddb974
KH
5589 (backward-char)
5590 (setq foundp t))))
5591 (and (/= (following-char) ?\;)
5eabfe72 5592 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
d2ddb974
KH
5593 t)
5594 ;; "begin", "then":
5595 ((looking-at "be\\|t")
5596 t)
5597 ;; "else":
5598 ((and (looking-at "e")
5599 ;; make sure that the "else" isn't inside a
5600 ;; conditional signal assignment.
5601 (save-excursion
5602 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5603 (or (eq (following-char) ?\;)
5604 (eq (point) lim))))
5605 t)
5eabfe72 5606 ;; "block", "generate", "loop", "process", "procedural",
d2ddb974
KH
5607 ;; "units", "record":
5608 ((and (looking-at "bl\\|[glpur]")
5609 (save-excursion
5610 (backward-sexp)
5611 (not (looking-at "end\\s-+\\w"))))
5612 t)
5613 ;; "component":
5614 ((and (looking-at "c")
5615 (save-excursion
5616 (backward-sexp)
5617 (not (looking-at "end\\s-+\\w")))
5618 ;; look out for the dreaded entity class in an attribute
5619 (save-excursion
5620 (vhdl-backward-syntactic-ws lim)
5621 (/= (preceding-char) ?:)))
5622 t)
5623 ;; "for" (inside configuration declaration):
5624 ((and (looking-at "f")
5625 (save-excursion
5626 (backward-sexp)
5627 (not (looking-at "end\\s-+\\w")))
5628 (vhdl-has-syntax 'configuration))
5629 t)
5630 ))
5631
5632(defun vhdl-corresponding-mid (&optional lim)
5633 (cond
5eabfe72 5634 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
d2ddb974
KH
5635 "begin")
5636 ((looking-at "then")
5637 "<else>")
5638 (t
5639 "end")))
5640
5641(defun vhdl-corresponding-end (&optional lim)
5642 "If the word at the current position corresponds to a \"begin\"
5643keyword, then return a vector containing enough information to find
5644the corresponding \"end\" keyword, else return nil. The keyword to
5645search forward for is aref 0. The column in which the keyword must
5646appear is aref 1 or nil if any column is suitable.
5647Assumes that the caller will make sure that we are not in the middle
5648of an identifier that just happens to contain a \"begin\" keyword."
5649 (save-excursion
5650 (and (looking-at vhdl-begin-fwd-re)
5651 (/= (preceding-char) ?_)
3dcb36b7 5652 (not (vhdl-in-literal))
d2ddb974
KH
5653 (vhdl-begin-p lim)
5654 (cond
5655 ;; "is", "generate", "loop":
5656 ((looking-at "[igl]")
5657 (vector "end"
5658 (and (vhdl-last-word (point))
5659 (or (vhdl-first-word (point))
5660 (save-excursion
5661 (vhdl-beginning-of-statement-1 lim)
5662 (vhdl-backward-skip-label lim)
5663 (vhdl-first-word (point)))))))
5664 ;; "begin", "else", "for":
5665 ((looking-at "be\\|[ef]")
5666 (vector "end"
5667 (and (vhdl-last-word (point))
5668 (or (vhdl-first-word (point))
5669 (save-excursion
5670 (vhdl-beginning-of-statement-1 lim)
5671 (vhdl-backward-skip-label lim)
5672 (vhdl-first-word (point)))))))
5673 ;; "component", "units", "record":
5674 ((looking-at "[cur]")
5675 ;; The first end found will close the block
5676 (vector "end" nil))
5eabfe72 5677 ;; "block", "process", "procedural":
d2ddb974
KH
5678 ((looking-at "bl\\|p")
5679 (vector "end"
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 ;; "then":
5686 ((looking-at "t")
5687 (vector "elsif\\|else\\|end\\s-+if"
5688 (and (vhdl-last-word (point))
5689 (or (vhdl-first-word (point))
5690 (save-excursion
5691 (vhdl-beginning-of-statement-1 lim)
5692 (vhdl-backward-skip-label lim)
5693 (vhdl-first-word (point)))))))
5694 ))))
5695
5696(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5697
5698(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5699
5700(defun vhdl-end-p (&optional lim)
5701 "Return t if we are looking at a real \"end\" keyword.
5702Assumes that the caller will make sure that we are looking at
5703vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5704the middle of an identifier that just happens to contain an \"end\"
5705keyword."
5706 (or (not (looking-at "else"))
5707 ;; make sure that the "else" isn't inside a conditional signal
5708 ;; assignment.
5709 (save-excursion
5710 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5711 (or (eq (following-char) ?\;)
0a2e512a
RF
5712 (eq (point) lim)
5713 (vhdl-in-literal)))))
d2ddb974
KH
5714
5715(defun vhdl-corresponding-begin (&optional lim)
5716 "If the word at the current position corresponds to an \"end\"
5717keyword, then return a vector containing enough information to find
5718the corresponding \"begin\" keyword, else return nil. The keyword to
a4c6cfad 5719search backward for is aref 0. The column in which the keyword must
d2ddb974
KH
5720appear is aref 1 or nil if any column is suitable. The supplementary
5721keyword to search forward for is aref 2 or nil if this is not
5722required. If aref 3 is t, then the \"begin\" keyword may be found in
5723the middle of a statement.
5724Assumes that the caller will make sure that we are not in the middle
5725of an identifier that just happens to contain an \"end\" keyword."
5726 (save-excursion
5727 (let (pos)
5728 (if (and (looking-at vhdl-end-fwd-re)
3dcb36b7 5729 (not (vhdl-in-literal))
d2ddb974
KH
5730 (vhdl-end-p lim))
5731 (if (looking-at "el")
5732 ;; "else", "elsif":
5733 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5734 ;; "end ...":
5735 (setq pos (point))
5736 (forward-sexp)
5737 (skip-chars-forward " \t\n")
5738 (cond
5739 ;; "end if":
5740 ((looking-at "if\\b[^_]")
5741 (vector "else\\|elsif\\|if"
5742 (vhdl-first-word pos)
5743 "else\\|then" nil))
5744 ;; "end component":
5745 ((looking-at "component\\b[^_]")
5746 (vector (buffer-substring (match-beginning 1)
5747 (match-end 1))
5748 (vhdl-first-word pos)
5749 nil nil))
5750 ;; "end units", "end record":
5751 ((looking-at "\\(units\\|record\\)\\b[^_]")
5752 (vector (buffer-substring (match-beginning 1)
5753 (match-end 1))
5754 (vhdl-first-word pos)
5755 nil t))
5eabfe72
KH
5756 ;; "end block", "end process", "end procedural":
5757 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
d2ddb974
KH
5758 (vector "begin" (vhdl-first-word pos) nil nil))
5759 ;; "end case":
5760 ((looking-at "case\\b[^_]")
5761 (vector "case" (vhdl-first-word pos) "is" nil))
5762 ;; "end generate":
5763 ((looking-at "generate\\b[^_]")
5764 (vector "generate\\|for\\|if"
5765 (vhdl-first-word pos)
5766 "generate" nil))
5767 ;; "end loop":
5768 ((looking-at "loop\\b[^_]")
5769 (vector "loop\\|while\\|for"
5770 (vhdl-first-word pos)
5771 "loop" nil))
5772 ;; "end for" (inside configuration declaration):
5773 ((looking-at "for\\b[^_]")
5774 (vector "for" (vhdl-first-word pos) nil nil))
5775 ;; "end [id]":
5776 (t
5777 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5778 (vhdl-first-word pos)
5779 ;; return an alist of (statement . keyword) mappings
5780 '(
5781 ;; "begin ... end [id]":
0a2e512a 5782 ("begin" . nil)
d2ddb974 5783 ;; "architecture ... is ... begin ... end [id]":
0a2e512a 5784 ("architecture" . "is")
d2ddb974
KH
5785 ;; "configuration ... is ... end [id]":
5786 ("configuration" . "is")
5787 ;; "entity ... is ... end [id]":
0a2e512a 5788 ("entity" . "is")
d2ddb974 5789 ;; "package ... is ... end [id]":
0a2e512a 5790 ("package" . "is")
d2ddb974
KH
5791 ;; "procedure ... is ... begin ... end [id]":
5792 ("procedure" . "is")
5793 ;; "function ... is ... begin ... end [id]":
5794 ("function" . "is")
5795 )
5796 nil))
5797 ))) ; "end ..."
5798 )))
5799
5800(defconst vhdl-leader-re
5eabfe72 5801 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
d2ddb974
KH
5802
5803(defun vhdl-end-of-leader ()
5804 (save-excursion
5eabfe72 5805 (cond ((looking-at "block\\|process\\|procedural")
d2ddb974
KH
5806 (if (save-excursion
5807 (forward-sexp)
5808 (skip-chars-forward " \t\n")
5809 (= (following-char) ?\())
5810 (forward-sexp 2)
5811 (forward-sexp))
3dcb36b7
JB
5812 (when (looking-at "[ \t\n]*is")
5813 (goto-char (match-end 0)))
d2ddb974
KH
5814 (point))
5815 ((looking-at "component")
5816 (forward-sexp 2)
3dcb36b7
JB
5817 (when (looking-at "[ \t\n]*is")
5818 (goto-char (match-end 0)))
d2ddb974
KH
5819 (point))
5820 ((looking-at "for")
5821 (forward-sexp 2)
5822 (skip-chars-forward " \t\n")
5823 (while (looking-at "[,:(]")
5824 (forward-sexp)
5825 (skip-chars-forward " \t\n"))
5826 (point))
5827 (t nil)
5828 )))
5829
5830(defconst vhdl-trailer-re
0a2e512a 5831 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
d2ddb974
KH
5832
5833(defconst vhdl-statement-fwd-re
5834 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5835 "A regular expression for searching forward that matches all known
5836\"statement\" keywords.")
5837
5838(defconst vhdl-statement-bwd-re
5839 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5840 "A regular expression for searching backward that matches all known
5841\"statement\" keywords.")
5842
5843(defun vhdl-statement-p (&optional lim)
5844 "Return t if we are looking at a real \"statement\" keyword.
5845Assumes that the caller will make sure that we are looking at
5eabfe72
KH
5846vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5847in the middle of an identifier that just happens to contain a
5848\"statement\" keyword."
d2ddb974
KH
5849 (cond
5850 ;; "for" ... "generate":
5851 ((and (looking-at "f")
5852 ;; Make sure it's the start of a parameter specification.
5853 (save-excursion
5854 (forward-sexp 2)
5855 (skip-chars-forward " \t\n")
5856 (looking-at "in\\b[^_]"))
5857 ;; Make sure it's not an "end for".
5858 (save-excursion
5859 (backward-sexp)
5860 (not (looking-at "end\\s-+\\w"))))
5861 t)
5862 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5863 ((and (looking-at "i")
5864 ;; Make sure it's not an "end if".
5865 (save-excursion
5866 (backward-sexp)
5867 (not (looking-at "end\\s-+\\w"))))
5868 t)
5869 ;; "while" ... "loop":
5870 ((looking-at "w")
5871 t)
5872 ))
5873
5874(defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5875 "Regexp describing a case statement alternative key.")
5876
5877(defun vhdl-case-alternative-p (&optional lim)
5878 "Return t if we are looking at a real case alternative.
5879Assumes that the caller will make sure that we are looking at
5880vhdl-case-alternative-re, and are not inside a literal, and that
5881we are not in the middle of an identifier that just happens to
5882contain a \"when\" keyword."
5883 (save-excursion
5884 (let (foundp)
5885 (while (and (not foundp)
5886 (re-search-backward ";\\|<=" lim 'move))
5887 (if (or (= (preceding-char) ?_)
3dcb36b7 5888 (vhdl-in-literal))
d2ddb974
KH
5889 (backward-char)
5890 (setq foundp t)))
5891 (or (eq (following-char) ?\;)
5892 (eq (point) lim)))
5893 ))
5894
5895;; Core syntactic movement functions:
5896
5897(defconst vhdl-b-t-b-re
5898 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5899
5900(defun vhdl-backward-to-block (&optional lim)
5901 "Move backward to the previous \"begin\" or \"end\" keyword."
5902 (let (foundp)
5903 (while (and (not foundp)
5904 (re-search-backward vhdl-b-t-b-re lim 'move))
5905 (if (or (= (preceding-char) ?_)
3dcb36b7 5906 (vhdl-in-literal))
d2ddb974
KH
5907 (backward-char)
5908 (cond
5909 ;; "begin" keyword:
5910 ((and (looking-at vhdl-begin-fwd-re)
5911 (/= (preceding-char) ?_)
5912 (vhdl-begin-p lim))
5913 (setq foundp 'begin))
5914 ;; "end" keyword:
5915 ((and (looking-at vhdl-end-fwd-re)
5916 (/= (preceding-char) ?_)
5917 (vhdl-end-p lim))
5918 (setq foundp 'end))
5919 ))
5920 )
5921 foundp
5922 ))
5923
5924(defun vhdl-forward-sexp (&optional count lim)
5925 "Move forward across one balanced expression (sexp).
5926With COUNT, do it that many times."
5927 (interactive "p")
5928 (let ((count (or count 1))
5929 (case-fold-search t)
5930 end-vec target)
5931 (save-excursion
5932 (while (> count 0)
5933 ;; skip whitespace
5934 (skip-chars-forward " \t\n")
5935 ;; Check for an unbalanced "end" keyword
5936 (if (and (looking-at vhdl-end-fwd-re)
5937 (/= (preceding-char) ?_)
3dcb36b7 5938 (not (vhdl-in-literal))
d2ddb974
KH
5939 (vhdl-end-p lim)
5940 (not (looking-at "else")))
5941 (error
3dcb36b7 5942 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
d2ddb974
KH
5943 ;; If the current keyword is a "begin" keyword, then find the
5944 ;; corresponding "end" keyword.
5945 (if (setq end-vec (vhdl-corresponding-end lim))
5946 (let (
5947 ;; end-re is the statement keyword to search for
5948 (end-re
5949 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5950 ;; column is either the statement keyword target column
5951 ;; or nil
5952 (column (aref end-vec 1))
5953 (eol (vhdl-point 'eol))
5954 foundp literal placeholder)
5955 ;; Look for the statement keyword.
5956 (while (and (not foundp)
5957 (re-search-forward end-re nil t)
5958 (setq placeholder (match-end 1))
5959 (goto-char (match-beginning 0)))
5960 ;; If we are in a literal, or not in the right target
5961 ;; column and not on the same line as the begin, then
5962 ;; try again.
5963 (if (or (and column
5964 (/= (current-indentation) column)
5965 (> (point) eol))
5966 (= (preceding-char) ?_)
3dcb36b7 5967 (setq literal (vhdl-in-literal)))
d2ddb974
KH
5968 (if (eq literal 'comment)
5969 (end-of-line)
5970 (forward-char))
5971 ;; An "else" keyword corresponds to both the opening brace
5972 ;; of the following sexp and the closing brace of the
5973 ;; previous sexp.
5974 (if (not (looking-at "else"))
5975 (goto-char placeholder))
5976 (setq foundp t))
5977 )
5978 (if (not foundp)
3dcb36b7 5979 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
d2ddb974
KH
5980 )
5981 ;; If the current keyword is not a "begin" keyword, then just
5982 ;; perform the normal forward-sexp.
5983 (forward-sexp)
5984 )
5985 (setq count (1- count))
5986 )
5987 (setq target (point)))
5988 (goto-char target)
5989 nil))
5990
5991(defun vhdl-backward-sexp (&optional count lim)
5992 "Move backward across one balanced expression (sexp).
5993With COUNT, do it that many times. LIM bounds any required backward
5994searches."
5995 (interactive "p")
5996 (let ((count (or count 1))
5997 (case-fold-search t)
5998 begin-vec target)
5999 (save-excursion
6000 (while (> count 0)
6001 ;; Perform the normal backward-sexp, unless we are looking at
6002 ;; "else" - an "else" keyword corresponds to both the opening brace
6003 ;; of the following sexp and the closing brace of the previous sexp.
6004 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6005 (/= (preceding-char) ?_)
3dcb36b7 6006 (not (vhdl-in-literal)))
d2ddb974
KH
6007 nil
6008 (backward-sexp)
6009 (if (and (looking-at vhdl-begin-fwd-re)
6010 (/= (preceding-char) ?_)
3dcb36b7 6011 (not (vhdl-in-literal))
d2ddb974 6012 (vhdl-begin-p lim))
3dcb36b7 6013 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
d2ddb974
KH
6014 ;; If the current keyword is an "end" keyword, then find the
6015 ;; corresponding "begin" keyword.
6016 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6017 (/= (preceding-char) ?_))
6018 (let (
6019 ;; begin-re is the statement keyword to search for
6020 (begin-re
6021 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6022 ;; column is either the statement keyword target column
6023 ;; or nil
6024 (column (aref begin-vec 1))
6025 ;; internal-p controls where the statement keyword can
6026 ;; be found.
6027 (internal-p (aref begin-vec 3))
6028 (last-backward (point)) last-forward
6029 foundp literal keyword)
6030 ;; Look for the statement keyword.
6031 (while (and (not foundp)
6032 (re-search-backward begin-re lim t)
6033 (setq keyword
6034 (buffer-substring (match-beginning 1)
6035 (match-end 1))))
6036 ;; If we are in a literal or in the wrong column,
6037 ;; then try again.
6038 (if (or (and column
6039 (and (/= (current-indentation) column)
6040 ;; possibly accept current-column as
6041 ;; well as current-indentation.
6042 (or (not internal-p)
6043 (/= (current-column) column))))
6044 (= (preceding-char) ?_)
3dcb36b7 6045 (vhdl-in-literal))
d2ddb974
KH
6046 (backward-char)
6047 ;; If there is a supplementary keyword, then
6048 ;; search forward for it.
6049 (if (and (setq begin-re (aref begin-vec 2))
6050 (or (not (listp begin-re))
6051 ;; If begin-re is an alist, then find the
6052 ;; element corresponding to the actual
6053 ;; keyword that we found.
6054 (progn
6055 (setq begin-re
6056 (assoc keyword begin-re))
6057 (and begin-re
6058 (setq begin-re (cdr begin-re))))))
6059 (and
6060 (setq begin-re
6061 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6062 (save-excursion
6063 (setq last-forward (point))
6064 ;; Look for the supplementary keyword
6065 ;; (bounded by the backward search start
6066 ;; point).
6067 (while (and (not foundp)
6068 (re-search-forward begin-re
6069 last-backward t)
6070 (goto-char (match-beginning 1)))
6071 ;; If we are in a literal, then try again.
6072 (if (or (= (preceding-char) ?_)
6073 (setq literal
3dcb36b7 6074 (vhdl-in-literal)))
d2ddb974
KH
6075 (if (eq literal 'comment)
6076 (goto-char
6077 (min (vhdl-point 'eol) last-backward))
6078 (forward-char))
6079 ;; We have found the supplementary keyword.
6080 ;; Save the position of the keyword in foundp.
6081 (setq foundp (point)))
6082 )
6083 foundp)
6084 ;; If the supplementary keyword was found, then
6085 ;; move point to the supplementary keyword.
6086 (goto-char foundp))
6087 ;; If there was no supplementary keyword, then
6088 ;; point is already at the statement keyword.
6089 (setq foundp t)))
6090 ) ; end of the search for the statement keyword
6091 (if (not foundp)
3dcb36b7 6092 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
d2ddb974
KH
6093 ))
6094 (setq count (1- count))
6095 )
6096 (setq target (point)))
6097 (goto-char target)
6098 nil))
6099
6100(defun vhdl-backward-up-list (&optional count limit)
6101 "Move backward out of one level of blocks.
6102With argument, do this that many times."
6103 (interactive "p")
6104 (let ((count (or count 1))
6105 target)
6106 (save-excursion
6107 (while (> count 0)
6108 (if (looking-at vhdl-defun-re)
3dcb36b7 6109 (error "ERROR: Unbalanced blocks"))
d2ddb974
KH
6110 (vhdl-backward-to-block limit)
6111 (setq count (1- count)))
6112 (setq target (point)))
6113 (goto-char target)))
6114
6115(defun vhdl-end-of-defun (&optional count)
6116 "Move forward to the end of a VHDL defun."
6117 (interactive)
6118 (let ((case-fold-search t))
6119 (vhdl-beginning-of-defun)
5eabfe72 6120 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6121 (re-search-forward "\\bis\\b"))
6122 (vhdl-forward-sexp)))
6123
6124(defun vhdl-mark-defun ()
6125 "Put mark at end of this \"defun\", point at beginning."
6126 (interactive)
6127 (let ((case-fold-search t))
6128 (push-mark)
6129 (vhdl-beginning-of-defun)
6130 (push-mark)
5eabfe72 6131 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6132 (re-search-forward "\\bis\\b"))
6133 (vhdl-forward-sexp)
6134 (exchange-point-and-mark)))
6135
6136(defun vhdl-beginning-of-libunit ()
6137 "Move backward to the beginning of a VHDL library unit.
6138Returns the location of the corresponding begin keyword, unless search
5eabfe72
KH
6139stops due to beginning or end of buffer.
6140Note that if point is between the \"libunit\" keyword and the
6141corresponding \"begin\" keyword, then that libunit will not be
a3dd3c0e
JB
6142recognized, and the search will continue backwards. If point is
6143at the \"begin\" keyword, then the defun will be recognized. The
5eabfe72 6144returned point is at the first character of the \"libunit\" keyword."
d2ddb974
KH
6145 (let ((last-forward (point))
6146 (last-backward
6147 ;; Just in case we are actually sitting on the "begin"
6148 ;; keyword, allow for the keyword and an extra character,
6149 ;; as this will be used when looking forward for the
6150 ;; "begin" keyword.
6151 (save-excursion (forward-word 1) (1+ (point))))
6152 foundp literal placeholder)
6153 ;; Find the "libunit" keyword.
6154 (while (and (not foundp)
6155 (re-search-backward vhdl-libunit-re nil 'move))
6156 ;; If we are in a literal, or not at a real libunit, then try again.
6157 (if (or (= (preceding-char) ?_)
3dcb36b7 6158 (vhdl-in-literal)
d2ddb974
KH
6159 (not (vhdl-libunit-p)))
6160 (backward-char)
6161 ;; Find the corresponding "begin" keyword.
6162 (setq last-forward (point))
6163 (while (and (not foundp)
6164 (re-search-forward "\\bis\\b[^_]" last-backward t)
6165 (setq placeholder (match-beginning 0)))
6166 (if (or (= (preceding-char) ?_)
3dcb36b7 6167 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6168 ;; It wasn't a real keyword, so keep searching.
6169 (if (eq literal 'comment)
6170 (goto-char
6171 (min (vhdl-point 'eol) last-backward))
6172 (forward-char))
6173 ;; We have found the begin keyword, loop will exit.
6174 (setq foundp placeholder)))
6175 ;; Go back to the libunit keyword
6176 (goto-char last-forward)))
6177 foundp))
6178
6179(defun vhdl-beginning-of-defun (&optional count)
6180 "Move backward to the beginning of a VHDL defun.
6181With argument, do it that many times.
6182Returns the location of the corresponding begin keyword, unless search
6183stops due to beginning or end of buffer."
6184 ;; Note that if point is between the "defun" keyword and the
6185 ;; corresponding "begin" keyword, then that defun will not be
0a2e512a
RF
6186 ;; recognized, and the search will continue backwards. If point is
6187 ;; at the "begin" keyword, then the defun will be recognized. The
d2ddb974
KH
6188 ;; returned point is at the first character of the "defun" keyword.
6189 (interactive "p")
6190 (let ((count (or count 1))
6191 (case-fold-search t)
6192 (last-forward (point))
6193 foundp)
6194 (while (> count 0)
6195 (setq foundp nil)
6196 (goto-char last-forward)
6197 (let ((last-backward
6198 ;; Just in case we are actually sitting on the "begin"
6199 ;; keyword, allow for the keyword and an extra character,
6200 ;; as this will be used when looking forward for the
6201 ;; "begin" keyword.
6202 (save-excursion (forward-word 1) (1+ (point))))
6203 begin-string literal)
6204 (while (and (not foundp)
6205 (re-search-backward vhdl-defun-re nil 'move))
6206 ;; If we are in a literal, then try again.
6207 (if (or (= (preceding-char) ?_)
3dcb36b7 6208 (vhdl-in-literal))
d2ddb974
KH
6209 (backward-char)
6210 (if (setq begin-string (vhdl-corresponding-defun))
6211 ;; This is a real defun keyword.
6212 ;; Find the corresponding "begin" keyword.
6213 ;; Look for the begin keyword.
6214 (progn
6215 ;; Save the search start point.
6216 (setq last-forward (point))
6217 (while (and (not foundp)
6218 (search-forward begin-string last-backward t))
6219 (if (or (= (preceding-char) ?_)
6220 (save-match-data
3dcb36b7 6221 (setq literal (vhdl-in-literal))))
d2ddb974
KH
6222 ;; It wasn't a real keyword, so keep searching.
6223 (if (eq literal 'comment)
6224 (goto-char
6225 (min (vhdl-point 'eol) last-backward))
6226 (forward-char))
6227 ;; We have found the begin keyword, loop will exit.
6228 (setq foundp (match-beginning 0)))
6229 )
6230 ;; Go back to the defun keyword
6231 (goto-char last-forward)) ; end search for begin keyword
6232 ))
6233 ) ; end of the search for the defun keyword
6234 )
6235 (setq count (1- count))
6236 )
6237 (vhdl-keep-region-active)
6238 foundp))
6239
8d422bd5 6240(defun vhdl-beginning-of-statement (&optional count lim interactive)
d2ddb974
KH
6241 "Go to the beginning of the innermost VHDL statement.
6242With prefix arg, go back N - 1 statements. If already at the
6243beginning of a statement then go to the beginning of the preceding
6244one. If within a string or comment, or next to a comment (only
6245whitespace between), move by sentences instead of statements.
6246
8d422bd5 6247When called from a program, this function takes 3 optional args: the
0a2e512a
RF
6248prefix arg, a buffer position limit which is the farthest back to
6249search, and an argument indicating an interactive call."
8d422bd5 6250 (interactive "p\np")
d2ddb974
KH
6251 (let ((count (or count 1))
6252 (case-fold-search t)
6253 (lim (or lim (point-min)))
6254 (here (point))
6255 state)
6256 (save-excursion
6257 (goto-char lim)
6258 (setq state (parse-partial-sexp (point) here nil nil)))
8d422bd5 6259 (if (and interactive
d2ddb974
KH
6260 (or (nth 3 state)
6261 (nth 4 state)
6262 (looking-at (concat "[ \t]*" comment-start-skip))))
6263 (forward-sentence (- count))
6264 (while (> count 0)
6265 (vhdl-beginning-of-statement-1 lim)
6266 (setq count (1- count))))
6267 ;; its possible we've been left up-buf of lim
6268 (goto-char (max (point) lim))
6269 )
6270 (vhdl-keep-region-active))
6271
6272(defconst vhdl-e-o-s-re
6273 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6274
6275(defun vhdl-end-of-statement ()
6276 "Very simple implementation."
6277 (interactive)
6278 (re-search-forward vhdl-e-o-s-re))
6279
6280(defconst vhdl-b-o-s-re
6281 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6282 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6283
6284(defun vhdl-beginning-of-statement-1 (&optional lim)
5eabfe72
KH
6285 "Move to the start of the current statement, or the previous
6286statement if already at the beginning of one."
d2ddb974
KH
6287 (let ((lim (or lim (point-min)))
6288 (here (point))
6289 (pos (point))
6290 donep)
6291 ;; go backwards one balanced expression, but be careful of
6292 ;; unbalanced paren being reached
6293 (if (not (vhdl-safe (progn (backward-sexp) t)))
6294 (progn
6295 (backward-up-list 1)
6296 (forward-char)
6297 (vhdl-forward-syntactic-ws here)
6298 (setq donep t)))
6299 (while (and (not donep)
6300 (not (bobp))
6301 ;; look backwards for a statement boundary
6302 (re-search-backward vhdl-b-o-s-re lim 'move))
6303 (if (or (= (preceding-char) ?_)
3dcb36b7 6304 (vhdl-in-literal))
d2ddb974
KH
6305 (backward-char)
6306 (cond
6307 ;; If we are looking at an open paren, then stop after it
6308 ((eq (following-char) ?\()
6309 (forward-char)
6310 (vhdl-forward-syntactic-ws here)
6311 (setq donep t))
6312 ;; If we are looking at a close paren, then skip it
6313 ((eq (following-char) ?\))
6314 (forward-char)
6315 (setq pos (point))
6316 (backward-sexp)
6317 (if (< (point) lim)
6318 (progn (goto-char pos)
6319 (vhdl-forward-syntactic-ws here)
6320 (setq donep t))))
6321 ;; If we are looking at a semicolon, then stop
6322 ((eq (following-char) ?\;)
6323 (progn
6324 (forward-char)
6325 (vhdl-forward-syntactic-ws here)
6326 (setq donep t)))
6327 ;; If we are looking at a "begin", then stop
6328 ((and (looking-at vhdl-begin-fwd-re)
6329 (/= (preceding-char) ?_)
6330 (vhdl-begin-p nil))
6331 ;; If it's a leader "begin", then find the
6332 ;; right place
6333 (if (looking-at vhdl-leader-re)
6334 (save-excursion
6335 ;; set a default stop point at the begin
6336 (setq pos (point))
6337 ;; is the start point inside the leader area ?
6338 (goto-char (vhdl-end-of-leader))
6339 (vhdl-forward-syntactic-ws here)
6340 (if (< (point) here)
6341 ;; start point was not inside leader area
6342 ;; set stop point at word after leader
6343 (setq pos (point))))
6344 (forward-word 1)
6345 (vhdl-forward-syntactic-ws here)
6346 (setq pos (point)))
6347 (goto-char pos)
6348 (setq donep t))
6349 ;; If we are looking at a "statement", then stop
6350 ((and (looking-at vhdl-statement-fwd-re)
6351 (/= (preceding-char) ?_)
6352 (vhdl-statement-p nil))
6353 (setq donep t))
6354 ;; If we are looking at a case alternative key, then stop
5eabfe72
KH
6355 ((and (looking-at vhdl-case-alternative-re)
6356 (vhdl-case-alternative-p lim))
d2ddb974
KH
6357 (save-excursion
6358 ;; set a default stop point at the when
6359 (setq pos (point))
6360 ;; is the start point inside the case alternative key ?
6361 (looking-at vhdl-case-alternative-re)
6362 (goto-char (match-end 0))
6363 (vhdl-forward-syntactic-ws here)
6364 (if (< (point) here)
6365 ;; start point was not inside the case alternative key
6366 ;; set stop point at word after case alternative keyleader
6367 (setq pos (point))))
6368 (goto-char pos)
6369 (setq donep t))
6370 ;; Bogus find, continue
6371 (t
6372 (backward-char)))))
6373 ))
6374
6375;; Defuns for calculating the current syntactic state:
6376
6377(defun vhdl-get-library-unit (bod placeholder)
a4c6cfad
JB
6378 "If there is an enclosing library unit at BOD, with its \"begin\"
6379keyword at PLACEHOLDER, then return the library unit type."
d2ddb974
KH
6380 (let ((here (vhdl-point 'bol)))
6381 (if (save-excursion
6382 (goto-char placeholder)
6383 (vhdl-safe (vhdl-forward-sexp 1 bod))
6384 (<= here (point)))
6385 (save-excursion
6386 (goto-char bod)
6387 (cond
6388 ((looking-at "e") 'entity)
6389 ((looking-at "a") 'architecture)
6390 ((looking-at "c") 'configuration)
6391 ((looking-at "p")
6392 (save-excursion
6393 (goto-char bod)
6394 (forward-sexp)
6395 (vhdl-forward-syntactic-ws here)
6396 (if (looking-at "body\\b[^_]")
6397 'package-body 'package))))))
6398 ))
6399
6400(defun vhdl-get-block-state (&optional lim)
5eabfe72 6401 "Finds and records all the closest opens.
a4c6cfad 6402LIM is the furthest back we need to search (it should be the
5eabfe72 6403previous libunit keyword)."
d2ddb974
KH
6404 (let ((here (point))
6405 (lim (or lim (point-min)))
6406 keyword sexp-start sexp-mid sexp-end
6407 preceding-sexp containing-sexp
6408 containing-begin containing-mid containing-paren)
6409 (save-excursion
6410 ;; Find the containing-paren, and use that as the limit
6411 (if (setq containing-paren
6412 (save-restriction
6413 (narrow-to-region lim (point))
6414 (vhdl-safe (scan-lists (point) -1 1))))
6415 (setq lim containing-paren))
6416 ;; Look backwards for "begin" and "end" keywords.
6417 (while (and (> (point) lim)
6418 (not containing-sexp))
6419 (setq keyword (vhdl-backward-to-block lim))
6420 (cond
6421 ((eq keyword 'begin)
6422 ;; Found a "begin" keyword
6423 (setq sexp-start (point))
6424 (setq sexp-mid (vhdl-corresponding-mid lim))
6425 (setq sexp-end (vhdl-safe
6426 (save-excursion
6427 (vhdl-forward-sexp 1 lim) (point))))
6428 (if (and sexp-end (<= sexp-end here))
6429 ;; we want to record this sexp, but we only want to
6430 ;; record the last-most of any of them before here
6431 (or preceding-sexp
6432 (setq preceding-sexp sexp-start))
6433 ;; we're contained in this sexp so put sexp-start on
6434 ;; front of list
6435 (setq containing-sexp sexp-start)
6436 (setq containing-mid sexp-mid)
6437 (setq containing-begin t)))
6438 ((eq keyword 'end)
6439 ;; Found an "end" keyword
6440 (forward-sexp)
6441 (setq sexp-end (point))
6442 (setq sexp-mid nil)
6443 (setq sexp-start
6444 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6445 (progn (backward-sexp) (point))))
6446 ;; we want to record this sexp, but we only want to
6447 ;; record the last-most of any of them before here
6448 (or preceding-sexp
6449 (setq preceding-sexp sexp-start)))
6450 )))
6451 ;; Check if the containing-paren should be the containing-sexp
6452 (if (and containing-paren
6453 (or (null containing-sexp)
6454 (< containing-sexp containing-paren)))
6455 (setq containing-sexp containing-paren
6456 preceding-sexp nil
6457 containing-begin nil
6458 containing-mid nil))
6459 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6460 ))
6461
6462
6463(defconst vhdl-s-c-a-re
6464 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6465
6466(defun vhdl-skip-case-alternative (&optional lim)
5eabfe72 6467 "Skip forward over case/when bodies, with optional maximal
a4c6cfad
JB
6468limit. If no next case alternative is found, nil is returned and
6469point is not moved."
d2ddb974
KH
6470 (let ((lim (or lim (point-max)))
6471 (here (point))
6472 donep foundp)
6473 (while (and (< (point) lim)
6474 (not donep))
6475 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6476 (save-match-data
6477 (not (vhdl-in-literal)))
6478 (/= (match-beginning 0) here))
6479 (progn
6480 (goto-char (match-beginning 0))
6481 (cond
6482 ((and (looking-at "case")
6483 (re-search-forward "\\bis[^_]" lim t))
6484 (backward-sexp)
6485 (vhdl-forward-sexp))
6486 (t
6487 (setq donep t
6488 foundp t))))))
6489 (if (not foundp)
6490 (goto-char here))
6491 foundp))
6492
6493(defun vhdl-backward-skip-label (&optional lim)
5eabfe72 6494 "Skip backward over a label, with optional maximal
a4c6cfad 6495limit. If label is not found, nil is returned and point
5eabfe72 6496is not moved."
d2ddb974
KH
6497 (let ((lim (or lim (point-min)))
6498 placeholder)
6499 (if (save-excursion
6500 (vhdl-backward-syntactic-ws lim)
6501 (and (eq (preceding-char) ?:)
6502 (progn
6503 (backward-sexp)
6504 (setq placeholder (point))
6505 (looking-at vhdl-label-key))))
6506 (goto-char placeholder))
6507 ))
6508
6509(defun vhdl-forward-skip-label (&optional lim)
5eabfe72
KH
6510 "Skip forward over a label, with optional maximal
6511limit. If label is not found, nil is returned and point
6512is not moved."
d2ddb974
KH
6513 (let ((lim (or lim (point-max))))
6514 (if (looking-at vhdl-label-key)
6515 (progn
6516 (goto-char (match-end 0))
6517 (vhdl-forward-syntactic-ws lim)))
6518 ))
6519
6520(defun vhdl-get-syntactic-context ()
5eabfe72 6521 "Guess the syntactic description of the current line of VHDL code."
d2ddb974
KH
6522 (save-excursion
6523 (save-restriction
6524 (beginning-of-line)
6525 (let* ((indent-point (point))
6526 (case-fold-search t)
6527 vec literal containing-sexp preceding-sexp
6528 containing-begin containing-mid containing-leader
6529 char-before-ip char-after-ip begin-after-ip end-after-ip
6530 placeholder lim library-unit
6531 )
6532
6533 ;; Reset the syntactic context
6534 (setq vhdl-syntactic-context nil)
6535
6536 (save-excursion
6537 ;; Move to the start of the previous library unit, and
6538 ;; record the position of the "begin" keyword.
6539 (setq placeholder (vhdl-beginning-of-libunit))
6540 ;; The position of the "libunit" keyword gives us a gross
6541 ;; limit point.
6542 (setq lim (point))
6543 )
6544
6545 ;; If there is a previous library unit, and we are enclosed by
6546 ;; it, then set the syntax accordingly.
6547 (and placeholder
6548 (setq library-unit (vhdl-get-library-unit lim placeholder))
6549 (vhdl-add-syntax library-unit lim))
6550
6551 ;; Find the surrounding state.
6552 (if (setq vec (vhdl-get-block-state lim))
6553 (progn
6554 (setq containing-sexp (aref vec 0))
6555 (setq preceding-sexp (aref vec 1))
6556 (setq containing-begin (aref vec 2))
6557 (setq containing-mid (aref vec 3))
6558 ))
6559
6560 ;; set the limit on the farthest back we need to search
6561 (setq lim (if containing-sexp
6562 (save-excursion
6563 (goto-char containing-sexp)
6564 ;; set containing-leader if required
6565 (if (looking-at vhdl-leader-re)
6566 (setq containing-leader (vhdl-end-of-leader)))
6567 (vhdl-point 'bol))
6568 (point-min)))
6569
6570 ;; cache char before and after indent point, and move point to
6571 ;; the most likely position to perform the majority of tests
6572 (goto-char indent-point)
6573 (skip-chars-forward " \t")
3dcb36b7 6574 (setq literal (vhdl-in-literal))
d2ddb974
KH
6575 (setq char-after-ip (following-char))
6576 (setq begin-after-ip (and
6577 (not literal)
6578 (looking-at vhdl-begin-fwd-re)
6579 (vhdl-begin-p)))
6580 (setq end-after-ip (and
6581 (not literal)
6582 (looking-at vhdl-end-fwd-re)
6583 (vhdl-end-p)))
6584 (vhdl-backward-syntactic-ws lim)
6585 (setq char-before-ip (preceding-char))
6586 (goto-char indent-point)
6587 (skip-chars-forward " \t")
6588
6589 ;; now figure out syntactic qualities of the current line
6590 (cond
6591 ;; CASE 1: in a string or comment.
6592 ((memq literal '(string comment))
6593 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6594 ;; CASE 2: Line is at top level.
6595 ((null containing-sexp)
6596 ;; Find the point to which indentation will be relative
6597 (save-excursion
6598 (if (null preceding-sexp)
6599 ;; CASE 2X.1
6600 ;; no preceding-sexp -> use the preceding statement
6601 (vhdl-beginning-of-statement-1 lim)
6602 ;; CASE 2X.2
6603 ;; if there is a preceding-sexp then indent relative to it
6604 (goto-char preceding-sexp)
6605 ;; if not at boi, then the block-opening keyword is
6606 ;; probably following a label, so we need a different
6607 ;; relpos
6608 (if (/= (point) (vhdl-point 'boi))
6609 ;; CASE 2X.3
6610 (vhdl-beginning-of-statement-1 lim)))
6611 ;; v-b-o-s could have left us at point-min
6612 (and (bobp)
6613 ;; CASE 2X.4
6614 (vhdl-forward-syntactic-ws indent-point))
6615 (setq placeholder (point)))
6616 (cond
6617 ;; CASE 2A : we are looking at a block-open
6618 (begin-after-ip
6619 (vhdl-add-syntax 'block-open placeholder))
6620 ;; CASE 2B: we are looking at a block-close
6621 (end-after-ip
6622 (vhdl-add-syntax 'block-close placeholder))
6623 ;; CASE 2C: we are looking at a top-level statement
6624 ((progn
6625 (vhdl-backward-syntactic-ws lim)
6626 (or (bobp)
6627 (= (preceding-char) ?\;)))
6628 (vhdl-add-syntax 'statement placeholder))
6629 ;; CASE 2D: we are looking at a top-level statement-cont
6630 (t
6631 (vhdl-beginning-of-statement-1 lim)
6632 ;; v-b-o-s could have left us at point-min
6633 (and (bobp)
6634 ;; CASE 2D.1
6635 (vhdl-forward-syntactic-ws indent-point))
6636 (vhdl-add-syntax 'statement-cont (point)))
6637 )) ; end CASE 2
6638 ;; CASE 3: line is inside parentheses. Most likely we are
6639 ;; either in a subprogram argument (interface) list, or a
6640 ;; continued expression containing parentheses.
6641 ((null containing-begin)
6642 (vhdl-backward-syntactic-ws containing-sexp)
6643 (cond
6644 ;; CASE 3A: we are looking at the arglist closing paren
6645 ((eq char-after-ip ?\))
6646 (goto-char containing-sexp)
6647 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6648 ;; CASE 3B: we are looking at the first argument in an empty
6649 ;; argument list.
6650 ((eq char-before-ip ?\()
6651 (goto-char containing-sexp)
6652 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6653 ;; CASE 3C: we are looking at an arglist continuation line,
6654 ;; but the preceding argument is on the same line as the
6655 ;; opening paren. This case includes multi-line
6656 ;; expression paren groupings.
6657 ((and (save-excursion
6658 (goto-char (1+ containing-sexp))
6659 (skip-chars-forward " \t")
6660 (not (eolp))
6661 (not (looking-at "--")))
6662 (save-excursion
6663 (vhdl-beginning-of-statement-1 containing-sexp)
6664 (skip-chars-backward " \t(")
6665 (<= (point) containing-sexp)))
6666 (goto-char containing-sexp)
6667 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6668 ;; CASE 3D: we are looking at just a normal arglist
6669 ;; continuation line
6670 (t (vhdl-beginning-of-statement-1 containing-sexp)
6671 (vhdl-forward-syntactic-ws indent-point)
6672 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6673 ))
6674 ;; CASE 4: A block mid open
6675 ((and begin-after-ip
6676 (looking-at containing-mid))
6677 (goto-char containing-sexp)
6678 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6679 (if (looking-at vhdl-trailer-re)
6680 ;; CASE 4.1
6681 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6682 (vhdl-backward-skip-label (vhdl-point 'boi))
6683 (vhdl-add-syntax 'block-open (point)))
6684 ;; CASE 5: block close brace
6685 (end-after-ip
6686 (goto-char containing-sexp)
6687 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6688 (if (looking-at vhdl-trailer-re)
6689 ;; CASE 5.1
6690 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6691 (vhdl-backward-skip-label (vhdl-point 'boi))
6692 (vhdl-add-syntax 'block-close (point)))
6693 ;; CASE 6: A continued statement
6694 ((and (/= char-before-ip ?\;)
6695 ;; check it's not a trailer begin keyword, or a begin
6696 ;; keyword immediately following a label.
6697 (not (and begin-after-ip
6698 (or (looking-at vhdl-trailer-re)
6699 (save-excursion
6700 (vhdl-backward-skip-label containing-sexp)))))
6701 ;; check it's not a statement keyword
6702 (not (and (looking-at vhdl-statement-fwd-re)
6703 (vhdl-statement-p)))
6704 ;; see if the b-o-s is before the indent point
6705 (> indent-point
6706 (save-excursion
6707 (vhdl-beginning-of-statement-1 containing-sexp)
6708 ;; If we ended up after a leader, then this will
6709 ;; move us forward to the start of the first
6710 ;; statement. Note that a containing sexp here is
6711 ;; always a keyword, not a paren, so this will
6712 ;; have no effect if we hit the containing-sexp.
6713 (vhdl-forward-syntactic-ws indent-point)
6714 (setq placeholder (point))))
6715 ;; check it's not a block-intro
6716 (/= placeholder containing-sexp)
6717 ;; check it's not a case block-intro
6718 (save-excursion
6719 (goto-char placeholder)
6720 (or (not (looking-at vhdl-case-alternative-re))
6721 (> (match-end 0) indent-point))))
6722 ;; Make placeholder skip a label, but only if it puts us
6723 ;; before the indent point at the start of a line.
6724 (let ((new placeholder))
6725 (if (and (> indent-point
6726 (save-excursion
6727 (goto-char placeholder)
6728 (vhdl-forward-skip-label indent-point)
6729 (setq new (point))))
6730 (save-excursion
6731 (goto-char new)
6732 (eq new (progn (back-to-indentation) (point)))))
6733 (setq placeholder new)))
6734 (vhdl-add-syntax 'statement-cont placeholder)
6735 (if begin-after-ip
6736 (vhdl-add-syntax 'block-open)))
6737 ;; Statement. But what kind?
6738 ;; CASE 7: A case alternative key
6739 ((and (looking-at vhdl-case-alternative-re)
6740 (vhdl-case-alternative-p containing-sexp))
6741 ;; for a case alternative key, we set relpos to the first
6742 ;; non-whitespace char on the line containing the "case"
6743 ;; keyword.
6744 (goto-char containing-sexp)
6745 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6746 (if (looking-at vhdl-trailer-re)
6747 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6748 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6749 ;; CASE 8: statement catchall
6750 (t
6751 ;; we know its a statement, but we need to find out if it is
6752 ;; the first statement in a block
6753 (if containing-leader
6754 (goto-char containing-leader)
6755 (goto-char containing-sexp)
6756 ;; Note that a containing sexp here is always a keyword,
6757 ;; not a paren, so skip over the keyword.
6758 (forward-sexp))
6759 ;; move to the start of the first statement
6760 (vhdl-forward-syntactic-ws indent-point)
6761 (setq placeholder (point))
6762 ;; we want to ignore case alternatives keys when skipping forward
6763 (let (incase-p)
6764 (while (looking-at vhdl-case-alternative-re)
6765 (setq incase-p (point))
6766 ;; we also want to skip over the body of the
6767 ;; case/when statement if that doesn't put us at
6768 ;; after the indent-point
6769 (while (vhdl-skip-case-alternative indent-point))
6770 ;; set up the match end
6771 (looking-at vhdl-case-alternative-re)
6772 (goto-char (match-end 0))
6773 ;; move to the start of the first case alternative statement
6774 (vhdl-forward-syntactic-ws indent-point)
6775 (setq placeholder (point)))
6776 (cond
6777 ;; CASE 8A: we saw a case/when statement so we must be
6778 ;; in a switch statement. find out if we are at the
6779 ;; statement just after a case alternative key
6780 ((and incase-p
6781 (= (point) indent-point))
6782 ;; relpos is the "when" keyword
6783 (vhdl-add-syntax 'statement-case-intro incase-p))
6784 ;; CASE 8B: any old statement
6785 ((< (point) indent-point)
6786 ;; relpos is the first statement of the block
6787 (vhdl-add-syntax 'statement placeholder)
6788 (if begin-after-ip
6789 (vhdl-add-syntax 'block-open)))
6790 ;; CASE 8C: first statement in a block
6791 (t
6792 (goto-char containing-sexp)
6793 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6794 (if (looking-at vhdl-trailer-re)
6795 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6796 (vhdl-backward-skip-label (vhdl-point 'boi))
6797 (vhdl-add-syntax 'statement-block-intro (point))
6798 (if begin-after-ip
6799 (vhdl-add-syntax 'block-open)))
6800 )))
6801 )
6802
6803 ;; now we need to look at any modifiers
6804 (goto-char indent-point)
6805 (skip-chars-forward " \t")
6806 (if (looking-at "--")
6807 (vhdl-add-syntax 'comment))
0a2e512a
RF
6808 (if (eq literal 'pound)
6809 (vhdl-add-syntax 'cpp-macro))
d2ddb974
KH
6810 ;; return the syntax
6811 vhdl-syntactic-context))))
6812
6813;; Standard indentation line-ups:
6814
6815(defun vhdl-lineup-arglist (langelem)
5eabfe72
KH
6816 "Lineup the current arglist line with the arglist appearing just
6817after the containing paren which starts the arglist."
d2ddb974
KH
6818 (save-excursion
6819 (let* ((containing-sexp
6820 (save-excursion
6821 ;; arglist-cont-nonempty gives relpos ==
6822 ;; to boi of containing-sexp paren. This
6823 ;; is good when offset is +, but bad
6824 ;; when it is vhdl-lineup-arglist, so we
6825 ;; have to special case a kludge here.
6826 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6827 (progn
6828 (beginning-of-line)
6829 (backward-up-list 1)
6830 (skip-chars-forward " \t" (vhdl-point 'eol)))
6831 (goto-char (cdr langelem)))
6832 (point)))
6833 (cs-curcol (save-excursion
6834 (goto-char (cdr langelem))
6835 (current-column))))
6836 (if (save-excursion
6837 (beginning-of-line)
6838 (looking-at "[ \t]*)"))
6839 (progn (goto-char (match-end 0))
6840 (backward-sexp)
6841 (forward-char)
6842 (vhdl-forward-syntactic-ws)
6843 (- (current-column) cs-curcol))
6844 (goto-char containing-sexp)
6845 (or (eolp)
6846 (let ((eol (vhdl-point 'eol))
6847 (here (progn
6848 (forward-char)
6849 (skip-chars-forward " \t")
6850 (point))))
6851 (vhdl-forward-syntactic-ws)
6852 (if (< (point) eol)
6853 (goto-char here))))
6854 (- (current-column) cs-curcol)
6855 ))))
6856
6857(defun vhdl-lineup-arglist-intro (langelem)
5eabfe72 6858 "Lineup an arglist-intro line to just after the open paren."
d2ddb974
KH
6859 (save-excursion
6860 (let ((cs-curcol (save-excursion
6861 (goto-char (cdr langelem))
6862 (current-column)))
6863 (ce-curcol (save-excursion
6864 (beginning-of-line)
6865 (backward-up-list 1)
6866 (skip-chars-forward " \t" (vhdl-point 'eol))
6867 (current-column))))
6868 (- ce-curcol cs-curcol -1))))
6869
6870(defun vhdl-lineup-comment (langelem)
5eabfe72
KH
6871 "Support old behavior for comment indentation. We look at
6872vhdl-comment-only-line-offset to decide how to indent comment
6873only-lines."
d2ddb974
KH
6874 (save-excursion
6875 (back-to-indentation)
6876 ;; at or to the right of comment-column
6877 (if (>= (current-column) comment-column)
6878 (vhdl-comment-indent)
6879 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6880 (if (not (bolp))
6881 (or (car-safe vhdl-comment-only-line-offset)
6882 vhdl-comment-only-line-offset)
6883 (or (cdr-safe vhdl-comment-only-line-offset)
6884 (car-safe vhdl-comment-only-line-offset)
0a2e512a 6885 -1000 ;jam it against the left side
d2ddb974
KH
6886 )))))
6887
6888(defun vhdl-lineup-statement-cont (langelem)
5eabfe72 6889 "Line up statement-cont after the assignment operator."
d2ddb974
KH
6890 (save-excursion
6891 (let* ((relpos (cdr langelem))
6892 (assignp (save-excursion
6893 (goto-char (vhdl-point 'boi))
6894 (and (re-search-forward "\\(<\\|:\\)="
6895 (vhdl-point 'eol) t)
6896 (- (point) (vhdl-point 'boi)))))
6897 (curcol (progn
6898 (goto-char relpos)
6899 (current-column)))
6900 foundp)
6901 (while (and (not foundp)
6902 (< (point) (vhdl-point 'eol)))
6903 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
3dcb36b7 6904 (if (vhdl-in-literal)
d2ddb974
KH
6905 (forward-char)
6906 (if (= (preceding-char) ?\()
6907 ;; skip over any parenthesized expressions
6908 (goto-char (min (vhdl-point 'eol)
6909 (scan-lists (point) 1 1)))
6910 ;; found an assignment operator (not at eol)
6911 (setq foundp (not (looking-at "\\s-*$"))))))
6912 (if (not foundp)
6913 ;; there's no assignment operator on the line
6914 vhdl-basic-offset
6915 ;; calculate indentation column after assign and ws, unless
6916 ;; our line contains an assignment operator
6917 (if (not assignp)
6918 (progn
6919 (forward-char)
6920 (skip-chars-forward " \t")
6921 (setq assignp 0)))
6922 (- (current-column) assignp curcol))
6923 )))
6924
5eabfe72 6925;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 6926;; Progress reporting
d2ddb974 6927
3dcb36b7
JB
6928(defvar vhdl-progress-info nil
6929 "Array variable for progress information: 0 begin, 1 end, 2 time.")
5eabfe72 6930
3dcb36b7
JB
6931(defun vhdl-update-progress-info (string pos)
6932 "Update progress information."
6933 (when (and vhdl-progress-info (not noninteractive)
6934 (< vhdl-progress-interval
6935 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
b0cf7916
JB
6936 (let ((delta (- (aref vhdl-progress-info 1)
6937 (aref vhdl-progress-info 0))))
6938 (if (= 0 delta)
6939 (message (concat string "... (100%s)") "%")
6940 (message (concat string "... (%2d%s)")
6941 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6942 delta) "%")))
3dcb36b7 6943 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
5eabfe72 6944
3dcb36b7
JB
6945;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6946;; Indentation commands
5eabfe72
KH
6947
6948(defun vhdl-electric-tab (&optional prefix-arg)
6949 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7
JB
6950else if right of non whitespace on line then insert tab,
6951else if last command was a tab or return then dedent one step or if a comment
6952toggle between normal indent and inline comment indent,
d2ddb974
KH
6953else indent `correctly'."
6954 (interactive "*P")
3dcb36b7
JB
6955 (vhdl-prepare-search-2
6956 (cond
75e0af77
DN
6957 ;; indent region if region is active
6958 ((and (not (featurep 'xemacs)) (use-region-p))
6959 (vhdl-indent-region (region-beginning) (region-end) nil))
3dcb36b7
JB
6960 ;; expand word
6961 ((= (char-syntax (preceding-char)) ?w)
6962 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6963 (case-replace nil)
6964 (hippie-expand-only-buffers
6965 (or (and (boundp 'hippie-expand-only-buffers)
6966 hippie-expand-only-buffers)
6967 '(vhdl-mode))))
6968 (vhdl-expand-abbrev prefix-arg)))
6969 ;; expand parenthesis
6970 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6971 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6972 (case-replace nil))
6973 (vhdl-expand-paren prefix-arg)))
6974 ;; insert tab
6975 ((> (current-column) (current-indentation))
6976 (insert-tab))
6977 ;; toggle comment indent
6978 ((and (looking-at "--")
6979 (or (eq last-command 'vhdl-electric-tab)
6980 (eq last-command 'vhdl-electric-return)))
6981 (cond ((= (current-indentation) 0) ; no indent
6982 (indent-to 1)
6983 (indent-according-to-mode))
6984 ((< (current-indentation) comment-column) ; normal indent
6985 (indent-to comment-column)
6986 (indent-according-to-mode))
6987 (t ; inline comment indent
453cfeb3 6988 (delete-region (line-beginning-position) (point)))))
3dcb36b7
JB
6989 ;; dedent
6990 ((and (>= (current-indentation) vhdl-basic-offset)
6991 (or (eq last-command 'vhdl-electric-tab)
6992 (eq last-command 'vhdl-electric-return)))
6993 (backward-delete-char-untabify vhdl-basic-offset nil))
6994 ;; indent line
6995 (t (indent-according-to-mode)))
5eabfe72
KH
6996 (setq this-command 'vhdl-electric-tab)))
6997
6998(defun vhdl-electric-return ()
d2ddb974
KH
6999 "newline-and-indent or indent-new-comment-line if in comment and preceding
7000character is a space."
7001 (interactive)
7002 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7003 (indent-new-comment-line)
3dcb36b7
JB
7004 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7005 (vhdl-fix-case-word -1))
5eabfe72
KH
7006 (newline-and-indent)))
7007
d2ddb974 7008(defun vhdl-indent-line ()
5eabfe72 7009 "Indent the current line as VHDL code. Returns the amount of
d2ddb974
KH
7010indentation change."
7011 (interactive)
3dcb36b7 7012 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
d2ddb974 7013 (pos (- (point-max) (point)))
3dcb36b7
JB
7014 (indent
7015 (if syntax
7016 ;; indent syntax-based
7017 (if (and (eq (caar syntax) 'comment)
7018 (>= (vhdl-get-offset (car syntax)) comment-column))
7019 ;; special case: comments at or right of comment-column
7020 (vhdl-get-offset (car syntax))
7021 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7022 ;; indent like previous nonblank line
7023 (save-excursion (beginning-of-line)
7024 (re-search-backward "^[^\n]" nil t)
7025 (current-indentation))))
5eabfe72 7026 (shift-amt (- indent (current-indentation))))
d2ddb974
KH
7027 (and vhdl-echo-syntactic-information-p
7028 (message "syntax: %s, indent= %d" syntax indent))
5eabfe72 7029 (unless (zerop shift-amt)
d2ddb974
KH
7030 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7031 (beginning-of-line)
7032 (indent-to indent))
7033 (if (< (point) (vhdl-point 'boi))
7034 (back-to-indentation)
7035 ;; If initial point was within line's indentation, position after
7036 ;; the indentation. Else stay at same point in text.
5eabfe72
KH
7037 (when (> (- (point-max) pos) (point))
7038 (goto-char (- (point-max) pos))))
d2ddb974 7039 (run-hooks 'vhdl-special-indent-hook)
3dcb36b7 7040 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
d2ddb974
KH
7041 shift-amt))
7042
3dcb36b7 7043(defun vhdl-indent-region (beg end column)
5eabfe72
KH
7044 "Indent region as VHDL code.
7045Adds progress reporting to `indent-region'."
7046 (interactive "r\nP")
3dcb36b7
JB
7047 (when vhdl-progress-interval
7048 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7049 (count-lines (point-min) end) 0)))
7050 (indent-region beg end column)
5eabfe72
KH
7051 (when vhdl-progress-interval (message "Indenting...done"))
7052 (setq vhdl-progress-info nil))
d2ddb974 7053
3dcb36b7
JB
7054(defun vhdl-indent-buffer ()
7055 "Indent whole buffer as VHDL code.
7056Calls `indent-region' for whole buffer and adds progress reporting."
7057 (interactive)
7058 (vhdl-indent-region (point-min) (point-max) nil))
7059
7060(defun vhdl-indent-group ()
7061 "Indent group of lines between empty lines."
7062 (interactive)
7063 (let ((beg (save-excursion
7064 (if (re-search-backward vhdl-align-group-separate nil t)
7065 (point-marker)
7066 (point-min-marker))))
7067 (end (save-excursion
7068 (if (re-search-forward vhdl-align-group-separate nil t)
7069 (point-marker)
7070 (point-max-marker)))))
7071 (vhdl-indent-region beg end nil)))
7072
d2ddb974
KH
7073(defun vhdl-indent-sexp (&optional endpos)
7074 "Indent each line of the list starting just after point.
7075If optional arg ENDPOS is given, indent each line, stopping when
7076ENDPOS is encountered."
7077 (interactive)
7078 (save-excursion
7079 (let ((beg (point))
5eabfe72 7080 (end (progn (vhdl-forward-sexp nil endpos) (point))))
d2ddb974
KH
7081 (indent-region beg end nil))))
7082
5eabfe72 7083;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
7084;; Miscellaneous commands
7085
7086(defun vhdl-show-syntactic-information ()
7087 "Show syntactic information for current line."
7088 (interactive)
3dcb36b7 7089 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
d2ddb974
KH
7090 (vhdl-keep-region-active))
7091
7092;; Verification and regression functions:
7093
7094(defun vhdl-regress-line (&optional arg)
7095 "Check syntactic information for current line."
7096 (interactive "P")
7097 (let ((expected (save-excursion
7098 (end-of-line)
5eabfe72
KH
7099 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7100 (forward-char 4)
7101 (read (current-buffer)))))
d2ddb974
KH
7102 (actual (vhdl-get-syntactic-context))
7103 (expurgated))
7104 ;; remove the library unit symbols
51b5ad57 7105 (mapc
d2ddb974
KH
7106 (function
7107 (lambda (elt)
7108 (if (memq (car elt) '(entity configuration package
7109 package-body architecture))
7110 nil
7111 (setq expurgated (append expurgated (list elt))))))
7112 actual)
7113 (if (and (not arg) expected (listp expected))
7114 (if (not (equal expected expurgated))
3dcb36b7 7115 (error "ERROR: Should be: %s, is: %s" expected expurgated))
d2ddb974
KH
7116 (save-excursion
7117 (beginning-of-line)
5eabfe72
KH
7118 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7119 (end-of-line)
7120 (if (search-backward " -- ((" (vhdl-point 'bol) t)
453cfeb3 7121 (delete-region (point) (line-end-position)))
5eabfe72
KH
7122 (insert " -- ")
7123 (insert (format "%s" expurgated))))))
d2ddb974
KH
7124 (vhdl-keep-region-active))
7125
7126
5eabfe72
KH
7127;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7128;;; Alignment, whitespace fixup, beautifying
7129;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7130
3dcb36b7 7131(defconst vhdl-align-alist
d2ddb974
KH
7132 '(
7133 ;; after some keywords
3dcb36b7
JB
7134 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7135 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
d2ddb974 7136 ;; before ':'
5eabfe72 7137 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
d2ddb974 7138 ;; after direction specifications
5eabfe72
KH
7139 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7140 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7141 ;; before "==", ":=", "=>", and "<="
3dcb36b7 7142 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
5eabfe72 7143 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
3dcb36b7 7144 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
d2ddb974
KH
7145 ;; before some keywords
7146 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
d2ddb974
KH
7147 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7148 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
3dcb36b7
JB
7149 ;; before "=>" since "when/else ... =>" can occur
7150 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
d2ddb974 7151 )
5eabfe72 7152 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
d2ddb974
KH
7153It is searched in order. If REGEXP is found anywhere in the first
7154line of a region to be aligned, ALIGN-PATTERN will be used for that
7155region. ALIGN-PATTERN must include the whitespace to be expanded or
5eabfe72
KH
7156contracted. It may also provide regexps for the text surrounding the
7157whitespace. SUBEXP specifies which sub-expression of
d2ddb974
KH
7158ALIGN-PATTERN matches the white space to be expanded/contracted.")
7159
3dcb36b7
JB
7160;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7161;; Align code
7162
d2ddb974
KH
7163(defvar vhdl-align-try-all-clauses t
7164 "If REGEXP is not found on the first line of the region that clause
5eabfe72 7165is ignored. If this variable is non-nil, then the clause is tried anyway.")
d2ddb974 7166
3dcb36b7
JB
7167(defun vhdl-do-group (function &optional spacing)
7168 "Apply FUNCTION on group of lines between empty lines."
7169 (let
7170 ;; search for group beginning
7171 ((beg (save-excursion
7172 (if (re-search-backward vhdl-align-group-separate nil t)
7173 (progn (beginning-of-line 2) (back-to-indentation) (point))
7174 (point-min))))
7175 ;; search for group end
7176 (end (save-excursion
7177 (if (re-search-forward vhdl-align-group-separate nil t)
7178 (progn (beginning-of-line) (point))
7179 (point-max)))))
7180 ;; run FUNCTION
7181 (funcall function beg end spacing)))
7182
7183(defun vhdl-do-list (function &optional spacing)
7184 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7185parentheses."
7186 (let (beg end)
7187 (save-excursion
7188 ;; search for beginning of balanced group of parentheses
7189 (setq beg (vhdl-re-search-backward "[()]" nil t))
7190 (while (looking-at ")")
7191 (forward-char) (backward-sexp)
7192 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7193 ;; search for end of balanced group of parentheses
7194 (when beg
7195 (forward-list)
7196 (setq end (point))
7197 (goto-char (1+ beg))
7198 (skip-chars-forward " \t\n")
7199 (setq beg (point))))
7200 ;; run FUNCTION
7201 (if beg
7202 (funcall function beg end spacing)
7203 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7204
7205(defun vhdl-do-same-indent (function &optional spacing)
7206 "Apply FUNCTION to block of lines with same indent."
7207 (let ((indent (current-indentation))
7208 beg end)
7209 ;; search for first line with same indent
7210 (save-excursion
7211 (while (and (not (bobp))
7212 (or (looking-at "^\\s-*\\(--.*\\)?$")
7213 (= (current-indentation) indent)))
7214 (unless (looking-at "^\\s-*$")
7215 (back-to-indentation) (setq beg (point)))
7216 (beginning-of-line -0)))
7217 ;; search for last line with same indent
7218 (save-excursion
7219 (while (and (not (eobp))
7220 (or (looking-at "^\\s-*\\(--.*\\)?$")
7221 (= (current-indentation) indent)))
7222 (if (looking-at "^\\s-*$")
7223 (beginning-of-line 2)
7224 (beginning-of-line 2)
7225 (setq end (point)))))
7226 ;; run FUNCTION
7227 (funcall function beg end spacing)))
7228
7229(defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
d2ddb974 7230 "Attempt to align a range of lines based on the content of the
5eabfe72
KH
7231lines. The definition of `alignment-list' determines the matching
7232order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7233is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
d2ddb974
KH
7234indentation is done before aligning."
7235 (interactive "r\np")
5eabfe72
KH
7236 (setq alignment-list (or alignment-list vhdl-align-alist))
7237 (setq spacing (or spacing 1))
d2ddb974
KH
7238 (save-excursion
7239 (let (bol indent)
7240 (goto-char end)
7241 (setq end (point-marker))
7242 (goto-char begin)
5eabfe72 7243 (setq bol (setq begin (progn (beginning-of-line) (point))))
3dcb36b7 7244; (untabify bol end)
5eabfe72
KH
7245 (when indent
7246 (indent-region bol end nil))))
3dcb36b7
JB
7247 (let ((copy (copy-alist alignment-list)))
7248 (vhdl-prepare-search-2
5eabfe72
KH
7249 (while copy
7250 (save-excursion
7251 (goto-char begin)
7252 (let (element
e180ab9f 7253 (eol (point-at-eol)))
5eabfe72
KH
7254 (setq element (nth 0 copy))
7255 (when (and (or (and (listp (car element))
7256 (memq major-mode (car element)))
7257 (eq major-mode (car element)))
7258 (or vhdl-align-try-all-clauses
7259 (re-search-forward (car (cdr element)) eol t)))
3dcb36b7 7260 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
5eabfe72
KH
7261 (car (cdr (cdr (cdr element)))) spacing))
7262 (setq copy (cdr copy))))))))
7263
3dcb36b7 7264(defun vhdl-align-region-2 (begin end match &optional substr spacing)
d2ddb974 7265 "Align a range of lines from BEGIN to END. The regular expression
a4c6cfad 7266MATCH must match exactly one field: the whitespace to be
d2ddb974 7267contracted/expanded. The alignment column will equal the
a4c6cfad 7268rightmost column of the widest whitespace block. SPACING is
d2ddb974
KH
7269the amount of extra spaces to add to the calculated maximum required.
7270SPACING defaults to 1 so that at least one space is inserted after
7271the token in MATCH."
5eabfe72
KH
7272 (setq spacing (or spacing 1))
7273 (setq substr (or substr 1))
d2ddb974
KH
7274 (save-excursion
7275 (let (distance (max 0) (lines 0) bol eol width)
7276 ;; Determine the greatest whitespace distance to the alignment
7277 ;; character
7278 (goto-char begin)
e180ab9f 7279 (setq eol (point-at-eol)
5eabfe72 7280 bol (setq begin (progn (beginning-of-line) (point))))
d2ddb974 7281 (while (< bol end)
5eabfe72
KH
7282 (save-excursion
7283 (when (and (re-search-forward match eol t)
3dcb36b7 7284 (not (vhdl-in-literal)))
5eabfe72
KH
7285 (setq distance (- (match-beginning substr) bol))
7286 (when (> distance max)
7287 (setq max distance))))
7288 (forward-line)
7289 (setq bol (point)
e180ab9f 7290 eol (point-at-eol))
5eabfe72 7291 (setq lines (1+ lines)))
d2ddb974
KH
7292 ;; Now insert enough maxs to push each assignment operator to
7293 ;; the same column. We need to use 'lines' as a counter, since
7294 ;; the location of the mark may change
7295 (goto-char (setq bol begin))
e180ab9f 7296 (setq eol (point-at-eol))
d2ddb974 7297 (while (> lines 0)
5eabfe72 7298 (when (and (re-search-forward match eol t)
3dcb36b7 7299 (not (vhdl-in-literal)))
5eabfe72
KH
7300 (setq width (- (match-end substr) (match-beginning substr)))
7301 (setq distance (- (match-beginning substr) bol))
7302 (goto-char (match-beginning substr))
7303 (delete-char width)
7304 (insert-char ? (+ (- max distance) spacing)))
7305 (beginning-of-line)
7306 (forward-line)
7307 (setq bol (point)
e180ab9f 7308 eol (point-at-eol))
5eabfe72
KH
7309 (setq lines (1- lines))))))
7310
3dcb36b7
JB
7311(defun vhdl-align-region-groups (beg end &optional spacing
7312 no-message no-comments)
7313 "Align region, treat groups of lines separately."
d2ddb974 7314 (interactive "r\nP")
5eabfe72 7315 (save-excursion
3dcb36b7 7316 (let (orig pos)
5eabfe72
KH
7317 (goto-char beg)
7318 (beginning-of-line)
3dcb36b7 7319 (setq orig (point-marker))
5eabfe72
KH
7320 (setq beg (point))
7321 (goto-char end)
7322 (setq end (point-marker))
7323 (untabify beg end)
3dcb36b7
JB
7324 (unless no-message
7325 (when vhdl-progress-interval
7326 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7327 (count-lines (point-min) end) 0))))
5eabfe72
KH
7328 (vhdl-fixup-whitespace-region beg end t)
7329 (goto-char beg)
7330 (if (not vhdl-align-groups)
7331 ;; align entire region
3dcb36b7
JB
7332 (progn (vhdl-align-region-1 beg end spacing)
7333 (unless no-comments
7334 (vhdl-align-inline-comment-region-1 beg end)))
5eabfe72
KH
7335 ;; align groups
7336 (while (and (< beg end)
3dcb36b7 7337 (re-search-forward vhdl-align-group-separate end t))
5eabfe72 7338 (setq pos (point-marker))
3dcb36b7
JB
7339 (vhdl-align-region-1 beg pos spacing)
7340 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7341 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
5eabfe72
KH
7342 (setq beg (1+ pos))
7343 (goto-char beg))
7344 ;; align last group
7345 (when (< beg end)
3dcb36b7
JB
7346 (vhdl-align-region-1 beg end spacing)
7347 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7348 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7349 (when vhdl-indent-tabs-mode
7350 (tabify orig end))
7351 (unless no-message
7352 (when vhdl-progress-interval (message "Aligning...done"))
7353 (setq vhdl-progress-info nil)))))
7354
7355(defun vhdl-align-region (beg end &optional spacing)
7356 "Align region, treat blocks with same indent and argument lists separately."
7357 (interactive "r\nP")
7358 (if (not vhdl-align-same-indent)
7359 ;; align entire region
7360 (vhdl-align-region-groups beg end spacing)
7361 ;; align blocks with same indent and argument lists
7362 (save-excursion
7363 (let ((cur-beg beg)
7364 indent cur-end)
7365 (when vhdl-progress-interval
7366 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7367 (count-lines (point-min) end) 0)))
7368 (goto-char end)
7369 (setq end (point-marker))
7370 (goto-char cur-beg)
7371 (while (< (point) end)
7372 ;; is argument list opening?
7373 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7374 (point) (vhdl-point 'eol)))))
7375 ;; determine region for argument list
7376 (progn (goto-char cur-beg)
7377 (forward-sexp)
7378 (setq cur-end (point))
7379 (beginning-of-line 2))
7380 ;; determine region with same indent
7381 (setq indent (current-indentation))
7382 (setq cur-beg (point))
7383 (setq cur-end (vhdl-point 'bonl))
7384 (beginning-of-line 2)
7385 (while (and (< (point) end)
7386 (or (looking-at "^\\s-*\\(--.*\\)?$")
7387 (= (current-indentation) indent))
7388 (<= (save-excursion
7389 (nth 0 (parse-partial-sexp
7390 (point) (vhdl-point 'eol)))) 0))
7391 (unless (looking-at "^\\s-*$")
7392 (setq cur-end (vhdl-point 'bonl)))
7393 (beginning-of-line 2)))
7394 ;; align region
7395 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7396 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7397 (when vhdl-progress-interval (message "Aligning...done"))
7398 (setq vhdl-progress-info nil)))))
5eabfe72
KH
7399
7400(defun vhdl-align-group (&optional spacing)
7401 "Align group of lines between empty lines."
7402 (interactive)
3dcb36b7 7403 (vhdl-do-group 'vhdl-align-region spacing))
5eabfe72 7404
3dcb36b7
JB
7405(defun vhdl-align-list (&optional spacing)
7406 "Align the lines of a list surrounded by a balanced group of parentheses."
5eabfe72 7407 (interactive)
3dcb36b7
JB
7408 (vhdl-do-list 'vhdl-align-region-groups spacing))
7409
7410(defun vhdl-align-same-indent (&optional spacing)
7411 "Align block of lines with same indent."
7412 (interactive)
7413 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7414
7415(defun vhdl-align-declarations (&optional spacing)
7416 "Align the lines within the declarative part of a design unit."
7417 (interactive)
7418 (let (beg end)
7419 (vhdl-prepare-search-2
7420 (save-excursion
7421 ;; search for declarative part
7422 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7423 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7424 (setq beg (point))
7425 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7426 (setq end (point)))))
7427 (if beg
7428 (vhdl-align-region-groups beg end spacing)
7429 (error "ERROR: Not within the declarative part of a design unit"))))
7430
7431(defun vhdl-align-buffer ()
7432 "Align buffer."
7433 (interactive)
7434 (vhdl-align-region (point-min) (point-max)))
7435
7436;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7437;; Align inline comments
7438
7439(defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7440 "Align inline comments in region."
7441 (save-excursion
7442 (let ((start-max comment-column)
7443 (length-max 0)
7444 comment-list start-list tmp-list start length
7445 cur-start prev-start no-code)
7446 (setq spacing (or spacing 2))
7447 (vhdl-prepare-search-2
7448 (goto-char beg)
7449 ;; search for comment start positions and lengths
7450 (while (< (point) end)
7451 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7452 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7453 (not (save-excursion (goto-char (match-beginning 2))
7454 (vhdl-in-literal))))
7455 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7456 (setq length (- (match-end 2) (match-beginning 2)))
7457 (setq start-max (max start start-max))
7458 (setq length-max (max length length-max))
7459 (setq comment-list (cons (cons start length) comment-list)))
7460 (beginning-of-line 2))
7461 (setq comment-list
7462 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7463 ;; reduce start positions
7464 (setq start-list (list (caar comment-list)))
7465 (setq comment-list (cdr comment-list))
7466 (while comment-list
7467 (unless (or (= (caar comment-list) (car start-list))
7468 (<= (+ (car start-list) (cdar comment-list))
7469 end-comment-column))
7470 (setq start-list (cons (caar comment-list) start-list)))
7471 (setq comment-list (cdr comment-list)))
7472 ;; align lines as nicely as possible
7473 (goto-char beg)
7474 (while (< (point) end)
7475 (setq cur-start nil)
7476 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7477 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7478 (not (save-excursion
7479 (goto-char (match-beginning 3))
7480 (vhdl-in-literal))))
7481 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7482 (>= (- (match-end 2) (match-beginning 2))
7483 comment-column))))
7484 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7485 (setq length (- (match-end 3) (match-beginning 3)))
7486 (setq no-code (= (match-beginning 1) (match-end 1)))
7487 ;; insert minimum whitespace
7488 (goto-char (match-end 2))
7489 (delete-region (match-beginning 2) (match-end 2))
7490 (insert-char ?\ spacing)
7491 (setq tmp-list start-list)
7492 ;; insert additional whitespace to align
7493 (setq cur-start
7494 (cond
7495 ;; align comment-only line to inline comment of previous line
7496 ((and no-code prev-start
7497 (<= length (- end-comment-column prev-start)))
7498 prev-start)
7499 ;; align all comments at `start-max' if this is possible
7500 ((<= (+ start-max length-max) end-comment-column)
7501 start-max)
7502 ;; align at `comment-column' if possible
7503 ((and (<= start comment-column)
7504 (<= length (- end-comment-column comment-column)))
7505 comment-column)
7506 ;; align at left-most possible start position otherwise
7507 (t
7508 (while (and tmp-list (< (car tmp-list) start))
7509 (setq tmp-list (cdr tmp-list)))
7510 (car tmp-list))))
7511 (indent-to cur-start))
7512 (setq prev-start cur-start)
7513 (beginning-of-line 2))))))
d2ddb974 7514
5eabfe72
KH
7515(defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7516 "Align inline comments within a region. Groups of code lines separated by
7517empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
d2ddb974 7518 (interactive "r\nP")
5eabfe72 7519 (save-excursion
3dcb36b7 7520 (let (orig pos)
5eabfe72
KH
7521 (goto-char beg)
7522 (beginning-of-line)
3dcb36b7 7523 (setq orig (point-marker))
5eabfe72
KH
7524 (setq beg (point))
7525 (goto-char end)
7526 (setq end (point-marker))
7527 (untabify beg end)
7528 (unless no-message (message "Aligning inline comments..."))
7529 (goto-char beg)
7530 (if (not vhdl-align-groups)
7531 ;; align entire region
7532 (vhdl-align-inline-comment-region-1 beg end spacing)
7533 ;; align groups
3dcb36b7
JB
7534 (while (and (< beg end)
7535 (re-search-forward vhdl-align-group-separate end t))
5eabfe72
KH
7536 (setq pos (point-marker))
7537 (vhdl-align-inline-comment-region-1 beg pos spacing)
7538 (setq beg (1+ pos))
7539 (goto-char beg))
7540 ;; align last group
7541 (when (< beg end)
3dcb36b7
JB
7542 (vhdl-align-inline-comment-region-1 beg end spacing)))
7543 (when vhdl-indent-tabs-mode
7544 (tabify orig end))
7545 (unless no-message (message "Aligning inline comments...done")))))
5eabfe72
KH
7546
7547(defun vhdl-align-inline-comment-group (&optional spacing)
7548 "Align inline comments within a group of lines between empty lines."
7549 (interactive)
7550 (save-excursion
7551 (let ((start (point))
7552 beg end)
3dcb36b7 7553 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
5eabfe72
KH
7554 (point-marker) (point-max)))
7555 (goto-char start)
3dcb36b7
JB
7556 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7557 (point) (point-min)))
5eabfe72
KH
7558 (untabify beg end)
7559 (message "Aligning inline comments...")
7560 (vhdl-align-inline-comment-region-1 beg end)
3dcb36b7
JB
7561 (when vhdl-indent-tabs-mode
7562 (tabify beg end))
5eabfe72
KH
7563 (message "Aligning inline comments...done"))))
7564
7565(defun vhdl-align-inline-comment-buffer ()
7566 "Align inline comments within buffer. Groups of code lines separated by
7567empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7568 (interactive)
7569 (vhdl-align-inline-comment-region (point-min) (point-max)))
7570
3dcb36b7
JB
7571;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7572;; Fixup whitespace
7573
5eabfe72
KH
7574(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7575 "Fixup whitespace in region. Surround operator symbols by one space,
7576eliminate multiple spaces (except at beginning of line), eliminate spaces at
3dcb36b7 7577end of line, do nothing in comments and strings."
5eabfe72
KH
7578 (interactive "r")
7579 (unless no-message (message "Fixing up whitespace..."))
7580 (save-excursion
7581 (goto-char end)
7582 (setq end (point-marker))
5eabfe72
KH
7583 ;; have no space before and one space after `,' and ';'
7584 (goto-char beg)
0a2e512a 7585 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
3dcb36b7
JB
7586 (if (match-string 1)
7587 (goto-char (match-end 1))
7588 (replace-match "\\3 " nil nil nil 3)))
7589 ;; have no space after `('
7590 (goto-char beg)
0a2e512a 7591 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
3dcb36b7
JB
7592 (if (match-string 1)
7593 (goto-char (match-end 1))
7594 (replace-match "\\2")))
7595 ;; have no space before `)'
7596 (goto-char beg)
0a2e512a 7597 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
3dcb36b7
JB
7598 (if (match-string 1)
7599 (goto-char (match-end 1))
7600 (replace-match "\\2")))
7601 ;; surround operator symbols by one space
7602 (goto-char beg)
0a2e512a 7603 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
3dcb36b7
JB
7604 (if (match-string 1)
7605 (goto-char (match-end 1))
0a2e512a
RF
7606 (replace-match "\\3 \\4 \\5")
7607 (goto-char (match-end 2))))
5eabfe72
KH
7608 ;; eliminate multiple spaces and spaces at end of line
7609 (goto-char beg)
7610 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
3dcb36b7 7611 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
5eabfe72
KH
7612 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7613 (progn (replace-match "" nil nil) t))
7614 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7615 (progn (replace-match ";" nil nil) t))
7616 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7617 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
3dcb36b7 7618 (progn (replace-match " " nil nil) t))
5eabfe72 7619 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
3dcb36b7 7620 (progn (replace-match " " nil nil) t))
0a2e512a
RF
7621; (re-search-forward "[^ \t-]+" end t))))
7622 (re-search-forward "[^ \t\"-]+" end t))))
5eabfe72
KH
7623 (unless no-message (message "Fixing up whitespace...done")))
7624
7625(defun vhdl-fixup-whitespace-buffer ()
7626 "Fixup whitespace in buffer. Surround operator symbols by one space,
7627eliminate multiple spaces (except at beginning of line), eliminate spaces at
7628end of line, do nothing in comments."
7629 (interactive)
7630 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7631
3dcb36b7
JB
7632;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7633;; Beautify
7634
5eabfe72
KH
7635(defun vhdl-beautify-region (beg end)
7636 "Beautify region by applying indentation, whitespace fixup, alignment, and
3dcb36b7
JB
7637case fixing to a region. Calls functions `vhdl-indent-buffer',
7638`vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
5eabfe72
KH
7639`vhdl-fix-case-buffer'."
7640 (interactive "r")
3dcb36b7 7641 (setq end (save-excursion (goto-char end) (point-marker)))
5eabfe72
KH
7642 (vhdl-indent-region beg end nil)
7643 (let ((vhdl-align-groups t))
3dcb36b7 7644 (vhdl-align-region beg end))
5eabfe72
KH
7645 (vhdl-fix-case-region beg end))
7646
7647(defun vhdl-beautify-buffer ()
7648 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7649case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7650buffer."
7651 (interactive)
3dcb36b7
JB
7652 (vhdl-beautify-region (point-min) (point-max))
7653 (when noninteractive (save-buffer)))
7654
7655;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7656;; Code filling
7657
7658(defun vhdl-fill-region (beg end &optional arg)
7659 "Fill lines for a region of code."
8d422bd5 7660 (interactive "r\np")
3dcb36b7
JB
7661 (save-excursion
7662 (goto-char beg)
f35aff82 7663 (let ((margin (if arg (current-indentation) (current-column))))
3dcb36b7
JB
7664 (goto-char end)
7665 (setq end (point-marker))
7666 ;; remove inline comments, newlines and whitespace
7667 (vhdl-comment-kill-region beg end)
7668 (vhdl-comment-kill-inline-region beg end)
7669 (subst-char-in-region beg (1- end) ?\n ?\ )
7670 (vhdl-fixup-whitespace-region beg end)
7671 ;; wrap and end-comment-column
7672 (goto-char beg)
7673 (while (re-search-forward "\\s-" end t)
7674 (when(> (current-column) vhdl-end-comment-column)
7675 (backward-char)
7676 (when (re-search-backward "\\s-" beg t)
7677 (replace-match "\n")
7678 (indent-to margin)))))))
7679
7680(defun vhdl-fill-group ()
7681 "Fill group of lines between empty lines."
7682 (interactive)
7683 (vhdl-do-group 'vhdl-fill-region))
7684
7685(defun vhdl-fill-list ()
7686 "Fill the lines of a list surrounded by a balanced group of parentheses."
7687 (interactive)
7688 (vhdl-do-list 'vhdl-fill-region))
7689
7690(defun vhdl-fill-same-indent ()
7691 "Fill the lines of block of lines with same indent."
7692 (interactive)
7693 (vhdl-do-same-indent 'vhdl-fill-region))
7694
7695
7696;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7697;;; Code updating/fixing
7698;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7699
7700;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7701;; Sensitivity list update
7702
7703;; Strategy:
7704;; - no sensitivity list is generated for processes with wait statements
7705;; - otherwise, do the following:
7706;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7707;; 2. scan for all signals already in the sensitivity list (in order to catch
7708;; manually entered global signals)
7709;; 3. signals from 1. and 2. form the list of visible signals
7710;; 4. search for if/elsif conditions containing an event (sequential code)
7711;; 5. scan for strings that are within syntactical regions where signals are
7712;; read but not within sequential code, and that correspond to visible
7713;; signals
7714;; 6. replace sensitivity list by list of signals from 5.
7715
7716(defun vhdl-update-sensitivity-list-process ()
7717 "Update sensitivity list of current process."
7718 (interactive)
7719 (save-excursion
7720 (vhdl-prepare-search-2
7721 (end-of-line)
7722 ;; look whether in process
7723 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7724 (equal (upcase (match-string 2)) "PROCESS")
7725 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7726 (error "ERROR: Not within a process")
7727 (message "Updating sensitivity list...")
7728 (vhdl-update-sensitivity-list)
7729 (message "Updating sensitivity list...done")))))
7730
7731(defun vhdl-update-sensitivity-list-buffer ()
7732 "Update sensitivity list of all processes in current buffer."
7733 (interactive)
7734 (save-excursion
7735 (vhdl-prepare-search-2
7736 (goto-char (point-min))
7737 (message "Updating sensitivity lists...")
7738 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7739 (goto-char (match-beginning 0))
0a2e512a 7740 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
3dcb36b7
JB
7741 (message "Updating sensitivity lists...done"))))
7742
7743(defun vhdl-update-sensitivity-list ()
7744 "Update sensitivity list."
7745 (let ((proc-beg (point))
7746 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7747 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7748 seq-region-list)
7749 (cond
7750 ;; search for wait statement (no sensitivity list allowed)
7751 ((progn (goto-char proc-mid)
7752 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7753 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7754 ;; combinational process (update sensitivity list)
7755 (t
7756 (let
7757 ;; scan for visible signals
7758 ((visible-list (vhdl-get-visible-signals))
7759 ;; define syntactic regions where signals are read
7760 (scan-regions-list
7761 '(;; right-hand side of signal/variable assignment
7762 ;; (special case: "<=" is relational operator in a condition)
7763 ((re-search-forward "[<:]=" proc-end t)
7764 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7765 ;; if condition
7766 ((re-search-forward "^\\s-*if\\>" proc-end t)
7767 (re-search-forward "\\<then\\>" proc-end t))
7768 ;; elsif condition
7769 ((re-search-forward "\\<elsif\\>" proc-end t)
7770 (re-search-forward "\\<then\\>" proc-end t))
7771 ;; while loop condition
7772 ((re-search-forward "^\\s-*while\\>" proc-end t)
7773 (re-search-forward "\\<loop\\>" proc-end t))
7774 ;; exit/next condition
7775 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7776 (re-search-forward ";" proc-end t))
7777 ;; assert condition
7778 ((re-search-forward "\\<assert\\>" proc-end t)
7779 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7780 ;; case expression
7781 ((re-search-forward "^\\s-*case\\>" proc-end t)
7782 (re-search-forward "\\<is\\>" proc-end t))
7783 ;; parameter list of procedure call
0a2e512a
RF
7784 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7785 (1- (point)))
7786 (progn (backward-char) (forward-sexp)
7787 (while (looking-at "(") (forward-sexp)) (point)))))
3dcb36b7
JB
7788 name read-list sens-list signal-list
7789 sens-beg sens-end beg end margin)
7790 ;; scan for signals in old sensitivity list
7791 (goto-char proc-beg)
7792 (re-search-forward "\\<process\\>" proc-mid t)
7793 (if (not (looking-at "[ \t\n]*("))
7794 (setq sens-beg (point))
7795 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7796 (goto-char (match-end 1))
7797 (forward-sexp)
7798 (setq sens-end (1- (point)))
7799 (goto-char sens-beg)
7800 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7801 (setq sens-list
7802 (cons (downcase (match-string 0)) sens-list))
7803 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7804 (setq signal-list (append visible-list sens-list))
7805 ;; search for sequential parts
7806 (goto-char proc-mid)
7807 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7808 (setq end (re-search-forward "\\<then\\>" proc-end t))
7809 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7810 (goto-char end)
7811 (backward-word 1)
7812 (vhdl-forward-sexp)
7813 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7814 (beginning-of-line)))
7815 ;; scan for signals read in process
7816 (while scan-regions-list
7817 (goto-char proc-mid)
7818 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7819 (setq end (eval (nth 1 (car scan-regions-list)))))
7820 (goto-char beg)
7821 (unless (or (vhdl-in-literal)
7822 (and seq-region-list
7823 (let ((tmp-list seq-region-list))
7824 (while (and tmp-list
7825 (< (point) (caar tmp-list)))
7826 (setq tmp-list (cdr tmp-list)))
7827 (and tmp-list (< (point) (cdar tmp-list))))))
0a2e512a 7828 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
3dcb36b7 7829 (setq name (match-string 1))
0a2e512a
RF
7830 (when (and (not (match-string 4)) ; not when formal parameter
7831 (not (and (match-string 3) ; not event attribute
7832 (not (member (downcase (match-string 3))
7833 '("event" "last_event" "transaction")))))
7834 (member (downcase name) signal-list))
7835 (unless (member-ignore-case name read-list)
7836 (setq read-list (cons name read-list))))
7837 (goto-char (match-end 1)))))
3dcb36b7
JB
7838 (setq scan-regions-list (cdr scan-regions-list)))
7839 ;; update sensitivity list
7840 (goto-char sens-beg)
7841 (if sens-end
7842 (delete-region sens-beg sens-end)
7843 (when read-list
7844 (insert " ()") (backward-char)))
7845 (setq read-list (sort read-list 'string<))
7846 (when read-list
7847 (setq margin (current-column))
7848 (insert (car read-list))
7849 (setq read-list (cdr read-list))
7850 (while read-list
7851 (insert ",")
7852 (if (<= (+ (current-column) (length (car read-list)) 2)
7853 end-comment-column)
7854 (insert " ")
7855 (insert "\n") (indent-to margin))
7856 (insert (car read-list))
7857 (setq read-list (cdr read-list)))))))))
7858
7859(defun vhdl-get-visible-signals ()
7860 "Get all signals visible in the current block."
0a2e512a
RF
7861 (let (beg end signal-list entity-name file-name)
7862 (vhdl-prepare-search-2
7863 ;; get entity name
7864 (save-excursion
7865 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
3dcb36b7 7866 (not (equal "END" (upcase (match-string 1))))
0a2e512a
RF
7867 (setq entity-name (match-string 2)))
7868 (error "ERROR: Not within an architecture")))
7869 ;; search for signals declared in entity port clause
7870 (save-excursion
7871 (goto-char (point-min))
7872 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7873 (setq file-name
7874 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7875 "." (file-name-extension (buffer-file-name)))))
7876 (vhdl-visit-file
7877 file-name t
7878 (vhdl-prepare-search-2
7879 (goto-char (point-min))
7880 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7881 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7882 (when (setq beg (re-search-forward
7883 "^\\s-*port[ \t\n]*("
7884 (save-excursion
7885 (re-search-forward "^end\\>" nil t)) t))
7886 (setq end (save-excursion
7887 (backward-char) (forward-sexp) (point)))
7888 (vhdl-forward-syntactic-ws)
7889 (while (< (point) end)
7890 (when (looking-at "signal[ \t\n]+")
7891 (goto-char (match-end 0)))
7892 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7893 (setq signal-list
7894 (cons (downcase (match-string 1)) signal-list))
7895 (goto-char (match-end 0))
7896 (vhdl-forward-syntactic-ws))
7897 (re-search-forward ";" end 1)
7898 (vhdl-forward-syntactic-ws)))))))
7899 ;; search for signals declared in architecture declarative part
7900 (save-excursion
7901 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7902 (not (equal "END" (upcase (match-string 1))))
7903 (setq end (re-search-forward "^begin\\>" nil t))))
7904 (error "ERROR: No architecture declarative part found")
7905 ;; scan for all declared signal and alias names
7906 (goto-char beg)
7907 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7908 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7909 (if (match-string 2)
7910 ;; scan signal name
7911 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7912 (setq signal-list
7913 (cons (downcase (match-string 1)) signal-list))
7914 (goto-char (match-end 0)))
7915 ;; scan alias name, check is alias of (declared) signal
7916 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7917 (member (downcase (match-string 2)) signal-list))
7918 (setq signal-list
7919 (cons (downcase (match-string 1)) signal-list))
7920 (goto-char (match-end 0))))
7921 (setq beg (point))))))
7922 ;; search for signals declared in surrounding block declarative parts
7923 (save-excursion
7924 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7925 (match-string 2))
7926 (goto-char (match-end 2))
7927 (vhdl-backward-sexp)
7928 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7929 beg)
7930 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7931 ;; scan for all declared signal names
7932 (goto-char beg)
7933 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7934 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7935 (if (match-string 2)
7936 ;; scan signal name
7937 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7938 (setq signal-list
7939 (cons (downcase (match-string 1)) signal-list))
7940 (goto-char (match-end 0)))
7941 ;; scan alias name, check is alias of (declared) signal
7942 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7943 (member (downcase (match-string 2)) signal-list))
7944 (setq signal-list
7945 (cons (downcase (match-string 1)) signal-list))
7946 (goto-char (match-end 0))))))
7947 (goto-char beg)))
7948 signal-list)))
3dcb36b7
JB
7949
7950;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7951;; Generic/port clause fixing
7952
7953(defun vhdl-fix-clause ()
7954 "Fix closing parenthesis within generic/port clause."
7955 (interactive)
7956 (save-excursion
7957 (vhdl-prepare-search-2
7958 (let ((pos (point))
7959 beg end)
7960 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7961 (error "ERROR: Not within a generic/port clause")
7962 ;; search for end of clause
7963 (goto-char (match-end 0))
7964 (setq beg (1- (point)))
7965 (vhdl-forward-syntactic-ws)
7966 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7967 (goto-char (1- (match-end 0)))
7968 (setq end (point-marker))
7969 (forward-char)
7970 (vhdl-forward-syntactic-ws))
7971 (goto-char end)
e180ab9f 7972 (when (> pos (point-at-eol))
3dcb36b7
JB
7973 (error "ERROR: Not within a generic/port clause"))
7974 ;; delete closing parenthesis on separate line (not supported style)
7975 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7976 (vhdl-line-kill)
7977 (vhdl-backward-syntactic-ws)
7978 (setq end (point-marker))
7979 (insert ";"))
7980 ;; delete superfluous parentheses
7981 (while (progn (goto-char beg)
7982 (condition-case () (forward-sexp)
7983 (error (goto-char (point-max))))
7984 (< (point) end))
d355a0b7 7985 (delete-char -1))
3dcb36b7
JB
7986 ;; add closing parenthesis
7987 (when (> (point) end)
7988 (goto-char end)
7989 (insert ")")))))))
7990
7991;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7992;; Miscellaneous
7993
7994(defun vhdl-remove-trailing-spaces ()
7995 "Remove trailing spaces in the whole buffer."
7996 (interactive)
7997 (save-match-data
7998 (save-excursion
7999 (goto-char (point-min))
8000 (while (re-search-forward "[ \t]+$" (point-max) t)
8001 (unless (vhdl-in-literal)
8002 (replace-match "" nil nil))))))
d2ddb974
KH
8003
8004
5eabfe72
KH
8005;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8006;;; Electrification
8007;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 8008
5eabfe72
KH
8009(defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8010 "Syntax of prompt inserted by template generators.")
8011
8012(defvar vhdl-template-invoked-by-hook nil
8013 "Indicates whether a template has been invoked by a hook or by key or menu.
8014Used for undoing after template abortion.")
8015
8016;; correct different behavior of function `unread-command-events' in XEmacs
3dcb36b7 8017(defun vhdl-character-to-event (arg))
5eabfe72 8018(defalias 'vhdl-character-to-event
4bcb9c95 8019 (if (fboundp 'character-to-event) 'character-to-event 'identity))
3dcb36b7
JB
8020
8021(defun vhdl-work-library ()
8022 "Return the working library name of the current project or \"work\" if no
8023project is defined."
8024 (vhdl-resolve-env-variable
8025 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
5eabfe72
KH
8026
8027;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8028;; Enabling/disabling
8029
56eb0904 8030(define-minor-mode vhdl-electric-mode
5eabfe72
KH
8031 "Toggle VHDL electric mode.
8032Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
56eb0904 8033 :global t)
5eabfe72 8034
56eb0904 8035(define-minor-mode vhdl-stutter-mode
5eabfe72
KH
8036 "Toggle VHDL stuttering mode.
8037Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
56eb0904 8038 :global t)
5eabfe72
KH
8039
8040;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8041;; Stuttering
d2ddb974 8042
5eabfe72
KH
8043(defun vhdl-electric-dash (count)
8044 "-- starts a comment, --- draws a horizontal line,
a4c6cfad 8045---- starts a display comment."
d2ddb974 8046 (interactive "p")
3dcb36b7 8047 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
5eabfe72
KH
8048 (cond
8049 ((and abbrev-start-location (= abbrev-start-location (point)))
8050 (setq abbrev-start-location nil)
8051 (goto-char last-abbrev-location)
8052 (beginning-of-line nil)
8053 (vhdl-comment-display))
8054 ((/= (preceding-char) ?-) ; standard dash (minus)
d2ddb974 8055 (self-insert-command count))
5eabfe72
KH
8056 (t (self-insert-command count)
8057 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8058 (let ((next-input (read-char)))
8059 (if (= next-input ?-) ; triple dash
8060 (progn
8061 (vhdl-comment-display-line)
8062 (message
8063 "Enter '-' for display comment, else continue coding")
8064 (let ((next-input (read-char)))
8065 (if (= next-input ?-) ; four dashes
8066 (vhdl-comment-display t)
8067 (setq unread-command-events ; pushback the char
8068 (list (vhdl-character-to-event next-input))))))
8069 (setq unread-command-events ; pushback the char
8070 (list (vhdl-character-to-event next-input)))
8071 (vhdl-comment-insert)))))
8072 (self-insert-command count)))
8073
8074(defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
d2ddb974 8075 (interactive "p")
3dcb36b7 8076 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8077 (if (= (preceding-char) ?\()
8078 (progn (delete-char -1) (insert-char ?\[ 1))
8079 (insert-char ?\( 1))
8080 (self-insert-command count)))
d2ddb974 8081
5eabfe72 8082(defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
d2ddb974 8083 (interactive "p")
3dcb36b7 8084 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974 8085 (progn
5eabfe72
KH
8086 (if (= (preceding-char) ?\))
8087 (progn (delete-char -1) (insert-char ?\] 1))
8088 (insert-char ?\) 1))
8089 (blink-matching-open))
8090 (self-insert-command count)))
d2ddb974 8091
5eabfe72 8092(defun vhdl-electric-quote (count) "'' --> \""
d2ddb974 8093 (interactive "p")
3dcb36b7 8094 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8095 (if (= (preceding-char) last-input-event)
d355a0b7 8096 (progn (delete-char -1) (insert-char ?\" 1))
5eabfe72
KH
8097 (insert-char ?\' 1))
8098 (self-insert-command count)))
d2ddb974 8099
5eabfe72 8100(defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
d2ddb974 8101 (interactive "p")
3dcb36b7 8102 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8103 (cond ((= (preceding-char) last-input-event)
5eabfe72 8104 (progn (delete-char -1)
3dcb36b7 8105 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8106 (insert ": ")
8107 (setq this-command 'vhdl-electric-colon)))
8108 ((and
8109 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8110 (progn (delete-char -1) (insert "= ")))
8111 (t (insert-char ?\; 1)))
8112 (self-insert-command count)))
8113
8114(defun vhdl-electric-comma (count) "',,' --> ' <= '"
d2ddb974 8115 (interactive "p")
3dcb36b7 8116 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8117 (cond ((= (preceding-char) last-input-event)
d2ddb974 8118 (progn (delete-char -1)
3dcb36b7 8119 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8120 (insert "<= ")))
5eabfe72
KH
8121 (t (insert-char ?\, 1)))
8122 (self-insert-command count)))
d2ddb974 8123
5eabfe72 8124(defun vhdl-electric-period (count) "'..' --> ' => '"
d2ddb974 8125 (interactive "p")
3dcb36b7 8126 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8127 (cond ((= (preceding-char) last-input-event)
d2ddb974 8128 (progn (delete-char -1)
3dcb36b7 8129 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8130 (insert "=> ")))
5eabfe72
KH
8131 (t (insert-char ?\. 1)))
8132 (self-insert-command count)))
d2ddb974 8133
5eabfe72 8134(defun vhdl-electric-equal (count) "'==' --> ' == '"
d2ddb974 8135 (interactive "p")
3dcb36b7 8136 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
1e4bd40d 8137 (cond ((= (preceding-char) last-input-event)
5eabfe72 8138 (progn (delete-char -1)
3dcb36b7 8139 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8140 (insert "== ")))
8141 (t (insert-char ?\= 1)))
8142 (self-insert-command count)))
d2ddb974 8143
5eabfe72 8144;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
8145;; VHDL templates
8146
5eabfe72
KH
8147(defun vhdl-template-paired-parens ()
8148 "Insert a pair of round parentheses, placing point between them."
d2ddb974 8149 (interactive)
5eabfe72
KH
8150 (insert "()")
8151 (backward-char))
d2ddb974 8152
5eabfe72
KH
8153(defun vhdl-template-alias ()
8154 "Insert alias declaration."
d2ddb974 8155 (interactive)
5eabfe72
KH
8156 (let ((start (point)))
8157 (vhdl-insert-keyword "ALIAS ")
8158 (when (vhdl-template-field "name" nil t start (point))
8159 (insert " : ")
8160 (unless (vhdl-template-field
8161 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8162 nil t)
d355a0b7 8163 (delete-char -3))
5eabfe72
KH
8164 (vhdl-insert-keyword " IS ")
8165 (vhdl-template-field "name" ";")
8166 (vhdl-comment-insert-inline))))
8167
8168(defun vhdl-template-architecture ()
8169 "Insert architecture."
8170 (interactive)
8171 (let ((margin (current-indentation))
8172 (start (point))
3dcb36b7 8173 arch-name)
d2ddb974 8174 (vhdl-insert-keyword "ARCHITECTURE ")
5eabfe72
KH
8175 (when (setq arch-name
8176 (vhdl-template-field "name" nil t start (point)))
d2ddb974 8177 (vhdl-insert-keyword " OF ")
3dcb36b7
JB
8178 (if (save-excursion
8179 (vhdl-prepare-search-1
8180 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8181 (insert (match-string 1))
5eabfe72 8182 (vhdl-template-field "entity name"))
3dcb36b7 8183 (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8184 (vhdl-template-begin-end
8185 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8186 (memq vhdl-insert-empty-lines '(unit all))))))
d2ddb974 8187
5eabfe72 8188(defun vhdl-template-array (kind &optional secondary)
d2ddb974
KH
8189 "Insert array type definition."
8190 (interactive)
5eabfe72
KH
8191 (let ((start (point)))
8192 (vhdl-insert-keyword "ARRAY (")
8193 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8194 secondary)
8195 (vhdl-insert-keyword ") OF ")
8196 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8197 (vhdl-insert-keyword ";"))))
8198
8199(defun vhdl-template-assert ()
8200 "Insert an assertion statement."
8201 (interactive)
8202 (let ((start (point)))
8203 (vhdl-insert-keyword "ASSERT ")
8204 (when vhdl-conditions-in-parenthesis (insert "("))
8205 (when (vhdl-template-field "condition (negated)" nil t start (point))
8206 (when vhdl-conditions-in-parenthesis (insert ")"))
8207 (setq start (point))
8208 (vhdl-insert-keyword " REPORT ")
8209 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8210 (delete-region start (point)))
8211 (setq start (point))
8212 (vhdl-insert-keyword " SEVERITY ")
8213 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8214 (delete-region start (point)))
8215 (insert ";"))))
8216
8217(defun vhdl-template-attribute ()
8218 "Insert an attribute declaration or specification."
8219 (interactive)
8220 (if (eq (vhdl-decision-query
8221 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8222 (vhdl-template-attribute-spec)
8223 (vhdl-template-attribute-decl)))
d2ddb974 8224
5eabfe72
KH
8225(defun vhdl-template-attribute-decl ()
8226 "Insert an attribute declaration."
d2ddb974 8227 (interactive)
5eabfe72
KH
8228 (let ((start (point)))
8229 (vhdl-insert-keyword "ATTRIBUTE ")
8230 (when (vhdl-template-field "name" " : " t start (point))
8231 (vhdl-template-field "type" ";")
8232 (vhdl-comment-insert-inline))))
8233
8234(defun vhdl-template-attribute-spec ()
8235 "Insert an attribute specification."
8236 (interactive)
8237 (let ((start (point)))
8238 (vhdl-insert-keyword "ATTRIBUTE ")
8239 (when (vhdl-template-field "name" nil t start (point))
8240 (vhdl-insert-keyword " OF ")
8241 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8242 (vhdl-template-field "entity class")
8243 (vhdl-insert-keyword " IS ")
8244 (vhdl-template-field "expression" ";"))))
d2ddb974 8245
5eabfe72
KH
8246(defun vhdl-template-block ()
8247 "Insert a block."
d2ddb974 8248 (interactive)
5eabfe72
KH
8249 (let ((margin (current-indentation))
8250 (start (point))
8251 label)
8252 (vhdl-insert-keyword ": BLOCK ")
8253 (goto-char start)
8254 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8255 (forward-word 1)
8256 (forward-char 1)
d2ddb974 8257 (insert "(")
5eabfe72
KH
8258 (if (vhdl-template-field "[guard expression]" nil t)
8259 (insert ")")
8260 (delete-char -2))
8261 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 8262 (insert "\n")
5eabfe72
KH
8263 (vhdl-template-begin-end "BLOCK" label margin)
8264 (vhdl-comment-block))))
d2ddb974 8265
5eabfe72 8266(defun vhdl-template-block-configuration ()
d2ddb974
KH
8267 "Insert a block configuration statement."
8268 (interactive)
5eabfe72
KH
8269 (let ((margin (current-indentation))
8270 (start (point)))
d2ddb974 8271 (vhdl-insert-keyword "FOR ")
5eabfe72 8272 (when (vhdl-template-field "block name" nil t start (point))
d2ddb974
KH
8273 (vhdl-insert-keyword "\n\n")
8274 (indent-to margin)
8275 (vhdl-insert-keyword "END FOR;")
8276 (end-of-line 0)
5eabfe72 8277 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8278
5eabfe72
KH
8279(defun vhdl-template-break ()
8280 "Insert a break statement."
d2ddb974 8281 (interactive)
5eabfe72
KH
8282 (let (position)
8283 (vhdl-insert-keyword "BREAK")
8284 (setq position (point))
8285 (insert " ")
8286 (while (or
8287 (progn (vhdl-insert-keyword "FOR ")
8288 (if (vhdl-template-field "[quantity name]" " USE " t)
8289 (progn (vhdl-template-field "quantity name" " => ") t)
453cfeb3
CY
8290 (delete-region (point)
8291 (progn (forward-word -1) (point)))
8292 nil))
5eabfe72
KH
8293 (vhdl-template-field "[quantity name]" " => " t))
8294 (vhdl-template-field "expression")
8295 (setq position (point))
8296 (insert ", "))
8297 (delete-region position (point))
8298 (unless (vhdl-sequential-statement-p)
8299 (vhdl-insert-keyword " ON ")
8300 (if (vhdl-template-field "[sensitivity list]" nil t)
8301 (setq position (point))
8302 (delete-region position (point))))
8303 (vhdl-insert-keyword " WHEN ")
8304 (when vhdl-conditions-in-parenthesis (insert "("))
8305 (if (vhdl-template-field "[condition]" nil t)
8306 (when vhdl-conditions-in-parenthesis (insert ")"))
8307 (delete-region position (point)))
8308 (insert ";")))
8309
8310(defun vhdl-template-case (&optional kind)
8311 "Insert a case statement."
8312 (interactive)
8313 (let ((margin (current-indentation))
8314 (start (point))
8315 label)
8316 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8317 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8318 (vhdl-insert-keyword "CASE ")
8319 (vhdl-insert-keyword ": CASE ")
8320 (goto-char start)
8321 (setq label (vhdl-template-field "[label]" nil t))
8322 (unless label (delete-char 2))
8323 (forward-word 1)
8324 (forward-char 1))
8325 (when (vhdl-template-field "expression" nil t start (point))
8326 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
d2ddb974 8327 (indent-to margin)
5eabfe72
KH
8328 (vhdl-insert-keyword "END CASE")
8329 (when label (insert " " label))
8330 (insert ";")
d2ddb974
KH
8331 (forward-line -1)
8332 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8333 (vhdl-insert-keyword "WHEN ")
8334 (let ((position (point)))
8335 (insert " => ;\n")
8336 (indent-to (+ margin vhdl-basic-offset))
8337 (vhdl-insert-keyword "WHEN OTHERS => null;")
8338 (goto-char position)))))
d2ddb974 8339
5eabfe72
KH
8340(defun vhdl-template-case-is ()
8341 "Insert a sequential case statement."
d2ddb974 8342 (interactive)
5eabfe72
KH
8343 (vhdl-template-case 'is))
8344
8345(defun vhdl-template-case-use ()
8346 "Insert a simultaneous case statement."
8347 (interactive)
8348 (vhdl-template-case 'use))
8349
8350(defun vhdl-template-component ()
8351 "Insert a component declaration."
8352 (interactive)
8353 (vhdl-template-component-decl))
8354
8355(defun vhdl-template-component-conf ()
8356 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8357since these are almost equivalent)."
8358 (interactive)
8359 (let ((margin (current-indentation))
8360 (result (vhdl-template-configuration-spec t)))
8361 (when result
8362 (insert "\n")
8363 (indent-to margin)
8364 (vhdl-insert-keyword "END FOR;")
8365 (when (eq result 'no-use)
8366 (end-of-line -0)))))
8367
8368(defun vhdl-template-component-decl ()
8369 "Insert a component declaration."
8370 (interactive)
8371 (let ((margin (current-indentation))
8372 (start (point))
8373 name end-column)
d2ddb974 8374 (vhdl-insert-keyword "COMPONENT ")
5eabfe72 8375 (when (setq name (vhdl-template-field "name" nil t start (point)))
3dcb36b7 8376 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
d2ddb974
KH
8377 (insert "\n\n")
8378 (indent-to margin)
5eabfe72
KH
8379 (vhdl-insert-keyword "END COMPONENT")
8380 (unless (vhdl-standard-p '87) (insert " " name))
8381 (insert ";")
8382 (setq end-column (current-column))
d2ddb974
KH
8383 (end-of-line -0)
8384 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 8385 (vhdl-template-generic-list t t)
d2ddb974
KH
8386 (insert "\n")
8387 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8388 (vhdl-template-port-list t)
8389 (beginning-of-line 2)
8390 (forward-char end-column))))
d2ddb974 8391
5eabfe72
KH
8392(defun vhdl-template-component-inst ()
8393 "Insert a component instantiation statement."
d2ddb974 8394 (interactive)
5eabfe72
KH
8395 (let ((margin (current-indentation))
8396 (start (point))
8397 unit position)
8398 (when (vhdl-template-field "instance label" nil t start (point))
8399 (insert ": ")
3dcb36b7 8400 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
8401 (vhdl-template-field "component name")
8402 ;; direct instantiation
8403 (setq unit (vhdl-template-field
8404 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8405 (setq unit (upcase (or unit "")))
8406 (cond ((equal unit "ENTITY")
3dcb36b7
JB
8407 (vhdl-template-field "library name" "." nil nil nil nil
8408 (vhdl-work-library))
5eabfe72
KH
8409 (vhdl-template-field "entity name" "(")
8410 (if (vhdl-template-field "[architecture name]" nil t)
8411 (insert ")")
8412 (delete-char -1)))
8413 ((equal unit "CONFIGURATION")
3dcb36b7
JB
8414 (vhdl-template-field "library name" "." nil nil nil nil
8415 (vhdl-work-library))
5eabfe72
KH
8416 (vhdl-template-field "configuration name"))
8417 (t (vhdl-template-field "component name"))))
8418 (insert "\n")
d2ddb974 8419 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8420 (setq position (point))
8421 (vhdl-insert-keyword "GENERIC ")
8422 (when (vhdl-template-map position t t)
8423 (insert "\n")
8424 (indent-to (+ margin vhdl-basic-offset)))
8425 (setq position (point))
8426 (vhdl-insert-keyword "PORT ")
8427 (unless (vhdl-template-map position t t)
453cfeb3 8428 (delete-region (line-beginning-position) (point))
5eabfe72
KH
8429 (delete-char -1))
8430 (insert ";"))))
d2ddb974 8431
5eabfe72
KH
8432(defun vhdl-template-conditional-signal-asst ()
8433 "Insert a conditional signal assignment."
d2ddb974 8434 (interactive)
5eabfe72 8435 (when (vhdl-template-field "target signal")
d2ddb974 8436 (insert " <= ")
5eabfe72
KH
8437; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8438; (insert " "))
d2ddb974 8439 (let ((margin (current-column))
5eabfe72
KH
8440 (start (point))
8441 position)
8442 (vhdl-template-field "waveform")
8443 (setq position (point))
d2ddb974 8444 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8445 (when vhdl-conditions-in-parenthesis (insert "("))
8446 (while (and (vhdl-template-field "[condition]" nil t)
8447 (progn
8448 (when vhdl-conditions-in-parenthesis (insert ")"))
8449 (setq position (point))
8450 (vhdl-insert-keyword " ELSE")
8451 (insert "\n")
8452 (indent-to margin)
8453 (vhdl-template-field "[waveform]" nil t)))
8454 (setq position (point))
d2ddb974 8455 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8456 (when vhdl-conditions-in-parenthesis (insert "(")))
8457 (delete-region position (point))
d2ddb974 8458 (insert ";")
3dcb36b7 8459 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 8460
5eabfe72
KH
8461(defun vhdl-template-configuration ()
8462 "Insert a configuration specification if within an architecture,
d2ddb974
KH
8463a block or component configuration if within a configuration declaration,
8464a configuration declaration if not within a design unit."
8465 (interactive)
3dcb36b7
JB
8466 (vhdl-prepare-search-1
8467 (cond
8468 ((and (save-excursion ; architecture body
8469 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8470 (equal "ARCHITECTURE" (upcase (match-string 1))))
8471 (vhdl-template-configuration-spec))
8472 ((and (save-excursion ; configuration declaration
8473 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8474 (equal "CONFIGURATION" (upcase (match-string 1))))
8475 (if (eq (vhdl-decision-query
8476 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8477 (vhdl-template-component-conf)
8478 (vhdl-template-block-configuration)))
8479 (t (vhdl-template-configuration-decl))))) ; otherwise
5eabfe72
KH
8480
8481(defun vhdl-template-configuration-spec (&optional optional-use)
8482 "Insert a configuration specification."
d2ddb974 8483 (interactive)
5eabfe72
KH
8484 (let ((margin (current-indentation))
8485 (start (point))
8486 aspect position)
d2ddb974 8487 (vhdl-insert-keyword "FOR ")
3dcb36b7 8488 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
5eabfe72 8489 t start (point))
3dcb36b7 8490 (vhdl-template-field "component name" "\n")
d2ddb974 8491 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8492 (setq start (point))
8493 (vhdl-insert-keyword "USE ")
8494 (if (and optional-use
8495 (not (setq aspect (vhdl-template-field
8496 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8497 (progn (delete-region start (point)) 'no-use)
8498 (unless optional-use
8499 (setq aspect (vhdl-template-field
8500 "ENTITY | CONFIGURATION | OPEN" " ")))
8501 (setq aspect (upcase (or aspect "")))
8502 (cond ((equal aspect "ENTITY")
3dcb36b7
JB
8503 (vhdl-template-field "library name" "." nil nil nil nil
8504 (vhdl-work-library))
5eabfe72
KH
8505 (vhdl-template-field "entity name" "(")
8506 (if (vhdl-template-field "[architecture name]" nil t)
8507 (insert ")")
d2ddb974 8508 (delete-char -1))
5eabfe72
KH
8509 (insert "\n")
8510 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8511 (setq position (point))
8512 (vhdl-insert-keyword "GENERIC ")
8513 (when (vhdl-template-map position t t)
8514 (insert "\n")
8515 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8516 (setq position (point))
8517 (vhdl-insert-keyword "PORT ")
8518 (unless (vhdl-template-map position t t)
453cfeb3 8519 (delete-region (line-beginning-position) (point))
5eabfe72
KH
8520 (delete-char -1))
8521 (insert ";")
8522 t)
8523 ((equal aspect "CONFIGURATION")
3dcb36b7
JB
8524 (vhdl-template-field "library name" "." nil nil nil nil
8525 (vhdl-work-library))
5eabfe72 8526 (vhdl-template-field "configuration name" ";"))
d355a0b7 8527 (t (delete-char -1) (insert ";") t))))))
5eabfe72 8528
d2ddb974 8529
5eabfe72
KH
8530(defun vhdl-template-configuration-decl ()
8531 "Insert a configuration declaration."
d2ddb974 8532 (interactive)
5eabfe72
KH
8533 (let ((margin (current-indentation))
8534 (start (point))
5eabfe72 8535 entity-exists string name position)
d2ddb974 8536 (vhdl-insert-keyword "CONFIGURATION ")
5eabfe72 8537 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974 8538 (vhdl-insert-keyword " OF ")
5eabfe72 8539 (save-excursion
3dcb36b7
JB
8540 (vhdl-prepare-search-1
8541 (setq entity-exists (vhdl-re-search-backward
5eabfe72
KH
8542 "\\<entity \\(\\w*\\) is\\>" nil t))
8543 (setq string (match-string 1))))
d2ddb974 8544 (if (and entity-exists (not (equal string "")))
5eabfe72
KH
8545 (insert string)
8546 (vhdl-template-field "entity name"))
8547 (vhdl-insert-keyword " IS\n")
8548 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8549 (indent-to (+ margin vhdl-basic-offset))
8550 (setq position (point))
8551 (insert "\n")
8552 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
d2ddb974
KH
8553 (indent-to margin)
8554 (vhdl-insert-keyword "END ")
5eabfe72
KH
8555 (unless (vhdl-standard-p '87)
8556 (vhdl-insert-keyword "CONFIGURATION "))
d2ddb974 8557 (insert name ";")
5eabfe72 8558 (goto-char position))))
d2ddb974 8559
5eabfe72
KH
8560(defun vhdl-template-constant ()
8561 "Insert a constant declaration."
8562 (interactive)
8563 (let ((start (point))
8564 (in-arglist (vhdl-in-argument-list-p)))
8565 (vhdl-insert-keyword "CONSTANT ")
8566 (when (vhdl-template-field "name" nil t start (point))
d2ddb974 8567 (insert " : ")
5eabfe72
KH
8568 (when in-arglist (vhdl-insert-keyword "IN "))
8569 (vhdl-template-field "type")
d2ddb974 8570 (if in-arglist
5eabfe72
KH
8571 (progn (insert ";")
8572 (vhdl-comment-insert-inline))
d2ddb974
KH
8573 (let ((position (point)))
8574 (insert " := ")
5eabfe72
KH
8575 (unless (vhdl-template-field "[initialization]" nil t)
8576 (delete-region position (point)))
8577 (insert ";")
8578 (vhdl-comment-insert-inline))))))
d2ddb974 8579
5eabfe72 8580(defun vhdl-template-default ()
d2ddb974
KH
8581 "Insert nothing."
8582 (interactive)
8583 (insert " ")
8584 (unexpand-abbrev)
8585 (backward-word 1)
8586 (vhdl-case-word 1)
5eabfe72 8587 (forward-char 1))
d2ddb974 8588
5eabfe72 8589(defun vhdl-template-default-indent ()
d2ddb974
KH
8590 "Insert nothing and indent."
8591 (interactive)
8592 (insert " ")
8593 (unexpand-abbrev)
8594 (backward-word 1)
8595 (vhdl-case-word 1)
8596 (forward-char 1)
3dcb36b7 8597 (indent-according-to-mode))
d2ddb974 8598
5eabfe72 8599(defun vhdl-template-disconnect ()
d2ddb974
KH
8600 "Insert a disconnect statement."
8601 (interactive)
5eabfe72
KH
8602 (let ((start (point)))
8603 (vhdl-insert-keyword "DISCONNECT ")
8604 (when (vhdl-template-field "signal names | OTHERS | ALL"
8605 " : " t start (point))
8606 (vhdl-template-field "type")
8607 (vhdl-insert-keyword " AFTER ")
8608 (vhdl-template-field "time expression" ";"))))
8609
8610(defun vhdl-template-else ()
d2ddb974
KH
8611 "Insert an else statement."
8612 (interactive)
3dcb36b7
JB
8613 (let (margin)
8614 (vhdl-prepare-search-1
5eabfe72 8615 (vhdl-insert-keyword "ELSE")
3dcb36b7
JB
8616 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8617 (equal "WHEN" (upcase (match-string 1))))
5eabfe72 8618 (insert " ")
3dcb36b7 8619 (indent-according-to-mode)
5eabfe72
KH
8620 (setq margin (current-indentation))
8621 (insert "\n")
8622 (indent-to (+ margin vhdl-basic-offset))))))
8623
8624(defun vhdl-template-elsif ()
d2ddb974
KH
8625 "Insert an elsif statement."
8626 (interactive)
5eabfe72
KH
8627 (let ((start (point))
8628 margin)
d2ddb974 8629 (vhdl-insert-keyword "ELSIF ")
3dcb36b7
JB
8630 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8631 (when vhdl-conditions-in-parenthesis (insert "("))
8632 (when (vhdl-template-field "condition" nil t start (point))
8633 (when vhdl-conditions-in-parenthesis (insert ")"))
8634 (indent-according-to-mode)
8635 (setq margin (current-indentation))
8636 (vhdl-insert-keyword
8637 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8638 (indent-to (+ margin vhdl-basic-offset))))))
d2ddb974 8639
5eabfe72
KH
8640(defun vhdl-template-entity ()
8641 "Insert an entity."
d2ddb974 8642 (interactive)
5eabfe72
KH
8643 (let ((margin (current-indentation))
8644 (start (point))
8645 name end-column)
d2ddb974 8646 (vhdl-insert-keyword "ENTITY ")
5eabfe72 8647 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974
KH
8648 (vhdl-insert-keyword " IS\n\n")
8649 (indent-to margin)
8650 (vhdl-insert-keyword "END ")
5eabfe72
KH
8651 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8652 (insert name ";")
8653 (setq end-column (current-column))
d2ddb974
KH
8654 (end-of-line -0)
8655 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8656 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8657 (indent-to (+ margin vhdl-basic-offset))
8658 (when (vhdl-template-generic-list t)
8659 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8660 (insert "\n")
8661 (indent-to (+ margin vhdl-basic-offset))
8662 (when (vhdl-template-port-list t)
8663 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8664 (beginning-of-line 2)
8665 (forward-char end-column))))
d2ddb974 8666
5eabfe72 8667(defun vhdl-template-exit ()
d2ddb974
KH
8668 "Insert an exit statement."
8669 (interactive)
5eabfe72
KH
8670 (let ((start (point)))
8671 (vhdl-insert-keyword "EXIT ")
3dcb36b7
JB
8672 (if (vhdl-template-field "[loop label]" nil t start (point))
8673 (let ((position (point)))
8674 (vhdl-insert-keyword " WHEN ")
8675 (when vhdl-conditions-in-parenthesis (insert "("))
8676 (if (vhdl-template-field "[condition]" nil t)
8677 (when vhdl-conditions-in-parenthesis (insert ")"))
8678 (delete-region position (point))))
d2ddb974 8679 (delete-char -1))
5eabfe72
KH
8680 (insert ";")))
8681
8682(defun vhdl-template-file ()
8683 "Insert a file declaration."
8684 (interactive)
8685 (let ((start (point)))
8686 (vhdl-insert-keyword "FILE ")
8687 (when (vhdl-template-field "name" nil t start (point))
8688 (insert " : ")
8689 (vhdl-template-field "type")
8690 (unless (vhdl-standard-p '87)
8691 (vhdl-insert-keyword " OPEN ")
8692 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8693 nil t)
d355a0b7 8694 (delete-char -6)))
5eabfe72
KH
8695 (vhdl-insert-keyword " IS ")
8696 (when (vhdl-standard-p '87)
8697 (vhdl-template-field "[IN | OUT]" " " t))
8698 (vhdl-template-field "filename-string" nil nil nil nil t)
8699 (insert ";")
8700 (vhdl-comment-insert-inline))))
d2ddb974 8701
5eabfe72
KH
8702(defun vhdl-template-for ()
8703 "Insert a block or component configuration if within a configuration
8704declaration, a configuration specification if within an architecture
3dcb36b7
JB
8705declarative part (and not within a subprogram), a for-loop if within a
8706sequential statement part (subprogram or process), and a for-generate
8707otherwise."
5eabfe72 8708 (interactive)
3dcb36b7
JB
8709 (vhdl-prepare-search-1
8710 (cond
8711 ((vhdl-sequential-statement-p) ; sequential statement
8712 (vhdl-template-for-loop))
8713 ((and (save-excursion ; configuration declaration
8714 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8715 (equal "CONFIGURATION" (upcase (match-string 1))))
8716 (if (eq (vhdl-decision-query
8717 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8718 (vhdl-template-component-conf)
8719 (vhdl-template-block-configuration)))
8720 ((and (save-excursion
8721 (re-search-backward ; architecture declarative part
8722 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8723 (equal "ARCHITECTURE" (upcase (match-string 1))))
8724 (vhdl-template-configuration-spec))
8725 (t (vhdl-template-for-generate))))) ; concurrent statement
5eabfe72
KH
8726
8727(defun vhdl-template-for-generate ()
8728 "Insert a for-generate."
d2ddb974 8729 (interactive)
5eabfe72
KH
8730 (let ((margin (current-indentation))
8731 (start (point))
3dcb36b7 8732 label position)
5eabfe72
KH
8733 (vhdl-insert-keyword ": FOR ")
8734 (setq position (point-marker))
8735 (goto-char start)
8736 (when (setq label (vhdl-template-field "label" nil t start position))
8737 (goto-char position)
8738 (vhdl-template-field "loop variable")
8739 (vhdl-insert-keyword " IN ")
8740 (vhdl-template-field "range")
8741 (vhdl-template-generate-body margin label))))
d2ddb974 8742
5eabfe72
KH
8743(defun vhdl-template-for-loop ()
8744 "Insert a for loop."
d2ddb974 8745 (interactive)
5eabfe72
KH
8746 (let ((margin (current-indentation))
8747 (start (point))
8748 label index)
8749 (if (not (eq vhdl-optional-labels 'all))
8750 (vhdl-insert-keyword "FOR ")
8751 (vhdl-insert-keyword ": FOR ")
8752 (goto-char start)
8753 (setq label (vhdl-template-field "[label]" nil t))
8754 (unless label (delete-char 2))
8755 (forward-word 1)
8756 (forward-char 1))
8757 (when (setq index (vhdl-template-field "loop variable"
8758 nil t start (point)))
d2ddb974 8759 (vhdl-insert-keyword " IN ")
5eabfe72 8760 (vhdl-template-field "range")
d2ddb974
KH
8761 (vhdl-insert-keyword " LOOP\n\n")
8762 (indent-to margin)
8763 (vhdl-insert-keyword "END LOOP")
5eabfe72
KH
8764 (if label
8765 (insert " " label ";")
d2ddb974 8766 (insert ";")
5eabfe72 8767 (when vhdl-self-insert-comments (insert " -- " index)))
d2ddb974 8768 (forward-line -1)
5eabfe72 8769 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8770
5eabfe72
KH
8771(defun vhdl-template-function (&optional kind)
8772 "Insert a function declaration or body."
d2ddb974 8773 (interactive)
5eabfe72
KH
8774 (let ((margin (current-indentation))
8775 (start (point))
8776 name)
8777 (vhdl-insert-keyword "FUNCTION ")
8778 (when (setq name (vhdl-template-field "name" nil t start (point)))
8779 (vhdl-template-argument-list t)
3dcb36b7 8780 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
d2ddb974 8781 (end-of-line)
5eabfe72 8782 (insert "\n")
d2ddb974 8783 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8784 (vhdl-insert-keyword "RETURN ")
8785 (vhdl-template-field "type")
8786 (if (if kind (eq kind 'body)
8787 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
3dcb36b7 8788 (progn (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8789 (vhdl-template-begin-end
8790 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8791 (vhdl-comment-block))
8792 (insert ";")))))
8793
8794(defun vhdl-template-function-decl ()
8795 "Insert a function declaration."
8796 (interactive)
8797 (vhdl-template-function 'decl))
d2ddb974 8798
5eabfe72
KH
8799(defun vhdl-template-function-body ()
8800 "Insert a function declaration."
d2ddb974 8801 (interactive)
5eabfe72
KH
8802 (vhdl-template-function 'body))
8803
8804(defun vhdl-template-generate ()
8805 "Insert a generation scheme."
8806 (interactive)
8807 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8808 (vhdl-template-if-generate)
8809 (vhdl-template-for-generate)))
d2ddb974 8810
5eabfe72
KH
8811(defun vhdl-template-generic ()
8812 "Insert generic declaration, or generic map in instantiation statements."
8813 (interactive)
3dcb36b7
JB
8814 (let ((start (point)))
8815 (vhdl-prepare-search-1
5eabfe72
KH
8816 (cond
8817 ((and (save-excursion ; entity declaration
8818 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8819 (equal "ENTITY" (upcase (match-string 1))))
8820 (vhdl-template-generic-list nil))
8821 ((or (save-excursion
8822 (or (beginning-of-line)
8823 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 8824 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
8825 (vhdl-insert-keyword "GENERIC ")
8826 (vhdl-template-map start))
8827 (t (vhdl-template-generic-list nil t))))))
8828
8829(defun vhdl-template-group ()
8830 "Insert group or group template declaration."
8831 (interactive)
8832 (let ((start (point)))
8833 (if (eq (vhdl-decision-query
8834 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8835 (vhdl-template-group-template)
8836 (vhdl-template-group-decl))))
8837
8838(defun vhdl-template-group-decl ()
8839 "Insert group declaration."
8840 (interactive)
8841 (let ((start (point)))
8842 (vhdl-insert-keyword "GROUP ")
8843 (when (vhdl-template-field "name" " : " t start (point))
8844 (vhdl-template-field "template name" " (")
8845 (vhdl-template-field "constituent list" ");")
8846 (vhdl-comment-insert-inline))))
8847
8848(defun vhdl-template-group-template ()
8849 "Insert group template declaration."
8850 (interactive)
8851 (let ((start (point)))
8852 (vhdl-insert-keyword "GROUP ")
8853 (when (vhdl-template-field "template name" nil t start (point))
8854 (vhdl-insert-keyword " IS (")
8855 (vhdl-template-field "entity class list" ");")
8856 (vhdl-comment-insert-inline))))
8857
5eabfe72
KH
8858(defun vhdl-template-if ()
8859 "Insert a sequential if statement or an if-generate statement."
8860 (interactive)
8861 (if (vhdl-sequential-statement-p)
8862 (vhdl-template-if-then)
8863 (if (and (vhdl-standard-p 'ams)
8864 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8865 (vhdl-template-if-use)
8866 (vhdl-template-if-generate))))
8867
8868(defun vhdl-template-if-generate ()
8869 "Insert an if-generate."
8870 (interactive)
8871 (let ((margin (current-indentation))
8872 (start (point))
3dcb36b7 8873 label position)
5eabfe72
KH
8874 (vhdl-insert-keyword ": IF ")
8875 (setq position (point-marker))
8876 (goto-char start)
8877 (when (setq label (vhdl-template-field "label" nil t start position))
8878 (goto-char position)
8879 (when vhdl-conditions-in-parenthesis (insert "("))
8880 (vhdl-template-field "condition")
8881 (when vhdl-conditions-in-parenthesis (insert ")"))
8882 (vhdl-template-generate-body margin label))))
d2ddb974 8883
5eabfe72
KH
8884(defun vhdl-template-if-then-use (kind)
8885 "Insert a sequential if statement."
8886 (interactive)
8887 (let ((margin (current-indentation))
8888 (start (point))
8889 label)
8890 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8891 (vhdl-insert-keyword "IF ")
8892 (vhdl-insert-keyword ": IF ")
8893 (goto-char start)
8894 (setq label (vhdl-template-field "[label]" nil t))
8895 (unless label (delete-char 2))
8896 (forward-word 1)
8897 (forward-char 1))
8898 (when vhdl-conditions-in-parenthesis (insert "("))
8899 (when (vhdl-template-field "condition" nil t start (point))
8900 (when vhdl-conditions-in-parenthesis (insert ")"))
8901 (vhdl-insert-keyword
8902 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
d2ddb974 8903 (indent-to margin)
5eabfe72
KH
8904 (vhdl-insert-keyword "END IF")
8905 (when label (insert " " label))
8906 (insert ";")
d2ddb974 8907 (forward-line -1)
5eabfe72
KH
8908 (indent-to (+ margin vhdl-basic-offset)))))
8909
8910(defun vhdl-template-if-then ()
8911 "Insert a sequential if statement."
8912 (interactive)
8913 (vhdl-template-if-then-use 'then))
8914
8915(defun vhdl-template-if-use ()
8916 "Insert a simultaneous if statement."
8917 (interactive)
8918 (vhdl-template-if-then-use 'use))
8919
8920(defun vhdl-template-instance ()
8921 "Insert a component instantiation statement."
8922 (interactive)
8923 (vhdl-template-component-inst))
d2ddb974 8924
5eabfe72 8925(defun vhdl-template-library ()
d2ddb974
KH
8926 "Insert a library specification."
8927 (interactive)
5eabfe72
KH
8928 (let ((margin (current-indentation))
8929 (start (point))
8930 name end-pos)
d2ddb974 8931 (vhdl-insert-keyword "LIBRARY ")
5eabfe72
KH
8932 (when (setq name (vhdl-template-field "names" nil t start (point)))
8933 (insert ";")
8934 (unless (string-match "," name)
8935 (setq end-pos (point))
8936 (insert "\n")
8937 (indent-to margin)
8938 (vhdl-insert-keyword "USE ")
8939 (insert name)
8940 (vhdl-insert-keyword "..ALL;")
8941 (backward-char 5)
8942 (if (vhdl-template-field "package name")
8943 (forward-char 5)
8944 (delete-region end-pos (+ (point) 5)))))))
8945
8946(defun vhdl-template-limit ()
8947 "Insert a limit."
d2ddb974 8948 (interactive)
5eabfe72
KH
8949 (let ((start (point)))
8950 (vhdl-insert-keyword "LIMIT ")
8951 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8952 t start (point))
8953 (vhdl-template-field "type")
8954 (vhdl-insert-keyword " WITH ")
8955 (vhdl-template-field "real expression" ";"))))
8956
8957(defun vhdl-template-loop ()
8958 "Insert a loop."
8959 (interactive)
8960 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8961 (cond ((eq char ?w)
8962 (vhdl-template-while-loop))
8963 ((eq char ?f)
8964 (vhdl-template-for-loop))
8965 (t (vhdl-template-bare-loop)))))
8966
8967(defun vhdl-template-bare-loop ()
8968 "Insert a loop."
8969 (interactive)
8970 (let ((margin (current-indentation))
8971 (start (point))
8972 label)
8973 (if (not (eq vhdl-optional-labels 'all))
8974 (vhdl-insert-keyword "LOOP ")
8975 (vhdl-insert-keyword ": LOOP ")
8976 (goto-char start)
8977 (setq label (vhdl-template-field "[label]" nil t))
8978 (unless label (delete-char 2))
8979 (forward-word 1)
8980 (delete-char 1))
d2ddb974
KH
8981 (insert "\n\n")
8982 (indent-to margin)
8983 (vhdl-insert-keyword "END LOOP")
5eabfe72 8984 (insert (if label (concat " " label ";") ";"))
d2ddb974 8985 (forward-line -1)
5eabfe72 8986 (indent-to (+ margin vhdl-basic-offset))))
d2ddb974 8987
5eabfe72
KH
8988(defun vhdl-template-map (&optional start optional secondary)
8989 "Insert a map specification with association list."
d2ddb974 8990 (interactive)
5eabfe72
KH
8991 (let ((start (or start (point)))
8992 margin end-pos)
8993 (vhdl-insert-keyword "MAP (")
8994 (if (not vhdl-association-list-with-formals)
8995 (if (vhdl-template-field
8996 (concat (and optional "[") "association list" (and optional "]"))
8997 ")" (or (not secondary) optional)
8998 (and (not secondary) start) (point))
8999 t
9000 (if (and optional secondary) (delete-region start (point)))
9001 nil)
9002 (if vhdl-argument-list-indent
9003 (setq margin (current-column))
9004 (setq margin (+ (current-indentation) vhdl-basic-offset))
9005 (insert "\n")
9006 (indent-to margin))
9007 (if (vhdl-template-field
9008 (concat (and optional "[") "formal" (and optional "]"))
9009 " => " (or (not secondary) optional)
9010 (and (not secondary) start) (point))
9011 (progn
9012 (vhdl-template-field "actual" ",")
9013 (setq end-pos (point))
9014 (insert "\n")
9015 (indent-to margin)
9016 (while (vhdl-template-field "[formal]" " => " t)
9017 (vhdl-template-field "actual" ",")
9018 (setq end-pos (point))
9019 (insert "\n")
9020 (indent-to margin))
9021 (delete-region end-pos (point))
d355a0b7 9022 (delete-char -1)
5eabfe72 9023 (insert ")")
3dcb36b7 9024 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9025 t)
9026 (when (and optional secondary) (delete-region start (point)))
9027 nil))))
d2ddb974 9028
5eabfe72 9029(defun vhdl-template-modify (&optional noerror)
d2ddb974
KH
9030 "Actualize modification date."
9031 (interactive)
3dcb36b7
JB
9032 (vhdl-prepare-search-2
9033 (save-excursion
9034 (goto-char (point-min))
9035 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9036 (progn (delete-region (point) (progn (end-of-line) (point)))
9037 (vhdl-template-insert-date))
9038 (unless noerror
a867ead0
DG
9039 (error "ERROR: Modification date prefix string \"%s\" not found"
9040 vhdl-modify-date-prefix-string))))))
9041
5eabfe72
KH
9042
9043(defun vhdl-template-modify-noerror ()
9044 "Call `vhdl-template-modify' with NOERROR non-nil."
9045 (vhdl-template-modify t))
9046
9047(defun vhdl-template-nature ()
9048 "Insert a nature declaration."
9049 (interactive)
9050 (let ((start (point))
9051 name mid-pos end-pos)
9052 (vhdl-insert-keyword "NATURE ")
9053 (when (setq name (vhdl-template-field "name" nil t start (point)))
9054 (vhdl-insert-keyword " IS ")
9055 (let ((definition
9056 (upcase
9057 (or (vhdl-template-field
9058 "across type | ARRAY | RECORD")
9059 ""))))
9060 (cond ((equal definition "")
9061 (insert ";"))
9062 ((equal definition "ARRAY")
453cfeb3 9063 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9064 (vhdl-template-array 'nature t))
9065 ((equal definition "RECORD")
9066 (setq mid-pos (point-marker))
453cfeb3 9067 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9068 (vhdl-template-record 'nature name t))
9069 (t
9070 (vhdl-insert-keyword " ACROSS ")
9071 (vhdl-template-field "through type")
9072 (vhdl-insert-keyword " THROUGH ")
9073 (vhdl-template-field "reference name")
9074 (vhdl-insert-keyword " REFERENCE;")))
9075 (when mid-pos
9076 (setq end-pos (point-marker))
9077 (goto-char mid-pos)
9078 (end-of-line))
9079 (vhdl-comment-insert-inline)
9080 (when end-pos (goto-char end-pos))))))
9081
9082(defun vhdl-template-next ()
9083 "Insert a next statement."
d2ddb974 9084 (interactive)
3dcb36b7
JB
9085 (let ((start (point)))
9086 (vhdl-insert-keyword "NEXT ")
9087 (if (vhdl-template-field "[loop label]" nil t start (point))
9088 (let ((position (point)))
9089 (vhdl-insert-keyword " WHEN ")
9090 (when vhdl-conditions-in-parenthesis (insert "("))
9091 (if (vhdl-template-field "[condition]" nil t)
9092 (when vhdl-conditions-in-parenthesis (insert ")"))
9093 (delete-region position (point))))
9094 (delete-char -1))
5eabfe72
KH
9095 (insert ";")))
9096
9097(defun vhdl-template-others ()
9098 "Insert an others aggregate."
9099 (interactive)
3dcb36b7
JB
9100 (let ((start (point)))
9101 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9102 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9103 (vhdl-insert-keyword "OTHERS => '")
9104 (when (vhdl-template-field "value" nil t start (point))
9105 (insert "')")))
9106 (vhdl-insert-keyword "OTHERS "))))
d2ddb974 9107
5eabfe72 9108(defun vhdl-template-package (&optional kind)
d2ddb974
KH
9109 "Insert a package specification or body."
9110 (interactive)
5eabfe72
KH
9111 (let ((margin (current-indentation))
9112 (start (point))
9113 name body position)
d2ddb974 9114 (vhdl-insert-keyword "PACKAGE ")
5eabfe72
KH
9115 (setq body (if kind (eq kind 'body)
9116 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
3dcb36b7
JB
9117 (when body
9118 (vhdl-insert-keyword "BODY ")
9119 (when (save-excursion
9120 (vhdl-prepare-search-1
9121 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9122 (insert (setq name (match-string 1)))))
9123 (when (or name
9124 (setq name (vhdl-template-field "name" nil t start (point))))
5eabfe72
KH
9125 (vhdl-insert-keyword " IS\n")
9126 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9127 (indent-to (+ margin vhdl-basic-offset))
9128 (setq position (point))
9129 (insert "\n")
9130 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9131 (indent-to margin)
9132 (vhdl-insert-keyword "END ")
9133 (unless (vhdl-standard-p '87)
9134 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9135 (insert (or name "") ";")
9136 (goto-char position))))
d2ddb974 9137
5eabfe72
KH
9138(defun vhdl-template-package-decl ()
9139 "Insert a package specification."
d2ddb974 9140 (interactive)
5eabfe72 9141 (vhdl-template-package 'decl))
d2ddb974 9142
5eabfe72
KH
9143(defun vhdl-template-package-body ()
9144 "Insert a package body."
d2ddb974 9145 (interactive)
5eabfe72 9146 (vhdl-template-package 'body))
d2ddb974 9147
5eabfe72
KH
9148(defun vhdl-template-port ()
9149 "Insert a port declaration, or port map in instantiation statements."
d2ddb974 9150 (interactive)
3dcb36b7
JB
9151 (let ((start (point)))
9152 (vhdl-prepare-search-1
5eabfe72
KH
9153 (cond
9154 ((and (save-excursion ; entity declaration
9155 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9156 (equal "ENTITY" (upcase (match-string 1))))
9157 (vhdl-template-port-list nil))
9158 ((or (save-excursion
9159 (or (beginning-of-line)
9160 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 9161 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
9162 (vhdl-insert-keyword "PORT ")
9163 (vhdl-template-map start))
9164 (t (vhdl-template-port-list nil))))))
9165
9166(defun vhdl-template-procedural ()
9167 "Insert a procedural."
9168 (interactive)
9169 (let ((margin (current-indentation))
9170 (start (point))
9171 (case-fold-search t)
9172 label)
9173 (vhdl-insert-keyword "PROCEDURAL ")
9174 (when (memq vhdl-optional-labels '(process all))
9175 (goto-char start)
9176 (insert ": ")
9177 (goto-char start)
9178 (setq label (vhdl-template-field "[label]" nil t))
9179 (unless label (delete-char 2))
9180 (forward-word 1)
9181 (forward-char 1))
9182 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
3dcb36b7 9183 (insert "\n")
5eabfe72
KH
9184 (vhdl-template-begin-end "PROCEDURAL" label margin)
9185 (vhdl-comment-block)))
9186
9187(defun vhdl-template-procedure (&optional kind)
9188 "Insert a procedure declaration or body."
9189 (interactive)
9190 (let ((margin (current-indentation))
9191 (start (point))
9192 name)
9193 (vhdl-insert-keyword "PROCEDURE ")
9194 (when (setq name (vhdl-template-field "name" nil t start (point)))
9195 (vhdl-template-argument-list)
9196 (if (if kind (eq kind 'body)
9197 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9198 (progn (vhdl-insert-keyword " IS")
9199 (when vhdl-auto-align
3dcb36b7
JB
9200 (vhdl-align-region-groups start (point) 1))
9201 (end-of-line) (insert "\n")
5eabfe72
KH
9202 (vhdl-template-begin-end
9203 (unless (vhdl-standard-p '87) "PROCEDURE")
9204 name margin)
9205 (vhdl-comment-block))
9206 (insert ";")
3dcb36b7 9207 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9208 (end-of-line)))))
9209
9210(defun vhdl-template-procedure-decl ()
9211 "Insert a procedure declaration."
9212 (interactive)
9213 (vhdl-template-procedure 'decl))
d2ddb974 9214
5eabfe72
KH
9215(defun vhdl-template-procedure-body ()
9216 "Insert a procedure body."
9217 (interactive)
9218 (vhdl-template-procedure 'body))
9219
9220(defun vhdl-template-process (&optional kind)
9221 "Insert a process."
9222 (interactive)
9223 (let ((margin (current-indentation))
9224 (start (point))
5eabfe72
KH
9225 label seq input-signals clock reset final-pos)
9226 (setq seq (if kind (eq kind 'seq)
9227 (eq (vhdl-decision-query
9228 "process" "(c)ombinational or (s)equential?" t) ?s)))
9229 (vhdl-insert-keyword "PROCESS ")
9230 (when (memq vhdl-optional-labels '(process all))
9231 (goto-char start)
9232 (insert ": ")
9233 (goto-char start)
9234 (setq label (vhdl-template-field "[label]" nil t))
9235 (unless label (delete-char 2))
9236 (forward-word 1)
9237 (forward-char 1))
9238 (insert "(")
9239 (if (not seq)
9240 (unless (setq input-signals
9241 (vhdl-template-field "[sensitivity list]" ")" t))
9242 (setq input-signals "")
9243 (delete-char -2))
9244 (setq clock (or (and (not (equal "" vhdl-clock-name))
9245 (progn (insert vhdl-clock-name) vhdl-clock-name))
9246 (vhdl-template-field "clock name") "<clock>"))
9247 (when (eq vhdl-reset-kind 'async)
9248 (insert ", ")
9249 (setq reset (or (and (not (equal "" vhdl-reset-name))
9250 (progn (insert vhdl-reset-name) vhdl-reset-name))
9251 (vhdl-template-field "reset name") "<reset>")))
9252 (insert ")"))
9253 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 9254 (insert "\n")
5eabfe72
KH
9255 (vhdl-template-begin-end "PROCESS" label margin)
9256 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9257 (when vhdl-prompt-for-comments
9258 (setq final-pos (point-marker))
3dcb36b7
JB
9259 (vhdl-prepare-search-2
9260 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9261 (vhdl-re-search-backward "\\<process\\>" nil t))
5eabfe72
KH
9262 (end-of-line -0)
9263 (if (bobp)
9264 (progn (insert "\n") (forward-line -1))
9265 (insert "\n"))
9266 (indent-to margin)
9267 (insert "-- purpose: ")
9268 (if (not (vhdl-template-field "[description]" nil t))
9269 (vhdl-line-kill-entire)
9270 (insert "\n")
9271 (indent-to margin)
9272 (insert "-- type : ")
9273 (insert (if seq "sequential" "combinational") "\n")
9274 (indent-to margin)
9275 (insert "-- inputs : ")
9276 (if (not seq)
9277 (insert input-signals)
9278 (insert clock ", ")
9279 (when reset (insert reset ", "))
9280 (unless (vhdl-template-field "[signal names]" nil t)
9281 (delete-char -2)))
9282 (insert "\n")
9283 (indent-to margin)
9284 (insert "-- outputs: ")
9285 (vhdl-template-field "[signal names]" nil t))))
9286 (goto-char final-pos))))
9287
9288(defun vhdl-template-process-comb ()
9289 "Insert a combinational process."
9290 (interactive)
9291 (vhdl-template-process 'comb))
9292
9293(defun vhdl-template-process-seq ()
9294 "Insert a sequential process."
9295 (interactive)
9296 (vhdl-template-process 'seq))
9297
9298(defun vhdl-template-quantity ()
9299 "Insert a quantity declaration."
9300 (interactive)
9301 (if (vhdl-in-argument-list-p)
9302 (let ((start (point)))
9303 (vhdl-insert-keyword "QUANTITY ")
9304 (when (vhdl-template-field "names" nil t start (point))
9305 (insert " : ")
9306 (vhdl-template-field "[IN | OUT]" " " t)
9307 (vhdl-template-field "type")
9308 (insert ";")
9309 (vhdl-comment-insert-inline)))
9310 (let ((char (vhdl-decision-query
9311 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9312 (cond ((eq char ?f) (vhdl-template-quantity-free))
9313 ((eq char ?b) (vhdl-template-quantity-branch))
9314 ((eq char ?s) (vhdl-template-quantity-source))
9315 (t (vhdl-template-undo (point) (point)))))))
9316
9317(defun vhdl-template-quantity-free ()
9318 "Insert a free quantity declaration."
9319 (interactive)
9320 (vhdl-insert-keyword "QUANTITY ")
9321 (vhdl-template-field "names")
9322 (insert " : ")
9323 (vhdl-template-field "type")
9324 (let ((position (point)))
9325 (insert " := ")
9326 (unless (vhdl-template-field "[initialization]" nil t)
9327 (delete-region position (point)))
9328 (insert ";")
9329 (vhdl-comment-insert-inline)))
9330
9331(defun vhdl-template-quantity-branch ()
9332 "Insert a branch quantity declaration."
9333 (interactive)
9334 (let (position)
9335 (vhdl-insert-keyword "QUANTITY ")
9336 (when (vhdl-template-field "[across names]" " " t)
9337 (vhdl-insert-keyword "ACROSS "))
9338 (when (vhdl-template-field "[through names]" " " t)
9339 (vhdl-insert-keyword "THROUGH "))
9340 (vhdl-template-field "plus terminal name")
9341 (setq position (point))
9342 (vhdl-insert-keyword " TO ")
9343 (unless (vhdl-template-field "[minus terminal name]" nil t)
9344 (delete-region position (point)))
9345 (insert ";")
9346 (vhdl-comment-insert-inline)))
9347
9348(defun vhdl-template-quantity-source ()
9349 "Insert a source quantity declaration."
9350 (interactive)
9351 (vhdl-insert-keyword "QUANTITY ")
9352 (vhdl-template-field "names")
9353 (insert " : ")
9354 (vhdl-template-field "type" " ")
9355 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9356 (progn (vhdl-insert-keyword "NOISE ")
9357 (vhdl-template-field "power expression"))
9358 (vhdl-insert-keyword "SPECTRUM ")
9359 (vhdl-template-field "magnitude expression" ", ")
9360 (vhdl-template-field "phase expression"))
9361 (insert ";")
9362 (vhdl-comment-insert-inline))
9363
9364(defun vhdl-template-record (kind &optional name secondary)
d2ddb974
KH
9365 "Insert a record type declaration."
9366 (interactive)
9367 (let ((margin (current-column))
9368 (start (point))
9369 (first t))
9370 (vhdl-insert-keyword "RECORD\n")
9371 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9372 (when (or (vhdl-template-field "element names"
9373 nil (not secondary) start (point))
9374 secondary)
9375 (while (or first (vhdl-template-field "[element names]" nil t))
9376 (insert " : ")
9377 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9378 (vhdl-comment-insert-inline)
9379 (insert "\n")
d2ddb974 9380 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 9381 (setq first nil))
453cfeb3 9382 (delete-region (line-beginning-position) (point))
d2ddb974 9383 (indent-to margin)
5eabfe72
KH
9384 (vhdl-insert-keyword "END RECORD")
9385 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9386 (insert ";")
3dcb36b7 9387 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9388
5eabfe72
KH
9389(defun vhdl-template-report ()
9390 "Insert a report statement."
9391 (interactive)
9392 (let ((start (point)))
9393 (vhdl-insert-keyword "REPORT ")
9394 (if (equal "\"\"" (vhdl-template-field
9395 "string expression" nil t start (point) t))
d355a0b7 9396 (delete-char -2)
5eabfe72
KH
9397 (setq start (point))
9398 (vhdl-insert-keyword " SEVERITY ")
9399 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9400 (delete-region start (point)))
9401 (insert ";"))))
9402
9403(defun vhdl-template-return ()
d2ddb974
KH
9404 "Insert a return statement."
9405 (interactive)
3dcb36b7
JB
9406 (let ((start (point)))
9407 (vhdl-insert-keyword "RETURN ")
9408 (unless (vhdl-template-field "[expression]" nil t start (point))
9409 (delete-char -1))
9410 (insert ";")))
d2ddb974 9411
5eabfe72 9412(defun vhdl-template-selected-signal-asst ()
d2ddb974
KH
9413 "Insert a selected signal assignment."
9414 (interactive)
5eabfe72
KH
9415 (let ((margin (current-indentation))
9416 (start (point))
9417 (choices t))
d2ddb974 9418 (let ((position (point)))
5eabfe72 9419 (vhdl-insert-keyword " SELECT ")
d2ddb974
KH
9420 (goto-char position))
9421 (vhdl-insert-keyword "WITH ")
5eabfe72
KH
9422 (when (vhdl-template-field "selector expression"
9423 nil t start (+ (point) 7))
9424 (forward-word 1)
9425 (delete-char 1)
d2ddb974
KH
9426 (insert "\n")
9427 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9428 (vhdl-template-field "target signal" " <= ")
9429; (vhdl-template-field "[GUARDED] [TRANSPORT]")
d2ddb974
KH
9430 (insert "\n")
9431 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9432 (vhdl-template-field "waveform")
9433 (vhdl-insert-keyword " WHEN ")
9434 (vhdl-template-field "choices" ",")
9435 (insert "\n")
9436 (indent-to (+ margin vhdl-basic-offset))
9437 (while (and choices (vhdl-template-field "[waveform]" nil t))
d2ddb974 9438 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
9439 (if (setq choices (vhdl-template-field "[choices]" "," t))
9440 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9441 (vhdl-insert-keyword "OTHERS")))
9442 (when choices
d2ddb974
KH
9443 (fixup-whitespace)
9444 (delete-char -2))
9445 (insert ";")
3dcb36b7 9446 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9447
5eabfe72 9448(defun vhdl-template-signal ()
d2ddb974
KH
9449 "Insert a signal declaration."
9450 (interactive)
5eabfe72
KH
9451 (let ((start (point))
9452 (in-arglist (vhdl-in-argument-list-p)))
9453 (vhdl-insert-keyword "SIGNAL ")
9454 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9455 (insert " : ")
5eabfe72
KH
9456 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9457 (vhdl-template-field "type")
d2ddb974 9458 (if in-arglist
5eabfe72
KH
9459 (progn (insert ";")
9460 (vhdl-comment-insert-inline))
d2ddb974
KH
9461 (let ((position (point)))
9462 (insert " := ")
5eabfe72
KH
9463 (unless (vhdl-template-field "[initialization]" nil t)
9464 (delete-region position (point)))
9465 (insert ";")
9466 (vhdl-comment-insert-inline))))))
9467
9468(defun vhdl-template-subnature ()
9469 "Insert a subnature declaration."
9470 (interactive)
9471 (let ((start (point))
9472 position)
9473 (vhdl-insert-keyword "SUBNATURE ")
9474 (when (vhdl-template-field "name" nil t start (point))
9475 (vhdl-insert-keyword " IS ")
9476 (vhdl-template-field "nature" " (")
9477 (if (vhdl-template-field "[index range]" nil t)
9478 (insert ")")
9479 (delete-char -2))
9480 (setq position (point))
9481 (vhdl-insert-keyword " TOLERANCE ")
9482 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9483 nil t nil nil t))
9484 (delete-region position (point))
9485 (vhdl-insert-keyword " ACROSS ")
9486 (vhdl-template-field "string expression" nil nil nil nil t)
9487 (vhdl-insert-keyword " THROUGH"))
9488 (insert ";")
9489 (vhdl-comment-insert-inline))))
9490
9491(defun vhdl-template-subprogram-body ()
9492 "Insert a subprogram body."
9493 (interactive)
9494 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9495 (vhdl-template-function-body)
9496 (vhdl-template-procedure-body)))
d2ddb974 9497
5eabfe72
KH
9498(defun vhdl-template-subprogram-decl ()
9499 "Insert a subprogram declaration."
9500 (interactive)
9501 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9502 (vhdl-template-function-decl)
9503 (vhdl-template-procedure-decl)))
9504
9505(defun vhdl-template-subtype ()
d2ddb974
KH
9506 "Insert a subtype declaration."
9507 (interactive)
5eabfe72
KH
9508 (let ((start (point)))
9509 (vhdl-insert-keyword "SUBTYPE ")
9510 (when (vhdl-template-field "name" nil t start (point))
9511 (vhdl-insert-keyword " IS ")
9512 (vhdl-template-field "type" " ")
9513 (unless
9514 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
d2ddb974 9515 (delete-char -1))
5eabfe72
KH
9516 (insert ";")
9517 (vhdl-comment-insert-inline))))
d2ddb974 9518
5eabfe72
KH
9519(defun vhdl-template-terminal ()
9520 "Insert a terminal declaration."
d2ddb974 9521 (interactive)
5eabfe72
KH
9522 (let ((start (point)))
9523 (vhdl-insert-keyword "TERMINAL ")
9524 (when (vhdl-template-field "names" nil t start (point))
9525 (insert " : ")
9526 (vhdl-template-field "nature")
9527 (insert ";")
9528 (vhdl-comment-insert-inline))))
d2ddb974 9529
5eabfe72
KH
9530(defun vhdl-template-type ()
9531 "Insert a type declaration."
9532 (interactive)
9533 (let ((start (point))
9534 name mid-pos end-pos)
9535 (vhdl-insert-keyword "TYPE ")
9536 (when (setq name (vhdl-template-field "name" nil t start (point)))
9537 (vhdl-insert-keyword " IS ")
9538 (let ((definition
9539 (upcase
9540 (or (vhdl-template-field
9541 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9542 ""))))
9543 (cond ((equal definition "")
d355a0b7 9544 (delete-char -4)
5eabfe72
KH
9545 (insert ";"))
9546 ((equal definition "ARRAY")
453cfeb3 9547 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9548 (vhdl-template-array 'type t))
9549 ((equal definition "RECORD")
9550 (setq mid-pos (point-marker))
453cfeb3 9551 (delete-region (point) (progn (forward-word -1) (point)))
5eabfe72
KH
9552 (vhdl-template-record 'type name t))
9553 ((equal definition "ACCESS")
9554 (insert " ")
9555 (vhdl-template-field "type" ";"))
9556 ((equal definition "FILE")
9557 (vhdl-insert-keyword " OF ")
9558 (vhdl-template-field "type" ";"))
9559 (t (insert ";")))
9560 (when mid-pos
9561 (setq end-pos (point-marker))
9562 (goto-char mid-pos)
9563 (end-of-line))
9564 (vhdl-comment-insert-inline)
9565 (when end-pos (goto-char end-pos))))))
9566
9567(defun vhdl-template-use ()
d2ddb974
KH
9568 "Insert a use clause."
9569 (interactive)
3dcb36b7
JB
9570 (let ((start (point)))
9571 (vhdl-prepare-search-1
5eabfe72
KH
9572 (vhdl-insert-keyword "USE ")
9573 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9574 (vhdl-insert-keyword "..ALL;")
9575 (backward-char 6)
9576 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9577 (forward-char 1)
9578 (vhdl-template-field "package name")
9579 (forward-char 5))))))
9580
9581(defun vhdl-template-variable ()
d2ddb974
KH
9582 "Insert a variable declaration."
9583 (interactive)
5eabfe72 9584 (let ((start (point))
5eabfe72 9585 (in-arglist (vhdl-in-argument-list-p)))
3dcb36b7 9586 (vhdl-prepare-search-2
5eabfe72 9587 (if (or (save-excursion
3dcb36b7 9588 (and (vhdl-re-search-backward
5eabfe72
KH
9589 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9590 nil t)
9591 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9592 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9593 (vhdl-insert-keyword "VARIABLE ")
9594 (vhdl-insert-keyword "SHARED VARIABLE ")))
9595 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9596 (insert " : ")
5eabfe72
KH
9597 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9598 (vhdl-template-field "type")
d2ddb974 9599 (if in-arglist
5eabfe72
KH
9600 (progn (insert ";")
9601 (vhdl-comment-insert-inline))
d2ddb974
KH
9602 (let ((position (point)))
9603 (insert " := ")
5eabfe72
KH
9604 (unless (vhdl-template-field "[initialization]" nil t)
9605 (delete-region position (point)))
9606 (insert ";")
9607 (vhdl-comment-insert-inline))))))
d2ddb974 9608
5eabfe72 9609(defun vhdl-template-wait ()
d2ddb974
KH
9610 "Insert a wait statement."
9611 (interactive)
9612 (vhdl-insert-keyword "WAIT ")
5eabfe72
KH
9613 (unless (vhdl-template-field
9614 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9615 nil t)
9616 (delete-char -1))
9617 (insert ";"))
d2ddb974 9618
5eabfe72 9619(defun vhdl-template-when ()
d2ddb974
KH
9620 "Indent correctly if within a case statement."
9621 (interactive)
9622 (let ((position (point))
5eabfe72 9623 margin)
3dcb36b7 9624 (vhdl-prepare-search-2
5eabfe72 9625 (if (and (= (current-column) (current-indentation))
3dcb36b7 9626 (vhdl-re-search-forward "\\<end\\>" nil t)
5eabfe72
KH
9627 (looking-at "\\s-*\\<case\\>"))
9628 (progn
9629 (setq margin (current-indentation))
9630 (goto-char position)
9631 (delete-horizontal-space)
9632 (indent-to (+ margin vhdl-basic-offset)))
9633 (goto-char position)))
9634 (vhdl-insert-keyword "WHEN ")))
9635
9636(defun vhdl-template-while-loop ()
9637 "Insert a while loop."
d2ddb974 9638 (interactive)
5eabfe72
KH
9639 (let* ((margin (current-indentation))
9640 (start (point))
9641 label)
9642 (if (not (eq vhdl-optional-labels 'all))
9643 (vhdl-insert-keyword "WHILE ")
9644 (vhdl-insert-keyword ": WHILE ")
9645 (goto-char start)
9646 (setq label (vhdl-template-field "[label]" nil t))
9647 (unless label (delete-char 2))
9648 (forward-word 1)
9649 (forward-char 1))
9650 (when vhdl-conditions-in-parenthesis (insert "("))
9651 (when (vhdl-template-field "condition" nil t start (point))
9652 (when vhdl-conditions-in-parenthesis (insert ")"))
d2ddb974
KH
9653 (vhdl-insert-keyword " LOOP\n\n")
9654 (indent-to margin)
9655 (vhdl-insert-keyword "END LOOP")
5eabfe72 9656 (insert (if label (concat " " label ";") ";"))
d2ddb974 9657 (forward-line -1)
5eabfe72 9658 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 9659
5eabfe72 9660(defun vhdl-template-with ()
d2ddb974
KH
9661 "Insert a with statement (i.e. selected signal assignment)."
9662 (interactive)
3dcb36b7
JB
9663 (vhdl-prepare-search-1
9664 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9665 (equal ";" (match-string 1)))
9666 (vhdl-template-selected-signal-asst)
9667 (vhdl-insert-keyword "WITH "))))
5eabfe72
KH
9668
9669;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9670;; Special templates
9671
9672(defun vhdl-template-clocked-wait ()
9673 "Insert a wait statement for rising/falling clock edge."
9674 (interactive)
9675 (let ((start (point))
9676 clock)
9677 (vhdl-insert-keyword "WAIT UNTIL ")
9678 (when (setq clock
9679 (or (and (not (equal "" vhdl-clock-name))
9680 (progn (insert vhdl-clock-name) vhdl-clock-name))
9681 (vhdl-template-field "clock name" nil t start (point))))
9682 (insert "'event")
9683 (vhdl-insert-keyword " AND ")
9684 (insert clock)
9685 (insert
9686 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9687 (vhdl-comment-insert-inline
9688 (concat (if vhdl-clock-rising-edge "rising" "falling")
9689 " clock edge")))))
9690
9691(defun vhdl-template-seq-process (clock reset)
9692 "Insert a template for the body of a sequential process."
9693 (let ((margin (current-indentation))
9694 position)
d2ddb974 9695 (vhdl-insert-keyword "IF ")
5eabfe72
KH
9696 (when (eq vhdl-reset-kind 'async)
9697 (insert reset " = "
9698 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9699 (vhdl-insert-keyword " THEN")
9700 (vhdl-comment-insert-inline
9701 (concat "asynchronous reset (active "
9702 (if vhdl-reset-active-high "high" "low") ")"))
9703 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9704 (setq position (point))
9705 (insert "\n") (indent-to margin)
9706 (vhdl-insert-keyword "ELSIF "))
9707 (if (eq vhdl-clock-edge-condition 'function)
9708 (insert (if vhdl-clock-rising-edge "rising" "falling")
9709 "_edge(" clock ")")
9710 (insert clock "'event")
9711 (vhdl-insert-keyword " AND ")
9712 (insert clock " = "
9713 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9714 (vhdl-insert-keyword " THEN")
9715 (vhdl-comment-insert-inline
9716 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9717 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9718 (when (eq vhdl-reset-kind 'sync)
9719 (vhdl-insert-keyword "IF ")
9720 (setq reset (or (and (not (equal "" vhdl-reset-name))
9721 (progn (insert vhdl-reset-name) vhdl-reset-name))
9722 (vhdl-template-field "reset name") "<reset>"))
9723 (insert " = "
9724 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9725 (vhdl-insert-keyword " THEN")
9726 (vhdl-comment-insert-inline
9727 (concat "synchronous reset (active "
9728 (if vhdl-reset-active-high "high" "low") ")"))
9729 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9730 (setq position (point))
9731 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9732 (vhdl-insert-keyword "ELSE")
9733 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9734 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9735 (vhdl-insert-keyword "END IF;"))
9736 (when (eq vhdl-reset-kind 'none)
9737 (setq position (point)))
9738 (insert "\n") (indent-to margin)
d2ddb974 9739 (vhdl-insert-keyword "END IF;")
5eabfe72
KH
9740 (goto-char position)
9741 reset))
d2ddb974 9742
5eabfe72
KH
9743(defun vhdl-template-standard-package (library package)
9744 "Insert specification of a standard package. Include a library
9745specification, if not already there."
3dcb36b7
JB
9746 (let ((margin (current-indentation)))
9747 (unless (equal library "std")
9748 (unless (or (save-excursion
9749 (vhdl-prepare-search-1
9750 (and (not (bobp))
9751 (re-search-backward
9752 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9753 library "\\|end\\)\\>") nil t)
9754 (match-string 2))))
9755 (equal (downcase library) "work"))
9756 (vhdl-insert-keyword "LIBRARY ")
0a2e512a
RF
9757 (insert library ";")
9758 (when package
9759 (insert "\n")
9760 (indent-to margin)))
9761 (when package
9762 (vhdl-insert-keyword "USE ")
9763 (insert library "." package)
9764 (vhdl-insert-keyword ".ALL;")))))
d2ddb974 9765
5eabfe72
KH
9766(defun vhdl-template-package-math-complex ()
9767 "Insert specification of `math_complex' package."
d2ddb974 9768 (interactive)
5eabfe72 9769 (vhdl-template-standard-package "ieee" "math_complex"))
d2ddb974 9770
5eabfe72
KH
9771(defun vhdl-template-package-math-real ()
9772 "Insert specification of `math_real' package."
d2ddb974 9773 (interactive)
5eabfe72 9774 (vhdl-template-standard-package "ieee" "math_real"))
d2ddb974 9775
5eabfe72
KH
9776(defun vhdl-template-package-numeric-bit ()
9777 "Insert specification of `numeric_bit' package."
d2ddb974 9778 (interactive)
5eabfe72 9779 (vhdl-template-standard-package "ieee" "numeric_bit"))
d2ddb974 9780
5eabfe72
KH
9781(defun vhdl-template-package-numeric-std ()
9782 "Insert specification of `numeric_std' package."
d2ddb974 9783 (interactive)
5eabfe72 9784 (vhdl-template-standard-package "ieee" "numeric_std"))
d2ddb974 9785
5eabfe72
KH
9786(defun vhdl-template-package-std-logic-1164 ()
9787 "Insert specification of `std_logic_1164' package."
9788 (interactive)
9789 (vhdl-template-standard-package "ieee" "std_logic_1164"))
d2ddb974 9790
5eabfe72
KH
9791(defun vhdl-template-package-std-logic-arith ()
9792 "Insert specification of `std_logic_arith' package."
9793 (interactive)
9794 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9795
9796(defun vhdl-template-package-std-logic-misc ()
9797 "Insert specification of `std_logic_misc' package."
9798 (interactive)
9799 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9800
9801(defun vhdl-template-package-std-logic-signed ()
9802 "Insert specification of `std_logic_signed' package."
9803 (interactive)
9804 (vhdl-template-standard-package "ieee" "std_logic_signed"))
d2ddb974 9805
5eabfe72
KH
9806(defun vhdl-template-package-std-logic-textio ()
9807 "Insert specification of `std_logic_textio' package."
9808 (interactive)
9809 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9810
9811(defun vhdl-template-package-std-logic-unsigned ()
9812 "Insert specification of `std_logic_unsigned' package."
9813 (interactive)
9814 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9815
9816(defun vhdl-template-package-textio ()
9817 "Insert specification of `textio' package."
9818 (interactive)
9819 (vhdl-template-standard-package "std" "textio"))
9820
9821(defun vhdl-template-directive (directive)
9822 "Insert directive."
9823 (unless (= (current-indentation) (current-column))
9824 (delete-horizontal-space)
9825 (insert " "))
9826 (insert "-- pragma " directive))
9827
9828(defun vhdl-template-directive-translate-on ()
9829 "Insert directive 'translate_on'."
9830 (interactive)
9831 (vhdl-template-directive "translate_on"))
9832
9833(defun vhdl-template-directive-translate-off ()
9834 "Insert directive 'translate_off'."
9835 (interactive)
9836 (vhdl-template-directive "translate_off"))
9837
9838(defun vhdl-template-directive-synthesis-on ()
9839 "Insert directive 'synthesis_on'."
9840 (interactive)
9841 (vhdl-template-directive "synthesis_on"))
9842
9843(defun vhdl-template-directive-synthesis-off ()
9844 "Insert directive 'synthesis_off'."
9845 (interactive)
9846 (vhdl-template-directive "synthesis_off"))
9847
3dcb36b7
JB
9848;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9849;; Header and footer templates
9850
9851(defun vhdl-template-header (&optional file-title)
9852 "Insert a VHDL file header."
9853 (interactive)
9854 (unless (equal vhdl-file-header "")
9855 (let (pos)
9856 (save-excursion
9857 (goto-char (point-min))
9858 (vhdl-insert-string-or-file vhdl-file-header)
9859 (setq pos (point-marker)))
9860 (vhdl-template-replace-header-keywords
9861 (point-min-marker) pos file-title))))
9862
9863(defun vhdl-template-footer ()
9864 "Insert a VHDL file footer."
9865 (interactive)
9866 (unless (equal vhdl-file-footer "")
9867 (let (pos)
9868 (save-excursion
9869 (goto-char (point-max))
9870 (setq pos (point-marker))
9871 (vhdl-insert-string-or-file vhdl-file-footer)
9872 (unless (= (preceding-char) ?\n)
9873 (insert "\n")))
9874 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9875
9876(defun vhdl-template-replace-header-keywords (beg end &optional file-title
9877 is-model)
9878 "Replace keywords in header and footer."
9879 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9880 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9881 pos)
9882 (vhdl-prepare-search-2
9883 (save-excursion
9884 (goto-char beg)
9885 (while (search-forward "<projectdesc>" end t)
9886 (replace-match project-desc t t))
9887 (goto-char beg)
9888 (while (search-forward "<filename>" end t)
9889 (replace-match (buffer-name) t t))
9890 (goto-char beg)
9891 (while (search-forward "<copyright>" end t)
9892 (replace-match vhdl-copyright-string t t))
9893 (goto-char beg)
9894 (while (search-forward "<author>" end t)
9895 (replace-match "" t t)
9896 (insert (user-full-name))
9897 (when user-mail-address (insert " <" user-mail-address ">")))
9898 (goto-char beg)
9899 (while (search-forward "<login>" end t)
9900 (replace-match (user-login-name) t t))
9901 (goto-char beg)
9902 (while (search-forward "<project>" end t)
9903 (replace-match project-title t t))
9904 (goto-char beg)
9905 (while (search-forward "<company>" end t)
9906 (replace-match vhdl-company-name t t))
9907 (goto-char beg)
9908 (while (search-forward "<platform>" end t)
9909 (replace-match vhdl-platform-spec t t))
9910 (goto-char beg)
9911 (while (search-forward "<standard>" end t)
9912 (replace-match
9913 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9914 ((vhdl-standard-p '93) "'93"))
9915 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9916 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9917 (goto-char beg)
9918 ;; Replace <RCS> with $, so that RCS for the source is
9919 ;; not over-enthusiastic with replacements
9920 (while (search-forward "<RCS>" end t)
9921 (replace-match "$" nil t))
9922 (goto-char beg)
9923 (while (search-forward "<date>" end t)
9924 (replace-match "" t t)
9925 (vhdl-template-insert-date))
9926 (goto-char beg)
9927 (while (search-forward "<year>" end t)
9928 (replace-match (format-time-string "%Y" nil) t t))
9929 (goto-char beg)
9930 (when file-title
9931 (while (search-forward "<title string>" end t)
9932 (replace-match file-title t t))
9933 (goto-char beg))
9934 (let (string)
9935 (while
9936 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9937 (setq string (read-string (concat (match-string 1) ": ")))
9938 (replace-match string t t)))
9939 (goto-char beg)
9940 (when (and (not is-model) (search-forward "<cursor>" end t))
9941 (replace-match "" t t)
9942 (setq pos (point))))
9943 (when pos (goto-char pos))
9944 (unless is-model
9945 (when (or (not project-title) (equal project-title ""))
9946 (message "You can specify a project title in user option `vhdl-project-alist'"))
9947 (when (or (not project-desc) (equal project-desc ""))
9948 (message "You can specify a project description in user option `vhdl-project-alist'"))
9949 (when (equal vhdl-platform-spec "")
9950 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9951 (when (equal vhdl-company-name "")
9952 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9953
5eabfe72
KH
9954;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9955;; Comment templates and functions
9956
9957(defun vhdl-comment-indent ()
9958 "Indent comments."
9959 (let* ((position (point))
9960 (col
9961 (progn
9962 (forward-line -1)
9963 (if (re-search-forward "--" position t)
9964 (- (current-column) 2) ; existing comment at bol stays there
9965 (goto-char position)
9966 (skip-chars-backward " \t")
9967 (max comment-column ; else indent to comment column
9968 (1+ (current-column))))))) ; except leave at least one space
9969 (goto-char position)
9970 col))
9971
9972(defun vhdl-comment-insert ()
d2ddb974 9973 "Start a comment at the end of the line.
5eabfe72
KH
9974If on line with code, indent at least `comment-column'.
9975If starting after end-comment-column, start a new line."
d2ddb974 9976 (interactive)
5eabfe72
KH
9977 (when (> (current-column) end-comment-column) (newline-and-indent))
9978 (if (or (looking-at "\\s-*$") ; end of line
d2ddb974
KH
9979 (and (not unread-command-events) ; called with key binding or menu
9980 (not (end-of-line))))
5eabfe72
KH
9981 (let (margin)
9982 (while (= (preceding-char) ?-) (delete-char -1))
d2ddb974 9983 (setq margin (current-column))
5eabfe72
KH
9984 (delete-horizontal-space)
9985 (if (bolp)
9986 (progn (indent-to margin) (insert "--"))
d2ddb974 9987 (insert " ")
5eabfe72
KH
9988 (indent-to comment-column)
9989 (insert "--"))
d2ddb974 9990 (if (not unread-command-events) (insert " ")))
5eabfe72 9991 ;; else code following current point implies commenting out code
d2ddb974
KH
9992 (let (next-input code)
9993 (while (= (preceding-char) ?-) (delete-char -2))
9994 (while (= (setq next-input (read-char)) 13) ; CR
5eabfe72 9995 (insert "--") ; or have a space after it?
d2ddb974
KH
9996 (forward-char -2)
9997 (forward-line 1)
9998 (message "Enter CR if commenting out a line of code.")
5eabfe72 9999 (setq code t))
3dcb36b7 10000 (unless code
5eabfe72 10001 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
d2ddb974 10002 (setq unread-command-events
5eabfe72 10003 (list (vhdl-character-to-event next-input)))))) ; pushback the char
d2ddb974 10004
5eabfe72 10005(defun vhdl-comment-display (&optional line-exists)
d2ddb974
KH
10006 "Add 2 comment lines at the current indent, making a display comment."
10007 (interactive)
5eabfe72 10008 (let ((margin (current-indentation)))
3dcb36b7 10009 (unless line-exists (vhdl-comment-display-line))
5eabfe72
KH
10010 (insert "\n") (indent-to margin)
10011 (insert "\n") (indent-to margin)
10012 (vhdl-comment-display-line)
10013 (end-of-line -0)
10014 (insert "-- ")))
10015
10016(defun vhdl-comment-display-line ()
d2ddb974
KH
10017 "Displays one line of dashes."
10018 (interactive)
10019 (while (= (preceding-char) ?-) (delete-char -2))
10020 (let* ((col (current-column))
10021 (len (- end-comment-column col)))
5eabfe72 10022 (insert-char ?- len)))
d2ddb974 10023
5eabfe72
KH
10024(defun vhdl-comment-append-inline ()
10025 "Append empty inline comment to current line."
10026 (interactive)
10027 (end-of-line)
10028 (delete-horizontal-space)
10029 (insert " ")
10030 (indent-to comment-column)
10031 (insert "-- "))
10032
10033(defun vhdl-comment-insert-inline (&optional string always-insert)
10034 "Insert inline comment."
10035 (when (or (and string (or vhdl-self-insert-comments always-insert))
10036 (and (not string) vhdl-prompt-for-comments))
10037 (let ((position (point)))
10038 (insert " ")
10039 (indent-to comment-column)
10040 (insert "-- ")
3dcb36b7
JB
10041 (if (not (or (and string (progn (insert string) t))
10042 (vhdl-template-field "[comment]" nil t)))
10043 (delete-region position (point))
d355a0b7
SM
10044 (while (= (preceding-char) ?\ ) (delete-char -1))
10045 ;; (when (> (current-column) end-comment-column)
10046 ;; (setq position (point-marker))
10047 ;; (re-search-backward "-- ")
10048 ;; (insert "\n")
10049 ;; (indent-to comment-column)
10050 ;; (goto-char position))
3dcb36b7 10051 ))))
5eabfe72
KH
10052
10053(defun vhdl-comment-block ()
10054 "Insert comment for code block."
10055 (when vhdl-prompt-for-comments
3dcb36b7
JB
10056 (let ((final-pos (point-marker)))
10057 (vhdl-prepare-search-2
5eabfe72 10058 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
3dcb36b7 10059 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
5eabfe72
KH
10060 (let (margin)
10061 (back-to-indentation)
10062 (setq margin (current-column))
10063 (end-of-line -0)
10064 (if (bobp)
10065 (progn (insert "\n") (forward-line -1))
10066 (insert "\n"))
10067 (indent-to margin)
10068 (insert "-- purpose: ")
10069 (unless (vhdl-template-field "[description]" nil t)
10070 (vhdl-line-kill-entire)))))
10071 (goto-char final-pos))))
d2ddb974
KH
10072
10073(defun vhdl-comment-uncomment-region (beg end &optional arg)
5eabfe72 10074 "Comment out region if not commented out, uncomment otherwise."
d2ddb974 10075 (interactive "r\nP")
5eabfe72
KH
10076 (save-excursion
10077 (goto-char (1- end))
10078 (end-of-line)
10079 (setq end (point-marker))
10080 (goto-char beg)
10081 (beginning-of-line)
10082 (setq beg (point))
10083 (if (looking-at comment-start)
3dcb36b7 10084 (comment-region beg end '(4))
5eabfe72
KH
10085 (comment-region beg end))))
10086
10087(defun vhdl-comment-uncomment-line (&optional arg)
10088 "Comment out line if not commented out, uncomment otherwise."
d2ddb974 10089 (interactive "p")
5eabfe72
KH
10090 (save-excursion
10091 (beginning-of-line)
10092 (let ((position (point)))
10093 (forward-line (or arg 1))
10094 (vhdl-comment-uncomment-region position (point)))))
d2ddb974 10095
5eabfe72
KH
10096(defun vhdl-comment-kill-region (beg end)
10097 "Kill comments in region."
10098 (interactive "r")
10099 (save-excursion
10100 (goto-char end)
10101 (setq end (point-marker))
10102 (goto-char beg)
10103 (beginning-of-line)
10104 (while (< (point) end)
10105 (if (looking-at "^\\(\\s-*--.*\n\\)")
10106 (progn (delete-region (match-beginning 1) (match-end 1)))
10107 (beginning-of-line 2)))))
10108
10109(defun vhdl-comment-kill-inline-region (beg end)
10110 "Kill inline comments in region."
10111 (interactive "r")
10112 (save-excursion
10113 (goto-char end)
10114 (setq end (point-marker))
10115 (goto-char beg)
10116 (beginning-of-line)
10117 (while (< (point) end)
10118 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10119 (delete-region (match-beginning 1) (match-end 1)))
10120 (beginning-of-line 2))))
10121
10122;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10123;; Subtemplates
10124
10125(defun vhdl-template-begin-end (construct name margin &optional empty-lines)
d2ddb974
KH
10126 "Insert a begin ... end pair with optional name after the end.
10127Point is left between them."
5eabfe72 10128 (let (position)
5eabfe72 10129 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10130 (indent-to margin)
10131 (vhdl-insert-keyword "BEGIN")
5eabfe72
KH
10132 (when (and (or construct name) vhdl-self-insert-comments)
10133 (insert " --")
10134 (when construct (insert " ") (vhdl-insert-keyword construct))
10135 (when name (insert " " name)))
d2ddb974 10136 (insert "\n")
5eabfe72 10137 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974 10138 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
10139 (setq position (point))
10140 (insert "\n")
10141 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10142 (indent-to margin)
10143 (vhdl-insert-keyword "END")
5eabfe72
KH
10144 (when construct (insert " ") (vhdl-insert-keyword construct))
10145 (insert (if name (concat " " name) "") ";")
10146 (goto-char position)))
d2ddb974 10147
5eabfe72 10148(defun vhdl-template-argument-list (&optional is-function)
d2ddb974
KH
10149 "Read from user a procedure or function argument list."
10150 (insert " (")
d2ddb974 10151 (let ((margin (current-column))
5eabfe72
KH
10152 (start (point))
10153 (end-pos (point))
10154 not-empty interface semicolon-pos)
3dcb36b7 10155 (unless vhdl-argument-list-indent
5eabfe72
KH
10156 (setq margin (+ (current-indentation) vhdl-basic-offset))
10157 (insert "\n")
10158 (indent-to margin))
10159 (setq interface (vhdl-template-field
10160 (concat "[CONSTANT | SIGNAL"
10161 (unless is-function " | VARIABLE") "]") " " t))
10162 (while (vhdl-template-field "[names]" nil t)
10163 (setq not-empty t)
10164 (insert " : ")
3dcb36b7 10165 (unless is-function
5eabfe72
KH
10166 (if (and interface (equal (upcase interface) "CONSTANT"))
10167 (vhdl-insert-keyword "IN ")
10168 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10169 (vhdl-template-field "type")
10170 (setq semicolon-pos (point))
10171 (insert ";")
10172 (vhdl-comment-insert-inline)
10173 (setq end-pos (point))
10174 (insert "\n")
10175 (indent-to margin)
10176 (setq interface (vhdl-template-field
10177 (concat "[CONSTANT | SIGNAL"
10178 (unless is-function " | VARIABLE") "]") " " t)))
10179 (delete-region end-pos (point))
10180 (when semicolon-pos (goto-char semicolon-pos))
10181 (if not-empty
10182 (progn (delete-char 1) (insert ")"))
d355a0b7 10183 (delete-char -2))))
5eabfe72
KH
10184
10185(defun vhdl-template-generic-list (optional &optional no-value)
d2ddb974 10186 "Read from user a generic spec argument list."
5eabfe72 10187 (let (margin
d2ddb974 10188 (start (point)))
5eabfe72
KH
10189 (vhdl-insert-keyword "GENERIC (")
10190 (setq margin (current-column))
3dcb36b7 10191 (unless vhdl-argument-list-indent
5eabfe72
KH
10192 (let ((position (point)))
10193 (back-to-indentation)
10194 (setq margin (+ (current-column) vhdl-basic-offset))
10195 (goto-char position)
10196 (insert "\n")
10197 (indent-to margin)))
10198 (let ((vhdl-generics (vhdl-template-field
10199 (concat (and optional "[") "name"
10200 (and no-value "s") (and optional "]"))
10201 nil optional)))
10202 (if (not vhdl-generics)
d2ddb974 10203 (if optional
5eabfe72 10204 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10205 (unless vhdl-argument-list-indent
5eabfe72
KH
10206 (vhdl-line-kill-entire) (end-of-line -0)))
10207 (vhdl-template-undo start (point))
d2ddb974
KH
10208 nil )
10209 (insert " : ")
5eabfe72
KH
10210 (let (semicolon-pos end-pos)
10211 (while vhdl-generics
10212 (vhdl-template-field "type")
10213 (if no-value
10214 (progn (setq semicolon-pos (point))
10215 (insert ";"))
10216 (insert " := ")
10217 (unless (vhdl-template-field "[value]" nil t)
10218 (delete-char -4))
10219 (setq semicolon-pos (point))
10220 (insert ";"))
10221 (vhdl-comment-insert-inline)
10222 (setq end-pos (point))
10223 (insert "\n")
10224 (indent-to margin)
10225 (setq vhdl-generics (vhdl-template-field
10226 (concat "[name" (and no-value "s") "]")
10227 " : " t)))
10228 (delete-region end-pos (point))
10229 (goto-char semicolon-pos)
10230 (insert ")")
10231 (end-of-line)
3dcb36b7 10232 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
10233 t)))))
10234
10235(defun vhdl-template-port-list (optional)
10236 "Read from user a port spec argument list."
10237 (let ((start (point))
10238 margin vhdl-ports object)
10239 (vhdl-insert-keyword "PORT (")
10240 (setq margin (current-column))
3dcb36b7 10241 (unless vhdl-argument-list-indent
5eabfe72
KH
10242 (let ((position (point)))
10243 (back-to-indentation)
10244 (setq margin (+ (current-column) vhdl-basic-offset))
10245 (goto-char position)
10246 (insert "\n")
10247 (indent-to margin)))
10248 (when (vhdl-standard-p 'ams)
10249 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10250 " " t)))
10251 (setq vhdl-ports (vhdl-template-field
10252 (concat (and optional "[") "names" (and optional "]"))
10253 nil optional))
10254 (if (not vhdl-ports)
10255 (if optional
10256 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10257 (unless vhdl-argument-list-indent
5eabfe72
KH
10258 (vhdl-line-kill-entire) (end-of-line -0)))
10259 (vhdl-template-undo start (point))
10260 nil)
10261 (insert " : ")
10262 (let (semicolon-pos end-pos)
10263 (while vhdl-ports
10264 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10265 (vhdl-template-field "IN | OUT | INOUT" " "))
10266 ((equal "QUANTITY" (upcase object))
10267 (vhdl-template-field "[IN | OUT]" " " t)))
10268 (vhdl-template-field
10269 (if (and object (equal "TERMINAL" (upcase object)))
10270 "nature" "type"))
10271 (setq semicolon-pos (point))
10272 (insert ";")
10273 (vhdl-comment-insert-inline)
10274 (setq end-pos (point))
10275 (insert "\n")
10276 (indent-to margin)
10277 (when (vhdl-standard-p 'ams)
10278 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10279 " " t)))
10280 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10281 (delete-region end-pos (point))
10282 (goto-char semicolon-pos)
10283 (insert ")")
10284 (end-of-line)
3dcb36b7 10285 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
5eabfe72
KH
10286 t))))
10287
10288(defun vhdl-template-generate-body (margin label)
10289 "Insert body for generate template."
10290 (vhdl-insert-keyword " GENERATE")
3dcb36b7
JB
10291; (if (not (vhdl-standard-p '87))
10292; (vhdl-template-begin-end "GENERATE" label margin)
10293 (insert "\n\n")
10294 (indent-to margin)
10295 (vhdl-insert-keyword "END GENERATE ")
10296 (insert label ";")
10297 (end-of-line 0)
10298 (indent-to (+ margin vhdl-basic-offset)))
5eabfe72
KH
10299
10300(defun vhdl-template-insert-date ()
d2ddb974
KH
10301 "Insert date in appropriate format."
10302 (interactive)
5eabfe72
KH
10303 (insert
10304 (cond
3dcb36b7 10305 ;; 'american, 'european, 'scientific kept for backward compatibility
5eabfe72
KH
10306 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10307 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10308 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10309 (t (format-time-string vhdl-date-format nil)))))
10310
10311;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10312;; Help functions
10313
10314(defun vhdl-electric-space (count)
10315 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10316if in comment and past end-comment-column."
10317 (interactive "p")
10318 (cond ((vhdl-in-comment-p)
10319 (self-insert-command count)
10320 (cond ((>= (current-column) (+ 2 end-comment-column))
3dcb36b7
JB
10321 (backward-char 1)
10322 (skip-chars-backward "^ \t\n")
5eabfe72 10323 (indent-new-comment-line)
3dcb36b7 10324 (skip-chars-forward "^ \t\n")
5eabfe72
KH
10325 (forward-char 1))
10326 ((>= (current-column) end-comment-column)
10327 (indent-new-comment-line))
10328 (t nil)))
10329 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10330 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
3dcb36b7
JB
10331 (vhdl-prepare-search-1
10332 (or (expand-abbrev) (vhdl-fix-case-word -1)))
5eabfe72
KH
10333 (self-insert-command count))
10334 (t (self-insert-command count))))
10335
10336(defun vhdl-template-field (prompt &optional follow-string optional
10337 begin end is-string default)
10338 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10339If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10340an empty string is inserted, return nil and call `vhdl-template-undo' for
10341the region between BEGIN and END. IS-STRING indicates whether a string
10342with double-quotes is to be inserted. DEFAULT specifies a default string."
10343 (let ((position (point))
10344 string)
10345 (insert "<" prompt ">")
10346 (setq string
10347 (condition-case ()
10348 (read-from-minibuffer (concat prompt ": ")
10349 (or (and is-string '("\"\"" . 2)) default)
10350 vhdl-minibuffer-local-map)
10351 (quit (if (and optional begin end)
10352 (progn (beep) "")
10353 (keyboard-quit)))))
10354 (when (or (not (equal string "")) optional)
10355 (delete-region position (point)))
10356 (when (and (equal string "") optional begin end)
10357 (vhdl-template-undo begin end)
10358 (message "Template aborted"))
3dcb36b7 10359 (unless (equal string "")
5eabfe72
KH
10360 (insert string)
10361 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
3dcb36b7
JB
10362 vhdl-keywords-regexp)
10363 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10364 vhdl-types-regexp)
10365 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10366 (concat "'" vhdl-attributes-regexp))
10367 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10368 vhdl-enum-values-regexp))
5eabfe72
KH
10369 (when (or (not (equal string "")) (not optional))
10370 (insert (or follow-string "")))
10371 (if (equal string "") nil string)))
10372
10373(defun vhdl-decision-query (string prompt &optional optional)
10374 "Query a decision from the user."
10375 (let ((start (point)))
10376 (when string (vhdl-insert-keyword (concat string " ")))
274f1353 10377 (message "%s" (or prompt ""))
5eabfe72
KH
10378 (let ((char (read-char)))
10379 (delete-region start (point))
10380 (if (and optional (eq char ?\r))
10381 (progn (insert " ")
10382 (unexpand-abbrev)
3dcb36b7 10383 (throw 'abort "ERROR: Template aborted"))
5eabfe72 10384 char))))
d2ddb974
KH
10385
10386(defun vhdl-insert-keyword (keyword)
5eabfe72
KH
10387 "Insert KEYWORD and adjust case."
10388 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
d2ddb974
KH
10389
10390(defun vhdl-case-keyword (keyword)
5eabfe72
KH
10391 "Adjust case of KEYWORD."
10392 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
d2ddb974
KH
10393
10394(defun vhdl-case-word (num)
a4c6cfad 10395 "Adjust case of following NUM words."
5eabfe72
KH
10396 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10397
10398(defun vhdl-minibuffer-tab (&optional prefix-arg)
10399 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7 10400else insert tab (used for word completion in VHDL minibuffer)."
5eabfe72 10401 (interactive "P")
3dcb36b7
JB
10402 (cond
10403 ;; expand word
10404 ((= (char-syntax (preceding-char)) ?w)
10405 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10406 (case-replace nil)
10407 (hippie-expand-only-buffers
10408 (or (and (boundp 'hippie-expand-only-buffers)
10409 hippie-expand-only-buffers)
10410 '(vhdl-mode))))
10411 (vhdl-expand-abbrev prefix-arg)))
10412 ;; expand parenthesis
10413 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10414 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10415 (case-replace nil))
10416 (vhdl-expand-paren prefix-arg)))
10417 ;; insert tab
10418 (t (insert-tab))))
5eabfe72
KH
10419
10420(defun vhdl-template-search-prompt ()
10421 "Search for left out template prompts and query again."
10422 (interactive)
3dcb36b7
JB
10423 (vhdl-prepare-search-2
10424 (when (or (re-search-forward
10425 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10426 (re-search-backward
10427 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10428 (let ((string (match-string 1)))
10429 (replace-match "")
10430 (vhdl-template-field string)))))
5eabfe72
KH
10431
10432(defun vhdl-template-undo (begin end)
10433 "Undo aborted template by deleting region and unexpanding the keyword."
10434 (cond (vhdl-template-invoked-by-hook
10435 (goto-char end)
10436 (insert " ")
10437 (delete-region begin end)
10438 (unexpand-abbrev))
10439 (t (delete-region begin end))))
10440
10441(defun vhdl-insert-string-or-file (string)
10442 "Insert STRING or file contents if STRING is an existing file name."
10443 (unless (equal string "")
3dcb36b7
JB
10444 (let ((file-name
10445 (progn (string-match "^\\([^\n]+\\)" string)
10446 (vhdl-resolve-env-variable (match-string 1 string)))))
10447 (if (file-exists-p file-name)
10448 (forward-char (cadr (insert-file-contents file-name)))
10449 (insert string)))))
10450
10451(defun vhdl-beginning-of-block ()
10452 "Move cursor to the beginning of the enclosing block."
10453 (let (pos)
10454 (save-excursion
10455 (beginning-of-line)
10456 ;; search backward for block beginning or end
10457 (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))
10458 ;; not consider subprogram declarations
10459 (or (and (match-string 5)
10460 (save-match-data
10461 (save-excursion
10462 (goto-char (match-end 5))
0a2e512a
RF
10463 (forward-word 1)
10464 (vhdl-forward-syntactic-ws)
10465 (when (looking-at "(")
10466 (forward-sexp))
3dcb36b7
JB
10467 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10468 (match-string 1)))
10469 ;; not consider configuration specifications
10470 (and (match-string 6)
10471 (save-match-data
10472 (save-excursion
10473 (vhdl-end-of-block)
10474 (beginning-of-line)
10475 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10476 (match-string 2))
10477 ;; skip subblock if block end found
10478 (vhdl-beginning-of-block)))
10479 (when pos (goto-char pos))))
10480
10481(defun vhdl-end-of-block ()
10482 "Move cursor to the end of the enclosing block."
10483 (let (pos)
10484 (save-excursion
10485 (end-of-line)
10486 ;; search forward for block beginning or end
10487 (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))
10488 ;; not consider subprogram declarations
10489 (or (and (match-string 5)
10490 (save-match-data
10491 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10492 (match-string 1)))
10493 ;; not consider configuration specifications
10494 (and (match-string 6)
10495 (save-match-data
10496 (save-excursion
10497 (vhdl-end-of-block)
10498 (beginning-of-line)
10499 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10500 (not (match-string 2)))
10501 ;; skip subblock if block beginning found
10502 (vhdl-end-of-block)))
10503 (when pos (goto-char pos))))
5eabfe72
KH
10504
10505(defun vhdl-sequential-statement-p ()
10506 "Check if point is within sequential statement part."
3dcb36b7
JB
10507 (let ((start (point)))
10508 (save-excursion
10509 (vhdl-prepare-search-2
10510 ;; is sequential statement if ...
10511 (and (re-search-backward "^\\s-*begin\\>" nil t)
10512 ;; ... point is between "begin" and "end" of ...
10513 (progn (vhdl-end-of-block)
10514 (< start (point)))
10515 ;; ... a sequential block
10516 (progn (vhdl-beginning-of-block)
10517 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
5eabfe72
KH
10518
10519(defun vhdl-in-argument-list-p ()
10520 "Check if within an argument list."
10521 (save-excursion
3dcb36b7
JB
10522 (vhdl-prepare-search-2
10523 (or (string-match "arglist"
10524 (format "%s" (caar (vhdl-get-syntactic-context))))
10525 (progn (beginning-of-line)
10526 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
5eabfe72
KH
10527
10528;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10529;; Abbrev hooks
10530
10531(defun vhdl-hooked-abbrev (func)
10532 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
a4c6cfad 10533but not if inside a comment or quote."
3dcb36b7 10534 (if (or (vhdl-in-literal)
5eabfe72
KH
10535 (save-excursion
10536 (forward-word -1)
10537 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10538 (progn
10539 (insert " ")
10540 (unexpand-abbrev)
10541 (delete-char -1))
10542 (if (not vhdl-electric-mode)
10543 (progn
10544 (insert " ")
10545 (unexpand-abbrev)
10546 (backward-word 1)
10547 (vhdl-case-word 1)
10548 (delete-char 1))
1ba983e8 10549 (let ((invoke-char last-command-event)
5eabfe72
KH
10550 (abbrev-mode -1)
10551 (vhdl-template-invoked-by-hook t))
10552 (let ((caught (catch 'abort
10553 (funcall func))))
29a4e67d 10554 (when (stringp caught) (message "%s" caught)))
5eabfe72
KH
10555 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10556 ;; delete CR which is still in event queue
4bcb9c95 10557 (if (fboundp 'enqueue-eval-event)
5eabfe72
KH
10558 (enqueue-eval-event 'delete-char -1)
10559 (setq unread-command-events ; push back a delete char
10560 (list (vhdl-character-to-event ?\177))))))))
10561
10562(defun vhdl-template-alias-hook ()
10563 (vhdl-hooked-abbrev 'vhdl-template-alias))
10564(defun vhdl-template-architecture-hook ()
10565 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10566(defun vhdl-template-assert-hook ()
10567 (vhdl-hooked-abbrev 'vhdl-template-assert))
10568(defun vhdl-template-attribute-hook ()
10569 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10570(defun vhdl-template-block-hook ()
10571 (vhdl-hooked-abbrev 'vhdl-template-block))
10572(defun vhdl-template-break-hook ()
10573 (vhdl-hooked-abbrev 'vhdl-template-break))
10574(defun vhdl-template-case-hook ()
10575 (vhdl-hooked-abbrev 'vhdl-template-case))
10576(defun vhdl-template-component-hook ()
10577 (vhdl-hooked-abbrev 'vhdl-template-component))
10578(defun vhdl-template-instance-hook ()
10579 (vhdl-hooked-abbrev 'vhdl-template-instance))
10580(defun vhdl-template-conditional-signal-asst-hook ()
10581 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10582(defun vhdl-template-configuration-hook ()
10583 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10584(defun vhdl-template-constant-hook ()
10585 (vhdl-hooked-abbrev 'vhdl-template-constant))
10586(defun vhdl-template-disconnect-hook ()
10587 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10588(defun vhdl-template-display-comment-hook ()
10589 (vhdl-hooked-abbrev 'vhdl-comment-display))
10590(defun vhdl-template-else-hook ()
10591 (vhdl-hooked-abbrev 'vhdl-template-else))
10592(defun vhdl-template-elsif-hook ()
10593 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10594(defun vhdl-template-entity-hook ()
10595 (vhdl-hooked-abbrev 'vhdl-template-entity))
10596(defun vhdl-template-exit-hook ()
10597 (vhdl-hooked-abbrev 'vhdl-template-exit))
10598(defun vhdl-template-file-hook ()
10599 (vhdl-hooked-abbrev 'vhdl-template-file))
10600(defun vhdl-template-for-hook ()
10601 (vhdl-hooked-abbrev 'vhdl-template-for))
10602(defun vhdl-template-function-hook ()
10603 (vhdl-hooked-abbrev 'vhdl-template-function))
10604(defun vhdl-template-generic-hook ()
10605 (vhdl-hooked-abbrev 'vhdl-template-generic))
10606(defun vhdl-template-group-hook ()
10607 (vhdl-hooked-abbrev 'vhdl-template-group))
10608(defun vhdl-template-library-hook ()
10609 (vhdl-hooked-abbrev 'vhdl-template-library))
10610(defun vhdl-template-limit-hook ()
10611 (vhdl-hooked-abbrev 'vhdl-template-limit))
10612(defun vhdl-template-if-hook ()
10613 (vhdl-hooked-abbrev 'vhdl-template-if))
10614(defun vhdl-template-bare-loop-hook ()
10615 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10616(defun vhdl-template-map-hook ()
10617 (vhdl-hooked-abbrev 'vhdl-template-map))
10618(defun vhdl-template-nature-hook ()
10619 (vhdl-hooked-abbrev 'vhdl-template-nature))
10620(defun vhdl-template-next-hook ()
10621 (vhdl-hooked-abbrev 'vhdl-template-next))
3dcb36b7
JB
10622(defun vhdl-template-others-hook ()
10623 (vhdl-hooked-abbrev 'vhdl-template-others))
5eabfe72
KH
10624(defun vhdl-template-package-hook ()
10625 (vhdl-hooked-abbrev 'vhdl-template-package))
10626(defun vhdl-template-port-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-port))
10628(defun vhdl-template-procedural-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10630(defun vhdl-template-procedure-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10632(defun vhdl-template-process-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-template-process))
10634(defun vhdl-template-quantity-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10636(defun vhdl-template-report-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-report))
10638(defun vhdl-template-return-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-return))
10640(defun vhdl-template-selected-signal-asst-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10642(defun vhdl-template-signal-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-signal))
10644(defun vhdl-template-subnature-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10646(defun vhdl-template-subtype-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10648(defun vhdl-template-terminal-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10650(defun vhdl-template-type-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-type))
10652(defun vhdl-template-use-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-use))
10654(defun vhdl-template-variable-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-variable))
10656(defun vhdl-template-wait-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-wait))
10658(defun vhdl-template-when-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-when))
10660(defun vhdl-template-while-loop-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10662(defun vhdl-template-with-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-with))
10664(defun vhdl-template-and-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-and))
10666(defun vhdl-template-or-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-or))
10668(defun vhdl-template-nand-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-nand))
10670(defun vhdl-template-nor-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-nor))
10672(defun vhdl-template-xor-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-xor))
10674(defun vhdl-template-xnor-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10676(defun vhdl-template-not-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-not))
10678
10679(defun vhdl-template-default-hook ()
10680 (vhdl-hooked-abbrev 'vhdl-template-default))
10681(defun vhdl-template-default-indent-hook ()
10682 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10683
10684;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10685;; Template insertion from completion list
10686
10687(defun vhdl-template-insert-construct (name)
10688 "Insert the built-in construct template with NAME."
10689 (interactive
10690 (list (let ((completion-ignore-case t))
10691 (completing-read "Construct name: "
10692 vhdl-template-construct-alist nil t))))
10693 (vhdl-template-insert-fun
3dcb36b7 10694 (cadr (assoc name vhdl-template-construct-alist))))
5eabfe72
KH
10695
10696(defun vhdl-template-insert-package (name)
10697 "Insert the built-in package template with NAME."
10698 (interactive
10699 (list (let ((completion-ignore-case t))
10700 (completing-read "Package name: "
10701 vhdl-template-package-alist nil t))))
10702 (vhdl-template-insert-fun
3dcb36b7 10703 (cadr (assoc name vhdl-template-package-alist))))
5eabfe72
KH
10704
10705(defun vhdl-template-insert-directive (name)
10706 "Insert the built-in directive template with NAME."
10707 (interactive
10708 (list (let ((completion-ignore-case t))
10709 (completing-read "Directive name: "
10710 vhdl-template-directive-alist nil t))))
10711 (vhdl-template-insert-fun
3dcb36b7 10712 (cadr (assoc name vhdl-template-directive-alist))))
5eabfe72
KH
10713
10714(defun vhdl-template-insert-fun (fun)
10715 "Call FUN to insert a built-in template."
10716 (let ((caught (catch 'abort (when fun (funcall fun)))))
29a4e67d 10717 (when (stringp caught) (message "%s" caught))))
5eabfe72
KH
10718
10719
10720;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10721;;; Models
10722;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10723
10724(defun vhdl-model-insert (model-name)
10725 "Insert the user model with name MODEL-NAME."
10726 (interactive
10727 (let ((completion-ignore-case t))
10728 (list (completing-read "Model name: " vhdl-model-alist))))
3dcb36b7 10729 (indent-according-to-mode)
5eabfe72
KH
10730 (let ((start (point-marker))
10731 (margin (current-indentation))
5eabfe72 10732 model position prompt string end)
3dcb36b7 10733 (vhdl-prepare-search-2
5eabfe72
KH
10734 (when (setq model (assoc model-name vhdl-model-alist))
10735 ;; insert model
10736 (beginning-of-line)
10737 (delete-horizontal-space)
10738 (goto-char start)
10739 (vhdl-insert-string-or-file (nth 1 model))
10740 (setq end (point-marker))
10741 ;; indent code
10742 (goto-char start)
10743 (beginning-of-line)
10744 (while (< (point) end)
10745 (unless (looking-at "^$")
10746 (insert-char ? margin))
10747 (beginning-of-line 2))
10748 (goto-char start)
10749 ;; insert clock
10750 (unless (equal "" vhdl-clock-name)
10751 (while (re-search-forward "<clock>" end t)
10752 (replace-match vhdl-clock-name)))
10753 (goto-char start)
10754 ;; insert reset
10755 (unless (equal "" vhdl-reset-name)
10756 (while (re-search-forward "<reset>" end t)
10757 (replace-match vhdl-reset-name)))
3dcb36b7
JB
10758 ;; replace header prompts
10759 (vhdl-template-replace-header-keywords start end nil t)
5eabfe72 10760 (goto-char start)
3dcb36b7 10761 ;; query other prompts
5eabfe72
KH
10762 (while (re-search-forward
10763 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10764 (unless (equal "cursor" (match-string 1))
10765 (setq position (match-beginning 1))
10766 (setq prompt (match-string 1))
10767 (replace-match "")
10768 (setq string (vhdl-template-field prompt nil t))
a5a08b1f 10769 ;; replace occurrences of same prompt
5eabfe72
KH
10770 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10771 (replace-match (or string "")))
10772 (goto-char position)))
10773 (goto-char start)
10774 ;; goto final position
10775 (if (re-search-forward "<cursor>" end t)
10776 (replace-match "")
10777 (goto-char end))))))
10778
10779(defun vhdl-model-defun ()
10780 "Define help and hook functions for user models."
10781 (let ((model-alist vhdl-model-alist)
10782 model-name model-keyword)
10783 (while model-alist
10784 ;; define functions for user models that can be invoked from menu and key
10785 ;; bindings and which themselves call `vhdl-model-insert' with the model
10786 ;; name as argument
10787 (setq model-name (nth 0 (car model-alist)))
d4a5b644
GM
10788 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10789 ,(concat "Insert model for \"" model-name "\".")
10790 (interactive)
10791 (vhdl-model-insert ,model-name)))
5eabfe72
KH
10792 ;; define hooks for user models that are invoked from keyword abbrevs
10793 (setq model-keyword (nth 3 (car model-alist)))
10794 (unless (equal model-keyword "")
d4a5b644
GM
10795 (eval `(defun
10796 ,(vhdl-function-name
10797 "vhdl-model" model-name "hook") ()
10798 (vhdl-hooked-abbrev
10799 ',(vhdl-function-name "vhdl-model" model-name)))))
5eabfe72
KH
10800 (setq model-alist (cdr model-alist)))))
10801
10802(vhdl-model-defun)
10803
10804
10805;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10806;;; Port translation
10807;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10808
10809(defvar vhdl-port-list nil
3dcb36b7 10810 "Variable to hold last port map parsed.")
5eabfe72 10811;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
10812;; (ent-name
10813;; ((generic-names) generic-type generic-init generic-comment group-comment)
10814;; ((port-names) port-object port-direct port-type port-comment group-comment)
10815;; (lib-name pack-key))
5eabfe72
KH
10816
10817(defun vhdl-parse-string (string &optional optional)
3dcb36b7 10818 "Check that the text following point matches the regexp in STRING."
5eabfe72 10819 (if (looking-at string)
3dcb36b7 10820 (goto-char (match-end 0))
5eabfe72 10821 (unless optional
3dcb36b7
JB
10822 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10823 (vhdl-current-line) string)))
5eabfe72
KH
10824 nil))
10825
0a2e512a 10826(defun vhdl-replace-string (regexp-cons string &optional adjust-case)
5eabfe72 10827 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
3dcb36b7 10828 (vhdl-prepare-search-1
5eabfe72 10829 (if (string-match (car regexp-cons) string)
0a2e512a
RF
10830 (if adjust-case
10831 (funcall vhdl-file-name-case
10832 (replace-match (cdr regexp-cons) t nil string))
10833 (replace-match (cdr regexp-cons) t nil string))
5eabfe72
KH
10834 string)))
10835
3dcb36b7
JB
10836(defun vhdl-parse-group-comment ()
10837 "Parse comment and empty lines between groups of lines."
10838 (let ((start (point))
10839 string)
10840 (vhdl-forward-comment (point-max))
10841 (setq string (buffer-substring-no-properties start (point)))
0a2e512a 10842 (vhdl-forward-syntactic-ws)
3dcb36b7
JB
10843 ;; strip off leading blanks and first newline
10844 (while (string-match "^\\(\\s-+\\)" string)
10845 (setq string (concat (substring string 0 (match-beginning 1))
10846 (substring string (match-end 1)))))
10847 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10848 (substring string 1)
10849 string)))
10850
10851(defun vhdl-paste-group-comment (string indent)
10852 "Paste comment and empty lines from STRING between groups of lines
10853with INDENT."
10854 (let ((pos (point-marker)))
10855 (when (> indent 0)
10856 (while (string-match "^\\(--\\)" string)
10857 (setq string (concat (substring string 0 (match-beginning 1))
10858 (make-string indent ? )
10859 (substring string (match-beginning 1))))))
10860 (beginning-of-line)
10861 (insert string)
10862 (goto-char pos)))
10863
10864(defvar vhdl-port-flattened nil
10865 "Indicates whether a port has been flattened.")
10866
10867(defun vhdl-port-flatten (&optional as-alist)
0a2e512a
RF
10868 "Flatten port list so that only one generic/port exists per line.
10869This operation is performed on an internally stored port and is only
10870reflected in a subsequent paste operation."
5eabfe72
KH
10871 (interactive)
10872 (if (not vhdl-port-list)
3dcb36b7 10873 (error "ERROR: No port has been read")
0a2e512a 10874 (message "Flattening port for next paste...")
5eabfe72
KH
10875 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10876 (old-vhdl-port-list (cdr vhdl-port-list))
10877 old-port-list new-port-list old-port new-port names)
10878 ;; traverse port list and flatten entries
3dcb36b7 10879 (while (cdr old-vhdl-port-list)
5eabfe72
KH
10880 (setq old-port-list (car old-vhdl-port-list))
10881 (setq new-port-list nil)
10882 (while old-port-list
10883 (setq old-port (car old-port-list))
10884 (setq names (car old-port))
10885 (while names
3dcb36b7
JB
10886 (setq new-port (cons (if as-alist (car names) (list (car names)))
10887 (cdr old-port)))
5eabfe72
KH
10888 (setq new-port-list (append new-port-list (list new-port)))
10889 (setq names (cdr names)))
10890 (setq old-port-list (cdr old-port-list)))
10891 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10892 (setq new-vhdl-port-list (append new-vhdl-port-list
10893 (list new-port-list))))
3dcb36b7
JB
10894 (setq vhdl-port-list
10895 (append new-vhdl-port-list (list old-vhdl-port-list))
10896 vhdl-port-flattened t)
0a2e512a 10897 (message "Flattening port for next paste...done"))))
5eabfe72 10898
3dcb36b7
JB
10899(defvar vhdl-port-reversed-direction nil
10900 "Indicates whether port directions are reversed.")
10901
10902(defun vhdl-port-reverse-direction ()
0a2e512a
RF
10903 "Reverse direction for all ports (useful in testbenches).
10904This operation is performed on an internally stored port and is only
10905reflected in a subsequent paste operation."
3dcb36b7
JB
10906 (interactive)
10907 (if (not vhdl-port-list)
10908 (error "ERROR: No port has been read")
0a2e512a 10909 (message "Reversing port directions for next paste...")
3dcb36b7
JB
10910 (let ((port-list (nth 2 vhdl-port-list))
10911 port-dir-car port-dir)
10912 ;; traverse port list and reverse directions
10913 (while port-list
10914 (setq port-dir-car (cddr (car port-list))
10915 port-dir (car port-dir-car))
10916 (setcar port-dir-car
10917 (cond ((equal port-dir "in") "out")
10918 ((equal port-dir "out") "in")
10919 (t port-dir)))
10920 (setq port-list (cdr port-list)))
10921 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
0a2e512a 10922 (message "Reversing port directions for next paste...done"))))
3dcb36b7 10923
5eabfe72
KH
10924(defun vhdl-port-copy ()
10925 "Get generic and port information from an entity or component declaration."
10926 (interactive)
5eabfe72 10927 (save-excursion
3dcb36b7
JB
10928 (let (parse-error end-of-list
10929 decl-type name generic-list port-list context-clause
10930 object names direct type init comment group-comment)
10931 (vhdl-prepare-search-2
5eabfe72
KH
10932 (setq
10933 parse-error
10934 (catch 'parse
10935 ;; check if within entity or component declaration
3dcb36b7 10936 (end-of-line)
5eabfe72
KH
10937 (when (or (not (re-search-backward
10938 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
3dcb36b7
JB
10939 (equal "END" (upcase (match-string 1))))
10940 (throw 'parse "ERROR: Not within an entity or component declaration"))
10941 (setq decl-type (downcase (match-string-no-properties 1)))
5eabfe72 10942 (forward-word 1)
3dcb36b7
JB
10943 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10944 (setq name (match-string-no-properties 1))
10945 (message "Reading port of %s \"%s\"..." decl-type name)
5eabfe72
KH
10946 (vhdl-forward-syntactic-ws)
10947 ;; parse generic clause
10948 (when (vhdl-parse-string "generic[ \t\n]*(" t)
3dcb36b7
JB
10949 ;; parse group comment and spacing
10950 (setq group-comment (vhdl-parse-group-comment))
10951 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72 10952 (while (not end-of-list)
0a2e512a
RF
10953 ;; parse names (accept extended identifiers)
10954 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
3dcb36b7 10955 (setq names (list (match-string-no-properties 1)))
5eabfe72 10956 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
3dcb36b7
JB
10957 (setq names
10958 (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10959 ;; parse type
10960 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
3dcb36b7 10961 (setq type (match-string-no-properties 1))
5eabfe72
KH
10962 (setq comment nil)
10963 (while (looking-at "(")
10964 (setq type
10965 (concat type
3dcb36b7 10966 (buffer-substring-no-properties
5eabfe72
KH
10967 (point) (progn (forward-sexp) (point)))
10968 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
3dcb36b7 10969 (match-string-no-properties 1)))))
5eabfe72
KH
10970 ;; special case: closing parenthesis is on separate line
10971 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10972 (setq comment (substring type (match-beginning 2)))
10973 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10974 ;; strip of trailing group-comment
5eabfe72
KH
10975 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10976 (setq type (substring type 0 (match-end 1)))
10977 ;; parse initialization expression
10978 (setq init nil)
10979 (when (vhdl-parse-string ":=[ \t\n]*" t)
10980 (vhdl-parse-string "\\([^();\n]*\\)")
3dcb36b7 10981 (setq init (match-string-no-properties 1))
5eabfe72
KH
10982 (while (looking-at "(")
10983 (setq init
10984 (concat init
3dcb36b7 10985 (buffer-substring-no-properties
5eabfe72
KH
10986 (point) (progn (forward-sexp) (point)))
10987 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 10988 (match-string-no-properties 1))))))
5eabfe72
KH
10989 ;; special case: closing parenthesis is on separate line
10990 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10991 (setq comment (substring init (match-beginning 2)))
10992 (setq init (substring init 0 (match-beginning 1)))
10993 (vhdl-forward-syntactic-ws))
10994 (skip-chars-forward " \t")
10995 ;; parse inline comment, special case: as above, no initial.
10996 (unless comment
10997 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10998 (match-string-no-properties 1))))
5eabfe72
KH
10999 (vhdl-forward-syntactic-ws)
11000 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11001 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11002 ;; parse inline comment
11003 (unless comment
11004 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11005 (match-string-no-properties 1))))
5eabfe72 11006 ;; save everything in list
3dcb36b7
JB
11007 (setq generic-list (append generic-list
11008 (list (list names type init
11009 comment group-comment))))
11010 ;; parse group comment and spacing
11011 (setq group-comment (vhdl-parse-group-comment))))
5eabfe72
KH
11012 ;; parse port clause
11013 (when (vhdl-parse-string "port[ \t\n]*(" t)
3dcb36b7
JB
11014 ;; parse group comment and spacing
11015 (setq group-comment (vhdl-parse-group-comment))
11016 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
11017 (while (not end-of-list)
11018 ;; parse object
11019 (setq object
0a2e512a 11020 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
3dcb36b7
JB
11021 (match-string-no-properties 1)))
11022 ;; parse names (accept extended identifiers)
11023 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11024 (setq names (list (match-string-no-properties 1)))
11025 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11026 (setq names (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
11027 ;; parse direction
11028 (vhdl-parse-string ":[ \t\n]*")
11029 (setq direct
0a2e512a 11030 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
3dcb36b7 11031 (match-string-no-properties 1)))
5eabfe72
KH
11032 ;; parse type
11033 (vhdl-parse-string "\\([^();\n]+\\)")
3dcb36b7 11034 (setq type (match-string-no-properties 1))
5eabfe72
KH
11035 (setq comment nil)
11036 (while (looking-at "(")
11037 (setq type (concat type
3dcb36b7 11038 (buffer-substring-no-properties
5eabfe72
KH
11039 (point) (progn (forward-sexp) (point)))
11040 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11041 (match-string-no-properties 1)))))
5eabfe72 11042 ;; special case: closing parenthesis is on separate line
3dcb36b7 11043 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
5eabfe72
KH
11044 (setq comment (substring type (match-beginning 2)))
11045 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 11046 ;; strip of trailing group-comment
5eabfe72
KH
11047 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11048 (setq type (substring type 0 (match-end 1)))
11049 (vhdl-forward-syntactic-ws)
11050 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11051 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11052 ;; parse inline comment
11053 (unless comment
11054 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11055 (match-string-no-properties 1))))
5eabfe72 11056 ;; save everything in list
3dcb36b7
JB
11057 (setq port-list (append port-list
11058 (list (list names object direct type
11059 comment group-comment))))
11060 ;; parse group comment and spacing
11061 (setq group-comment (vhdl-parse-group-comment))))
11062; (vhdl-parse-string "end\\>")
11063 ;; parse context clause
11064 (setq context-clause (vhdl-scan-context-clause))
11065; ;; add surrounding package to context clause
11066; (when (and (equal decl-type "component")
11067; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11068; (setq context-clause
11069; (append context-clause
11070; (list (cons (vhdl-work-library)
11071; (match-string-no-properties 1))))))
11072 (message "Reading port of %s \"%s\"...done" decl-type name)
5eabfe72
KH
11073 nil)))
11074 ;; finish parsing
11075 (if parse-error
11076 (error parse-error)
3dcb36b7
JB
11077 (setq vhdl-port-list (list name generic-list port-list context-clause)
11078 vhdl-port-reversed-direction nil
11079 vhdl-port-flattened nil)))))
11080
11081(defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11082 "Paste a context clause."
11083 (let ((margin (current-indentation))
11084 (clause-list (nth 3 vhdl-port-list))
11085 clause)
11086 (while clause-list
11087 (setq clause (car clause-list))
11088 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11089 (downcase exclude-pack-name)))
11090 (save-excursion
11091 (re-search-backward
11092 (concat "^\\s-*use\\s-+" (car clause)
11093 "\." (cdr clause) "\\>") nil t)))
11094 (vhdl-template-standard-package (car clause) (cdr clause))
11095 (insert "\n"))
11096 (setq clause-list (cdr clause-list)))))
5eabfe72
KH
11097
11098(defun vhdl-port-paste-generic (&optional no-init)
11099 "Paste a generic clause."
11100 (let ((margin (current-indentation))
3dcb36b7
JB
11101 (generic-list (nth 1 vhdl-port-list))
11102 list-margin start names generic)
5eabfe72 11103 ;; paste generic clause
3dcb36b7 11104 (when generic-list
5eabfe72
KH
11105 (setq start (point))
11106 (vhdl-insert-keyword "GENERIC (")
11107 (unless vhdl-argument-list-indent
11108 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11109 (setq list-margin (current-column))
3dcb36b7
JB
11110 (while generic-list
11111 (setq generic (car generic-list))
11112 ;; paste group comment and spacing
11113 (when (memq vhdl-include-group-comments '(decl always))
11114 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72 11115 ;; paste names
5eabfe72
KH
11116 (setq names (nth 0 generic))
11117 (while names
11118 (insert (car names))
11119 (setq names (cdr names))
11120 (when names (insert ", ")))
11121 ;; paste type
11122 (insert " : " (nth 1 generic))
11123 ;; paste initialization
11124 (when (and (not no-init) (nth 2 generic))
11125 (insert " := " (nth 2 generic)))
3dcb36b7 11126 (unless (cdr generic-list) (insert ")"))
5eabfe72
KH
11127 (insert ";")
11128 ;; paste comment
11129 (when (and vhdl-include-port-comments (nth 3 generic))
11130 (vhdl-comment-insert-inline (nth 3 generic) t))
3dcb36b7
JB
11131 (setq generic-list (cdr generic-list))
11132 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72 11133 ;; align generic clause
3dcb36b7 11134 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
5eabfe72
KH
11135
11136(defun vhdl-port-paste-port ()
11137 "Paste a port clause."
11138 (let ((margin (current-indentation))
3dcb36b7
JB
11139 (port-list (nth 2 vhdl-port-list))
11140 list-margin start names port)
5eabfe72 11141 ;; paste port clause
3dcb36b7 11142 (when port-list
5eabfe72
KH
11143 (setq start (point))
11144 (vhdl-insert-keyword "PORT (")
11145 (unless vhdl-argument-list-indent
11146 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11147 (setq list-margin (current-column))
3dcb36b7
JB
11148 (while port-list
11149 (setq port (car port-list))
11150 ;; paste group comment and spacing
11151 (when (memq vhdl-include-group-comments '(decl always))
11152 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11153 ;; paste object
11154 (when (nth 1 port) (insert (nth 1 port) " "))
11155 ;; paste names
11156 (setq names (nth 0 port))
11157 (while names
11158 (insert (car names))
11159 (setq names (cdr names))
11160 (when names (insert ", ")))
11161 ;; paste direction
11162 (insert " : ")
11163 (when (nth 2 port) (insert (nth 2 port) " "))
11164 ;; paste type
11165 (insert (nth 3 port))
3dcb36b7 11166 (unless (cdr port-list) (insert ")"))
5eabfe72
KH
11167 (insert ";")
11168 ;; paste comment
11169 (when (and vhdl-include-port-comments (nth 4 port))
11170 (vhdl-comment-insert-inline (nth 4 port) t))
3dcb36b7
JB
11171 (setq port-list (cdr port-list))
11172 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72 11173 ;; align port clause
3dcb36b7 11174 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
5eabfe72 11175
3dcb36b7 11176(defun vhdl-port-paste-declaration (kind &optional no-indent)
5eabfe72 11177 "Paste as an entity or component declaration."
3dcb36b7 11178 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11179 (let ((margin (current-indentation))
11180 (name (nth 0 vhdl-port-list)))
11181 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11182 (insert name)
3dcb36b7
JB
11183 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11184 (vhdl-insert-keyword " IS"))
11185 ;; paste generic and port clause
5eabfe72
KH
11186 (when (nth 1 vhdl-port-list)
11187 (insert "\n")
11188 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11189 (insert "\n"))
11190 (indent-to (+ margin vhdl-basic-offset))
11191 (vhdl-port-paste-generic (eq kind 'component)))
11192 (when (nth 2 vhdl-port-list)
11193 (insert "\n")
11194 (when (and (memq vhdl-insert-empty-lines '(unit all))
11195 (eq kind 'entity))
11196 (insert "\n"))
11197 (indent-to (+ margin vhdl-basic-offset)))
11198 (vhdl-port-paste-port)
11199 (insert "\n")
11200 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11201 (insert "\n"))
11202 (indent-to margin)
11203 (vhdl-insert-keyword "END")
11204 (if (eq kind 'entity)
11205 (progn
11206 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11207 (insert " " name))
11208 (vhdl-insert-keyword " COMPONENT")
11209 (unless (vhdl-standard-p '87) (insert " " name)))
11210 (insert ";")))
11211
3dcb36b7 11212(defun vhdl-port-paste-entity (&optional no-indent)
5eabfe72
KH
11213 "Paste as an entity declaration."
11214 (interactive)
11215 (if (not vhdl-port-list)
3dcb36b7
JB
11216 (error "ERROR: No port read")
11217 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11218 (vhdl-port-paste-declaration 'entity no-indent)
11219 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
5eabfe72 11220
3dcb36b7 11221(defun vhdl-port-paste-component (&optional no-indent)
5eabfe72
KH
11222 "Paste as a component declaration."
11223 (interactive)
11224 (if (not vhdl-port-list)
3dcb36b7
JB
11225 (error "ERROR: No port read")
11226 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11227 (vhdl-port-paste-declaration 'component no-indent)
11228 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
5eabfe72
KH
11229
11230(defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11231 "Paste as a generic map."
11232 (interactive)
3dcb36b7 11233 (unless secondary (indent-according-to-mode))
5eabfe72
KH
11234 (let ((margin (current-indentation))
11235 list-margin start generic
3dcb36b7
JB
11236 (generic-list (nth 1 vhdl-port-list)))
11237 (when generic-list
5eabfe72
KH
11238 (setq start (point))
11239 (vhdl-insert-keyword "GENERIC MAP (")
11240 (if (not vhdl-association-list-with-formals)
11241 ;; paste list of actual generics
3dcb36b7
JB
11242 (while generic-list
11243 (insert (if no-constants
11244 (car (nth 0 (car generic-list)))
11245 (or (nth 2 (car generic-list)) " ")))
11246 (setq generic-list (cdr generic-list))
0a2e512a
RF
11247 (insert (if generic-list ", " ")"))
11248 (when (and (not generic-list) secondary
11249 (null (nth 2 vhdl-port-list)))
11250 (insert ";")))
5eabfe72 11251 (unless vhdl-argument-list-indent
3dcb36b7 11252 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11253 (setq list-margin (current-column))
3dcb36b7
JB
11254 (while generic-list
11255 (setq generic (car generic-list))
11256 ;; paste group comment and spacing
11257 (when (eq vhdl-include-group-comments 'always)
11258 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72
KH
11259 ;; paste formal and actual generic
11260 (insert (car (nth 0 generic)) " => "
11261 (if no-constants
11262 (car (nth 0 generic))
11263 (or (nth 2 generic) "")))
3dcb36b7
JB
11264 (setq generic-list (cdr generic-list))
11265 (insert (if generic-list "," ")"))
0a2e512a
RF
11266 (when (and (not generic-list) secondary
11267 (null (nth 2 vhdl-port-list)))
11268 (insert ";"))
5eabfe72 11269 ;; paste comment
3dcb36b7
JB
11270 (when (or vhdl-include-type-comments
11271 (and vhdl-include-port-comments (nth 3 generic)))
11272 (vhdl-comment-insert-inline
11273 (concat
11274 (when vhdl-include-type-comments
11275 (concat "[" (nth 1 generic) "] "))
11276 (when vhdl-include-port-comments (nth 3 generic))) t))
11277 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11278 ;; align generic map
11279 (when vhdl-auto-align
3dcb36b7 11280 (vhdl-align-region-groups start (point) 1 t))))))
5eabfe72
KH
11281
11282(defun vhdl-port-paste-port-map ()
11283 "Paste as a port map."
11284 (let ((margin (current-indentation))
11285 list-margin start port
3dcb36b7
JB
11286 (port-list (nth 2 vhdl-port-list)))
11287 (when port-list
5eabfe72
KH
11288 (setq start (point))
11289 (vhdl-insert-keyword "PORT MAP (")
11290 (if (not vhdl-association-list-with-formals)
11291 ;; paste list of actual ports
3dcb36b7 11292 (while port-list
5eabfe72 11293 (insert (vhdl-replace-string vhdl-actual-port-name
3dcb36b7
JB
11294 (car (nth 0 (car port-list)))))
11295 (setq port-list (cdr port-list))
0a2e512a 11296 (insert (if port-list ", " ")")))
5eabfe72 11297 (unless vhdl-argument-list-indent
3dcb36b7 11298 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11299 (setq list-margin (current-column))
3dcb36b7
JB
11300 (while port-list
11301 (setq port (car port-list))
11302 ;; paste group comment and spacing
11303 (when (eq vhdl-include-group-comments 'always)
11304 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11305 ;; paste formal and actual port
11306 (insert (car (nth 0 port)) " => ")
11307 (insert (vhdl-replace-string vhdl-actual-port-name
11308 (car (nth 0 port))))
3dcb36b7
JB
11309 (setq port-list (cdr port-list))
11310 (insert (if port-list "," ");"))
5eabfe72
KH
11311 ;; paste comment
11312 (when (or vhdl-include-direction-comments
3dcb36b7 11313 vhdl-include-type-comments
5eabfe72
KH
11314 (and vhdl-include-port-comments (nth 4 port)))
11315 (vhdl-comment-insert-inline
11316 (concat
3dcb36b7
JB
11317 (cond ((and vhdl-include-direction-comments
11318 vhdl-include-type-comments)
11319 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11320 (nth 3 port) "] "))
11321 ((and vhdl-include-direction-comments (nth 2 port))
11322 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11323 (vhdl-include-direction-comments " ")
11324 (vhdl-include-type-comments
11325 (concat "[" (nth 3 port) "] ")))
11326 (when vhdl-include-port-comments (nth 4 port))) t))
11327 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11328 ;; align port clause
11329 (when vhdl-auto-align
3dcb36b7 11330 (vhdl-align-region-groups start (point) 1))))))
5eabfe72 11331
3dcb36b7 11332(defun vhdl-port-paste-instance (&optional name no-indent title)
5eabfe72
KH
11333 "Paste as an instantiation."
11334 (interactive)
11335 (if (not vhdl-port-list)
3dcb36b7 11336 (error "ERROR: No port read")
5eabfe72
KH
11337 (let ((orig-vhdl-port-list vhdl-port-list))
11338 ;; flatten local copy of port list (must be flat for port mapping)
11339 (vhdl-port-flatten)
3dcb36b7
JB
11340 (unless no-indent (indent-according-to-mode))
11341 (let ((margin (current-indentation)))
5eabfe72 11342 ;; paste instantiation
3dcb36b7
JB
11343 (cond (name
11344 (insert name))
11345 ((equal (cdr vhdl-instance-name) "")
11346 (setq name (vhdl-template-field "instance name")))
11347 ((string-match "\%d" (cdr vhdl-instance-name))
11348 (let ((n 1))
11349 (while (save-excursion
11350 (setq name (format (vhdl-replace-string
11351 vhdl-instance-name
11352 (nth 0 vhdl-port-list)) n))
11353 (goto-char (point-min))
11354 (vhdl-re-search-forward name nil t))
11355 (setq n (1+ n)))
11356 (insert name)))
11357 (t (insert (vhdl-replace-string vhdl-instance-name
11358 (nth 0 vhdl-port-list)))))
11359 (message "Pasting port as instantiation \"%s\"..." name)
11360 (insert ": ")
11361 (when title
11362 (save-excursion
11363 (beginning-of-line)
11364 (indent-to vhdl-basic-offset)
11365 (insert "-- instance \"" name "\"\n")))
11366 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
11367 (insert (nth 0 vhdl-port-list))
11368 (vhdl-insert-keyword "ENTITY ")
3dcb36b7 11369 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
5eabfe72
KH
11370 (when (nth 1 vhdl-port-list)
11371 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11372 (vhdl-port-paste-generic-map t t))
11373 (when (nth 2 vhdl-port-list)
11374 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11375 (vhdl-port-paste-port-map))
0a2e512a
RF
11376 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11377 (insert ";"))
3dcb36b7
JB
11378 (message "Pasting port as instantiation \"%s\"...done" name))
11379 (setq vhdl-port-list orig-vhdl-port-list))))
11380
11381(defun vhdl-port-paste-constants (&optional no-indent)
11382 "Paste generics as constants."
11383 (interactive)
11384 (if (not vhdl-port-list)
11385 (error "ERROR: No port read")
11386 (let ((orig-vhdl-port-list vhdl-port-list))
11387 (message "Pasting port as constants...")
11388 ;; flatten local copy of port list (must be flat for constant initial.)
11389 (vhdl-port-flatten)
11390 (unless no-indent (indent-according-to-mode))
11391 (let ((margin (current-indentation))
11392 start generic name
11393 (generic-list (nth 1 vhdl-port-list)))
11394 (when generic-list
11395 (setq start (point))
11396 (while generic-list
11397 (setq generic (car generic-list))
11398 ;; paste group comment and spacing
11399 (when (memq vhdl-include-group-comments '(decl always))
11400 (vhdl-paste-group-comment (nth 4 generic) margin))
11401 (vhdl-insert-keyword "CONSTANT ")
11402 ;; paste generic constants
11403 (setq name (nth 0 generic))
11404 (when name
11405 (insert (car name))
11406 ;; paste type
11407 (insert " : " (nth 1 generic))
11408 ;; paste initialization
11409 (when (nth 2 generic)
11410 (insert " := " (nth 2 generic)))
11411 (insert ";")
11412 ;; paste comment
11413 (when (and vhdl-include-port-comments (nth 3 generic))
11414 (vhdl-comment-insert-inline (nth 3 generic) t))
11415 (setq generic-list (cdr generic-list))
11416 (when generic-list (insert "\n") (indent-to margin))))
11417 ;; align signal list
11418 (when vhdl-auto-align
11419 (vhdl-align-region-groups start (point) 1))))
11420 (message "Pasting port as constants...done")
5eabfe72
KH
11421 (setq vhdl-port-list orig-vhdl-port-list))))
11422
3dcb36b7 11423(defun vhdl-port-paste-signals (&optional initialize no-indent)
5eabfe72
KH
11424 "Paste ports as internal signals."
11425 (interactive)
11426 (if (not vhdl-port-list)
3dcb36b7 11427 (error "ERROR: No port read")
5eabfe72 11428 (message "Pasting port as signals...")
3dcb36b7 11429 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11430 (let ((margin (current-indentation))
11431 start port names
3dcb36b7
JB
11432 (port-list (nth 2 vhdl-port-list)))
11433 (when port-list
5eabfe72 11434 (setq start (point))
3dcb36b7
JB
11435 (while port-list
11436 (setq port (car port-list))
11437 ;; paste group comment and spacing
11438 (when (memq vhdl-include-group-comments '(decl always))
11439 (vhdl-paste-group-comment (nth 5 port) margin))
5eabfe72
KH
11440 ;; paste object
11441 (if (nth 1 port)
11442 (insert (nth 1 port) " ")
11443 (vhdl-insert-keyword "SIGNAL "))
11444 ;; paste actual port signals
11445 (setq names (nth 0 port))
11446 (while names
11447 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11448 (setq names (cdr names))
11449 (when names (insert ", ")))
11450 ;; paste type
11451 (insert " : " (nth 3 port))
11452 ;; paste initialization (inputs only)
3dcb36b7
JB
11453 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11454 (insert " := " (if (string-match "(.+)" (nth 3 port))
11455 "(others => '0')" "'0'")))
5eabfe72
KH
11456 (insert ";")
11457 ;; paste comment
3dcb36b7
JB
11458 (when (or vhdl-include-direction-comments
11459 (and vhdl-include-port-comments (nth 4 port)))
11460 (vhdl-comment-insert-inline
11461 (concat
11462 (cond ((and vhdl-include-direction-comments (nth 2 port))
11463 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11464 (vhdl-include-direction-comments " "))
11465 (when vhdl-include-port-comments (nth 4 port))) t))
11466 (setq port-list (cdr port-list))
11467 (when port-list (insert "\n") (indent-to margin)))
5eabfe72 11468 ;; align signal list
3dcb36b7 11469 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
5eabfe72
KH
11470 (message "Pasting port as signals...done")))
11471
3dcb36b7
JB
11472(defun vhdl-port-paste-initializations (&optional no-indent)
11473 "Paste ports as signal initializations."
5eabfe72
KH
11474 (interactive)
11475 (if (not vhdl-port-list)
3dcb36b7 11476 (error "ERROR: No port read")
5eabfe72 11477 (let ((orig-vhdl-port-list vhdl-port-list))
3dcb36b7
JB
11478 (message "Pasting port as initializations...")
11479 ;; flatten local copy of port list (must be flat for signal initial.)
5eabfe72 11480 (vhdl-port-flatten)
3dcb36b7 11481 (unless no-indent (indent-according-to-mode))
5eabfe72 11482 (let ((margin (current-indentation))
3dcb36b7
JB
11483 start port name
11484 (port-list (nth 2 vhdl-port-list)))
11485 (when port-list
5eabfe72 11486 (setq start (point))
3dcb36b7
JB
11487 (while port-list
11488 (setq port (car port-list))
11489 ;; paste actual port signal (inputs only)
11490 (when (equal "IN" (upcase (nth 2 port)))
11491 (setq name (car (nth 0 port)))
11492 (insert (vhdl-replace-string vhdl-actual-port-name name))
5eabfe72 11493 ;; paste initialization
3dcb36b7
JB
11494 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11495 "(others => '0')" "'0'") ";"))
11496 (setq port-list (cdr port-list))
11497 (when (and port-list
11498 (equal "IN" (upcase (nth 2 (car port-list)))))
11499 (insert "\n") (indent-to margin)))
11500 ;; align signal list
11501 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11502 (message "Pasting port as initializations...done")
5eabfe72
KH
11503 (setq vhdl-port-list orig-vhdl-port-list))))
11504
11505(defun vhdl-port-paste-testbench ()
3dcb36b7 11506 "Paste as a bare-bones testbench."
5eabfe72
KH
11507 (interactive)
11508 (if (not vhdl-port-list)
3dcb36b7 11509 (error "ERROR: No port read")
5eabfe72
KH
11510 (let ((case-fold-search t)
11511 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11512 (nth 0 vhdl-port-list)))
11513 (source-buffer (current-buffer))
3dcb36b7
JB
11514 arch-name config-name ent-file-name arch-file-name
11515 ent-buffer arch-buffer position)
5eabfe72 11516 ;; open entity file
3dcb36b7 11517 (unless (eq vhdl-testbench-create-files 'none)
5eabfe72 11518 (setq ent-file-name
0a2e512a
RF
11519 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11520 ent-name t)
11521 "." (file-name-extension (buffer-file-name))))
3dcb36b7 11522 (if (file-exists-p ent-file-name)
5eabfe72 11523 (if (y-or-n-p
3dcb36b7
JB
11524 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11525 (progn (find-file ent-file-name)
11526 (erase-buffer)
11527 (set-buffer-modified-p nil))
11528 (if (eq vhdl-testbench-create-files 'separate)
11529 (setq ent-file-name nil)
11530 (error "ERROR: Pasting port as testbench...aborted")))
11531 (find-file ent-file-name)))
11532 (unless (and (eq vhdl-testbench-create-files 'separate)
11533 (null ent-file-name))
11534 ;; paste entity header
11535 (if vhdl-testbench-include-header
11536 (progn (vhdl-template-header
11537 (concat "Testbench for design \""
11538 (nth 0 vhdl-port-list) "\""))
11539 (goto-char (point-max)))
11540 (vhdl-comment-display-line) (insert "\n\n"))
11541 ;; paste std_logic_1164 package
11542 (when vhdl-testbench-include-library
11543 (vhdl-template-package-std-logic-1164)
11544 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11545 ;; paste entity declaration
11546 (vhdl-insert-keyword "ENTITY ")
5eabfe72
KH
11547 (insert ent-name)
11548 (vhdl-insert-keyword " IS")
3dcb36b7 11549 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
5eabfe72 11550 (insert "\n")
3dcb36b7
JB
11551 (vhdl-insert-keyword "END ")
11552 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11553 (insert ent-name ";")
11554 (insert "\n\n")
11555 (vhdl-comment-display-line) (insert "\n"))
11556 ;; get architecture name
11557 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11558 (read-from-minibuffer "architecture name: "
11559 nil vhdl-minibuffer-local-map)
11560 (vhdl-replace-string vhdl-testbench-architecture-name
11561 (nth 0 vhdl-port-list))))
11562 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11563 ;; open architecture file
11564 (if (not (eq vhdl-testbench-create-files 'separate))
5eabfe72 11565 (insert "\n")
3dcb36b7
JB
11566 (setq ent-buffer (current-buffer))
11567 (setq arch-file-name
0a2e512a
RF
11568 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11569 (concat ent-name " " arch-name) t)
11570 "." (file-name-extension (buffer-file-name))))
3dcb36b7
JB
11571 (when (and (file-exists-p arch-file-name)
11572 (not (y-or-n-p (concat "File \"" arch-file-name
11573 "\" exists; overwrite? "))))
11574 (error "ERROR: Pasting port as testbench...aborted"))
11575 (find-file arch-file-name)
11576 (erase-buffer)
11577 (set-buffer-modified-p nil)
11578 ;; paste architecture header
11579 (if vhdl-testbench-include-header
11580 (progn (vhdl-template-header
11581 (concat "Testbench architecture for design \""
11582 (nth 0 vhdl-port-list) "\""))
11583 (goto-char (point-max)))
11584 (vhdl-comment-display-line) (insert "\n\n")))
11585 ;; paste architecture body
11586 (vhdl-insert-keyword "ARCHITECTURE ")
11587 (insert arch-name)
11588 (vhdl-insert-keyword " OF ")
11589 (insert ent-name)
11590 (vhdl-insert-keyword " IS")
11591 (insert "\n\n") (indent-to vhdl-basic-offset)
11592 ;; paste component declaration
11593 (unless (vhdl-use-direct-instantiation)
11594 (vhdl-port-paste-component t)
11595 (insert "\n\n") (indent-to vhdl-basic-offset))
11596 ;; paste constants
11597 (when (nth 1 vhdl-port-list)
11598 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11599 (vhdl-port-paste-constants t)
11600 (insert "\n\n") (indent-to vhdl-basic-offset))
11601 ;; paste internal signals
11602 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11603 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11604 (insert "\n")
11605 ;; paste custom declarations
11606 (unless (equal "" vhdl-testbench-declarations)
5eabfe72 11607 (insert "\n")
3dcb36b7
JB
11608 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11609 (setq position (point))
11610 (insert "\n\n")
11611 (vhdl-comment-display-line) (insert "\n")
11612 (when vhdl-testbench-include-configuration
11613 (setq config-name (vhdl-replace-string
11614 vhdl-testbench-configuration-name
11615 (concat ent-name " " arch-name)))
11616 (insert "\n")
11617 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11618 (vhdl-insert-keyword " OF ") (insert ent-name)
11619 (vhdl-insert-keyword " IS\n")
11620 (indent-to vhdl-basic-offset)
11621 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11622 (indent-to vhdl-basic-offset)
11623 (vhdl-insert-keyword "END FOR;\n")
11624 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11625 (vhdl-comment-display-line) (insert "\n"))
11626 (goto-char position)
11627 (vhdl-template-begin-end
11628 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11629 ;; paste instantiation
11630 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11631 (vhdl-port-paste-instance
11632 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11633 (insert "\n")
11634 ;; paste custom statements
11635 (unless (equal "" vhdl-testbench-statements)
11636 (insert "\n")
11637 (vhdl-insert-string-or-file vhdl-testbench-statements))
11638 (insert "\n")
11639 (indent-to vhdl-basic-offset)
11640 (unless (eq vhdl-testbench-create-files 'none)
11641 (setq arch-buffer (current-buffer))
11642 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11643 (set-buffer arch-buffer) (save-buffer))
29a4e67d 11644 (message "%s"
3dcb36b7
JB
11645 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11646 ent-name arch-name)
11647 (and ent-file-name
11648 (format "\n File created: \"%s\"" ent-file-name))
11649 (and arch-file-name
11650 (format "\n File created: \"%s\"" arch-file-name)))))))
5eabfe72
KH
11651
11652
11653;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11654;;; Subprogram interface translation
5eabfe72
KH
11655;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11656
3dcb36b7
JB
11657(defvar vhdl-subprog-list nil
11658 "Variable to hold last subprogram interface parsed.")
11659;; structure: (parenthesised expression means list of such entries)
11660;; (subprog-name kind
11661;; ((names) object direct type init comment group-comment)
11662;; return-type return-comment group-comment)
5eabfe72 11663
3dcb36b7
JB
11664(defvar vhdl-subprog-flattened nil
11665 "Indicates whether an subprogram interface has been flattened.")
5eabfe72 11666
3dcb36b7
JB
11667(defun vhdl-subprog-flatten ()
11668 "Flatten interface list so that only one parameter exists per line."
11669 (interactive)
11670 (if (not vhdl-subprog-list)
11671 (error "ERROR: No subprogram interface has been read")
11672 (message "Flattening subprogram interface...")
11673 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11674 new-subprog-list old-subprog new-subprog names)
11675 ;; traverse parameter list and flatten entries
11676 (while old-subprog-list
11677 (setq old-subprog (car old-subprog-list))
11678 (setq names (car old-subprog))
11679 (while names
11680 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11681 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11682 (setq names (cdr names)))
11683 (setq old-subprog-list (cdr old-subprog-list)))
11684 (setq vhdl-subprog-list
11685 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11686 new-subprog-list (nth 3 vhdl-subprog-list)
11687 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11688 vhdl-subprog-flattened t)
11689 (message "Flattening subprogram interface...done"))))
11690
11691(defun vhdl-subprog-copy ()
11692 "Get interface information from a subprogram specification."
11693 (interactive)
11694 (save-excursion
11695 (let (parse-error pos end-of-list
11696 name kind param-list object names direct type init
11697 comment group-comment
11698 return-type return-comment return-group-comment)
11699 (vhdl-prepare-search-2
11700 (setq
11701 parse-error
11702 (catch 'parse
11703 ;; check if within function declaration
11704 (setq pos (point))
11705 (end-of-line)
11706 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11707 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11708 (goto-char (match-end 0))
11709 (save-excursion (backward-char)
11710 (forward-sexp)
11711 (<= pos (point))))
11712 (throw 'parse "ERROR: Not within a subprogram specification"))
11713 (setq name (match-string-no-properties 5))
11714 (setq kind (if (match-string 2) 'procedure 'function))
11715 (setq end-of-list (not (match-string 7)))
11716 (message "Reading interface of subprogram \"%s\"..." name)
11717 ;; parse parameter list
11718 (setq group-comment (vhdl-parse-group-comment))
11719 (setq end-of-list (or end-of-list
11720 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11721 (while (not end-of-list)
11722 ;; parse object
11723 (setq object
11724 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11725 (match-string-no-properties 1)))
11726 ;; parse names (accept extended identifiers)
11727 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11728 (setq names (list (match-string-no-properties 1)))
11729 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11730 (setq names (append names (list (match-string-no-properties 1)))))
11731 ;; parse direction
11732 (vhdl-parse-string ":[ \t\n]*")
11733 (setq direct
11734 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11735 (match-string-no-properties 1)))
11736 ;; parse type
11737 (vhdl-parse-string "\\([^():;\n]+\\)")
11738 (setq type (match-string-no-properties 1))
11739 (setq comment nil)
11740 (while (looking-at "(")
11741 (setq type
11742 (concat type
11743 (buffer-substring-no-properties
11744 (point) (progn (forward-sexp) (point)))
11745 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11746 (match-string-no-properties 1)))))
11747 ;; special case: closing parenthesis is on separate line
11748 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11749 (setq comment (substring type (match-beginning 2)))
11750 (setq type (substring type 0 (match-beginning 1))))
11751 ;; strip off trailing group-comment
11752 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11753 (setq type (substring type 0 (match-end 1)))
11754 ;; parse initialization expression
11755 (setq init nil)
11756 (when (vhdl-parse-string ":=[ \t\n]*" t)
11757 (vhdl-parse-string "\\([^();\n]*\\)")
11758 (setq init (match-string-no-properties 1))
11759 (while (looking-at "(")
11760 (setq init
11761 (concat init
11762 (buffer-substring-no-properties
11763 (point) (progn (forward-sexp) (point)))
11764 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11765 (match-string-no-properties 1))))))
11766 ;; special case: closing parenthesis is on separate line
11767 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11768 (setq comment (substring init (match-beginning 2)))
11769 (setq init (substring init 0 (match-beginning 1)))
11770 (vhdl-forward-syntactic-ws))
11771 (skip-chars-forward " \t")
11772 ;; parse inline comment, special case: as above, no initial.
11773 (unless comment
11774 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11775 (match-string-no-properties 1))))
11776 (vhdl-forward-syntactic-ws)
11777 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11778 ;; parse inline comment
11779 (unless comment
11780 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11781 (match-string-no-properties 1))))
11782 (setq return-group-comment (vhdl-parse-group-comment))
11783 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11784 ;; parse return type
11785 (when (match-string 3)
11786 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11787 (setq return-type (match-string-no-properties 1))
11788 (when (and return-type
11789 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11790 (setq return-comment (substring return-type (match-beginning 2)))
11791 (setq return-type (substring return-type 0 (match-beginning 1))))
11792 ;; strip of trailing group-comment
11793 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11794 (setq return-type (substring return-type 0 (match-end 1)))
11795 ;; parse return comment
11796 (unless return-comment
11797 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11798 (match-string-no-properties 1)))))
11799 ;; parse inline comment
11800 (unless comment
11801 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11802 (match-string-no-properties 1))))
11803 ;; save everything in list
11804 (setq param-list (append param-list
11805 (list (list names object direct type init
11806 comment group-comment))))
11807 ;; parse group comment and spacing
11808 (setq group-comment (vhdl-parse-group-comment)))
11809 (message "Reading interface of subprogram \"%s\"...done" name)
11810 nil)))
11811 ;; finish parsing
11812 (if parse-error
11813 (error parse-error)
11814 (setq vhdl-subprog-list
11815 (list name kind param-list return-type return-comment
11816 return-group-comment)
11817 vhdl-subprog-flattened nil)))))
11818
11819(defun vhdl-subprog-paste-specification (kind)
11820 "Paste as a subprogram specification."
11821 (indent-according-to-mode)
11822 (let ((margin (current-column))
11823 (param-list (nth 2 vhdl-subprog-list))
11824 list-margin start names param)
11825 ;; paste keyword and name
11826 (vhdl-insert-keyword
11827 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11828 (insert (nth 0 vhdl-subprog-list))
11829 (if (not param-list)
11830 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11831 (setq start (point))
11832 ;; paste parameter list
11833 (insert " (")
11834 (unless vhdl-argument-list-indent
11835 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11836 (setq list-margin (current-column))
11837 (while param-list
11838 (setq param (car param-list))
11839 ;; paste group comment and spacing
11840 (when (memq vhdl-include-group-comments (list kind 'always))
11841 (vhdl-paste-group-comment (nth 6 param) list-margin))
11842 ;; paste object
11843 (when (nth 1 param) (insert (nth 1 param) " "))
11844 ;; paste names
11845 (setq names (nth 0 param))
11846 (while names
11847 (insert (car names))
11848 (setq names (cdr names))
11849 (when names (insert ", ")))
11850 ;; paste direction
11851 (insert " : ")
11852 (when (nth 2 param) (insert (nth 2 param) " "))
11853 ;; paste type
11854 (insert (nth 3 param))
11855 ;; paste initialization
11856 (when (nth 4 param) (insert " := " (nth 4 param)))
11857 ;; terminate line
11858 (if (cdr param-list)
11859 (insert ";")
11860 (insert ")")
11861 (when (null (nth 3 vhdl-subprog-list))
11862 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11863 ;; paste comment
11864 (when (and vhdl-include-port-comments (nth 5 param))
11865 (vhdl-comment-insert-inline (nth 5 param) t))
11866 (setq param-list (cdr param-list))
11867 (when param-list (insert "\n") (indent-to list-margin)))
11868 (when (nth 3 vhdl-subprog-list)
11869 (insert "\n") (indent-to list-margin)
11870 ;; paste group comment and spacing
11871 (when (memq vhdl-include-group-comments (list kind 'always))
11872 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11873 ;; paste return type
11874 (insert "return " (nth 3 vhdl-subprog-list))
0a2e512a 11875 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
3dcb36b7
JB
11876 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11877 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11878 ;; align parameter list
11879 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11880 ;; paste body
11881 (when (eq kind 'body)
11882 (insert "\n")
11883 (vhdl-template-begin-end
11884 (unless (vhdl-standard-p '87)
11885 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11886 (nth 0 vhdl-subprog-list) margin))))
11887
11888(defun vhdl-subprog-paste-declaration ()
11889 "Paste as a subprogram declaration."
11890 (interactive)
11891 (if (not vhdl-subprog-list)
11892 (error "ERROR: No subprogram interface read")
11893 (message "Pasting interface as subprogram declaration \"%s\"..."
11894 (car vhdl-subprog-list))
11895 ;; paste specification
11896 (vhdl-subprog-paste-specification 'decl)
11897 (message "Pasting interface as subprogram declaration \"%s\"...done"
11898 (car vhdl-subprog-list))))
11899
11900(defun vhdl-subprog-paste-body ()
11901 "Paste as a subprogram body."
11902 (interactive)
11903 (if (not vhdl-subprog-list)
11904 (error "ERROR: No subprogram interface read")
11905 (message "Pasting interface as subprogram body \"%s\"..."
11906 (car vhdl-subprog-list))
11907 ;; paste specification and body
11908 (vhdl-subprog-paste-specification 'body)
11909 (message "Pasting interface as subprogram body \"%s\"...done"
11910 (car vhdl-subprog-list))))
11911
11912(defun vhdl-subprog-paste-call ()
11913 "Paste as a subprogram call."
11914 (interactive)
11915 (if (not vhdl-subprog-list)
11916 (error "ERROR: No subprogram interface read")
11917 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11918 param-list margin list-margin param start)
11919 ;; flatten local copy of interface list (must be flat for parameter mapping)
11920 (vhdl-subprog-flatten)
11921 (setq param-list (nth 2 vhdl-subprog-list))
11922 (indent-according-to-mode)
11923 (setq margin (current-indentation))
11924 (message "Pasting interface as subprogram call \"%s\"..."
11925 (car vhdl-subprog-list))
11926 ;; paste name
11927 (insert (nth 0 vhdl-subprog-list))
11928 (if (not param-list)
11929 (insert ";")
11930 (setq start (point))
11931 ;; paste parameter list
11932 (insert " (")
11933 (unless vhdl-argument-list-indent
11934 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11935 (setq list-margin (current-column))
11936 (while param-list
11937 (setq param (car param-list))
11938 ;; paste group comment and spacing
11939 (when (eq vhdl-include-group-comments 'always)
11940 (vhdl-paste-group-comment (nth 6 param) list-margin))
11941 ;; paste formal port
11942 (insert (car (nth 0 param)) " => ")
11943 (setq param-list (cdr param-list))
11944 (insert (if param-list "," ");"))
11945 ;; paste comment
11946 (when (and vhdl-include-port-comments (nth 5 param))
11947 (vhdl-comment-insert-inline (nth 5 param)))
11948 (when param-list (insert "\n") (indent-to list-margin)))
11949 ;; align parameter list
11950 (when vhdl-auto-align
11951 (vhdl-align-region-groups start (point) 1)))
11952 (message "Pasting interface as subprogram call \"%s\"...done"
11953 (car vhdl-subprog-list))
11954 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11955
11956
11957;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11958;;; Miscellaneous
11959;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11960
11961;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11962;; Hippie expand customization
11963
11964(defvar vhdl-expand-upper-case nil)
11965
11966(defun vhdl-try-expand-abbrev (old)
11967 "Try expanding abbreviations from `vhdl-abbrev-list'."
11968 (unless old
11969 (he-init-string (he-dabbrev-beg) (point))
5eabfe72
KH
11970 (setq he-expand-list
11971 (let ((abbrev-list vhdl-abbrev-list)
11972 (sel-abbrev-list '()))
11973 (while abbrev-list
11974 (when (or (not (stringp (car abbrev-list)))
11975 (string-match
11976 (concat "^" he-search-string) (car abbrev-list)))
11977 (setq sel-abbrev-list
11978 (cons (car abbrev-list) sel-abbrev-list)))
11979 (setq abbrev-list (cdr abbrev-list)))
11980 (nreverse sel-abbrev-list))))
11981 (while (and he-expand-list
11982 (or (not (stringp (car he-expand-list)))
11983 (he-string-member (car he-expand-list) he-tried-table t)))
11984; (equal (car he-expand-list) he-search-string)))
11985 (unless (stringp (car he-expand-list))
11986 (setq vhdl-expand-upper-case (car he-expand-list)))
11987 (setq he-expand-list (cdr he-expand-list)))
11988 (if (null he-expand-list)
11989 (progn (when old (he-reset-string))
11990 nil)
11991 (he-substitute-string
11992 (if vhdl-expand-upper-case
11993 (upcase (car he-expand-list))
11994 (car he-expand-list))
11995 t)
11996 (setq he-expand-list (cdr he-expand-list))
11997 t))
11998
11999(defun vhdl-he-list-beg ()
12000 "Also looks at the word before `(' in order to better match parenthesized
12001expressions (e.g. for index ranges of types and signals)."
12002 (save-excursion
12003 (condition-case ()
12004 (progn (backward-up-list 1)
12005 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12006 (error ()))
12007 (point)))
12008
12009;; override `he-list-beg' from `hippie-exp'
12010(unless (and (boundp 'viper-mode) viper-mode)
5eabfe72
KH
12011 (defalias 'he-list-beg 'vhdl-he-list-beg))
12012
12013;; function for expanding abbrevs and dabbrevs
3dcb36b7 12014(defun vhdl-expand-abbrev (arg))
5eabfe72
KH
12015(fset 'vhdl-expand-abbrev (make-hippie-expand-function
12016 '(try-expand-dabbrev
12017 try-expand-dabbrev-all-buffers
12018 vhdl-try-expand-abbrev)))
12019
12020;; function for expanding parenthesis
3dcb36b7 12021(defun vhdl-expand-paren (arg))
5eabfe72
KH
12022(fset 'vhdl-expand-paren (make-hippie-expand-function
12023 '(try-expand-list
12024 try-expand-list-all-buffers)))
12025
12026;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12027;; Case fixing
d2ddb974
KH
12028
12029(defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
a4c6cfad
JB
12030 "Convert all words matching WORD-REGEXP in region to lower or upper case,
12031depending on parameter UPPER-CASE."
3dcb36b7 12032 (let ((case-replace nil)
5eabfe72 12033 (last-update 0))
3dcb36b7 12034 (vhdl-prepare-search-2
5eabfe72
KH
12035 (save-excursion
12036 (goto-char end)
12037 (setq end (point-marker))
12038 (goto-char beg)
12039 (while (re-search-forward word-regexp end t)
3dcb36b7 12040 (or (vhdl-in-literal)
5eabfe72
KH
12041 (if upper-case
12042 (upcase-word -1)
12043 (downcase-word -1)))
3dcb36b7 12044 (when (and count vhdl-progress-interval (not noninteractive)
5eabfe72
KH
12045 (< vhdl-progress-interval
12046 (- (nth 1 (current-time)) last-update)))
12047 (message "Fixing case... (%2d%s)"
12048 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12049 "%")
12050 (setq last-update (nth 1 (current-time)))))
3dcb36b7 12051 (goto-char end)))))
d2ddb974
KH
12052
12053(defun vhdl-fix-case-region (beg end &optional arg)
12054 "Convert all VHDL words in region to lower or upper case, depending on
3dcb36b7 12055options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974
KH
12056 (interactive "r\nP")
12057 (vhdl-fix-case-region-1
5eabfe72 12058 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
d2ddb974 12059 (vhdl-fix-case-region-1
5eabfe72 12060 beg end vhdl-upper-case-types vhdl-types-regexp 1)
d2ddb974 12061 (vhdl-fix-case-region-1
5eabfe72
KH
12062 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12063 (vhdl-fix-case-region-1
3dcb36b7
JB
12064 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12065 (when vhdl-progress-interval (message "Fixing case...done")))
d2ddb974 12066
5eabfe72
KH
12067(defun vhdl-fix-case-buffer ()
12068 "Convert all VHDL words in buffer to lower or upper case, depending on
3dcb36b7 12069options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974 12070 (interactive)
5eabfe72
KH
12071 (vhdl-fix-case-region (point-min) (point-max)))
12072
3dcb36b7
JB
12073(defun vhdl-fix-case-word (&optional arg)
12074 "Convert word after cursor to upper case if necessary."
12075 (interactive "p")
12076 (save-excursion
12077 (when arg (backward-word 1))
12078 (vhdl-prepare-search-1
12079 (when (and vhdl-upper-case-keywords
12080 (looking-at vhdl-keywords-regexp))
12081 (upcase-word 1))
12082 (when (and vhdl-upper-case-types
12083 (looking-at vhdl-types-regexp))
12084 (upcase-word 1))
12085 (when (and vhdl-upper-case-attributes
12086 (looking-at vhdl-attributes-regexp))
12087 (upcase-word 1))
12088 (when (and vhdl-upper-case-enum-values
12089 (looking-at vhdl-enum-values-regexp))
12090 (upcase-word 1)))))
12091
5eabfe72
KH
12092;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12093;; Line handling functions
d2ddb974
KH
12094
12095(defun vhdl-current-line ()
12096 "Return the line number of the line containing point."
12097 (save-restriction
12098 (widen)
9b026d9f 12099 (1+ (count-lines (point-min) (point-at-bol)))))
d2ddb974 12100
5eabfe72 12101(defun vhdl-line-kill-entire (&optional arg)
d2ddb974 12102 "Delete entire line."
5eabfe72
KH
12103 (interactive "p")
12104 (beginning-of-line)
12105 (kill-line (or arg 1)))
12106
12107(defun vhdl-line-kill (&optional arg)
12108 "Kill current line."
12109 (interactive "p")
12110 (vhdl-line-kill-entire arg))
12111
12112(defun vhdl-line-copy (&optional arg)
12113 "Copy current line."
12114 (interactive "p")
12115 (save-excursion
9b026d9f 12116 (let ((position (point-at-bol)))
5eabfe72
KH
12117 (forward-line (or arg 1))
12118 (copy-region-as-kill position (point)))))
12119
12120(defun vhdl-line-yank ()
12121 "Yank entire line."
d2ddb974 12122 (interactive)
5eabfe72
KH
12123 (beginning-of-line)
12124 (yank))
d2ddb974 12125
5eabfe72
KH
12126(defun vhdl-line-expand (&optional prefix-arg)
12127 "Hippie-expand current line."
12128 (interactive "P")
12129 (let ((case-fold-search t) (case-replace nil)
12130 (hippie-expand-try-functions-list
12131 '(try-expand-line try-expand-line-all-buffers)))
12132 (hippie-expand prefix-arg)))
12133
12134(defun vhdl-line-transpose-next (&optional arg)
12135 "Interchange this line with next line."
12136 (interactive "p")
12137 (forward-line 1)
12138 (transpose-lines (or arg 1))
12139 (forward-line -1))
12140
12141(defun vhdl-line-transpose-previous (&optional arg)
12142 "Interchange this line with previous line."
12143 (interactive "p")
12144 (forward-line 1)
12145 (transpose-lines (- 0 (or arg 0)))
12146 (forward-line -1))
12147
12148(defun vhdl-line-open ()
d2ddb974
KH
12149 "Open a new line and indent."
12150 (interactive)
5eabfe72
KH
12151 (end-of-line -0)
12152 (newline-and-indent))
d2ddb974 12153
3dcb36b7
JB
12154(defun vhdl-delete-indentation ()
12155 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12156it works within comments too."
12157 (interactive)
12158 (let ((fill-prefix "-- "))
12159 (delete-indentation)))
d2ddb974 12160
5eabfe72 12161;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12162;; Move functions
d2ddb974 12163
3dcb36b7
JB
12164(defun vhdl-forward-same-indent ()
12165 "Move forward to next line with same indent."
12166 (interactive)
12167 (let ((pos (point))
12168 (indent (current-indentation)))
12169 (beginning-of-line 2)
12170 (while (and (not (eobp))
12171 (or (looking-at "^\\s-*\\(--.*\\)?$")
12172 (> (current-indentation) indent)))
12173 (beginning-of-line 2))
12174 (if (= (current-indentation) indent)
12175 (back-to-indentation)
12176 (message "No following line with same indent found in this block")
12177 (goto-char pos)
12178 nil)))
5eabfe72 12179
3dcb36b7
JB
12180(defun vhdl-backward-same-indent ()
12181 "Move backward to previous line with same indent."
12182 (interactive)
12183 (let ((pos (point))
12184 (indent (current-indentation)))
12185 (beginning-of-line -0)
12186 (while (and (not (bobp))
12187 (or (looking-at "^\\s-*\\(--.*\\)?$")
12188 (> (current-indentation) indent)))
12189 (beginning-of-line -0))
12190 (if (= (current-indentation) indent)
12191 (back-to-indentation)
12192 (message "No preceding line with same indent found in this block")
12193 (goto-char pos)
12194 nil)))
5eabfe72
KH
12195
12196;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
12197;; Statistics
12198
12199(defun vhdl-statistics-buffer ()
12200 "Get some file statistics."
12201 (interactive)
12202 (let ((no-stats 0)
12203 (no-code-lines 0)
12204 (no-lines (count-lines (point-min) (point-max))))
12205 (save-excursion
12206 ;; count statements
12207 (goto-char (point-min))
12208 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12209 (if (match-string 1)
12210 (goto-char (match-end 1))
12211 (setq no-stats (1+ no-stats))))
12212 ;; count code lines
12213 (goto-char (point-min))
12214 (while (not (eobp))
12215 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12216 (setq no-code-lines (1+ no-code-lines)))
12217 (beginning-of-line 2)))
12218 ;; print results
12219 (message "\n\
12220File statistics: \"%s\"\n\
12221---------------------\n\
12222# statements : %5d\n\
12223# code lines : %5d\n\
12224# total lines : %5d\n\ "
0a2e512a
RF
12225 (buffer-file-name) no-stats no-code-lines no-lines)
12226 (unless vhdl-emacs-21 (vhdl-show-messages))))
3dcb36b7 12227
5eabfe72 12228;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12229;; Help functions
d2ddb974 12230
3dcb36b7
JB
12231(defun vhdl-re-search-forward (regexp &optional bound noerror count)
12232 "Like `re-search-forward', but does not match within literals."
12233 (let (pos)
12234 (save-excursion
12235 (while (and (setq pos (re-search-forward regexp bound noerror count))
12236 (vhdl-in-literal))))
12237 (when pos (goto-char pos))
12238 pos))
12239
12240(defun vhdl-re-search-backward (regexp &optional bound noerror count)
12241 "Like `re-search-backward', but does not match within literals."
12242 (let (pos)
12243 (save-excursion
12244 (while (and (setq pos (re-search-backward regexp bound noerror count))
12245 (vhdl-in-literal))))
12246 (when pos (goto-char pos))
12247 pos))
5eabfe72 12248
d2ddb974 12249
3dcb36b7
JB
12250;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12251;;; Project
12252;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12253
12254(defun vhdl-set-project (name)
12255 "Set current project to NAME."
12256 (interactive
12257 (list (let ((completion-ignore-case t))
12258 (completing-read "Project name: " vhdl-project-alist nil t))))
12259 (cond ((equal name "")
12260 (setq vhdl-project nil)
12261 (message "Current VHDL project: None"))
12262 ((assoc name vhdl-project-alist)
12263 (setq vhdl-project name)
12264 (message "Current VHDL project: \"%s\"" name))
12265 (t
12266 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12267 (vhdl-speedbar-update-current-project))
12268
0a2e512a
RF
12269(defun vhdl-set-default-project ()
12270 "Set current project as default on startup."
12271 (interactive)
12272 (customize-set-variable 'vhdl-project vhdl-project)
12273 (customize-save-customized))
12274
3dcb36b7
JB
12275(defun vhdl-toggle-project (name token indent)
12276 "Set current project to NAME or unset if NAME is current project."
12277 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12278
12279(defun vhdl-export-project (file-name)
12280 "Write project setup for current project."
12281 (interactive
12282 (let ((name (vhdl-resolve-env-variable
12283 (vhdl-replace-string
12284 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12285 (concat (subst-char-in-string
12286 ? ?_ (or (vhdl-project-p)
12287 (error "ERROR: No current project")))
12288 " " (user-login-name))))))
12289 (list (read-file-name
12290 "Write project file: "
12291 (when (file-name-absolute-p name) "") nil nil name))))
12292 (setq file-name (abbreviate-file-name file-name))
12293 (let ((orig-buffer (current-buffer)))
12294 (unless (file-exists-p (file-name-directory file-name))
12295 (make-directory (file-name-directory file-name) t))
12296 (if (not (file-writable-p file-name))
12297 (error "ERROR: File not writable: \"%s\"" file-name)
12298 (set-buffer (find-file-noselect file-name t t))
12299 (erase-buffer)
12300 (insert ";; -*- Emacs-Lisp -*-\n\n"
12301 ";;; " (file-name-nondirectory file-name)
12302 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12303 ";; Project : " vhdl-project "\n"
12304 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12305 (user-login-name) "\n\n\n"
12306 ";; project name\n"
12307 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12308 ";; project setup\n"
12309 "(aput 'vhdl-project-alist vhdl-project\n'")
12310 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12311 (insert ")\n")
12312 (save-buffer)
12313 (kill-buffer (current-buffer))
12314 (set-buffer orig-buffer))))
12315
12316(defun vhdl-import-project (file-name &optional auto not-make-current)
12317 "Read project setup and set current project."
12318 (interactive
12319 (let ((name (vhdl-resolve-env-variable
12320 (vhdl-replace-string
12321 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12322 (concat "" " " (user-login-name))))))
12323 (list (read-file-name
12324 "Read project file: " (when (file-name-absolute-p name) "") nil t
12325 (file-name-directory name)))))
12326 (when (file-exists-p file-name)
12327 (condition-case ()
12328 (let ((current-project vhdl-project))
12329 (load-file file-name)
12330 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12331 (adelete 'vhdl-project-alist vhdl-project)
0a2e512a 12332 (error ""))
3dcb36b7
JB
12333 (when not-make-current
12334 (setq vhdl-project current-project))
12335 (vhdl-update-mode-menu)
12336 (vhdl-speedbar-refresh)
12337 (unless not-make-current
12338 (message "Current VHDL project: \"%s\"%s"
12339 vhdl-project (if auto " (auto-loaded)" ""))))
12340 (error (vhdl-warning
12341 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12342
12343(defun vhdl-duplicate-project ()
12344 "Duplicate setup of current project."
5eabfe72 12345 (interactive)
3dcb36b7
JB
12346 (let ((new-name (read-from-minibuffer "New project name: "))
12347 (project-entry (aget vhdl-project-alist vhdl-project t)))
12348 (setq vhdl-project-alist
12349 (append vhdl-project-alist
12350 (list (cons new-name project-entry))))
12351 (vhdl-update-mode-menu)))
12352
12353(defun vhdl-auto-load-project ()
12354 "Automatically load project setup at startup."
12355 (let ((file-name-list vhdl-project-file-name)
12356 file-list list-length)
12357 (while file-name-list
12358 (setq file-list
12359 (append file-list
12360 (file-expand-wildcards
12361 (vhdl-resolve-env-variable
12362 (vhdl-replace-string
12363 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12364 (concat "\*" " " (user-login-name)))))))
12365 (setq list-length (or list-length (length file-list)))
12366 (setq file-name-list (cdr file-name-list)))
12367 (while file-list
12368 (vhdl-import-project (expand-file-name (car file-list)) t
12369 (not (> list-length 0)))
12370 (setq list-length (1- list-length))
12371 (setq file-list (cdr file-list)))))
12372
12373;; automatically load project setup when idle after startup
12374(when (memq 'startup vhdl-project-auto-load)
12375 (if noninteractive
12376 (vhdl-auto-load-project)
12377 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
5eabfe72
KH
12378
12379
12380;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12381;;; Hideshow
12382;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12383;; (using `hideshow.el')
d2ddb974 12384
3dcb36b7
JB
12385(defconst vhdl-hs-start-regexp
12386 (concat
12387 "\\(^\\)\\s-*\\("
12388 ;; generic/port clause
12389 "\\(generic\\|port\\)[ \t\n]*(\\|"
12390 ;; component
12391 "component\\>\\|"
12392 ;; component instantiation
12393 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12394 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12395 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12396 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12397 ;; subprogram
12398 "\\(function\\|procedure\\)\\>\\|"
12399 ;; process, block
12400 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12401 ;; configuration declaration
12402 "configuration\\>"
12403 "\\)")
12404 "Regexp to match start of construct to hide.")
12405
12406(defun vhdl-hs-forward-sexp-func (count)
a4c6cfad 12407 "Find end of construct to hide (for hideshow). Only searches forward."
3dcb36b7
JB
12408 (let ((pos (point)))
12409 (vhdl-prepare-search-2
12410 (beginning-of-line)
12411 (cond
12412 ;; generic/port clause
12413 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12414 (goto-char (match-end 0))
12415 (backward-char)
12416 (forward-sexp))
12417 ;; component declaration
12418 ((looking-at "^\\s-*component\\>")
12419 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12420 ;; component instantiation
12421 ((looking-at
12422 (concat
12423 "^\\s-*\\w+\\s-*:[ \t\n]*"
12424 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12425 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12426 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12427 (goto-char (match-end 0))
12428 (backward-char)
12429 (forward-sexp)
12430 (setq pos (point))
12431 (vhdl-forward-syntactic-ws)
12432 (when (looking-at "port\\s-+map[ \t\n]*(")
12433 (goto-char (match-end 0))
12434 (backward-char)
12435 (forward-sexp)
12436 (setq pos (point)))
12437 (goto-char pos))
12438 ;; subprogram declaration/body
12439 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12440 (goto-char (match-end 0))
12441 (vhdl-forward-syntactic-ws)
12442 (when (looking-at "(")
12443 (forward-sexp))
12444 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12445 (vhdl-in-literal)))
12446 ;; subprogram body
12447 (when (match-string 2)
12448 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12449 (backward-word 1)
12450 (vhdl-forward-sexp)))
12451 ;; block (recursive)
12452 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12453 (goto-char (match-end 0))
12454 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12455 (match-beginning 2))
12456 (vhdl-hs-forward-sexp-func count)))
12457 ;; process
12458 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12459 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12460 ;; configuration declaration
12461 ((looking-at "^\\s-*configuration\\>")
12462 (forward-word 4)
12463 (vhdl-forward-sexp))
12464 (t (goto-char pos))))))
5eabfe72
KH
12465
12466(defun vhdl-hideshow-init ()
12467 "Initialize `hideshow'."
3dcb36b7
JB
12468 (when vhdl-hideshow-menu
12469 (vhdl-hs-minor-mode 1)))
12470
12471(defun vhdl-hs-minor-mode (&optional arg)
12472 "Toggle hideshow minor mode and update menu bar."
12473 (interactive "P")
12474 (require 'hideshow)
12475 ;; check for hideshow version 5.x
12476 (if (not (boundp 'hs-block-start-mdata-select))
12477 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12478 ;; initialize hideshow
12479 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12480 (setq hs-special-modes-alist
12481 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12482 'vhdl-hs-forward-sexp-func nil)
12483 hs-special-modes-alist)))
175069ef 12484 (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
3dcb36b7 12485 (if vhdl-hide-all-init
175069ef
SM
12486 (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
12487 (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
3dcb36b7 12488 (hs-minor-mode arg)
56eb0904 12489 (force-mode-line-update))) ; hack to update menu bar
5eabfe72
KH
12490
12491
12492;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12493;;; Font locking
12494;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12495;; (using `font-lock.el')
12496
5eabfe72 12497;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12498;; Help functions
5eabfe72
KH
12499
12500(defun vhdl-within-translate-off ()
12501 "Return point if within translate-off region, else nil."
12502 (and (save-excursion
12503 (re-search-backward
12504 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12505 (equal "off" (match-string 1))
12506 (point)))
12507
12508(defun vhdl-start-translate-off (limit)
12509 "Return point before translate-off pragma if before LIMIT, else nil."
12510 (when (re-search-forward
12511 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12512 (match-beginning 0)))
12513
12514(defun vhdl-end-translate-off (limit)
12515 "Return point after translate-on pragma if before LIMIT, else nil."
12516 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12517
12518(defun vhdl-match-translate-off (limit)
12519 "Match a translate-off block, setting match-data and returning t, else nil."
12520 (when (< (point) limit)
12521 (let ((start (or (vhdl-within-translate-off)
12522 (vhdl-start-translate-off limit)))
12523 (case-fold-search t))
12524 (when start
12525 (let ((end (or (vhdl-end-translate-off limit) limit)))
12526 (set-match-data (list start end))
12527 (goto-char end))))))
12528
12529(defun vhdl-font-lock-match-item (limit)
a4c6cfad 12530 "Match, and move over, any declaration item after point. Adapted from
5eabfe72
KH
12531`font-lock-match-c-style-declaration-item-and-skip-to-next'."
12532 (condition-case nil
12533 (save-restriction
12534 (narrow-to-region (point-min) limit)
12535 ;; match item
3dcb36b7 12536 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5eabfe72
KH
12537 (save-match-data
12538 (goto-char (match-end 1))
12539 ;; move to next item
0a2e512a
RF
12540 (if (looking-at "\\(\\s-*,\\)")
12541 (goto-char (match-end 1))
5eabfe72
KH
12542 (end-of-line) t))))
12543 (error t)))
12544
12545;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12546;; Syntax definitions
12547
5eabfe72
KH
12548(defconst vhdl-font-lock-syntactic-keywords
12549 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12550 "Mark single quotes as having string quote syntax in 'c' instances.")
12551
d2ddb974
KH
12552(defvar vhdl-font-lock-keywords nil
12553 "Regular expressions to highlight in VHDL Mode.")
12554
3dcb36b7
JB
12555(defvar vhdl-font-lock-keywords-0
12556 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12557 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12558This does highlighting of template prompts and directives (pragmas).")
d2ddb974 12559
5eabfe72 12560(defvar vhdl-font-lock-keywords-1 nil
3dcb36b7 12561 ;; set in `vhdl-font-lock-init' because dependent on user options
5eabfe72
KH
12562 "For consideration as a value of `vhdl-font-lock-keywords'.
12563This does highlighting of keywords and standard identifiers.")
12564
12565(defconst vhdl-font-lock-keywords-2
d2ddb974
KH
12566 (list
12567 ;; highlight names of units, subprograms, and components when declared
12568 (list
12569 (concat
12570 "^\\s-*\\("
3dcb36b7
JB
12571 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12572 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
d2ddb974 12573 "\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12574 5 'font-lock-function-name-face)
12575
12576 ;; highlight entity names of architectures and configurations
12577 (list
12578 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12579 2 'font-lock-function-name-face)
d2ddb974
KH
12580
12581 ;; highlight labels of common constructs
12582 (list
12583 (concat
3dcb36b7
JB
12584 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12585 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12586 "postponed\\|process\\|"
5eabfe72
KH
12587 (when (vhdl-standard-p 'ams) "procedural\\|")
12588 "with\\|while"
0a2e512a 12589 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
d2ddb974
KH
12590 1 'font-lock-function-name-face)
12591
5eabfe72 12592 ;; highlight label and component name of component instantiations
d2ddb974 12593 (list
5eabfe72 12594 (concat
3dcb36b7
JB
12595 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12596 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12597 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12598
12599 ;; highlight label and instantiated unit of component instantiations
12600 (list
12601 (concat
12602 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12603 "\\(component\\|configuration\\|entity\\)\\s-+"
12604 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12605 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12606 '(5 font-lock-function-name-face nil t)
12607 '(7 font-lock-function-name-face nil t))
d2ddb974
KH
12608
12609 ;; highlight names and labels at end of constructs
12610 (list
12611 (concat
5eabfe72
KH
12612 "^\\s-*end\\s-+\\(\\("
12613 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
3dcb36b7
JB
12614 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12615 "procedure\\|\\(postponed\\s-+\\)?process\\|"
5eabfe72
KH
12616 (when (vhdl-standard-p 'ams) "procedural\\|")
12617 "units"
3dcb36b7 12618 "\\)\\s-+\\)?\\(\\w*\\)")
5eabfe72
KH
12619 5 'font-lock-function-name-face)
12620
12621 ;; highlight labels in exit and next statements
12622 (list
12623 (concat
12624 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12625 3 'font-lock-function-name-face)
12626
12627 ;; highlight entity name in attribute specifications
12628 (list
12629 (concat
12630 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12631 1 'font-lock-function-name-face)
12632
3dcb36b7
JB
12633 ;; highlight labels in block and component specifications
12634 (list
12635 (concat
12636 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12637 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12638 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12639
12640 ;; highlight names in library clauses
12641 (list "^\\s-*library\\>"
12642 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12643
12644 ;; highlight names in use clauses
5eabfe72
KH
12645 (list
12646 (concat
3dcb36b7
JB
12647 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12648 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12649 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12650 '(7 font-lock-function-name-face nil t))
5eabfe72
KH
12651
12652 ;; highlight attribute name in attribute declarations/specifications
12653 (list
12654 (concat
12655 "^\\s-*attribute\\s-+\\(\\w+\\)")
0a2e512a 12656 1 'vhdl-font-lock-attribute-face)
5eabfe72
KH
12657
12658 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12659 (list
12660 (concat
3dcb36b7 12661 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12662 3 'font-lock-type-face)
12663
12664 ;; highlight signal/variable/constant declaration names
12665 (list "\\(:[^=]\\)"
12666 '(vhdl-font-lock-match-item
12667 (progn (goto-char (match-beginning 1))
12668 (skip-syntax-backward " ")
12669 (skip-syntax-backward "w_")
12670 (skip-syntax-backward " ")
12671 (while (= (preceding-char) ?,)
12672 (backward-char 1)
12673 (skip-syntax-backward " ")
12674 (skip-syntax-backward "w_")
12675 (skip-syntax-backward " ")))
12676; (skip-chars-backward "^-(\n\";")
12677 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12678
3dcb36b7
JB
12679 ;; highlight formal parameters in component instantiations and subprogram
12680 ;; calls
12681 (list "\\(=>\\)"
12682 '(vhdl-font-lock-match-item
12683 (progn (goto-char (match-beginning 1))
12684 (skip-syntax-backward " ")
12685 (while (= (preceding-char) ?\)) (backward-sexp))
12686 (skip-syntax-backward "w_")
12687 (skip-syntax-backward " ")
0a2e512a 12688 (when (memq (preceding-char) '(?n ?N ?|))
3dcb36b7
JB
12689 (goto-char (point-max))))
12690 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12691
12692 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12693 ;; variables
12694 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
5eabfe72
KH
12695 '(vhdl-font-lock-match-item
12696 (progn (goto-char (match-end 1)) (match-beginning 2))
12697 nil (1 font-lock-variable-name-face)))
d2ddb974 12698 )
5eabfe72
KH
12699 "For consideration as a value of `vhdl-font-lock-keywords'.
12700This does context sensitive highlighting of names and labels.")
d2ddb974 12701
5eabfe72 12702(defvar vhdl-font-lock-keywords-3 nil
3dcb36b7 12703 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12704 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72
KH
12705This does highlighting of words with special syntax.")
12706
12707(defvar vhdl-font-lock-keywords-4 nil
3dcb36b7 12708 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12709 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12710This does highlighting of additional reserved words.")
d2ddb974 12711
5eabfe72
KH
12712(defconst vhdl-font-lock-keywords-5
12713 ;; background highlight translate-off regions
0a2e512a 12714 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
5eabfe72
KH
12715 "For consideration as a value of `vhdl-font-lock-keywords'.
12716This does background highlighting of translate-off regions.")
12717
12718;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12719;; Font and color definitions
12720
0a2e512a 12721(defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
d2ddb974
KH
12722 "Face name to use for prompts.")
12723
0a2e512a 12724(defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
5eabfe72
KH
12725 "Face name to use for standardized attributes.")
12726
0a2e512a 12727(defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
5eabfe72 12728 "Face name to use for standardized enumeration values.")
d2ddb974 12729
0a2e512a 12730(defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
5eabfe72 12731 "Face name to use for standardized functions and packages.")
d2ddb974 12732
0a2e512a 12733(defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
5eabfe72 12734 "Face name to use for directives.")
d2ddb974 12735
0a2e512a 12736(defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
5eabfe72 12737 "Face name to use for additional reserved words.")
d2ddb974 12738
0a2e512a 12739(defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
5eabfe72 12740 "Face name to use for translate-off regions.")
d2ddb974 12741
5eabfe72
KH
12742;; face names to use for words with special syntax.
12743(let ((syntax-alist vhdl-special-syntax-alist)
12744 name)
12745 (while syntax-alist
0a2e512a
RF
12746 (setq name (vhdl-function-name
12747 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
d4a5b644
GM
12748 (eval `(defvar ,name ',name
12749 ,(concat "Face name to use for "
12750 (nth 0 (car syntax-alist)) ".")))
5eabfe72
KH
12751 (setq syntax-alist (cdr syntax-alist))))
12752
3dcb36b7 12753(defgroup vhdl-highlight-faces nil
5eabfe72
KH
12754 "Faces for highlighting."
12755 :group 'vhdl-highlight)
d2ddb974 12756
3dcb36b7
JB
12757;; add faces used from `font-lock'
12758(custom-add-to-group
12759 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12760(custom-add-to-group
12761 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12762(custom-add-to-group
12763 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12764(custom-add-to-group
12765 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12766(custom-add-to-group
12767 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12768(custom-add-to-group
12769 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12770
0a2e512a 12771(defface vhdl-font-lock-prompt-face
f47877ee 12772 '((((min-colors 88) (class color) (background light))
ea81d57e 12773 (:foreground "Red1" :bold t))
f47877ee 12774 (((class color) (background light)) (:foreground "Red" :bold t))
3dcb36b7 12775 (((class color) (background dark)) (:foreground "Pink" :bold t))
d2ddb974 12776 (t (:inverse-video t)))
5eabfe72 12777 "Font lock mode face used to highlight prompts."
fa6674e3 12778 :group 'vhdl-highlight-faces)
d2ddb974 12779
0a2e512a 12780(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12781 '((((class color) (background light)) (:foreground "Orchid"))
12782 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12783 (t (:italic t :bold t)))
5eabfe72 12784 "Font lock mode face used to highlight standardized attributes."
fa6674e3 12785 :group 'vhdl-highlight-faces)
d2ddb974 12786
0a2e512a 12787(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12788 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12789 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12790 (t (:italic t :bold t)))
5eabfe72 12791 "Font lock mode face used to highlight standardized enumeration values."
fa6674e3 12792 :group 'vhdl-highlight-faces)
d2ddb974 12793
0a2e512a 12794(defface vhdl-font-lock-function-face
3dcb36b7 12795 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12796 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12797 (t (:italic t :bold t)))
5eabfe72 12798 "Font lock mode face used to highlight standardized functions and packages."
fa6674e3 12799 :group 'vhdl-highlight-faces)
d2ddb974 12800
0a2e512a 12801(defface vhdl-font-lock-directive-face
5eabfe72
KH
12802 '((((class color) (background light)) (:foreground "CadetBlue"))
12803 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12804 (t (:italic t :bold t)))
5eabfe72 12805 "Font lock mode face used to highlight directives."
fa6674e3 12806 :group 'vhdl-highlight-faces)
d2ddb974 12807
0a2e512a 12808(defface vhdl-font-lock-reserved-words-face
3dcb36b7 12809 '((((class color) (background light)) (:foreground "Orange" :bold t))
5bb5087f 12810 (((min-colors 88) (class color) (background dark))
ea81d57e 12811 (:foreground "Yellow1" :bold t))
3dcb36b7 12812 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12813 (t ()))
5eabfe72 12814 "Font lock mode face used to highlight additional reserved words."
fa6674e3 12815 :group 'vhdl-highlight-faces)
d2ddb974 12816
0a2e512a 12817(defface vhdl-font-lock-translate-off-face
5eabfe72
KH
12818 '((((class color) (background light)) (:background "LightGray"))
12819 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12820 (t ()))
5eabfe72 12821 "Font lock mode face used to background highlight translate-off regions."
fa6674e3 12822 :group 'vhdl-highlight-faces)
d2ddb974 12823
5eabfe72
KH
12824;; font lock mode faces used to highlight words with special syntax.
12825(let ((syntax-alist vhdl-special-syntax-alist))
12826 (while syntax-alist
0a2e512a
RF
12827 (eval `(defface ,(vhdl-function-name
12828 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12829 '((((class color) (background light))
12830 (:foreground ,(nth 2 (car syntax-alist))))
12831 (((class color) (background dark))
12832 (:foreground ,(nth 3 (car syntax-alist))))
12833 (t ()))
12834 ,(concat "Font lock mode face used to highlight "
12835 (nth 0 (car syntax-alist)) ".")
fa6674e3 12836 :group 'vhdl-highlight-faces))
5eabfe72
KH
12837 (setq syntax-alist (cdr syntax-alist))))
12838
12839;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12840;; Font lock initialization
12841
12842(defun vhdl-font-lock-init ()
5eabfe72 12843 "Initialize fontification."
0a2e512a 12844 ;; highlight template prompts and directives
3dcb36b7
JB
12845 (setq vhdl-font-lock-keywords-0
12846 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12847 vhdl-template-prompt-syntax ">\\)")
0a2e512a 12848 2 'vhdl-font-lock-prompt-face t)
3dcb36b7
JB
12849 (list (concat "--\\s-*"
12850 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
0a2e512a
RF
12851 2 'vhdl-font-lock-directive-face t)
12852 ;; highlight c-preprocessor directives
12853 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12854 '(1 font-lock-builtin-face)
12855 '(3 font-lock-variable-name-face nil t))))
5eabfe72
KH
12856 ;; highlight keywords and standardized types, attributes, enumeration
12857 ;; values, and subprograms
12858 (setq vhdl-font-lock-keywords-1
12859 (list
0a2e512a
RF
12860 (list (concat "'" vhdl-attributes-regexp)
12861 1 'vhdl-font-lock-attribute-face)
5eabfe72 12862 (list vhdl-types-regexp 1 'font-lock-type-face)
0a2e512a
RF
12863 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12864 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12865 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
5eabfe72
KH
12866 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12867 ;; highlight words with special syntax.
12868 (setq vhdl-font-lock-keywords-3
12869 (let ((syntax-alist vhdl-special-syntax-alist)
12870 keywords)
12871 (while syntax-alist
12872 (setq keywords
12873 (cons
12874 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12875 (vhdl-function-name
0a2e512a 12876 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
5eabfe72
KH
12877 keywords))
12878 (setq syntax-alist (cdr syntax-alist)))
12879 keywords))
12880 ;; highlight additional reserved words
12881 (setq vhdl-font-lock-keywords-4
0a2e512a
RF
12882 (list (list vhdl-reserved-words-regexp 1
12883 'vhdl-font-lock-reserved-words-face)))
5eabfe72 12884 ;; highlight everything together
d2ddb974 12885 (setq vhdl-font-lock-keywords
5eabfe72
KH
12886 (append
12887 vhdl-font-lock-keywords-0
12888 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12889 (when (or vhdl-highlight-forbidden-words
12890 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12891 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12892 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12893 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12894
12895;; initialize fontification for VHDL Mode
12896(vhdl-font-lock-init)
12897
12898(defun vhdl-fontify-buffer ()
12899 "Re-initialize fontification and fontify buffer."
12900 (interactive)
12901 (setq font-lock-defaults
cf38dd42
SM
12902 `(vhdl-font-lock-keywords
12903 nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
12904 beginning-of-line))
5eabfe72
KH
12905 (when (fboundp 'font-lock-unset-defaults)
12906 (font-lock-unset-defaults)) ; not implemented in XEmacs
0a2e512a 12907 (font-lock-set-defaults)
3dcb36b7
JB
12908 (font-lock-mode nil)
12909 (font-lock-mode t))
5eabfe72
KH
12910
12911;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12912;; Initialization for postscript printing
12913
12914(defun vhdl-ps-print-settings ()
12915 "Initialize custom face and page settings for postscript printing."
12916 ;; define custom face settings
12917 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12918 ps-print-color-p)
12919 (set (make-local-variable 'ps-bold-faces)
0a2e512a
RF
12920 '(font-lock-keyword-face
12921 font-lock-type-face
12922 vhdl-font-lock-attribute-face
12923 vhdl-font-lock-enumvalue-face
12924 vhdl-font-lock-directive-face))
d2ddb974
KH
12925 (set (make-local-variable 'ps-italic-faces)
12926 '(font-lock-comment-face
0a2e512a
RF
12927 font-lock-function-name-face
12928 font-lock-type-face
12929 vhdl-font-lock-attribute-face
12930 vhdl-font-lock-enumvalue-face
12931 vhdl-font-lock-directive-face))
d2ddb974
KH
12932 (set (make-local-variable 'ps-underlined-faces)
12933 '(font-lock-string-face))
5eabfe72 12934 (setq ps-always-build-face-reference t))
d2ddb974
KH
12935 ;; define page settings, so that a line containing 79 characters (default)
12936 ;; fits into one column
5eabfe72
KH
12937 (when vhdl-print-two-column
12938 (set (make-local-variable 'ps-landscape-mode) t)
12939 (set (make-local-variable 'ps-number-of-columns) 2)
12940 (set (make-local-variable 'ps-font-size) 7.0)
12941 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12942 (set (make-local-variable 'ps-header-font-size) 9.0)
12943 (set (make-local-variable 'ps-header-offset) 12.0)
12944 (when (eq ps-paper-type 'letter)
12945 (set (make-local-variable 'ps-inter-column) 40.0)
12946 (set (make-local-variable 'ps-left-margin) 40.0)
12947 (set (make-local-variable 'ps-right-margin) 40.0))))
12948
12949(defun vhdl-ps-print-init ()
12950 "Initialize postscript printing."
f8246027 12951 (if (featurep 'xemacs)
3dcb36b7
JB
12952 (when (boundp 'ps-print-color-p)
12953 (vhdl-ps-print-settings))
175069ef
SM
12954 (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
12955 (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
5eabfe72
KH
12956
12957
12958;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12959;;; Hierarchy browser (using `speedbar.el')
12960;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12961;; Allows displaying the hierarchy of all VHDL design units contained in a
12962;; directory by using the speedbar.
12963
12964;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12965;; Variables
12966
12967(defvar vhdl-entity-alist nil
3dcb36b7
JB
12968 "Cache with entities and corresponding architectures for each
12969project/directory.")
5eabfe72 12970;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12971;; (cache-key
12972;; (ent-key ent-name ent-file ent-line
12973;; (arch-key arch-name arch-file arch-line
12974;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
0a2e512a
RF
12975;; inst-arch-key inst-conf-key inst-lib-key inst-path)
12976;; (lib-name pack-key))
12977;; mra-key (lib-name pack-key))
3dcb36b7
JB
12978
12979(defvar vhdl-config-alist nil
12980 "Cache with configurations for each project/directory.")
12981;; structure: (parenthesised expression means list of such entries)
12982;; (cache-key
12983;; (conf-key conf-name conf-file conf-line ent-key arch-key
12984;; (inst-key inst-comp-name inst-ent-key inst-arch-key
0a2e512a 12985;; inst-conf-key inst-lib-key)
3dcb36b7 12986;; (lib-name pack-key)))
5eabfe72
KH
12987
12988(defvar vhdl-package-alist nil
3dcb36b7 12989 "Cache with packages for each project/directory.")
5eabfe72 12990;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12991;; (cache-key
12992;; (pack-key pack-name pack-file pack-line
12993;; (comp-key comp-name comp-file comp-line)
12994;; (func-key func-name func-file func-line)
12995;; (lib-name pack-key)
12996;; pack-body-file pack-body-line
12997;; (func-key func-name func-body-file func-body-line)
12998;; (lib-name pack-key)))
5eabfe72
KH
12999
13000(defvar vhdl-ent-inst-alist nil
3dcb36b7 13001 "Cache with instantiated entities for each project/directory.")
5eabfe72 13002;; structure: (parenthesised expression means list of such entries)
3dcb36b7 13003;; (cache-key (inst-ent-key))
5eabfe72 13004
3dcb36b7
JB
13005(defvar vhdl-file-alist nil
13006 "Cache with design units in each file for each project/directory.")
13007;; structure: (parenthesised expression means list of such entries)
13008;; (cache-key
13009;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
0a2e512a 13010;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 13011
3dcb36b7
JB
13012(defvar vhdl-directory-alist nil
13013 "Cache with source directories for each project.")
13014;; structure: (parenthesised expression means list of such entries)
13015;; (cache-key (directory))
5eabfe72 13016
3dcb36b7 13017(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
13018 "Alist of design units simultaneously open in the current speedbar for each
13019directory and project.")
13020
3dcb36b7
JB
13021(defvar vhdl-speedbar-shown-project-list nil
13022 "List of projects simultaneously open in the current speedbar.")
5eabfe72 13023
3dcb36b7
JB
13024(defvar vhdl-updated-project-list nil
13025 "List of projects and directories with updated files.")
13026
13027(defvar vhdl-modified-file-list nil
13028 "List of modified files to be rescanned for hierarchy updating.")
13029
13030(defvar vhdl-speedbar-hierarchy-depth 0
13031 "Depth of instantiation hierarchy to display.")
13032
13033(defvar vhdl-speedbar-show-projects nil
13034 "Non-nil means project hierarchy is displayed in speedbar, directory
13035hierarchy otherwise.")
13036
13037(defun vhdl-get-end-of-unit ()
13038 "Return position of end of current unit."
13039 (let ((pos (point)))
13040 (save-excursion
13041 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13042 (save-excursion
13043 (goto-char (match-beginning 0))
13044 (vhdl-backward-syntactic-ws)
13045 (and (/= (preceding-char) ?\;) (not (bobp))))))
13046 (re-search-backward "^[ \t]*end\\>" pos 1)
13047 (point))))
13048
13049(defun vhdl-match-string-downcase (num &optional string)
13050 "Like `match-string-no-properties' with down-casing."
13051 (let ((match (match-string-no-properties num string)))
13052 (and match (downcase match))))
5eabfe72 13053
5eabfe72
KH
13054
13055;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13056;; Scan functions
13057
3dcb36b7
JB
13058(defun vhdl-scan-context-clause ()
13059 "Scan the context clause that preceeds a design unit."
13060 (let (lib-alist)
13061 (save-excursion
13062 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13063 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13064 (equal "USE" (upcase (match-string 1))))
13065 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13066 (setq lib-alist (cons (cons (match-string-no-properties 1)
13067 (vhdl-match-string-downcase 2))
13068 lib-alist))))))
13069 lib-alist))
13070
13071(defun vhdl-scan-directory-contents (name &optional project update num-string
13072 non-final)
a4c6cfad 13073 "Scan contents of VHDL files in directory or file pattern NAME."
3dcb36b7 13074 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
13075; (unless (file-directory-p (match-string 1 name))
13076; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
13077 (let* ((dir-name (match-string 1 name))
13078 (file-pattern (match-string 2 name))
13079 (is-directory (= 0 (length file-pattern)))
5eabfe72 13080 (file-list
3dcb36b7
JB
13081 (if update
13082 (list name)
13083 (if is-directory
13084 (vhdl-get-source-files t dir-name)
13085 (vhdl-directory-files
13086 dir-name t (wildcard-to-regexp file-pattern)))))
13087 (key (or project dir-name))
13088 (file-exclude-regexp
13089 (or (nth 3 (aget vhdl-project-alist project)) ""))
13090 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13091 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13092 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13093 ent-alist conf-alist pack-alist ent-inst-list file-alist
13094 tmp-list tmp-entry no-files files-exist big-files)
13095 (when (or project update)
13096 (setq ent-alist (aget vhdl-entity-alist key t)
13097 conf-alist (aget vhdl-config-alist key t)
13098 pack-alist (aget vhdl-package-alist key t)
13099 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13100 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
13101 (when (and (not is-directory) (null file-list))
13102 (message "No such file: \"%s\"" name))
3dcb36b7
JB
13103 (setq files-exist file-list)
13104 (when file-list
13105 (setq no-files (length file-list))
13106 (message "Scanning %s %s\"%s\"..."
13107 (if is-directory "directory" "files") (or num-string "") name)
13108 ;; exclude files
13109 (unless (equal file-exclude-regexp "")
13110 (let ((case-fold-search nil)
13111 file-tmp-list)
13112 (while file-list
13113 (unless (string-match file-exclude-regexp (car file-list))
13114 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13115 (setq file-list (cdr file-list)))
13116 (setq file-list (nreverse file-tmp-list))))
13117 ;; do for all files
13118 (while file-list
13119 (unless noninteractive
5eabfe72
KH
13120 (message "Scanning %s %s\"%s\"... (%2d%s)"
13121 (if is-directory "directory" "files")
13122 (or num-string "") name
3dcb36b7
JB
13123 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13124 (let ((file-name (abbreviate-file-name (car file-list)))
13125 ent-list arch-list arch-ent-list conf-list
13126 pack-list pack-body-list inst-list inst-ent-list)
13127 ;; scan file
13128 (vhdl-visit-file
13129 file-name nil
13130 (vhdl-prepare-search-2
13131 (save-excursion
13132 ;; scan for design units
13133 (if (and limit-design-file-size
13134 (< limit-design-file-size (buffer-size)))
13135 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13136 (setq big-files t))
13137 ;; scan for entities
13138 (goto-char (point-min))
13139 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13140 (let* ((ent-name (match-string-no-properties 1))
13141 (ent-key (downcase ent-name))
13142 (ent-entry (aget ent-alist ent-key t))
3dcb36b7
JB
13143 (lib-alist (vhdl-scan-context-clause)))
13144 (if (nth 1 ent-entry)
13145 (vhdl-warning-when-idle
13146 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13147 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13148 file-name (vhdl-current-line))
13149 (setq ent-list (cons ent-key ent-list))
13150 (aput 'ent-alist ent-key
13151 (list ent-name file-name (vhdl-current-line)
0a2e512a
RF
13152 (nth 3 ent-entry) (nth 4 ent-entry)
13153 lib-alist)))))
3dcb36b7
JB
13154 ;; scan for architectures
13155 (goto-char (point-min))
0a2e512a 13156 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
3dcb36b7
JB
13157 (let* ((arch-name (match-string-no-properties 1))
13158 (arch-key (downcase arch-name))
13159 (ent-name (match-string-no-properties 2))
13160 (ent-key (downcase ent-name))
13161 (ent-entry (aget ent-alist ent-key t))
13162 (arch-alist (nth 3 ent-entry))
13163 (arch-entry (aget arch-alist arch-key t))
13164 (lib-arch-alist (vhdl-scan-context-clause)))
13165 (if arch-entry
13166 (vhdl-warning-when-idle
13167 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13168 arch-name ent-name (nth 1 arch-entry)
13169 (nth 2 arch-entry) file-name (vhdl-current-line))
13170 (setq arch-list (cons arch-key arch-list)
13171 arch-ent-list (cons ent-key arch-ent-list))
13172 (aput 'arch-alist arch-key
13173 (list arch-name file-name (vhdl-current-line) nil
13174 lib-arch-alist))
13175 (aput 'ent-alist ent-key
13176 (list (or (nth 0 ent-entry) ent-name)
13177 (nth 1 ent-entry) (nth 2 ent-entry)
13178 (vhdl-sort-alist arch-alist)
0a2e512a 13179 arch-key (nth 5 ent-entry))))))
3dcb36b7
JB
13180 ;; scan for configurations
13181 (goto-char (point-min))
13182 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13183 (let* ((conf-name (match-string-no-properties 1))
13184 (conf-key (downcase conf-name))
13185 (conf-entry (aget conf-alist conf-key t))
13186 (ent-name (match-string-no-properties 2))
13187 (ent-key (downcase ent-name))
13188 (lib-alist (vhdl-scan-context-clause))
13189 (conf-line (vhdl-current-line))
13190 (end-of-unit (vhdl-get-end-of-unit))
13191 arch-key comp-conf-list inst-key-list
13192 inst-comp-key inst-ent-key inst-arch-key
13193 inst-conf-key inst-lib-key)
13194 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13195 (setq arch-key (vhdl-match-string-downcase 1)))
13196 (if conf-entry
13197 (vhdl-warning-when-idle
13198 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13199 conf-name ent-name (nth 1 conf-entry)
13200 (nth 2 conf-entry) file-name conf-line)
13201 (setq conf-list (cons conf-key conf-list))
13202 ;; scan for subconfigurations and subentities
13203 (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)
13204 (setq inst-comp-key (vhdl-match-string-downcase 3)
13205 inst-key-list (split-string
13206 (vhdl-match-string-downcase 1)
13207 "[ \t\n]*,[ \t\n]*"))
13208 (vhdl-forward-syntactic-ws)
13209 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13210 (setq
13211 inst-lib-key (vhdl-match-string-downcase 3)
13212 inst-ent-key (and (match-string 2)
13213 (vhdl-match-string-downcase 4))
13214 inst-arch-key (and (match-string 2)
13215 (vhdl-match-string-downcase 6))
13216 inst-conf-key (and (not (match-string 2))
13217 (vhdl-match-string-downcase 4)))
13218 (while inst-key-list
13219 (setq comp-conf-list
13220 (cons (list (car inst-key-list)
13221 inst-comp-key inst-ent-key
13222 inst-arch-key inst-conf-key
13223 inst-lib-key)
13224 comp-conf-list))
13225 (setq inst-key-list (cdr inst-key-list)))))
13226 (aput 'conf-alist conf-key
13227 (list conf-name file-name conf-line ent-key
13228 arch-key comp-conf-list lib-alist)))))
13229 ;; scan for packages
13230 (goto-char (point-min))
13231 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13232 (let* ((pack-name (match-string-no-properties 2))
13233 (pack-key (downcase pack-name))
13234 (is-body (match-string-no-properties 1))
13235 (pack-entry (aget pack-alist pack-key t))
13236 (pack-line (vhdl-current-line))
13237 (end-of-unit (vhdl-get-end-of-unit))
13238 comp-name func-name comp-alist func-alist lib-alist)
13239 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13240 (vhdl-warning-when-idle
13241 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13242 (if is-body " body" "") pack-name
13243 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13244 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13245 file-name (vhdl-current-line))
13246 ;; scan for context clauses
13247 (setq lib-alist (vhdl-scan-context-clause))
13248 ;; scan for component and subprogram declarations/bodies
13249 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13250 (if (equal (upcase (match-string 1)) "COMPONENT")
13251 (setq comp-name (match-string-no-properties 2)
13252 comp-alist
13253 (cons (list (downcase comp-name) comp-name
13254 file-name (vhdl-current-line))
13255 comp-alist))
13256 (setq func-name (match-string-no-properties 2)
13257 func-alist
13258 (cons (list (downcase func-name) func-name
13259 file-name (vhdl-current-line))
13260 func-alist))))
13261 (setq func-alist (nreverse func-alist))
13262 (setq comp-alist (nreverse comp-alist))
13263 (if is-body
13264 (setq pack-body-list (cons pack-key pack-body-list))
13265 (setq pack-list (cons pack-key pack-list)))
13266 (aput
13267 'pack-alist pack-key
13268 (if is-body
13269 (list (or (nth 0 pack-entry) pack-name)
13270 (nth 1 pack-entry) (nth 2 pack-entry)
13271 (nth 3 pack-entry) (nth 4 pack-entry)
13272 (nth 5 pack-entry)
13273 file-name pack-line func-alist lib-alist)
13274 (list pack-name file-name pack-line
13275 comp-alist func-alist lib-alist
13276 (nth 6 pack-entry) (nth 7 pack-entry)
13277 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13278 ;; scan for hierarchy
13279 (if (and limit-hier-file-size
13280 (< limit-hier-file-size (buffer-size)))
13281 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13282 (setq big-files t))
13283 ;; scan for architectures
13284 (goto-char (point-min))
13285 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13286 (let* ((ent-name (match-string-no-properties 2))
13287 (ent-key (downcase ent-name))
13288 (arch-name (match-string-no-properties 1))
13289 (arch-key (downcase arch-name))
13290 (ent-entry (aget ent-alist ent-key t))
13291 (arch-alist (nth 3 ent-entry))
13292 (arch-entry (aget arch-alist arch-key t))
13293 (beg-of-unit (point))
13294 (end-of-unit (vhdl-get-end-of-unit))
13295 (inst-no 0)
0a2e512a 13296 inst-alist inst-path)
3dcb36b7
JB
13297 ;; scan for contained instantiations
13298 (while (and (re-search-forward
13299 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13300 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13301 "component[ \t\n]+\\(\\w+\\)\\|"
0a2e512a
RF
13302 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13303 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13304 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
3dcb36b7
JB
13305 (or (not limit-hier-inst-no)
13306 (<= (setq inst-no (1+ inst-no))
13307 limit-hier-inst-no)))
0a2e512a
RF
13308 (cond
13309 ;; block/generate beginning found
13310 ((match-string 14)
13311 (setq inst-path
13312 (cons (match-string-no-properties 1) inst-path)))
13313 ;; block/generate end found
13314 ((match-string 16)
13315 (setq inst-path (cdr inst-path)))
13316 ;; instantiation found
13317 (t
13318 (let* ((inst-name (match-string-no-properties 1))
13319 (inst-key (downcase inst-name))
13320 (inst-comp-name
13321 (or (match-string-no-properties 3)
13322 (match-string-no-properties 6)))
13323 (inst-ent-key
13324 (or (and (match-string 8)
13325 (vhdl-match-string-downcase 11))
13326 (and inst-comp-name
13327 (downcase inst-comp-name))))
13328 (inst-arch-key (vhdl-match-string-downcase 13))
13329 (inst-conf-key
13330 (and (not (match-string 8))
13331 (vhdl-match-string-downcase 11)))
13332 (inst-lib-key (vhdl-match-string-downcase 10)))
13333 (goto-char (match-end 1))
13334 (setq inst-list (cons inst-key inst-list)
13335 inst-ent-list
13336 (cons inst-ent-key inst-ent-list))
13337 (setq inst-alist
13338 (append
13339 inst-alist
13340 (list (list inst-key inst-name file-name
13341 (vhdl-current-line) inst-comp-name
13342 inst-ent-key inst-arch-key
13343 inst-conf-key inst-lib-key
13344 (reverse inst-path)))))))))
3dcb36b7
JB
13345 ;; scan for contained configuration specifications
13346 (goto-char beg-of-unit)
13347 (while (re-search-forward
13348 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13349 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
0a2e512a 13350 (let* ((inst-comp-name (match-string-no-properties 3))
3dcb36b7
JB
13351 (inst-ent-key
13352 (and (match-string 6)
13353 (vhdl-match-string-downcase 9)))
13354 (inst-arch-key (vhdl-match-string-downcase 11))
13355 (inst-conf-key
13356 (and (not (match-string 6))
13357 (vhdl-match-string-downcase 9)))
13358 (inst-lib-key (vhdl-match-string-downcase 8))
13359 (inst-key-list
13360 (split-string (vhdl-match-string-downcase 1)
13361 "[ \t\n]*,[ \t\n]*"))
13362 (tmp-inst-alist inst-alist)
13363 inst-entry)
13364 (while tmp-inst-alist
13365 (when (and (or (equal "all" (car inst-key-list))
13366 (member (nth 0 (car tmp-inst-alist))
13367 inst-key-list))
13368 (equal
13369 (downcase
13370 (or (nth 4 (car tmp-inst-alist)) ""))
13371 (downcase inst-comp-name)))
13372 (setq inst-entry (car tmp-inst-alist))
13373 (setq inst-ent-list
13374 (cons (or inst-ent-key (nth 5 inst-entry))
13375 (vhdl-delete
13376 (nth 5 inst-entry) inst-ent-list)))
13377 (setq inst-entry
13378 (list (nth 0 inst-entry) (nth 1 inst-entry)
13379 (nth 2 inst-entry) (nth 3 inst-entry)
13380 (nth 4 inst-entry)
13381 (or inst-ent-key (nth 5 inst-entry))
13382 (or inst-arch-key (nth 6 inst-entry))
13383 inst-conf-key inst-lib-key))
13384 (setcar tmp-inst-alist inst-entry))
13385 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13386 ;; save in cache
13387 (aput 'arch-alist arch-key
13388 (list (nth 0 arch-entry) (nth 1 arch-entry)
13389 (nth 2 arch-entry) inst-alist
13390 (nth 4 arch-entry)))
13391 (aput 'ent-alist ent-key
13392 (list (nth 0 ent-entry) (nth 1 ent-entry)
13393 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
0a2e512a 13394 (nth 4 ent-entry) (nth 5 ent-entry)))
3dcb36b7
JB
13395 (when (and limit-hier-inst-no
13396 (> inst-no limit-hier-inst-no))
13397 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13398 (setq big-files t))
13399 (goto-char end-of-unit))))
13400 ;; remember design units for this file
13401 (aput 'file-alist file-name
13402 (list ent-list arch-list arch-ent-list conf-list
13403 pack-list pack-body-list inst-list inst-ent-list))
13404 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13405 (setq file-list (cdr file-list))))
13406 (when (or (and (not project) files-exist)
13407 (and project (not non-final)))
13408 ;; consistency checks:
13409 ;; check whether each architecture has a corresponding entity
13410 (setq tmp-list ent-alist)
13411 (while tmp-list
13412 (when (null (nth 2 (car tmp-list)))
13413 (setq tmp-entry (car (nth 4 (car tmp-list))))
13414 (vhdl-warning-when-idle
13415 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13416 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13417 (nth 3 tmp-entry)))
13418 (setq tmp-list (cdr tmp-list)))
13419 ;; check whether configuration has a corresponding entity/architecture
13420 (setq tmp-list conf-alist)
13421 (while tmp-list
13422 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13423 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13424 (setq tmp-entry (car tmp-list))
13425 (vhdl-warning-when-idle
13426 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13427 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13428 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13429 (setq tmp-entry (car tmp-list))
13430 (vhdl-warning-when-idle
13431 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13432 (nth 1 tmp-entry) (nth 4 tmp-entry)
13433 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13434 (setq tmp-list (cdr tmp-list)))
13435 ;; check whether each package body has a package declaration
13436 (setq tmp-list pack-alist)
13437 (while tmp-list
13438 (when (null (nth 2 (car tmp-list)))
13439 (setq tmp-entry (car tmp-list))
13440 (vhdl-warning-when-idle
13441 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13442 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13443 (setq tmp-list (cdr tmp-list)))
13444 ;; sort lists
13445 (setq ent-alist (vhdl-sort-alist ent-alist))
13446 (setq conf-alist (vhdl-sort-alist conf-alist))
13447 (setq pack-alist (vhdl-sort-alist pack-alist))
13448 ;; remember updated directory/project
13449 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13450 ;; clear directory alists
13451 (unless project
13452 (adelete 'vhdl-entity-alist key)
13453 (adelete 'vhdl-config-alist key)
13454 (adelete 'vhdl-package-alist key)
13455 (adelete 'vhdl-ent-inst-alist key)
13456 (adelete 'vhdl-file-alist key))
13457 ;; put directory contents into cache
13458 (aput 'vhdl-entity-alist key ent-alist)
13459 (aput 'vhdl-config-alist key conf-alist)
13460 (aput 'vhdl-package-alist key pack-alist)
13461 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13462 (aput 'vhdl-file-alist key file-alist)
13463 ;; final messages
13464 (message "Scanning %s %s\"%s\"...done"
13465 (if is-directory "directory" "files") (or num-string "") name)
13466 (unless project (message "Scanning directory...done"))
13467 (when big-files
13468 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13469 ;; save cache when scanned non-interactively
13470 (when (or (not project) (not non-final))
13471 (when (and noninteractive vhdl-speedbar-save-cache)
13472 (vhdl-save-cache key)))
13473 t))
5eabfe72 13474
3dcb36b7 13475(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13476 "Scan the contents of all VHDL files found in the directories and files
13477of PROJECT."
3dcb36b7
JB
13478 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13479 (default-dir (vhdl-resolve-env-variable
13480 (nth 1 (aget vhdl-project-alist project))))
13481 (file-exclude-regexp
13482 (or (nth 3 (aget vhdl-project-alist project)) ""))
13483 dir-list-tmp dir dir-name num-dir act-dir recursive)
13484 ;; clear project alists
13485 (adelete 'vhdl-entity-alist project)
13486 (adelete 'vhdl-config-alist project)
13487 (adelete 'vhdl-package-alist project)
13488 (adelete 'vhdl-ent-inst-alist project)
13489 (adelete 'vhdl-file-alist project)
13490 ;; expand directory names by default-directory
13491 (message "Collecting source files...")
13492 (while dir-list
13493 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13494 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13495 (setq recursive (match-string 1 dir)
13496 dir-name (match-string 3 dir))
13497 (setq dir-list-tmp
13498 (cons (concat recursive
13499 (if (file-name-absolute-p dir-name) "" default-dir)
13500 dir-name)
13501 dir-list-tmp))
13502 (setq dir-list (cdr dir-list)))
13503 ;; resolve path wildcards
5eabfe72
KH
13504 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13505 ;; expand directories
13506 (while dir-list-tmp
13507 (setq dir (car dir-list-tmp))
13508 ;; get subdirectories
3dcb36b7 13509 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13510 (setq dir-list (append dir-list (vhdl-get-subdirs
13511 (match-string 1 dir))))
13512 (setq dir-list (append dir-list (list dir))))
13513 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13514 ;; exclude files
13515 (unless (equal file-exclude-regexp "")
13516 (let ((case-fold-search nil))
13517 (while dir-list
13518 (unless (string-match file-exclude-regexp (car dir-list))
13519 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13520 (setq dir-list (cdr dir-list)))
13521 (setq dir-list (nreverse dir-list-tmp))))
13522 (message "Collecting source files...done")
13523 ;; scan for design units for each directory in DIR-LIST
13524 (setq dir-list-tmp nil
13525 num-dir (length dir-list)
5eabfe72
KH
13526 act-dir 1)
13527 (while dir-list
3dcb36b7
JB
13528 (setq dir-name (abbreviate-file-name
13529 (expand-file-name (car dir-list))))
13530 (vhdl-scan-directory-contents dir-name project nil
13531 (format "(%s/%s) " act-dir num-dir)
13532 (cdr dir-list))
13533 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13534 (setq dir-list (cdr dir-list)
13535 act-dir (1+ act-dir)))
3dcb36b7
JB
13536 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13537 (message "Scanning project \"%s\"...done" project)))
13538
13539(defun vhdl-update-file-contents (file-name)
13540 "Update hierarchy information by contents of current buffer."
13541 (setq file-name (abbreviate-file-name file-name))
13542 (let* ((dir-name (file-name-directory file-name))
13543 (directory-alist vhdl-directory-alist)
13544 updated)
13545 (while directory-alist
13546 (when (member dir-name (nth 1 (car directory-alist)))
13547 (let* ((vhdl-project (nth 0 (car directory-alist)))
13548 (project (vhdl-project-p))
13549 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13550 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13551 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13552 (ent-inst-list (car (aget vhdl-ent-inst-alist
13553 (or project dir-name) t)))
13554 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13555 (file-entry (aget file-alist file-name t))
13556 (ent-list (nth 0 file-entry))
13557 (arch-list (nth 1 file-entry))
13558 (arch-ent-list (nth 2 file-entry))
13559 (conf-list (nth 3 file-entry))
13560 (pack-list (nth 4 file-entry))
13561 (pack-body-list (nth 5 file-entry))
13562 (inst-ent-list (nth 7 file-entry))
13563 (cache-key (or project dir-name))
13564 arch-alist key ent-key entry)
13565 ;; delete design units previously contained in this file:
13566 ;; entities
13567 (while ent-list
13568 (setq key (car ent-list)
13569 entry (aget ent-alist key t))
13570 (when (equal file-name (nth 1 entry))
13571 (if (nth 3 entry)
13572 (aput 'ent-alist key
13573 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13574 (adelete 'ent-alist key)))
13575 (setq ent-list (cdr ent-list)))
13576 ;; architectures
13577 (while arch-list
13578 (setq key (car arch-list)
13579 ent-key (car arch-ent-list)
13580 entry (aget ent-alist ent-key t)
13581 arch-alist (nth 3 entry))
13582 (when (equal file-name (nth 1 (aget arch-alist key t)))
13583 (adelete 'arch-alist key)
13584 (if (or (nth 1 entry) arch-alist)
13585 (aput 'ent-alist ent-key
13586 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
0a2e512a 13587 arch-alist (nth 4 entry) (nth 5 entry)))
3dcb36b7
JB
13588 (adelete 'ent-alist ent-key)))
13589 (setq arch-list (cdr arch-list)
13590 arch-ent-list (cdr arch-ent-list)))
13591 ;; configurations
13592 (while conf-list
13593 (setq key (car conf-list))
13594 (when (equal file-name (nth 1 (aget conf-alist key t)))
13595 (adelete 'conf-alist key))
13596 (setq conf-list (cdr conf-list)))
13597 ;; package declarations
13598 (while pack-list
13599 (setq key (car pack-list)
13600 entry (aget pack-alist key t))
13601 (when (equal file-name (nth 1 entry))
13602 (if (nth 6 entry)
13603 (aput 'pack-alist key
13604 (list (nth 0 entry) nil nil nil nil nil
13605 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13606 (nth 9 entry)))
13607 (adelete 'pack-alist key)))
13608 (setq pack-list (cdr pack-list)))
13609 ;; package bodies
13610 (while pack-body-list
13611 (setq key (car pack-body-list)
13612 entry (aget pack-alist key t))
13613 (when (equal file-name (nth 6 entry))
13614 (if (nth 1 entry)
13615 (aput 'pack-alist key
13616 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13617 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13618 nil nil nil nil))
13619 (adelete 'pack-alist key)))
13620 (setq pack-body-list (cdr pack-body-list)))
13621 ;; instantiated entities
13622 (while inst-ent-list
13623 (setq ent-inst-list
13624 (vhdl-delete (car inst-ent-list) ent-inst-list))
13625 (setq inst-ent-list (cdr inst-ent-list)))
13626 ;; update caches
13627 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13628 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13629 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13630 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13631 ;; scan file
13632 (vhdl-scan-directory-contents file-name project t)
13633 (when (or (and vhdl-speedbar-show-projects project)
13634 (and (not vhdl-speedbar-show-projects) (not project)))
13635 (vhdl-speedbar-refresh project))
13636 (setq updated t)))
13637 (setq directory-alist (cdr directory-alist)))
13638 updated))
13639
13640(defun vhdl-update-hierarchy ()
13641 "Update directory and hierarchy information in speedbar."
13642 (let ((file-list (reverse vhdl-modified-file-list))
13643 updated)
13644 (when (and vhdl-speedbar-update-on-saving file-list)
13645 (while file-list
13646 (setq updated
13647 (or (vhdl-update-file-contents (car file-list))
13648 updated))
13649 (setq file-list (cdr file-list)))
13650 (setq vhdl-modified-file-list nil)
0a2e512a 13651 (vhdl-speedbar-update-current-unit)
3dcb36b7
JB
13652 (when updated (message "Updating hierarchy...done")))))
13653
13654;; structure (parenthesised expression means list of such entries)
13655;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13656;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13657;; comp-lib-name level)
13658(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13659 conf-inst-alist level indent
13660 &optional include-top ent-hier)
13661 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13662entity ENT-KEY."
13663 (let* ((ent-entry (aget ent-alist ent-key t))
13664 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13665 (cdar (last (nth 3 ent-entry)))))
13666 (inst-alist (nth 3 arch-entry))
13667 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13668 hier-list subcomp-list tmp-list inst-key inst-comp-name
13669 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13670 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13671 (when include-top
13672 (setq level (1+ level)))
13673 (when (member ent-key ent-hier)
13674 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13675 ;; check configured architecture (already checked during scanning)
13676; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13677; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13678 ;; process all instances
13679 (while inst-alist
13680 (setq inst-entry (car inst-alist)
13681 inst-key (nth 0 inst-entry)
13682 inst-comp-name (nth 4 inst-entry)
13683 inst-conf-key (nth 7 inst-entry))
13684 ;; search entry in configuration's instantiations list
13685 (setq tmp-list conf-inst-alist)
13686 (while (and tmp-list
13687 (not (and (member (nth 0 (car tmp-list))
13688 (list "all" inst-key))
13689 (equal (nth 1 (car tmp-list))
13690 (downcase (or inst-comp-name ""))))))
13691 (setq tmp-list (cdr tmp-list)))
13692 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13693 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13694 (when (and inst-conf-key (not inst-conf-entry))
13695 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13696 ;; determine entity
13697 (setq inst-ent-key
13698 (or (nth 2 (car tmp-list)) ; from configuration
13699 (nth 3 inst-conf-entry) ; from subconfiguration
13700 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13701 ; from configuration spec.
13702 (nth 5 inst-entry))) ; from direct instantiation
13703 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13704 ;; determine architecture
13705 (setq inst-arch-key
0a2e512a
RF
13706 (or (nth 3 (car tmp-list)) ; from configuration
13707 (nth 4 inst-conf-entry) ; from subconfiguration
13708 (nth 6 inst-entry) ; from direct instantiation
3dcb36b7 13709 (nth 4 (aget conf-alist (nth 7 inst-entry)))
0a2e512a
RF
13710 ; from configuration spec.
13711 (nth 4 inst-ent-entry) ; MRA
13712 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
3dcb36b7
JB
13713 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13714 ;; set library
13715 (setq inst-lib-key
0a2e512a
RF
13716 (or (nth 5 (car tmp-list)) ; from configuration
13717 (nth 8 inst-entry))) ; from direct instantiation
3dcb36b7
JB
13718 ;; gather information for this instance
13719 (setq comp-entry
13720 (list (nth 1 inst-entry)
13721 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13722 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13723 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13724 (or (nth 0 inst-arch-entry) inst-arch-key)
13725 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13726 (or (nth 0 inst-conf-entry) inst-conf-key)
13727 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13728 inst-lib-key level))
13729 ;; get subcomponent hierarchy
13730 (setq subcomp-list (vhdl-get-hierarchy
13731 ent-alist conf-alist
13732 inst-ent-key inst-arch-key inst-conf-key
13733 (nth 5 inst-conf-entry)
13734 (1+ level) indent nil (cons ent-key ent-hier)))
13735 ;; add to list
13736 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13737 (setq inst-alist (cdr inst-alist)))
13738 (when include-top
5eabfe72 13739 (setq hier-list
3dcb36b7
JB
13740 (cons (list nil nil (nth 0 ent-entry)
13741 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13742 (nth 0 arch-entry)
13743 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13744 nil nil
13745 nil (1- level))
13746 hier-list)))
13747 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13748 hier-list))
13749
3dcb36b7
JB
13750(defun vhdl-get-instantiations (ent-key indent)
13751 "Get all instantiations of entity ENT-KEY."
13752 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13753 arch-alist inst-alist ent-inst-list
13754 ent-entry arch-entry inst-entry)
13755 (while ent-alist
13756 (setq ent-entry (car ent-alist))
3dcb36b7 13757 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13758 (while arch-alist
13759 (setq arch-entry (car arch-alist))
3dcb36b7 13760 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13761 (while inst-alist
13762 (setq inst-entry (car inst-alist))
3dcb36b7 13763 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13764 (setq ent-inst-list
3dcb36b7
JB
13765 (cons (list (nth 1 inst-entry)
13766 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13767 (nth 1 ent-entry)
13768 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13769 (nth 1 arch-entry)
13770 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13771 ent-inst-list)))
5eabfe72
KH
13772 (setq inst-alist (cdr inst-alist)))
13773 (setq arch-alist (cdr arch-alist)))
13774 (setq ent-alist (cdr ent-alist)))
13775 (nreverse ent-inst-list)))
13776
13777;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13778;; Caching in file
13779
13780(defun vhdl-save-caches ()
13781 "Save all updated hierarchy caches to file."
13782 (interactive)
13783 (condition-case nil
13784 (when vhdl-speedbar-save-cache
13785 ;; update hierarchy
13786 (vhdl-update-hierarchy)
13787 (let ((project-list vhdl-updated-project-list))
13788 (message "Saving hierarchy caches...")
13789 ;; write updated project caches
13790 (while project-list
13791 (vhdl-save-cache (car project-list))
13792 (setq project-list (cdr project-list)))
13793 (message "Saving hierarchy caches...done")))
b65d82ca 13794 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
3dcb36b7
JB
13795 (sit-for 2)))))
13796
13797(defun vhdl-save-cache (key)
13798 "Save current hierarchy cache to file."
13799 (let* ((orig-buffer (current-buffer))
13800 (vhdl-project key)
13801 (project (vhdl-project-p))
13802 (default-directory key)
13803 (directory (abbreviate-file-name (vhdl-default-directory)))
13804 (file-name (vhdl-resolve-env-variable
13805 (vhdl-replace-string
13806 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13807 (concat
13808 (subst-char-in-string ? ?_ (or project "dir"))
13809 " " (user-login-name)))))
13810 (file-dir-name (expand-file-name file-name directory))
13811 (cache-key (or project directory))
13812 (key (if project "project" "directory")))
13813 (unless (file-exists-p (file-name-directory file-dir-name))
13814 (make-directory (file-name-directory file-dir-name) t))
13815 (if (not (file-writable-p file-dir-name))
13816 (progn (vhdl-warning (format "File not writable: \"%s\""
13817 (abbreviate-file-name file-dir-name)))
13818 (sit-for 2))
13819 (message "Saving cache: \"%s\"" file-dir-name)
13820 (set-buffer (find-file-noselect file-dir-name t t))
13821 (erase-buffer)
13822 (insert ";; -*- Emacs-Lisp -*-\n\n"
13823 ";;; " (file-name-nondirectory file-name)
13824 " - design hierarchy cache file for Emacs VHDL Mode "
13825 vhdl-version "\n")
13826 (insert "\n;; " (if project "Project " "Directory") " : ")
13827 (if project (insert project) (prin1 directory (current-buffer)))
13828 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13829 (user-login-name) "\n\n"
13830 "\n;; version number\n"
13831 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13832 "\n;; " (if project "project" "directory") " name"
13833 "\n(setq " key " ")
13834 (prin1 (or project directory) (current-buffer))
13835 (insert ")\n")
13836 (when (member 'hierarchy vhdl-speedbar-save-cache)
13837 (insert "\n;; entity and architecture cache\n"
13838 "(aput 'vhdl-entity-alist " key " '")
13839 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13840 (insert ")\n\n;; configuration cache\n"
13841 "(aput 'vhdl-config-alist " key " '")
13842 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13843 (insert ")\n\n;; package cache\n"
13844 "(aput 'vhdl-package-alist " key " '")
13845 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13846 (insert ")\n\n;; instantiated entities cache\n"
13847 "(aput 'vhdl-ent-inst-alist " key " '")
13848 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13849 (insert ")\n\n;; design units per file cache\n"
13850 "(aput 'vhdl-file-alist " key " '")
13851 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13852 (when project
13853 (insert ")\n\n;; source directories in project cache\n"
13854 "(aput 'vhdl-directory-alist " key " '")
13855 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13856 (insert ")\n"))
13857 (when (member 'display vhdl-speedbar-save-cache)
13858 (insert "\n;; shown design units cache\n"
13859 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13860 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13861 (current-buffer))
13862 (insert ")\n"))
13863 (setq vhdl-updated-project-list
13864 (delete cache-key vhdl-updated-project-list))
13865 (save-buffer)
13866 (kill-buffer (current-buffer))
13867 (set-buffer orig-buffer))))
13868
13869(defun vhdl-load-cache (key)
13870 "Load hierarchy cache information from file."
13871 (let* ((vhdl-project key)
13872 (default-directory key)
13873 (directory (vhdl-default-directory))
13874 (file-name (vhdl-resolve-env-variable
13875 (vhdl-replace-string
13876 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13877 (concat
13878 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13879 " " (user-login-name)))))
13880 (file-dir-name (expand-file-name file-name directory))
13881 vhdl-cache-version)
13882 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13883 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13884 (when (file-exists-p file-dir-name)
13885 (condition-case ()
13886 (progn (load-file file-dir-name)
13887 (string< (mapconcat
027a4b6b 13888 (lambda (a) (format "%3d" (string-to-number a)))
0a2e512a 13889 (split-string "3.33" "\\.") "")
3dcb36b7 13890 (mapconcat
027a4b6b 13891 (lambda (a) (format "%3d" (string-to-number a)))
3dcb36b7
JB
13892 (split-string vhdl-cache-version "\\.") "")))
13893 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13894 nil))))))
13895
13896(defun vhdl-require-hierarchy-info ()
13897 "Make sure that hierarchy information is available. Load cache or scan files
13898if required."
13899 (if (vhdl-project-p)
13900 (unless (or (assoc vhdl-project vhdl-file-alist)
13901 (vhdl-load-cache vhdl-project))
13902 (vhdl-scan-project-contents vhdl-project))
13903 (let ((directory (abbreviate-file-name default-directory)))
13904 (unless (or (assoc directory vhdl-file-alist)
13905 (vhdl-load-cache directory))
13906 (vhdl-scan-directory-contents directory)))))
13907
13908;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13909;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13910
13911(defvar vhdl-speedbar-key-map nil
13912 "Keymap used when in the VHDL hierarchy browser mode.")
13913
3dcb36b7 13914(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13915 "Additional menu-items to add to speedbar frame.")
13916
13917(defun vhdl-speedbar-initialize ()
13918 "Initialize speedbar."
13919 ;; general settings
13920; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13921 ;; VHDL file extensions (extracted from `auto-mode-alist')
13922 (let ((mode-alist auto-mode-alist))
13923 (while mode-alist
3dcb36b7
JB
13924 (when (eq (cdar mode-alist) 'vhdl-mode)
13925 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13926 (setq mode-alist (cdr mode-alist))))
13927 ;; hierarchy browser settings
13928 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13929 ;; special functions
5eabfe72 13930 (speedbar-add-mode-functions-list
3dcb36b7 13931 '("vhdl directory"
5eabfe72 13932 (speedbar-item-info . vhdl-speedbar-item-info)
7752250e 13933 (speedbar-line-directory . speedbar-files-line-path)))
3dcb36b7
JB
13934 (speedbar-add-mode-functions-list
13935 '("vhdl project"
13936 (speedbar-item-info . vhdl-speedbar-item-info)
7752250e 13937 (speedbar-line-directory . vhdl-speedbar-line-project)))
3dcb36b7 13938 ;; keymap
5eabfe72
KH
13939 (unless vhdl-speedbar-key-map
13940 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13941 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13942 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13943 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
13944 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13945 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13946 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13947 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13948 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
0a2e512a
RF
13949 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
13950 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
3dcb36b7
JB
13951 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13952 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13953 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13954 (let ((key 0))
13955 (while (<= key 9)
13956 (define-key vhdl-speedbar-key-map (int-to-string key)
13957 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13958 (setq key (1+ key)))))
5eabfe72
KH
13959 (define-key speedbar-key-map "h"
13960 (lambda () (interactive)
3dcb36b7
JB
13961 (speedbar-change-initial-expansion-list "vhdl directory")))
13962 (define-key speedbar-key-map "H"
13963 (lambda () (interactive)
13964 (speedbar-change-initial-expansion-list "vhdl project")))
13965 ;; menu
13966 (unless vhdl-speedbar-menu-items
13967 (setq
13968 vhdl-speedbar-menu-items
13969 `(["Edit" speedbar-edit-line t]
13970 ["Expand" speedbar-expand-line
13971 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13972 ["Contract" vhdl-speedbar-contract-level t]
13973 ["Expand All" vhdl-speedbar-expand-all t]
13974 ["Contract All" vhdl-speedbar-contract-all t]
13975 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13976 (while (<= key 9)
13977 (setq menu-list
13978 (cons `[,(if (= key 0) "All" (int-to-string key))
13979 (vhdl-speedbar-set-depth ,key)
13980 :style radio
13981 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13982 :keys ,(int-to-string key)]
13983 menu-list))
13984 (setq key (1+ key)))
13985 (nreverse menu-list))
13986 "--"
13987 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13988 (or (vhdl-speedbar-check-unit 'entity)
13989 (vhdl-speedbar-check-unit 'subprogram))]
13990 ["Place Component" vhdl-speedbar-place-component
13991 (vhdl-speedbar-check-unit 'entity)]
0a2e512a
RF
13992 ["Generate Configuration" vhdl-speedbar-configuration
13993 (vhdl-speedbar-check-unit 'architecture)]
13994 ["Select as MRA" vhdl-speedbar-select-mra
13995 (vhdl-speedbar-check-unit 'architecture)]
3dcb36b7
JB
13996 ["Make" vhdl-speedbar-make-design
13997 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13998 ["Generate Makefile" vhdl-speedbar-generate-makefile
13999 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14000 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14001 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
f8246027 14002 ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
3dcb36b7
JB
14003 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14004 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
f8246027 14005 ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
3dcb36b7
JB
14006 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14007 ;; hook-ups
14008 (speedbar-add-expansion-list
14009 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14010 vhdl-speedbar-display-directory))
14011 (speedbar-add-expansion-list
14012 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14013 vhdl-speedbar-display-projects))
5eabfe72 14014 (setq speedbar-stealthy-function-list
3dcb36b7
JB
14015 (append
14016 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14017 ("vhdl project" vhdl-speedbar-update-current-project
14018 vhdl-speedbar-update-current-unit)
14019; ("files" (lambda () (setq speedbar-ignored-path-regexp
14020; (speedbar-extension-list-to-regex
14021; speedbar-ignored-path-expressions))))
14022 )
14023 speedbar-stealthy-function-list))
14024 (when (eq vhdl-speedbar-display-mode 'directory)
14025 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14026 (when (eq vhdl-speedbar-display-mode 'project)
14027 (setq speedbar-initial-expansion-list-name "vhdl project"))
14028 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
14029
14030(defun vhdl-speedbar (&optional arg)
14031 "Open/close speedbar."
d2ddb974 14032 (interactive)
5eabfe72 14033 (if (not (fboundp 'speedbar))
3dcb36b7
JB
14034 (error "WARNING: Speedbar is not available or not installed")
14035 (condition-case ()
5eabfe72 14036 (speedbar-frame-mode arg)
3dcb36b7 14037 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
14038
14039;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14040;; Display functions
14041
3dcb36b7
JB
14042(defvar vhdl-speedbar-last-selected-project nil
14043 "Name of last selected project.")
14044
5eabfe72
KH
14045;; macros must be defined in the file they are used (copied from `speedbar.el')
14046(defmacro speedbar-with-writable (&rest forms)
14047 "Allow the buffer to be writable and evaluate FORMS."
14048 (list 'let '((inhibit-read-only t))
14049 (cons 'progn forms)))
14050(put 'speedbar-with-writable 'lisp-indent-function 0)
14051
3dcb36b7 14052(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 14053 "Display directory and hierarchy information in speedbar."
3dcb36b7 14054 (setq vhdl-speedbar-show-projects nil)
f8262222
RS
14055 (setq speedbar-ignored-directory-regexp
14056 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
5eabfe72
KH
14057 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14058 (setq speedbar-last-selected-file nil)
14059 (speedbar-with-writable
3dcb36b7
JB
14060 (condition-case nil
14061 (progn
14062 ;; insert directory path
14063 (speedbar-directory-buttons directory depth)
14064 ;; insert subdirectories
14065 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14066 ;; scan and insert hierarchy of current directory
14067 (vhdl-speedbar-insert-dir-hierarchy directory depth
14068 speedbar-power-click)
14069 ;; expand subdirectories
14070 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14071 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14072
14073(defun vhdl-speedbar-display-projects (project depth &optional rescan)
14074 "Display projects and hierarchy information in speedbar."
14075 (setq vhdl-speedbar-show-projects t)
f8262222 14076 (setq speedbar-ignored-directory-regexp ".")
3dcb36b7
JB
14077 (setq speedbar-last-selected-file nil)
14078 (setq vhdl-speedbar-last-selected-project nil)
14079 (speedbar-with-writable
14080 (condition-case nil
14081 ;; insert projects
14082 (vhdl-speedbar-insert-projects)
14083 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14084 (setq speedbar-full-text-cache nil)) ; prevent caching
14085
14086(defun vhdl-speedbar-insert-projects ()
14087 "Insert all projects in speedbar."
14088 (vhdl-speedbar-make-title-line "Projects:")
14089 (let ((project-alist (if vhdl-project-sort
14090 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14091 vhdl-project-alist))
14092 (vhdl-speedbar-update-current-unit nil))
14093 ;; insert projects
14094 (while project-alist
14095 (speedbar-make-tag-line
14096 'angle ?+ 'vhdl-speedbar-expand-project
14097 (caar project-alist) (caar project-alist)
14098 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14099 (setq project-alist (cdr project-alist)))
14100 (setq project-alist vhdl-project-alist)
14101 ;; expand projects
14102 (while project-alist
14103 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14104 (goto-char (point-min))
14105 (when (re-search-forward
14106 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14107 (goto-char (match-end 1))
14108 (speedbar-do-function-pointer)))
14109 (setq project-alist (cdr project-alist))))
14110; (vhdl-speedbar-update-current-project)
14111; (vhdl-speedbar-update-current-unit nil t)
14112 )
14113
14114(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
a4c6cfad 14115 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
3dcb36b7
JB
14116otherwise use cached data."
14117 (when (or rescan (and (not (assoc project vhdl-file-alist))
14118 (not (vhdl-load-cache project))))
14119 (vhdl-scan-project-contents project))
14120 ;; insert design hierarchy
14121 (vhdl-speedbar-insert-hierarchy
14122 (aget vhdl-entity-alist project t)
14123 (aget vhdl-config-alist project t)
14124 (aget vhdl-package-alist project t)
14125 (car (aget vhdl-ent-inst-alist project t)) indent)
14126 (insert (int-to-string indent) ":\n")
14127 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14128 (put-text-property (1- (point)) (point) 'invisible nil)
14129 ;; expand design units
14130 (vhdl-speedbar-expand-units project))
14131
14132(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14133 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14134otherwise use cached data."
14135 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14136 (not (vhdl-load-cache directory))))
14137 (vhdl-scan-directory-contents directory))
14138 ;; insert design hierarchy
14139 (vhdl-speedbar-insert-hierarchy
14140 (aget vhdl-entity-alist directory t)
14141 (aget vhdl-config-alist directory t)
14142 (aget vhdl-package-alist directory t)
14143 (car (aget vhdl-ent-inst-alist directory t)) depth)
14144 ;; expand design units
14145 (vhdl-speedbar-expand-units directory)
14146 (aput 'vhdl-directory-alist directory (list (list directory))))
14147
14148(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 14149 ent-inst-list depth)
3dcb36b7
JB
14150 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14151 (if (not (or ent-alist conf-alist pack-alist))
14152 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14153 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
14154 ;; insert entities
14155 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14156 (while ent-alist
14157 (setq ent-entry (car ent-alist))
14158 (speedbar-make-tag-line
14159 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
14160 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14161 (cons (nth 2 ent-entry) (nth 3 ent-entry))
0a2e512a 14162 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
14163 (unless (nth 2 ent-entry)
14164 (end-of-line 0) (insert "!") (forward-char 1))
14165 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
14166 (end-of-line 0) (insert " (top)") (forward-char 1))
14167 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
14168 ;; insert configurations
14169 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14170 (while conf-alist
14171 (setq conf-entry (car conf-alist))
14172 (speedbar-make-tag-line
14173 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14174 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14175 (cons (nth 2 conf-entry) (nth 3 conf-entry))
0a2e512a 14176 'vhdl-speedbar-configuration-face depth)
3dcb36b7 14177 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
14178 ;; insert packages
14179 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14180 (while pack-alist
14181 (setq pack-entry (car pack-alist))
14182 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
14183 (nth 0 pack-entry) (nth 1 pack-entry)
14184 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14185 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
14186 depth)
14187 (setq pack-alist (cdr pack-alist))))))
14188
5eabfe72 14189(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 14190 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 14191 (interactive)
3dcb36b7
JB
14192 (let (key path)
14193 (cond
14194 ;; current project
14195 (vhdl-speedbar-show-projects
14196 (setq key (vhdl-speedbar-line-project))
14197 (vhdl-scan-project-contents key))
14198 ;; top-level directory
14199 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14200 (re-search-forward "[0-9]+:" nil t)
14201 (vhdl-scan-directory-contents
7752250e 14202 (abbreviate-file-name (speedbar-line-directory))))
3dcb36b7 14203 ;; current directory
7752250e 14204 (t (setq path (speedbar-line-directory))
3dcb36b7
JB
14205 (string-match "^\\(.+[/\\]\\)" path)
14206 (vhdl-scan-directory-contents
14207 (abbreviate-file-name (match-string 1 path)))))
14208 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14209
14210(defun vhdl-speedbar-expand-dirs (directory)
14211 "Expand subdirectories in DIRECTORY according to
14212 `speedbar-shown-directories'."
14213 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14214 (let ((sf (cdr (reverse speedbar-shown-directories)))
14215 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14216 (setq speedbar-shown-directories
14217 (list (expand-file-name default-directory)))
14218 (while sf
14219 (when (speedbar-goto-this-file (car sf))
14220 (beginning-of-line)
14221 (when (looking-at "[0-9]+:\\s-*<")
14222 (goto-char (match-end 0))
3dcb36b7
JB
14223 (speedbar-do-function-pointer)))
14224 (setq sf (cdr sf))))
14225 (vhdl-speedbar-update-current-unit nil t))
14226
14227(defun vhdl-speedbar-expand-units (key)
14228 "Expand design units in directory/project KEY according to
14229`vhdl-speedbar-shown-unit-alist'."
14230 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14231 (vhdl-speedbar-update-current-unit nil)
14232 vhdl-updated-project-list)
14233 (adelete 'vhdl-speedbar-shown-unit-alist key)
14234 (vhdl-prepare-search-1
14235 (while unit-alist ; expand units
14236 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14237 (beginning-of-line)
14238 (let ((arch-alist (nth 1 (car unit-alist)))
14239 position)
14240 (when (looking-at "^[0-9]+:\\s-*\\[")
14241 (goto-char (match-end 0))
14242 (setq position (point))
14243 (speedbar-do-function-pointer)
14244 (select-frame speedbar-frame)
14245 (while arch-alist ; expand architectures
14246 (goto-char position)
14247 (when (re-search-forward
14248 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14249 (car arch-alist) "\\>\\)") nil t)
14250 (beginning-of-line)
14251 (when (looking-at "^[0-9]+:\\s-*{")
14252 (goto-char (match-end 0))
14253 (speedbar-do-function-pointer)
14254 (select-frame speedbar-frame)))
14255 (setq arch-alist (cdr arch-alist))))
14256 (setq unit-alist (cdr unit-alist))))))
14257 (vhdl-speedbar-update-current-unit nil t))
14258
14259(defun vhdl-speedbar-contract-level ()
14260 "Contract current level in current directory/project."
14261 (interactive)
14262 (when (or (save-excursion
14263 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14264 (and (save-excursion
14265 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14266 (re-search-backward
14267 (format "^[0-%d]:\\s-*[[{<]-"
027a4b6b 14268 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
3dcb36b7
JB
14269 (goto-char (match-end 0))
14270 (speedbar-do-function-pointer)
14271 (speedbar-center-buffer-smartly)))
14272
14273(defun vhdl-speedbar-contract-all ()
14274 "Contract all expanded design units in current directory/project."
14275 (interactive)
14276 (if (and vhdl-speedbar-show-projects
14277 (save-excursion (beginning-of-line) (looking-at "^0:")))
14278 (progn (setq vhdl-speedbar-shown-project-list nil)
14279 (vhdl-speedbar-refresh))
14280 (let ((key (vhdl-speedbar-line-key)))
14281 (adelete 'vhdl-speedbar-shown-unit-alist key)
14282 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14283 (when (memq 'display vhdl-speedbar-save-cache)
14284 (add-to-list 'vhdl-updated-project-list key)))))
14285
14286(defun vhdl-speedbar-expand-all ()
14287 "Expand all design units in current directory/project."
14288 (interactive)
14289 (let* ((key (vhdl-speedbar-line-key))
14290 (ent-alist (aget vhdl-entity-alist key t))
14291 (conf-alist (aget vhdl-config-alist key t))
14292 (pack-alist (aget vhdl-package-alist key t))
14293 arch-alist unit-alist subunit-alist)
14294 (add-to-list 'vhdl-speedbar-shown-project-list key)
14295 (while ent-alist
14296 (setq arch-alist (nth 4 (car ent-alist)))
14297 (setq subunit-alist nil)
14298 (while arch-alist
14299 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14300 (setq arch-alist (cdr arch-alist)))
14301 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14302 (setq ent-alist (cdr ent-alist)))
14303 (while conf-alist
14304 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14305 (setq conf-alist (cdr conf-alist)))
14306 (while pack-alist
14307 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14308 (setq pack-alist (cdr pack-alist)))
14309 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14310 (vhdl-speedbar-refresh)
14311 (when (memq 'display vhdl-speedbar-save-cache)
14312 (add-to-list 'vhdl-updated-project-list key))))
14313
14314(defun vhdl-speedbar-expand-project (text token indent)
14315 "Expand/contract the project under the cursor."
14316 (cond
14317 ((string-match "+" text) ; expand project
14318 (speedbar-change-expand-button-char ?-)
14319 (unless (member token vhdl-speedbar-shown-project-list)
14320 (setq vhdl-speedbar-shown-project-list
14321 (cons token vhdl-speedbar-shown-project-list)))
14322 (speedbar-with-writable
14323 (save-excursion
14324 (end-of-line) (forward-char 1)
14325 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14326 speedbar-power-click))))
14327 ((string-match "-" text) ; contract project
14328 (speedbar-change-expand-button-char ?+)
14329 (setq vhdl-speedbar-shown-project-list
14330 (delete token vhdl-speedbar-shown-project-list))
14331 (speedbar-delete-subblock indent))
14332 (t (error "Nothing to display")))
14333 (when (equal (selected-frame) speedbar-frame)
14334 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14335
14336(defun vhdl-speedbar-expand-entity (text token indent)
14337 "Expand/contract the entity under the cursor."
14338 (cond
14339 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14340 (let* ((key (vhdl-speedbar-line-key indent))
14341 (ent-alist (aget vhdl-entity-alist key t))
14342 (ent-entry (aget ent-alist token t))
14343 (arch-alist (nth 3 ent-entry))
5eabfe72 14344 (inst-alist (vhdl-get-instantiations token indent))
0a2e512a
RF
14345 (subpack-alist (nth 5 ent-entry))
14346 (multiple-arch (> (length arch-alist) 1))
3dcb36b7
JB
14347 arch-entry inst-entry)
14348 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14349 (speedbar-change-expand-button-char ??)
14350 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14351 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14352 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14353 (aput 'unit-alist token nil)
14354 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14355 (speedbar-with-writable
3dcb36b7
JB
14356 (save-excursion
14357 (end-of-line) (forward-char 1)
14358 ;; insert architectures
14359 (when arch-alist
14360 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14361 (while arch-alist
14362 (setq arch-entry (car arch-alist))
14363 (speedbar-make-tag-line
14364 'curly ?+ 'vhdl-speedbar-expand-architecture
14365 (cons token (nth 0 arch-entry))
14366 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14367 (cons (nth 2 arch-entry) (nth 3 arch-entry))
0a2e512a
RF
14368 'vhdl-speedbar-architecture-face (1+ indent))
14369 (when (and multiple-arch
14370 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14371 (end-of-line 0) (insert " (mra)") (forward-char 1))
3dcb36b7
JB
14372 (setq arch-alist (cdr arch-alist)))
14373 ;; insert instantiations
14374 (when inst-alist
14375 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14376 (while inst-alist
14377 (setq inst-entry (car inst-alist))
14378 (vhdl-speedbar-make-inst-line
14379 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14380 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14381 nil nil nil (1+ indent) 0 " in ")
14382 (setq inst-alist (cdr inst-alist)))
14383 ;; insert required packages
14384 (vhdl-speedbar-insert-subpackages
14385 subpack-alist (1+ indent) indent)))
14386 (when (memq 'display vhdl-speedbar-save-cache)
14387 (add-to-list 'vhdl-updated-project-list key))
14388 (vhdl-speedbar-update-current-unit t t))))
5eabfe72
KH
14389 ((string-match "-" text) ; contract entity
14390 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14391 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14392 (let* ((key (vhdl-speedbar-line-key indent))
14393 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14394 (adelete 'unit-alist token)
14395 (if unit-alist
14396 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14397 (adelete 'vhdl-speedbar-shown-unit-alist key))
14398 (speedbar-delete-subblock indent)
14399 (when (memq 'display vhdl-speedbar-save-cache)
14400 (add-to-list 'vhdl-updated-project-list key))))
14401 (t (error "Nothing to display")))
14402 (when (equal (selected-frame) speedbar-frame)
14403 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14404
14405(defun vhdl-speedbar-expand-architecture (text token indent)
14406 "Expand/contract the architecture under the cursor."
14407 (cond
14408 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14409 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14410 (ent-alist (aget vhdl-entity-alist key t))
14411 (conf-alist (aget vhdl-config-alist key t))
14412 (hier-alist (vhdl-get-hierarchy
14413 ent-alist conf-alist (car token) (cdr token) nil nil
14414 0 (1- indent)))
14415 (ent-entry (aget ent-alist (car token) t))
14416 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14417 (subpack-alist (nth 4 arch-entry))
14418 entry)
14419 (if (not (or hier-alist subpack-alist))
14420 (speedbar-change-expand-button-char ??)
14421 (speedbar-change-expand-button-char ?-)
14422 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14423 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14424 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14425 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14426 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14427 (speedbar-with-writable
14428 (save-excursion
14429 (end-of-line) (forward-char 1)
14430 ;; insert instance hierarchy
14431 (when hier-alist
14432 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14433 (1+ indent)))
14434 (while hier-alist
14435 (setq entry (car hier-alist))
14436 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14437 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14438 (vhdl-speedbar-make-inst-line
14439 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14440 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14441 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14442 (setq hier-alist (cdr hier-alist)))
14443 ;; insert required packages
14444 (vhdl-speedbar-insert-subpackages
14445 subpack-alist (1+ indent) (1- indent))))
14446 (when (memq 'display vhdl-speedbar-save-cache)
14447 (add-to-list 'vhdl-updated-project-list key))
14448 (vhdl-speedbar-update-current-unit t t))))
14449 ((string-match "-" text) ; contract architecture
14450 (speedbar-change-expand-button-char ?+)
14451 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14452 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14453 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14454 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14455 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14456 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14457 (speedbar-delete-subblock indent)
14458 (when (memq 'display vhdl-speedbar-save-cache)
14459 (add-to-list 'vhdl-updated-project-list key))))
14460 (t (error "Nothing to display")))
14461 (when (equal (selected-frame) speedbar-frame)
14462 (speedbar-center-buffer-smartly)))
14463
14464(defun vhdl-speedbar-expand-config (text token indent)
14465 "Expand/contract the configuration under the cursor."
14466 (cond
14467 ((string-match "+" text) ; expand configuration
14468 (let* ((key (vhdl-speedbar-line-key indent))
14469 (conf-alist (aget vhdl-config-alist key t))
14470 (conf-entry (aget conf-alist token))
14471 (ent-alist (aget vhdl-entity-alist key t))
14472 (hier-alist (vhdl-get-hierarchy
14473 ent-alist conf-alist (nth 3 conf-entry)
14474 (nth 4 conf-entry) token (nth 5 conf-entry)
14475 0 indent t))
14476 (subpack-alist (nth 6 conf-entry))
14477 entry)
14478 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14479 (speedbar-change-expand-button-char ??)
14480 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14481 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14482 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14483 (aput 'unit-alist token nil)
14484 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14485 (speedbar-with-writable
14486 (save-excursion
14487 (end-of-line) (forward-char 1)
14488 ;; insert instance hierarchy
14489 (when hier-alist
3dcb36b7 14490 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14491 (while hier-alist
3dcb36b7
JB
14492 (setq entry (car hier-alist))
14493 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14494 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14495 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14496 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14497 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14498 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14499 (setq hier-alist (cdr hier-alist)))
14500 ;; insert required packages
14501 (vhdl-speedbar-insert-subpackages
14502 subpack-alist (1+ indent) indent)))
14503 (when (memq 'display vhdl-speedbar-save-cache)
14504 (add-to-list 'vhdl-updated-project-list key))
14505 (vhdl-speedbar-update-current-unit t t))))
14506 ((string-match "-" text) ; contract configuration
5eabfe72 14507 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14508 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14509 (let* ((key (vhdl-speedbar-line-key indent))
14510 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14511 (adelete 'unit-alist token)
14512 (if unit-alist
14513 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14514 (adelete 'vhdl-speedbar-shown-unit-alist key))
14515 (speedbar-delete-subblock indent)
14516 (when (memq 'display vhdl-speedbar-save-cache)
14517 (add-to-list 'vhdl-updated-project-list key))))
14518 (t (error "Nothing to display")))
14519 (when (equal (selected-frame) speedbar-frame)
14520 (speedbar-center-buffer-smartly)))
14521
14522(defun vhdl-speedbar-expand-package (text token indent)
14523 "Expand/contract the package under the cursor."
14524 (cond
14525 ((string-match "+" text) ; expand package
14526 (let* ((key (vhdl-speedbar-line-key indent))
14527 (pack-alist (aget vhdl-package-alist key t))
14528 (pack-entry (aget pack-alist token t))
14529 (comp-alist (nth 3 pack-entry))
14530 (func-alist (nth 4 pack-entry))
14531 (func-body-alist (nth 8 pack-entry))
14532 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14533 comp-entry func-entry func-body-entry)
14534 (if (not (or comp-alist func-alist subpack-alist))
14535 (speedbar-change-expand-button-char ??)
14536 (speedbar-change-expand-button-char ?-)
14537 ;; add package to `vhdl-speedbar-shown-unit-alist'
14538 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14539 (aput 'unit-alist token nil)
14540 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14541 (speedbar-with-writable
14542 (save-excursion
14543 (end-of-line) (forward-char 1)
14544 ;; insert components
14545 (when comp-alist
14546 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14547 (while comp-alist
14548 (setq comp-entry (car comp-alist))
14549 (speedbar-make-tag-line
14550 nil nil nil
14551 (cons token (nth 0 comp-entry))
14552 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14553 (cons (nth 2 comp-entry) (nth 3 comp-entry))
0a2e512a 14554 'vhdl-speedbar-entity-face (1+ indent))
3dcb36b7
JB
14555 (setq comp-alist (cdr comp-alist)))
14556 ;; insert subprograms
14557 (when func-alist
14558 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14559 (while func-alist
14560 (setq func-entry (car func-alist)
14561 func-body-entry (aget func-body-alist (car func-entry) t))
14562 (when (nth 2 func-entry)
14563 (vhdl-speedbar-make-subprogram-line
14564 (nth 1 func-entry)
14565 (cons (nth 2 func-entry) (nth 3 func-entry))
14566 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14567 (1+ indent)))
14568 (setq func-alist (cdr func-alist)))
14569 ;; insert required packages
14570 (vhdl-speedbar-insert-subpackages
14571 subpack-alist (1+ indent) indent)))
14572 (when (memq 'display vhdl-speedbar-save-cache)
14573 (add-to-list 'vhdl-updated-project-list key))
14574 (vhdl-speedbar-update-current-unit t t))))
14575 ((string-match "-" text) ; contract package
14576 (speedbar-change-expand-button-char ?+)
14577 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14578 (let* ((key (vhdl-speedbar-line-key indent))
14579 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14580 (adelete 'unit-alist token)
14581 (if unit-alist
14582 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14583 (adelete 'vhdl-speedbar-shown-unit-alist key))
14584 (speedbar-delete-subblock indent)
14585 (when (memq 'display vhdl-speedbar-save-cache)
14586 (add-to-list 'vhdl-updated-project-list key))))
14587 (t (error "Nothing to display")))
14588 (when (equal (selected-frame) speedbar-frame)
14589 (speedbar-center-buffer-smartly)))
14590
14591(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14592 "Insert required packages."
14593 (let* ((pack-alist (aget vhdl-package-alist
14594 (vhdl-speedbar-line-key dir-indent) t))
14595 pack-key lib-name pack-entry)
14596 (when subpack-alist
14597 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14598 (while subpack-alist
14599 (setq pack-key (cdar subpack-alist)
14600 lib-name (caar subpack-alist))
14601 (setq pack-entry (aget pack-alist pack-key t))
14602 (vhdl-speedbar-make-subpack-line
14603 (or (nth 0 pack-entry) pack-key) lib-name
0a2e512a
RF
14604 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14605 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
3dcb36b7 14606 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14607
14608;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14609;; Display help functions
14610
3dcb36b7
JB
14611(defvar vhdl-speedbar-update-current-unit t
14612 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14613
14614(defun vhdl-speedbar-update-current-project ()
14615 "Highlight project that is currently active."
14616 (when (and vhdl-speedbar-show-projects
14617 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14618 (and (boundp 'speedbar-frame)
14619 (frame-live-p speedbar-frame)))
14620 (let ((last-frame (selected-frame))
14621 (project-alist vhdl-project-alist)
14622 pos)
14623 (select-frame speedbar-frame)
14624 (speedbar-with-writable
14625 (save-excursion
14626 (while project-alist
14627 (goto-char (point-min))
14628 (when (re-search-forward
14629 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14630 (put-text-property (match-beginning 1) (match-end 1) 'face
14631 (if (equal (caar project-alist) vhdl-project)
14632 'speedbar-selected-face
14633 'speedbar-directory-face))
14634 (when (equal (caar project-alist) vhdl-project)
14635 (setq pos (1- (match-beginning 1)))))
14636 (setq project-alist (cdr project-alist))))
14637 (when pos (goto-char pos)))
14638 (select-frame last-frame)
14639 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14640 t)
14641
14642(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14643 "Highlight all design units that are contained in the current file.
14644NO-POSITION non-nil means do not re-position cursor."
14645 (let ((last-frame (selected-frame))
3dcb36b7
JB
14646 (project-list vhdl-speedbar-shown-project-list)
14647 file-alist pos file-name)
5eabfe72 14648 ;; get current file name
3dcb36b7
JB
14649 (if (fboundp 'speedbar-select-attached-frame)
14650 (speedbar-select-attached-frame)
14651 (select-frame speedbar-attached-frame))
5eabfe72 14652 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14653 (when (and vhdl-speedbar-update-current-unit
14654 (or always (not (equal file-name speedbar-last-selected-file))))
14655 (if vhdl-speedbar-show-projects
14656 (while project-list
14657 (setq file-alist (append file-alist (aget vhdl-file-alist
14658 (car project-list) t)))
14659 (setq project-list (cdr project-list)))
14660 (setq file-alist (aget vhdl-file-alist
14661 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14662 (select-frame speedbar-frame)
14663 (set-buffer speedbar-buffer)
14664 (speedbar-with-writable
3dcb36b7 14665 (vhdl-prepare-search-1
5eabfe72
KH
14666 (save-excursion
14667 ;; unhighlight last units
3dcb36b7 14668 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14669 (vhdl-speedbar-update-units
3dcb36b7 14670 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14671 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
5eabfe72 14672 (vhdl-speedbar-update-units
3dcb36b7 14673 "{.} " (nth 1 file-entry)
0a2e512a 14674 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
5eabfe72 14675 (vhdl-speedbar-update-units
3dcb36b7 14676 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14677 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
5eabfe72 14678 (vhdl-speedbar-update-units
3dcb36b7 14679 "[]>] " (nth 4 file-entry)
0a2e512a 14680 speedbar-last-selected-file 'vhdl-speedbar-package-face)
5eabfe72 14681 (vhdl-speedbar-update-units
3dcb36b7 14682 "\\[.\\].+(" '("body")
0a2e512a 14683 speedbar-last-selected-file 'vhdl-speedbar-package-face)
3dcb36b7
JB
14684 (vhdl-speedbar-update-units
14685 "> " (nth 6 file-entry)
0a2e512a 14686 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
5eabfe72 14687 ;; highlight current units
3dcb36b7
JB
14688 (let* ((file-entry (aget file-alist file-name t)))
14689 (setq
14690 pos (vhdl-speedbar-update-units
14691 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14692 file-name 'vhdl-speedbar-entity-selected-face pos)
3dcb36b7
JB
14693 pos (vhdl-speedbar-update-units
14694 "{.} " (nth 1 file-entry)
0a2e512a 14695 file-name 'vhdl-speedbar-architecture-selected-face pos)
3dcb36b7
JB
14696 pos (vhdl-speedbar-update-units
14697 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14698 file-name 'vhdl-speedbar-configuration-selected-face pos)
3dcb36b7
JB
14699 pos (vhdl-speedbar-update-units
14700 "[]>] " (nth 4 file-entry)
0a2e512a 14701 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14702 pos (vhdl-speedbar-update-units
14703 "\\[.\\].+(" '("body")
0a2e512a 14704 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14705 pos (vhdl-speedbar-update-units
14706 "> " (nth 6 file-entry)
0a2e512a 14707 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14708 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14709 (when (and pos (not no-position))
14710 (goto-char pos)
14711 (speedbar-center-buffer-smartly)
5eabfe72
KH
14712 (speedbar-position-cursor-on-line))
14713 (setq speedbar-last-selected-file file-name))
14714 (select-frame last-frame)
14715 t))
14716
3dcb36b7
JB
14717(defun vhdl-speedbar-update-units (text unit-list file-name face
14718 &optional pos)
5eabfe72 14719 "Help function to highlight design units."
3dcb36b7
JB
14720 (while unit-list
14721 (goto-char (point-min))
14722 (while (re-search-forward
14723 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14724 (when (equal file-name (car (get-text-property
14725 (match-beginning 1) 'speedbar-token)))
14726 (setq pos (or pos (point-marker)))
14727 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14728 (setq unit-list (cdr unit-list)))
14729 pos)
5eabfe72
KH
14730
14731(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14732 ent-name ent-file-marker
14733 arch-name arch-file-marker
14734 conf-name conf-file-marker
14735 lib-name depth offset delimiter)
5eabfe72 14736 "Insert instantiation entry."
3dcb36b7
JB
14737 (let ((start (point))
14738 visible-start)
5eabfe72
KH
14739 (insert (int-to-string depth) ":")
14740 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14741 (setq visible-start (point))
14742 (insert-char ? (* depth speedbar-indentation-width))
14743 (while (> offset 0)
14744 (insert "|")
14745 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14746 (setq offset (1- offset)))
14747 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14748 (setq start (point))
3dcb36b7
JB
14749 (insert ">")
14750 (speedbar-make-button start (point) nil nil nil)
14751 (setq visible-start (point))
14752 (insert " ")
5eabfe72 14753 (setq start (point))
3dcb36b7
JB
14754 (if (not inst-name)
14755 (insert "(top)")
14756 (insert inst-name)
14757 (speedbar-make-button
0a2e512a 14758 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
3dcb36b7
JB
14759 'vhdl-speedbar-find-file inst-file-marker))
14760 (insert delimiter)
14761 (when ent-name
5eabfe72 14762 (setq start (point))
3dcb36b7 14763 (insert ent-name)
5eabfe72 14764 (speedbar-make-button
0a2e512a 14765 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
3dcb36b7
JB
14766 'vhdl-speedbar-find-file ent-file-marker)
14767 (when arch-name
14768 (insert " (")
14769 (setq start (point))
14770 (insert arch-name)
14771 (speedbar-make-button
0a2e512a 14772 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
3dcb36b7
JB
14773 'vhdl-speedbar-find-file arch-file-marker)
14774 (insert ")"))
14775 (when conf-name
14776 (insert " (")
14777 (setq start (point))
14778 (insert conf-name)
14779 (speedbar-make-button
0a2e512a 14780 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
3dcb36b7
JB
14781 'vhdl-speedbar-find-file conf-file-marker)
14782 (insert ")")))
14783 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14784 (setq start (point))
3dcb36b7
JB
14785 (insert " (" lib-name ")")
14786 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14787 'vhdl-speedbar-library-face))
5eabfe72 14788 (insert-char ?\n 1)
3dcb36b7 14789 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14790
3dcb36b7
JB
14791(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14792 body-file-marker depth)
5eabfe72 14793 "Insert package entry."
3dcb36b7
JB
14794 (let ((start (point))
14795 visible-start)
5eabfe72
KH
14796 (insert (int-to-string depth) ":")
14797 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14798 (setq visible-start (point))
14799 (insert-char ? (* depth speedbar-indentation-width))
14800 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14801 (setq start (point))
3dcb36b7
JB
14802 (insert "[+]")
14803 (speedbar-make-button
14804 start (point) 'speedbar-button-face 'speedbar-highlight-face
14805 'vhdl-speedbar-expand-package pack-key)
14806 (setq visible-start (point))
14807 (insert-char ? 1 nil)
5eabfe72
KH
14808 (setq start (point))
14809 (insert pack-name)
14810 (speedbar-make-button
0a2e512a 14811 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14812 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14813 (unless (car pack-file-marker)
14814 (insert "!"))
5eabfe72 14815 (when (car body-file-marker)
5eabfe72 14816 (insert " (")
5eabfe72
KH
14817 (setq start (point))
14818 (insert "body")
14819 (speedbar-make-button
0a2e512a 14820 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14821 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14822 (insert ")"))
5eabfe72 14823 (insert-char ?\n 1)
3dcb36b7 14824 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14825
3dcb36b7 14826(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
0a2e512a 14827 pack-body-file-marker depth)
3dcb36b7
JB
14828 "Insert used package entry."
14829 (let ((start (point))
14830 visible-start)
14831 (insert (int-to-string depth) ":")
14832 (put-text-property start (point) 'invisible t)
14833 (setq visible-start (point))
14834 (insert-char ? (* depth speedbar-indentation-width))
14835 (put-text-property visible-start (point) 'invisible nil)
14836 (setq start (point))
14837 (insert ">")
14838 (speedbar-make-button start (point) nil nil nil)
14839 (setq visible-start (point))
14840 (insert " ")
14841 (setq start (point))
14842 (insert pack-name)
14843 (speedbar-make-button
0a2e512a 14844 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
3dcb36b7 14845 'vhdl-speedbar-find-file pack-file-marker)
0a2e512a
RF
14846 (when (car pack-body-file-marker)
14847 (insert " (")
14848 (setq start (point))
14849 (insert "body")
14850 (speedbar-make-button
14851 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14852 'vhdl-speedbar-find-file pack-body-file-marker)
14853 (insert ")"))
3dcb36b7
JB
14854 (setq start (point))
14855 (insert " (" lib-name ")")
14856 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14857 'vhdl-speedbar-library-face)
3dcb36b7
JB
14858 (insert-char ?\n 1)
14859 (put-text-property visible-start (point) 'invisible nil)))
14860
14861(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14862 func-body-file-marker
14863 depth)
14864 "Insert subprogram entry."
14865 (let ((start (point))
14866 visible-start)
5eabfe72
KH
14867 (insert (int-to-string depth) ":")
14868 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14869 (setq visible-start (point))
14870 (insert-char ? (* depth speedbar-indentation-width))
14871 (put-text-property visible-start (point) 'invisible nil)
14872 (setq start (point))
14873 (insert ">")
14874 (speedbar-make-button start (point) nil nil nil)
14875 (setq visible-start (point))
14876 (insert " ")
5eabfe72 14877 (setq start (point))
3dcb36b7
JB
14878 (insert func-name)
14879 (speedbar-make-button
0a2e512a 14880 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14881 'vhdl-speedbar-find-file func-file-marker)
14882 (when (car func-body-file-marker)
14883 (insert " (")
14884 (setq start (point))
14885 (insert "body")
14886 (speedbar-make-button
0a2e512a 14887 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14888 'vhdl-speedbar-find-file func-body-file-marker)
14889 (insert ")"))
14890 (insert-char ?\n 1)
14891 (put-text-property visible-start (point) 'invisible nil)))
14892
14893(defun vhdl-speedbar-make-title-line (text &optional depth)
14894 "Insert design unit title entry."
14895 (let ((start (point))
14896 visible-start)
14897 (when depth
14898 (insert (int-to-string depth) ":")
14899 (put-text-property start (point) 'invisible t))
14900 (setq visible-start (point))
14901 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14902 (setq start (point))
14903 (insert text)
14904 (speedbar-make-button start (point) nil nil nil nil)
14905 (insert-char ?\n 1)
3dcb36b7 14906 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14907
14908(defun vhdl-speedbar-insert-dirs (files level)
14909 "Insert subdirectories."
14910 (let ((dirs (car files)))
14911 (while dirs
14912 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14913 (car dirs) 'speedbar-dir-follow nil
14914 'speedbar-directory-face level)
14915 (setq dirs (cdr dirs)))))
14916
14917(defun vhdl-speedbar-dired (text token indent)
14918 "Speedbar click handler for directory expand button in hierarchy mode."
14919 (cond ((string-match "+" text) ; we have to expand this dir
14920 (setq speedbar-shown-directories
14921 (cons (expand-file-name
7752250e 14922 (concat (speedbar-line-directory indent) token "/"))
5eabfe72
KH
14923 speedbar-shown-directories))
14924 (speedbar-change-expand-button-char ?-)
14925 (speedbar-reset-scanners)
14926 (speedbar-with-writable
14927 (save-excursion
14928 (end-of-line) (forward-char 1)
14929 (vhdl-speedbar-insert-dirs
14930 (speedbar-file-lists
7752250e 14931 (concat (speedbar-line-directory indent) token "/"))
5eabfe72
KH
14932 (1+ indent))
14933 (speedbar-reset-scanners)
14934 (vhdl-speedbar-insert-dir-hierarchy
14935 (abbreviate-file-name
7752250e 14936 (concat (speedbar-line-directory indent) token "/"))
5eabfe72 14937 (1+ indent) speedbar-power-click)))
3dcb36b7 14938 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
14939 ((string-match "-" text) ; we have to contract this node
14940 (speedbar-reset-scanners)
14941 (let ((oldl speedbar-shown-directories)
14942 (newl nil)
14943 (td (expand-file-name
7752250e 14944 (concat (speedbar-line-directory indent) token))))
5eabfe72
KH
14945 (while oldl
14946 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14947 (setq newl (cons (car oldl) newl)))
14948 (setq oldl (cdr oldl)))
14949 (setq speedbar-shown-directories (nreverse newl)))
14950 (speedbar-change-expand-button-char ?+)
14951 (speedbar-delete-subblock indent))
3dcb36b7
JB
14952 (t (error "Nothing to display")))
14953 (when (equal (selected-frame) speedbar-frame)
14954 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14955
14956(defun vhdl-speedbar-item-info ()
14957 "Derive and display information about this line item."
14958 (save-excursion
14959 (beginning-of-line)
14960 ;; skip invisible number info
3dcb36b7 14961 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 14962 (cond
3dcb36b7
JB
14963 ;; project/directory entry
14964 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14965 (if vhdl-speedbar-show-projects
14966 (message "Project \"%s\"" (match-string-no-properties 1))
14967 (speedbar-files-item-info)))
5eabfe72 14968 ;; design unit entry
3dcb36b7
JB
14969 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14970 (goto-char (match-end 1))
5eabfe72
KH
14971 (let ((face (get-text-property (point) 'face)))
14972 (message
14973 "%s \"%s\" in \"%s\""
14974 ;; design unit kind
0a2e512a
RF
14975 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14976 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 14977 (if (equal (match-string 2) ">") "Component" "Entity"))
0a2e512a
RF
14978 ((or (eq face 'vhdl-speedbar-architecture-face)
14979 (eq face 'vhdl-speedbar-architecture-selected-face))
5eabfe72 14980 "Architecture")
0a2e512a
RF
14981 ((or (eq face 'vhdl-speedbar-configuration-face)
14982 (eq face 'vhdl-speedbar-configuration-selected-face))
5eabfe72 14983 "Configuration")
0a2e512a
RF
14984 ((or (eq face 'vhdl-speedbar-package-face)
14985 (eq face 'vhdl-speedbar-package-selected-face))
5eabfe72 14986 "Package")
0a2e512a
RF
14987 ((or (eq face 'vhdl-speedbar-instantiation-face)
14988 (eq face 'vhdl-speedbar-instantiation-selected-face))
5eabfe72 14989 "Instantiation")
0a2e512a 14990 ((eq face 'vhdl-speedbar-subprogram-face)
3dcb36b7 14991 "Subprogram")
5eabfe72
KH
14992 (t ""))
14993 ;; design unit name
14994 (buffer-substring-no-properties
3dcb36b7
JB
14995 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14996 (match-end 1))
5eabfe72 14997 ;; file name
3dcb36b7
JB
14998 (file-relative-name
14999 (or (car (get-text-property (point) 'speedbar-token))
15000 "?")
15001 (vhdl-default-directory)))))
15002 (t (message "")))))
15003
15004(defun vhdl-speedbar-line-text ()
15005 "Calls `speedbar-line-text' and removes text properties."
15006 (let ((string (speedbar-line-text)))
15007 (set-text-properties 0 (length string) nil string)
15008 string))
5eabfe72 15009
0a2e512a
RF
15010(defun vhdl-speedbar-higher-text ()
15011 "Get speedbar-line-text of higher level."
15012 (let (depth string)
15013 (save-excursion
15014 (beginning-of-line)
15015 (looking-at "^\\([0-9]+\\):")
15016 (setq depth (string-to-number (match-string 1)))
15017 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15018 (setq string (match-string 1))
15019 (set-text-properties 0 (length string) nil string)
15020 string))))
15021
5eabfe72
KH
15022;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15023;; Help functions
d2ddb974 15024
3dcb36b7
JB
15025(defun vhdl-speedbar-line-key (&optional indent)
15026 "Get currently displayed directory of project name."
15027 (if vhdl-speedbar-show-projects
15028 (vhdl-speedbar-line-project)
15029 (abbreviate-file-name
7752250e 15030 (file-name-as-directory (speedbar-line-directory indent)))))
3dcb36b7
JB
15031
15032(defun vhdl-speedbar-line-project (&optional indent)
15033 "Get currently displayed project name."
15034 (and vhdl-speedbar-show-projects
15035 (save-excursion
15036 (end-of-line)
15037 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15038 (match-string-no-properties 1))))
15039
15040(defun vhdl-add-modified-file ()
15041 "Add file to `vhdl-modified-file-list'."
15042 (when vhdl-file-alist
15043 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15044 nil)
5eabfe72
KH
15045
15046(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
15047 "Resolve path wildcards in PATH-LIST."
15048 (let (path-list-1 path-list-2 path-beg path-end dir)
15049 ;; eliminate non-existent directories
5eabfe72
KH
15050 (while path-list
15051 (setq dir (car path-list))
3dcb36b7
JB
15052 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15053 (if (file-directory-p (match-string 2 dir))
15054 (setq path-list-1 (cons dir path-list-1))
15055 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 15056 (setq path-list (cdr path-list)))
3dcb36b7 15057 ;; resolve path wildcards
5eabfe72
KH
15058 (while path-list-1
15059 (setq dir (car path-list-1))
3dcb36b7 15060 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
15061 (progn
15062 (setq path-beg (match-string 1 dir)
15063 path-end (match-string 5 dir))
3dcb36b7 15064 (setq path-list-1
5eabfe72
KH
15065 (append
15066 (mapcar
15067 (function
15068 (lambda (var) (concat path-beg var path-end)))
15069 (let ((all-list (vhdl-directory-files
15070 (match-string 2 dir) t
15071 (concat "\\<" (wildcard-to-regexp
15072 (match-string 4 dir)))))
15073 dir-list)
15074 (while all-list
15075 (when (file-directory-p (car all-list))
15076 (setq dir-list (cons (car all-list) dir-list)))
15077 (setq all-list (cdr all-list)))
15078 dir-list))
3dcb36b7
JB
15079 (cdr path-list-1))))
15080 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 15081 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
15082 (setq path-list-2 (cons dir path-list-2)))
15083 (setq path-list-1 (cdr path-list-1))))
15084 (nreverse path-list-2)))
5eabfe72
KH
15085
15086(defun vhdl-speedbar-goto-this-unit (directory unit)
15087 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15088 (let ((dest (point)))
3dcb36b7 15089 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
15090 (progn (goto-char (point-min)) t)
15091 (speedbar-goto-this-file directory))
15092 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15093 (progn (speedbar-position-cursor-on-line)
15094 t)
15095 (goto-char dest)
15096 nil)))
15097
15098(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
15099 "When user clicks on TEXT, load file with name and position in TOKEN.
15100Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15101is already shown in a buffer."
5eabfe72 15102 (if (not (car token))
3dcb36b7
JB
15103 (error "ERROR: File cannot be found")
15104 (let ((buffer (get-file-buffer (car token))))
15105 (speedbar-find-file-in-frame (car token))
15106 (when (or vhdl-speedbar-jump-to-unit buffer)
e6ce8c42
GM
15107 (goto-char (point-min))
15108 (forward-line (1- (cdr token)))
3dcb36b7
JB
15109 (recenter))
15110 (vhdl-speedbar-update-current-unit t t)
051897ff 15111 (speedbar-set-timer dframe-update-speed)
3dcb36b7 15112 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
15113
15114(defun vhdl-speedbar-port-copy ()
3dcb36b7 15115 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 15116 (interactive)
3dcb36b7
JB
15117 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15118 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15119 (error "ERROR: No entity/component or subprogram under cursor")
15120 (beginning-of-line)
15121 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15122 (condition-case info
15123 (let ((token (get-text-property
15124 (match-beginning 3) 'speedbar-token)))
15125 (vhdl-visit-file (car token) t
e6ce8c42
GM
15126 (progn (goto-char (point-min))
15127 (forward-line (1- (cdr token)))
3dcb36b7
JB
15128 (end-of-line)
15129 (if is-entity
15130 (vhdl-port-copy)
15131 (vhdl-subprog-copy)))))
15132 (error (error "ERROR: %s not scanned successfully\n (%s)"
15133 (if is-entity "Port" "Interface") (cadr info))))
15134 (error "ERROR: No entity/component or subprogram on current line")))))
15135
15136(defun vhdl-speedbar-place-component ()
15137 "Place the entity/component under the cursor as component."
15138 (interactive)
15139 (if (not (vhdl-speedbar-check-unit 'entity))
5bb5087f 15140 (error "ERROR: No entity/component under cursor")
3dcb36b7
JB
15141 (vhdl-speedbar-port-copy)
15142 (if (fboundp 'speedbar-select-attached-frame)
15143 (speedbar-select-attached-frame)
15144 (select-frame speedbar-attached-frame))
15145 (vhdl-compose-place-component)
15146 (select-frame speedbar-frame)))
15147
0a2e512a
RF
15148(defun vhdl-speedbar-configuration ()
15149 "Generate configuration for the architecture under the cursor."
15150 (interactive)
15151 (if (not (vhdl-speedbar-check-unit 'architecture))
15152 (error "ERROR: No architecture under cursor")
15153 (let ((arch-name (vhdl-speedbar-line-text))
15154 (ent-name (vhdl-speedbar-higher-text)))
15155 (if (fboundp 'speedbar-select-attached-frame)
15156 (speedbar-select-attached-frame)
15157 (select-frame speedbar-attached-frame))
15158 (vhdl-compose-configuration ent-name arch-name))))
15159
15160(defun vhdl-speedbar-select-mra ()
15161 "Select the architecture under the cursor as MRA."
15162 (interactive)
15163 (if (not (vhdl-speedbar-check-unit 'architecture))
15164 (error "ERROR: No architecture under cursor")
15165 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15166 (ent-key (downcase (vhdl-speedbar-higher-text)))
15167 (ent-alist (aget vhdl-entity-alist
15168 (or (vhdl-project-p) default-directory) t))
15169 (ent-entry (aget ent-alist ent-key t)))
15170 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15171 (speedbar-refresh))))
15172
3dcb36b7
JB
15173(defun vhdl-speedbar-make-design ()
15174 "Make (compile) design unit or directory/project under the cursor."
15175 (interactive)
15176 (if (not (save-excursion (beginning-of-line)
15177 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15178 (error "ERROR: No primary design unit or directory/project under cursor")
15179 (let ((is-unit (match-string 2))
15180 (unit-name (vhdl-speedbar-line-text))
15181 (vhdl-project (vhdl-speedbar-line-project))
15182 (directory (file-name-as-directory
7752250e 15183 (or (speedbar-line-file) (speedbar-line-directory)))))
3dcb36b7
JB
15184 (if (fboundp 'speedbar-select-attached-frame)
15185 (speedbar-select-attached-frame)
15186 (select-frame speedbar-attached-frame))
15187 (let ((default-directory directory))
15188 (vhdl-make (and is-unit unit-name))))))
15189
15190(defun vhdl-speedbar-generate-makefile ()
15191 "Generate Makefile for directory/project under the cursor."
15192 (interactive)
15193 (let ((vhdl-project (vhdl-speedbar-line-project))
15194 (default-directory (file-name-as-directory
7752250e 15195 (or (speedbar-line-file) (speedbar-line-directory)))))
3dcb36b7
JB
15196 (vhdl-generate-makefile)))
15197
15198(defun vhdl-speedbar-check-unit (design-unit)
15199 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15200expansion function)."
15201 (save-excursion
15202 (speedbar-position-cursor-on-line)
15203 (cond ((eq design-unit 'entity)
15204 (memq (get-text-property (match-end 0) 'face)
0a2e512a
RF
15205 '(vhdl-speedbar-entity-face
15206 vhdl-speedbar-entity-selected-face)))
15207 ((eq design-unit 'architecture)
15208 (memq (get-text-property (match-end 0) 'face)
15209 '(vhdl-speedbar-architecture-face
15210 vhdl-speedbar-architecture-selected-face)))
3dcb36b7
JB
15211 ((eq design-unit 'subprogram)
15212 (eq (get-text-property (match-end 0) 'face)
0a2e512a 15213 'vhdl-speedbar-subprogram-face))
3dcb36b7
JB
15214 (t nil))))
15215
15216(defun vhdl-speedbar-set-depth (depth)
15217 "Set hierarchy display depth to DEPTH and refresh speedbar."
15218 (setq vhdl-speedbar-hierarchy-depth depth)
15219 (speedbar-refresh))
5eabfe72
KH
15220
15221;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15222;; Fontification
15223
0a2e512a 15224(defface vhdl-speedbar-entity-face
5eabfe72
KH
15225 '((((class color) (background light)) (:foreground "ForestGreen"))
15226 (((class color) (background dark)) (:foreground "PaleGreen")))
15227 "Face used for displaying entity names."
15228 :group 'speedbar-faces)
15229
0a2e512a 15230(defface vhdl-speedbar-architecture-face
f47877ee
DN
15231 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15232 (((class color) (background light)) (:foreground "Blue"))
84c98ace 15233
5eabfe72
KH
15234 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15235 "Face used for displaying architecture names."
15236 :group 'speedbar-faces)
d2ddb974 15237
0a2e512a 15238(defface vhdl-speedbar-configuration-face
5eabfe72
KH
15239 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15240 (((class color) (background dark)) (:foreground "Salmon")))
15241 "Face used for displaying configuration names."
15242 :group 'speedbar-faces)
15243
0a2e512a 15244(defface vhdl-speedbar-package-face
5eabfe72
KH
15245 '((((class color) (background light)) (:foreground "Grey50"))
15246 (((class color) (background dark)) (:foreground "Grey80")))
15247 "Face used for displaying package names."
15248 :group 'speedbar-faces)
15249
0a2e512a 15250(defface vhdl-speedbar-library-face
3dcb36b7
JB
15251 '((((class color) (background light)) (:foreground "Purple"))
15252 (((class color) (background dark)) (:foreground "Orchid1")))
15253 "Face used for displaying library names."
15254 :group 'speedbar-faces)
15255
0a2e512a 15256(defface vhdl-speedbar-instantiation-face
5eabfe72 15257 '((((class color) (background light)) (:foreground "Brown"))
ea81d57e 15258 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
5eabfe72
KH
15259 (((class color) (background dark)) (:foreground "Yellow")))
15260 "Face used for displaying instantiation names."
15261 :group 'speedbar-faces)
15262
0a2e512a 15263(defface vhdl-speedbar-subprogram-face
3dcb36b7
JB
15264 '((((class color) (background light)) (:foreground "Orchid4"))
15265 (((class color) (background dark)) (:foreground "BurlyWood2")))
15266 "Face used for displaying subprogram names."
15267 :group 'speedbar-faces)
15268
0a2e512a 15269(defface vhdl-speedbar-entity-selected-face
5eabfe72
KH
15270 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15271 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15272 "Face used for displaying entity names."
15273 :group 'speedbar-faces)
15274
0a2e512a 15275(defface vhdl-speedbar-architecture-selected-face
f47877ee
DN
15276 '((((min-colors 88) (class color) (background light)) (:foreground
15277 "Blue1" :underline t))
15278 (((class color) (background light)) (:foreground "Blue" :underline t))
5eabfe72
KH
15279 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15280 "Face used for displaying architecture names."
15281 :group 'speedbar-faces)
15282
0a2e512a 15283(defface vhdl-speedbar-configuration-selected-face
5eabfe72
KH
15284 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15285 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15286 "Face used for displaying configuration names."
15287 :group 'speedbar-faces)
15288
0a2e512a 15289(defface vhdl-speedbar-package-selected-face
5eabfe72
KH
15290 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15291 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15292 "Face used for displaying package names."
15293 :group 'speedbar-faces)
15294
0a2e512a 15295(defface vhdl-speedbar-instantiation-selected-face
5eabfe72
KH
15296 '((((class color) (background light)) (:foreground "Brown" :underline t))
15297 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15298 "Face used for displaying instantiation names."
15299 :group 'speedbar-faces)
15300
3dcb36b7
JB
15301;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15302;; Initialization
15303
15304;; add speedbar
15305(when (fboundp 'speedbar)
15306 (condition-case ()
15307 (when (and vhdl-speedbar-auto-open
15308 (not (and (boundp 'speedbar-frame)
15309 (frame-live-p speedbar-frame))))
15310 (speedbar-frame-mode 1)
15311 (if (fboundp 'speedbar-select-attached-frame)
15312 (speedbar-select-attached-frame)
15313 (select-frame speedbar-attached-frame)))
15314 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15315
15316;; initialize speedbar
15317(if (not (boundp 'speedbar-frame))
15318 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15319 (vhdl-speedbar-initialize)
15320 (when speedbar-frame (vhdl-speedbar-refresh)))
15321
15322
15323;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15324;;; Structural composition
15325;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15326
15327(defun vhdl-get-components-package-name ()
15328 "Return the name of the components package."
15329 (let ((project (vhdl-project-p)))
15330 (if project
15331 (vhdl-replace-string (car vhdl-components-package-name)
15332 (subst-char-in-string ? ?_ project))
15333 (cdr vhdl-components-package-name))))
15334
15335(defun vhdl-compose-new-component ()
15336 "Create entity and architecture for new component."
15337 (interactive)
15338 (let* ((case-fold-search t)
15339 (ent-name (read-from-minibuffer "entity name: "
15340 nil vhdl-minibuffer-local-map))
15341 (arch-name
15342 (if (equal (cdr vhdl-compose-architecture-name) "")
15343 (read-from-minibuffer "architecture name: "
15344 nil vhdl-minibuffer-local-map)
15345 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15346 ent-file-name arch-file-name ent-buffer arch-buffer project)
15347 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15348 ;; open entity file
15349 (unless (eq vhdl-compose-create-files 'none)
15350 (setq ent-file-name
0a2e512a 15351 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15352 "." (file-name-extension (buffer-file-name))))
15353 (when (and (file-exists-p ent-file-name)
15354 (not (y-or-n-p (concat "File \"" ent-file-name
15355 "\" exists; overwrite? "))))
15356 (error "ERROR: Creating component...aborted"))
15357 (find-file ent-file-name)
15358 (erase-buffer)
15359 (set-buffer-modified-p nil))
15360 ;; insert header
15361 (if vhdl-compose-include-header
15362 (progn (vhdl-template-header)
15363 (goto-char (point-max)))
15364 (vhdl-comment-display-line) (insert "\n\n"))
15365 ;; insert library clause
15366 (vhdl-template-package-std-logic-1164)
15367 (when vhdl-use-components-package
15368 (insert "\n")
15369 (vhdl-template-standard-package (vhdl-work-library)
15370 (vhdl-get-components-package-name)))
15371 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15372 ;; insert entity declaration
15373 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15374 (vhdl-insert-keyword " IS\n")
15375 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15376 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15377 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15378 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15379 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15380 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15381 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15382 (vhdl-insert-keyword "END ")
15383 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15384 (insert ent-name ";\n\n")
15385 (vhdl-comment-display-line) (insert "\n")
15386 ;; open architecture file
15387 (if (not (eq vhdl-compose-create-files 'separate))
15388 (insert "\n")
15389 (setq ent-buffer (current-buffer))
15390 (setq arch-file-name
15391 (concat (vhdl-replace-string vhdl-architecture-file-name
0a2e512a 15392 (concat ent-name " " arch-name) t)
3dcb36b7
JB
15393 "." (file-name-extension (buffer-file-name))))
15394 (when (and (file-exists-p arch-file-name)
15395 (not (y-or-n-p (concat "File \"" arch-file-name
15396 "\" exists; overwrite? "))))
15397 (error "ERROR: Creating component...aborted"))
15398 (find-file arch-file-name)
15399 (erase-buffer)
15400 (set-buffer-modified-p nil)
15401 ;; insert header
15402 (if vhdl-compose-include-header
15403 (progn (vhdl-template-header)
15404 (goto-char (point-max)))
15405 (vhdl-comment-display-line) (insert "\n\n")))
15406 ;; insert architecture body
15407 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15408 (vhdl-insert-keyword " OF ") (insert ent-name)
15409 (vhdl-insert-keyword " IS\n\n")
15410 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15411 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15412 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15413 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15414 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15415 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15416 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15417 (vhdl-insert-keyword "BEGIN")
15418 (when vhdl-self-insert-comments
15419 (insert " -- ")
15420 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15421 (insert arch-name))
15422 (insert "\n\n")
15423 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15424 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15425 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15426 (vhdl-insert-keyword "END ")
15427 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15428 (insert arch-name ";\n\n")
0a2e512a 15429 ;; insert footer and save
3dcb36b7
JB
15430 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15431 (vhdl-template-footer)
15432 (vhdl-comment-display-line) (insert "\n"))
15433 (goto-char (point-min))
15434 (setq arch-buffer (current-buffer))
15435 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15436 (set-buffer arch-buffer) (save-buffer)
29a4e67d 15437 (message "%s"
3dcb36b7
JB
15438 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15439 (and ent-file-name
15440 (format "\n File created: \"%s\"" ent-file-name))
15441 (and arch-file-name
15442 (format "\n File created: \"%s\"" arch-file-name))))))
15443
15444(defun vhdl-compose-place-component ()
15445 "Place new component by pasting current port as component declaration and
15446component instantiation."
15447 (interactive)
15448 (if (not vhdl-port-list)
15449 (error "ERROR: No port has been read")
15450 (save-excursion
15451 (vhdl-prepare-search-2
15452 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15453 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15454 (error "ERROR: No architecture found"))
15455 (let* ((ent-name (match-string 1))
15456 (ent-file-name
0a2e512a 15457 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15458 "." (file-name-extension (buffer-file-name))))
15459 (orig-buffer (current-buffer)))
15460 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15461 ;; place component declaration
15462 (unless (or vhdl-use-components-package
15463 (vhdl-use-direct-instantiation)
15464 (save-excursion
15465 (re-search-forward
15466 (concat "^\\s-*component\\s-+"
15467 (car vhdl-port-list) "\\>") nil t)))
15468 (re-search-forward "^begin\\>" nil)
15469 (beginning-of-line)
15470 (skip-chars-backward " \t\n")
15471 (insert "\n\n") (indent-to vhdl-basic-offset)
15472 (vhdl-port-paste-component t))
15473 ;; place component instantiation
15474 (re-search-forward "^end\\>" nil)
15475 (beginning-of-line)
15476 (skip-chars-backward " \t\n")
15477 (insert "\n\n") (indent-to vhdl-basic-offset)
15478 (vhdl-port-paste-instance nil t t)
15479 ;; place use clause for used packages
15480 (when (nth 3 vhdl-port-list)
15481 ;; open entity file
15482 (when (file-exists-p ent-file-name)
15483 (find-file ent-file-name))
15484 (goto-char (point-min))
15485 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15486 (error "ERROR: Entity not found: \"%s\"" ent-name))
15487 (goto-char (match-beginning 0))
15488 (if (and (save-excursion
15489 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15490 (match-string 1))
15491 (progn (goto-char (match-end 0))
15492 (beginning-of-line 2))
15493 (insert "\n")
15494 (backward-char))
15495 (vhdl-port-paste-context-clause)
15496 (switch-to-buffer orig-buffer))
15497 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15498
15499(defun vhdl-compose-wire-components ()
15500 "Connect components."
15501 (interactive)
15502 (save-excursion
15503 (vhdl-prepare-search-2
15504 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15505 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15506 (error "ERROR: No architecture found"))
15507 (let* ((ent-name (match-string 1))
15508 (ent-file-name
0a2e512a 15509 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15510 "." (file-name-extension (buffer-file-name))))
15511 (arch-decl-pos (point-marker))
15512 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15513 (arch-end-pos (re-search-forward "^end\\>" nil))
15514 (pack-name (vhdl-get-components-package-name))
15515 (pack-file-name
0a2e512a 15516 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15517 "." (file-name-extension (buffer-file-name))))
15518 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15519 port-alist generic-alist inst-alist
15520 signal-name signal-entry signal-alist local-list written-list
15521 single-in-list multi-in-list single-out-list multi-out-list
15522 constant-name constant-entry constant-alist single-list multi-list
15523 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15524 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15525 signal-beg-pos signal-pos
15526 constant-temp-pos port-temp-pos signal-temp-pos)
15527 (message "Wiring components...")
15528 ;; process all instances
15529 (goto-char arch-stat-pos)
15530 (while (re-search-forward
15531 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15532 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15533 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15534 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15535 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15536 (setq inst-name (match-string-no-properties 1)
15537 comp-name (match-string-no-properties 4)
15538 comp-ent-name (match-string-no-properties 12)
15539 has-generic (or (match-string 7) (match-string 17)))
15540 ;; get port ...
15541 (if comp-name
15542 ;; ... from component declaration
15543 (vhdl-visit-file
15544 (when vhdl-use-components-package pack-file-name) t
15545 (save-excursion
15546 (goto-char (point-min))
15547 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15548 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15549 (vhdl-port-copy)))
15550 ;; ... from entity declaration (direct instantiation)
15551 (setq comp-ent-file-name
0a2e512a 15552 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
3dcb36b7
JB
15553 "." (file-name-extension (buffer-file-name))))
15554 (vhdl-visit-file
15555 comp-ent-file-name t
15556 (save-excursion
15557 (goto-char (point-min))
15558 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15559 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15560 (vhdl-port-copy))))
15561 (vhdl-port-flatten t)
15562 (setq generic-alist (nth 1 vhdl-port-list)
0a2e512a
RF
15563 port-alist (nth 2 vhdl-port-list)
15564 vhdl-port-list nil)
3dcb36b7
JB
15565 (setq constant-alist nil
15566 signal-alist nil)
15567 (when has-generic
15568 ;; process all constants in generic map
15569 (vhdl-forward-syntactic-ws)
15570 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15571 (setq constant-name (match-string-no-properties 3))
15572 (setq constant-entry
15573 (cons constant-name
15574 (if (match-string 1)
15575 (or (aget generic-alist (match-string 2) t)
ec3ec9cc 15576 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15577 (cdar generic-alist))))
15578 (setq constant-alist (cons constant-entry constant-alist))
15579 (setq constant-name (downcase constant-name))
15580 (if (or (member constant-name single-list)
15581 (member constant-name multi-list))
15582 (progn (setq single-list (delete constant-name single-list))
15583 (add-to-list 'multi-list constant-name))
15584 (add-to-list 'single-list constant-name))
15585 (unless (match-string 1)
15586 (setq generic-alist (cdr generic-alist)))
15587 (vhdl-forward-syntactic-ws))
15588 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15589 ;; process all signals in port map
15590 (vhdl-forward-syntactic-ws)
15591 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15592 (setq signal-name (match-string-no-properties 3))
15593 (setq signal-entry (cons signal-name
15594 (if (match-string 1)
15595 (or (aget port-alist (match-string 2) t)
ec3ec9cc 15596 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15597 (cdar port-alist))))
15598 (setq signal-alist (cons signal-entry signal-alist))
15599 (setq signal-name (downcase signal-name))
15600 (if (equal (upcase (nth 2 signal-entry)) "IN")
15601 ;; input signal
15602 (cond
15603 ((member signal-name local-list)
15604 nil)
15605 ((or (member signal-name single-out-list)
15606 (member signal-name multi-out-list))
15607 (setq single-out-list (delete signal-name single-out-list))
15608 (setq multi-out-list (delete signal-name multi-out-list))
15609 (add-to-list 'local-list signal-name))
15610 ((member signal-name single-in-list)
15611 (setq single-in-list (delete signal-name single-in-list))
15612 (add-to-list 'multi-in-list signal-name))
15613 ((not (member signal-name multi-in-list))
15614 (add-to-list 'single-in-list signal-name)))
15615 ;; output signal
15616 (cond
15617 ((member signal-name local-list)
15618 nil)
15619 ((or (member signal-name single-in-list)
15620 (member signal-name multi-in-list))
15621 (setq single-in-list (delete signal-name single-in-list))
15622 (setq multi-in-list (delete signal-name multi-in-list))
15623 (add-to-list 'local-list signal-name))
15624 ((member signal-name single-out-list)
15625 (setq single-out-list (delete signal-name single-out-list))
15626 (add-to-list 'multi-out-list signal-name))
15627 ((not (member signal-name multi-out-list))
15628 (add-to-list 'single-out-list signal-name))))
15629 (unless (match-string 1)
15630 (setq port-alist (cdr port-alist)))
15631 (vhdl-forward-syntactic-ws))
15632 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15633 (nreverse signal-alist)) inst-alist)))
15634 ;; prepare signal insertion
15635 (vhdl-goto-marker arch-decl-pos)
15636 (forward-line 1)
15637 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15638 (setq signal-pos (point-marker))
15639 (while (progn (vhdl-forward-syntactic-ws)
15640 (looking-at "signal\\>"))
15641 (beginning-of-line 2)
15642 (delete-region signal-pos (point)))
15643 (setq signal-beg-pos signal-pos)
15644 ;; open entity file
15645 (when (file-exists-p ent-file-name)
15646 (find-file ent-file-name))
15647 (goto-char (point-min))
15648 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15649 (error "ERROR: Entity not found: \"%s\"" ent-name))
15650 ;; prepare generic clause insertion
15651 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15652 (match-string 1))
15653 (goto-char (match-beginning 0))
15654 (indent-to vhdl-basic-offset)
15655 (insert "generic ();\n\n")
15656 (backward-char 4))
15657 (backward-char)
15658 (setq generic-pos (point-marker))
15659 (forward-sexp) (end-of-line)
15660 (delete-region generic-pos (point)) (delete-char 1)
15661 (insert "(\n")
15662 (when multi-list
15663 (insert "\n")
15664 (indent-to (* 2 vhdl-basic-offset))
15665 (insert "-- global generics\n"))
15666 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15667 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15668 ;; prepare port clause insertion
15669 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15670 (match-string 1))
15671 (goto-char (match-beginning 0))
15672 (indent-to vhdl-basic-offset)
15673 (insert "port ();\n\n")
15674 (backward-char 4))
15675 (backward-char)
15676 (setq port-in-pos (point-marker))
15677 (forward-sexp) (end-of-line)
15678 (delete-region port-in-pos (point)) (delete-char 1)
15679 (insert "(\n")
15680 (when (or multi-in-list multi-out-list)
15681 (insert "\n")
15682 (indent-to (* 2 vhdl-basic-offset))
15683 (insert "-- global ports\n"))
15684 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15685 port-out-pos (point-marker) port-inst-pos (point-marker)
15686 port-end-pos (point-marker))
15687 ;; insert generics, ports and signals
15688 (setq inst-alist (nreverse inst-alist))
15689 (while inst-alist
15690 (setq inst-name (nth 0 (car inst-alist))
15691 constant-alist (nth 1 (car inst-alist))
15692 signal-alist (nth 2 (car inst-alist))
15693 constant-temp-pos generic-inst-pos
15694 port-temp-pos port-inst-pos
15695 signal-temp-pos signal-pos)
15696 ;; generics
15697 (while constant-alist
15698 (setq constant-name (downcase (caar constant-alist))
15699 constant-entry (car constant-alist))
15700 (cond ((member constant-name written-list)
15701 nil)
15702 ((member constant-name multi-list)
15703 (vhdl-goto-marker generic-pos)
15704 (setq generic-end-pos
15705 (vhdl-max-marker
15706 generic-end-pos
15707 (vhdl-compose-insert-generic constant-entry)))
15708 (setq generic-pos (point-marker))
15709 (add-to-list 'written-list constant-name))
15710 (t
15711 (vhdl-goto-marker
15712 (vhdl-max-marker generic-inst-pos generic-pos))
15713 (setq generic-end-pos
15714 (vhdl-compose-insert-generic constant-entry))
15715 (setq generic-inst-pos (point-marker))
15716 (add-to-list 'written-list constant-name)))
15717 (setq constant-alist (cdr constant-alist)))
15718 (when (/= constant-temp-pos generic-inst-pos)
15719 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15720 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15721 (insert "-- generics for \"" inst-name "\"\n")
15722 (vhdl-goto-marker generic-inst-pos))
15723 ;; ports and signals
15724 (while signal-alist
15725 (setq signal-name (downcase (caar signal-alist))
15726 signal-entry (car signal-alist))
15727 (cond ((member signal-name written-list)
15728 nil)
15729 ((member signal-name multi-in-list)
15730 (vhdl-goto-marker port-in-pos)
15731 (setq port-end-pos
15732 (vhdl-max-marker
15733 port-end-pos (vhdl-compose-insert-port signal-entry)))
15734 (setq port-in-pos (point-marker))
15735 (add-to-list 'written-list signal-name))
15736 ((member signal-name multi-out-list)
15737 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15738 (setq port-end-pos
15739 (vhdl-max-marker
15740 port-end-pos (vhdl-compose-insert-port signal-entry)))
15741 (setq port-out-pos (point-marker))
15742 (add-to-list 'written-list signal-name))
15743 ((or (member signal-name single-in-list)
15744 (member signal-name single-out-list))
15745 (vhdl-goto-marker
15746 (vhdl-max-marker
15747 port-inst-pos
15748 (vhdl-max-marker port-out-pos port-in-pos)))
15749 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15750 (setq port-inst-pos (point-marker))
15751 (add-to-list 'written-list signal-name))
15752 ((equal (upcase (nth 2 signal-entry)) "OUT")
15753 (vhdl-goto-marker signal-pos)
15754 (vhdl-compose-insert-signal signal-entry)
15755 (setq signal-pos (point-marker))
15756 (add-to-list 'written-list signal-name)))
15757 (setq signal-alist (cdr signal-alist)))
15758 (when (/= port-temp-pos port-inst-pos)
15759 (vhdl-goto-marker
15760 (vhdl-max-marker port-temp-pos
15761 (vhdl-max-marker port-in-pos port-out-pos)))
15762 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15763 (insert "-- ports to \"" inst-name "\"\n")
15764 (vhdl-goto-marker port-inst-pos))
15765 (when (/= signal-temp-pos signal-pos)
15766 (vhdl-goto-marker signal-temp-pos)
15767 (insert "\n") (indent-to vhdl-basic-offset)
15768 (insert "-- outputs of \"" inst-name "\"\n")
15769 (vhdl-goto-marker signal-pos))
15770 (setq inst-alist (cdr inst-alist)))
15771 ;; finalize generic/port clause
15772 (vhdl-goto-marker generic-end-pos) (backward-char)
15773 (when (= generic-beg-pos generic-end-pos)
15774 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15775 (insert ";") (backward-char))
15776 (insert ")")
15777 (vhdl-goto-marker port-end-pos) (backward-char)
15778 (when (= port-beg-pos port-end-pos)
15779 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15780 (insert ";") (backward-char))
15781 (insert ")")
15782 ;; align everything
15783 (when vhdl-auto-align
15784 (vhdl-goto-marker generic-beg-pos)
15785 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15786 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15787 (vhdl-goto-marker signal-beg-pos)
15788 (vhdl-align-region-groups signal-beg-pos signal-pos))
15789 (switch-to-buffer (marker-buffer signal-beg-pos))
15790 (message "Wiring components...done")))))
15791
15792(defun vhdl-compose-insert-generic (entry)
15793 "Insert ENTRY as generic declaration."
15794 (let (pos)
15795 (indent-to (* 2 vhdl-basic-offset))
15796 (insert (nth 0 entry) " : " (nth 1 entry))
15797 (when (nth 2 entry)
15798 (insert " := " (nth 2 entry)))
15799 (insert ";")
15800 (setq pos (point-marker))
15801 (when (and vhdl-include-port-comments (nth 3 entry))
15802 (vhdl-comment-insert-inline (nth 3 entry) t))
15803 (insert "\n")
15804 pos))
15805
15806(defun vhdl-compose-insert-port (entry)
15807 "Insert ENTRY as port declaration."
15808 (let (pos)
15809 (indent-to (* 2 vhdl-basic-offset))
15810 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15811 (setq pos (point-marker))
15812 (when (and vhdl-include-port-comments (nth 4 entry))
15813 (vhdl-comment-insert-inline (nth 4 entry) t))
15814 (insert "\n")
15815 pos))
15816
15817(defun vhdl-compose-insert-signal (entry)
15818 "Insert ENTRY as signal declaration."
15819 (indent-to vhdl-basic-offset)
15820 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15821 (when (and vhdl-include-port-comments (nth 4 entry))
15822 (vhdl-comment-insert-inline (nth 4 entry) t))
15823 (insert "\n"))
15824
15825(defun vhdl-compose-components-package ()
15826 "Generate a package containing component declarations for all entities in the
15827current project/directory."
15828 (interactive)
15829 (vhdl-require-hierarchy-info)
15830 (let* ((project (vhdl-project-p))
15831 (pack-name (vhdl-get-components-package-name))
15832 (pack-file-name
0a2e512a 15833 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15834 "." (file-name-extension (buffer-file-name))))
15835 (ent-alist (aget vhdl-entity-alist
15836 (or project default-directory) t))
15837 (lazy-lock-minimum-size 0)
15838 clause-pos component-pos)
15839 (message "Generating components package \"%s\"..." pack-name)
15840 ;; open package file
15841 (when (and (file-exists-p pack-file-name)
15842 (not (y-or-n-p (concat "File \"" pack-file-name
15843 "\" exists; overwrite? "))))
15844 (error "ERROR: Generating components package...aborted"))
15845 (find-file pack-file-name)
15846 (erase-buffer)
15847 ;; insert header
15848 (if vhdl-compose-include-header
15849 (progn (vhdl-template-header
15850 (concat "Components package (generated by Emacs VHDL Mode "
15851 vhdl-version ")"))
15852 (goto-char (point-max)))
15853 (vhdl-comment-display-line) (insert "\n\n"))
15854 ;; insert std_logic_1164 package
15855 (vhdl-template-package-std-logic-1164)
15856 (insert "\n") (setq clause-pos (point-marker))
15857 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15858 ;; insert package declaration
15859 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15860 (vhdl-insert-keyword " IS\n\n")
15861 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15862 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15863 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15864 (indent-to vhdl-basic-offset)
15865 (setq component-pos (point-marker))
15866 (insert "\n\n") (vhdl-insert-keyword "END ")
15867 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15868 (insert pack-name ";\n\n")
15869 ;; insert footer
15870 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15871 (vhdl-template-footer)
15872 (vhdl-comment-display-line) (insert "\n"))
15873 ;; insert component declarations
15874 (while ent-alist
15875 (vhdl-visit-file (nth 2 (car ent-alist)) nil
e6ce8c42
GM
15876 (progn (goto-char (point-min))
15877 (forward-line (1- (nth 3 (car ent-alist))))
3dcb36b7
JB
15878 (end-of-line)
15879 (vhdl-port-copy)))
15880 (goto-char component-pos)
15881 (vhdl-port-paste-component t)
15882 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15883 (setq component-pos (point-marker))
15884 (goto-char clause-pos)
15885 (vhdl-port-paste-context-clause pack-name)
15886 (setq clause-pos (point-marker))
15887 (setq ent-alist (cdr ent-alist)))
15888 (goto-char (point-min))
15889 (save-buffer)
15890 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15891 pack-name pack-file-name)))
15892
0a2e512a
RF
15893(defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15894 &optional insert-conf)
15895 "Generate block configuration for architecture."
15896 (let ((margin (current-indentation))
e180ab9f 15897 (beg (point-at-bol))
0a2e512a
RF
15898 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15899 ;; insert block configuration (for architecture)
15900 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15901 (setq margin (+ margin vhdl-basic-offset))
15902 ;; process all instances
15903 (while inst-alist
15904 (setq inst-entry (car inst-alist))
15905 ;; is component?
15906 (when (nth 4 inst-entry)
15907 (setq insert-conf t)
15908 (setq inst-path (nth 9 inst-entry))
15909 ;; skip common path with previous instance
15910 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15911 (setq inst-path (cdr inst-path)
15912 inst-prev-path (cdr inst-prev-path)))
15913 ;; insert block configuration end (for previous block/generate)
15914 (while inst-prev-path
15915 (setq margin (- margin vhdl-basic-offset))
15916 (indent-to margin)
15917 (vhdl-insert-keyword "END FOR;\n")
15918 (setq inst-prev-path (cdr inst-prev-path)))
15919 ;; insert block configuration beginning (for current block/generate)
15920 (indent-to margin)
15921 (while inst-path
15922 (setq margin (+ margin vhdl-basic-offset))
15923 (vhdl-insert-keyword "FOR ")
15924 (insert (car inst-path) "\n")
15925 (indent-to margin)
15926 (setq inst-path (cdr inst-path)))
15927 ;; insert component configuration beginning
15928 (vhdl-insert-keyword "FOR ")
15929 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15930 ;; find subconfiguration
15931 (setq conf-key (nth 7 inst-entry))
15932 (setq tmp-alist conf-alist)
15933 ;; use first configuration found for instance's entity
15934 (while (and tmp-alist (null conf-key))
15935 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15936 (setq conf-key (nth 0 (car tmp-alist))))
15937 (setq tmp-alist (cdr tmp-alist)))
15938 (setq conf-entry (aget conf-alist conf-key t))
15939 ;; insert binding indication ...
15940 ;; ... with subconfiguration (if exists)
15941 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15942 (progn
15943 (indent-to (+ margin vhdl-basic-offset))
15944 (vhdl-insert-keyword "USE CONFIGURATION ")
15945 (insert (vhdl-work-library) "." (nth 0 conf-entry))
15946 (insert ";\n"))
15947 ;; ... with entity (if exists)
15948 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
15949 (when ent-entry
15950 (indent-to (+ margin vhdl-basic-offset))
15951 (vhdl-insert-keyword "USE ENTITY ")
15952 (insert (vhdl-work-library) "." (nth 0 ent-entry))
15953 ;; insert architecture name (if architecture exists)
15954 (when (nth 3 ent-entry)
15955 (setq arch-name
15956 ;; choose architecture name a) from configuration,
15957 ;; b) from mra, or c) from first architecture
15958 (or (nth 0 (aget (nth 3 ent-entry)
15959 (or (nth 6 inst-entry)
15960 (nth 4 ent-entry)) t))
15961 (nth 1 (car (nth 3 ent-entry)))))
15962 (insert "(" arch-name ")"))
15963 (insert ";\n")
15964 ;; insert block configuration (for architecture of subcomponent)
15965 (when (and vhdl-compose-configuration-hierarchical
15966 (nth 3 ent-entry))
15967 (indent-to (+ margin vhdl-basic-offset))
15968 (vhdl-compose-configuration-architecture
15969 (nth 0 ent-entry) arch-name
15970 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
15971 ;; insert component configuration end
15972 (indent-to margin)
15973 (vhdl-insert-keyword "END FOR;\n")
15974 (setq inst-prev-path (nth 9 inst-entry)))
15975 (setq inst-alist (cdr inst-alist)))
15976 ;; insert block configuration end (for block/generate)
15977 (while inst-prev-path
15978 (setq margin (- margin vhdl-basic-offset))
15979 (indent-to margin)
15980 (vhdl-insert-keyword "END FOR;\n")
15981 (setq inst-prev-path (cdr inst-prev-path)))
15982 (indent-to (- margin vhdl-basic-offset))
15983 ;; insert block configuration end or remove beginning (for architecture)
15984 (if insert-conf
15985 (vhdl-insert-keyword "END FOR;\n")
15986 (delete-region beg (point)))))
15987
15988(defun vhdl-compose-configuration (&optional ent-name arch-name)
15989 "Generate configuration declaration."
15990 (interactive)
15991 (vhdl-require-hierarchy-info)
15992 (let ((ent-alist (aget vhdl-entity-alist
15993 (or (vhdl-project-p) default-directory) t))
15994 (conf-alist (aget vhdl-config-alist
15995 (or (vhdl-project-p) default-directory) t))
15996 (from-speedbar ent-name)
15997 inst-alist conf-name conf-file-name pos)
15998 (vhdl-prepare-search-2
15999 ;; get entity and architecture name
16000 (unless ent-name
16001 (save-excursion
16002 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16003 (not (equal "END" (upcase (match-string 1))))
16004 (setq ent-name (match-string-no-properties 3))
16005 (setq arch-name (match-string-no-properties 2)))
16006 (error "ERROR: Not within an architecture"))))
16007 (setq conf-name (vhdl-replace-string
16008 vhdl-compose-configuration-name
16009 (concat ent-name " " arch-name)))
16010 (setq inst-alist
16011 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16012 (downcase arch-name) t))))
16013 (message "Generating configuration \"%s\"..." conf-name)
16014 (if vhdl-compose-configuration-create-file
16015 ;; open configuration file
16016 (progn
16017 (setq conf-file-name
16018 (concat (vhdl-replace-string vhdl-configuration-file-name
16019 conf-name t)
16020 "." (file-name-extension (buffer-file-name))))
16021 (when (and (file-exists-p conf-file-name)
16022 (not (y-or-n-p (concat "File \"" conf-file-name
16023 "\" exists; overwrite? "))))
16024 (error "ERROR: Creating configuration...aborted"))
16025 (find-file conf-file-name)
16026 (erase-buffer)
16027 (set-buffer-modified-p nil)
16028 ;; insert header
16029 (if vhdl-compose-include-header
16030 (progn (vhdl-template-header
16031 (concat "Configuration declaration for design \""
16032 ent-name "(" arch-name ")\""))
16033 (goto-char (point-max)))
16034 (vhdl-comment-display-line) (insert "\n\n")))
16035 ;; goto end of architecture
16036 (unless from-speedbar
16037 (re-search-forward "^end\\>" nil)
16038 (end-of-line) (insert "\n\n")
16039 (vhdl-comment-display-line) (insert "\n\n")))
16040 ;; insert library clause
16041 (setq pos (point))
16042 (vhdl-template-standard-package (vhdl-work-library) nil)
16043 (when (/= pos (point))
16044 (insert "\n\n"))
16045 ;; insert configuration
16046 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16047 (vhdl-insert-keyword " OF ") (insert ent-name)
16048 (vhdl-insert-keyword " IS\n")
16049 (indent-to vhdl-basic-offset)
16050 ;; insert block configuration (for architecture)
16051 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16052 (vhdl-insert-keyword "END ") (insert conf-name ";")
16053 (when conf-file-name
16054 ;; insert footer and save
16055 (insert "\n\n")
16056 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16057 (vhdl-template-footer)
16058 (vhdl-comment-display-line) (insert "\n"))
16059 (save-buffer))
29a4e67d 16060 (message "%s"
0a2e512a
RF
16061 (concat (format "Generating configuration \"%s\"...done" conf-name)
16062 (and conf-file-name
16063 (format "\n File created: \"%s\"" conf-file-name))))))
16064
3dcb36b7
JB
16065
16066;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16067;;; Compilation / Makefile generation
16068;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16069;; (using `compile.el')
16070
16071(defun vhdl-makefile-name ()
16072 "Return the Makefile name of the current project or the current compiler if
16073no project is defined."
16074 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16075 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16076 (vhdl-replace-string
16077 (cons "\\(.*\\)\n\\(.*\\)"
16078 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16079 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16080
16081(defun vhdl-compile-directory ()
16082 "Return the directory where compilation/make should be run."
16083 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16084 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16085 (directory (vhdl-resolve-env-variable
16086 (if project
16087 (vhdl-replace-string
16088 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16089 (nth 6 compiler)))))
16090 (file-name-as-directory
16091 (if (file-name-absolute-p directory)
16092 directory
16093 (expand-file-name directory (vhdl-default-directory))))))
16094
16095(defun vhdl-uniquify (in-list)
16096 "Remove duplicate elements from IN-LIST."
16097 (let (out-list)
16098 (while in-list
16099 (add-to-list 'out-list (car in-list))
16100 (setq in-list (cdr in-list)))
16101 out-list))
16102
16103(defun vhdl-set-compiler (name)
16104 "Set current compiler to NAME."
16105 (interactive
16106 (list (let ((completion-ignore-case t))
16107 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16108 (if (assoc name vhdl-compiler-alist)
16109 (progn (setq vhdl-compiler name)
16110 (message "Current compiler: \"%s\"" vhdl-compiler))
16111 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16112
16113;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16114;; Compilation
16115
16116(defun vhdl-compile-init ()
16117 "Initialize for compilation."
16118 (when (or (null compilation-error-regexp-alist)
16119 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16120 compilation-error-regexp-alist)))
16121 ;; `compilation-error-regexp-alist'
16122 (let ((commands-alist vhdl-compiler-alist)
16123 regexp-alist sublist)
16124 (while commands-alist
16125 (setq sublist (nth 11 (car commands-alist)))
16126 (unless (or (equal "" (car sublist))
16127 (assoc (car sublist) regexp-alist))
16128 (setq regexp-alist (cons (list (nth 0 sublist)
16129 (if (= 0 (nth 1 sublist))
f8246027 16130 (if (featurep 'xemacs) 9 nil)
3dcb36b7
JB
16131 (nth 1 sublist))
16132 (nth 2 sublist) (nth 3 sublist))
16133 regexp-alist)))
16134 (setq commands-alist (cdr commands-alist)))
16135 (setq compilation-error-regexp-alist
16136 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16137 ;; `compilation-file-regexp-alist'
16138 (let ((commands-alist vhdl-compiler-alist)
16139 regexp-alist sublist)
16140 ;; matches vhdl-mode file name output
16141 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16142 (while commands-alist
16143 (setq sublist (nth 12 (car commands-alist)))
16144 (unless (or (equal "" (car sublist))
16145 (assoc (car sublist) regexp-alist))
16146 (setq regexp-alist (cons sublist regexp-alist)))
16147 (setq commands-alist (cdr commands-alist)))
16148 (setq compilation-file-regexp-alist
16149 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16150
16151(defvar vhdl-compile-file-name nil
16152 "Name of file to be compiled.")
16153
16154(defun vhdl-compile-print-file-name ()
16155 "Function called within `compile' to print out file name for compilers that
16156do not print any file names."
16157 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16158
16159(defun vhdl-get-compile-options (project compiler file-name
16160 &optional file-options-only)
16161 "Get compiler options. Returning nil means do not compile this file."
16162 (let* ((compiler-options (nth 1 compiler))
16163 (project-entry (aget (nth 4 project) vhdl-compiler))
16164 (project-options (nth 0 project-entry))
16165 (exception-list (and file-name (nth 2 project-entry)))
16166 (work-library (vhdl-work-library))
16167 (case-fold-search nil)
16168 file-options)
16169 (while (and exception-list
16170 (not (string-match (caar exception-list) file-name)))
16171 (setq exception-list (cdr exception-list)))
16172 (if (and exception-list (not (cdar exception-list)))
16173 nil
16174 (if (and file-options-only (not exception-list))
16175 'default
16176 (setq file-options (cdar exception-list))
16177 ;; insert library name in compiler-specific options
16178 (setq compiler-options
16179 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16180 work-library))
16181 ;; insert compiler-specific options in project-specific options
16182 (when project-options
16183 (setq project-options
16184 (vhdl-replace-string
16185 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16186 (concat work-library "\n" compiler-options))))
16187 ;; insert project-specific options in file-specific options
16188 (when file-options
16189 (setq file-options
16190 (vhdl-replace-string
16191 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16192 (concat work-library "\n" compiler-options "\n"
16193 project-options))))
16194 ;; return options
16195 (or file-options project-options compiler-options)))))
16196
16197(defun vhdl-get-make-options (project compiler)
16198 "Get make options."
16199 (let* ((compiler-options (nth 3 compiler))
16200 (project-entry (aget (nth 4 project) vhdl-compiler))
16201 (project-options (nth 1 project-entry))
16202 (makefile-name (vhdl-makefile-name)))
16203 ;; insert Makefile name in compiler-specific options
16204 (setq compiler-options
16205 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16206 makefile-name))
16207 ;; insert compiler-specific options in project-specific options
16208 (when project-options
16209 (setq project-options
16210 (vhdl-replace-string
16211 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16212 (concat makefile-name "\n" compiler-options))))
16213 ;; return options
16214 (or project-options compiler-options)))
16215
16216(defun vhdl-compile ()
16217 "Compile current buffer using the VHDL compiler specified in
16218`vhdl-compiler'."
16219 (interactive)
16220 (vhdl-compile-init)
16221 (let* ((project (aget vhdl-project-alist vhdl-project))
16222 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16223 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16224 (command (nth 0 compiler))
16225 (file-name (buffer-file-name))
16226 (options (vhdl-get-compile-options project compiler file-name))
16227 (default-directory (vhdl-compile-directory))
16228 compilation-process-setup-function)
16229 (unless (file-directory-p default-directory)
16230 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16231 ;; put file name into quotes if it contains spaces
16232 (when (string-match " " file-name)
16233 (setq file-name (concat "\"" file-name "\"")))
16234 ;; print out file name if compiler does not
16235 (setq vhdl-compile-file-name (buffer-file-name))
16236 (when (and (= 0 (nth 1 (nth 10 compiler)))
16237 (= 0 (nth 1 (nth 11 compiler))))
16238 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16239 ;; run compilation
16240 (if options
16241 (when command
16242 (compile (concat command " " options " " file-name)))
16243 (vhdl-warning "Your project settings tell me not to compile this file"))))
16244
0a2e512a
RF
16245(defvar vhdl-make-target "all"
16246 "Default target for `vhdl-make' command.")
16247
3dcb36b7
JB
16248(defun vhdl-make (&optional target)
16249 "Call make command for compilation of all updated source files (requires
16250`Makefile'). Optional argument TARGET allows to compile the design
16251specified by a target."
16252 (interactive)
0a2e512a
RF
16253 (setq vhdl-make-target
16254 (or target (read-from-minibuffer "Target: " vhdl-make-target
16255 vhdl-minibuffer-local-map)))
3dcb36b7
JB
16256 (vhdl-compile-init)
16257 (let* ((project (aget vhdl-project-alist vhdl-project))
16258 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16259 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16260 (command (nth 2 compiler))
16261 (options (vhdl-get-make-options project compiler))
16262 (default-directory (vhdl-compile-directory)))
16263 (unless (file-directory-p default-directory)
16264 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16265 ;; run make
16266 (compile (concat (if (equal command "") "make" command)
0a2e512a 16267 " " options " " vhdl-make-target))))
3dcb36b7
JB
16268
16269;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16270;; Makefile generation
16271
16272(defun vhdl-generate-makefile ()
16273 "Generate `Makefile'."
16274 (interactive)
16275 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16276 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16277 (command (nth 4 compiler)))
16278 ;; generate makefile
16279 (if command
16280 (let ((default-directory (vhdl-compile-directory)))
16281 (compile (vhdl-replace-string
16282 (cons "\\(.*\\) \\(.*\\)" command)
16283 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16284 (vhdl-generate-makefile-1))))
16285
16286(defun vhdl-get-packages (lib-alist work-library)
16287 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16288 (let (pack-list)
16289 (while lib-alist
16290 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16291 (setq pack-list (cons (cdar lib-alist) pack-list)))
16292 (setq lib-alist (cdr lib-alist)))
16293 pack-list))
16294
16295(defun vhdl-generate-makefile-1 ()
16296 "Generate Makefile for current project or directory."
16297 ;; scan hierarchy if required
16298 (if (vhdl-project-p)
16299 (unless (or (assoc vhdl-project vhdl-file-alist)
16300 (vhdl-load-cache vhdl-project))
16301 (vhdl-scan-project-contents vhdl-project))
16302 (let ((directory (abbreviate-file-name default-directory)))
16303 (unless (or (assoc directory vhdl-file-alist)
16304 (vhdl-load-cache directory))
16305 (vhdl-scan-directory-contents directory))))
16306 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16307 (project (vhdl-project-p))
16308 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16309 (conf-alist (aget vhdl-config-alist (or project directory) t))
16310 (pack-alist (aget vhdl-package-alist (or project directory) t))
16311 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16312 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16313 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16314 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16315 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16316 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16317 (adjust-case (nth 5 regexp-list))
16318 (work-library (downcase (vhdl-work-library)))
16319 (compile-directory (expand-file-name (vhdl-compile-directory)
16320 default-directory))
16321 (makefile-name (vhdl-makefile-name))
16322 rule-alist arch-alist inst-alist
16323 target-list depend-list unit-list prim-list second-list subcomp-list
16324 lib-alist lib-body-alist pack-list all-pack-list
16325 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16326 conf-key conf-file-name pack-key pack-file-name
16327 ent-entry arch-entry conf-entry pack-entry inst-entry
16328 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16329 tmp-key tmp-list rule)
16330 ;; check prerequisites
16331 (unless (file-exists-p compile-directory)
16332 (make-directory compile-directory t))
16333 (unless regexp-list
16334 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16335 vhdl-compiler))
16336 (message "Generating makefile \"%s\"..." makefile-name)
16337 ;; rules for all entities
16338 (setq tmp-list ent-alist)
16339 (while ent-alist
16340 (setq ent-entry (car ent-alist)
16341 ent-key (nth 0 ent-entry))
16342 (when (nth 2 ent-entry)
16343 (setq ent-file-name (file-relative-name
16344 (nth 2 ent-entry) compile-directory)
16345 arch-alist (nth 4 ent-entry)
0a2e512a 16346 lib-alist (nth 6 ent-entry)
3dcb36b7
JB
16347 rule (aget rule-alist ent-file-name)
16348 target-list (nth 0 rule)
16349 depend-list (nth 1 rule)
16350 second-list nil
16351 subcomp-list nil)
16352 (setq tmp-key (vhdl-replace-string
16353 ent-regexp (funcall adjust-case ent-key)))
16354 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16355 ;; rule target for this entity
16356 (setq target-list (cons ent-key target-list))
16357 ;; rule dependencies for all used packages
16358 (setq pack-list (vhdl-get-packages lib-alist work-library))
16359 (setq depend-list (append depend-list pack-list))
16360 (setq all-pack-list pack-list)
16361 ;; add rule
16362 (aput 'rule-alist ent-file-name (list target-list depend-list))
16363 ;; rules for all corresponding architectures
16364 (while arch-alist
16365 (setq arch-entry (car arch-alist)
16366 arch-key (nth 0 arch-entry)
16367 ent-arch-key (concat ent-key "-" arch-key)
16368 arch-file-name (file-relative-name (nth 2 arch-entry)
16369 compile-directory)
16370 inst-alist (nth 4 arch-entry)
16371 lib-alist (nth 5 arch-entry)
16372 rule (aget rule-alist arch-file-name)
16373 target-list (nth 0 rule)
16374 depend-list (nth 1 rule))
16375 (setq tmp-key (vhdl-replace-string
16376 arch-regexp
16377 (funcall adjust-case (concat arch-key " " ent-key))))
16378 (setq unit-list
16379 (cons (cons ent-arch-key tmp-key) unit-list))
16380 (setq second-list (cons ent-arch-key second-list))
16381 ;; rule target for this architecture
16382 (setq target-list (cons ent-arch-key target-list))
16383 ;; rule dependency for corresponding entity
16384 (setq depend-list (cons ent-key depend-list))
16385 ;; rule dependencies for contained component instantiations
16386 (while inst-alist
16387 (setq inst-entry (car inst-alist))
16388 (when (or (null (nth 8 inst-entry))
16389 (equal (downcase (nth 8 inst-entry)) work-library))
16390 (setq inst-ent-key (or (nth 7 inst-entry)
16391 (nth 5 inst-entry)))
16392 (setq depend-list (cons inst-ent-key depend-list)
16393 subcomp-list (cons inst-ent-key subcomp-list)))
16394 (setq inst-alist (cdr inst-alist)))
16395 ;; rule dependencies for all used packages
16396 (setq pack-list (vhdl-get-packages lib-alist work-library))
16397 (setq depend-list (append depend-list pack-list))
16398 (setq all-pack-list (append all-pack-list pack-list))
16399 ;; add rule
16400 (aput 'rule-alist arch-file-name (list target-list depend-list))
16401 (setq arch-alist (cdr arch-alist)))
16402 (setq prim-list (cons (list ent-key second-list
16403 (append subcomp-list all-pack-list))
16404 prim-list)))
16405 (setq ent-alist (cdr ent-alist)))
16406 (setq ent-alist tmp-list)
16407 ;; rules for all configurations
16408 (setq tmp-list conf-alist)
16409 (while conf-alist
16410 (setq conf-entry (car conf-alist)
16411 conf-key (nth 0 conf-entry)
16412 conf-file-name (file-relative-name
16413 (nth 2 conf-entry) compile-directory)
16414 ent-key (nth 4 conf-entry)
16415 arch-key (nth 5 conf-entry)
16416 inst-alist (nth 6 conf-entry)
16417 lib-alist (nth 7 conf-entry)
16418 rule (aget rule-alist conf-file-name)
16419 target-list (nth 0 rule)
16420 depend-list (nth 1 rule)
16421 subcomp-list (list ent-key))
16422 (setq tmp-key (vhdl-replace-string
16423 conf-regexp (funcall adjust-case conf-key)))
16424 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16425 ;; rule target for this configuration
16426 (setq target-list (cons conf-key target-list))
16427 ;; rule dependency for corresponding entity and architecture
16428 (setq depend-list
16429 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16430 ;; rule dependencies for used packages
16431 (setq pack-list (vhdl-get-packages lib-alist work-library))
16432 (setq depend-list (append depend-list pack-list))
16433 ;; rule dependencies for contained component configurations
16434 (while inst-alist
16435 (setq inst-entry (car inst-alist))
16436 (setq inst-ent-key (nth 2 inst-entry)
16437; comp-arch-key (nth 2 inst-entry))
16438 inst-conf-key (nth 4 inst-entry))
16439 (when (equal (downcase (nth 5 inst-entry)) work-library)
16440 (when inst-ent-key
16441 (setq depend-list (cons inst-ent-key depend-list)
16442 subcomp-list (cons inst-ent-key subcomp-list)))
16443; (when comp-arch-key
16444; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16445; depend-list)))
16446 (when inst-conf-key
16447 (setq depend-list (cons inst-conf-key depend-list)
16448 subcomp-list (cons inst-conf-key subcomp-list))))
16449 (setq inst-alist (cdr inst-alist)))
16450 ;; add rule
16451 (aput 'rule-alist conf-file-name (list target-list depend-list))
16452 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16453 prim-list))
16454 (setq conf-alist (cdr conf-alist)))
16455 (setq conf-alist tmp-list)
16456 ;; rules for all packages
16457 (setq tmp-list pack-alist)
16458 (while pack-alist
16459 (setq pack-entry (car pack-alist)
16460 pack-key (nth 0 pack-entry)
16461 pack-body-key nil)
16462 (when (nth 2 pack-entry)
16463 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16464 compile-directory)
16465 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16466 rule (aget rule-alist pack-file-name)
16467 target-list (nth 0 rule) depend-list (nth 1 rule))
16468 (setq tmp-key (vhdl-replace-string
16469 pack-regexp (funcall adjust-case pack-key)))
16470 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16471 ;; rule target for this package
16472 (setq target-list (cons pack-key target-list))
16473 ;; rule dependencies for all used packages
16474 (setq pack-list (vhdl-get-packages lib-alist work-library))
16475 (setq depend-list (append depend-list pack-list))
16476 (setq all-pack-list pack-list)
16477 ;; add rule
16478 (aput 'rule-alist pack-file-name (list target-list depend-list))
16479 ;; rules for this package's body
16480 (when (nth 7 pack-entry)
16481 (setq pack-body-key (concat pack-key "-body")
16482 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16483 compile-directory)
16484 rule (aget rule-alist pack-body-file-name)
16485 target-list (nth 0 rule)
16486 depend-list (nth 1 rule))
16487 (setq tmp-key (vhdl-replace-string
16488 pack-body-regexp (funcall adjust-case pack-key)))
16489 (setq unit-list
16490 (cons (cons pack-body-key tmp-key) unit-list))
16491 ;; rule target for this package's body
16492 (setq target-list (cons pack-body-key target-list))
16493 ;; rule dependency for corresponding package declaration
16494 (setq depend-list (cons pack-key depend-list))
16495 ;; rule dependencies for all used packages
16496 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16497 (setq depend-list (append depend-list pack-list))
16498 (setq all-pack-list (append all-pack-list pack-list))
16499 ;; add rule
16500 (aput 'rule-alist pack-body-file-name
16501 (list target-list depend-list)))
16502 (setq prim-list
16503 (cons (list pack-key (when pack-body-key (list pack-body-key))
16504 all-pack-list)
16505 prim-list)))
16506 (setq pack-alist (cdr pack-alist)))
16507 (setq pack-alist tmp-list)
16508 ;; generate Makefile
16509 (let* ((project (aget vhdl-project-alist project))
16510 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16511 (compiler-id (nth 9 compiler))
16512 (library-directory
16513 (vhdl-resolve-env-variable
16514 (vhdl-replace-string
16515 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16516 compiler-id)))
16517 (makefile-path-name (expand-file-name
16518 makefile-name compile-directory))
16519 (orig-buffer (current-buffer))
16520 cell second-list subcomp-list options unit-key unit-name)
16521 ;; sort lists
16522 (setq unit-list (vhdl-sort-alist unit-list))
16523 (setq prim-list (vhdl-sort-alist prim-list))
16524 (setq tmp-list rule-alist)
16525 (while tmp-list ; pre-sort rule targets
16526 (setq cell (cdar tmp-list))
16527 (setcar cell (sort (car cell) 'string<))
16528 (setq tmp-list (cdr tmp-list)))
16529 (setq rule-alist ; sort by first rule target
16530 (sort rule-alist
16531 (function (lambda (a b)
16532 (string< (car (cadr a)) (car (cadr b)))))))
16533 ;; open and clear Makefile
16534 (set-buffer (find-file-noselect makefile-path-name t t))
16535 (erase-buffer)
16536 (insert "# -*- Makefile -*-\n"
16537 "### " (file-name-nondirectory makefile-name)
16538 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16539 "\n")
16540 (if project
16541 (insert "\n# Project : " (nth 0 project))
16542 (insert "\n# Directory : \"" directory "\""))
16543 (insert "\n# Platform : " vhdl-compiler
16544 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16545 (user-login-name) "\n")
16546 ;; insert compile and option variable settings
16547 (insert "\n\n# Define compilation command and options\n"
16548 "\nCOMPILE = " (nth 0 compiler)
16549 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16550 "\n")
16551 ;; insert library paths
16552 (setq library-directory
16553 (directory-file-name
16554 (if (file-name-absolute-p library-directory)
16555 library-directory
16556 (file-relative-name
16557 (expand-file-name library-directory directory)
16558 compile-directory))))
16559 (insert "\n\n# Define library paths\n"
16560 "\nLIBRARY-" work-library " = " library-directory "\n")
16561 ;; insert variable definitions for all library unit files
16562 (insert "\n\n# Define library unit files\n")
16563 (setq tmp-list unit-list)
16564 (while unit-list
16565 (insert "\nUNIT-" work-library "-" (caar unit-list)
16566 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16567 (setq unit-list (cdr unit-list)))
16568 ;; insert variable definition for list of all library unit files
16569 (insert "\n\n\n# Define list of all library unit files\n"
16570 "\nALL_UNITS =")
16571 (setq unit-list tmp-list)
16572 (while unit-list
16573 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16574 (setq unit-list (cdr unit-list)))
16575 (insert "\n")
16576 (setq unit-list tmp-list)
16577 ;; insert `make all' rule
16578 (insert "\n\n\n# Rule for compiling entire design\n"
16579 "\nall :"
16580 " \\\n\t\tlibrary"
16581 " \\\n\t\t$(ALL_UNITS)\n")
16582 ;; insert `make clean' rule
16583 (insert "\n\n# Rule for cleaning entire design\n"
16584 "\nclean : "
16585 "\n\t-rm -f $(ALL_UNITS)\n")
16586 ;; insert `make library' rule
16587 (insert "\n\n# Rule for creating library directory\n"
16588 "\nlibrary :"
16589 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16590 "\n$(LIBRARY-" work-library ") :"
16591 "\n\t"
16592 (vhdl-replace-string
16593 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16594 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16595 "\n")
16596 ;; insert rule for each library unit
16597 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16598 (while prim-list
16599 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16600 (setq subcomp-list
16601 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16602 (setq unit-key (caar prim-list)
16603 unit-name (or (nth 0 (aget ent-alist unit-key t))
16604 (nth 0 (aget conf-alist unit-key t))
16605 (nth 0 (aget pack-alist unit-key t))))
16606 (insert "\n" unit-key)
16607 (unless (equal unit-key unit-name)
16608 (insert " \\\n" unit-name))
16609 (insert " :"
16610 " \\\n\t\tlibrary"
16611 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16612 (while second-list
16613 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16614 (setq second-list (cdr second-list)))
16615 (while subcomp-list
0a2e512a
RF
16616 (when (and (assoc (car subcomp-list) unit-list)
16617 (not (equal unit-key (car subcomp-list))))
3dcb36b7
JB
16618 (insert " \\\n\t\t" (car subcomp-list)))
16619 (setq subcomp-list (cdr subcomp-list)))
16620 (insert "\n")
16621 (setq prim-list (cdr prim-list)))
16622 ;; insert rule for each library unit file
16623 (insert "\n\n# Rules for compiling single library unit files\n")
16624 (while rule-alist
16625 (setq rule (car rule-alist))
16626 ;; get compiler options for this file
16627 (setq options
16628 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16629 ;; insert rule if file is supposed to be compiled
16630 (setq target-list (nth 1 rule)
16631 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16632 ;; insert targets
16633 (setq tmp-list target-list)
16634 (while target-list
16635 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16636 (if (cdr target-list) " \\" " :"))
16637 (setq target-list (cdr target-list)))
16638 (setq target-list tmp-list)
16639 ;; insert file name as first dependency
16640 (insert " \\\n\t\t" (nth 0 rule))
16641 ;; insert dependencies (except if also target or unit does not exist)
16642 (while depend-list
16643 (when (and (not (member (car depend-list) target-list))
16644 (assoc (car depend-list) unit-list))
16645 (insert " \\\n\t\t"
16646 "$(UNIT-" work-library "-" (car depend-list) ")"))
16647 (setq depend-list (cdr depend-list)))
16648 ;; insert compile command
16649 (if options
16650 (insert "\n\t$(COMPILE) "
16651 (if (eq options 'default) "$(OPTIONS)" options) " "
16652 (nth 0 rule) "\n")
16653 (setq tmp-list target-list)
16654 (while target-list
16655 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16656 (if (cdr target-list) " \\" "\n"))
16657 (setq target-list (cdr target-list)))
16658 (setq target-list tmp-list))
16659 (setq rule-alist (cdr rule-alist)))
16660 (insert "\n\n### " makefile-name " ends here\n")
16661 ;; run Makefile generation hook
16662 (run-hooks 'vhdl-makefile-generation-hook)
16663 (message "Generating makefile \"%s\"...done" makefile-name)
16664 ;; save and close file
16665 (if (file-writable-p makefile-path-name)
16666 (progn (save-buffer)
16667 (kill-buffer (current-buffer))
16668 (set-buffer orig-buffer)
7cd80673 16669 (add-to-history 'file-name-history makefile-path-name))
3dcb36b7
JB
16670 (vhdl-warning-when-idle
16671 (format "File not writable: \"%s\""
16672 (abbreviate-file-name makefile-path-name)))
16673 (switch-to-buffer (current-buffer))))))
16674
5eabfe72
KH
16675
16676;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16677;;; Bug reports
16678;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16679;; (using `reporter.el')
16680
3dcb36b7
JB
16681(defconst vhdl-mode-help-address
16682 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16683 "Address for VHDL Mode bug reports.")
16684
3dcb36b7
JB
16685(defun vhdl-submit-bug-report ()
16686 "Submit via mail a bug report on VHDL Mode."
16687 (interactive)
16688 ;; load in reporter
16689 (and
16690 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16691 (let ((reporter-prompt-for-summary-p t))
16692 (reporter-submit-bug-report
16693 vhdl-mode-help-address
16694 (concat "VHDL Mode " vhdl-version)
16695 (list
16696 ;; report all important user options
16697 'vhdl-offsets-alist
16698 'vhdl-comment-only-line-offset
16699 'tab-width
16700 'vhdl-electric-mode
16701 'vhdl-stutter-mode
16702 'vhdl-indent-tabs-mode
16703 'vhdl-project-alist
16704 'vhdl-project
16705 'vhdl-project-file-name
16706 'vhdl-project-auto-load
16707 'vhdl-project-sort
16708 'vhdl-compiler-alist
16709 'vhdl-compiler
16710 'vhdl-compile-use-local-error-regexp
16711 'vhdl-makefile-generation-hook
16712 'vhdl-default-library
16713 'vhdl-standard
16714 'vhdl-basic-offset
16715 'vhdl-upper-case-keywords
16716 'vhdl-upper-case-types
16717 'vhdl-upper-case-attributes
16718 'vhdl-upper-case-enum-values
16719 'vhdl-upper-case-constants
16720 'vhdl-use-direct-instantiation
0a2e512a 16721 'vhdl-compose-configuration-name
3dcb36b7
JB
16722 'vhdl-entity-file-name
16723 'vhdl-architecture-file-name
0a2e512a 16724 'vhdl-configuration-file-name
3dcb36b7
JB
16725 'vhdl-package-file-name
16726 'vhdl-file-name-case
16727 'vhdl-electric-keywords
16728 'vhdl-optional-labels
16729 'vhdl-insert-empty-lines
16730 'vhdl-argument-list-indent
16731 'vhdl-association-list-with-formals
16732 'vhdl-conditions-in-parenthesis
16733 'vhdl-zero-string
16734 'vhdl-one-string
16735 'vhdl-file-header
16736 'vhdl-file-footer
16737 'vhdl-company-name
16738 'vhdl-copyright-string
16739 'vhdl-platform-spec
16740 'vhdl-date-format
16741 'vhdl-modify-date-prefix-string
16742 'vhdl-modify-date-on-saving
16743 'vhdl-reset-kind
16744 'vhdl-reset-active-high
16745 'vhdl-clock-rising-edge
16746 'vhdl-clock-edge-condition
16747 'vhdl-clock-name
16748 'vhdl-reset-name
16749 'vhdl-model-alist
16750 'vhdl-include-port-comments
16751 'vhdl-include-direction-comments
16752 'vhdl-include-type-comments
16753 'vhdl-include-group-comments
16754 'vhdl-actual-port-name
16755 'vhdl-instance-name
16756 'vhdl-testbench-entity-name
16757 'vhdl-testbench-architecture-name
16758 'vhdl-testbench-configuration-name
16759 'vhdl-testbench-dut-name
16760 'vhdl-testbench-include-header
16761 'vhdl-testbench-declarations
16762 'vhdl-testbench-statements
16763 'vhdl-testbench-initialize-signals
16764 'vhdl-testbench-include-library
16765 'vhdl-testbench-include-configuration
16766 'vhdl-testbench-create-files
0a2e512a
RF
16767 'vhdl-testbench-entity-file-name
16768 'vhdl-testbench-architecture-file-name
3dcb36b7 16769 'vhdl-compose-create-files
0a2e512a
RF
16770 'vhdl-compose-configuration-create-file
16771 'vhdl-compose-configuration-hierarchical
16772 'vhdl-compose-configuration-use-subconfiguration
3dcb36b7
JB
16773 'vhdl-compose-include-header
16774 'vhdl-compose-architecture-name
16775 'vhdl-components-package-name
16776 'vhdl-use-components-package
16777 'vhdl-self-insert-comments
16778 'vhdl-prompt-for-comments
16779 'vhdl-inline-comment-column
16780 'vhdl-end-comment-column
16781 'vhdl-auto-align
16782 'vhdl-align-groups
16783 'vhdl-align-group-separate
16784 'vhdl-align-same-indent
16785 'vhdl-highlight-keywords
16786 'vhdl-highlight-names
16787 'vhdl-highlight-special-words
16788 'vhdl-highlight-forbidden-words
16789 'vhdl-highlight-verilog-keywords
16790 'vhdl-highlight-translate-off
16791 'vhdl-highlight-case-sensitive
16792 'vhdl-special-syntax-alist
16793 'vhdl-forbidden-words
16794 'vhdl-forbidden-syntax
16795 'vhdl-directive-keywords
16796 'vhdl-speedbar-auto-open
16797 'vhdl-speedbar-display-mode
16798 'vhdl-speedbar-scan-limit
16799 'vhdl-speedbar-jump-to-unit
16800 'vhdl-speedbar-update-on-saving
16801 'vhdl-speedbar-save-cache
16802 'vhdl-speedbar-cache-file-name
16803 'vhdl-index-menu
16804 'vhdl-source-file-menu
16805 'vhdl-hideshow-menu
16806 'vhdl-hide-all-init
16807 'vhdl-print-two-column
16808 'vhdl-print-customize-faces
16809 'vhdl-intelligent-tab
16810 'vhdl-indent-syntax-based
16811 'vhdl-word-completion-case-sensitive
16812 'vhdl-word-completion-in-minibuffer
16813 'vhdl-underscore-is-part-of-word
16814 'vhdl-mode-hook)
16815 (function
16816 (lambda ()
16817 (insert
16818 (if vhdl-special-indent-hook
16819 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16820 "vhdl-special-indent-hook is set to '"
16821 (format "%s" vhdl-special-indent-hook)
16822 ".\nPerhaps this is your problem?\n"
16823 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16824 "\n"))))
16825 nil
16826 "Hi Reto,"))))
16827
16828
16829;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16830;;; Documentation
16831;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16832
16833(defconst vhdl-doc-release-notes nil
16834 "\
0a2e512a 16835Release Notes for VHDL Mode 3.33
3dcb36b7
JB
16836================================
16837
16838 - New Features
3dcb36b7 16839 - User Options
3dcb36b7
JB
16840
16841
16842New Features
16843------------
16844
0a2e512a
RF
16845CONFIGURATION DECLARATION GENERATION:
16846 - Automatic generation of a configuration declaration for a design.
16847 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
3dcb36b7
JB
16848
16849
16850User Options
16851------------
16852
0a2e512a
RF
16853`vhdl-configuration-file-name': (new)
16854 Specify how the configuration file name is obtained.
16855`vhdl-compose-configuration-name': (new)
16856 Specify how the configuration name is optained.
16857`vhdl-compose-configuration-create-file': (new)
16858 Specify whether a new file should be created for a configuration.
16859`vhdl-compose-configuration-hierarchical': (new)
16860 Specify whether hierarchical configurations should be created.
16861`vhdl-compose-configuration-use-subconfiguration': (new)
16862 Specify whether subconfigurations should be used inside configurations.
3dcb36b7
JB
16863")
16864
16865
16866(defconst vhdl-doc-keywords nil
16867 "\
16868Reserved words in VHDL
16869----------------------
16870
16871VHDL'93 (IEEE Std 1076-1993):
16872 `vhdl-93-keywords' : keywords
16873 `vhdl-93-types' : standardized types
16874 `vhdl-93-attributes' : standardized attributes
16875 `vhdl-93-enum-values' : standardized enumeration values
16876 `vhdl-93-functions' : standardized functions
16877 `vhdl-93-packages' : standardized packages and libraries
16878
16879VHDL-AMS (IEEE Std 1076.1):
16880 `vhdl-ams-keywords' : keywords
16881 `vhdl-ams-types' : standardized types
16882 `vhdl-ams-attributes' : standardized attributes
16883 `vhdl-ams-enum-values' : standardized enumeration values
16884 `vhdl-ams-functions' : standardized functions
16885
16886Math Packages (IEEE Std 1076.2):
16887 `vhdl-math-types' : standardized types
16888 `vhdl-math-constants' : standardized constants
16889 `vhdl-math-functions' : standardized functions
16890 `vhdl-math-packages' : standardized packages
16891
16892Forbidden words:
16893 `vhdl-verilog-keywords' : Verilog reserved words
16894
16895NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16896
16897
16898(defconst vhdl-doc-coding-style nil
16899 "\
16900For VHDL coding style and naming convention guidelines, see the following
16901references:
16902
16903\[1] Ben Cohen.
16904 \"VHDL Coding Styles and Methodologies\".
16905 Kluwer Academic Publishers, 1999.
16906 http://members.aol.com/vhdlcohen/vhdl/
16907
16908\[2] Michael Keating and Pierre Bricaud.
16909 \"Reuse Methodology Manual, Second Edition\".
16910 Kluwer Academic Publishers, 1999.
16911 http://www.openmore.com/openmore/rmm2.html
16912
16913\[3] European Space Agency.
16914 \"VHDL Modelling Guidelines\".
16915 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16916
16917Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16918to visually support naming conventions.")
16919
16920
d2ddb974
KH
16921(defun vhdl-version ()
16922 "Echo the current version of VHDL Mode in the minibuffer."
16923 (interactive)
3dcb36b7 16924 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16925 (vhdl-keep-region-active))
16926
3dcb36b7
JB
16927(defun vhdl-doc-variable (variable)
16928 "Display VARIABLE's documentation in *Help* buffer."
16929 (interactive)
f8246027 16930 (unless (featurep 'xemacs)
4bcb9c95 16931 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
0a2e512a
RF
16932 (with-output-to-temp-buffer
16933 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7 16934 (princ (documentation-property variable 'variable-documentation))
4bcb9c95 16935 (with-current-buffer standard-output
3dcb36b7 16936 (help-mode))
d5d105e8 16937 (help-print-return-message)))
d2ddb974 16938
3dcb36b7
JB
16939(defun vhdl-doc-mode ()
16940 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 16941 (interactive)
f8246027 16942 (unless (featurep 'xemacs)
4bcb9c95 16943 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
0a2e512a
RF
16944 (with-output-to-temp-buffer
16945 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7
JB
16946 (princ mode-name)
16947 (princ " mode:\n")
16948 (princ (documentation 'vhdl-mode))
4bcb9c95 16949 (with-current-buffer standard-output
3dcb36b7 16950 (help-mode))
d5d105e8 16951 (help-print-return-message)))
d2ddb974
KH
16952
16953
5eabfe72 16954;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16955
16956(provide 'vhdl-mode)
16957
16958;;; vhdl-mode.el ends here