(lgrep, rgrep): Use add-to-history.
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
CommitLineData
d2ddb974
KH
1;;; vhdl-mode.el --- major mode for editing VHDL code
2
d91362c9 3;; Copyright (C) 1992-2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3dcb36b7
JB
4
5;; Authors: Reto Zimmermann <reto@gnu.org>
6;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
0a2e512a 7;; Maintainer: Reto Zimmermann <reto@gnu.org>
5eabfe72 8;; Keywords: languages vhdl
0a2e512a 9;; WWW: http://opensource.ethz.ch/emacs/vhdl-mode.html
3dcb36b7 10
0a2e512a 11(defconst vhdl-version "3.33.6"
3dcb36b7
JB
12 "VHDL Mode version number.")
13
0a2e512a 14(defconst vhdl-time-stamp "2005-08-30"
3dcb36b7 15 "VHDL Mode time stamp for last update.")
d2ddb974
KH
16
17;; This file is part of GNU Emacs.
18
19;; GNU Emacs is free software; you can redistribute it and/or modify
20;; it under the terms of the GNU General Public License as published by
21;; the Free Software Foundation; either version 2, or (at your option)
22;; any later version.
23
24;; GNU Emacs is distributed in the hope that it will be useful,
25;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27;; GNU General Public License for more details.
28
29;; You should have received a copy of the GNU General Public License
30;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
31;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
32;; Boston, MA 02110-1301, USA.
d2ddb974 33
5eabfe72 34;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 35;;; Commentary:
5eabfe72 36;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
37
38;; This package provides an Emacs major mode for editing VHDL code.
39;; It includes the following features:
40
3dcb36b7
JB
41;; - Syntax highlighting
42;; - Indentation
43;; - Template insertion (electrification)
44;; - Insertion of file headers
5eabfe72 45;; - Insertion of user-specified models
3dcb36b7 46;; - Port translation / testbench generation
0a2e512a
RF
47;; - Structural composition
48;; - Configuration generation
3dcb36b7
JB
49;; - Sensitivity list updating
50;; - File browser
51;; - Design hierarchy browser
d2ddb974 52;; - Source file compilation (syntax analysis)
3dcb36b7
JB
53;; - Makefile generation
54;; - Code hiding
55;; - Word/keyword completion
56;; - Block commenting
57;; - Code fixing/alignment/beautification
58;; - Postscript printing
5eabfe72 59;; - VHDL'87/'93 and VHDL-AMS supported
3dcb36b7 60;; - Comprehensive menu
5eabfe72 61;; - Fully customizable
3dcb36b7 62;; - Works under GNU Emacs (recommended) and XEmacs
5eabfe72
KH
63
64;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 65;; Documentation
d2ddb974 66
3dcb36b7 67;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
d2ddb974 68
5eabfe72 69;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 70;; Emacs Versions
3dcb36b7 71
9e5538bc 72;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
3dcb36b7
JB
73;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
74
5eabfe72 75;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
76;; Installation
77
9e5538bc 78;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
3dcb36b7
JB
79
80;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
81;; or into an arbitrary directory that is added to the load path by the
82;; following line in your Emacs start-up file `.emacs':
83
84;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
d2ddb974 85
3dcb36b7
JB
86;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
87;; directory. Otherwise, byte-compile the source file:
88;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
89;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
90
91;; Add the following lines to the `site-start.el' file in the `site-lisp'
92;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
93;; (not required in Emacs 20.X):
94
95;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
96;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
97
98;; More detailed installation instructions are included in the official
99;; VHDL Mode distribution.
d2ddb974 100
5eabfe72 101;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 102;; Acknowledgements
d2ddb974
KH
103
104;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
5eabfe72 105;; and Steve Grout.
d2ddb974 106
5eabfe72 107;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
3dcb36b7 108;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
d2ddb974
KH
109
110;; Many thanks to all the users who sent me bug reports and enhancement
3dcb36b7
JB
111;; requests.
112;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
113;; enhancement suggestions and the fruitful discussions.
5eabfe72
KH
114;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
115;; Thanks to Ulf Klaperski for the indentation speedup hint.
116
117;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
118;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
119;; giving me the opportunity to develop this code.
120;; This work has been funded in part by MICROSWISS, a Microelectronics Program
121;; of the Swiss Government.
122
3dcb36b7 123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
124
125;;; Code:
126
3dcb36b7
JB
127;; XEmacs handling
128(defconst vhdl-xemacs (string-match "XEmacs" emacs-version)
129 "Non-nil if XEmacs is used.")
9e5538bc
TTN
130;; Emacs 21+ handling
131(defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not vhdl-xemacs))
0a2e512a
RF
132 "Non-nil if GNU Emacs 21, 22, ... is used.")
133(defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not vhdl-xemacs))
134 "Non-nil if GNU Emacs 22, ... is used.")
3dcb36b7 135
354617b5 136(defvar compilation-file-regexp-alist)
84c98ace
JB
137(defvar conf-alist)
138(defvar conf-entry)
139(defvar conf-key)
140(defvar ent-alist)
354617b5
JB
141(defvar itimer-version)
142(defvar lazy-lock-defer-contextually)
143(defvar lazy-lock-defer-on-scrolling)
144(defvar lazy-lock-defer-on-the-fly)
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
200(defcustom vhdl-electric-mode t
5eabfe72
KH
201 "*Non-nil enables electrification (automatic template generation).
202If nil, template generators can still be invoked through key bindings and
3dcb36b7 203menu. Is indicated in the modeline by \"/e\" after the mode name and can be
5eabfe72 204toggled by `\\[vhdl-electric-mode]'."
d2ddb974
KH
205 :type 'boolean
206 :group 'vhdl-mode)
207
208(defcustom vhdl-stutter-mode t
5eabfe72 209 "*Non-nil enables stuttering.
3dcb36b7 210Is indicated in the modeline by \"/s\" after the mode name and can be toggled
5eabfe72 211by `\\[vhdl-stutter-mode]'."
d2ddb974
KH
212 :type 'boolean
213 :group 'vhdl-mode)
214
5eabfe72
KH
215(defcustom vhdl-indent-tabs-mode nil
216 "*Non-nil means indentation can insert tabs.
d2ddb974
KH
217Overrides local variable `indent-tabs-mode'."
218 :type 'boolean
219 :group 'vhdl-mode)
220
221
222(defgroup vhdl-compile nil
223 "Customizations for compilation."
224 :group 'vhdl)
225
5eabfe72
KH
226(defcustom vhdl-compiler-alist
227 '(
3dcb36b7 228 ;; Cadence Leapfrog: cv -file test.vhd
5eabfe72 229 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
3dcb36b7
JB
230 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
231 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
232 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
233 ("\\1/entity" "\\2/\\1" "\\1/configuration"
234 "\\1/package" "\\1/body" downcase))
235 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
236 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
237 ;; (PLL_400X_TOP) is not declared [10.3].
238 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
239 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
240 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
0a2e512a
RF
241 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
242 "\\1/package/pc.db" "\\1/body/pc.db" downcase))
5eabfe72 243 ;; Ikos Voyager: analyze test.vhd
3dcb36b7 244 ;; analyze test.vhd
5eabfe72 245 ;; E L4/C5: this library unit is inaccessible
3dcb36b7
JB
246 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
247 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
248 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
249 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
250 nil)
5eabfe72
KH
251 ;; ModelSim, Model Technology: vcom test.vhd
252 ;; ERROR: test.vhd(14): Unknown identifier: positiv
253 ;; WARNING[2]: test.vhd(85): Possible infinite loop
3dcb36b7
JB
254 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
255 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
256 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
257 ("\\(ERROR\\|WARNING\\|\\*\\* 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 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
261 ;; test.vhd:34: error message
262 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
263 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
264 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
265 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
266 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
5eabfe72
KH
267 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
268 ;; ERROR: test.vhd(24): near "dnd": expecting: END
269 ;; WARNING[4]: test.vhd(30): A space is required between ...
3dcb36b7
JB
270 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
271 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
272 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
273 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
274 "\\1/_primary.dat" "\\1/body.dat" downcase))
275 ;; Savant: scram -publish-cc test.vhd
276 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
277 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
278 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
279 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
280 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
281 "\\1_config.vhdl" "\\1_package.vhdl"
282 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
283 ;; Simili: vhdlp -work test.vhd
284 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
285 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
286 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
287 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
288 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
289 "\\1/prim.var" "\\1/_body.var" downcase))
290 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
291 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
292 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
293 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
294 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
295 nil)
296 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
5eabfe72 297 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
3dcb36b7
JB
298 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
299 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
300 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
301 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
302 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
303 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
304 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
305 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
306 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
307 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
308 ;; Synplify:
309 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
310 ("Synplify" "n/a" "n/a" "make" "-f \\1"
311 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
312 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
313 nil)
5eabfe72 314 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
315 ;; Compiling "test.vhd" line 1...
316 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
317 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
318 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
319 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
320 ("^ *Compiling \"\\(.+\\)\" " 1)
321 nil)
322 ;; VeriBest: vc vhdl test.vhd
323 ;; (no file name printed out!)
324 ;; 32: Z <= A and BitA ;
325 ;; ^^^^
326 ;; [Error] Name BITA is unknown
327 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
328 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
329 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
330 nil)
5eabfe72 331 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
332 ;; Compiling "test.vhd" line 1...
333 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
334 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
335 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
336 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
337 ("^ *Compiling \"\\(.+\\)\" " 1)
338 nil)
5eabfe72
KH
339 )
340 "*List of available VHDL compilers and their properties.
341Each list entry specifies the following items for a compiler:
342Compiler:
3dcb36b7
JB
343 Compiler name : name used in option `vhdl-compiler' to choose compiler
344 Compile command : command used for source file compilation
345 Compile options : compile options (\"\\1\" inserts library name)
346 Make command : command used for compilation using a Makefile
347 Make options : make options (\"\\1\" inserts Makefile name)
348 Generate Makefile: use built-in function or command to generate a Makefile
349 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
350 Library command : command to create library directory \(\"\\1\" inserts
351 library directory, \"\\2\" inserts library name)
352 Compile directory: where compilation is run and the Makefile is placed
353 Library directory: directory of default library
354 Makefile name : name of Makefile (default is \"Makefile\")
355 ID string : compiler identification string (see `vhdl-project-alist')
356Error message:
0a2e512a 357 Regexp : regular expression to match error messages (*)
3dcb36b7
JB
358 File subexp index: index of subexpression that matches the file name
359 Line subexp index: index of subexpression that matches the line number
360 Column subexp idx: index of subexpression that matches the column number
361File message:
5eabfe72 362 Regexp : regular expression to match a file name message
3dcb36b7
JB
363 File subexp index: index of subexpression that matches the file name
364Unit-to-file name mapping: mapping of library unit names to names of files
365 generated by the compiler (used for Makefile generation)
366 To string : string a name is mapped to (\"\\1\" inserts the unit name,
367 \"\\2\" inserts the entity name for architectures)
368 Case adjustment : adjust case of inserted unit names
369
0a2e512a 370\(*) The regular expression must match the error message starting from the
84c98ace 371 beginning of the line (but not necessarily to the end of the line).
0a2e512a 372
3dcb36b7
JB
373Compile options allows insertion of the library name (see `vhdl-project-alist')
374in order to set the compilers library option (e.g. \"vcom -work my_lib\").
375
376For Makefile generation, the built-in function can be used (requires
377specification of the unit-to-file name mapping). Alternatively, an
378external command can be specified. Work directory allows specification of
379an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
380used for Makefile generation). To use another library name than \"work\",
381customize `vhdl-project-alist'. The library command is inserted in Makefiles
382to automatically create the library directory if not existent.
383
384Compile options, compile directory, library directory, and Makefile name are
385overwritten by the project settings if a project is defined (see
386`vhdl-project-alist'). Directory paths are relative to the source file
387directory.
5eabfe72
KH
388
389Some compilers do not include the file name in the error message, but print
390out a file name message in advance. In this case, set \"File Subexp Index\"
3dcb36b7
JB
391under \"Error Message\" to 0 and fill out the \"File Message\" entries.
392If no file name at all is printed out, set both \"File Message\" entries to 0
393\(a default file name message will be printed out instead, does not work in
394XEmacs).
5eabfe72
KH
395
396A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
3dcb36b7 397assigning its name to option `vhdl-compiler'.
5eabfe72 398
3dcb36b7
JB
399Please send any missing or erroneous compiler properties to the maintainer for
400updating.
401
0a2e512a
RF
402NOTE: Activate new error and file message regexps and reflect the new setting
403 in the choice list of option `vhdl-compiler' by restarting Emacs."
3dcb36b7
JB
404 :type '(repeat
405 (list :tag "Compiler" :indent 2
406 (string :tag "Compiler name ")
407 (string :tag "Compile command ")
408 (string :tag "Compile options " "-work \\1")
409 (string :tag "Make command " "make")
410 (string :tag "Make options " "-f \\1")
411 (choice :tag "Generate Makefile "
412 (const :tag "Built-in function" nil)
413 (string :tag "Command" "vmake \\2 > \\1"))
414 (string :tag "Library command " "mkdir \\1")
415 (directory :tag "Compile directory "
416 :validate vhdl-widget-directory-validate "./")
417 (directory :tag "Library directory "
418 :validate vhdl-widget-directory-validate "work/")
419 (file :tag "Makefile name " "Makefile")
420 (string :tag "ID string ")
421 (list :tag "Error message" :indent 4
422 (regexp :tag "Regexp ")
423 (integer :tag "File subexp index")
424 (integer :tag "Line subexp index")
425 (integer :tag "Column subexp idx"))
426 (list :tag "File message" :indent 4
427 (regexp :tag "Regexp ")
428 (integer :tag "File subexp index"))
429 (choice :tag "Unit-to-file name mapping"
430 :format "%t: %[Value Menu%] %v\n"
431 (const :tag "Not defined" nil)
432 (list :tag "To string" :indent 4
433 (string :tag "Entity " "\\1.vhd")
434 (string :tag "Architecture " "\\2_\\1.vhd")
435 (string :tag "Configuration " "\\1.vhd")
436 (string :tag "Package " "\\1.vhd")
437 (string :tag "Package Body " "\\1_body.vhd")
438 (choice :tag "Case adjustment "
439 (const :tag "None" identity)
440 (const :tag "Upcase" upcase)
441 (const :tag "Downcase" downcase))))))
5eabfe72 442 :set (lambda (variable value)
0a2e512a 443 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
5eabfe72
KH
444 :group 'vhdl-compile)
445
446(defcustom vhdl-compiler "ModelSim"
447 "*Specifies the VHDL compiler to be used for syntax analysis.
3dcb36b7
JB
448Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
449 :type (let ((alist vhdl-compiler-alist) list)
450 (while alist
451 (setq list (cons (list 'const (caar alist)) list))
452 (setq alist (cdr alist)))
453 (append '(choice) (nreverse list)))
454 :group 'vhdl-compile)
455
456(defcustom vhdl-compile-use-local-error-regexp t
457 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
458In this case, only error message regexps for VHDL compilers are active if
459compilation is started from a VHDL buffer. Otherwise, the error message
460regexps are appended to the predefined global regexps, and all regexps are
461active all the time. Note that by doing that, the predefined global regexps
462might result in erroneous parsing of error messages for some VHDL compilers.
463
464NOTE: Activate the new setting by restarting Emacs."
465 :type 'boolean
d2ddb974
KH
466 :group 'vhdl-compile)
467
3dcb36b7
JB
468(defcustom vhdl-makefile-generation-hook nil
469 "*Functions to run at the end of Makefile generation.
470Allows to insert user specific parts into a Makefile.
471
472Example:
473 \(lambda nil
474 \(re-search-backward \"^# Rule for compiling entire design\")
475 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
476 :type 'hook
477 :group 'vhdl-compile)
478
479(defcustom vhdl-default-library "work"
480 "*Name of default library.
481Is overwritten by project settings if a project is active."
d2ddb974
KH
482 :type 'string
483 :group 'vhdl-compile)
484
485
3dcb36b7
JB
486(defgroup vhdl-project nil
487 "Customizations for projects."
d2ddb974
KH
488 :group 'vhdl)
489
3dcb36b7
JB
490(defcustom vhdl-project-alist
491 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
492 "~/example1/" ("src/system/" "src/components/") ""
493 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
494 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
495 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
496 ("Example 2" "Individual source files, multiple compilers in different directories"
497 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
498 nil "\\1/" "work" "\\1/work/" "Makefile" "")
499 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
500 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
501 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
502-------------------------------------------------------------------------------
503-- This is a multi-line project description
504-- that can be used as a project dependent part of the file header.
505"))
506 "*List of projects and their properties.
507 Name : name used in option `vhdl-project' to choose project
508 Title : title of project (single-line string)
509 Default directory: default project directory (absolute path)
510 Sources : a) source files : path + \"/\" + file name
511 b) directory : path + \"/\"
512 c) directory tree: \"-r \" + path + \"/\"
513 Exclude regexp : matches file/directory names to be excluded as sources
514 Compile options : project-specific options for each compiler
515 Compiler name : name of compiler for which these options are valid
516 Compile options: project-specific compiler options
517 (\"\\1\" inserts library name, \"\\2\" default options)
518 Make options: project-specific make options
519 (\"\\1\" inserts Makefile name, \"\\2\" default options)
520 Exceptions : file-specific exceptions
521 File name regexp: matches file names for which exceptions are valid
522 - Options : file-specific compiler options string
523 (\"\\1\" inserts library name, \"\\2\" default options,
524 \"\\3\" project-specific options)
525 - Do not compile: do not compile this file (in Makefile)
526 Compile directory: where compilation is run and the Makefile is placed
527 \(\"\\1\" inserts compiler ID string)
528 Library name : name of library (default is \"work\")
529 Library directory: path to library (\"\\1\" inserts compiler ID string)
530 Makefile name : name of Makefile
531 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
532 Description : description of project (multi-line string)
533
534Project title and description are used to insert into the file header (see
535option `vhdl-file-header').
536
537The default directory must have an absolute path (use `M-TAB' for completion).
538All other paths can be absolute or relative to the default directory. All
539paths must end with '/'.
540
541The design units found in the sources (files and directories) are shown in the
542hierarchy browser. Path and file name can contain wildcards `*' and `?' as
543well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
544Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
545specified, the default directory is taken as source directory. Otherwise,
546the default directory is only taken as source directory if there is a sources
547entry with the empty string or \"./\". Exclude regexp allows to filter out
548specific file and directory names from the list of sources (e.g. CVS
549directories).
550
551Files are compiled in the compile directory. Makefiles are also placed into
552the compile directory. Library directory specifies which directory the
553compiler compiles into (used to generate the Makefile).
554
555Since different compile/library directories and Makefiles may exist for
556different compilers within one project, these paths and names allow the
557insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
558Compile options, compile directory, library directory, and Makefile name
559overwrite the settings of the current compiler.
560
561File-specific compiler options (highest priority) overwrite project-specific
562options which overwrite default options (lowest priority). Lower priority
563options can be inserted in higher priority options. This allows to reuse
564default options (e.g. \"-file\") in project- or file-specific options (e.g.
565\"-93 -file\").
566
567NOTE: Reflect the new setting in the choice list of option `vhdl-project'
568 by restarting Emacs."
569 :type `(repeat
570 (list :tag "Project" :indent 2
571 (string :tag "Name ")
572 (string :tag "Title ")
573 (directory :tag "Default directory"
574 :validate vhdl-widget-directory-validate
575 ,(abbreviate-file-name default-directory))
576 (repeat :tag "Sources " :indent 4
577 (directory :format " %v" "./"))
578 (regexp :tag "Exclude regexp ")
579 (repeat
580 :tag "Compile options " :indent 4
581 (list :tag "Compiler" :indent 6
582 ,(let ((alist vhdl-compiler-alist) list)
583 (while alist
584 (setq list (cons (list 'const (caar alist)) list))
585 (setq alist (cdr alist)))
586 (append '(choice :tag "Compiler name")
587 (nreverse list)))
588 (string :tag "Compile options" "\\2")
589 (string :tag "Make options " "\\2")
590 (repeat
591 :tag "Exceptions " :indent 8
592 (cons :format "%v"
593 (regexp :tag "File name regexp ")
594 (choice :format "%[Value Menu%] %v"
595 (string :tag "Options" "\\3")
596 (const :tag "Do not compile" nil))))))
597 (directory :tag "Compile directory"
598 :validate vhdl-widget-directory-validate "./")
599 (string :tag "Library name " "work")
600 (directory :tag "Library directory"
601 :validate vhdl-widget-directory-validate "work/")
602 (file :tag "Makefile name " "Makefile")
603 (string :tag "Description: (type `C-j' for newline)"
604 :format "%t\n%v\n")))
605 :set (lambda (variable value)
0a2e512a 606 (vhdl-custom-set variable value
3dcb36b7
JB
607 'vhdl-update-mode-menu
608 'vhdl-speedbar-refresh))
609 :group 'vhdl-project)
610
611(defcustom vhdl-project nil
612 "*Specifies the default for the current project.
613Select a project name from the ones defined in option `vhdl-project-alist'.
614Is used to determine the project title and description to be inserted in file
615headers and the source files/directories to be scanned in the hierarchy
616browser. The current project can also be changed temporarily in the menu."
617 :type (let ((alist vhdl-project-alist) list)
618 (while alist
619 (setq list (cons (list 'const (caar alist)) list))
620 (setq alist (cdr alist)))
621 (append '(choice (const :tag "None" nil) (const :tag "--"))
622 (nreverse list)))
623 :group 'vhdl-project)
624
625(defcustom vhdl-project-file-name '("\\1.prj")
626 "*List of file names/paths for importing/exporting project setups.
627\"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
628replaced by the user name (allows to have user-specific project setups).
629The first entry is used as file name to import/export individual project
630setups. All entries are used to automatically import project setups at
631startup (see option `vhdl-project-auto-load'). Projects loaded from the
632first entry are automatically made current. Hint: specify local project
633setups in first entry, global setups in following entries; loading a local
634project setup will make it current, while loading the global setups
635is done without changing the current project.
636Names can also have an absolute path (i.e. project setups can be stored
637in global directories)."
638 :type '(repeat (string :tag "File name" "\\1.prj"))
639 :group 'vhdl-project)
640
641(defcustom vhdl-project-auto-load '(startup)
642 "*Automatically load project setups from files.
643All project setup files that match the file names specified in option
644`vhdl-project-file-name' are automatically loaded. The project of the
645\(alphabetically) last loaded setup of the first `vhdl-project-file-name'
646entry is activated.
647A project setup file can be obtained by exporting a project (see menu).
648 At startup: project setup file is loaded at Emacs startup"
649 :type '(set (const :tag "At startup" startup))
650 :group 'vhdl-project)
651
652(defcustom vhdl-project-sort t
653 "*Non-nil means projects are displayed in alphabetical order."
654 :type 'boolean
655 :group 'vhdl-project)
656
657
658(defgroup vhdl-style nil
659 "Customizations for coding styles."
660 :group 'vhdl
661 :group 'vhdl-template
662 :group 'vhdl-port
663 :group 'vhdl-compose)
664
5eabfe72
KH
665(defcustom vhdl-standard '(87 nil)
666 "*VHDL standards used.
667Basic standard:
668 VHDL'87 : IEEE Std 1076-1987
669 VHDL'93 : IEEE Std 1076-1993
670Additional standards:
671 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
3dcb36b7 672 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
5eabfe72 673
3dcb36b7
JB
674NOTE: Activate the new setting in a VHDL buffer by using the menu entry
675 \"Activate Options\"."
5eabfe72
KH
676 :type '(list (choice :tag "Basic standard"
677 (const :tag "VHDL'87" 87)
678 (const :tag "VHDL'93" 93))
679 (set :tag "Additional standards" :indent 2
680 (const :tag "VHDL-AMS" ams)
3dcb36b7 681 (const :tag "Math packages" math)))
5eabfe72 682 :set (lambda (variable value)
0a2e512a 683 (vhdl-custom-set variable value
5eabfe72
KH
684 'vhdl-template-map-init
685 'vhdl-mode-abbrev-table-init
686 'vhdl-template-construct-alist-init
687 'vhdl-template-package-alist-init
688 'vhdl-update-mode-menu
689 'vhdl-words-init 'vhdl-font-lock-init))
690 :group 'vhdl-style)
691
692(defcustom vhdl-basic-offset 2
d2ddb974
KH
693 "*Amount of basic offset used for indentation.
694This value is used by + and - symbols in `vhdl-offsets-alist'."
695 :type 'integer
696 :group 'vhdl-style)
697
d2ddb974 698(defcustom vhdl-upper-case-keywords nil
5eabfe72
KH
699 "*Non-nil means convert keywords to upper case.
700This is done when typed or expanded or by the fix case functions."
d2ddb974 701 :type 'boolean
5eabfe72 702 :set (lambda (variable value)
0a2e512a 703 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 704 :group 'vhdl-style)
d2ddb974
KH
705
706(defcustom vhdl-upper-case-types nil
5eabfe72
KH
707 "*Non-nil means convert standardized types to upper case.
708This is done when expanded or by the fix case functions."
d2ddb974 709 :type 'boolean
5eabfe72 710 :set (lambda (variable value)
0a2e512a 711 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 712 :group 'vhdl-style)
d2ddb974
KH
713
714(defcustom vhdl-upper-case-attributes nil
5eabfe72
KH
715 "*Non-nil means convert standardized attributes to upper case.
716This is done when expanded or by the fix case functions."
d2ddb974 717 :type 'boolean
5eabfe72 718 :set (lambda (variable value)
0a2e512a 719 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 720 :group 'vhdl-style)
d2ddb974
KH
721
722(defcustom vhdl-upper-case-enum-values nil
5eabfe72
KH
723 "*Non-nil means convert standardized enumeration values to upper case.
724This is done when expanded or by the fix case functions."
d2ddb974 725 :type 'boolean
5eabfe72 726 :set (lambda (variable value)
0a2e512a 727 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72
KH
728 :group 'vhdl-style)
729
730(defcustom vhdl-upper-case-constants t
731 "*Non-nil means convert standardized constants to upper case.
732This is done when expanded."
733 :type 'boolean
734 :set (lambda (variable value)
0a2e512a 735 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
5eabfe72 736 :group 'vhdl-style)
d2ddb974 737
3dcb36b7
JB
738(defcustom vhdl-use-direct-instantiation 'standard
739 "*Non-nil means use VHDL'93 direct component instantiation.
740 Never : never
741 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
742 Always : always"
743 :type '(choice (const :tag "Never" never)
744 (const :tag "Standard" standard)
745 (const :tag "Always" always))
746 :group 'vhdl-style)
747
748
749(defgroup vhdl-naming nil
750 "Customizations for naming conventions."
751 :group 'vhdl)
752
753(defcustom vhdl-entity-file-name '(".*" . "\\&")
754 (concat
755 "*Specifies how the entity file name is obtained.
756The entity file name can be obtained by modifying the entity name (e.g.
757attaching or stripping off a substring). The file extension is automatically
758taken from the file name of the current buffer."
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)
d2ddb974 764
3dcb36b7
JB
765(defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
766 (concat
767 "*Specifies how the architecture file name is obtained.
768The architecture file name can be obtained by modifying the entity
769and/or architecture name (e.g. attaching or stripping off a substring). The
0a2e512a
RF
770file extension is automatically taken from the file name of the current
771buffer. The string that is matched against the regexp is the concatenation
772of the entity and the architecture name separated by a space. This gives
773access to both names (see default setting as example)."
774 vhdl-name-doc-string)
775 :type '(cons (regexp :tag "From regexp")
776 (string :tag "To string "))
777 :group 'vhdl-naming
778 :group 'vhdl-compose)
779
780(defcustom vhdl-configuration-file-name '(".*" . "\\&")
781 (concat
782 "*Specifies how the configuration file name is obtained.
783The configuration file name can be obtained by modifying the configuration
784name (e.g. attaching or stripping off a substring). The file extension is
785automatically taken from the file name of the current buffer."
3dcb36b7
JB
786 vhdl-name-doc-string)
787 :type '(cons (regexp :tag "From regexp")
788 (string :tag "To string "))
789 :group 'vhdl-naming
790 :group 'vhdl-compose)
791
792(defcustom vhdl-package-file-name '(".*" . "\\&")
793 (concat
794 "*Specifies how the package file name is obtained.
795The package file name can be obtained by modifying the package name (e.g.
796attaching or stripping off a substring). The file extension is automatically
0a2e512a
RF
797taken from the file name of the current buffer. Package files can be created
798in a different directory by prepending a relative or absolute path to the
799file name."
3dcb36b7
JB
800 vhdl-name-doc-string)
801 :type '(cons (regexp :tag "From regexp")
802 (string :tag "To string "))
803 :group 'vhdl-naming
804 :group 'vhdl-compose)
805
806(defcustom vhdl-file-name-case 'identity
807 "*Specifies how to change case for obtaining file names.
808When deriving a file name from a VHDL unit name, case can be changed as
809follows:
810 As Is: case is not changed (taken as is)
811 Lower Case: whole name is changed to lower case
812 Upper Case: whole name is changed to upper case
813 Capitalize: first letter of each word in name is capitalized"
814 :type '(choice (const :tag "As Is" identity)
815 (const :tag "Lower Case" downcase)
816 (const :tag "Upper Case" upcase)
817 (const :tag "Capitalize" capitalize))
818 :group 'vhdl-naming
819 :group 'vhdl-compose)
820
821
822(defgroup vhdl-template nil
5eabfe72 823 "Customizations for electrification."
d2ddb974
KH
824 :group 'vhdl)
825
5eabfe72
KH
826(defcustom vhdl-electric-keywords '(vhdl user)
827 "*Type of keywords for which electrification is enabled.
828 VHDL keywords: invoke built-in templates
3dcb36b7 829 User keywords: invoke user models (see option `vhdl-model-alist')"
5eabfe72 830 :type '(set (const :tag "VHDL keywords" vhdl)
3dcb36b7 831 (const :tag "User model keywords" user))
5eabfe72 832 :set (lambda (variable value)
0a2e512a 833 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
3dcb36b7 834 :group 'vhdl-template)
5eabfe72
KH
835
836(defcustom vhdl-optional-labels 'process
837 "*Constructs for which labels are to be queried.
838Template generators prompt for optional labels for:
839 None : no constructs
840 Processes only: processes only (also procedurals in VHDL-AMS)
841 All constructs: all constructs with optional labels and keyword END"
842 :type '(choice (const :tag "None" none)
843 (const :tag "Processes only" process)
844 (const :tag "All constructs" all))
3dcb36b7 845 :group 'vhdl-template)
d2ddb974 846
5eabfe72
KH
847(defcustom vhdl-insert-empty-lines 'unit
848 "*Specifies whether to insert empty lines in some templates.
849This improves readability of code. Empty lines are inserted in:
850 None : no constructs
851 Design units only: entities, architectures, configurations, packages only
852 All constructs : also all constructs with BEGIN...END parts
853
3dcb36b7 854Replaces option `vhdl-additional-empty-lines'."
5eabfe72
KH
855 :type '(choice (const :tag "None" none)
856 (const :tag "Design units only" unit)
857 (const :tag "All constructs" all))
3dcb36b7
JB
858 :group 'vhdl-template
859 :group 'vhdl-port
860 :group 'vhdl-compose)
5eabfe72
KH
861
862(defcustom vhdl-argument-list-indent nil
863 "*Non-nil means indent argument lists relative to opening parenthesis.
864That is, argument, association, and port lists start on the same line as the
865opening parenthesis and subsequent lines are indented accordingly.
866Otherwise, lists start on a new line and are indented as normal code."
d2ddb974 867 :type 'boolean
3dcb36b7
JB
868 :group 'vhdl-template
869 :group 'vhdl-port
870 :group 'vhdl-compose)
d2ddb974 871
5eabfe72
KH
872(defcustom vhdl-association-list-with-formals t
873 "*Non-nil means write association lists with formal parameters.
3dcb36b7
JB
874Templates prompt for formal and actual parameters (ports/generics).
875When pasting component instantiations, formals are included.
5eabfe72 876If nil, only a list of actual parameters is entered."
d2ddb974 877 :type 'boolean
3dcb36b7
JB
878 :group 'vhdl-template
879 :group 'vhdl-port
880 :group 'vhdl-compose)
d2ddb974
KH
881
882(defcustom vhdl-conditions-in-parenthesis nil
5eabfe72 883 "*Non-nil means place parenthesis around condition expressions."
d2ddb974 884 :type 'boolean
3dcb36b7 885 :group 'vhdl-template)
d2ddb974 886
5eabfe72
KH
887(defcustom vhdl-zero-string "'0'"
888 "*String to use for a logic zero."
889 :type 'string
3dcb36b7 890 :group 'vhdl-template)
5eabfe72
KH
891
892(defcustom vhdl-one-string "'1'"
893 "*String to use for a logic one."
894 :type 'string
3dcb36b7 895 :group 'vhdl-template)
5eabfe72
KH
896
897
898(defgroup vhdl-header nil
899 "Customizations for file header."
3dcb36b7
JB
900 :group 'vhdl-template
901 :group 'vhdl-compose)
d2ddb974 902
5eabfe72
KH
903(defcustom vhdl-file-header "\
904-------------------------------------------------------------------------------
905-- Title : <title string>
906-- Project : <project>
907-------------------------------------------------------------------------------
908-- File : <filename>
909-- Author : <author>
910-- Company : <company>
3dcb36b7 911-- Created : <date>
5eabfe72
KH
912-- Last update: <date>
913-- Platform : <platform>
3dcb36b7 914-- Standard : <standard>
5eabfe72
KH
915<projectdesc>-------------------------------------------------------------------------------
916-- Description: <cursor>
3dcb36b7 917<copyright>-------------------------------------------------------------------------------
5eabfe72
KH
918-- Revisions :
919-- Date Version Author Description
920-- <date> 1.0 <login>\tCreated
921-------------------------------------------------------------------------------
922
923"
924 "*String or file to insert as file header.
925If the string specifies an existing file name, the contents of the file is
926inserted, otherwise the string itself is inserted as file header.
927Type `C-j' for newlines.
d2ddb974
KH
928If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
929if the header needs to be version controlled.
930
931The following keywords for template generation are supported:
3dcb36b7
JB
932 <filename> : replaced by the name of the buffer
933 <author> : replaced by the user name and email address
934 \(`user-full-name',`mail-host-address', `user-mail-address')
935 <login> : replaced by user login name (`user-login-name')
936 <company> : replaced by contents of option `vhdl-company-name'
937 <date> : replaced by the current date
938 <year> : replaced by the current year
939 <project> : replaced by title of current project (`vhdl-project')
940 <projectdesc> : replaced by description of current project (`vhdl-project')
941 <copyright> : replaced by copyright string (`vhdl-copyright-string')
942 <platform> : replaced by contents of option `vhdl-platform-spec'
943 <standard> : replaced by the VHDL language standard(s) used
944 <... string> : replaced by a queried string (\"...\" is the prompt word)
945 <title string>: replaced by file title in automatically generated files
946 <cursor> : final cursor position
d2ddb974 947
5eabfe72
KH
948The (multi-line) project description <projectdesc> can be used as a project
949dependent part of the file header and can also contain the above keywords."
950 :type 'string
951 :group 'vhdl-header)
952
953(defcustom vhdl-file-footer ""
954 "*String or file to insert as file footer.
955If the string specifies an existing file name, the contents of the file is
956inserted, otherwise the string itself is inserted as file footer (i.e. at
957the end of the file).
3dcb36b7
JB
958Type `C-j' for newlines.
959The same keywords as in option `vhdl-file-header' can be used."
5eabfe72
KH
960 :type 'string
961 :group 'vhdl-header)
962
963(defcustom vhdl-company-name ""
3dcb36b7
JB
964 "*Name of company to insert in file header.
965See option `vhdl-file-header'."
966 :type 'string
967 :group 'vhdl-header)
968
969(defcustom vhdl-copyright-string "\
970-------------------------------------------------------------------------------
971-- Copyright (c) <year> <company>
972"
973 "*Copyright string to insert in file header.
974Can be multi-line string (type `C-j' for newline) and contain other file
975header keywords (see option `vhdl-file-header')."
5eabfe72
KH
976 :type 'string
977 :group 'vhdl-header)
978
979(defcustom vhdl-platform-spec ""
980 "*Specification of VHDL platform to insert in file header.
981The platform specification should contain names and versions of the
3dcb36b7
JB
982simulation and synthesis tools used.
983See option `vhdl-file-header'."
5eabfe72
KH
984 :type 'string
985 :group 'vhdl-header)
986
3dcb36b7 987(defcustom vhdl-date-format "%Y-%m-%d"
5eabfe72
KH
988 "*Specifies the date format to use in the header.
989This string is passed as argument to the command `format-time-string'.
990For more information on format strings, see the documentation for the
991`format-time-string' command (C-h f `format-time-string')."
992 :type 'string
993 :group 'vhdl-header)
d2ddb974 994
5eabfe72 995(defcustom vhdl-modify-date-prefix-string "-- Last update: "
d2ddb974 996 "*Prefix string of modification date in VHDL file header.
5eabfe72
KH
997If actualization of the modification date is called (menu,
998`\\[vhdl-template-modify]'), this string is searched and the rest
999of the line replaced by the current date."
d2ddb974 1000 :type 'string
5eabfe72
KH
1001 :group 'vhdl-header)
1002
1003(defcustom vhdl-modify-date-on-saving t
1004 "*Non-nil means update the modification date when the buffer is saved.
1005Calls function `\\[vhdl-template-modify]').
1006
3dcb36b7
JB
1007NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1008 \"Activate Options\"."
5eabfe72
KH
1009 :type 'boolean
1010 :group 'vhdl-header)
1011
1012
1013(defgroup vhdl-sequential-process nil
1014 "Customizations for sequential processes."
3dcb36b7 1015 :group 'vhdl-template)
d2ddb974 1016
5eabfe72
KH
1017(defcustom vhdl-reset-kind 'async
1018 "*Specifies which kind of reset to use in sequential processes."
1019 :type '(choice (const :tag "None" none)
1020 (const :tag "Synchronous" sync)
1021 (const :tag "Asynchronous" async))
1022 :group 'vhdl-sequential-process)
1023
1024(defcustom vhdl-reset-active-high nil
1025 "*Non-nil means reset in sequential processes is active high.
3dcb36b7 1026Nil means active low."
5eabfe72
KH
1027 :type 'boolean
1028 :group 'vhdl-sequential-process)
1029
1030(defcustom vhdl-clock-rising-edge t
1031 "*Non-nil means rising edge of clock triggers sequential processes.
3dcb36b7 1032Nil means falling edge."
5eabfe72
KH
1033 :type 'boolean
1034 :group 'vhdl-sequential-process)
1035
1036(defcustom vhdl-clock-edge-condition 'standard
1037 "*Syntax of the clock edge condition.
1038 Standard: \"clk'event and clk = '1'\"
1039 Function: \"rising_edge(clk)\""
1040 :type '(choice (const :tag "Standard" standard)
1041 (const :tag "Function" function))
1042 :group 'vhdl-sequential-process)
1043
1044(defcustom vhdl-clock-name ""
1045 "*Name of clock signal to use in templates."
d2ddb974 1046 :type 'string
5eabfe72 1047 :group 'vhdl-sequential-process)
d2ddb974 1048
5eabfe72
KH
1049(defcustom vhdl-reset-name ""
1050 "*Name of reset signal to use in templates."
d2ddb974 1051 :type 'string
5eabfe72
KH
1052 :group 'vhdl-sequential-process)
1053
1054
1055(defgroup vhdl-model nil
1056 "Customizations for user models."
1057 :group 'vhdl)
1058
1059(defcustom vhdl-model-alist
3dcb36b7 1060 '(("Example Model"
5eabfe72
KH
1061 "<label> : process (<clock>, <reset>)
1062begin -- process <label>
1063 if <reset> = '0' then -- asynchronous reset (active low)
1064 <cursor>
1065 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1066 if <enable> = '1' then -- synchronous load
84c98ace 1067
5eabfe72
KH
1068 end if;
1069 end if;
1070end process <label>;"
1071 "e" ""))
1072 "*List of user models.
1073VHDL models (templates) can be specified by the user in this list. They can be
1074invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1075electrification (i.e. overriding existing or creating new keywords, see
3dcb36b7 1076option `vhdl-electric-keywords').
5eabfe72
KH
1077 Name : name of model (string of words and spaces)
1078 String : string or name of file to be inserted as model (newline: `C-j')
1079 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1080 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1081 Keyword : keyword to invoke model
1082
1083The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1084A prompt that appears several times is queried once and replaced throughout
1085the model. Special prompts are:
1086 <clock> : name specified in `vhdl-clock-name' (if not empty)
1087 <reset> : name specified in `vhdl-reset-name' (if not empty)
1088 <cursor>: final cursor position
3dcb36b7
JB
1089File header prompts (see variable `vhdl-file-header') are automatically
1090replaced, so that user models can also be used to insert different types of
1091headers.
5eabfe72
KH
1092
1093If the string specifies an existing file name, the contents of the file is
1094inserted, otherwise the string itself is inserted.
1095The code within the models should be correctly indented.
1096Type `C-j' for newlines.
1097
3dcb36b7
JB
1098NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1099 \"Activate Options\"."
5eabfe72
KH
1100 :type '(repeat (list :tag "Model" :indent 2
1101 (string :tag "Name ")
1102 (string :tag "String : (type `C-j' for newline)"
1103 :format "%t\n%v")
3dcb36b7
JB
1104 (sexp :tag "Key binding" x)
1105 (string :tag "Keyword " :format "%t: %v\n")))
5eabfe72 1106 :set (lambda (variable value)
0a2e512a 1107 (vhdl-custom-set variable value
5eabfe72
KH
1108 'vhdl-model-map-init
1109 'vhdl-model-defun
1110 'vhdl-mode-abbrev-table-init
1111 'vhdl-update-mode-menu))
1112 :group 'vhdl-model)
1113
3dcb36b7 1114
0a2e512a
RF
1115(defgroup vhdl-compose nil
1116 "Customizations for structural composition."
1117 :group 'vhdl)
1118
1119(defcustom vhdl-compose-architecture-name '(".*" . "str")
1120 (concat
1121 "*Specifies how the component architecture name is obtained.
1122The component architecture name can be obtained by modifying the entity name
1123\(e.g. attaching or stripping off a substring).
1124If TO STRING is empty, the architecture name is queried."
1125 vhdl-name-doc-string)
1126 :type '(cons (regexp :tag "From regexp")
1127 (string :tag "To string "))
1128 :group 'vhdl-compose)
1129
1130(defcustom vhdl-compose-configuration-name
1131 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1132 (concat
1133 "*Specifies how the configuration name is obtained.
1134The configuration name can be obtained by modifying the entity and/or
1135architecture name (e.g. attaching or stripping off a substring). The string
1136that is matched against the regexp is the concatenation of the entity and the
1137architecture name separated by a space. This gives access to both names (see
1138default setting as example)."
1139 vhdl-name-doc-string)
1140 :type '(cons (regexp :tag "From regexp")
1141 (string :tag "To string "))
1142 :group 'vhdl-compose)
1143
1144(defcustom vhdl-components-package-name
1145 '((".*" . "\\&_components") . "components")
1146 (concat
1147 "*Specifies how the name for the components package is obtained.
1148The components package is a package containing all component declarations for
1149the current design. It's name can be obtained by modifying the project name
1150\(e.g. attaching or stripping off a substring). If no project is defined, the
1151DIRECTORY entry is chosen."
1152 vhdl-name-doc-string)
1153 :type '(cons (cons :tag "Project" :indent 2
1154 (regexp :tag "From regexp")
1155 (string :tag "To string "))
1156 (string :tag "Directory:\n String "))
1157 :group 'vhdl-compose)
1158
1159(defcustom vhdl-use-components-package nil
1160 "*Non-nil means use a separate components package for component declarations.
1161Otherwise, component declarations are inserted and searched for in the
1162architecture declarative parts."
1163 :type 'boolean
1164 :group 'vhdl-compose)
1165
1166(defcustom vhdl-compose-include-header t
1167 "*Non-nil means include a header in automatically generated files."
1168 :type 'boolean
1169 :group 'vhdl-compose)
1170
1171(defcustom vhdl-compose-create-files 'single
1172 "*Specifies whether new files should be created for the new component.
1173The component's entity and architecture are inserted:
1174 None : in current buffer
1175 Single file : in new single file
1176 Separate files: in two separate files
1177The file names are obtained from variables `vhdl-entity-file-name' and
1178`vhdl-architecture-file-name'."
1179 :type '(choice (const :tag "None" none)
1180 (const :tag "Single file" single)
1181 (const :tag "Separate files" separate))
1182 :group 'vhdl-compose)
1183
1184(defcustom vhdl-compose-configuration-create-file nil
1185 "*Specifies whether a new file should be created for the configuration.
1186If non-nil, a new file is created for the configuration.
1187The file name is obtained from variable `vhdl-configuration-file-name'."
1188 :type 'boolean
1189 :group 'vhdl-compose)
1190
1191(defcustom vhdl-compose-configuration-hierarchical t
1192 "*Specifies whether hierarchical configurations should be created.
1193If non-nil, automatically created configurations are hierarchical and include
1194the whole hierarchy of subcomponents. Otherwise the configuration only
1195includes one level of subcomponents."
1196 :type 'boolean
1197 :group 'vhdl-compose)
1198
1199(defcustom vhdl-compose-configuration-use-subconfiguration t
1200 "*Specifies whether subconfigurations should be used inside configurations.
1201If non-nil, automatically created configurations use configurations in binding
1202indications for subcomponents, if such configurations exist. Otherwise,
1203entities are used in binding indications for subcomponents."
1204 :type 'boolean
1205 :group 'vhdl-compose)
1206
1207
5eabfe72 1208(defgroup vhdl-port nil
3dcb36b7
JB
1209 "Customizations for port translation functions."
1210 :group 'vhdl
1211 :group 'vhdl-compose)
5eabfe72
KH
1212
1213(defcustom vhdl-include-port-comments nil
1214 "*Non-nil means include port comments when a port is pasted."
1215 :type 'boolean
1216 :group 'vhdl-port)
1217
1218(defcustom vhdl-include-direction-comments nil
3dcb36b7 1219 "*Non-nil means include port direction in instantiations as comments."
5eabfe72
KH
1220 :type 'boolean
1221 :group 'vhdl-port)
1222
3dcb36b7
JB
1223(defcustom vhdl-include-type-comments nil
1224 "*Non-nil means include generic/port type in instantiations as comments."
1225 :type 'boolean
1226 :group 'vhdl-port)
5eabfe72 1227
3dcb36b7
JB
1228(defcustom vhdl-include-group-comments 'never
1229 "*Specifies whether to include group comments and spacings.
1230The comments and empty lines between groups of ports are pasted:
1231 Never : never
1232 Declarations: in entity/component/constant/signal declarations only
1233 Always : also in generic/port maps"
1234 :type '(choice (const :tag "Never" never)
1235 (const :tag "Declarations" decl)
1236 (const :tag "Always" always))
1237 :group 'vhdl-port)
5eabfe72 1238
3dcb36b7 1239(defcustom vhdl-actual-port-name '(".*" . "\\&")
5eabfe72
KH
1240 (concat
1241 "*Specifies how actual port names are obtained from formal port names.
1242In a component instantiation, an actual port name can be obtained by
1243modifying the formal port name (e.g. attaching or stripping off a substring)."
1244 vhdl-name-doc-string)
3dcb36b7
JB
1245 :type '(cons (regexp :tag "From regexp")
1246 (string :tag "To string "))
5eabfe72
KH
1247 :group 'vhdl-port)
1248
3dcb36b7 1249(defcustom vhdl-instance-name '(".*" . "\\&_%d")
5eabfe72
KH
1250 (concat
1251 "*Specifies how an instance name is obtained.
1252The instance name can be obtained by modifying the name of the component to be
3dcb36b7
JB
1253instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1254by a unique number (starting with 1).
5eabfe72
KH
1255If TO STRING is empty, the instance name is queried."
1256 vhdl-name-doc-string)
3dcb36b7
JB
1257 :type '(cons (regexp :tag "From regexp")
1258 (string :tag "To string "))
1259 :group 'vhdl-port)
1260
1261
1262(defgroup vhdl-testbench nil
bc25429a 1263 "Customizations for testbench generation."
5eabfe72
KH
1264 :group 'vhdl-port)
1265
1266(defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1267 (concat
3dcb36b7
JB
1268 "*Specifies how the testbench entity name is obtained.
1269The entity name of a testbench can be obtained by modifying the name of
5eabfe72
KH
1270the component to be tested (e.g. attaching or stripping off a substring)."
1271 vhdl-name-doc-string)
3dcb36b7
JB
1272 :type '(cons (regexp :tag "From regexp")
1273 (string :tag "To string "))
1274 :group 'vhdl-testbench)
5eabfe72
KH
1275
1276(defcustom vhdl-testbench-architecture-name '(".*" . "")
1277 (concat
3dcb36b7
JB
1278 "*Specifies how the testbench architecture name is obtained.
1279The testbench architecture name can be obtained by modifying the name of
5eabfe72
KH
1280the component to be tested (e.g. attaching or stripping off a substring).
1281If TO STRING is empty, the architecture name is queried."
1282 vhdl-name-doc-string)
3dcb36b7
JB
1283 :type '(cons (regexp :tag "From regexp")
1284 (string :tag "To string "))
1285 :group 'vhdl-testbench)
1286
0a2e512a 1287(defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
3dcb36b7
JB
1288 (concat
1289 "*Specifies how the testbench configuration name is obtained.
1290The configuration name of a testbench can be obtained by modifying the entity
1291and/or architecture name (e.g. attaching or stripping off a substring). The
1292string that is matched against the regexp is the concatenation of the entity
1293and the architecture name separated by a space. This gives access to both
1294names (see default setting as example)."
1295 vhdl-name-doc-string)
1296 :type '(cons (regexp :tag "From regexp")
1297 (string :tag "To string "))
1298 :group 'vhdl-testbench)
5eabfe72
KH
1299
1300(defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1301 (concat
1302 "*Specifies how a DUT instance name is obtained.
1303The design-under-test instance name (i.e. the component instantiated in the
3dcb36b7 1304testbench) can be obtained by modifying the component name (e.g. attaching
5eabfe72
KH
1305or stripping off a substring)."
1306 vhdl-name-doc-string)
3dcb36b7
JB
1307 :type '(cons (regexp :tag "From regexp")
1308 (string :tag "To string "))
1309 :group 'vhdl-testbench)
5eabfe72 1310
3dcb36b7
JB
1311(defcustom vhdl-testbench-include-header t
1312 "*Non-nil means include a header in automatically generated files."
1313 :type 'boolean
1314 :group 'vhdl-testbench)
5eabfe72 1315
3dcb36b7
JB
1316(defcustom vhdl-testbench-declarations "\
1317 -- clock
1318 signal Clk : std_logic := '1';
1319"
1320 "*String or file to be inserted in the testbench declarative part.
5eabfe72 1321If the string specifies an existing file name, the contents of the file is
3dcb36b7 1322inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1323architecture before the BEGIN keyword.
1324Type `C-j' for newlines."
1325 :type 'string
3dcb36b7
JB
1326 :group 'vhdl-testbench)
1327
1328(defcustom vhdl-testbench-statements "\
1329 -- clock generation
1330 Clk <= not Clk after 10 ns;
5eabfe72 1331
3dcb36b7
JB
1332 -- waveform generation
1333 WaveGen_Proc: process
1334 begin
1335 -- insert signal assignments here
84c98ace 1336
3dcb36b7
JB
1337 wait until Clk = '1';
1338 end process WaveGen_Proc;
1339"
1340 "*String or file to be inserted in the testbench statement part.
5eabfe72 1341If the string specifies an existing file name, the contents of the file is
3dcb36b7 1342inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1343architecture before the END keyword.
1344Type `C-j' for newlines."
1345 :type 'string
3dcb36b7 1346 :group 'vhdl-testbench)
5eabfe72
KH
1347
1348(defcustom vhdl-testbench-initialize-signals nil
3dcb36b7 1349 "*Non-nil means initialize signals with `0' when declared in testbench."
5eabfe72 1350 :type 'boolean
3dcb36b7
JB
1351 :group 'vhdl-testbench)
1352
1353(defcustom vhdl-testbench-include-library t
1354 "*Non-nil means a library/use clause for std_logic_1164 is included."
1355 :type 'boolean
1356 :group 'vhdl-testbench)
1357
1358(defcustom vhdl-testbench-include-configuration t
1359 "*Non-nil means a testbench configuration is attached at the end."
1360 :type 'boolean
1361 :group 'vhdl-testbench)
5eabfe72
KH
1362
1363(defcustom vhdl-testbench-create-files 'single
3dcb36b7
JB
1364 "*Specifies whether new files should be created for the testbench.
1365testbench entity and architecture are inserted:
5eabfe72
KH
1366 None : in current buffer
1367 Single file : in new single file
1368 Separate files: in two separate files
0a2e512a
RF
1369The file names are obtained from variables `vhdl-testbench-entity-file-name'
1370and `vhdl-testbench-architecture-file-name'."
5eabfe72
KH
1371 :type '(choice (const :tag "None" none)
1372 (const :tag "Single file" single)
1373 (const :tag "Separate files" separate))
3dcb36b7
JB
1374 :group 'vhdl-testbench)
1375
0a2e512a 1376(defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
3dcb36b7 1377 (concat
0a2e512a
RF
1378 "*Specifies how the testbench entity file name is obtained.
1379The entity file name can be obtained by modifying the testbench entity name
1380\(e.g. attaching or stripping off a substring). The file extension is
1381automatically taken from the file name of the current buffer. Testbench
1382files can be created in a different directory by prepending a relative or
1383absolute path to the file name."
3dcb36b7
JB
1384 vhdl-name-doc-string)
1385 :type '(cons (regexp :tag "From regexp")
1386 (string :tag "To string "))
0a2e512a 1387 :group 'vhdl-testbench)
3dcb36b7 1388
0a2e512a 1389(defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
3dcb36b7 1390 (concat
0a2e512a
RF
1391 "*Specifies how the testbench architecture file name is obtained.
1392The architecture file name can be obtained by modifying the testbench entity
1393and/or architecture name (e.g. attaching or stripping off a substring). The
1394string that is matched against the regexp is the concatenation of the entity
1395and the architecture name separated by a space. This gives access to both
1396names (see default setting as example). Testbench files can be created in
1397a different directory by prepending a relative or absolute path to the file
1398name."
3dcb36b7 1399 vhdl-name-doc-string)
0a2e512a
RF
1400 :type '(cons (regexp :tag "From regexp")
1401 (string :tag "To string "))
1402 :group 'vhdl-testbench)
d2ddb974
KH
1403
1404
1405(defgroup vhdl-comment nil
1406 "Customizations for comments."
5eabfe72 1407 :group 'vhdl)
d2ddb974
KH
1408
1409(defcustom vhdl-self-insert-comments t
5eabfe72 1410 "*Non-nil means various templates automatically insert help comments."
d2ddb974
KH
1411 :type 'boolean
1412 :group 'vhdl-comment)
1413
1414(defcustom vhdl-prompt-for-comments t
5eabfe72 1415 "*Non-nil means various templates prompt for user definable comments."
d2ddb974
KH
1416 :type 'boolean
1417 :group 'vhdl-comment)
1418
5eabfe72 1419(defcustom vhdl-inline-comment-column 40
3dcb36b7
JB
1420 "*Column to indent and align inline comments to.
1421Overrides local option `comment-column'.
5eabfe72 1422
3dcb36b7
JB
1423NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1424 \"Activate Options\"."
d2ddb974
KH
1425 :type 'integer
1426 :group 'vhdl-comment)
1427
1428(defcustom vhdl-end-comment-column 79
5eabfe72
KH
1429 "*End of comment column.
1430Comments that exceed this column number are wrapped.
1431
3dcb36b7
JB
1432NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1433 \"Activate Options\"."
d2ddb974
KH
1434 :type 'integer
1435 :group 'vhdl-comment)
1436
5eabfe72 1437(defvar end-comment-column)
d2ddb974
KH
1438
1439
5eabfe72
KH
1440(defgroup vhdl-align nil
1441 "Customizations for alignment."
d2ddb974
KH
1442 :group 'vhdl)
1443
5eabfe72
KH
1444(defcustom vhdl-auto-align t
1445 "*Non-nil means align some templates automatically after generation."
d2ddb974 1446 :type 'boolean
5eabfe72
KH
1447 :group 'vhdl-align)
1448
1449(defcustom vhdl-align-groups t
1450 "*Non-nil means align groups of code lines separately.
3dcb36b7
JB
1451A group of code lines is a region of consecutive lines between two lines that
1452match the regexp in option `vhdl-align-group-separate'."
1453 :type 'boolean
1454 :group 'vhdl-align)
1455
1456(defcustom vhdl-align-group-separate "^\\s-*$"
1457 "*Regexp for matching a line that separates groups of lines for alignment.
1458Examples:
1459 \"^\\s-*$\": matches an empty line
1460 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1461 :type 'regexp
1462 :group 'vhdl-align)
1463
1464(defcustom vhdl-align-same-indent t
1465 "*Non-nil means align blocks with same indent separately.
1466When a region or the entire buffer is aligned, the code is divided into
1467blocks of same indent which are aligned separately (except for argument/port
1468lists). This gives nicer alignment in most cases.
1469Option `vhdl-align-groups' still applies within these blocks."
5eabfe72
KH
1470 :type 'boolean
1471 :group 'vhdl-align)
1472
1473
1474(defgroup vhdl-highlight nil
1475 "Customizations for highlighting."
1476 :group 'vhdl)
d2ddb974
KH
1477
1478(defcustom vhdl-highlight-keywords t
5eabfe72
KH
1479 "*Non-nil means highlight VHDL keywords and other standardized words.
1480The following faces are used:
0a2e512a
RF
1481 `font-lock-keyword-face' : keywords
1482 `font-lock-type-face' : standardized types
1483 `vhdl-font-lock-attribute-face': standardized attributes
1484 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1485 `vhdl-font-lock-function-face' : standardized function and package names
5eabfe72
KH
1486
1487NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1488 entry \"Fontify Buffer\")."
d2ddb974 1489 :type 'boolean
5eabfe72 1490 :set (lambda (variable value)
0a2e512a 1491 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1492 :group 'vhdl-highlight)
1493
5eabfe72
KH
1494(defcustom vhdl-highlight-names t
1495 "*Non-nil means highlight declaration names and construct labels.
1496The following faces are used:
3dcb36b7 1497 `font-lock-function-name-face' : names in declarations of units,
5eabfe72 1498 subprograms, components, as well as labels of VHDL constructs
3dcb36b7 1499 `font-lock-type-face' : names in type/nature declarations
0a2e512a 1500 `vhdl-font-lock-attribute-face': names in attribute declarations
3dcb36b7 1501 `font-lock-variable-name-face' : names in declarations of signals,
5eabfe72
KH
1502 variables, constants, subprogram parameters, generics, and ports
1503
1504NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1505 entry \"Fontify Buffer\")."
d2ddb974 1506 :type 'boolean
5eabfe72 1507 :set (lambda (variable value)
0a2e512a 1508 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1509 :group 'vhdl-highlight)
1510
5eabfe72
KH
1511(defcustom vhdl-highlight-special-words nil
1512 "*Non-nil means highlight words with special syntax.
3dcb36b7
JB
1513The words with syntax and color specified in option `vhdl-special-syntax-alist'
1514are highlighted accordingly.
5eabfe72
KH
1515Can be used for visual support of naming conventions.
1516
1517NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1518 entry \"Fontify Buffer\")."
d2ddb974 1519 :type 'boolean
5eabfe72 1520 :set (lambda (variable value)
0a2e512a 1521 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1522 :group 'vhdl-highlight)
1523
5eabfe72
KH
1524(defcustom vhdl-highlight-forbidden-words nil
1525 "*Non-nil means highlight forbidden words.
3dcb36b7
JB
1526The reserved words specified in option `vhdl-forbidden-words' or having the
1527syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
0a2e512a 1528warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
5eabfe72
KH
1529use them.
1530
1531NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1532 entry \"Fontify Buffer\")."
d2ddb974 1533 :type 'boolean
5eabfe72 1534 :set (lambda (variable value)
0a2e512a 1535 (vhdl-custom-set variable value
5eabfe72 1536 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1537 :group 'vhdl-highlight)
1538
5eabfe72
KH
1539(defcustom vhdl-highlight-verilog-keywords nil
1540 "*Non-nil means highlight Verilog keywords as reserved words.
1541Verilog keywords are highlighted in a warning color (face
0a2e512a 1542`vhdl-font-lock-reserved-words-face') to indicate not to use them.
2f402702 1543
5eabfe72 1544NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1545 entry \"Fontify Buffer\")."
d2ddb974 1546 :type 'boolean
5eabfe72 1547 :set (lambda (variable value)
0a2e512a 1548 (vhdl-custom-set variable value
5eabfe72 1549 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1550 :group 'vhdl-highlight)
1551
5eabfe72
KH
1552(defcustom vhdl-highlight-translate-off nil
1553 "*Non-nil means background-highlight code excluded from translation.
1554That is, all code between \"-- pragma translate_off\" and
1555\"-- pragma translate_on\" is highlighted using a different background color
0a2e512a 1556\(face `vhdl-font-lock-translate-off-face').
5eabfe72 1557Note: this might slow down on-the-fly fontification (and thus editing).
d2ddb974 1558
5eabfe72 1559NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1560 entry \"Fontify Buffer\")."
5eabfe72
KH
1561 :type 'boolean
1562 :set (lambda (variable value)
0a2e512a 1563 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1564 :group 'vhdl-highlight)
1565
5eabfe72
KH
1566(defcustom vhdl-highlight-case-sensitive nil
1567 "*Non-nil means consider case for highlighting.
1568Possible trade-off:
1569 non-nil also upper-case VHDL words are highlighted, but case of words with
1570 special syntax is not considered
1571 nil only lower-case VHDL words are highlighted, but case of words with
1572 special syntax is considered
3dcb36b7 1573Overrides local option `font-lock-keywords-case-fold-search'.
5eabfe72
KH
1574
1575NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1576 entry \"Fontify Buffer\")."
5eabfe72
KH
1577 :type 'boolean
1578 :group 'vhdl-highlight)
d2ddb974 1579
3dcb36b7
JB
1580(defcustom vhdl-special-syntax-alist
1581 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1582 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1583 ("variable" "\\w+_v" "Grey50" "Grey80"))
5eabfe72 1584 "*List of special syntax to be highlighted.
3dcb36b7 1585If option `vhdl-highlight-special-words' is non-nil, words with the specified
5eabfe72
KH
1586syntax (as regular expression) are highlighted in the corresponding color.
1587
1588 Name : string of words and spaces
1589 Regexp : regular expression describing word syntax
1590 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1591 Color (light): foreground color for light background
1592 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1593 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1594 Color (dark) : foreground color for dark background
1595 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1596 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1597
1598Can be used for visual support of naming conventions, such as highlighting
3dcb36b7 1599different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
5eabfe72 1600\"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
3dcb36b7 1601common substrings or name suffices.
5eabfe72 1602For each entry, a new face is generated with the specified colors and name
0a2e512a 1603\"vhdl-font-lock-\" + name + \"-face\".
5eabfe72
KH
1604
1605NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1606 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
5eabfe72
KH
1607 :type '(repeat (list :tag "Face" :indent 2
1608 (string :tag "Name ")
1609 (regexp :tag "Regexp " "\\w+_")
1610 (string :tag "Color (light)")
1611 (string :tag "Color (dark) ")))
1612 :set (lambda (variable value)
0a2e512a 1613 (vhdl-custom-set variable value 'vhdl-font-lock-init))
5eabfe72 1614 :group 'vhdl-highlight)
d2ddb974 1615
5eabfe72
KH
1616(defcustom vhdl-forbidden-words '()
1617 "*List of forbidden words to be highlighted.
3dcb36b7 1618If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
5eabfe72
KH
1619words are highlighted in a warning color to indicate not to use them.
1620
1621NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1622 entry \"Fontify Buffer\")."
5eabfe72
KH
1623 :type '(repeat (string :format "%v"))
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
5eabfe72
KH
1629(defcustom vhdl-forbidden-syntax ""
1630 "*Syntax of forbidden words to be highlighted.
3dcb36b7 1631If option `vhdl-highlight-forbidden-words' is non-nil, words with this
5eabfe72
KH
1632syntax are highlighted in a warning color to indicate not to use them.
1633Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1634highlights identifiers with 10 or more characters).
d2ddb974 1635
5eabfe72 1636NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1637 entry \"Fontify Buffer\")."
d2ddb974 1638 :type 'regexp
5eabfe72 1639 :set (lambda (variable value)
0a2e512a 1640 (vhdl-custom-set variable value
5eabfe72
KH
1641 'vhdl-words-init 'vhdl-font-lock-init))
1642 :group 'vhdl-highlight)
d2ddb974 1643
3dcb36b7
JB
1644(defcustom vhdl-directive-keywords '("pragma" "synopsys")
1645 "*List of compiler directive keywords recognized for highlighting.
d2ddb974 1646
3dcb36b7
JB
1647NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1648 entry \"Fontify Buffer\")."
1649 :type '(repeat (string :format "%v"))
1650 :set (lambda (variable value)
1651 (vhdl-custom-set variable value
1652 'vhdl-words-init 'vhdl-font-lock-init))
1653 :group 'vhdl-highlight)
1654
1655
1656(defgroup vhdl-speedbar nil
1657 "Customizations for speedbar."
d2ddb974
KH
1658 :group 'vhdl)
1659
3dcb36b7
JB
1660(defcustom vhdl-speedbar-auto-open nil
1661 "*Non-nil means automatically open speedbar at startup.
5eabfe72 1662Alternatively, the speedbar can be opened from the VHDL menu."
d2ddb974 1663 :type 'boolean
3dcb36b7
JB
1664 :group 'vhdl-speedbar)
1665
1666(defcustom vhdl-speedbar-display-mode 'files
1667 "*Specifies the default displaying mode when opening speedbar.
1668Alternatively, the displaying mode can be selected from the speedbar menu or
1669by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1670 :type '(choice (const :tag "Files" files)
1671 (const :tag "Directory hierarchy" directory)
1672 (const :tag "Project hierarchy" project))
1673 :group 'vhdl-speedbar)
1674
1675(defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1676 "*Limits scanning of large files and netlists.
1677Design units: maximum file size to scan for design units
1678Hierarchy (instances of subcomponents):
1679 File size: maximum file size to scan for instances (in bytes)
1680 Instances per arch: maximum number of instances to scan per architecture
1681
1682\"None\" always means that there is no limit.
1683In case of files not or incompletely scanned, a warning message and the file
1684names are printed out.
1685Background: scanning for instances is considerably slower than scanning for
1686design units, especially when there are many instances. These limits should
1687prevent the scanning of large netlists."
1688 :type '(list (choice :tag "Design units"
1689 :format "%t : %[Value Menu%] %v"
1690 (const :tag "None" nil)
1691 (integer :tag "File size"))
1692 (list :tag "Hierarchy" :indent 2
1693 (choice :tag "File size"
1694 :format "%t : %[Value Menu%] %v"
1695 (const :tag "None" nil)
1696 (integer :tag "Size "))
1697 (choice :tag "Instances per arch"
1698 (const :tag "None" nil)
1699 (integer :tag "Number "))))
1700 :group 'vhdl-speedbar)
1701
1702(defcustom vhdl-speedbar-jump-to-unit t
1703 "*Non-nil means jump to the design unit code when opened in a buffer.
1704The buffer cursor position is left unchanged otherwise."
1705 :type 'boolean
1706 :group 'vhdl-speedbar)
d2ddb974 1707
3dcb36b7
JB
1708(defcustom vhdl-speedbar-update-on-saving t
1709 "*Automatically update design hierarchy when buffer is saved."
d2ddb974 1710 :type 'boolean
3dcb36b7
JB
1711 :group 'vhdl-speedbar)
1712
1713(defcustom vhdl-speedbar-save-cache '(hierarchy display)
1714 "*Automatically save modified hierarchy caches when exiting Emacs.
1715 Hierarchy: design hierarchy information
1716 Display: displaying information (which design units to expand)"
1717 :type '(set (const :tag "Hierarchy" hierarchy)
1718 (const :tag "Display" display))
1719 :group 'vhdl-speedbar)
1720
1721(defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1722 "*Name of file for saving hierarchy cache.
1723\"\\1\" is replaced by the project name if a project is specified,
1724\"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1725different users to have cache files in the same directory). Can also have
1726an absolute path (i.e. all caches can be stored in one global directory)."
1727 :type 'string
1728 :group 'vhdl-speedbar)
d2ddb974 1729
3dcb36b7
JB
1730
1731(defgroup vhdl-menu nil
1732 "Customizations for menues."
1733 :group 'vhdl)
5eabfe72
KH
1734
1735(defcustom vhdl-index-menu nil
1736 "*Non-nil means add an index menu for a source file when loading.
1737Alternatively, the speedbar can be used. Note that the index menu scans a file
3dcb36b7 1738when it is opened, while speedbar only scans the file upon request."
5eabfe72
KH
1739 :type 'boolean
1740 :group 'vhdl-menu)
1741
1742(defcustom vhdl-source-file-menu nil
1743 "*Non-nil means add a menu of all source files in current directory.
1744Alternatively, the speedbar can be used."
1745 :type 'boolean
1746 :group 'vhdl-menu)
1747
1748(defcustom vhdl-hideshow-menu nil
3dcb36b7
JB
1749 "*Non-nil means add hideshow menu and functionality at startup.
1750Hideshow can also be enabled from the VHDL Mode menu.
1751Hideshow allows hiding code of various VHDL constructs.
5eabfe72 1752
3dcb36b7
JB
1753NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1754 \"Activate Options\"."
5eabfe72
KH
1755 :type 'boolean
1756 :group 'vhdl-menu)
1757
1758(defcustom vhdl-hide-all-init nil
1759 "*Non-nil means hide all design units initially after a file is loaded."
d2ddb974
KH
1760 :type 'boolean
1761 :group 'vhdl-menu)
1762
1763
1764(defgroup vhdl-print nil
1765 "Customizations for printing."
1766 :group 'vhdl)
1767
1768(defcustom vhdl-print-two-column t
5eabfe72 1769 "*Non-nil means print code in two columns and landscape format.
3dcb36b7
JB
1770Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1771prints VHDL files in a nice two-column landscape style.
5eabfe72
KH
1772
1773NOTE: Activate the new setting by restarting Emacs.
1774 Overrides `ps-print' settings locally."
1775 :type 'boolean
1776 :group 'vhdl-print)
1777
1778(defcustom vhdl-print-customize-faces t
1779 "*Non-nil means use an optimized set of faces for postscript printing.
1780
1781NOTE: Activate the new setting by restarting Emacs.
1782 Overrides `ps-print' settings locally."
d2ddb974
KH
1783 :type 'boolean
1784 :group 'vhdl-print)
1785
1786
1787(defgroup vhdl-misc nil
1788 "Miscellaneous customizations."
1789 :group 'vhdl)
1790
1791(defcustom vhdl-intelligent-tab t
5eabfe72 1792 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
d2ddb974
KH
1793That is, if preceeding character is part of a word then complete word,
1794else if not at beginning of line then insert tab,
1795else if last command was a `TAB' or `RET' then dedent one step,
5eabfe72 1796else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
d2ddb974 1797If nil, TAB always indents current line (i.e. `TAB' is bound to
3dcb36b7
JB
1798`indent-according-to-mode').
1799
1800NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1801 \"Activate Options\"."
1802 :type 'boolean
1803 :group 'vhdl-misc)
5eabfe72 1804
3dcb36b7
JB
1805(defcustom vhdl-indent-syntax-based t
1806 "*Non-nil means indent lines of code based on their syntactic context.
1807Otherwise, a line is indented like the previous nonblank line. This can be
1808useful in large files where syntax-based indentation gets very slow."
d2ddb974
KH
1809 :type 'boolean
1810 :group 'vhdl-misc)
1811
5eabfe72
KH
1812(defcustom vhdl-word-completion-case-sensitive nil
1813 "*Non-nil means word completion using `TAB' is case sensitive.
1814That is, `TAB' completes words that start with the same letters and case.
1815Otherwise, case is ignored."
1816 :type 'boolean
d2ddb974
KH
1817 :group 'vhdl-misc)
1818
1819(defcustom vhdl-word-completion-in-minibuffer t
5eabfe72
KH
1820 "*Non-nil enables word completion in minibuffer (for template prompts).
1821
1822NOTE: Activate the new setting by restarting Emacs."
d2ddb974
KH
1823 :type 'boolean
1824 :group 'vhdl-misc)
1825
1826(defcustom vhdl-underscore-is-part-of-word nil
5eabfe72 1827 "*Non-nil means consider the underscore character `_' as part of word.
d2ddb974 1828An identifier containing underscores is then treated as a single word in
5eabfe72
KH
1829select and move operations. All parts of an identifier separated by underscore
1830are treated as single words otherwise.
1831
3dcb36b7
JB
1832NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1833 \"Activate Options\"."
d2ddb974 1834 :type 'boolean
5eabfe72 1835 :set (lambda (variable value)
0a2e512a 1836 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
d2ddb974
KH
1837 :group 'vhdl-misc)
1838
3dcb36b7
JB
1839
1840(defgroup vhdl-related nil
5eabfe72
KH
1841 "Related general customizations."
1842 :group 'vhdl)
1843
3dcb36b7
JB
1844;; add related general customizations
1845(custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1846(if vhdl-xemacs
1847 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1848 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1849(custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1850(custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1851(custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1852(unless vhdl-xemacs
1853 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1854(custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1855(custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1856(custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1857
5eabfe72
KH
1858;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1859;; Internal variables
1860
3dcb36b7
JB
1861(defvar vhdl-menu-max-size 20
1862 "*Specifies the maximum size of a menu before splitting it into submenues.")
5eabfe72
KH
1863
1864(defvar vhdl-progress-interval 1
1865 "*Interval used to update progress status during long operations.
1866If a number, percentage complete gets updated after each interval of
3dcb36b7 1867that many seconds. To inhibit all messages, set this option to nil.")
d2ddb974
KH
1868
1869(defvar vhdl-inhibit-startup-warnings-p nil
1870 "*If non-nil, inhibits start up compatibility warnings.")
1871
1872(defvar vhdl-strict-syntax-p nil
1873 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1874If the syntactic symbol for a particular line does not match a symbol
1875in the offsets alist, an error is generated, otherwise no error is
1876reported and the syntactic symbol is ignored.")
1877
1878(defvar vhdl-echo-syntactic-information-p nil
1879 "*If non-nil, syntactic info is echoed when the line is indented.")
1880
1881(defconst vhdl-offsets-alist-default
0a2e512a
RF
1882 '((string . -1000)
1883 (cpp-macro . -1000)
1884 (block-open . 0)
1885 (block-close . 0)
1886 (statement . 0)
1887 (statement-cont . vhdl-lineup-statement-cont)
d2ddb974
KH
1888 (statement-block-intro . +)
1889 (statement-case-intro . +)
0a2e512a
RF
1890 (case-alternative . +)
1891 (comment . vhdl-lineup-comment)
1892 (arglist-intro . +)
1893 (arglist-cont . 0)
d2ddb974 1894 (arglist-cont-nonempty . vhdl-lineup-arglist)
0a2e512a
RF
1895 (arglist-close . vhdl-lineup-arglist)
1896 (entity . 0)
1897 (configuration . 0)
1898 (package . 0)
1899 (architecture . 0)
1900 (package-body . 0)
d2ddb974
KH
1901 )
1902 "Default settings for offsets of syntactic elements.
1903Do not change this constant! See the variable `vhdl-offsets-alist' for
1904more information.")
1905
1906(defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1907 "*Association list of syntactic element symbols and indentation offsets.
1908As described below, each cons cell in this list has the form:
1909
1910 (SYNTACTIC-SYMBOL . OFFSET)
1911
5eabfe72 1912When a line is indented, `vhdl-mode' first determines the syntactic
d2ddb974
KH
1913context of the line by generating a list of symbols called syntactic
1914elements. This list can contain more than one syntactic element and
1915the global variable `vhdl-syntactic-context' contains the context list
1916for the line being indented. Each element in this list is actually a
1917cons cell of the syntactic symbol and a buffer position. This buffer
1918position is call the relative indent point for the line. Some
1919syntactic symbols may not have a relative indent point associated with
1920them.
1921
5eabfe72 1922After the syntactic context list for a line is generated, `vhdl-mode'
d2ddb974
KH
1923calculates the absolute indentation for the line by looking at each
1924syntactic element in the list. First, it compares the syntactic
1925element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1926finds a match, it adds the OFFSET to the column of the relative indent
1927point. The sum of this calculation for each element in the syntactic
1928list is the absolute offset for line being indented.
1929
1930If the syntactic element does not match any in the `vhdl-offsets-alist',
1931an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1932the element is ignored.
1933
1934Actually, OFFSET can be an integer, a function, a variable, or one of
1935the following symbols: `+', `-', `++', or `--'. These latter
1936designate positive or negative multiples of `vhdl-basic-offset',
5eabfe72 1937respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
d2ddb974
KH
1938called with a single argument containing the cons of the syntactic
1939element symbol and the relative indent point. The function should
1940return an integer offset.
1941
1942Here is the current list of valid syntactic element symbols:
1943
1944 string -- inside multi-line string
1945 block-open -- statement block open
1946 block-close -- statement block close
1947 statement -- a VHDL statement
1948 statement-cont -- a continuation of a VHDL statement
1949 statement-block-intro -- the first line in a new statement block
1950 statement-case-intro -- the first line in a case alternative block
1951 case-alternative -- a case statement alternative clause
1952 comment -- a line containing only a comment
1953 arglist-intro -- the first line in an argument list
1954 arglist-cont -- subsequent argument list lines when no
1955 arguments follow on the same line as the
1956 the arglist opening paren
1957 arglist-cont-nonempty -- subsequent argument list lines when at
1958 least one argument follows on the same
1959 line as the arglist opening paren
1960 arglist-close -- the solo close paren of an argument list
1961 entity -- inside an entity declaration
1962 configuration -- inside a configuration declaration
1963 package -- inside a package declaration
1964 architecture -- inside an architecture body
5eabfe72 1965 package-body -- inside a package body")
d2ddb974
KH
1966
1967(defvar vhdl-comment-only-line-offset 0
1968 "*Extra offset for line which contains only the start of a comment.
1969Can contain an integer or a cons cell of the form:
1970
1971 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1972
1973Where NON-ANCHORED-OFFSET is the amount of offset given to
1974non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1975the amount of offset to give column-zero anchored comment-only lines.
1976Just an integer as value is equivalent to (<val> . 0)")
1977
1978(defvar vhdl-special-indent-hook nil
1979 "*Hook for user defined special indentation adjustments.
1980This hook gets called after a line is indented by the mode.")
1981
1982(defvar vhdl-style-alist
1983 '(("IEEE"
1984 (vhdl-basic-offset . 4)
3dcb36b7 1985 (vhdl-offsets-alist . ())))
d2ddb974
KH
1986 "Styles of Indentation.
1987Elements of this alist are of the form:
1988
1989 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1990
1991where STYLE-STRING is a short descriptive string used to select a
5eabfe72 1992style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
d2ddb974
KH
1993value for that variable when using the selected style.
1994
1995There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1996case, the VALUE is a list containing elements of the form:
1997
1998 (SYNTACTIC-SYMBOL . VALUE)
1999
2000as described in `vhdl-offsets-alist'. These are passed directly to
2001`vhdl-set-offset' so there is no need to set every syntactic symbol in
2002your style, only those that are different from the default.")
2003
2004;; dynamically append the default value of most variables
2005(or (assoc "Default" vhdl-style-alist)
2006 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2007 vhdl-strict-syntax-p
2008 vhdl-echo-syntactic-information-p
2009 vhdl-basic-offset
2010 vhdl-offsets-alist
2011 vhdl-comment-only-line-offset))
2012 (default (cons "Default"
2013 (mapcar
2014 (function
2015 (lambda (var)
5eabfe72 2016 (cons var (symbol-value var))))
d2ddb974
KH
2017 varlist))))
2018 (setq vhdl-style-alist (cons default vhdl-style-alist))))
2019
2020(defvar vhdl-mode-hook nil
2021 "*Hook called by `vhdl-mode'.")
2022
2023
5eabfe72 2024;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2025;;; Required packages
5eabfe72 2026;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5eabfe72 2027
3dcb36b7 2028;; mandatory
5eabfe72 2029(require 'assoc)
3dcb36b7
JB
2030(require 'compile) ; XEmacs
2031(require 'easymenu)
2032(require 'hippie-exp)
2033
2034;; optional (minimize warning messages during compile)
2035(eval-when-compile
2036 (require 'font-lock)
2037 (require 'ps-print)
2038 (require 'speedbar))
5eabfe72
KH
2039
2040
2041;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2042;;; Compatibility
5eabfe72 2043;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 2044
3dcb36b7
JB
2045;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2046;; XEmacs compatibility
d2ddb974 2047
3dcb36b7 2048;; active regions
d2ddb974 2049(defun vhdl-keep-region-active ()
5eabfe72
KH
2050 "Do whatever is necessary to keep the region active in XEmacs.
2051Ignore byte-compiler warnings you might see."
d2ddb974
KH
2052 (and (boundp 'zmacs-region-stays)
2053 (setq zmacs-region-stays t)))
2054
3dcb36b7 2055;; `wildcard-to-regexp' is included only in XEmacs 21
5eabfe72
KH
2056(unless (fboundp 'wildcard-to-regexp)
2057 (defun wildcard-to-regexp (wildcard)
2058 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
2059 (let* ((i (string-match "[*?]" wildcard))
2060 (result (substring wildcard 0 i))
2061 (len (length wildcard)))
2062 (when i
2063 (while (< i len)
2064 (let ((ch (aref wildcard i)))
2065 (setq result (concat result
2066 (cond ((eq ch ?*) "[^\000]*")
2067 ((eq ch ??) "[^\000]")
2068 (t (char-to-string ch)))))
2069 (setq i (1+ i)))))
2070 (concat "\\`" result "\\'"))))
2071
3dcb36b7
JB
2072;; `regexp-opt' undefined (`xemacs-devel' not installed)
2073;; `regexp-opt' accelerates fontification by 10-20%
2074(unless (fboundp 'regexp-opt)
2075; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2076 (defun regexp-opt (strings &optional paren)
2077 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
2078 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
2079
2080;; `match-string-no-properties' undefined (XEmacs, what else?)
2081(unless (fboundp 'match-string-no-properties)
2082 (defalias 'match-string-no-properties 'match-string))
2083
2084;; `subst-char-in-string' undefined (XEmacs)
2085(unless (fboundp 'subst-char-in-string)
2086 (defun subst-char-in-string (fromchar tochar string &optional inplace)
2087 (let ((i (length string))
2088 (newstr (if inplace string (copy-sequence string))))
2089 (while (> i 0)
2090 (setq i (1- i))
2091 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
2092 newstr)))
2093
2094;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2095(when (and vhdl-xemacs (string< itimer-version "1.09")
2096 (not noninteractive))
2097 (load "itimer")
2098 (when (string< itimer-version "1.09")
2099 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2100 (beep) (sit-for 5)))
2101
2102;; `file-expand-wildcards' undefined (XEmacs)
2103(unless (fboundp 'file-expand-wildcards)
2104 (defun file-expand-wildcards (pattern &optional full)
2105 "Taken from Emacs' `files.el'."
2106 (let* ((nondir (file-name-nondirectory pattern))
2107 (dirpart (file-name-directory pattern))
2108 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2109 (mapcar 'file-name-as-directory
2110 (file-expand-wildcards (directory-file-name dirpart)))
2111 (list dirpart)))
2112 contents)
2113 (while dirs
2114 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2115 (file-directory-p (directory-file-name (car dirs))))
2116 (let ((this-dir-contents
2117 (delq nil
2118 (mapcar #'(lambda (name)
2119 (unless (string-match "\\`\\.\\.?\\'"
2120 (file-name-nondirectory name))
2121 name))
2122 (directory-files (or (car dirs) ".") full
2123 (wildcard-to-regexp nondir))))))
2124 (setq contents
2125 (nconc
2126 (if (and (car dirs) (not full))
2127 (mapcar (function (lambda (name) (concat (car dirs) name)))
2128 this-dir-contents)
2129 this-dir-contents)
2130 contents))))
2131 (setq dirs (cdr dirs)))
2132 contents)))
5eabfe72 2133
0a2e512a
RF
2134;; `member-ignore-case' undefined (XEmacs)
2135(unless (fboundp 'member-ignore-case)
2136 (defalias 'member-ignore-case 'member))
2137
5eabfe72 2138;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2139;; Compatibility with older VHDL Mode versions
5eabfe72 2140
3dcb36b7
JB
2141(defvar vhdl-warnings nil
2142 "Warnings to tell the user during start up.")
d2ddb974 2143
3dcb36b7
JB
2144(defun vhdl-run-when-idle (secs repeat function)
2145 "Wait until idle, then run FUNCTION."
4bcb9c95 2146 (if (fboundp 'start-itimer)
3dcb36b7
JB
2147 (start-itimer "vhdl-mode" function secs repeat t)
2148; (run-with-idle-timer secs repeat function)))
2149 ;; explicitely activate timer (necessary when Emacs is already idle)
2150 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2151
2152(defun vhdl-warning-when-idle (&rest args)
2153 "Wait until idle, then print out warning STRING and beep."
2154 (if noninteractive
2155 (vhdl-warning (apply 'format args) t)
2156 (unless vhdl-warnings
2157 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2158 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2159
2160(defun vhdl-warning (string &optional nobeep)
2161 "Print out warning STRING and beep."
29a4e67d 2162 (message "WARNING: %s" string)
3dcb36b7 2163 (unless (or nobeep noninteractive) (beep)))
d2ddb974 2164
3dcb36b7
JB
2165(defun vhdl-print-warnings ()
2166 "Print out messages in variable `vhdl-warnings'."
2167 (let ((no-warnings (length vhdl-warnings)))
2168 (setq vhdl-warnings (nreverse vhdl-warnings))
2169 (while vhdl-warnings
29a4e67d 2170 (message "WARNING: %s" (car vhdl-warnings))
3dcb36b7
JB
2171 (setq vhdl-warnings (cdr vhdl-warnings)))
2172 (beep)
2173 (when (> no-warnings 1)
2174 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2175
2176;; Backward compatibility checks and fixes
2177;; option `vhdl-compiler' changed format
2178(unless (stringp vhdl-compiler)
2179 (setq vhdl-compiler "ModelSim")
2180 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2181
2182;; option `vhdl-standard' changed format
2183(unless (listp vhdl-standard)
2184 (setq vhdl-standard '(87 nil))
2185 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2186
2187;; option `vhdl-model-alist' changed format
2188(when (= (length (car vhdl-model-alist)) 3)
2189 (let ((old-alist vhdl-model-alist)
2190 new-alist)
2191 (while old-alist
2192 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2193 (setq old-alist (cdr old-alist)))
2194 (setq vhdl-model-alist (nreverse new-alist)))
2195 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2196
2197;; option `vhdl-project-alist' changed format
2198(when (= (length (car vhdl-project-alist)) 3)
2199 (let ((old-alist vhdl-project-alist)
2200 new-alist)
2201 (while old-alist
2202 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2203 (setq old-alist (cdr old-alist)))
2204 (setq vhdl-project-alist (nreverse new-alist)))
2205 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2206
2207;; option `vhdl-project-alist' changed format (3.31.1)
2208(when (= (length (car vhdl-project-alist)) 4)
2209 (let ((old-alist vhdl-project-alist)
2210 new-alist elem)
2211 (while old-alist
2212 (setq elem (car old-alist))
2213 (setq new-alist
2214 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2215 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2216 new-alist))
2217 (setq old-alist (cdr old-alist)))
2218 (setq vhdl-project-alist (nreverse new-alist)))
2219 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2220
2221;; option `vhdl-project-alist' changed format (3.31.12)
2222(when (= (length (car vhdl-project-alist)) 10)
2223 (let ((tmp-alist vhdl-project-alist))
2224 (while tmp-alist
2225 (setcdr (nthcdr 3 (car tmp-alist))
2226 (cons "" (nthcdr 4 (car tmp-alist))))
2227 (setq tmp-alist (cdr tmp-alist))))
2228 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2229
2230;; option `vhdl-compiler-alist' changed format (3.31.1)
2231(when (= (length (car vhdl-compiler-alist)) 7)
2232 (let ((old-alist vhdl-compiler-alist)
2233 new-alist elem)
2234 (while old-alist
2235 (setq elem (car old-alist))
2236 (setq new-alist
2237 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2238 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2239 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2240 (nth 5 elem) (nth 6 elem) nil)
2241 new-alist))
2242 (setq old-alist (cdr old-alist)))
2243 (setq vhdl-compiler-alist (nreverse new-alist)))
2244 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2245
2246;; option `vhdl-compiler-alist' changed format (3.31.10)
2247(when (= (length (car vhdl-compiler-alist)) 12)
2248 (let ((tmp-alist vhdl-compiler-alist))
2249 (while tmp-alist
2250 (setcdr (nthcdr 4 (car tmp-alist))
2251 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2252 (setq tmp-alist (cdr tmp-alist))))
2253 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2254
2255;; option `vhdl-compiler-alist' changed format (3.31.11)
2256(when (= (length (car vhdl-compiler-alist)) 13)
2257 (let ((tmp-alist vhdl-compiler-alist))
2258 (while tmp-alist
2259 (setcdr (nthcdr 3 (car tmp-alist))
2260 (cons "" (nthcdr 4 (car tmp-alist))))
2261 (setq tmp-alist (cdr tmp-alist))))
2262 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2263
2264;; option `vhdl-compiler-alist' changed format (3.32.7)
2265(when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2266 (let ((tmp-alist vhdl-compiler-alist))
2267 (while tmp-alist
2268 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2269 '(0 . nil))
2270 (setq tmp-alist (cdr tmp-alist))))
2271 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2272
2273;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2274(when (equal vhdl-project "")
2275 (setq vhdl-project nil)
2276 (customize-save-variable 'vhdl-project vhdl-project))
2277
2278;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2279(when (stringp vhdl-project-file-name)
2280 (setq vhdl-project-file-name (list vhdl-project-file-name))
2281 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2282
2283;; option `speedbar-indentation-width': introduced in speedbar 0.10
2284(if (not (boundp 'speedbar-indentation-width))
2285 (defvar speedbar-indentation-width 2)
2286 ;; set default to 2 if not already customized
2287 (unless (get 'speedbar-indentation-width 'saved-value)
2288 (setq speedbar-indentation-width 2)))
2289
2290
2291;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2292;;; Help functions / inline substitutions / macros
2293;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2294
2295(defun vhdl-standard-p (standard)
2296 "Check if STANDARD is specified as used standard."
2297 (or (eq standard (car vhdl-standard))
2298 (memq standard (cadr vhdl-standard))))
2299
2300(defun vhdl-project-p (&optional warning)
2301 "Return non-nil if a project is displayed, i.e. directories or files are
2302specified."
2303 (if (assoc vhdl-project vhdl-project-alist)
2304 vhdl-project
2305 (when (and vhdl-project warning)
2306 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2307 nil))
2308
2309(defun vhdl-resolve-env-variable (string)
2310 "Resolve environment variables in STRING."
2311 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2312 (setq string (concat (match-string 1 string)
2313 (getenv (match-string 2 string))
2314 (match-string 4 string))))
2315 string)
2316
2317(defun vhdl-default-directory ()
2318 "Return the default directory of the current project or the directory of the
2319current buffer if no project is defined."
2320 (if (vhdl-project-p)
2321 (expand-file-name (vhdl-resolve-env-variable
2322 (nth 1 (aget vhdl-project-alist vhdl-project))))
2323 default-directory))
2324
2325(defmacro vhdl-prepare-search-1 (&rest body)
2326 "Enable case insensitive search and switch to syntax table that includes '_',
2327then execute BODY, and finally restore the old environment. Used for
2328consistent searching."
2329 `(let ((case-fold-search t) ; case insensitive search
2330 (current-syntax-table (syntax-table))
2331 result
2332 (restore-prog ; program to restore enviroment
2333 '(progn
2334 ;; restore syntax table
2335 (set-syntax-table current-syntax-table))))
2336 ;; use extended syntax table
2337 (set-syntax-table vhdl-mode-ext-syntax-table)
2338 ;; execute BODY safely
2339 (setq result
2340 (condition-case info
2341 (progn ,@body)
2342 (error (eval restore-prog) ; restore environment on error
2343 (error (cadr info))))) ; pass error up
2344 ;; restore environment
2345 (eval restore-prog)
2346 result))
2347
2348(defmacro vhdl-prepare-search-2 (&rest body)
2349 "Enable case insensitive search, switch to syntax table that includes '_',
2350and remove `intangible' overlays, then execute BODY, and finally restore the
2351old environment. Used for consistent searching."
2352 `(let ((case-fold-search t) ; case insensitive search
2353 (current-syntax-table (syntax-table))
2354 result overlay-all-list overlay-intangible-list overlay
2355 (restore-prog ; program to restore enviroment
2356 '(progn
2357 ;; restore syntax table
2358 (set-syntax-table current-syntax-table)
2359 ;; restore `intangible' overlays
2360 (when (fboundp 'overlay-lists)
2361 (while overlay-intangible-list
2362 (overlay-put (car overlay-intangible-list) 'intangible t)
2363 (setq overlay-intangible-list
2364 (cdr overlay-intangible-list)))))))
2365 ;; use extended syntax table
2366 (set-syntax-table vhdl-mode-ext-syntax-table)
2367 ;; remove `intangible' overlays
2368 (when (fboundp 'overlay-lists)
2369 (setq overlay-all-list (overlay-lists))
2370 (setq overlay-all-list
2371 (append (car overlay-all-list) (cdr overlay-all-list)))
2372 (while overlay-all-list
2373 (setq overlay (car overlay-all-list))
2374 (when (memq 'intangible (overlay-properties overlay))
2375 (setq overlay-intangible-list
2376 (cons overlay overlay-intangible-list))
2377 (overlay-put overlay 'intangible nil))
2378 (setq overlay-all-list (cdr overlay-all-list))))
2379 ;; execute BODY safely
2380 (setq result
2381 (condition-case info
2382 (progn ,@body)
2383 (error (eval restore-prog) ; restore environment on error
2384 (error (cadr info))))) ; pass error up
2385 ;; restore environment
2386 (eval restore-prog)
2387 result))
2388
2389(defmacro vhdl-visit-file (file-name issue-error &rest body)
2390 "Visit file FILE-NAME and execute BODY."
2391 `(if (null ,file-name)
2392 (progn ,@body)
2393 (unless (file-directory-p ,file-name)
2394 (let ((source-buffer (current-buffer))
2395 (visiting-buffer (find-buffer-visiting ,file-name))
2396 file-opened)
2397 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2398 (condition-case ()
2399 (progn (set-buffer (create-file-buffer ,file-name))
2400 (setq file-opened t)
2401 (vhdl-insert-file-contents ,file-name)
2402 (modify-syntax-entry ?\- ". 12" (syntax-table))
2403 (modify-syntax-entry ?\n ">" (syntax-table))
2404 (modify-syntax-entry ?\^M ">" (syntax-table))
2405 (modify-syntax-entry ?_ "w" (syntax-table))
2406 t)
2407 (error
2408 (if ,issue-error
2409 (progn
2410 (when file-opened (kill-buffer (current-buffer)))
2411 (set-buffer source-buffer)
ec3ec9cc 2412 (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
3dcb36b7
JB
2413 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2414 nil))))
2415 (condition-case info
2416 (progn ,@body)
2417 (error
2418 (if ,issue-error
2419 (progn
2420 (when file-opened (kill-buffer (current-buffer)))
2421 (set-buffer source-buffer)
2422 (error (cadr info)))
2423 (vhdl-warning (cadr info))))))
2424 (when file-opened (kill-buffer (current-buffer)))
2425 (set-buffer source-buffer)))))
2426
2427(defun vhdl-insert-file-contents (filename)
2428 "Nicked from `insert-file-contents-literally', but allow coding system
2429conversion."
2430 (let ((format-alist nil)
2431 (after-insert-file-functions nil)
2432 (jka-compr-compression-info-list nil))
2433 (insert-file-contents filename t)))
2434
2435(defun vhdl-sort-alist (alist)
2436 "Sort alist."
2437 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2438
2439(defun vhdl-get-subdirs (directory)
2440 "Recursively get subdirectories of DIRECTORY."
2441 (let ((dir-list (list (file-name-as-directory directory)))
2442 file-list)
2443 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2444 (while file-list
2445 (when (file-directory-p (car file-list))
2446 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2447 (setq file-list (cdr file-list)))
2448 dir-list))
2449
2450(defun vhdl-aput (alist-symbol key &optional value)
2451 "As `aput', but delete key-value pair if VALUE is nil."
2452 (if value
2453 (aput alist-symbol key value)
2454 (adelete alist-symbol key)))
2455
2456(defun vhdl-delete (elt list)
2457 "Delete by side effect the first occurrence of ELT as a member of LIST."
2458 (setq list (cons nil list))
2459 (let ((list1 list))
2460 (while (and (cdr list1) (not (equal elt (cadr list1))))
2461 (setq list1 (cdr list1)))
2462 (when list
2463 (setcdr list1 (cddr list1))))
2464 (cdr list))
2465
2466(defun vhdl-speedbar-refresh (&optional key)
2467 "Refresh directory or project with name KEY."
2468 (when (and (boundp 'speedbar-frame)
2469 (frame-live-p speedbar-frame))
2470 (let ((pos (point))
2471 (last-frame (selected-frame)))
2472 (if (null key)
2473 (speedbar-refresh)
2474 (select-frame speedbar-frame)
2475 (when (save-excursion
2476 (goto-char (point-min))
2477 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2478 (goto-char (match-end 1))
2479 (speedbar-do-function-pointer)
2480 (backward-char 2)
2481 (speedbar-do-function-pointer)
2482 (message "Refreshing speedbar...done"))
2483 (select-frame last-frame)))))
2484
2485(defun vhdl-show-messages ()
2486 "Get *Messages* buffer to show recent messages."
2487 (interactive)
2488 (display-buffer (if vhdl-xemacs " *Message-Log*" "*Messages*")))
2489
2490(defun vhdl-use-direct-instantiation ()
2491 "Return whether direct instantiation is used."
2492 (or (eq vhdl-use-direct-instantiation 'always)
2493 (and (eq vhdl-use-direct-instantiation 'standard)
2494 (not (vhdl-standard-p '87)))))
2495
2496(defun vhdl-max-marker (marker1 marker2)
2497 "Return larger marker."
2498 (if (> marker1 marker2) marker1 marker2))
2499
2500(defun vhdl-goto-marker (marker)
2501 "Goto marker in appropriate buffer."
2502 (when (markerp marker)
2503 (set-buffer (marker-buffer marker)))
2504 (goto-char marker))
2505
2506(defun vhdl-menu-split (list title)
2507 "Split menu LIST into several submenues, if number of
2508elements > `vhdl-menu-max-size'."
2509 (if (> (length list) vhdl-menu-max-size)
2510 (let ((remain list)
2511 (result '())
2512 (sublist '())
2513 (menuno 1)
2514 (i 0))
2515 (while remain
2516 (setq sublist (cons (car remain) sublist))
2517 (setq remain (cdr remain))
2518 (setq i (+ i 1))
2519 (if (= i vhdl-menu-max-size)
2520 (progn
2521 (setq result (cons (cons (format "%s %s" title menuno)
2522 (nreverse sublist)) result))
2523 (setq i 0)
2524 (setq menuno (+ menuno 1))
2525 (setq sublist '()))))
2526 (and sublist
2527 (setq result (cons (cons (format "%s %s" title menuno)
2528 (nreverse sublist)) result)))
2529 (nreverse result))
2530 list))
2531
2532
2533;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2534;;; Bindings
2535;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2536
2537;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2538;; Key bindings
2539
2540(defvar vhdl-template-map nil
2541 "Keymap for VHDL templates.")
2542
2543(defun vhdl-template-map-init ()
2544 "Initialize `vhdl-template-map'."
2545 (setq vhdl-template-map (make-sparse-keymap))
2546 ;; key bindings for VHDL templates
2547 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2548 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2549 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2550 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2551 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2552 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2553 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2554 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2555 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
5eabfe72
KH
2556 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2557 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2558 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2559 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2560 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2561 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2562 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2563 (define-key vhdl-template-map "el" 'vhdl-template-else)
2564 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2565 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2566 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2567 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2568 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2569 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2570 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2571 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2572 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2573 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2574 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2575 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2576 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2577 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2578 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2579 (define-key vhdl-template-map "li" 'vhdl-template-library)
2580 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2581 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2582 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2583 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2584 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2585 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2586 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2587 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2588 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2589 (define-key vhdl-template-map "po" 'vhdl-template-port)
2590 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2591 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2592 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2593 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2594 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2595 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2596 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2597 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2598 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2599 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2600 (define-key vhdl-template-map "us" 'vhdl-template-use)
2601 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2602 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2603 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2604 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2605 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2606 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2607 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2608 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2609 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2610 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2611 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2612 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2613 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2614 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2615 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2616 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2617 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2618 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2619 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2620 (when (vhdl-standard-p 'ams)
2621 (define-key vhdl-template-map "br" 'vhdl-template-break)
2622 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2623 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2624 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2625 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2626 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2627 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2628 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2629 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2630 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2631 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2632 )
2633 (when (vhdl-standard-p 'math)
2634 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2635 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2636 ))
2637
2638;; initialize template map for VHDL Mode
2639(vhdl-template-map-init)
2640
2641(defun vhdl-function-name (prefix string &optional postfix)
2642 "Generate a Lisp function name.
2643PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2644STRING are replaced by `-' and substrings are converted to lower case."
2645 (let ((name prefix))
2646 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2647 (setq name
2648 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2649 (setq string (substring string (match-beginning 2))))
2650 (when postfix (setq name (concat name "-" postfix)))
2651 (intern name)))
2652
3dcb36b7 2653(defvar vhdl-model-map nil
5eabfe72
KH
2654 "Keymap for VHDL models.")
2655
2656(defun vhdl-model-map-init ()
2657 "Initialize `vhdl-model-map'."
2658 (setq vhdl-model-map (make-sparse-keymap))
2659 ;; key bindings for VHDL models
2660 (let ((model-alist vhdl-model-alist) model)
2661 (while model-alist
2662 (setq model (car model-alist))
2663 (define-key vhdl-model-map (nth 2 model)
2664 (vhdl-function-name "vhdl-model" (nth 0 model)))
2665 (setq model-alist (cdr model-alist)))))
2666
2667;; initialize user model map for VHDL Mode
2668(vhdl-model-map-init)
d2ddb974 2669
3dcb36b7 2670(defvar vhdl-mode-map nil
d2ddb974
KH
2671 "Keymap for VHDL Mode.")
2672
5eabfe72
KH
2673(defun vhdl-mode-map-init ()
2674 "Initialize `vhdl-mode-map'."
d2ddb974 2675 (setq vhdl-mode-map (make-sparse-keymap))
5eabfe72 2676 ;; template key bindings
0a2e512a 2677 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
5eabfe72 2678 ;; model key bindings
0a2e512a 2679 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
d2ddb974 2680 ;; standard key bindings
0a2e512a
RF
2681 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2682 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2683 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2684 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2685 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
2686 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2687 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
3dcb36b7 2688 (unless vhdl-xemacs ; would override `M-backspace' in XEmacs
0a2e512a
RF
2689 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
2690 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
2691 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
5eabfe72 2692 ;; backspace/delete key bindings
0a2e512a 2693 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
3dcb36b7 2694 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
0a2e512a 2695 (define-key vhdl-mode-map [delete] 'delete-char)
3dcb36b7 2696 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
5eabfe72 2697 ;; mode specific key bindings
3dcb36b7
JB
2698 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2699 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2700 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2701 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2702 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2703 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2704 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
0a2e512a 2705 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
5eabfe72 2706 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
3dcb36b7 2707 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
5eabfe72
KH
2708 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2709 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2710 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2711 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2712 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2713 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2714 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
3dcb36b7 2715 (if vhdl-xemacs ; `... C-g' not allowed in XEmacs
5eabfe72
KH
2716 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2717 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
3dcb36b7 2718 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
5eabfe72
KH
2719 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2720 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
3dcb36b7
JB
2721 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2722 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2723 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2724 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2725 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2726 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2727 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2728 (define-key vhdl-mode-map "\C-c\C-c\C-n" 'vhdl-compose-new-component)
2729 (define-key vhdl-mode-map "\C-c\C-c\C-p" 'vhdl-compose-place-component)
2730 (define-key vhdl-mode-map "\C-c\C-c\C-w" 'vhdl-compose-wire-components)
0a2e512a 2731 (define-key vhdl-mode-map "\C-c\C-c\C-f" 'vhdl-compose-configuration)
3dcb36b7
JB
2732 (define-key vhdl-mode-map "\C-c\C-c\C-k" 'vhdl-compose-components-package)
2733 (define-key vhdl-mode-map "\C-cc" 'vhdl-comment-uncomment-region)
0a2e512a
RF
2734 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2735 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
3dcb36b7
JB
2736 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2737 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
0a2e512a 2738 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
3dcb36b7
JB
2739 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2740 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2741 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2742 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2743 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2744 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2745 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2746 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2747 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2748 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2749 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2750 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2751 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2752 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2753 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
5eabfe72
KH
2754 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2755 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2756 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2757 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2758 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2759 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2760 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2761 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2762 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
3dcb36b7
JB
2763 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2764 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2765 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2766 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2767 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
0a2e512a
RF
2768 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2769 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
3dcb36b7
JB
2770 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2771 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
0a2e512a
RF
2772 (define-key vhdl-mode-map "\C-cf" 'vhdl-fontify-buffer)
2773 (define-key vhdl-mode-map "\C-cs" 'vhdl-statistics-buffer)
2774 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
2775 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2776 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
2777 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
5eabfe72 2778 ;; insert commands bindings
3dcb36b7 2779 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
5eabfe72
KH
2780 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2781 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2782 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2783 ;; electric key bindings
0a2e512a
RF
2784 (define-key vhdl-mode-map " " 'vhdl-electric-space)
2785 (when vhdl-intelligent-tab
2786 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
2787 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2788 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2789 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2790 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2791 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2792 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2793 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2794 (define-key vhdl-mode-map "." 'vhdl-electric-period)
5eabfe72 2795 (when (vhdl-standard-p 'ams)
0a2e512a 2796 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
5eabfe72
KH
2797
2798;; initialize mode map for VHDL Mode
2799(vhdl-mode-map-init)
d2ddb974
KH
2800
2801;; define special minibuffer keymap for enabling word completion in minibuffer
2802;; (useful in template generator prompts)
4bcb9c95
SM
2803(defvar vhdl-minibuffer-local-map
2804 (let ((map (make-sparse-keymap)))
2805 (set-keymap-parent map minibuffer-local-map)
2806 (when vhdl-word-completion-in-minibuffer
2807 (define-key map "\t" 'vhdl-minibuffer-tab))
2808 map)
d2ddb974
KH
2809 "Keymap for minibuffer used in VHDL Mode.")
2810
5eabfe72
KH
2811;; set up electric character functions to work with
2812;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2813(mapcar
2814 (function
2815 (lambda (sym)
2816 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2817 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2818 '(vhdl-electric-space
2819 vhdl-electric-tab
2820 vhdl-electric-return
2821 vhdl-electric-dash
2822 vhdl-electric-open-bracket
2823 vhdl-electric-close-bracket
2824 vhdl-electric-quote
2825 vhdl-electric-semicolon
2826 vhdl-electric-comma
2827 vhdl-electric-period
2828 vhdl-electric-equal))
2829
3dcb36b7
JB
2830;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2831;; Syntax table
2832
d2ddb974 2833(defvar vhdl-mode-syntax-table nil
5eabfe72 2834 "Syntax table used in `vhdl-mode' buffers.")
d2ddb974 2835
3dcb36b7
JB
2836(defvar vhdl-mode-ext-syntax-table nil
2837 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2838
5eabfe72
KH
2839(defun vhdl-mode-syntax-table-init ()
2840 "Initialize `vhdl-mode-syntax-table'."
d2ddb974 2841 (setq vhdl-mode-syntax-table (make-syntax-table))
5eabfe72
KH
2842 ;; define punctuation
2843 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2844 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2845 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2846 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2847 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2848 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2849 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2850 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2851 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2852 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2853 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2854 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2855 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2856 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2857 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2858 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2859 ;; define string
2860 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2861 ;; define underscore
2862 (when vhdl-underscore-is-part-of-word
3dcb36b7 2863 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
5eabfe72
KH
2864 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2865 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2866 ;; and \n and \^M end a comment
2867 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2868 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2869 ;; define parentheses to match
2870 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2871 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2872 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2873 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2874 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
3dcb36b7
JB
2875 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2876 ;; extended syntax table including '_' (for simpler search regexps)
2877 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2878 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
5eabfe72
KH
2879
2880;; initialize syntax table for VHDL Mode
2881(vhdl-mode-syntax-table-init)
2882
d2ddb974
KH
2883(defvar vhdl-syntactic-context nil
2884 "Buffer local variable containing syntactic analysis list.")
2885(make-variable-buffer-local 'vhdl-syntactic-context)
2886
5eabfe72 2887;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2888;; Abbrev ook bindings
d2ddb974
KH
2889
2890(defvar vhdl-mode-abbrev-table nil
5eabfe72
KH
2891 "Abbrev table to use in `vhdl-mode' buffers.")
2892
2893(defun vhdl-mode-abbrev-table-init ()
2894 "Initialize `vhdl-mode-abbrev-table'."
2895 (when vhdl-mode-abbrev-table (clear-abbrev-table vhdl-mode-abbrev-table))
2896 (define-abbrev-table 'vhdl-mode-abbrev-table
2897 (append
2898 (when (memq 'vhdl vhdl-electric-keywords)
2899 ;; VHDL'93 keywords
2900 '(
0a2e512a
RF
2901 ("--" "" vhdl-template-display-comment-hook 0)
2902 ("abs" "" vhdl-template-default-hook 0)
2903 ("access" "" vhdl-template-default-hook 0)
2904 ("after" "" vhdl-template-default-hook 0)
2905 ("alias" "" vhdl-template-alias-hook 0)
2906 ("all" "" vhdl-template-default-hook 0)
2907 ("and" "" vhdl-template-default-hook 0)
2908 ("arch" "" vhdl-template-architecture-hook 0)
2909 ("architecture" "" vhdl-template-architecture-hook 0)
2910 ("array" "" vhdl-template-default-hook 0)
2911 ("assert" "" vhdl-template-assert-hook 0)
2912 ("attr" "" vhdl-template-attribute-hook 0)
2913 ("attribute" "" vhdl-template-attribute-hook 0)
2914 ("begin" "" vhdl-template-default-indent-hook 0)
2915 ("block" "" vhdl-template-block-hook 0)
2916 ("body" "" vhdl-template-default-hook 0)
2917 ("buffer" "" vhdl-template-default-hook 0)
2918 ("bus" "" vhdl-template-default-hook 0)
2919 ("case" "" vhdl-template-case-hook 0)
2920 ("comp" "" vhdl-template-component-hook 0)
2921 ("component" "" vhdl-template-component-hook 0)
2922 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2923 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2924 ("conf" "" vhdl-template-configuration-hook 0)
2925 ("configuration" "" vhdl-template-configuration-hook 0)
2926 ("cons" "" vhdl-template-constant-hook 0)
2927 ("constant" "" vhdl-template-constant-hook 0)
2928 ("disconnect" "" vhdl-template-disconnect-hook 0)
2929 ("downto" "" vhdl-template-default-hook 0)
2930 ("else" "" vhdl-template-else-hook 0)
2931 ("elseif" "" vhdl-template-elsif-hook 0)
2932 ("elsif" "" vhdl-template-elsif-hook 0)
2933 ("end" "" vhdl-template-default-indent-hook 0)
2934 ("entity" "" vhdl-template-entity-hook 0)
2935 ("exit" "" vhdl-template-exit-hook 0)
2936 ("file" "" vhdl-template-file-hook 0)
2937 ("for" "" vhdl-template-for-hook 0)
2938 ("func" "" vhdl-template-function-hook 0)
2939 ("function" "" vhdl-template-function-hook 0)
2940 ("generic" "" vhdl-template-generic-hook 0)
2941 ("group" "" vhdl-template-group-hook 0)
2942 ("guarded" "" vhdl-template-default-hook 0)
2943 ("if" "" vhdl-template-if-hook 0)
2944 ("impure" "" vhdl-template-default-hook 0)
2945 ("in" "" vhdl-template-default-hook 0)
2946 ("inertial" "" vhdl-template-default-hook 0)
2947 ("inout" "" vhdl-template-default-hook 0)
2948 ("inst" "" vhdl-template-instance-hook 0)
2949 ("instance" "" vhdl-template-instance-hook 0)
2950 ("is" "" vhdl-template-default-hook 0)
2951 ("label" "" vhdl-template-default-hook 0)
2952 ("library" "" vhdl-template-library-hook 0)
2953 ("linkage" "" vhdl-template-default-hook 0)
2954 ("literal" "" vhdl-template-default-hook 0)
2955 ("loop" "" vhdl-template-bare-loop-hook 0)
2956 ("map" "" vhdl-template-map-hook 0)
2957 ("mod" "" vhdl-template-default-hook 0)
2958 ("nand" "" vhdl-template-default-hook 0)
2959 ("new" "" vhdl-template-default-hook 0)
2960 ("next" "" vhdl-template-next-hook 0)
2961 ("nor" "" vhdl-template-default-hook 0)
2962 ("not" "" vhdl-template-default-hook 0)
2963 ("null" "" vhdl-template-default-hook 0)
2964 ("of" "" vhdl-template-default-hook 0)
2965 ("on" "" vhdl-template-default-hook 0)
2966 ("open" "" vhdl-template-default-hook 0)
2967 ("or" "" vhdl-template-default-hook 0)
2968 ("others" "" vhdl-template-others-hook 0)
2969 ("out" "" vhdl-template-default-hook 0)
2970 ("pack" "" vhdl-template-package-hook 0)
2971 ("package" "" vhdl-template-package-hook 0)
2972 ("port" "" vhdl-template-port-hook 0)
2973 ("postponed" "" vhdl-template-default-hook 0)
2974 ("procedure" "" vhdl-template-procedure-hook 0)
2975 ("process" "" vhdl-template-process-hook 0)
2976 ("pure" "" vhdl-template-default-hook 0)
2977 ("range" "" vhdl-template-default-hook 0)
2978 ("record" "" vhdl-template-default-hook 0)
2979 ("register" "" vhdl-template-default-hook 0)
2980 ("reject" "" vhdl-template-default-hook 0)
2981 ("rem" "" vhdl-template-default-hook 0)
2982 ("report" "" vhdl-template-report-hook 0)
2983 ("return" "" vhdl-template-return-hook 0)
2984 ("rol" "" vhdl-template-default-hook 0)
2985 ("ror" "" vhdl-template-default-hook 0)
2986 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2987 ("severity" "" vhdl-template-default-hook 0)
2988 ("shared" "" vhdl-template-default-hook 0)
2989 ("sig" "" vhdl-template-signal-hook 0)
2990 ("signal" "" vhdl-template-signal-hook 0)
2991 ("sla" "" vhdl-template-default-hook 0)
2992 ("sll" "" vhdl-template-default-hook 0)
2993 ("sra" "" vhdl-template-default-hook 0)
2994 ("srl" "" vhdl-template-default-hook 0)
2995 ("subtype" "" vhdl-template-subtype-hook 0)
2996 ("then" "" vhdl-template-default-hook 0)
2997 ("to" "" vhdl-template-default-hook 0)
2998 ("transport" "" vhdl-template-default-hook 0)
2999 ("type" "" vhdl-template-type-hook 0)
3000 ("unaffected" "" vhdl-template-default-hook 0)
3001 ("units" "" vhdl-template-default-hook 0)
3002 ("until" "" vhdl-template-default-hook 0)
3003 ("use" "" vhdl-template-use-hook 0)
3004 ("var" "" vhdl-template-variable-hook 0)
3005 ("variable" "" vhdl-template-variable-hook 0)
3006 ("wait" "" vhdl-template-wait-hook 0)
3007 ("when" "" vhdl-template-when-hook 0)
3008 ("while" "" vhdl-template-while-loop-hook 0)
3009 ("with" "" vhdl-template-with-hook 0)
3010 ("xnor" "" vhdl-template-default-hook 0)
3011 ("xor" "" vhdl-template-default-hook 0)
5eabfe72
KH
3012 ))
3013 ;; VHDL-AMS keywords
3014 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
3015 '(
0a2e512a
RF
3016 ("across" "" vhdl-template-default-hook 0)
3017 ("break" "" vhdl-template-break-hook 0)
3018 ("limit" "" vhdl-template-limit-hook 0)
3019 ("nature" "" vhdl-template-nature-hook 0)
3020 ("noise" "" vhdl-template-default-hook 0)
3021 ("procedural" "" vhdl-template-procedural-hook 0)
3022 ("quantity" "" vhdl-template-quantity-hook 0)
3023 ("reference" "" vhdl-template-default-hook 0)
3024 ("spectrum" "" vhdl-template-default-hook 0)
3025 ("subnature" "" vhdl-template-subnature-hook 0)
3026 ("terminal" "" vhdl-template-terminal-hook 0)
3027 ("through" "" vhdl-template-default-hook 0)
3028 ("tolerance" "" vhdl-template-default-hook 0)
5eabfe72
KH
3029 ))
3030 ;; user model keywords
3031 (when (memq 'user vhdl-electric-keywords)
3032 (let ((alist vhdl-model-alist)
3033 abbrev-list keyword)
3034 (while alist
3035 (setq keyword (nth 3 (car alist)))
3036 (unless (equal keyword "")
3037 (setq abbrev-list
3038 (cons (list keyword ""
3039 (vhdl-function-name
0a2e512a 3040 "vhdl-model" (nth 0 (car alist)) "hook") 0)
5eabfe72
KH
3041 abbrev-list)))
3042 (setq alist (cdr alist)))
3043 abbrev-list)))))
3044
3045;; initialize abbrev table for VHDL Mode
3046(vhdl-mode-abbrev-table-init)
3047
3048;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3049;; Template completion lists
3050
3051(defvar vhdl-template-construct-alist nil
3052 "List of built-in construct templates.")
3053
3054(defun vhdl-template-construct-alist-init ()
3055 "Initialize `vhdl-template-construct-alist'."
3056 (setq
3057 vhdl-template-construct-alist
3058 (append
3059 '(
3060 ("alias declaration" vhdl-template-alias)
3061 ("architecture body" vhdl-template-architecture)
3062 ("assertion" vhdl-template-assert)
3063 ("attribute declaration" vhdl-template-attribute-decl)
3064 ("attribute specification" vhdl-template-attribute-spec)
3065 ("block configuration" vhdl-template-block-configuration)
3066 ("block statement" vhdl-template-block)
3067 ("case statement" vhdl-template-case-is)
3068 ("component configuration" vhdl-template-component-conf)
3069 ("component declaration" vhdl-template-component-decl)
3070 ("component instantiation statement" vhdl-template-component-inst)
3071 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
3072 ("configuration declaration" vhdl-template-configuration-decl)
3073 ("configuration specification" vhdl-template-configuration-spec)
3074 ("constant declaration" vhdl-template-constant)
3075 ("disconnection specification" vhdl-template-disconnect)
3076 ("entity declaration" vhdl-template-entity)
3077 ("exit statement" vhdl-template-exit)
3078 ("file declaration" vhdl-template-file)
3079 ("generate statement" vhdl-template-generate)
3080 ("generic clause" vhdl-template-generic)
3081 ("group declaration" vhdl-template-group-decl)
3082 ("group template declaration" vhdl-template-group-template)
3083 ("if statement" vhdl-template-if-then)
3084 ("library clause" vhdl-template-library)
3085 ("loop statement" vhdl-template-loop)
3086 ("next statement" vhdl-template-next)
3087 ("package declaration" vhdl-template-package-decl)
3088 ("package body" vhdl-template-package-body)
3089 ("port clause" vhdl-template-port)
3090 ("process statement" vhdl-template-process)
3091 ("report statement" vhdl-template-report)
3092 ("return statement" vhdl-template-return)
3093 ("selected signal assignment" vhdl-template-selected-signal-asst)
3094 ("signal declaration" vhdl-template-signal)
3095 ("subprogram declaration" vhdl-template-subprogram-decl)
3096 ("subprogram body" vhdl-template-subprogram-body)
3097 ("subtype declaration" vhdl-template-subtype)
3098 ("type declaration" vhdl-template-type)
3099 ("use clause" vhdl-template-use)
3100 ("variable declaration" vhdl-template-variable)
3101 ("wait statement" vhdl-template-wait)
3102 )
3103 (when (vhdl-standard-p 'ams)
3104 '(
3105 ("break statement" vhdl-template-break)
3106 ("nature declaration" vhdl-template-nature)
3107 ("quantity declaration" vhdl-template-quantity)
3108 ("simultaneous case statement" vhdl-template-case-use)
3109 ("simultaneous if statement" vhdl-template-if-use)
3110 ("simultaneous procedural statement" vhdl-template-procedural)
3111 ("step limit specification" vhdl-template-limit)
3112 ("subnature declaration" vhdl-template-subnature)
3113 ("terminal declaration" vhdl-template-terminal)
3114 )))))
d2ddb974 3115
5eabfe72
KH
3116;; initialize for VHDL Mode
3117(vhdl-template-construct-alist-init)
3118
3119(defvar vhdl-template-package-alist nil
3120 "List of built-in package templates.")
3121
3122(defun vhdl-template-package-alist-init ()
3123 "Initialize `vhdl-template-package-alist'."
3124 (setq
3125 vhdl-template-package-alist
3126 (append
3127 '(
3128 ("numeric_bit" vhdl-template-package-numeric-bit)
3129 ("numeric_std" vhdl-template-package-numeric-std)
3130 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3131 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3132 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3133 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3134 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3135 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3136 ("textio" vhdl-template-package-textio)
3137 )
3138 (when (vhdl-standard-p 'math)
3139 '(
3140 ("math_complex" vhdl-template-package-math-complex)
3141 ("math_real" vhdl-template-package-math-real)
3142 )))))
d2ddb974 3143
5eabfe72
KH
3144;; initialize for VHDL Mode
3145(vhdl-template-package-alist-init)
d2ddb974 3146
5eabfe72 3147(defvar vhdl-template-directive-alist
3dcb36b7
JB
3148 '(
3149 ("translate_on" vhdl-template-directive-translate-on)
3150 ("translate_off" vhdl-template-directive-translate-off)
3151 ("synthesis_on" vhdl-template-directive-synthesis-on)
3152 ("synthesis_off" vhdl-template-directive-synthesis-off)
3153 )
5eabfe72 3154 "List of built-in directive templates.")
d2ddb974 3155
5eabfe72
KH
3156
3157;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3158;;; Menues
3159;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3160
3161;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
3162;; VHDL menu (using `easy-menu.el')
3163
5eabfe72
KH
3164(defun vhdl-customize ()
3165 "Call the customize function with `vhdl' as argument."
3166 (interactive)
3167 (customize-browse 'vhdl))
3168
5eabfe72
KH
3169(defun vhdl-create-mode-menu ()
3170 "Create VHDL Mode menu."
3dcb36b7
JB
3171 `("VHDL"
3172 ,(append
3173 '("Project"
3174 ["None" (vhdl-set-project "")
3175 :style radio :selected (null vhdl-project)]
3176 "--")
3177 ;; add menu entries for defined projects
3178 (let ((project-alist vhdl-project-alist) menu-list name)
3179 (while project-alist
3180 (setq name (caar project-alist))
3181 (setq menu-list
3182 (cons `[,name (vhdl-set-project ,name)
3183 :style radio :selected (equal ,name vhdl-project)]
3184 menu-list))
3185 (setq project-alist (cdr project-alist)))
3186 (setq menu-list
3187 (if vhdl-project-sort
3188 (sort menu-list
3189 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3190 (nreverse menu-list)))
3191 (vhdl-menu-split menu-list "Project"))
3192 '("--" "--"
3193 ["Select Project..." vhdl-set-project t]
0a2e512a 3194 ["Set As Default Project" vhdl-set-default-project t]
3dcb36b7
JB
3195 "--"
3196 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3197 ["Import Project..." vhdl-import-project
3198 :keys "C-c C-p C-m" :active t]
3199 ["Export Project" vhdl-export-project vhdl-project]
3200 "--"
3201 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
d2ddb974 3202 "--"
3dcb36b7
JB
3203 ("Compile"
3204 ["Compile Buffer" vhdl-compile t]
3205 ["Stop Compilation" kill-compilation t]
3206 "--"
3207 ["Make" vhdl-make t]
3208 ["Generate Makefile" vhdl-generate-makefile t]
3209 "--"
3210 ["Next Error" next-error t]
3211 ["Previous Error" previous-error t]
3212 ["First Error" first-error t]
3213 "--"
3214 ,(append
3215 '("Compiler")
3216 ;; add menu entries for defined compilers
3217 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3218 (while comp-alist
3219 (setq name (caar comp-alist))
3220 (setq menu-list
3221 (cons `[,name (setq vhdl-compiler ,name)
3222 :style radio :selected (equal ,name vhdl-compiler)]
3223 menu-list))
3224 (setq comp-alist (cdr comp-alist)))
3225 (setq menu-list (nreverse menu-list))
3226 (vhdl-menu-split menu-list "Compiler"))
3227 '("--" "--"
3228 ["Select Compiler..." vhdl-set-compiler t]
3229 "--"
3230 ["Customize Compiler..."
3231 (customize-option 'vhdl-compiler-alist) t])))
5eabfe72 3232 "--"
3dcb36b7
JB
3233 ,(append
3234 '("Template"
3235 ("VHDL Construct 1"
3236 ["Alias" vhdl-template-alias t]
3237 ["Architecture" vhdl-template-architecture t]
3238 ["Assert" vhdl-template-assert t]
3239 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3240 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3241 ["Block" vhdl-template-block t]
3242 ["Case" vhdl-template-case-is t]
3243 ["Component (Decl)" vhdl-template-component-decl t]
3244 ["(Component) Instance" vhdl-template-component-inst t]
3245 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3246 ["Configuration (Block)" vhdl-template-block-configuration t]
3247 ["Configuration (Comp)" vhdl-template-component-conf t]
3248 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3249 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3250 ["Constant" vhdl-template-constant t]
3251 ["Disconnect" vhdl-template-disconnect t]
3252 ["Else" vhdl-template-else t]
3253 ["Elsif" vhdl-template-elsif t]
3254 ["Entity" vhdl-template-entity t]
3255 ["Exit" vhdl-template-exit t]
3256 ["File" vhdl-template-file t]
3257 ["For (Generate)" vhdl-template-for-generate t]
3258 ["For (Loop)" vhdl-template-for-loop t]
3259 ["Function (Body)" vhdl-template-function-body t]
3260 ["Function (Decl)" vhdl-template-function-decl t]
3261 ["Generic" vhdl-template-generic t]
3262 ["Group (Decl)" vhdl-template-group-decl t]
3263 ["Group (Template)" vhdl-template-group-template t])
3264 ("VHDL Construct 2"
3265 ["If (Generate)" vhdl-template-if-generate t]
3266 ["If (Then)" vhdl-template-if-then t]
3267 ["Library" vhdl-template-library t]
3268 ["Loop" vhdl-template-bare-loop t]
3269 ["Map" vhdl-template-map t]
3270 ["Next" vhdl-template-next t]
3271 ["Others (Aggregate)" vhdl-template-others t]
3272 ["Package (Decl)" vhdl-template-package-decl t]
3273 ["Package (Body)" vhdl-template-package-body t]
3274 ["Port" vhdl-template-port t]
3275 ["Procedure (Body)" vhdl-template-procedure-body t]
3276 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3277 ["Process (Comb)" vhdl-template-process-comb t]
3278 ["Process (Seq)" vhdl-template-process-seq t]
3279 ["Report" vhdl-template-report t]
3280 ["Return" vhdl-template-return t]
3281 ["Select" vhdl-template-selected-signal-asst t]
3282 ["Signal" vhdl-template-signal t]
3283 ["Subtype" vhdl-template-subtype t]
3284 ["Type" vhdl-template-type t]
3285 ["Use" vhdl-template-use t]
3286 ["Variable" vhdl-template-variable t]
3287 ["Wait" vhdl-template-wait t]
3288 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3289 ["When" vhdl-template-when t]
3290 ["While (Loop)" vhdl-template-while-loop t]
3291 ["With" vhdl-template-with t]))
3292 (when (vhdl-standard-p 'ams)
3293 '(("VHDL-AMS Construct"
3294 ["Break" vhdl-template-break t]
3295 ["Case (Use)" vhdl-template-case-use t]
3296 ["If (Use)" vhdl-template-if-use t]
3297 ["Limit" vhdl-template-limit t]
3298 ["Nature" vhdl-template-nature t]
3299 ["Procedural" vhdl-template-procedural t]
3300 ["Quantity (Free)" vhdl-template-quantity-free t]
3301 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3302 ["Quantity (Source)" vhdl-template-quantity-source t]
3303 ["Subnature" vhdl-template-subnature t]
3304 ["Terminal" vhdl-template-terminal t])))
3305 '(["Insert Construct..." vhdl-template-insert-construct
3306 :keys "C-c C-i C-t"]
3307 "--")
3308 (list
3309 (append
3310 '("Package")
3311 (when (vhdl-standard-p 'math)
3312 '(["math_complex" vhdl-template-package-math-complex t]
3313 ["math_real" vhdl-template-package-math-real t]))
3314 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3315 ["numeric_std" vhdl-template-package-numeric-std t]
3316 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3317 ["textio" vhdl-template-package-textio t]
3318 "--"
3319 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3320 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3321 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3322 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3323 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3324 "--"
3325 ["Insert Package..." vhdl-template-insert-package
3326 :keys "C-c C-i C-p"])))
3327 '(("Directive"
3328 ["translate_on" vhdl-template-directive-translate-on t]
3329 ["translate_off" vhdl-template-directive-translate-off t]
3330 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3331 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3332 "--"
3333 ["Insert Directive..." vhdl-template-insert-directive
3334 :keys "C-c C-i C-d"])
5eabfe72 3335 "--"
3dcb36b7
JB
3336 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3337 ["Insert Footer" vhdl-template-footer t]
3338 ["Insert Date" vhdl-template-insert-date t]
3339 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
5eabfe72 3340 "--"
3dcb36b7
JB
3341 ["Query Next Prompt" vhdl-template-search-prompt t]))
3342 ,(append
3343 '("Model")
3344 ;; add menu entries for defined models
3345 (let ((model-alist vhdl-model-alist) menu-list model)
3346 (while model-alist
3347 (setq model (car model-alist))
3348 (setq menu-list
3349 (cons
3350 (vector
3351 (nth 0 model)
3352 (vhdl-function-name "vhdl-model" (nth 0 model))
3353 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3354 menu-list))
3355 (setq model-alist (cdr model-alist)))
3356 (setq menu-list (nreverse menu-list))
3357 (vhdl-menu-split menu-list "Model"))
3358 '("--" "--"
3359 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3360 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3361 ("Port"
5eabfe72 3362 ["Copy" vhdl-port-copy t]
d2ddb974 3363 "--"
5eabfe72
KH
3364 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3365 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3366 ["Paste As Instance" vhdl-port-paste-instance
3367 :keys "C-c C-p C-i" :active vhdl-port-list]
3368 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3369 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3370 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3dcb36b7 3371 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
d2ddb974 3372 "--"
3dcb36b7
JB
3373 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3374 "--"
3375 ["Flatten" vhdl-port-flatten
3376 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3377 ["Reverse Direction" vhdl-port-reverse-direction
3378 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3379 ("Compose"
3380 ["New Component" vhdl-compose-new-component t]
0a2e512a 3381 ["Copy Component" vhdl-port-copy t]
3dcb36b7
JB
3382 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3383 ["Wire Components" vhdl-compose-wire-components t]
3384 "--"
0a2e512a 3385 ["Generate Configuration" vhdl-compose-configuration t]
3dcb36b7
JB
3386 ["Generate Components Package" vhdl-compose-components-package t])
3387 ("Subprogram"
3388 ["Copy" vhdl-subprog-copy t]
3389 "--"
3390 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3391 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3392 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3393 "--"
3394 ["Flatten" vhdl-subprog-flatten
3395 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3396 "--"
3397 ("Comment"
5eabfe72
KH
3398 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3399 "--"
3400 ["Insert Inline Comment" vhdl-comment-append-inline t]
3401 ["Insert Horizontal Line" vhdl-comment-display-line t]
3402 ["Insert Display Comment" vhdl-comment-display t]
3403 "--"
3404 ["Fill Comment" fill-paragraph t]
3405 ["Fill Comment Region" fill-region (mark)]
3406 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3dcb36b7
JB
3407 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3408 ("Line"
5eabfe72
KH
3409 ["Kill" vhdl-line-kill t]
3410 ["Copy" vhdl-line-copy t]
3411 ["Yank" vhdl-line-yank t]
3412 ["Expand" vhdl-line-expand t]
3413 "--"
3414 ["Transpose Next" vhdl-line-transpose-next t]
3415 ["Transpose Prev" vhdl-line-transpose-previous t]
3416 ["Open" vhdl-line-open t]
3dcb36b7 3417 ["Join" vhdl-delete-indentation t]
5eabfe72
KH
3418 "--"
3419 ["Goto" goto-line t]
3dcb36b7
JB
3420 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3421 ("Move"
5eabfe72
KH
3422 ["Forward Statement" vhdl-end-of-statement t]
3423 ["Backward Statement" vhdl-beginning-of-statement t]
3424 ["Forward Expression" vhdl-forward-sexp t]
3425 ["Backward Expression" vhdl-backward-sexp t]
3dcb36b7
JB
3426 ["Forward Same Indent" vhdl-forward-same-indent t]
3427 ["Backward Same Indent" vhdl-backward-same-indent t]
5eabfe72
KH
3428 ["Forward Function" vhdl-end-of-defun t]
3429 ["Backward Function" vhdl-beginning-of-defun t]
3dcb36b7
JB
3430 ["Mark Function" vhdl-mark-defun t])
3431 "--"
3432 ("Indent"
3433 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3434 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
5eabfe72 3435 ["Region" vhdl-indent-region (mark)]
3dcb36b7
JB
3436 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3437 ("Align"
5eabfe72 3438 ["Group" vhdl-align-group t]
3dcb36b7
JB
3439 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3440 ["List" vhdl-align-list t]
3441 ["Declarations" vhdl-align-declarations t]
3442 ["Region" vhdl-align-region (mark)]
3443 ["Buffer" vhdl-align-buffer t]
5eabfe72
KH
3444 "--"
3445 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3446 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3dcb36b7
JB
3447 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3448 ("Fill"
3449 ["List" vhdl-fill-list t]
3450 ["Group" vhdl-fill-group t]
3451 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3452 ["Region" vhdl-fill-region (mark)])
3453 ("Beautify"
3454 ["Region" vhdl-beautify-region (mark)]
3455 ["Buffer" vhdl-beautify-buffer t])
3456 ("Fix"
3457 ["Generic/Port Clause" vhdl-fix-clause t]
5eabfe72 3458 "--"
3dcb36b7
JB
3459 ["Case Region" vhdl-fix-case-region (mark)]
3460 ["Case Buffer" vhdl-fix-case-buffer t]
3461 "--"
3462 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3463 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3464 "--"
3465 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3466 ("Update"
3467 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3468 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3469 "--"
3470 ["Fontify Buffer" vhdl-fontify-buffer t]
3471 ["Statistics Buffer" vhdl-statistics-buffer t]
3472 ["Show Messages" vhdl-show-messages t]
3473 ["Syntactic Info" vhdl-show-syntactic-information t]
3474 "--"
3475 ["Speedbar" vhdl-speedbar t]
3476 ["Hide/Show" vhdl-hs-minor-mode t]
3477 "--"
3478 ("Documentation"
5eabfe72 3479 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3dcb36b7 3480 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
5eabfe72 3481 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3dcb36b7
JB
3482 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3483 ["Version" vhdl-version t]
3484 ["Bug Report..." vhdl-submit-bug-report t]
3485 "--"
3486 ("Options"
3487 ("Mode"
3488 ["Electric Mode"
3489 (progn (customize-set-variable 'vhdl-electric-mode
3490 (not vhdl-electric-mode))
3491 (vhdl-mode-line-update))
3492 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3493 ["Stutter Mode"
3494 (progn (customize-set-variable 'vhdl-stutter-mode
3495 (not vhdl-stutter-mode))
3496 (vhdl-mode-line-update))
3497 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3498 ["Indent Tabs Mode"
3499 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3500 (not vhdl-indent-tabs-mode))
3501 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3502 :style toggle :selected vhdl-indent-tabs-mode]
3503 "--"
3504 ["Customize Group..." (customize-group 'vhdl-mode) t])
3505 ("Project"
3506 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3507 ,(append
3508 '("Selected Project at Startup"
3509 ["None" (progn (customize-set-variable 'vhdl-project nil)
3510 (vhdl-set-project ""))
3511 :style radio :selected (null vhdl-project)]
3512 "--")
3513 ;; add menu entries for defined projects
3514 (let ((project-alist vhdl-project-alist) menu-list name)
3515 (while project-alist
3516 (setq name (caar project-alist))
3517 (setq menu-list
3518 (cons `[,name (progn (customize-set-variable
3519 'vhdl-project ,name)
3520 (vhdl-set-project ,name))
3521 :style radio :selected (equal ,name vhdl-project)]
3522 menu-list))
3523 (setq project-alist (cdr project-alist)))
3524 (setq menu-list (nreverse menu-list))
3525 (vhdl-menu-split menu-list "Project")))
3526 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3527 ("Auto Load Setup File"
3528 ["At Startup"
3529 (customize-set-variable 'vhdl-project-auto-load
3530 (if (memq 'startup vhdl-project-auto-load)
3531 (delq 'startup vhdl-project-auto-load)
3532 (cons 'startup vhdl-project-auto-load)))
3533 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3534 ["Sort Projects"
3535 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3536 :style toggle :selected vhdl-project-sort]
3537 "--"
3538 ["Customize Group..." (customize-group 'vhdl-project) t])
3539 ("Compiler"
3540 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3541 ,(append
3542 '("Selected Compiler at Startup")
3543 ;; add menu entries for defined compilers
3544 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3545 (while comp-alist
3546 (setq name (caar comp-alist))
3547 (setq menu-list
3548 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3549 :style radio :selected (equal ,name vhdl-compiler)]
3550 menu-list))
3551 (setq comp-alist (cdr comp-alist)))
3552 (setq menu-list (nreverse menu-list))
3553 (vhdl-menu-split menu-list "Compler")))
3554 ["Use Local Error Regexp"
3555 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3556 (not vhdl-compile-use-local-error-regexp))
3557 :style toggle :selected vhdl-compile-use-local-error-regexp]
3558 ["Makefile Generation Hook..."
3559 (customize-option 'vhdl-makefile-generation-hook) t]
3560 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3561 "--"
3562 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3563 ("Style"
3564 ("VHDL Standard"
3565 ["VHDL'87"
3566 (progn (customize-set-variable 'vhdl-standard
3567 (list '87 (cadr vhdl-standard)))
3568 (vhdl-activate-customizations))
3569 :style radio :selected (eq '87 (car vhdl-standard))]
3570 ["VHDL'93"
3571 (progn (customize-set-variable 'vhdl-standard
3572 (list '93 (cadr vhdl-standard)))
3573 (vhdl-activate-customizations))
3574 :style radio :selected (eq '93 (car vhdl-standard))]
3575 "--"
3576 ["VHDL-AMS"
3577 (progn (customize-set-variable
3578 'vhdl-standard (list (car vhdl-standard)
3579 (if (memq 'ams (cadr vhdl-standard))
3580 (delq 'ams (cadr vhdl-standard))
3581 (cons 'ams (cadr vhdl-standard)))))
3582 (vhdl-activate-customizations))
3583 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3584 ["Math Packages"
3585 (progn (customize-set-variable
3586 'vhdl-standard (list (car vhdl-standard)
3587 (if (memq 'math (cadr vhdl-standard))
3588 (delq 'math (cadr vhdl-standard))
3589 (cons 'math (cadr vhdl-standard)))))
3590 (vhdl-activate-customizations))
3591 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3592 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3593 ["Upper Case Keywords"
3594 (customize-set-variable 'vhdl-upper-case-keywords
3595 (not vhdl-upper-case-keywords))
3596 :style toggle :selected vhdl-upper-case-keywords]
3597 ["Upper Case Types"
3598 (customize-set-variable 'vhdl-upper-case-types
3599 (not vhdl-upper-case-types))
3600 :style toggle :selected vhdl-upper-case-types]
3601 ["Upper Case Attributes"
3602 (customize-set-variable 'vhdl-upper-case-attributes
3603 (not vhdl-upper-case-attributes))
3604 :style toggle :selected vhdl-upper-case-attributes]
3605 ["Upper Case Enumeration Values"
3606 (customize-set-variable 'vhdl-upper-case-enum-values
3607 (not vhdl-upper-case-enum-values))
3608 :style toggle :selected vhdl-upper-case-enum-values]
3609 ["Upper Case Constants"
3610 (customize-set-variable 'vhdl-upper-case-constants
3611 (not vhdl-upper-case-constants))
3612 :style toggle :selected vhdl-upper-case-constants]
3613 ("Use Direct Instantiation"
3614 ["Never"
3615 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3616 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3617 ["Standard"
3618 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3619 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3620 ["Always"
3621 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3622 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3623 "--"
3624 ["Customize Group..." (customize-group 'vhdl-style) t])
3625 ("Naming"
3626 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3627 ["Architecture File Name..."
3628 (customize-option 'vhdl-architecture-file-name) t]
0a2e512a
RF
3629 ["Configuration File Name..."
3630 (customize-option 'vhdl-configuration-file-name) t]
3dcb36b7
JB
3631 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3632 ("File Name Case"
3633 ["As Is"
3634 (customize-set-variable 'vhdl-file-name-case 'identity)
3635 :style radio :selected (eq 'identity vhdl-file-name-case)]
3636 ["Lower Case"
3637 (customize-set-variable 'vhdl-file-name-case 'downcase)
3638 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3639 ["Upper Case"
3640 (customize-set-variable 'vhdl-file-name-case 'upcase)
3641 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3642 ["Capitalize"
3643 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3644 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3645 "--"
3646 ["Customize Group..." (customize-group 'vhdl-naming) t])
3647 ("Template"
3648 ("Electric Keywords"
3649 ["VHDL Keywords"
3650 (customize-set-variable 'vhdl-electric-keywords
3651 (if (memq 'vhdl vhdl-electric-keywords)
3652 (delq 'vhdl vhdl-electric-keywords)
3653 (cons 'vhdl vhdl-electric-keywords)))
3654 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3655 ["User Model Keywords"
3656 (customize-set-variable 'vhdl-electric-keywords
3657 (if (memq 'user vhdl-electric-keywords)
3658 (delq 'user vhdl-electric-keywords)
3659 (cons 'user vhdl-electric-keywords)))
3660 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3661 ("Insert Optional Labels"
3662 ["None"
3663 (customize-set-variable 'vhdl-optional-labels 'none)
3664 :style radio :selected (eq 'none vhdl-optional-labels)]
3665 ["Processes Only"
3666 (customize-set-variable 'vhdl-optional-labels 'process)
3667 :style radio :selected (eq 'process vhdl-optional-labels)]
3668 ["All Constructs"
3669 (customize-set-variable 'vhdl-optional-labels 'all)
3670 :style radio :selected (eq 'all vhdl-optional-labels)])
3671 ("Insert Empty Lines"
3672 ["None"
3673 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3674 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3675 ["Design Units Only"
3676 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3677 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3678 ["All Constructs"
3679 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3680 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3681 ["Argument List Indent"
3682 (customize-set-variable 'vhdl-argument-list-indent
3683 (not vhdl-argument-list-indent))
3684 :style toggle :selected vhdl-argument-list-indent]
3685 ["Association List with Formals"
3686 (customize-set-variable 'vhdl-association-list-with-formals
3687 (not vhdl-association-list-with-formals))
3688 :style toggle :selected vhdl-association-list-with-formals]
3689 ["Conditions in Parenthesis"
3690 (customize-set-variable 'vhdl-conditions-in-parenthesis
3691 (not vhdl-conditions-in-parenthesis))
3692 :style toggle :selected vhdl-conditions-in-parenthesis]
3693 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3694 ["One String..." (customize-option 'vhdl-one-string) t]
3695 ("File Header"
3696 ["Header String..." (customize-option 'vhdl-file-header) t]
3697 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3698 ["Company Name..." (customize-option 'vhdl-company-name) t]
3699 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3700 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3701 ["Date Format..." (customize-option 'vhdl-date-format) t]
3702 ["Modify Date Prefix String..."
3703 (customize-option 'vhdl-modify-date-prefix-string) t]
3704 ["Modify Date on Saving"
3705 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3706 (not vhdl-modify-date-on-saving))
3707 (vhdl-activate-customizations))
3708 :style toggle :selected vhdl-modify-date-on-saving])
3709 ("Sequential Process"
3710 ("Kind of Reset"
3711 ["None"
3712 (customize-set-variable 'vhdl-reset-kind 'none)
3713 :style radio :selected (eq 'none vhdl-reset-kind)]
3714 ["Synchronous"
3715 (customize-set-variable 'vhdl-reset-kind 'sync)
3716 :style radio :selected (eq 'sync vhdl-reset-kind)]
3717 ["Asynchronous"
3718 (customize-set-variable 'vhdl-reset-kind 'async)
3719 :style radio :selected (eq 'async vhdl-reset-kind)])
3720 ["Reset is Active High"
3721 (customize-set-variable 'vhdl-reset-active-high
3722 (not vhdl-reset-active-high))
3723 :style toggle :selected vhdl-reset-active-high]
3724 ["Use Rising Clock Edge"
3725 (customize-set-variable 'vhdl-clock-rising-edge
3726 (not vhdl-clock-rising-edge))
3727 :style toggle :selected vhdl-clock-rising-edge]
3728 ("Clock Edge Condition"
3729 ["Standard"
3730 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3731 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3732 ["Function \"rising_edge\""
3733 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3734 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3735 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3736 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3737 "--"
3738 ["Customize Group..." (customize-group 'vhdl-template) t])
3739 ("Model"
3740 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3741 ("Port"
3742 ["Include Port Comments"
3743 (customize-set-variable 'vhdl-include-port-comments
3744 (not vhdl-include-port-comments))
3745 :style toggle :selected vhdl-include-port-comments]
3746 ["Include Direction Comments"
3747 (customize-set-variable 'vhdl-include-direction-comments
3748 (not vhdl-include-direction-comments))
3749 :style toggle :selected vhdl-include-direction-comments]
3750 ["Include Type Comments"
3751 (customize-set-variable 'vhdl-include-type-comments
3752 (not vhdl-include-type-comments))
3753 :style toggle :selected vhdl-include-type-comments]
3754 ("Include Group Comments"
3755 ["Never"
3756 (customize-set-variable 'vhdl-include-group-comments 'never)
3757 :style radio :selected (eq 'never vhdl-include-group-comments)]
3758 ["Declarations"
3759 (customize-set-variable 'vhdl-include-group-comments 'decl)
3760 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3761 ["Always"
3762 (customize-set-variable 'vhdl-include-group-comments 'always)
3763 :style radio :selected (eq 'always vhdl-include-group-comments)])
3764 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3765 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3766 ("Testbench"
3767 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3768 ["Architecture Name..."
3769 (customize-option 'vhdl-testbench-architecture-name) t]
3770 ["Configuration Name..."
3771 (customize-option 'vhdl-testbench-configuration-name) t]
3772 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3773 ["Include Header"
3774 (customize-set-variable 'vhdl-testbench-include-header
3775 (not vhdl-testbench-include-header))
3776 :style toggle :selected vhdl-testbench-include-header]
3777 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3778 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3779 ["Initialize Signals"
3780 (customize-set-variable 'vhdl-testbench-initialize-signals
3781 (not vhdl-testbench-initialize-signals))
3782 :style toggle :selected vhdl-testbench-initialize-signals]
3783 ["Include Library Clause"
3784 (customize-set-variable 'vhdl-testbench-include-library
3785 (not vhdl-testbench-include-library))
3786 :style toggle :selected vhdl-testbench-include-library]
3787 ["Include Configuration"
3788 (customize-set-variable 'vhdl-testbench-include-configuration
3789 (not vhdl-testbench-include-configuration))
3790 :style toggle :selected vhdl-testbench-include-configuration]
3791 ("Create Files"
3792 ["None"
3793 (customize-set-variable 'vhdl-testbench-create-files 'none)
3794 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3795 ["Single"
3796 (customize-set-variable 'vhdl-testbench-create-files 'single)
3797 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3798 ["Separate"
3799 (customize-set-variable 'vhdl-testbench-create-files 'separate)
0a2e512a
RF
3800 :style radio :selected (eq 'separate vhdl-testbench-create-files)])
3801 ["Testbench Entity File Name..."
3802 (customize-option 'vhdl-testbench-entity-file-name) t]
3803 ["Testbench Architecture File Name..."
3804 (customize-option 'vhdl-testbench-architecture-file-name) t])
3dcb36b7
JB
3805 "--"
3806 ["Customize Group..." (customize-group 'vhdl-port) t])
3807 ("Compose"
0a2e512a
RF
3808 ["Architecture Name..."
3809 (customize-option 'vhdl-compose-architecture-name) t]
3810 ["Configuration Name..."
3811 (customize-option 'vhdl-compose-configuration-name) t]
3812 ["Components Package Name..."
3813 (customize-option 'vhdl-components-package-name) t]
3814 ["Use Components Package"
3815 (customize-set-variable 'vhdl-use-components-package
3816 (not vhdl-use-components-package))
3817 :style toggle :selected vhdl-use-components-package]
3818 ["Include Header"
3819 (customize-set-variable 'vhdl-compose-include-header
3820 (not vhdl-compose-include-header))
3821 :style toggle :selected vhdl-compose-include-header]
3822 ("Create Entity/Architecture Files"
3dcb36b7
JB
3823 ["None"
3824 (customize-set-variable 'vhdl-compose-create-files 'none)
3825 :style radio :selected (eq 'none vhdl-compose-create-files)]
3826 ["Single"
3827 (customize-set-variable 'vhdl-compose-create-files 'single)
3828 :style radio :selected (eq 'single vhdl-compose-create-files)]
3829 ["Separate"
3830 (customize-set-variable 'vhdl-compose-create-files 'separate)
3831 :style radio :selected (eq 'separate vhdl-compose-create-files)])
0a2e512a
RF
3832 ["Create Configuration File"
3833 (customize-set-variable 'vhdl-compose-configuration-create-file
3834 (not vhdl-compose-configuration-create-file))
3835 :style toggle :selected vhdl-compose-configuration-create-file]
3836 ["Hierarchical Configuration"
3837 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3838 (not vhdl-compose-configuration-hierarchical))
3839 :style toggle :selected vhdl-compose-configuration-hierarchical]
3840 ["Use Subconfiguration"
3841 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3842 (not vhdl-compose-configuration-use-subconfiguration))
3843 :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
3dcb36b7
JB
3844 "--"
3845 ["Customize Group..." (customize-group 'vhdl-compose) t])
3846 ("Comment"
3847 ["Self Insert Comments"
3848 (customize-set-variable 'vhdl-self-insert-comments
3849 (not vhdl-self-insert-comments))
3850 :style toggle :selected vhdl-self-insert-comments]
3851 ["Prompt for Comments"
3852 (customize-set-variable 'vhdl-prompt-for-comments
3853 (not vhdl-prompt-for-comments))
3854 :style toggle :selected vhdl-prompt-for-comments]
3855 ["Inline Comment Column..."
3856 (customize-option 'vhdl-inline-comment-column) t]
3857 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3858 "--"
3859 ["Customize Group..." (customize-group 'vhdl-comment) t])
3860 ("Align"
3861 ["Auto Align Templates"
3862 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3863 :style toggle :selected vhdl-auto-align]
3864 ["Align Line Groups"
3865 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3866 :style toggle :selected vhdl-align-groups]
3867 ["Group Separation String..."
3868 (customize-set-variable 'vhdl-align-group-separate) t]
3869 ["Align Lines with Same Indent"
3870 (customize-set-variable 'vhdl-align-same-indent
3871 (not vhdl-align-same-indent))
3872 :style toggle :selected vhdl-align-same-indent]
3873 "--"
3874 ["Customize Group..." (customize-group 'vhdl-align) t])
3875 ("Highlight"
3876 ["Highlighting On/Off..."
3877 (customize-option
4bcb9c95
SM
3878 (if (fboundp 'global-font-lock-mode)
3879 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3dcb36b7
JB
3880 ["Highlight Keywords"
3881 (progn (customize-set-variable 'vhdl-highlight-keywords
3882 (not vhdl-highlight-keywords))
3883 (vhdl-fontify-buffer))
3884 :style toggle :selected vhdl-highlight-keywords]
3885 ["Highlight Names"
3886 (progn (customize-set-variable 'vhdl-highlight-names
3887 (not vhdl-highlight-names))
3888 (vhdl-fontify-buffer))
3889 :style toggle :selected vhdl-highlight-names]
3890 ["Highlight Special Words"
3891 (progn (customize-set-variable 'vhdl-highlight-special-words
3892 (not vhdl-highlight-special-words))
3893 (vhdl-fontify-buffer))
3894 :style toggle :selected vhdl-highlight-special-words]
3895 ["Highlight Forbidden Words"
3896 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3897 (not vhdl-highlight-forbidden-words))
3898 (vhdl-fontify-buffer))
3899 :style toggle :selected vhdl-highlight-forbidden-words]
3900 ["Highlight Verilog Keywords"
3901 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3902 (not vhdl-highlight-verilog-keywords))
3903 (vhdl-fontify-buffer))
3904 :style toggle :selected vhdl-highlight-verilog-keywords]
3905 ["Highlight \"translate_off\""
3906 (progn (customize-set-variable 'vhdl-highlight-translate-off
3907 (not vhdl-highlight-translate-off))
3908 (vhdl-fontify-buffer))
3909 :style toggle :selected vhdl-highlight-translate-off]
3910 ["Case Sensitive Highlighting"
3911 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3912 (not vhdl-highlight-case-sensitive))
3913 (vhdl-fontify-buffer))
3914 :style toggle :selected vhdl-highlight-case-sensitive]
3915 ["Special Syntax Definition..."
3916 (customize-option 'vhdl-special-syntax-alist) t]
3917 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3918 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3919 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3920 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3921 "--"
3922 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3923 ("Speedbar"
3924 ["Auto Open at Startup"
3925 (customize-set-variable 'vhdl-speedbar-auto-open
3926 (not vhdl-speedbar-auto-open))
3927 :style toggle :selected vhdl-speedbar-auto-open]
3928 ("Default Displaying Mode"
3929 ["Files"
3930 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3931 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3932 ["Directory Hierarchy"
3933 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3934 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3935 ["Project Hierarchy"
3936 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3937 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3938 ["Indentation Offset..."
3939 (customize-option 'speedbar-indentation-width) t]
3940 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3941 ["Jump to Unit when Opening"
3942 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3943 (not vhdl-speedbar-jump-to-unit))
3944 :style toggle :selected vhdl-speedbar-jump-to-unit]
3945 ["Update Hierarchy on File Saving"
3946 (customize-set-variable 'vhdl-speedbar-update-on-saving
3947 (not vhdl-speedbar-update-on-saving))
3948 :style toggle :selected vhdl-speedbar-update-on-saving]
3949 ("Save in Cache File"
3950 ["Hierarchy Information"
3951 (customize-set-variable 'vhdl-speedbar-save-cache
3952 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3953 (delq 'hierarchy vhdl-speedbar-save-cache)
3954 (cons 'hierarchy vhdl-speedbar-save-cache)))
3955 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3956 ["Displaying Status"
3957 (customize-set-variable 'vhdl-speedbar-save-cache
3958 (if (memq 'display vhdl-speedbar-save-cache)
3959 (delq 'display vhdl-speedbar-save-cache)
3960 (cons 'display vhdl-speedbar-save-cache)))
3961 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3962 ["Cache File Name..."
3963 (customize-option 'vhdl-speedbar-cache-file-name) t]
3964 "--"
3965 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3966 ("Menu"
3967 ["Add Index Menu when Loading File"
3968 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3969 (vhdl-index-menu-init))
3970 :style toggle :selected vhdl-index-menu]
3971 ["Add Source File Menu when Loading File"
3972 (progn (customize-set-variable 'vhdl-source-file-menu
3973 (not vhdl-source-file-menu))
3974 (vhdl-add-source-files-menu))
3975 :style toggle :selected vhdl-source-file-menu]
3976 ["Add Hideshow Menu at Startup"
3977 (progn (customize-set-variable 'vhdl-hideshow-menu
3978 (not vhdl-hideshow-menu))
3979 (vhdl-activate-customizations))
3980 :style toggle :selected vhdl-hideshow-menu]
3981 ["Hide Everything Initially"
3982 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3983 :style toggle :selected vhdl-hide-all-init]
3984 "--"
3985 ["Customize Group..." (customize-group 'vhdl-menu) t])
3986 ("Print"
3987 ["In Two Column Format"
3988 (progn (customize-set-variable 'vhdl-print-two-column
3989 (not vhdl-print-two-column))
3990 (message "Activate new setting by saving options and restarting Emacs"))
3991 :style toggle :selected vhdl-print-two-column]
3992 ["Use Customized Faces"
3993 (progn (customize-set-variable 'vhdl-print-customize-faces
3994 (not vhdl-print-customize-faces))
3995 (message "Activate new setting by saving options and restarting Emacs"))
3996 :style toggle :selected vhdl-print-customize-faces]
3997 "--"
3998 ["Customize Group..." (customize-group 'vhdl-print) t])
3999 ("Miscellaneous"
4000 ["Use Intelligent Tab"
4001 (progn (customize-set-variable 'vhdl-intelligent-tab
4002 (not vhdl-intelligent-tab))
4003 (vhdl-activate-customizations))
4004 :style toggle :selected vhdl-intelligent-tab]
4005 ["Indent Syntax-Based"
4006 (customize-set-variable 'vhdl-indent-syntax-based
4007 (not vhdl-indent-syntax-based))
4008 :style toggle :selected vhdl-indent-syntax-based]
4009 ["Word Completion is Case Sensitive"
4010 (customize-set-variable 'vhdl-word-completion-case-sensitive
4011 (not vhdl-word-completion-case-sensitive))
4012 :style toggle :selected vhdl-word-completion-case-sensitive]
4013 ["Word Completion in Minibuffer"
4014 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4015 (not vhdl-word-completion-in-minibuffer))
4016 (message "Activate new setting by saving options and restarting Emacs"))
4017 :style toggle :selected vhdl-word-completion-in-minibuffer]
4018 ["Underscore is Part of Word"
4019 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4020 (not vhdl-underscore-is-part-of-word))
4021 (vhdl-activate-customizations))
4022 :style toggle :selected vhdl-underscore-is-part-of-word]
4023 "--"
4024 ["Customize Group..." (customize-group 'vhdl-misc) t])
4025 ["Related..." (customize-browse 'vhdl-related) t]
d2ddb974 4026 "--"
3dcb36b7
JB
4027 ["Save Options" customize-save-customized t]
4028 ["Activate Options" vhdl-activate-customizations t]
4029 ["Browse Options..." vhdl-customize t])))
5eabfe72
KH
4030
4031(defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
4032 "VHDL Mode menu.")
4033
4034(defun vhdl-update-mode-menu ()
3dcb36b7 4035 "Update VHDL Mode menu."
5eabfe72
KH
4036 (interactive)
4037 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
4038 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
4039 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4040 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4041 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
d2ddb974 4042
5eabfe72
KH
4043;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4044;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
d2ddb974 4045
3dcb36b7 4046(defconst vhdl-imenu-generic-expression
d2ddb974 4047 '(
5eabfe72
KH
4048 ("Subprogram"
4049 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4050 4)
4051 ("Instance"
4052 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4053 1)
4054 ("Component"
4055 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4056 2)
5eabfe72
KH
4057 ("Procedural"
4058 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4059 1)
4060 ("Process"
4061 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4062 1)
4063 ("Block"
4064 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4065 1)
4066 ("Package"
4067 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4068 3)
d2ddb974
KH
4069 ("Configuration"
4070 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4071 2)
5eabfe72
KH
4072 ("Architecture"
4073 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4074 2)
5eabfe72
KH
4075 ("Entity"
4076 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 4077 2)
d2ddb974
KH
4078 )
4079 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4080
5eabfe72
KH
4081(defun vhdl-index-menu-init ()
4082 "Initialize index menu."
4083 (set (make-local-variable 'imenu-case-fold-search) t)
4084 (set (make-local-variable 'imenu-generic-expression)
4085 vhdl-imenu-generic-expression)
3dcb36b7 4086 (when (and vhdl-index-menu (fboundp 'imenu))
5eabfe72
KH
4087 (if (or (not (boundp 'font-lock-maximum-size))
4088 (> font-lock-maximum-size (buffer-size)))
4089 (imenu-add-to-menubar "Index")
4090 (message "Scanning buffer for index...buffer too big"))))
d2ddb974 4091
3dcb36b7 4092;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
4093;; Source file menu (using `easy-menu.el')
4094
5eabfe72
KH
4095(defvar vhdl-sources-menu nil)
4096
4097(defun vhdl-directory-files (directory &optional full match)
4098 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4099message."
3dcb36b7
JB
4100 (if (not (file-directory-p directory))
4101 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
4102 (let ((dir (directory-files directory full match)))
4103 (setq dir (delete "." dir))
4104 (setq dir (delete ".." dir))
4105 dir)))
5eabfe72
KH
4106
4107(defun vhdl-get-source-files (&optional full directory)
4108 "Get list of VHDL source files in DIRECTORY or current directory."
4109 (let ((mode-alist auto-mode-alist)
4110 filename-regexp)
4111 ;; create regular expressions for matching file names
3dcb36b7 4112 (setq filename-regexp "\\`[^.].*\\(")
5eabfe72 4113 (while mode-alist
3dcb36b7 4114 (when (eq (cdar mode-alist) 'vhdl-mode)
5eabfe72 4115 (setq filename-regexp
3dcb36b7 4116 (concat filename-regexp (caar mode-alist) "\\|")))
5eabfe72
KH
4117 (setq mode-alist (cdr mode-alist)))
4118 (setq filename-regexp
4119 (concat (substring filename-regexp 0
4120 (string-match "\\\\|$" filename-regexp)) "\\)"))
4121 ;; find files
3dcb36b7
JB
4122 (vhdl-directory-files
4123 (or directory default-directory) full filename-regexp)))
d2ddb974
KH
4124
4125(defun vhdl-add-source-files-menu ()
5eabfe72
KH
4126 "Scan directory for all VHDL source files and generate menu.
4127The directory of the current source file is scanned."
d2ddb974
KH
4128 (interactive)
4129 (message "Scanning directory for source files ...")
5eabfe72 4130 (let ((newmap (current-local-map))
5eabfe72
KH
4131 (file-list (vhdl-get-source-files))
4132 menu-list found)
4133 ;; Create list for menu
4134 (setq found nil)
4135 (while file-list
4136 (setq found t)
4137 (setq menu-list (cons (vector (car file-list)
4138 (list 'find-file (car file-list)) t)
4139 menu-list))
4140 (setq file-list (cdr file-list)))
3dcb36b7 4141 (setq menu-list (vhdl-menu-split menu-list "Sources"))
5eabfe72
KH
4142 (when found (setq menu-list (cons "--" menu-list)))
4143 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4144 (setq menu-list (cons "Sources" menu-list))
d2ddb974 4145 ;; Create menu
5eabfe72
KH
4146 (easy-menu-add menu-list)
4147 (easy-menu-define vhdl-sources-menu newmap
4148 "VHDL source files menu" menu-list))
d2ddb974
KH
4149 (message ""))
4150
d2ddb974 4151
5eabfe72 4152;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4153;;; Mode definition
5eabfe72
KH
4154;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4155;; performs all buffer local initializations
4156
1c36bac6 4157;;;###autoload
d2ddb974
KH
4158(defun vhdl-mode ()
4159 "Major mode for editing VHDL code.
4160
4161Usage:
4162------
4163
3dcb36b7
JB
4164 TEMPLATE INSERTION (electrification):
4165 After typing a VHDL keyword and entering `SPC', you are prompted for
4166 arguments while a template is generated for that VHDL construct. Typing
4167 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4168 template generation. Optional arguments are indicated by square
4169 brackets and removed if the queried string is left empty. Prompts for
4170 mandatory arguments remain in the code if the queried string is left
4171 empty. They can be queried again by `C-c C-t C-q'. Enabled
4172 electrification is indicated by `/e' in the modeline.
4173
4174 Typing `M-SPC' after a keyword inserts a space without calling the
4175 template generator. Automatic template generation (i.e.
4176 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4177 setting option `vhdl-electric-mode' (see OPTIONS).
4178
4179 Template generators can be invoked from the VHDL menu, by key
4180 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4181 the keyword (i.e. first word of menu entry not in parenthesis) and
4182 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4183 conf, comp, cons, func, inst, pack, sig, var.
4184
4185 Template styles can be customized in customization group
4186 `vhdl-template' \(see OPTIONS).
4187
4188
4189 HEADER INSERTION:
4190 A file header can be inserted by `C-c C-t C-h'. A file footer
4191 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4192 See customization group `vhdl-header'.
4193
4194
4195 STUTTERING:
4196 Double striking of some keys inserts cumbersome VHDL syntax elements.
4197 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4198 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4199 the modeline. The stuttering keys and their effects are:
4200
4201 ;; --> \" : \" [ --> ( -- --> comment
4202 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4203 .. --> \" => \" ] --> ) --- --> horizontal line
4204 ,, --> \" <= \" ]] --> ] ---- --> display comment
4205 == --> \" == \" '' --> \\\"
4206
4207
4208 WORD COMPLETION:
4209 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4210 word in the buffer that starts alike, inserts it and adjusts case.
4211 Re-typing `TAB' toggles through alternative word completions. This also
4212 works in the minibuffer (i.e. in template generator prompts).
4213
4214 Typing `TAB' after `(' looks for and inserts complete parenthesized
4215 expressions (e.g. for array index ranges). All keywords as well as
4216 standard types and subprograms of VHDL have predefined abbreviations
4217 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4218 beginning with \"std\").
4219
4220 Typing `TAB' after a non-word character indents the line if at the
4221 beginning of a line (i.e. no preceding non-blank characters), and
4222 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4223 stop.
4224
4225
4226 COMMENTS:
4227 `--' puts a single comment.
4228 `---' draws a horizontal line for separating code segments.
4229 `----' inserts a display comment, i.e. two horizontal lines
4230 with a comment in between.
4231 `--CR' comments out code on that line. Re-hitting CR comments
4232 out following lines.
4233 `C-c c' comments out a region if not commented out,
4234 uncomments a region if already commented out.
4235
4236 You are prompted for comments after object definitions (i.e. signals,
4237 variables, constants, ports) and after subprogram and process
4238 specifications if option `vhdl-prompt-for-comments' is non-nil.
4239 Comments are automatically inserted as additional labels (e.g. after
4240 begin statements) and as help comments if `vhdl-self-insert-comments' is
4241 non-nil.
4242
4243 Inline comments (i.e. comments after a piece of code on the same line)
4244 are indented at least to `vhdl-inline-comment-column'. Comments go at
4245 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4246 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4247 in a comment automatically opens a new comment line. `M-q' re-fills
4248 multi-line comments.
4249
4250
4251 INDENTATION:
4252 `TAB' indents a line if at the beginning of the line. The amount of
4253 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4254 always indents the current line (is bound to `TAB' if option
4255 `vhdl-intelligent-tab' is nil).
4256
4257 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4258 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4259 indented normally (nil) or relative to the opening parenthesis (non-nil)
4260 according to option `vhdl-argument-list-indent'.
4261
4262 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4263 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4264 and vice versa.
4265
4266 Syntax-based indentation can be very slow in large files. Option
4267 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4268
4269
4270 ALIGNMENT:
4271 The alignment functions align operators, keywords, and inline comments
4272 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4273 separated by blank lines, `C-c C-a C-i' a block of lines with same
4274 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4275 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4276 C-a C-d' all lines within the declarative part of a design unit. `C-c
4277 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4278 for a group of lines, and `C-c C-a M-c' for a region.
4279
4280 If option `vhdl-align-groups' is non-nil, groups of code lines
4281 separated by special lines (see option `vhdl-align-group-separate') are
4282 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4283 blocks of lines with same indent are aligned separately. Some templates
4284 are automatically aligned after generation if option `vhdl-auto-align'
4285 is non-nil.
4286
4287 Alignment tries to align inline comments at
4288 `vhdl-inline-comment-column' and tries inline comment not to exceed
4289 `vhdl-end-comment-column'.
4290
4291 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4292 symbols are surrounded by one space, and multiple spaces are eliminated.
4293
4294
0a2e512a
RF
4295 CODE FILLING:
4296 Code filling allows to condense code (e.g. sensitivity lists or port
4297 maps) by removing comments and newlines and re-wrapping so that all
4298 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4299 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4300 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4301 `C-c C-f M-f' an entire region.
3dcb36b7
JB
4302
4303
4304 CODE BEAUTIFICATION:
4305 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4306 buffer respectively. This inludes indentation, alignment, and case
4307 fixing. Code beautification can also be run non-interactively using the
4308 command:
4309
4310 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4311
4312
4313 PORT TRANSLATION:
4314 Generic and port clauses from entity or component declarations can be
4315 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4316 as component instantiations and corresponding internal constants and
4317 signals, as a generic map with constants as actual generics, and as
4318 internal signal initializations (menu).
4319
4320 To include formals in component instantiations, see option
4321 `vhdl-association-list-with-formals'. To include comments in pasting,
4322 see options `vhdl-include-...-comments'.
4323
4324 A clause with several generic/port names on the same line can be
4325 flattened (`C-c C-p C-f') so that only one name per line exists. The
0a2e512a
RF
4326 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4327 outputs and vice versa, which can be useful in testbenches. (This
4328 reversion is done on the internal data structure and is only reflected
4329 in subsequent paste operations.)
3dcb36b7
JB
4330
4331 Names for actual ports, instances, testbenches, and
4332 design-under-test instances can be derived from existing names according
4333 to options `vhdl-...-name'. See customization group `vhdl-port'.
4334
4335
0a2e512a
RF
4336 SUBPROGRAM TRANSLATION:
4337 Similar functionality exists for copying/pasting the interface of
4338 subprograms (function/procedure). A subprogram interface can be copied
4339 and then pasted as a subprogram declaration, body or call (uses
4340 association list with formals).
3dcb36b7
JB
4341
4342
4343 TESTBENCH GENERATION:
4344 A copied port can also be pasted as a testbench. The generated
4345 testbench includes an entity, an architecture, and an optional
4346 configuration. The architecture contains the component declaration and
4347 instantiation of the DUT as well as internal constant and signal
4348 declarations. Additional user-defined templates can be inserted. The
4349 names used for entity/architecture/configuration/DUT as well as the file
4350 structure to be generated can be customized. See customization group
4351 `vhdl-testbench'.
4352
4353
4354 KEY BINDINGS:
4355 Key bindings (`C-c ...') exist for most commands (see in menu).
4356
4357
4358 VHDL MENU:
4359 All commands can be found in the VHDL menu including their key bindings.
4360
4361
4362 FILE BROWSER:
4363 The speedbar allows browsing of directories and file contents. It can
4364 be accessed from the VHDL menu and is automatically opened if option
4365 `vhdl-speedbar-auto-open' is non-nil.
4366
4367 In speedbar, open files and directories with `mouse-2' on the name and
4368 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4369
4370
4371 DESIGN HIERARCHY BROWSER:
4372 The speedbar can also be used for browsing the hierarchy of design units
4373 contained in the source files of the current directory or the specified
4374 projects (see option `vhdl-project-alist').
4375
4376 The speedbar can be switched between file, directory hierarchy and
4377 project hierarchy browsing mode in the speedbar menu or by typing `f',
4378 `h' or `H' in speedbar.
4379
4380 In speedbar, open design units with `mouse-2' on the name and browse
4381 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4382 from entities and components (in packages). Individual design units and
4383 complete designs can directly be compiled (\"Make\" menu entry).
4384
4385 The hierarchy is automatically updated upon saving a modified source
4386 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4387 hierarchy is only updated for projects that have been opened once in the
4388 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4389 options in group `vhdl-speedbar').
4390
4391 Simple design consistency checks are done during scanning, such as
4392 multiple declarations of the same unit or missing primary units that are
4393 required by secondary units.
4394
4395
0a2e512a
RF
4396 STRUCTURAL COMPOSITION:
4397 Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4398 for a new component. Subcomponents (i.e. component declaration and
4399 instantiation) can be automatically placed from a previously read port
4400 \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4401 all subcomponents can be automatically connected using internal signals
4402 and ports (`C-c C-c C-w') following these rules:
4403 - subcomponent actual ports with same name are considered to be
4404 connected by a signal (internal signal or port)
4405 - signals that are only inputs to subcomponents are considered as
4406 inputs to this component -> input port created
4407 - signals that are only outputs from subcomponents are considered as
4408 outputs from this component -> output port created
4409 - signals that are inputs to AND outputs from subcomponents are
4410 considered as internal connections -> internal signal created
84c98ace 4411
0a2e512a
RF
4412 Purpose: With appropriate naming conventions it is possible to
4413 create higher design levels with only a few mouse clicks or key
4414 strokes. A new design level can be created by simply generating a new
4415 component, placing the required subcomponents from the hierarchy
4416 browser, and wiring everything automatically.
84c98ace 4417
0a2e512a
RF
4418 Note: Automatic wiring only works reliably on templates of new
4419 components and component instantiations that were created by VHDL mode.
84c98ace 4420
0a2e512a
RF
4421 Component declarations can be placed in a components package (option
4422 `vhdl-use-components-package') which can be automatically generated for
4423 an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4424 component instantiation is also supported (option
4425 `vhdl-use-direct-instantiation').
4426
4427| Configuration declarations can automatically be generated either from
4428| the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
4429| the speedbar menu (for the architecture under the cursor). The
4430| configurations can optionally be hierarchical (i.e. include all
4431| component levels of a hierarchical design, option
4432| `vhdl-compose-configuration-hierarchical') or include subconfigurations
4433| (option `vhdl-compose-configuration-use-subconfiguration'). For
4434| subcomponents in hierarchical configurations, the most-recently-analyzed
4435| (mra) architecture is selected. If another architecture is desired, it
4436| can be marked as most-recently-analyzed (speedbar menu) before
4437| generating the configuration.
3dcb36b7 4438|
0a2e512a
RF
4439| Note: Configurations of subcomponents (i.e. hierarchical configuration
4440| declarations) are currently not considered when displaying
4441| configurations in speedbar.
84c98ace 4442
0a2e512a 4443 See the options group `vhdl-compose' for all relevant user options.
3dcb36b7
JB
4444
4445
4446 SOURCE FILE COMPILATION:
4447 The syntax of the current buffer can be analyzed by calling a VHDL
4448 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4449 option `vhdl-compiler'. The available compilers are listed in option
4450 `vhdl-compiler-alist' including all required compilation command,
4451 command options, compilation directory, and error message syntax
4452 information. New compilers can be added.
4453
4454 All the source files of an entire design can be compiled by the `make'
4455 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4456
4457
4458 MAKEFILE GENERATION:
4459 Makefiles can be generated automatically by an internal generation
4460 routine (`C-c M-k'). The library unit dependency information is
4461 obtained from the hierarchy browser. Makefile generation can be
4462 customized for each compiler in option `vhdl-compiler-alist'.
4463
4464 Makefile generation can also be run non-interactively using the
4465 command:
4466
4467 emacs -batch -l ~/.emacs -l vhdl-mode
4468 [-compiler compilername] [-project projectname]
4469 -f vhdl-generate-makefile
4470
4471 The Makefile's default target \"all\" compiles the entire design, the
4472 target \"clean\" removes it and the target \"library\" creates the
4473 library directory if not existent. The Makefile also includes a target
4474 for each primary library unit which allows selective compilation of this
4475 unit, its secondary units and its subhierarchy (example: compilation of
4476 a design specified by a configuration). User specific parts can be
4477 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4478
4479 Limitations:
4480 - Only library units and dependencies within the current library are
4481 considered. Makefiles for designs that span multiple libraries are
4482 not (yet) supported.
4483 - Only one-level configurations are supported (also hierarchical),
4484 but configurations that go down several levels are not.
4485 - The \"others\" keyword in configurations is not supported.
4486
4487
4488 PROJECTS:
4489 Projects can be defined in option `vhdl-project-alist' and a current
4490 project be selected using option `vhdl-project' (permanently) or from
4491 the menu or speedbar (temporarily). For each project, title and
4492 description strings (for the file headers), source files/directories
4493 (for the hierarchy browser and Makefile generation), library name, and
4494 compiler-dependent options, exceptions and compilation directory can be
4495 specified. Compilation settings overwrite the settings of option
4496 `vhdl-compiler-alist'.
4497
4498 Project setups can be exported (i.e. written to a file) and imported.
4499 Imported setups are not automatically saved in `vhdl-project-alist' but
4500 can be saved afterwards in its customization buffer. When starting
4501 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4502 vhdl-mode\") in a directory with an existing project setup file, it is
4503 automatically loaded and its project activated if option
4504 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4505 files can be specified in option `vhdl-project-file-name'. Multiple
4506 project setups can be automatically loaded from global directories.
4507 This is an alternative to specifying project setups with option
4508 `vhdl-project-alist'.
4509
4510
4511 SPECIAL MENUES:
4512 As an alternative to the speedbar, an index menu can be added (set
4513 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4514 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4515 file) for browsing the file contents (is not populated if buffer is
4516 larger than `font-lock-maximum-size'). Also, a source file menu can be
4517 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4518 current directory for VHDL source files.
4519
4520
4521 VHDL STANDARDS:
4522 The VHDL standards to be used are specified in option `vhdl-standard'.
4523 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4524
4525
4526 KEYWORD CASE:
4527 Lower and upper case for keywords and standardized types, attributes,
4528 and enumeration values is supported. If the option
4529 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4530 lower case and are converted into upper case automatically (not for
4531 types, attributes, and enumeration values). The case of keywords,
4532 types, attributes,and enumeration values can be fixed for an entire
4533 region (menu) or buffer (`C-c C-x C-c') according to the options
4534 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4535
4536
4537 HIGHLIGHTING (fontification):
4538 Keywords and standardized types, attributes, enumeration values, and
4539 function names (controlled by option `vhdl-highlight-keywords'), as well
4540 as comments, strings, and template prompts are highlighted using
4541 different colors. Unit, subprogram, signal, variable, constant,
4542 parameter and generic/port names in declarations as well as labels are
4543 highlighted if option `vhdl-highlight-names' is non-nil.
4544
4545 Additional reserved words or words with a forbidden syntax (e.g. words
4546 that should be avoided) can be specified in option
4547 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4548 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4549 keywords are highlighted as forbidden words if option
4550 `vhdl-highlight-verilog-keywords' is non-nil.
4551
4552 Words with special syntax can be highlighted by specifying their
4553 syntax and color in option `vhdl-special-syntax-alist' and by setting
4554 option `vhdl-highlight-special-words' to non-nil. This allows to
4555 establish some naming conventions (e.g. to distinguish different kinds
4556 of signals or other objects by using name suffices) and to support them
4557 visually.
4558
4559 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4560 to support case-sensitive highlighting. However, keywords are then only
4561 highlighted if written in lower case.
4562
4563 Code between \"translate_off\" and \"translate_on\" pragmas is
4564 highlighted using a different background color if option
4565 `vhdl-highlight-translate-off' is non-nil.
4566
4567 For documentation and customization of the used colors see
4568 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4569 highlighting of matching parenthesis, see customization group
4570 `paren-showing'. Automatic buffer highlighting is turned on/off by
4571 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4572
4573
4574 USER MODELS:
4575 VHDL models (templates) can be specified by the user and made accessible
4576 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4577 electrification. See option `vhdl-model-alist'.
4578
4579
4580 HIDE/SHOW:
4581 The code of blocks, processes, subprograms, component declarations and
4582 instantiations, generic/port clauses, and configuration declarations can
4583 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4584 the code (see customization group `vhdl-menu'). XEmacs: limited
4585 functionality due to old `hideshow.el' package.
4586
4587
4588 CODE UPDATING:
4589 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4590 current process, `C-c C-u M-s' of all processes in the current buffer.
4591 Limitations:
4592 - Only declared local signals (ports, signals declared in
4593 architecture and blocks) are automatically inserted.
4594 - Global signals declared in packages are not automatically inserted.
4595 Insert them once manually (will be kept afterwards).
4596 - Out parameters of procedures are considered to be read.
4597 Use option `vhdl-entity-file-name' to specify the entity file name
4598 \(used to obtain the port names).
4599
4600
4601 CODE FIXING:
4602 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4603 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4604
4605
4606 PRINTING:
4607 Postscript printing with different faces (an optimized set of faces is
4608 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4609 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4610 postscript printing commands. Option `vhdl-print-two-column' defines
4611 appropriate default settings for nice landscape two-column printing.
4612 The paper format can be set by option `ps-paper-type'. Do not forget to
4613 switch `ps-print-color-p' to nil for printing on black-and-white
4614 printers.
4615
4616
4617 OPTIONS:
4618 User options allow customization of VHDL Mode. All options are
4619 accessible from the \"Options\" menu entry. Simple options (switches
4620 and choices) can directly be changed, while for complex options a
4621 customization buffer is opened. Changed options can be saved for future
4622 sessions using the \"Save Options\" menu entry.
4623
4624 Options and their detailed descriptions can also be accessed by using
4625 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4626 customize-group' for groups). Some customizations only take effect
4627 after some action (read the NOTE in the option documentation).
4628 Customization can also be done globally (i.e. site-wide, read the
4629 INSTALL file).
4630
4631 Not all options are described in this documentation, so go and see
4632 what other useful user options there are (`M-x vhdl-customize' or menu)!
4633
4634
4635 FILE EXTENSIONS:
4636 As default, files with extensions \".vhd\" and \".vhdl\" are
4637 automatically recognized as VHDL source files. To add an extension
4638 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4639
4640 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4641
4642
4643 HINTS:
4644 - To start Emacs with open VHDL hierarchy browser without having to load
4645 a VHDL file first, use the command:
4646
4647 emacs -l vhdl-mode -f speedbar-frame-mode
4648
4649 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4650
4651 - Some features only work on properly indented code.
4652
4653
4654 RELEASE NOTES:
4655 See also the release notes (menu) for added features in new releases.
d2ddb974
KH
4656
4657
4658Maintenance:
4659------------
4660
3dcb36b7 4661To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
d2ddb974
KH
4662Add a description of the problem and include a reproducible test case.
4663
3dcb36b7 4664Questions and enhancement requests can be sent to <reto@gnu.org>.
d2ddb974
KH
4665
4666The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
3dcb36b7
JB
4667The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4668releases. You are kindly invited to participate in beta testing. Subscribe
4669to above mailing lists by sending an email to <reto@gnu.org>.
d2ddb974 4670
3dcb36b7
JB
4671VHDL Mode is officially distributed at
4672http://opensource.ethz.ch/emacs/vhdl-mode.html
4673where the latest version can be found.
d2ddb974
KH
4674
4675
3dcb36b7
JB
4676Known problems:
4677---------------
d2ddb974 4678
5eabfe72 4679- Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
3dcb36b7
JB
4680- XEmacs: Incorrect start-up when automatically opening speedbar.
4681- XEmacs: Indentation in XEmacs 21.4 (and higher).
d2ddb974
KH
4682
4683
3dcb36b7
JB
4684 The VHDL Mode Authors
4685 Reto Zimmermann and Rod Whitby
5eabfe72 4686
d2ddb974
KH
4687Key bindings:
4688-------------
4689
4690\\{vhdl-mode-map}"
4691 (interactive)
4692 (kill-all-local-variables)
d2ddb974
KH
4693 (setq major-mode 'vhdl-mode)
4694 (setq mode-name "VHDL")
5eabfe72
KH
4695
4696 ;; set maps and tables
d2ddb974 4697 (use-local-map vhdl-mode-map)
5eabfe72
KH
4698 (set-syntax-table vhdl-mode-syntax-table)
4699 (setq local-abbrev-table vhdl-mode-abbrev-table)
4700
3dcb36b7 4701 ;; set local variables
5eabfe72
KH
4702 (set (make-local-variable 'paragraph-start)
4703 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
d2ddb974
KH
4704 (set (make-local-variable 'paragraph-separate) paragraph-start)
4705 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
cf98062a 4706 (set (make-local-variable 'require-final-newline)
0a2e512a 4707 (if vhdl-emacs-22 mode-require-final-newline t))
d2ddb974
KH
4708 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4709 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4710 (set (make-local-variable 'comment-start) "--")
4711 (set (make-local-variable 'comment-end) "")
0a2e512a
RF
4712 (when vhdl-emacs-21
4713 (set (make-local-variable 'comment-padding) ""))
5eabfe72 4714 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
d2ddb974
KH
4715 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4716 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
5eabfe72 4717 (set (make-local-variable 'comment-multi-line) nil)
d2ddb974 4718 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
5eabfe72 4719 (set (make-local-variable 'hippie-expand-verbose) nil)
d2ddb974
KH
4720
4721 ;; setup the comment indent variable in a Emacs version portable way
4722 ;; ignore any byte compiler warnings you might get here
5eabfe72
KH
4723 (when (boundp 'comment-indent-function)
4724 (make-local-variable 'comment-indent-function)
4725 (setq comment-indent-function 'vhdl-comment-indent))
d2ddb974
KH
4726
4727 ;; initialize font locking
5eabfe72
KH
4728 (set (make-local-variable 'font-lock-defaults)
4729 (list
3dcb36b7 4730 '(nil vhdl-font-lock-keywords) nil
5eabfe72
KH
4731 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4732 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
3dcb36b7
JB
4733 (unless vhdl-emacs-21
4734 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4735 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4736 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4737; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4738 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4739; (turn-on-font-lock)
d2ddb974
KH
4740
4741 ;; variables for source file compilation
3dcb36b7
JB
4742 (when vhdl-compile-use-local-error-regexp
4743 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4744 (set (make-local-variable 'compilation-file-regexp-alist) nil))
5eabfe72
KH
4745
4746 ;; add index menu
4747 (vhdl-index-menu-init)
4748 ;; add source file menu
d2ddb974 4749 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
5eabfe72
KH
4750 ;; add VHDL menu
4751 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4752 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4753 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4754 ;; initialize hideshow and add menu
5eabfe72 4755 (vhdl-hideshow-init)
d2ddb974
KH
4756 (run-hooks 'menu-bar-update-hook)
4757
5eabfe72
KH
4758 ;; miscellaneous
4759 (vhdl-ps-print-init)
3dcb36b7 4760 (vhdl-write-file-hooks-init)
5eabfe72 4761 (vhdl-mode-line-update)
3dcb36b7
JB
4762 (message "VHDL Mode %s.%s" vhdl-version
4763 (if noninteractive "" " See menu for documentation and release notes."))
5eabfe72
KH
4764
4765 ;; run hooks
0a2e512a
RF
4766 (if vhdl-emacs-22
4767 (run-mode-hooks 'vhdl-mode-hook)
4768 (run-hooks 'vhdl-mode-hook)))
5eabfe72
KH
4769
4770(defun vhdl-activate-customizations ()
4771 "Activate all customizations on local variables."
4772 (interactive)
4773 (vhdl-mode-map-init)
4774 (use-local-map vhdl-mode-map)
4775 (set-syntax-table vhdl-mode-syntax-table)
4776 (setq comment-column vhdl-inline-comment-column)
4777 (setq end-comment-column vhdl-end-comment-column)
3dcb36b7 4778 (vhdl-write-file-hooks-init)
5eabfe72
KH
4779 (vhdl-update-mode-menu)
4780 (vhdl-hideshow-init)
4781 (run-hooks 'menu-bar-update-hook)
4782 (vhdl-mode-line-update))
4783
3dcb36b7
JB
4784(defun vhdl-write-file-hooks-init ()
4785 "Add/remove hooks when buffer is saved."
5eabfe72
KH
4786 (if vhdl-modify-date-on-saving
4787 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
3dcb36b7
JB
4788 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4789 (make-local-variable 'after-save-hook)
4790 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4791
4792(defun vhdl-process-command-line-option (option)
4793 "Process command line options for VHDL Mode."
4794 (cond
4795 ;; set compiler
4796 ((equal option "-compiler")
4797 (vhdl-set-compiler (car command-line-args-left))
4798 (setq command-line-args-left (cdr command-line-args-left)))
4799 ;; set project
4800 ((equal option "-project")
4801 (vhdl-set-project (car command-line-args-left))
4802 (setq command-line-args-left (cdr command-line-args-left)))))
4803
4804;; make Emacs process VHDL Mode options
4805(setq command-switch-alist
4806 (append command-switch-alist
4807 '(("-compiler" . vhdl-process-command-line-option)
4808 ("-project" . vhdl-process-command-line-option))))
5eabfe72
KH
4809
4810
4811;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4812;;; Keywords and standardized words
5eabfe72
KH
4813;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4814
3dcb36b7
JB
4815(defconst vhdl-93-keywords
4816 '(
4817 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4818 "assert" "attribute"
4819 "begin" "block" "body" "buffer" "bus"
4820 "case" "component" "configuration" "constant"
4821 "disconnect" "downto"
4822 "else" "elsif" "end" "entity" "exit"
4823 "file" "for" "function"
4824 "generate" "generic" "group" "guarded"
4825 "if" "impure" "in" "inertial" "inout" "is"
4826 "label" "library" "linkage" "literal" "loop"
4827 "map" "mod"
4828 "nand" "new" "next" "nor" "not" "null"
4829 "of" "on" "open" "or" "others" "out"
4830 "package" "port" "postponed" "procedure" "process" "pure"
4831 "range" "record" "register" "reject" "rem" "report" "return"
4832 "rol" "ror"
4833 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4834 "then" "to" "transport" "type"
4835 "unaffected" "units" "until" "use"
4836 "variable"
4837 "wait" "when" "while" "with"
4838 "xnor" "xor"
4839 )
4840 "List of VHDL'93 keywords.")
d2ddb974 4841
5eabfe72
KH
4842(defconst vhdl-ams-keywords
4843 '(
4844 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4845 "reference" "spectrum" "subnature" "terminal" "through"
4846 "tolerance"
4847 )
4848 "List of VHDL-AMS keywords.")
d2ddb974 4849
5eabfe72
KH
4850(defconst vhdl-verilog-keywords
4851 '(
4852 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4853 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4854 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4855 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4856 "endprimitive" "endspecify" "endtable" "endtask" "event"
4857 "for" "force" "forever" "fork" "function"
4858 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4859 "macromodule" "makefile" "medium" "module"
4860 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4861 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4862 "pullup"
4863 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4864 "rtranif0" "rtranif1"
4865 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4866 "strong1" "supply" "supply0" "supply1"
4867 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4868 "triand" "trior" "trireg"
4869 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4870 )
4871 "List of Verilog keywords as candidate for additional reserved words.")
d2ddb974 4872
5eabfe72
KH
4873(defconst vhdl-93-types
4874 '(
4875 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4876 "real" "time" "natural" "positive" "string" "line" "text" "side"
4877 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4878 "std_logic" "std_logic_vector"
4879 "std_ulogic" "std_ulogic_vector"
4880 )
4881 "List of VHDL'93 standardized types.")
d2ddb974 4882
5eabfe72
KH
4883(defconst vhdl-ams-types
4884 '(
4885 "domain_type" "real_vector"
3dcb36b7
JB
4886 ;; from `nature_pkg' package
4887 "voltage" "current" "electrical" "position" "velocity" "force"
4888 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4889 "pressure" "flowrate" "fluid"
4890 )
5eabfe72 4891 "List of VHDL-AMS standardized types.")
d2ddb974 4892
5eabfe72
KH
4893(defconst vhdl-math-types
4894 '(
4895 "complex" "complex_polar"
4896 )
4897 "List of Math Packages standardized types.")
d2ddb974 4898
5eabfe72
KH
4899(defconst vhdl-93-attributes
4900 '(
4901 "base" "left" "right" "high" "low" "pos" "val" "succ"
4902 "pred" "leftof" "rightof" "range" "reverse_range"
4903 "length" "delayed" "stable" "quiet" "transaction"
4904 "event" "active" "last_event" "last_active" "last_value"
4905 "driving" "driving_value" "ascending" "value" "image"
4906 "simple_name" "instance_name" "path_name"
4907 "foreign"
4908 )
4909 "List of VHDL'93 standardized attributes.")
d2ddb974 4910
5eabfe72
KH
4911(defconst vhdl-ams-attributes
4912 '(
4913 "across" "through"
4914 "reference" "contribution" "tolerance"
4915 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4916 "ramp" "slew"
4917 )
4918 "List of VHDL-AMS standardized attributes.")
d2ddb974 4919
5eabfe72
KH
4920(defconst vhdl-93-enum-values
4921 '(
4922 "true" "false"
4923 "note" "warning" "error" "failure"
4924 "read_mode" "write_mode" "append_mode"
4925 "open_ok" "status_error" "name_error" "mode_error"
4926 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4927 "right" "left"
4928 )
4929 "List of VHDL'93 standardized enumeration values.")
d2ddb974 4930
5eabfe72
KH
4931(defconst vhdl-ams-enum-values
4932 '(
4933 "quiescent_domain" "time_domain" "frequency_domain"
3dcb36b7
JB
4934 ;; from `nature_pkg' package
4935 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5eabfe72
KH
4936 )
4937 "List of VHDL-AMS standardized enumeration values.")
4938
4939(defconst vhdl-math-constants
4940 '(
4941 "math_e" "math_1_over_e"
4942 "math_pi" "math_two_pi" "math_1_over_pi"
4943 "math_half_pi" "math_q_pi" "math_3_half_pi"
4944 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4945 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4946 "math_deg_to_rad" "math_rad_to_deg"
4947 "cbase_1" "cbase_j" "czero"
4948 )
4949 "List of Math Packages standardized constants.")
4950
4951(defconst vhdl-93-functions
4952 '(
4953 "now" "resolved" "rising_edge" "falling_edge"
4954 "read" "readline" "write" "writeline" "endfile"
4955 "resize" "is_X" "std_match"
4956 "shift_left" "shift_right" "rotate_left" "rotate_right"
4957 "to_unsigned" "to_signed" "to_integer"
4958 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4959 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4960 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4961 "shl" "shr" "ext" "sxt"
3dcb36b7 4962 "deallocate"
5eabfe72
KH
4963 )
4964 "List of VHDL'93 standardized functions.")
4965
4966(defconst vhdl-ams-functions
4967 '(
4968 "frequency"
4969 )
4970 "List of VHDL-AMS standardized functions.")
4971
4972(defconst vhdl-math-functions
4973 '(
4974 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4975 "sqrt" "cbrt" "exp" "log"
4976 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4977 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4978 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4979 )
4980 "List of Math Packages standardized functions.")
4981
4982(defconst vhdl-93-packages
4983 '(
4984 "std_logic_1164" "numeric_std" "numeric_bit"
4985 "standard" "textio"
4986 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4987 "std_logic_misc" "std_logic_textio"
4988 "ieee" "std" "work"
4989 )
4990 "List of VHDL'93 standardized packages and libraries.")
4991
3dcb36b7
JB
4992(defconst vhdl-ams-packages
4993 '(
4994 ;; from `nature_pkg' package
4995 "nature_pkg"
4996 )
4997 "List of VHDL-AMS standardized packages and libraries.")
4998
5eabfe72
KH
4999(defconst vhdl-math-packages
5000 '(
5001 "math_real" "math_complex"
5002 )
5003 "List of Math Packages standardized packages and libraries.")
5004
5005(defvar vhdl-keywords nil
5006 "List of VHDL keywords.")
5007
5008(defvar vhdl-types nil
5009 "List of VHDL standardized types.")
5010
5011(defvar vhdl-attributes nil
5012 "List of VHDL standardized attributes.")
5013
5014(defvar vhdl-enum-values nil
5015 "List of VHDL standardized enumeration values.")
5016
5017(defvar vhdl-constants nil
5018 "List of VHDL standardized constants.")
5019
5020(defvar vhdl-functions nil
5021 "List of VHDL standardized functions.")
5022
5023(defvar vhdl-packages nil
5024 "List of VHDL standardized packages and libraries.")
5025
5026(defvar vhdl-reserved-words nil
5027 "List of additional reserved words.")
5028
5029(defvar vhdl-keywords-regexp nil
5030 "Regexp for VHDL keywords.")
5031
5032(defvar vhdl-types-regexp nil
5033 "Regexp for VHDL standardized types.")
5034
5035(defvar vhdl-attributes-regexp nil
5036 "Regexp for VHDL standardized attributes.")
5037
5038(defvar vhdl-enum-values-regexp nil
5039 "Regexp for VHDL standardized enumeration values.")
5040
5041(defvar vhdl-functions-regexp nil
5042 "Regexp for VHDL standardized functions.")
5043
5044(defvar vhdl-packages-regexp nil
5045 "Regexp for VHDL standardized packages and libraries.")
5046
5047(defvar vhdl-reserved-words-regexp nil
5048 "Regexp for additional reserved words.")
5049
3dcb36b7
JB
5050(defvar vhdl-directive-keywords-regexp nil
5051 "Regexp for compiler directive keywords.")
5052
5eabfe72
KH
5053(defun vhdl-words-init ()
5054 "Initialize reserved words."
5055 (setq vhdl-keywords
5056 (append vhdl-93-keywords
5057 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
5058 (setq vhdl-types
5059 (append vhdl-93-types
5060 (when (vhdl-standard-p 'ams) vhdl-ams-types)
5061 (when (vhdl-standard-p 'math) vhdl-math-types)))
5062 (setq vhdl-attributes
5063 (append vhdl-93-attributes
5064 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
5065 (setq vhdl-enum-values
5066 (append vhdl-93-enum-values
5067 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
5068 (setq vhdl-constants
5069 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
5070 (setq vhdl-functions
5071 (append vhdl-93-functions
5072 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
5073 (when (vhdl-standard-p 'math) vhdl-math-functions)))
5074 (setq vhdl-packages
5075 (append vhdl-93-packages
3dcb36b7 5076 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5eabfe72
KH
5077 (when (vhdl-standard-p 'math) vhdl-math-packages)))
5078 (setq vhdl-reserved-words
5079 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
5080 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
5081 '("")))
5082 (setq vhdl-keywords-regexp
5083 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
5084 (setq vhdl-types-regexp
5085 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
5086 (setq vhdl-attributes-regexp
5087 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
5088 (setq vhdl-enum-values-regexp
5089 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
5090 (setq vhdl-functions-regexp
5091 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
5092 (setq vhdl-packages-regexp
5093 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
5094 (setq vhdl-reserved-words-regexp
5095 (concat "\\<\\("
5096 (unless (equal vhdl-forbidden-syntax "")
5097 (concat vhdl-forbidden-syntax "\\|"))
5098 (regexp-opt vhdl-reserved-words)
5099 "\\)\\>"))
3dcb36b7
JB
5100 (setq vhdl-directive-keywords-regexp
5101 (concat "\\<\\(" (mapconcat 'regexp-quote
5102 vhdl-directive-keywords "\\|") "\\)\\>"))
5eabfe72
KH
5103 (vhdl-abbrev-list-init))
5104
5105;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5106;; Words to expand
5107
5108(defvar vhdl-abbrev-list nil
5109 "Predefined abbreviations for VHDL.")
5110
5111(defun vhdl-abbrev-list-init ()
5112 (setq vhdl-abbrev-list
5113 (append
5114 (list vhdl-upper-case-keywords) vhdl-keywords
5115 (list vhdl-upper-case-types) vhdl-types
5116 (list vhdl-upper-case-attributes) vhdl-attributes
5117 (list vhdl-upper-case-enum-values) vhdl-enum-values
5118 (list vhdl-upper-case-constants) vhdl-constants
5119 (list nil) vhdl-functions
5120 (list nil) vhdl-packages)))
5121
5122;; initialize reserved words for VHDL Mode
5123(vhdl-words-init)
5124
5125
5126;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 5127;;; Indentation
5eabfe72
KH
5128;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5129
5130;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
5131;; Syntax analysis
5132
5133;; constant regular expressions for looking at various constructs
5134
5135(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
5136 "Regexp describing a VHDL symbol.
5137We cannot use just `word' syntax class since `_' cannot be in word
5138class. Putting underscore in word class breaks forward word movement
5139behavior that users are familiar with.")
5140
5141(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
5142 "Regexp describing a case statement header key.")
5143
5144(defconst vhdl-label-key
5145 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5146 "Regexp describing a VHDL label.")
5147
5148;; Macro definitions:
5149
5150(defmacro vhdl-point (position)
5eabfe72
KH
5151 "Return the value of point at certain commonly referenced POSITIONs.
5152POSITION can be one of the following symbols:
5153
5154bol -- beginning of line
5155eol -- end of line
5156bod -- beginning of defun
5157boi -- back to indentation
5158eoi -- last whitespace on line
5159ionl -- indentation of next line
5160iopl -- indentation of previous line
5161bonl -- beginning of next line
5162bopl -- beginning of previous line
5163
5164This function does not modify point or mark."
d2ddb974 5165 (or (and (eq 'quote (car-safe position))
3dcb36b7
JB
5166 (null (cddr position)))
5167 (error "ERROR: Bad buffer position requested: %s" position))
d2ddb974 5168 (setq position (nth 1 position))
d4a5b644
GM
5169 `(let ((here (point)))
5170 ,@(cond
5171 ((eq position 'bol) '((beginning-of-line)))
5172 ((eq position 'eol) '((end-of-line)))
5173 ((eq position 'bod) '((save-match-data
5174 (vhdl-beginning-of-defun))))
5175 ((eq position 'boi) '((back-to-indentation)))
3dcb36b7 5176 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
d4a5b644
GM
5177 ((eq position 'bonl) '((forward-line 1)))
5178 ((eq position 'bopl) '((forward-line -1)))
5179 ((eq position 'iopl)
5180 '((forward-line -1)
5181 (back-to-indentation)))
5182 ((eq position 'ionl)
5183 '((forward-line 1)
5184 (back-to-indentation)))
3dcb36b7 5185 (t (error "ERROR: Unknown buffer position requested: %s" position))
d4a5b644
GM
5186 )
5187 (prog1
5188 (point)
5189 (goto-char here))
5190 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5191 ;; doesn't hurt for v19
5192 ,@nil
5193 ))
d2ddb974
KH
5194
5195(defmacro vhdl-safe (&rest body)
5eabfe72 5196 "Safely execute BODY, return nil if an error occurred."
d4a5b644
GM
5197 `(condition-case nil
5198 (progn ,@body)
5199 (error nil)))
d2ddb974
KH
5200
5201(defmacro vhdl-add-syntax (symbol &optional relpos)
5eabfe72
KH
5202 "A simple macro to append the syntax in SYMBOL to the syntax list.
5203Try to increase performance by using this macro."
d4a5b644
GM
5204 `(setq vhdl-syntactic-context
5205 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
d2ddb974
KH
5206
5207(defmacro vhdl-has-syntax (symbol)
5eabfe72
KH
5208 "A simple macro to return check the syntax list.
5209Try to increase performance by using this macro."
d4a5b644 5210 `(assoc ,symbol vhdl-syntactic-context))
d2ddb974
KH
5211
5212;; Syntactic element offset manipulation:
5213
5214(defun vhdl-read-offset (langelem)
5eabfe72 5215 "Read new offset value for LANGELEM from minibuffer.
2e8b9c7d 5216Return a valid value only."
d2ddb974
KH
5217 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5218 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5219 (prompt "Offset: ")
5220 offset input interned)
5221 (while (not offset)
5222 (setq input (read-string prompt oldoff)
5223 offset (cond ((string-equal "+" input) '+)
5224 ((string-equal "-" input) '-)
5225 ((string-equal "++" input) '++)
5226 ((string-equal "--" input) '--)
5227 ((string-match "^-?[0-9]+$" input)
027a4b6b 5228 (string-to-number input))
d2ddb974
KH
5229 ((fboundp (setq interned (intern input)))
5230 interned)
5231 ((boundp interned) interned)
5232 ;; error, but don't signal one, keep trying
5233 ;; to read an input value
5234 (t (ding)
5235 (setq prompt errmsg)
5236 nil))))
5237 offset))
5238
5239(defun vhdl-set-offset (symbol offset &optional add-p)
5240 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5241SYMBOL is the syntactic element symbol to change and OFFSET is the new
5242offset for that syntactic element. Optional ADD says to add SYMBOL to
5243`vhdl-offsets-alist' if it doesn't already appear there."
5244 (interactive
5245 (let* ((langelem
5246 (intern (completing-read
5247 (concat "Syntactic symbol to change"
5248 (if current-prefix-arg " or add" "")
5249 ": ")
5250 (mapcar
5251 (function
5252 (lambda (langelem)
5253 (cons (format "%s" (car langelem)) nil)))
5254 vhdl-offsets-alist)
5255 nil (not current-prefix-arg)
5256 ;; initial contents tries to be the last element
5257 ;; on the syntactic analysis list for the current
5258 ;; line
5259 (let* ((syntax (vhdl-get-syntactic-context))
5260 (len (length syntax))
5261 (ic (format "%s" (car (nth (1- len) syntax)))))
5eabfe72 5262 ic)
d2ddb974
KH
5263 )))
5264 (offset (vhdl-read-offset langelem)))
5265 (list langelem offset current-prefix-arg)))
5266 ;; sanity check offset
5267 (or (eq offset '+)
5268 (eq offset '-)
5269 (eq offset '++)
5270 (eq offset '--)
5271 (integerp offset)
5272 (fboundp offset)
5273 (boundp offset)
3dcb36b7 5274 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
d2ddb974
KH
5275 offset))
5276 (let ((entry (assq symbol vhdl-offsets-alist)))
5277 (if entry
5278 (setcdr entry offset)
5279 (if add-p
5eabfe72
KH
5280 (setq vhdl-offsets-alist
5281 (cons (cons symbol offset) vhdl-offsets-alist))
3dcb36b7 5282 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
d2ddb974
KH
5283 (vhdl-keep-region-active))
5284
5285(defun vhdl-set-style (style &optional local)
5eabfe72 5286 "Set `vhdl-mode' variables to use one of several different indentation styles.
d2ddb974
KH
5287STYLE is a string representing the desired style and optional LOCAL is
5288a flag which, if non-nil, means to make the style variables being
5289changed buffer local, instead of the default, which is to set the
5290global variables. Interactively, the flag comes from the prefix
5291argument. The styles are chosen from the `vhdl-style-alist' variable."
5292 (interactive (list (completing-read "Use which VHDL indentation style? "
5eabfe72 5293 vhdl-style-alist nil t)
d2ddb974
KH
5294 current-prefix-arg))
5295 (let ((vars (cdr (assoc style vhdl-style-alist))))
5296 (or vars
3dcb36b7 5297 (error "ERROR: Invalid VHDL indentation style `%s'" style))
d2ddb974
KH
5298 ;; set all the variables
5299 (mapcar
5300 (function
5301 (lambda (varentry)
5302 (let ((var (car varentry))
5303 (val (cdr varentry)))
5304 (and local
5305 (make-local-variable var))
5306 ;; special case for vhdl-offsets-alist
5307 (if (not (eq var 'vhdl-offsets-alist))
5308 (set var val)
5309 ;; reset vhdl-offsets-alist to the default value first
5310 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5311 ;; now set the langelems that are different
5312 (mapcar
5313 (function
5314 (lambda (langentry)
5315 (let ((langelem (car langentry))
5316 (offset (cdr langentry)))
5317 (vhdl-set-offset langelem offset)
5318 )))
5319 val))
5320 )))
5321 vars))
5322 (vhdl-keep-region-active))
5323
5324(defun vhdl-get-offset (langelem)
5eabfe72
KH
5325 "Get offset from LANGELEM which is a cons cell of the form:
5326\(SYMBOL . RELPOS). The symbol is matched against
5327vhdl-offsets-alist and the offset found there is either returned,
5328or added to the indentation at RELPOS. If RELPOS is nil, then
5329the offset is simply returned."
d2ddb974
KH
5330 (let* ((symbol (car langelem))
5331 (relpos (cdr langelem))
5332 (match (assq symbol vhdl-offsets-alist))
5333 (offset (cdr-safe match)))
5334 ;; offset can be a number, a function, a variable, or one of the
5335 ;; symbols + or -
5336 (cond
5337 ((not match)
5338 (if vhdl-strict-syntax-p
3dcb36b7 5339 (error "ERROR: Don't know how to indent a %s" symbol)
d2ddb974
KH
5340 (setq offset 0
5341 relpos 0)))
5342 ((eq offset '+) (setq offset vhdl-basic-offset))
5343 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5344 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5345 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5346 ((and (not (numberp offset))
5347 (fboundp offset))
5348 (setq offset (funcall offset langelem)))
5349 ((not (numberp offset))
5350 (setq offset (eval offset)))
5351 )
5352 (+ (if (and relpos
5353 (< relpos (vhdl-point 'bol)))
5354 (save-excursion
5355 (goto-char relpos)
5356 (current-column))
5357 0)
5358 offset)))
5359
5360;; Syntactic support functions:
5361
3dcb36b7
JB
5362(defun vhdl-in-comment-p ()
5363 "Check if point is in a comment."
5364 (eq (vhdl-in-literal) 'comment))
5365
5366(defun vhdl-in-string-p ()
5367 "Check if point is in a string."
5368 (eq (vhdl-in-literal) 'string))
d2ddb974 5369
3dcb36b7 5370(defun vhdl-in-literal ()
5eabfe72 5371 "Determine if point is in a VHDL literal."
d2ddb974 5372 (save-excursion
5eabfe72 5373 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
d2ddb974
KH
5374 (cond
5375 ((nth 3 state) 'string)
5376 ((nth 4 state) 'comment)
0a2e512a 5377 ((vhdl-beginning-of-macro) 'pound)
5eabfe72 5378 (t nil)))))
d2ddb974 5379
3dcb36b7
JB
5380(defun vhdl-forward-comment (&optional direction)
5381 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5382negative, skip forward otherwise."
5383 (interactive "p")
5384 (if (and direction (< direction 0))
5385 ;; skip backwards
5386 (progn
5387 (skip-chars-backward " \t\n")
5388 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5389 (goto-char (match-beginning 3))
5390 (skip-chars-backward " \t\n")))
5391 ;; skip forwards
5392 (skip-chars-forward " \t\n")
5393 (while (looking-at "--.*")
5394 (goto-char (match-end 0))
5395 (skip-chars-forward " \t\n"))))
5396
5397;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5398(unless (and vhdl-xemacs (string< "21.2" emacs-version))
5399 (defalias 'vhdl-forward-comment 'forward-comment))
5400
d2ddb974
KH
5401;; This is the best we can do in Win-Emacs.
5402(defun vhdl-win-il (&optional lim)
5eabfe72 5403 "Determine if point is in a VHDL literal."
d2ddb974
KH
5404 (save-excursion
5405 (let* ((here (point))
5406 (state nil)
5407 (match nil)
5408 (lim (or lim (vhdl-point 'bod))))
5409 (goto-char lim )
5410 (while (< (point) here)
5411 (setq match
5412 (and (re-search-forward "--\\|[\"']"
5413 here 'move)
5414 (buffer-substring (match-beginning 0) (match-end 0))))
5415 (setq state
5416 (cond
5417 ;; no match
5418 ((null match) nil)
5419 ;; looking at the opening of a VHDL style comment
5420 ((string= "--" match)
5421 (if (<= here (progn (end-of-line) (point))) 'comment))
5422 ;; looking at the opening of a double quote string
5423 ((string= "\"" match)
5424 (if (not (save-restriction
5425 ;; this seems to be necessary since the
5426 ;; re-search-forward will not work without it
5427 (narrow-to-region (point) here)
5428 (re-search-forward
5429 ;; this regexp matches a double quote
5430 ;; which is preceded by an even number
5431 ;; of backslashes, including zero
5432 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5433 'string))
5434 ;; looking at the opening of a single quote string
5435 ((string= "'" match)
5436 (if (not (save-restriction
5437 ;; see comments from above
5438 (narrow-to-region (point) here)
5439 (re-search-forward
5440 ;; this matches a single quote which is
5441 ;; preceded by zero or two backslashes.
5442 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5443 here 'move)))
5444 'string))
5445 (t nil)))
5446 ) ; end-while
5447 state)))
5448
5eabfe72 5449(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5450 (fset 'vhdl-in-literal 'vhdl-win-il))
5451
5452;; Skipping of "syntactic whitespace". Syntactic whitespace is
5453;; defined as lexical whitespace or comments. Search no farther back
5454;; or forward than optional LIM. If LIM is omitted, (point-min) is
5455;; used for backward skipping, (point-max) is used for forward
5456;; skipping.
5457
5458(defun vhdl-forward-syntactic-ws (&optional lim)
5eabfe72 5459 "Forward skip of syntactic whitespace."
0a2e512a
RF
5460 (let* ((here (point-max))
5461 (hugenum (point-max)))
5462 (while (/= here (point))
5463 (setq here (point))
5464 (vhdl-forward-comment hugenum)
5465 ;; skip preprocessor directives
5466 (when (and (eq (char-after) ?#)
5467 (= (vhdl-point 'boi) (point)))
5468 (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
5469 (= (forward-line 1) 0)))
5470 (end-of-line)))
5471 (if lim (goto-char (min (point) lim)))))
5472
d2ddb974
KH
5473
5474;; This is the best we can do in Win-Emacs.
5475(defun vhdl-win-fsws (&optional lim)
5eabfe72 5476 "Forward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5477 (let ((lim (or lim (point-max)))
5478 stop)
5479 (while (not stop)
5480 (skip-chars-forward " \t\n\r\f" lim)
5481 (cond
5482 ;; vhdl comment
5483 ((looking-at "--") (end-of-line))
5484 ;; none of the above
3dcb36b7 5485 (t (setq stop t))))))
d2ddb974 5486
5eabfe72 5487(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5488 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5489
0a2e512a
RF
5490(defun vhdl-beginning-of-macro (&optional lim)
5491 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5492 (let ((here (point)))
5493 (beginning-of-line)
5494 (while (eq (char-before (1- (point))) ?\\)
5495 (forward-line -1))
5496 (back-to-indentation)
5497 (if (and (<= (point) here)
5498 (eq (char-after) ?#))
5499 t
5500 (goto-char here)
5501 nil)))
5502
d2ddb974 5503(defun vhdl-backward-syntactic-ws (&optional lim)
5eabfe72 5504 "Backward skip over syntactic whitespace."
0a2e512a
RF
5505 (let* ((here (point-min))
5506 (hugenum (- (point-max))))
5507 (while (/= here (point))
5508 (setq here (point))
5509 (vhdl-forward-comment hugenum)
5510 (vhdl-beginning-of-macro))
5511 (if lim (goto-char (max (point) lim)))))
d2ddb974
KH
5512
5513;; This is the best we can do in Win-Emacs.
5514(defun vhdl-win-bsws (&optional lim)
5eabfe72 5515 "Backward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5516 (let ((lim (or lim (vhdl-point 'bod)))
5517 stop)
5518 (while (not stop)
5519 (skip-chars-backward " \t\n\r\f" lim)
5520 (cond
5521 ;; vhdl comment
3dcb36b7 5522 ((eq (vhdl-in-literal) 'comment)
d2ddb974
KH
5523 (skip-chars-backward "^-" lim)
5524 (skip-chars-backward "-" lim)
5525 (while (not (or (and (= (following-char) ?-)
5526 (= (char-after (1+ (point))) ?-))
5527 (<= (point) lim)))
5528 (skip-chars-backward "^-" lim)
5529 (skip-chars-backward "-" lim)))
5530 ;; none of the above
3dcb36b7 5531 (t (setq stop t))))))
d2ddb974 5532
5eabfe72 5533(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5534 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5535
5536;; Functions to help finding the correct indentation column:
5537
5538(defun vhdl-first-word (point)
5539 "If the keyword at POINT is at boi, then return (current-column) at
5540that point, else nil."
5541 (save-excursion
5542 (and (goto-char point)
5543 (eq (point) (vhdl-point 'boi))
5544 (current-column))))
5545
5546(defun vhdl-last-word (point)
5547 "If the keyword at POINT is at eoi, then return (current-column) at
5548that point, else nil."
5549 (save-excursion
5550 (and (goto-char point)
5551 (save-excursion (or (eq (progn (forward-sexp) (point))
5552 (vhdl-point 'eoi))
5553 (looking-at "\\s-*\\(--\\)?")))
5554 (current-column))))
5555
5556;; Core syntactic evaluation functions:
5557
5558(defconst vhdl-libunit-re
5559 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5560
5561(defun vhdl-libunit-p ()
5562 (and
5563 (save-excursion
5564 (forward-sexp)
5565 (skip-chars-forward " \t\n")
5566 (not (looking-at "is\\b[^_]")))
5567 (save-excursion
5568 (backward-sexp)
5569 (and (not (looking-at "use\\b[^_]"))
5570 (progn
5571 (forward-sexp)
5572 (vhdl-forward-syntactic-ws)
5573 (/= (following-char) ?:))))
5574 ))
5575
5576(defconst vhdl-defun-re
5eabfe72 5577 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
d2ddb974
KH
5578
5579(defun vhdl-defun-p ()
5580 (save-excursion
5eabfe72
KH
5581 (if (looking-at "block\\|process\\|procedural")
5582 ;; "block", "process", "procedural":
d2ddb974
KH
5583 (save-excursion
5584 (backward-sexp)
5585 (not (looking-at "end\\s-+\\w")))
5586 ;; "architecture", "configuration", "entity",
5587 ;; "package", "procedure", "function":
5588 t)))
5589
5590(defun vhdl-corresponding-defun ()
5591 "If the word at the current position corresponds to a \"defun\"
5592keyword, then return a string that can be used to find the
5593corresponding \"begin\" keyword, else return nil."
5594 (save-excursion
5595 (and (looking-at vhdl-defun-re)
5596 (vhdl-defun-p)
5eabfe72
KH
5597 (if (looking-at "block\\|process\\|procedural")
5598 ;; "block", "process". "procedural:
d2ddb974
KH
5599 (buffer-substring (match-beginning 0) (match-end 0))
5600 ;; "architecture", "configuration", "entity", "package",
5601 ;; "procedure", "function":
5602 "is"))))
5603
5604(defconst vhdl-begin-fwd-re
5eabfe72 5605 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
d2ddb974
KH
5606 "A regular expression for searching forward that matches all known
5607\"begin\" keywords.")
5608
5609(defconst vhdl-begin-bwd-re
5eabfe72 5610 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
d2ddb974
KH
5611 "A regular expression for searching backward that matches all known
5612\"begin\" keywords.")
5613
5614(defun vhdl-begin-p (&optional lim)
5615 "Return t if we are looking at a real \"begin\" keyword.
5616Assumes that the caller will make sure that we are looking at
5617vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5618the middle of an identifier that just happens to contain a \"begin\"
5619keyword."
5620 (cond
5621 ;; "[architecture|case|configuration|entity|package|
5622 ;; procedure|function] ... is":
5623 ((and (looking-at "i")
5624 (save-excursion
5625 ;; Skip backward over first sexp (needed to skip over a
5626 ;; procedure interface list, and is harmless in other
5627 ;; situations). Note that we need "return" in the
5628 ;; following search list so that we don't run into
5629 ;; semicolons in the function interface list.
5630 (backward-sexp)
5631 (let (foundp)
5632 (while (and (not foundp)
5633 (re-search-backward
5eabfe72 5634 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
d2ddb974
KH
5635 lim 'move))
5636 (if (or (= (preceding-char) ?_)
3dcb36b7 5637 (vhdl-in-literal))
d2ddb974
KH
5638 (backward-char)
5639 (setq foundp t))))
5640 (and (/= (following-char) ?\;)
5eabfe72 5641 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
d2ddb974
KH
5642 t)
5643 ;; "begin", "then":
5644 ((looking-at "be\\|t")
5645 t)
5646 ;; "else":
5647 ((and (looking-at "e")
5648 ;; make sure that the "else" isn't inside a
5649 ;; conditional signal assignment.
5650 (save-excursion
5651 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5652 (or (eq (following-char) ?\;)
5653 (eq (point) lim))))
5654 t)
5eabfe72 5655 ;; "block", "generate", "loop", "process", "procedural",
d2ddb974
KH
5656 ;; "units", "record":
5657 ((and (looking-at "bl\\|[glpur]")
5658 (save-excursion
5659 (backward-sexp)
5660 (not (looking-at "end\\s-+\\w"))))
5661 t)
5662 ;; "component":
5663 ((and (looking-at "c")
5664 (save-excursion
5665 (backward-sexp)
5666 (not (looking-at "end\\s-+\\w")))
5667 ;; look out for the dreaded entity class in an attribute
5668 (save-excursion
5669 (vhdl-backward-syntactic-ws lim)
5670 (/= (preceding-char) ?:)))
5671 t)
5672 ;; "for" (inside configuration declaration):
5673 ((and (looking-at "f")
5674 (save-excursion
5675 (backward-sexp)
5676 (not (looking-at "end\\s-+\\w")))
5677 (vhdl-has-syntax 'configuration))
5678 t)
5679 ))
5680
5681(defun vhdl-corresponding-mid (&optional lim)
5682 (cond
5eabfe72 5683 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
d2ddb974
KH
5684 "begin")
5685 ((looking-at "then")
5686 "<else>")
5687 (t
5688 "end")))
5689
5690(defun vhdl-corresponding-end (&optional lim)
5691 "If the word at the current position corresponds to a \"begin\"
5692keyword, then return a vector containing enough information to find
5693the corresponding \"end\" keyword, else return nil. The keyword to
5694search forward for is aref 0. The column in which the keyword must
5695appear is aref 1 or nil if any column is suitable.
5696Assumes that the caller will make sure that we are not in the middle
5697of an identifier that just happens to contain a \"begin\" keyword."
5698 (save-excursion
5699 (and (looking-at vhdl-begin-fwd-re)
5700 (/= (preceding-char) ?_)
3dcb36b7 5701 (not (vhdl-in-literal))
d2ddb974
KH
5702 (vhdl-begin-p lim)
5703 (cond
5704 ;; "is", "generate", "loop":
5705 ((looking-at "[igl]")
5706 (vector "end"
5707 (and (vhdl-last-word (point))
5708 (or (vhdl-first-word (point))
5709 (save-excursion
5710 (vhdl-beginning-of-statement-1 lim)
5711 (vhdl-backward-skip-label lim)
5712 (vhdl-first-word (point)))))))
5713 ;; "begin", "else", "for":
5714 ((looking-at "be\\|[ef]")
5715 (vector "end"
5716 (and (vhdl-last-word (point))
5717 (or (vhdl-first-word (point))
5718 (save-excursion
5719 (vhdl-beginning-of-statement-1 lim)
5720 (vhdl-backward-skip-label lim)
5721 (vhdl-first-word (point)))))))
5722 ;; "component", "units", "record":
5723 ((looking-at "[cur]")
5724 ;; The first end found will close the block
5725 (vector "end" nil))
5eabfe72 5726 ;; "block", "process", "procedural":
d2ddb974
KH
5727 ((looking-at "bl\\|p")
5728 (vector "end"
5729 (or (vhdl-first-word (point))
5730 (save-excursion
5731 (vhdl-beginning-of-statement-1 lim)
5732 (vhdl-backward-skip-label lim)
5733 (vhdl-first-word (point))))))
5734 ;; "then":
5735 ((looking-at "t")
5736 (vector "elsif\\|else\\|end\\s-+if"
5737 (and (vhdl-last-word (point))
5738 (or (vhdl-first-word (point))
5739 (save-excursion
5740 (vhdl-beginning-of-statement-1 lim)
5741 (vhdl-backward-skip-label lim)
5742 (vhdl-first-word (point)))))))
5743 ))))
5744
5745(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5746
5747(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5748
5749(defun vhdl-end-p (&optional lim)
5750 "Return t if we are looking at a real \"end\" keyword.
5751Assumes that the caller will make sure that we are looking at
5752vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5753the middle of an identifier that just happens to contain an \"end\"
5754keyword."
5755 (or (not (looking-at "else"))
5756 ;; make sure that the "else" isn't inside a conditional signal
5757 ;; assignment.
5758 (save-excursion
5759 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5760 (or (eq (following-char) ?\;)
0a2e512a
RF
5761 (eq (point) lim)
5762 (vhdl-in-literal)))))
d2ddb974
KH
5763
5764(defun vhdl-corresponding-begin (&optional lim)
5765 "If the word at the current position corresponds to an \"end\"
5766keyword, then return a vector containing enough information to find
5767the corresponding \"begin\" keyword, else return nil. The keyword to
3dcb36b7 5768search backward for is aref 0. The column in which the keyword must
d2ddb974
KH
5769appear is aref 1 or nil if any column is suitable. The supplementary
5770keyword to search forward for is aref 2 or nil if this is not
5771required. If aref 3 is t, then the \"begin\" keyword may be found in
5772the middle of a statement.
5773Assumes that the caller will make sure that we are not in the middle
5774of an identifier that just happens to contain an \"end\" keyword."
5775 (save-excursion
5776 (let (pos)
5777 (if (and (looking-at vhdl-end-fwd-re)
3dcb36b7 5778 (not (vhdl-in-literal))
d2ddb974
KH
5779 (vhdl-end-p lim))
5780 (if (looking-at "el")
5781 ;; "else", "elsif":
5782 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5783 ;; "end ...":
5784 (setq pos (point))
5785 (forward-sexp)
5786 (skip-chars-forward " \t\n")
5787 (cond
5788 ;; "end if":
5789 ((looking-at "if\\b[^_]")
5790 (vector "else\\|elsif\\|if"
5791 (vhdl-first-word pos)
5792 "else\\|then" nil))
5793 ;; "end component":
5794 ((looking-at "component\\b[^_]")
5795 (vector (buffer-substring (match-beginning 1)
5796 (match-end 1))
5797 (vhdl-first-word pos)
5798 nil nil))
5799 ;; "end units", "end record":
5800 ((looking-at "\\(units\\|record\\)\\b[^_]")
5801 (vector (buffer-substring (match-beginning 1)
5802 (match-end 1))
5803 (vhdl-first-word pos)
5804 nil t))
5eabfe72
KH
5805 ;; "end block", "end process", "end procedural":
5806 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
d2ddb974
KH
5807 (vector "begin" (vhdl-first-word pos) nil nil))
5808 ;; "end case":
5809 ((looking-at "case\\b[^_]")
5810 (vector "case" (vhdl-first-word pos) "is" nil))
5811 ;; "end generate":
5812 ((looking-at "generate\\b[^_]")
5813 (vector "generate\\|for\\|if"
5814 (vhdl-first-word pos)
5815 "generate" nil))
5816 ;; "end loop":
5817 ((looking-at "loop\\b[^_]")
5818 (vector "loop\\|while\\|for"
5819 (vhdl-first-word pos)
5820 "loop" nil))
5821 ;; "end for" (inside configuration declaration):
5822 ((looking-at "for\\b[^_]")
5823 (vector "for" (vhdl-first-word pos) nil nil))
5824 ;; "end [id]":
5825 (t
5826 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5827 (vhdl-first-word pos)
5828 ;; return an alist of (statement . keyword) mappings
5829 '(
5830 ;; "begin ... end [id]":
0a2e512a 5831 ("begin" . nil)
d2ddb974 5832 ;; "architecture ... is ... begin ... end [id]":
0a2e512a 5833 ("architecture" . "is")
d2ddb974
KH
5834 ;; "configuration ... is ... end [id]":
5835 ("configuration" . "is")
5836 ;; "entity ... is ... end [id]":
0a2e512a 5837 ("entity" . "is")
d2ddb974 5838 ;; "package ... is ... end [id]":
0a2e512a 5839 ("package" . "is")
d2ddb974
KH
5840 ;; "procedure ... is ... begin ... end [id]":
5841 ("procedure" . "is")
5842 ;; "function ... is ... begin ... end [id]":
5843 ("function" . "is")
5844 )
5845 nil))
5846 ))) ; "end ..."
5847 )))
5848
5849(defconst vhdl-leader-re
5eabfe72 5850 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
d2ddb974
KH
5851
5852(defun vhdl-end-of-leader ()
5853 (save-excursion
5eabfe72 5854 (cond ((looking-at "block\\|process\\|procedural")
d2ddb974
KH
5855 (if (save-excursion
5856 (forward-sexp)
5857 (skip-chars-forward " \t\n")
5858 (= (following-char) ?\())
5859 (forward-sexp 2)
5860 (forward-sexp))
3dcb36b7
JB
5861 (when (looking-at "[ \t\n]*is")
5862 (goto-char (match-end 0)))
d2ddb974
KH
5863 (point))
5864 ((looking-at "component")
5865 (forward-sexp 2)
3dcb36b7
JB
5866 (when (looking-at "[ \t\n]*is")
5867 (goto-char (match-end 0)))
d2ddb974
KH
5868 (point))
5869 ((looking-at "for")
5870 (forward-sexp 2)
5871 (skip-chars-forward " \t\n")
5872 (while (looking-at "[,:(]")
5873 (forward-sexp)
5874 (skip-chars-forward " \t\n"))
5875 (point))
5876 (t nil)
5877 )))
5878
5879(defconst vhdl-trailer-re
0a2e512a 5880 "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
d2ddb974
KH
5881
5882(defconst vhdl-statement-fwd-re
5883 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5884 "A regular expression for searching forward that matches all known
5885\"statement\" keywords.")
5886
5887(defconst vhdl-statement-bwd-re
5888 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5889 "A regular expression for searching backward that matches all known
5890\"statement\" keywords.")
5891
5892(defun vhdl-statement-p (&optional lim)
5893 "Return t if we are looking at a real \"statement\" keyword.
5894Assumes that the caller will make sure that we are looking at
5eabfe72
KH
5895vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5896in the middle of an identifier that just happens to contain a
5897\"statement\" keyword."
d2ddb974
KH
5898 (cond
5899 ;; "for" ... "generate":
5900 ((and (looking-at "f")
5901 ;; Make sure it's the start of a parameter specification.
5902 (save-excursion
5903 (forward-sexp 2)
5904 (skip-chars-forward " \t\n")
5905 (looking-at "in\\b[^_]"))
5906 ;; Make sure it's not an "end for".
5907 (save-excursion
5908 (backward-sexp)
5909 (not (looking-at "end\\s-+\\w"))))
5910 t)
5911 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5912 ((and (looking-at "i")
5913 ;; Make sure it's not an "end if".
5914 (save-excursion
5915 (backward-sexp)
5916 (not (looking-at "end\\s-+\\w"))))
5917 t)
5918 ;; "while" ... "loop":
5919 ((looking-at "w")
5920 t)
5921 ))
5922
5923(defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5924 "Regexp describing a case statement alternative key.")
5925
5926(defun vhdl-case-alternative-p (&optional lim)
5927 "Return t if we are looking at a real case alternative.
5928Assumes that the caller will make sure that we are looking at
5929vhdl-case-alternative-re, and are not inside a literal, and that
5930we are not in the middle of an identifier that just happens to
5931contain a \"when\" keyword."
5932 (save-excursion
5933 (let (foundp)
5934 (while (and (not foundp)
5935 (re-search-backward ";\\|<=" lim 'move))
5936 (if (or (= (preceding-char) ?_)
3dcb36b7 5937 (vhdl-in-literal))
d2ddb974
KH
5938 (backward-char)
5939 (setq foundp t)))
5940 (or (eq (following-char) ?\;)
5941 (eq (point) lim)))
5942 ))
5943
5944;; Core syntactic movement functions:
5945
5946(defconst vhdl-b-t-b-re
5947 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5948
5949(defun vhdl-backward-to-block (&optional lim)
5950 "Move backward to the previous \"begin\" or \"end\" keyword."
5951 (let (foundp)
5952 (while (and (not foundp)
5953 (re-search-backward vhdl-b-t-b-re lim 'move))
5954 (if (or (= (preceding-char) ?_)
3dcb36b7 5955 (vhdl-in-literal))
d2ddb974
KH
5956 (backward-char)
5957 (cond
5958 ;; "begin" keyword:
5959 ((and (looking-at vhdl-begin-fwd-re)
5960 (/= (preceding-char) ?_)
5961 (vhdl-begin-p lim))
5962 (setq foundp 'begin))
5963 ;; "end" keyword:
5964 ((and (looking-at vhdl-end-fwd-re)
5965 (/= (preceding-char) ?_)
5966 (vhdl-end-p lim))
5967 (setq foundp 'end))
5968 ))
5969 )
5970 foundp
5971 ))
5972
5973(defun vhdl-forward-sexp (&optional count lim)
5974 "Move forward across one balanced expression (sexp).
5975With COUNT, do it that many times."
5976 (interactive "p")
5977 (let ((count (or count 1))
5978 (case-fold-search t)
5979 end-vec target)
5980 (save-excursion
5981 (while (> count 0)
5982 ;; skip whitespace
5983 (skip-chars-forward " \t\n")
5984 ;; Check for an unbalanced "end" keyword
5985 (if (and (looking-at vhdl-end-fwd-re)
5986 (/= (preceding-char) ?_)
3dcb36b7 5987 (not (vhdl-in-literal))
d2ddb974
KH
5988 (vhdl-end-p lim)
5989 (not (looking-at "else")))
5990 (error
3dcb36b7 5991 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
d2ddb974
KH
5992 ;; If the current keyword is a "begin" keyword, then find the
5993 ;; corresponding "end" keyword.
5994 (if (setq end-vec (vhdl-corresponding-end lim))
5995 (let (
5996 ;; end-re is the statement keyword to search for
5997 (end-re
5998 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5999 ;; column is either the statement keyword target column
6000 ;; or nil
6001 (column (aref end-vec 1))
6002 (eol (vhdl-point 'eol))
6003 foundp literal placeholder)
6004 ;; Look for the statement keyword.
6005 (while (and (not foundp)
6006 (re-search-forward end-re nil t)
6007 (setq placeholder (match-end 1))
6008 (goto-char (match-beginning 0)))
6009 ;; If we are in a literal, or not in the right target
6010 ;; column and not on the same line as the begin, then
6011 ;; try again.
6012 (if (or (and column
6013 (/= (current-indentation) column)
6014 (> (point) eol))
6015 (= (preceding-char) ?_)
3dcb36b7 6016 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6017 (if (eq literal 'comment)
6018 (end-of-line)
6019 (forward-char))
6020 ;; An "else" keyword corresponds to both the opening brace
6021 ;; of the following sexp and the closing brace of the
6022 ;; previous sexp.
6023 (if (not (looking-at "else"))
6024 (goto-char placeholder))
6025 (setq foundp t))
6026 )
6027 (if (not foundp)
3dcb36b7 6028 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
d2ddb974
KH
6029 )
6030 ;; If the current keyword is not a "begin" keyword, then just
6031 ;; perform the normal forward-sexp.
6032 (forward-sexp)
6033 )
6034 (setq count (1- count))
6035 )
6036 (setq target (point)))
6037 (goto-char target)
6038 nil))
6039
6040(defun vhdl-backward-sexp (&optional count lim)
6041 "Move backward across one balanced expression (sexp).
6042With COUNT, do it that many times. LIM bounds any required backward
6043searches."
6044 (interactive "p")
6045 (let ((count (or count 1))
6046 (case-fold-search t)
6047 begin-vec target)
6048 (save-excursion
6049 (while (> count 0)
6050 ;; Perform the normal backward-sexp, unless we are looking at
6051 ;; "else" - an "else" keyword corresponds to both the opening brace
6052 ;; of the following sexp and the closing brace of the previous sexp.
6053 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6054 (/= (preceding-char) ?_)
3dcb36b7 6055 (not (vhdl-in-literal)))
d2ddb974
KH
6056 nil
6057 (backward-sexp)
6058 (if (and (looking-at vhdl-begin-fwd-re)
6059 (/= (preceding-char) ?_)
3dcb36b7 6060 (not (vhdl-in-literal))
d2ddb974 6061 (vhdl-begin-p lim))
3dcb36b7 6062 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
d2ddb974
KH
6063 ;; If the current keyword is an "end" keyword, then find the
6064 ;; corresponding "begin" keyword.
6065 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
6066 (/= (preceding-char) ?_))
6067 (let (
6068 ;; begin-re is the statement keyword to search for
6069 (begin-re
6070 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
6071 ;; column is either the statement keyword target column
6072 ;; or nil
6073 (column (aref begin-vec 1))
6074 ;; internal-p controls where the statement keyword can
6075 ;; be found.
6076 (internal-p (aref begin-vec 3))
6077 (last-backward (point)) last-forward
6078 foundp literal keyword)
6079 ;; Look for the statement keyword.
6080 (while (and (not foundp)
6081 (re-search-backward begin-re lim t)
6082 (setq keyword
6083 (buffer-substring (match-beginning 1)
6084 (match-end 1))))
6085 ;; If we are in a literal or in the wrong column,
6086 ;; then try again.
6087 (if (or (and column
6088 (and (/= (current-indentation) column)
6089 ;; possibly accept current-column as
6090 ;; well as current-indentation.
6091 (or (not internal-p)
6092 (/= (current-column) column))))
6093 (= (preceding-char) ?_)
3dcb36b7 6094 (vhdl-in-literal))
d2ddb974
KH
6095 (backward-char)
6096 ;; If there is a supplementary keyword, then
6097 ;; search forward for it.
6098 (if (and (setq begin-re (aref begin-vec 2))
6099 (or (not (listp begin-re))
6100 ;; If begin-re is an alist, then find the
6101 ;; element corresponding to the actual
6102 ;; keyword that we found.
6103 (progn
6104 (setq begin-re
6105 (assoc keyword begin-re))
6106 (and begin-re
6107 (setq begin-re (cdr begin-re))))))
6108 (and
6109 (setq begin-re
6110 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
6111 (save-excursion
6112 (setq last-forward (point))
6113 ;; Look for the supplementary keyword
6114 ;; (bounded by the backward search start
6115 ;; point).
6116 (while (and (not foundp)
6117 (re-search-forward begin-re
6118 last-backward t)
6119 (goto-char (match-beginning 1)))
6120 ;; If we are in a literal, then try again.
6121 (if (or (= (preceding-char) ?_)
6122 (setq literal
3dcb36b7 6123 (vhdl-in-literal)))
d2ddb974
KH
6124 (if (eq literal 'comment)
6125 (goto-char
6126 (min (vhdl-point 'eol) last-backward))
6127 (forward-char))
6128 ;; We have found the supplementary keyword.
6129 ;; Save the position of the keyword in foundp.
6130 (setq foundp (point)))
6131 )
6132 foundp)
6133 ;; If the supplementary keyword was found, then
6134 ;; move point to the supplementary keyword.
6135 (goto-char foundp))
6136 ;; If there was no supplementary keyword, then
6137 ;; point is already at the statement keyword.
6138 (setq foundp t)))
6139 ) ; end of the search for the statement keyword
6140 (if (not foundp)
3dcb36b7 6141 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
d2ddb974
KH
6142 ))
6143 (setq count (1- count))
6144 )
6145 (setq target (point)))
6146 (goto-char target)
6147 nil))
6148
6149(defun vhdl-backward-up-list (&optional count limit)
6150 "Move backward out of one level of blocks.
6151With argument, do this that many times."
6152 (interactive "p")
6153 (let ((count (or count 1))
6154 target)
6155 (save-excursion
6156 (while (> count 0)
6157 (if (looking-at vhdl-defun-re)
3dcb36b7 6158 (error "ERROR: Unbalanced blocks"))
d2ddb974
KH
6159 (vhdl-backward-to-block limit)
6160 (setq count (1- count)))
6161 (setq target (point)))
6162 (goto-char target)))
6163
6164(defun vhdl-end-of-defun (&optional count)
6165 "Move forward to the end of a VHDL defun."
6166 (interactive)
6167 (let ((case-fold-search t))
6168 (vhdl-beginning-of-defun)
5eabfe72 6169 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6170 (re-search-forward "\\bis\\b"))
6171 (vhdl-forward-sexp)))
6172
6173(defun vhdl-mark-defun ()
6174 "Put mark at end of this \"defun\", point at beginning."
6175 (interactive)
6176 (let ((case-fold-search t))
6177 (push-mark)
6178 (vhdl-beginning-of-defun)
6179 (push-mark)
5eabfe72 6180 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6181 (re-search-forward "\\bis\\b"))
6182 (vhdl-forward-sexp)
6183 (exchange-point-and-mark)))
6184
6185(defun vhdl-beginning-of-libunit ()
6186 "Move backward to the beginning of a VHDL library unit.
6187Returns the location of the corresponding begin keyword, unless search
5eabfe72
KH
6188stops due to beginning or end of buffer.
6189Note that if point is between the \"libunit\" keyword and the
6190corresponding \"begin\" keyword, then that libunit will not be
a3dd3c0e
JB
6191recognized, and the search will continue backwards. If point is
6192at the \"begin\" keyword, then the defun will be recognized. The
5eabfe72 6193returned point is at the first character of the \"libunit\" keyword."
d2ddb974
KH
6194 (let ((last-forward (point))
6195 (last-backward
6196 ;; Just in case we are actually sitting on the "begin"
6197 ;; keyword, allow for the keyword and an extra character,
6198 ;; as this will be used when looking forward for the
6199 ;; "begin" keyword.
6200 (save-excursion (forward-word 1) (1+ (point))))
6201 foundp literal placeholder)
6202 ;; Find the "libunit" keyword.
6203 (while (and (not foundp)
6204 (re-search-backward vhdl-libunit-re nil 'move))
6205 ;; If we are in a literal, or not at a real libunit, then try again.
6206 (if (or (= (preceding-char) ?_)
3dcb36b7 6207 (vhdl-in-literal)
d2ddb974
KH
6208 (not (vhdl-libunit-p)))
6209 (backward-char)
6210 ;; Find the corresponding "begin" keyword.
6211 (setq last-forward (point))
6212 (while (and (not foundp)
6213 (re-search-forward "\\bis\\b[^_]" last-backward t)
6214 (setq placeholder (match-beginning 0)))
6215 (if (or (= (preceding-char) ?_)
3dcb36b7 6216 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6217 ;; It wasn't a real keyword, so keep searching.
6218 (if (eq literal 'comment)
6219 (goto-char
6220 (min (vhdl-point 'eol) last-backward))
6221 (forward-char))
6222 ;; We have found the begin keyword, loop will exit.
6223 (setq foundp placeholder)))
6224 ;; Go back to the libunit keyword
6225 (goto-char last-forward)))
6226 foundp))
6227
6228(defun vhdl-beginning-of-defun (&optional count)
6229 "Move backward to the beginning of a VHDL defun.
6230With argument, do it that many times.
6231Returns the location of the corresponding begin keyword, unless search
6232stops due to beginning or end of buffer."
6233 ;; Note that if point is between the "defun" keyword and the
6234 ;; corresponding "begin" keyword, then that defun will not be
0a2e512a
RF
6235 ;; recognized, and the search will continue backwards. If point is
6236 ;; at the "begin" keyword, then the defun will be recognized. The
d2ddb974
KH
6237 ;; returned point is at the first character of the "defun" keyword.
6238 (interactive "p")
6239 (let ((count (or count 1))
6240 (case-fold-search t)
6241 (last-forward (point))
6242 foundp)
6243 (while (> count 0)
6244 (setq foundp nil)
6245 (goto-char last-forward)
6246 (let ((last-backward
6247 ;; Just in case we are actually sitting on the "begin"
6248 ;; keyword, allow for the keyword and an extra character,
6249 ;; as this will be used when looking forward for the
6250 ;; "begin" keyword.
6251 (save-excursion (forward-word 1) (1+ (point))))
6252 begin-string literal)
6253 (while (and (not foundp)
6254 (re-search-backward vhdl-defun-re nil 'move))
6255 ;; If we are in a literal, then try again.
6256 (if (or (= (preceding-char) ?_)
3dcb36b7 6257 (vhdl-in-literal))
d2ddb974
KH
6258 (backward-char)
6259 (if (setq begin-string (vhdl-corresponding-defun))
6260 ;; This is a real defun keyword.
6261 ;; Find the corresponding "begin" keyword.
6262 ;; Look for the begin keyword.
6263 (progn
6264 ;; Save the search start point.
6265 (setq last-forward (point))
6266 (while (and (not foundp)
6267 (search-forward begin-string last-backward t))
6268 (if (or (= (preceding-char) ?_)
6269 (save-match-data
3dcb36b7 6270 (setq literal (vhdl-in-literal))))
d2ddb974
KH
6271 ;; It wasn't a real keyword, so keep searching.
6272 (if (eq literal 'comment)
6273 (goto-char
6274 (min (vhdl-point 'eol) last-backward))
6275 (forward-char))
6276 ;; We have found the begin keyword, loop will exit.
6277 (setq foundp (match-beginning 0)))
6278 )
6279 ;; Go back to the defun keyword
6280 (goto-char last-forward)) ; end search for begin keyword
6281 ))
6282 ) ; end of the search for the defun keyword
6283 )
6284 (setq count (1- count))
6285 )
6286 (vhdl-keep-region-active)
6287 foundp))
6288
8d422bd5 6289(defun vhdl-beginning-of-statement (&optional count lim interactive)
d2ddb974
KH
6290 "Go to the beginning of the innermost VHDL statement.
6291With prefix arg, go back N - 1 statements. If already at the
6292beginning of a statement then go to the beginning of the preceding
6293one. If within a string or comment, or next to a comment (only
6294whitespace between), move by sentences instead of statements.
6295
8d422bd5 6296When called from a program, this function takes 3 optional args: the
0a2e512a
RF
6297prefix arg, a buffer position limit which is the farthest back to
6298search, and an argument indicating an interactive call."
8d422bd5 6299 (interactive "p\np")
d2ddb974
KH
6300 (let ((count (or count 1))
6301 (case-fold-search t)
6302 (lim (or lim (point-min)))
6303 (here (point))
6304 state)
6305 (save-excursion
6306 (goto-char lim)
6307 (setq state (parse-partial-sexp (point) here nil nil)))
8d422bd5 6308 (if (and interactive
d2ddb974
KH
6309 (or (nth 3 state)
6310 (nth 4 state)
6311 (looking-at (concat "[ \t]*" comment-start-skip))))
6312 (forward-sentence (- count))
6313 (while (> count 0)
6314 (vhdl-beginning-of-statement-1 lim)
6315 (setq count (1- count))))
6316 ;; its possible we've been left up-buf of lim
6317 (goto-char (max (point) lim))
6318 )
6319 (vhdl-keep-region-active))
6320
6321(defconst vhdl-e-o-s-re
6322 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6323
6324(defun vhdl-end-of-statement ()
6325 "Very simple implementation."
6326 (interactive)
6327 (re-search-forward vhdl-e-o-s-re))
6328
6329(defconst vhdl-b-o-s-re
6330 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6331 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6332
6333(defun vhdl-beginning-of-statement-1 (&optional lim)
5eabfe72
KH
6334 "Move to the start of the current statement, or the previous
6335statement if already at the beginning of one."
d2ddb974
KH
6336 (let ((lim (or lim (point-min)))
6337 (here (point))
6338 (pos (point))
6339 donep)
6340 ;; go backwards one balanced expression, but be careful of
6341 ;; unbalanced paren being reached
6342 (if (not (vhdl-safe (progn (backward-sexp) t)))
6343 (progn
6344 (backward-up-list 1)
6345 (forward-char)
6346 (vhdl-forward-syntactic-ws here)
6347 (setq donep t)))
6348 (while (and (not donep)
6349 (not (bobp))
6350 ;; look backwards for a statement boundary
6351 (re-search-backward vhdl-b-o-s-re lim 'move))
6352 (if (or (= (preceding-char) ?_)
3dcb36b7 6353 (vhdl-in-literal))
d2ddb974
KH
6354 (backward-char)
6355 (cond
6356 ;; If we are looking at an open paren, then stop after it
6357 ((eq (following-char) ?\()
6358 (forward-char)
6359 (vhdl-forward-syntactic-ws here)
6360 (setq donep t))
6361 ;; If we are looking at a close paren, then skip it
6362 ((eq (following-char) ?\))
6363 (forward-char)
6364 (setq pos (point))
6365 (backward-sexp)
6366 (if (< (point) lim)
6367 (progn (goto-char pos)
6368 (vhdl-forward-syntactic-ws here)
6369 (setq donep t))))
6370 ;; If we are looking at a semicolon, then stop
6371 ((eq (following-char) ?\;)
6372 (progn
6373 (forward-char)
6374 (vhdl-forward-syntactic-ws here)
6375 (setq donep t)))
6376 ;; If we are looking at a "begin", then stop
6377 ((and (looking-at vhdl-begin-fwd-re)
6378 (/= (preceding-char) ?_)
6379 (vhdl-begin-p nil))
6380 ;; If it's a leader "begin", then find the
6381 ;; right place
6382 (if (looking-at vhdl-leader-re)
6383 (save-excursion
6384 ;; set a default stop point at the begin
6385 (setq pos (point))
6386 ;; is the start point inside the leader area ?
6387 (goto-char (vhdl-end-of-leader))
6388 (vhdl-forward-syntactic-ws here)
6389 (if (< (point) here)
6390 ;; start point was not inside leader area
6391 ;; set stop point at word after leader
6392 (setq pos (point))))
6393 (forward-word 1)
6394 (vhdl-forward-syntactic-ws here)
6395 (setq pos (point)))
6396 (goto-char pos)
6397 (setq donep t))
6398 ;; If we are looking at a "statement", then stop
6399 ((and (looking-at vhdl-statement-fwd-re)
6400 (/= (preceding-char) ?_)
6401 (vhdl-statement-p nil))
6402 (setq donep t))
6403 ;; If we are looking at a case alternative key, then stop
5eabfe72
KH
6404 ((and (looking-at vhdl-case-alternative-re)
6405 (vhdl-case-alternative-p lim))
d2ddb974
KH
6406 (save-excursion
6407 ;; set a default stop point at the when
6408 (setq pos (point))
6409 ;; is the start point inside the case alternative key ?
6410 (looking-at vhdl-case-alternative-re)
6411 (goto-char (match-end 0))
6412 (vhdl-forward-syntactic-ws here)
6413 (if (< (point) here)
6414 ;; start point was not inside the case alternative key
6415 ;; set stop point at word after case alternative keyleader
6416 (setq pos (point))))
6417 (goto-char pos)
6418 (setq donep t))
6419 ;; Bogus find, continue
6420 (t
6421 (backward-char)))))
6422 ))
6423
6424;; Defuns for calculating the current syntactic state:
6425
6426(defun vhdl-get-library-unit (bod placeholder)
5eabfe72
KH
6427 "If there is an enclosing library unit at bod, with it's \"begin\"
6428keyword at placeholder, then return the library unit type."
d2ddb974
KH
6429 (let ((here (vhdl-point 'bol)))
6430 (if (save-excursion
6431 (goto-char placeholder)
6432 (vhdl-safe (vhdl-forward-sexp 1 bod))
6433 (<= here (point)))
6434 (save-excursion
6435 (goto-char bod)
6436 (cond
6437 ((looking-at "e") 'entity)
6438 ((looking-at "a") 'architecture)
6439 ((looking-at "c") 'configuration)
6440 ((looking-at "p")
6441 (save-excursion
6442 (goto-char bod)
6443 (forward-sexp)
6444 (vhdl-forward-syntactic-ws here)
6445 (if (looking-at "body\\b[^_]")
6446 'package-body 'package))))))
6447 ))
6448
6449(defun vhdl-get-block-state (&optional lim)
5eabfe72
KH
6450 "Finds and records all the closest opens.
6451lim is the furthest back we need to search (it should be the
6452previous libunit keyword)."
d2ddb974
KH
6453 (let ((here (point))
6454 (lim (or lim (point-min)))
6455 keyword sexp-start sexp-mid sexp-end
6456 preceding-sexp containing-sexp
6457 containing-begin containing-mid containing-paren)
6458 (save-excursion
6459 ;; Find the containing-paren, and use that as the limit
6460 (if (setq containing-paren
6461 (save-restriction
6462 (narrow-to-region lim (point))
6463 (vhdl-safe (scan-lists (point) -1 1))))
6464 (setq lim containing-paren))
6465 ;; Look backwards for "begin" and "end" keywords.
6466 (while (and (> (point) lim)
6467 (not containing-sexp))
6468 (setq keyword (vhdl-backward-to-block lim))
6469 (cond
6470 ((eq keyword 'begin)
6471 ;; Found a "begin" keyword
6472 (setq sexp-start (point))
6473 (setq sexp-mid (vhdl-corresponding-mid lim))
6474 (setq sexp-end (vhdl-safe
6475 (save-excursion
6476 (vhdl-forward-sexp 1 lim) (point))))
6477 (if (and sexp-end (<= sexp-end here))
6478 ;; we want to record this sexp, but we only want to
6479 ;; record the last-most of any of them before here
6480 (or preceding-sexp
6481 (setq preceding-sexp sexp-start))
6482 ;; we're contained in this sexp so put sexp-start on
6483 ;; front of list
6484 (setq containing-sexp sexp-start)
6485 (setq containing-mid sexp-mid)
6486 (setq containing-begin t)))
6487 ((eq keyword 'end)
6488 ;; Found an "end" keyword
6489 (forward-sexp)
6490 (setq sexp-end (point))
6491 (setq sexp-mid nil)
6492 (setq sexp-start
6493 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6494 (progn (backward-sexp) (point))))
6495 ;; we want to record this sexp, but we only want to
6496 ;; record the last-most of any of them before here
6497 (or preceding-sexp
6498 (setq preceding-sexp sexp-start)))
6499 )))
6500 ;; Check if the containing-paren should be the containing-sexp
6501 (if (and containing-paren
6502 (or (null containing-sexp)
6503 (< containing-sexp containing-paren)))
6504 (setq containing-sexp containing-paren
6505 preceding-sexp nil
6506 containing-begin nil
6507 containing-mid nil))
6508 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6509 ))
6510
6511
6512(defconst vhdl-s-c-a-re
6513 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6514
6515(defun vhdl-skip-case-alternative (&optional lim)
5eabfe72
KH
6516 "Skip forward over case/when bodies, with optional maximal
6517limit. If no next case alternative is found, nil is returned and point
6518is not moved."
d2ddb974
KH
6519 (let ((lim (or lim (point-max)))
6520 (here (point))
6521 donep foundp)
6522 (while (and (< (point) lim)
6523 (not donep))
6524 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6525 (save-match-data
6526 (not (vhdl-in-literal)))
6527 (/= (match-beginning 0) here))
6528 (progn
6529 (goto-char (match-beginning 0))
6530 (cond
6531 ((and (looking-at "case")
6532 (re-search-forward "\\bis[^_]" lim t))
6533 (backward-sexp)
6534 (vhdl-forward-sexp))
6535 (t
6536 (setq donep t
6537 foundp t))))))
6538 (if (not foundp)
6539 (goto-char here))
6540 foundp))
6541
6542(defun vhdl-backward-skip-label (&optional lim)
5eabfe72
KH
6543 "Skip backward over a label, with optional maximal
6544limit. If label is not found, nil is returned and point
6545is not moved."
d2ddb974
KH
6546 (let ((lim (or lim (point-min)))
6547 placeholder)
6548 (if (save-excursion
6549 (vhdl-backward-syntactic-ws lim)
6550 (and (eq (preceding-char) ?:)
6551 (progn
6552 (backward-sexp)
6553 (setq placeholder (point))
6554 (looking-at vhdl-label-key))))
6555 (goto-char placeholder))
6556 ))
6557
6558(defun vhdl-forward-skip-label (&optional lim)
5eabfe72
KH
6559 "Skip forward over a label, with optional maximal
6560limit. If label is not found, nil is returned and point
6561is not moved."
d2ddb974
KH
6562 (let ((lim (or lim (point-max))))
6563 (if (looking-at vhdl-label-key)
6564 (progn
6565 (goto-char (match-end 0))
6566 (vhdl-forward-syntactic-ws lim)))
6567 ))
6568
6569(defun vhdl-get-syntactic-context ()
5eabfe72 6570 "Guess the syntactic description of the current line of VHDL code."
d2ddb974
KH
6571 (save-excursion
6572 (save-restriction
6573 (beginning-of-line)
6574 (let* ((indent-point (point))
6575 (case-fold-search t)
6576 vec literal containing-sexp preceding-sexp
6577 containing-begin containing-mid containing-leader
6578 char-before-ip char-after-ip begin-after-ip end-after-ip
6579 placeholder lim library-unit
6580 )
6581
6582 ;; Reset the syntactic context
6583 (setq vhdl-syntactic-context nil)
6584
6585 (save-excursion
6586 ;; Move to the start of the previous library unit, and
6587 ;; record the position of the "begin" keyword.
6588 (setq placeholder (vhdl-beginning-of-libunit))
6589 ;; The position of the "libunit" keyword gives us a gross
6590 ;; limit point.
6591 (setq lim (point))
6592 )
6593
6594 ;; If there is a previous library unit, and we are enclosed by
6595 ;; it, then set the syntax accordingly.
6596 (and placeholder
6597 (setq library-unit (vhdl-get-library-unit lim placeholder))
6598 (vhdl-add-syntax library-unit lim))
6599
6600 ;; Find the surrounding state.
6601 (if (setq vec (vhdl-get-block-state lim))
6602 (progn
6603 (setq containing-sexp (aref vec 0))
6604 (setq preceding-sexp (aref vec 1))
6605 (setq containing-begin (aref vec 2))
6606 (setq containing-mid (aref vec 3))
6607 ))
6608
6609 ;; set the limit on the farthest back we need to search
6610 (setq lim (if containing-sexp
6611 (save-excursion
6612 (goto-char containing-sexp)
6613 ;; set containing-leader if required
6614 (if (looking-at vhdl-leader-re)
6615 (setq containing-leader (vhdl-end-of-leader)))
6616 (vhdl-point 'bol))
6617 (point-min)))
6618
6619 ;; cache char before and after indent point, and move point to
6620 ;; the most likely position to perform the majority of tests
6621 (goto-char indent-point)
6622 (skip-chars-forward " \t")
3dcb36b7 6623 (setq literal (vhdl-in-literal))
d2ddb974
KH
6624 (setq char-after-ip (following-char))
6625 (setq begin-after-ip (and
6626 (not literal)
6627 (looking-at vhdl-begin-fwd-re)
6628 (vhdl-begin-p)))
6629 (setq end-after-ip (and
6630 (not literal)
6631 (looking-at vhdl-end-fwd-re)
6632 (vhdl-end-p)))
6633 (vhdl-backward-syntactic-ws lim)
6634 (setq char-before-ip (preceding-char))
6635 (goto-char indent-point)
6636 (skip-chars-forward " \t")
6637
6638 ;; now figure out syntactic qualities of the current line
6639 (cond
6640 ;; CASE 1: in a string or comment.
6641 ((memq literal '(string comment))
6642 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6643 ;; CASE 2: Line is at top level.
6644 ((null containing-sexp)
6645 ;; Find the point to which indentation will be relative
6646 (save-excursion
6647 (if (null preceding-sexp)
6648 ;; CASE 2X.1
6649 ;; no preceding-sexp -> use the preceding statement
6650 (vhdl-beginning-of-statement-1 lim)
6651 ;; CASE 2X.2
6652 ;; if there is a preceding-sexp then indent relative to it
6653 (goto-char preceding-sexp)
6654 ;; if not at boi, then the block-opening keyword is
6655 ;; probably following a label, so we need a different
6656 ;; relpos
6657 (if (/= (point) (vhdl-point 'boi))
6658 ;; CASE 2X.3
6659 (vhdl-beginning-of-statement-1 lim)))
6660 ;; v-b-o-s could have left us at point-min
6661 (and (bobp)
6662 ;; CASE 2X.4
6663 (vhdl-forward-syntactic-ws indent-point))
6664 (setq placeholder (point)))
6665 (cond
6666 ;; CASE 2A : we are looking at a block-open
6667 (begin-after-ip
6668 (vhdl-add-syntax 'block-open placeholder))
6669 ;; CASE 2B: we are looking at a block-close
6670 (end-after-ip
6671 (vhdl-add-syntax 'block-close placeholder))
6672 ;; CASE 2C: we are looking at a top-level statement
6673 ((progn
6674 (vhdl-backward-syntactic-ws lim)
6675 (or (bobp)
6676 (= (preceding-char) ?\;)))
6677 (vhdl-add-syntax 'statement placeholder))
6678 ;; CASE 2D: we are looking at a top-level statement-cont
6679 (t
6680 (vhdl-beginning-of-statement-1 lim)
6681 ;; v-b-o-s could have left us at point-min
6682 (and (bobp)
6683 ;; CASE 2D.1
6684 (vhdl-forward-syntactic-ws indent-point))
6685 (vhdl-add-syntax 'statement-cont (point)))
6686 )) ; end CASE 2
6687 ;; CASE 3: line is inside parentheses. Most likely we are
6688 ;; either in a subprogram argument (interface) list, or a
6689 ;; continued expression containing parentheses.
6690 ((null containing-begin)
6691 (vhdl-backward-syntactic-ws containing-sexp)
6692 (cond
6693 ;; CASE 3A: we are looking at the arglist closing paren
6694 ((eq char-after-ip ?\))
6695 (goto-char containing-sexp)
6696 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6697 ;; CASE 3B: we are looking at the first argument in an empty
6698 ;; argument list.
6699 ((eq char-before-ip ?\()
6700 (goto-char containing-sexp)
6701 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6702 ;; CASE 3C: we are looking at an arglist continuation line,
6703 ;; but the preceding argument is on the same line as the
6704 ;; opening paren. This case includes multi-line
6705 ;; expression paren groupings.
6706 ((and (save-excursion
6707 (goto-char (1+ containing-sexp))
6708 (skip-chars-forward " \t")
6709 (not (eolp))
6710 (not (looking-at "--")))
6711 (save-excursion
6712 (vhdl-beginning-of-statement-1 containing-sexp)
6713 (skip-chars-backward " \t(")
6714 (<= (point) containing-sexp)))
6715 (goto-char containing-sexp)
6716 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6717 ;; CASE 3D: we are looking at just a normal arglist
6718 ;; continuation line
6719 (t (vhdl-beginning-of-statement-1 containing-sexp)
6720 (vhdl-forward-syntactic-ws indent-point)
6721 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6722 ))
6723 ;; CASE 4: A block mid open
6724 ((and begin-after-ip
6725 (looking-at containing-mid))
6726 (goto-char containing-sexp)
6727 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6728 (if (looking-at vhdl-trailer-re)
6729 ;; CASE 4.1
6730 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6731 (vhdl-backward-skip-label (vhdl-point 'boi))
6732 (vhdl-add-syntax 'block-open (point)))
6733 ;; CASE 5: block close brace
6734 (end-after-ip
6735 (goto-char containing-sexp)
6736 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6737 (if (looking-at vhdl-trailer-re)
6738 ;; CASE 5.1
6739 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6740 (vhdl-backward-skip-label (vhdl-point 'boi))
6741 (vhdl-add-syntax 'block-close (point)))
6742 ;; CASE 6: A continued statement
6743 ((and (/= char-before-ip ?\;)
6744 ;; check it's not a trailer begin keyword, or a begin
6745 ;; keyword immediately following a label.
6746 (not (and begin-after-ip
6747 (or (looking-at vhdl-trailer-re)
6748 (save-excursion
6749 (vhdl-backward-skip-label containing-sexp)))))
6750 ;; check it's not a statement keyword
6751 (not (and (looking-at vhdl-statement-fwd-re)
6752 (vhdl-statement-p)))
6753 ;; see if the b-o-s is before the indent point
6754 (> indent-point
6755 (save-excursion
6756 (vhdl-beginning-of-statement-1 containing-sexp)
6757 ;; If we ended up after a leader, then this will
6758 ;; move us forward to the start of the first
6759 ;; statement. Note that a containing sexp here is
6760 ;; always a keyword, not a paren, so this will
6761 ;; have no effect if we hit the containing-sexp.
6762 (vhdl-forward-syntactic-ws indent-point)
6763 (setq placeholder (point))))
6764 ;; check it's not a block-intro
6765 (/= placeholder containing-sexp)
6766 ;; check it's not a case block-intro
6767 (save-excursion
6768 (goto-char placeholder)
6769 (or (not (looking-at vhdl-case-alternative-re))
6770 (> (match-end 0) indent-point))))
6771 ;; Make placeholder skip a label, but only if it puts us
6772 ;; before the indent point at the start of a line.
6773 (let ((new placeholder))
6774 (if (and (> indent-point
6775 (save-excursion
6776 (goto-char placeholder)
6777 (vhdl-forward-skip-label indent-point)
6778 (setq new (point))))
6779 (save-excursion
6780 (goto-char new)
6781 (eq new (progn (back-to-indentation) (point)))))
6782 (setq placeholder new)))
6783 (vhdl-add-syntax 'statement-cont placeholder)
6784 (if begin-after-ip
6785 (vhdl-add-syntax 'block-open)))
6786 ;; Statement. But what kind?
6787 ;; CASE 7: A case alternative key
6788 ((and (looking-at vhdl-case-alternative-re)
6789 (vhdl-case-alternative-p containing-sexp))
6790 ;; for a case alternative key, we set relpos to the first
6791 ;; non-whitespace char on the line containing the "case"
6792 ;; keyword.
6793 (goto-char containing-sexp)
6794 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6795 (if (looking-at vhdl-trailer-re)
6796 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6797 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6798 ;; CASE 8: statement catchall
6799 (t
6800 ;; we know its a statement, but we need to find out if it is
6801 ;; the first statement in a block
6802 (if containing-leader
6803 (goto-char containing-leader)
6804 (goto-char containing-sexp)
6805 ;; Note that a containing sexp here is always a keyword,
6806 ;; not a paren, so skip over the keyword.
6807 (forward-sexp))
6808 ;; move to the start of the first statement
6809 (vhdl-forward-syntactic-ws indent-point)
6810 (setq placeholder (point))
6811 ;; we want to ignore case alternatives keys when skipping forward
6812 (let (incase-p)
6813 (while (looking-at vhdl-case-alternative-re)
6814 (setq incase-p (point))
6815 ;; we also want to skip over the body of the
6816 ;; case/when statement if that doesn't put us at
6817 ;; after the indent-point
6818 (while (vhdl-skip-case-alternative indent-point))
6819 ;; set up the match end
6820 (looking-at vhdl-case-alternative-re)
6821 (goto-char (match-end 0))
6822 ;; move to the start of the first case alternative statement
6823 (vhdl-forward-syntactic-ws indent-point)
6824 (setq placeholder (point)))
6825 (cond
6826 ;; CASE 8A: we saw a case/when statement so we must be
6827 ;; in a switch statement. find out if we are at the
6828 ;; statement just after a case alternative key
6829 ((and incase-p
6830 (= (point) indent-point))
6831 ;; relpos is the "when" keyword
6832 (vhdl-add-syntax 'statement-case-intro incase-p))
6833 ;; CASE 8B: any old statement
6834 ((< (point) indent-point)
6835 ;; relpos is the first statement of the block
6836 (vhdl-add-syntax 'statement placeholder)
6837 (if begin-after-ip
6838 (vhdl-add-syntax 'block-open)))
6839 ;; CASE 8C: first statement in a block
6840 (t
6841 (goto-char containing-sexp)
6842 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6843 (if (looking-at vhdl-trailer-re)
6844 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6845 (vhdl-backward-skip-label (vhdl-point 'boi))
6846 (vhdl-add-syntax 'statement-block-intro (point))
6847 (if begin-after-ip
6848 (vhdl-add-syntax 'block-open)))
6849 )))
6850 )
6851
6852 ;; now we need to look at any modifiers
6853 (goto-char indent-point)
6854 (skip-chars-forward " \t")
6855 (if (looking-at "--")
6856 (vhdl-add-syntax 'comment))
0a2e512a
RF
6857 (if (eq literal 'pound)
6858 (vhdl-add-syntax 'cpp-macro))
d2ddb974
KH
6859 ;; return the syntax
6860 vhdl-syntactic-context))))
6861
6862;; Standard indentation line-ups:
6863
6864(defun vhdl-lineup-arglist (langelem)
5eabfe72
KH
6865 "Lineup the current arglist line with the arglist appearing just
6866after the containing paren which starts the arglist."
d2ddb974
KH
6867 (save-excursion
6868 (let* ((containing-sexp
6869 (save-excursion
6870 ;; arglist-cont-nonempty gives relpos ==
6871 ;; to boi of containing-sexp paren. This
6872 ;; is good when offset is +, but bad
6873 ;; when it is vhdl-lineup-arglist, so we
6874 ;; have to special case a kludge here.
6875 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6876 (progn
6877 (beginning-of-line)
6878 (backward-up-list 1)
6879 (skip-chars-forward " \t" (vhdl-point 'eol)))
6880 (goto-char (cdr langelem)))
6881 (point)))
6882 (cs-curcol (save-excursion
6883 (goto-char (cdr langelem))
6884 (current-column))))
6885 (if (save-excursion
6886 (beginning-of-line)
6887 (looking-at "[ \t]*)"))
6888 (progn (goto-char (match-end 0))
6889 (backward-sexp)
6890 (forward-char)
6891 (vhdl-forward-syntactic-ws)
6892 (- (current-column) cs-curcol))
6893 (goto-char containing-sexp)
6894 (or (eolp)
6895 (let ((eol (vhdl-point 'eol))
6896 (here (progn
6897 (forward-char)
6898 (skip-chars-forward " \t")
6899 (point))))
6900 (vhdl-forward-syntactic-ws)
6901 (if (< (point) eol)
6902 (goto-char here))))
6903 (- (current-column) cs-curcol)
6904 ))))
6905
6906(defun vhdl-lineup-arglist-intro (langelem)
5eabfe72 6907 "Lineup an arglist-intro line to just after the open paren."
d2ddb974
KH
6908 (save-excursion
6909 (let ((cs-curcol (save-excursion
6910 (goto-char (cdr langelem))
6911 (current-column)))
6912 (ce-curcol (save-excursion
6913 (beginning-of-line)
6914 (backward-up-list 1)
6915 (skip-chars-forward " \t" (vhdl-point 'eol))
6916 (current-column))))
6917 (- ce-curcol cs-curcol -1))))
6918
6919(defun vhdl-lineup-comment (langelem)
5eabfe72
KH
6920 "Support old behavior for comment indentation. We look at
6921vhdl-comment-only-line-offset to decide how to indent comment
6922only-lines."
d2ddb974
KH
6923 (save-excursion
6924 (back-to-indentation)
6925 ;; at or to the right of comment-column
6926 (if (>= (current-column) comment-column)
6927 (vhdl-comment-indent)
6928 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6929 (if (not (bolp))
6930 (or (car-safe vhdl-comment-only-line-offset)
6931 vhdl-comment-only-line-offset)
6932 (or (cdr-safe vhdl-comment-only-line-offset)
6933 (car-safe vhdl-comment-only-line-offset)
0a2e512a 6934 -1000 ;jam it against the left side
d2ddb974
KH
6935 )))))
6936
6937(defun vhdl-lineup-statement-cont (langelem)
5eabfe72 6938 "Line up statement-cont after the assignment operator."
d2ddb974
KH
6939 (save-excursion
6940 (let* ((relpos (cdr langelem))
6941 (assignp (save-excursion
6942 (goto-char (vhdl-point 'boi))
6943 (and (re-search-forward "\\(<\\|:\\)="
6944 (vhdl-point 'eol) t)
6945 (- (point) (vhdl-point 'boi)))))
6946 (curcol (progn
6947 (goto-char relpos)
6948 (current-column)))
6949 foundp)
6950 (while (and (not foundp)
6951 (< (point) (vhdl-point 'eol)))
6952 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
3dcb36b7 6953 (if (vhdl-in-literal)
d2ddb974
KH
6954 (forward-char)
6955 (if (= (preceding-char) ?\()
6956 ;; skip over any parenthesized expressions
6957 (goto-char (min (vhdl-point 'eol)
6958 (scan-lists (point) 1 1)))
6959 ;; found an assignment operator (not at eol)
6960 (setq foundp (not (looking-at "\\s-*$"))))))
6961 (if (not foundp)
6962 ;; there's no assignment operator on the line
6963 vhdl-basic-offset
6964 ;; calculate indentation column after assign and ws, unless
6965 ;; our line contains an assignment operator
6966 (if (not assignp)
6967 (progn
6968 (forward-char)
6969 (skip-chars-forward " \t")
6970 (setq assignp 0)))
6971 (- (current-column) assignp curcol))
6972 )))
6973
5eabfe72 6974;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 6975;; Progress reporting
d2ddb974 6976
3dcb36b7
JB
6977(defvar vhdl-progress-info nil
6978 "Array variable for progress information: 0 begin, 1 end, 2 time.")
5eabfe72 6979
3dcb36b7
JB
6980(defun vhdl-update-progress-info (string pos)
6981 "Update progress information."
6982 (when (and vhdl-progress-info (not noninteractive)
6983 (< vhdl-progress-interval
6984 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6985 (message (concat string "... (%2d%s)")
6986 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6987 (- (aref vhdl-progress-info 1)
6988 (aref vhdl-progress-info 0))) "%")
6989 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
5eabfe72 6990
3dcb36b7
JB
6991;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6992;; Indentation commands
5eabfe72
KH
6993
6994(defun vhdl-electric-tab (&optional prefix-arg)
6995 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7
JB
6996else if right of non whitespace on line then insert tab,
6997else if last command was a tab or return then dedent one step or if a comment
6998toggle between normal indent and inline comment indent,
d2ddb974
KH
6999else indent `correctly'."
7000 (interactive "*P")
3dcb36b7
JB
7001 (vhdl-prepare-search-2
7002 (cond
7003 ;; expand word
7004 ((= (char-syntax (preceding-char)) ?w)
7005 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7006 (case-replace nil)
7007 (hippie-expand-only-buffers
7008 (or (and (boundp 'hippie-expand-only-buffers)
7009 hippie-expand-only-buffers)
7010 '(vhdl-mode))))
7011 (vhdl-expand-abbrev prefix-arg)))
7012 ;; expand parenthesis
7013 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
7014 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
7015 (case-replace nil))
7016 (vhdl-expand-paren prefix-arg)))
7017 ;; insert tab
7018 ((> (current-column) (current-indentation))
7019 (insert-tab))
7020 ;; toggle comment indent
7021 ((and (looking-at "--")
7022 (or (eq last-command 'vhdl-electric-tab)
7023 (eq last-command 'vhdl-electric-return)))
7024 (cond ((= (current-indentation) 0) ; no indent
7025 (indent-to 1)
7026 (indent-according-to-mode))
7027 ((< (current-indentation) comment-column) ; normal indent
7028 (indent-to comment-column)
7029 (indent-according-to-mode))
7030 (t ; inline comment indent
7031 (kill-line -0))))
7032 ;; dedent
7033 ((and (>= (current-indentation) vhdl-basic-offset)
7034 (or (eq last-command 'vhdl-electric-tab)
7035 (eq last-command 'vhdl-electric-return)))
7036 (backward-delete-char-untabify vhdl-basic-offset nil))
7037 ;; indent line
7038 (t (indent-according-to-mode)))
5eabfe72
KH
7039 (setq this-command 'vhdl-electric-tab)))
7040
7041(defun vhdl-electric-return ()
d2ddb974
KH
7042 "newline-and-indent or indent-new-comment-line if in comment and preceding
7043character is a space."
7044 (interactive)
7045 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
7046 (indent-new-comment-line)
3dcb36b7
JB
7047 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
7048 (vhdl-fix-case-word -1))
5eabfe72
KH
7049 (newline-and-indent)))
7050
d2ddb974 7051(defun vhdl-indent-line ()
5eabfe72 7052 "Indent the current line as VHDL code. Returns the amount of
d2ddb974
KH
7053indentation change."
7054 (interactive)
3dcb36b7 7055 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
d2ddb974 7056 (pos (- (point-max) (point)))
3dcb36b7
JB
7057 (indent
7058 (if syntax
7059 ;; indent syntax-based
7060 (if (and (eq (caar syntax) 'comment)
7061 (>= (vhdl-get-offset (car syntax)) comment-column))
7062 ;; special case: comments at or right of comment-column
7063 (vhdl-get-offset (car syntax))
7064 (apply '+ (mapcar 'vhdl-get-offset syntax)))
7065 ;; indent like previous nonblank line
7066 (save-excursion (beginning-of-line)
7067 (re-search-backward "^[^\n]" nil t)
7068 (current-indentation))))
5eabfe72 7069 (shift-amt (- indent (current-indentation))))
d2ddb974
KH
7070 (and vhdl-echo-syntactic-information-p
7071 (message "syntax: %s, indent= %d" syntax indent))
5eabfe72 7072 (unless (zerop shift-amt)
d2ddb974
KH
7073 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
7074 (beginning-of-line)
7075 (indent-to indent))
7076 (if (< (point) (vhdl-point 'boi))
7077 (back-to-indentation)
7078 ;; If initial point was within line's indentation, position after
7079 ;; the indentation. Else stay at same point in text.
5eabfe72
KH
7080 (when (> (- (point-max) pos) (point))
7081 (goto-char (- (point-max) pos))))
d2ddb974 7082 (run-hooks 'vhdl-special-indent-hook)
3dcb36b7 7083 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
d2ddb974
KH
7084 shift-amt))
7085
3dcb36b7 7086(defun vhdl-indent-region (beg end column)
5eabfe72
KH
7087 "Indent region as VHDL code.
7088Adds progress reporting to `indent-region'."
7089 (interactive "r\nP")
3dcb36b7
JB
7090 (when vhdl-progress-interval
7091 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7092 (count-lines (point-min) end) 0)))
7093 (indent-region beg end column)
5eabfe72
KH
7094 (when vhdl-progress-interval (message "Indenting...done"))
7095 (setq vhdl-progress-info nil))
d2ddb974 7096
3dcb36b7
JB
7097(defun vhdl-indent-buffer ()
7098 "Indent whole buffer as VHDL code.
7099Calls `indent-region' for whole buffer and adds progress reporting."
7100 (interactive)
7101 (vhdl-indent-region (point-min) (point-max) nil))
7102
7103(defun vhdl-indent-group ()
7104 "Indent group of lines between empty lines."
7105 (interactive)
7106 (let ((beg (save-excursion
7107 (if (re-search-backward vhdl-align-group-separate nil t)
7108 (point-marker)
7109 (point-min-marker))))
7110 (end (save-excursion
7111 (if (re-search-forward vhdl-align-group-separate nil t)
7112 (point-marker)
7113 (point-max-marker)))))
7114 (vhdl-indent-region beg end nil)))
7115
d2ddb974
KH
7116(defun vhdl-indent-sexp (&optional endpos)
7117 "Indent each line of the list starting just after point.
7118If optional arg ENDPOS is given, indent each line, stopping when
7119ENDPOS is encountered."
7120 (interactive)
7121 (save-excursion
7122 (let ((beg (point))
5eabfe72 7123 (end (progn (vhdl-forward-sexp nil endpos) (point))))
d2ddb974
KH
7124 (indent-region beg end nil))))
7125
5eabfe72 7126;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
7127;; Miscellaneous commands
7128
7129(defun vhdl-show-syntactic-information ()
7130 "Show syntactic information for current line."
7131 (interactive)
3dcb36b7 7132 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
d2ddb974
KH
7133 (vhdl-keep-region-active))
7134
7135;; Verification and regression functions:
7136
7137(defun vhdl-regress-line (&optional arg)
7138 "Check syntactic information for current line."
7139 (interactive "P")
7140 (let ((expected (save-excursion
7141 (end-of-line)
5eabfe72
KH
7142 (when (search-backward " -- ((" (vhdl-point 'bol) t)
7143 (forward-char 4)
7144 (read (current-buffer)))))
d2ddb974
KH
7145 (actual (vhdl-get-syntactic-context))
7146 (expurgated))
7147 ;; remove the library unit symbols
7148 (mapcar
7149 (function
7150 (lambda (elt)
7151 (if (memq (car elt) '(entity configuration package
7152 package-body architecture))
7153 nil
7154 (setq expurgated (append expurgated (list elt))))))
7155 actual)
7156 (if (and (not arg) expected (listp expected))
7157 (if (not (equal expected expurgated))
3dcb36b7 7158 (error "ERROR: Should be: %s, is: %s" expected expurgated))
d2ddb974
KH
7159 (save-excursion
7160 (beginning-of-line)
5eabfe72
KH
7161 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7162 (end-of-line)
7163 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7164 (kill-line))
7165 (insert " -- ")
7166 (insert (format "%s" expurgated))))))
d2ddb974
KH
7167 (vhdl-keep-region-active))
7168
7169
5eabfe72
KH
7170;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7171;;; Alignment, whitespace fixup, beautifying
7172;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7173
3dcb36b7 7174(defconst vhdl-align-alist
d2ddb974
KH
7175 '(
7176 ;; after some keywords
3dcb36b7
JB
7177 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7178 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
d2ddb974 7179 ;; before ':'
5eabfe72 7180 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
d2ddb974 7181 ;; after direction specifications
5eabfe72
KH
7182 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7183 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7184 ;; before "==", ":=", "=>", and "<="
3dcb36b7 7185 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
5eabfe72 7186 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
3dcb36b7 7187 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
d2ddb974
KH
7188 ;; before some keywords
7189 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
d2ddb974
KH
7190 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7191 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
3dcb36b7
JB
7192 ;; before "=>" since "when/else ... =>" can occur
7193 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
d2ddb974 7194 )
5eabfe72 7195 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
d2ddb974
KH
7196It is searched in order. If REGEXP is found anywhere in the first
7197line of a region to be aligned, ALIGN-PATTERN will be used for that
7198region. ALIGN-PATTERN must include the whitespace to be expanded or
5eabfe72
KH
7199contracted. It may also provide regexps for the text surrounding the
7200whitespace. SUBEXP specifies which sub-expression of
d2ddb974
KH
7201ALIGN-PATTERN matches the white space to be expanded/contracted.")
7202
3dcb36b7
JB
7203;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7204;; Align code
7205
d2ddb974
KH
7206(defvar vhdl-align-try-all-clauses t
7207 "If REGEXP is not found on the first line of the region that clause
5eabfe72 7208is ignored. If this variable is non-nil, then the clause is tried anyway.")
d2ddb974 7209
3dcb36b7
JB
7210(defun vhdl-do-group (function &optional spacing)
7211 "Apply FUNCTION on group of lines between empty lines."
7212 (let
7213 ;; search for group beginning
7214 ((beg (save-excursion
7215 (if (re-search-backward vhdl-align-group-separate nil t)
7216 (progn (beginning-of-line 2) (back-to-indentation) (point))
7217 (point-min))))
7218 ;; search for group end
7219 (end (save-excursion
7220 (if (re-search-forward vhdl-align-group-separate nil t)
7221 (progn (beginning-of-line) (point))
7222 (point-max)))))
7223 ;; run FUNCTION
7224 (funcall function beg end spacing)))
7225
7226(defun vhdl-do-list (function &optional spacing)
7227 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7228parentheses."
7229 (let (beg end)
7230 (save-excursion
7231 ;; search for beginning of balanced group of parentheses
7232 (setq beg (vhdl-re-search-backward "[()]" nil t))
7233 (while (looking-at ")")
7234 (forward-char) (backward-sexp)
7235 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7236 ;; search for end of balanced group of parentheses
7237 (when beg
7238 (forward-list)
7239 (setq end (point))
7240 (goto-char (1+ beg))
7241 (skip-chars-forward " \t\n")
7242 (setq beg (point))))
7243 ;; run FUNCTION
7244 (if beg
7245 (funcall function beg end spacing)
7246 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7247
7248(defun vhdl-do-same-indent (function &optional spacing)
7249 "Apply FUNCTION to block of lines with same indent."
7250 (let ((indent (current-indentation))
7251 beg end)
7252 ;; search for first line with same indent
7253 (save-excursion
7254 (while (and (not (bobp))
7255 (or (looking-at "^\\s-*\\(--.*\\)?$")
7256 (= (current-indentation) indent)))
7257 (unless (looking-at "^\\s-*$")
7258 (back-to-indentation) (setq beg (point)))
7259 (beginning-of-line -0)))
7260 ;; search for last line with same indent
7261 (save-excursion
7262 (while (and (not (eobp))
7263 (or (looking-at "^\\s-*\\(--.*\\)?$")
7264 (= (current-indentation) indent)))
7265 (if (looking-at "^\\s-*$")
7266 (beginning-of-line 2)
7267 (beginning-of-line 2)
7268 (setq end (point)))))
7269 ;; run FUNCTION
7270 (funcall function beg end spacing)))
7271
7272(defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
d2ddb974 7273 "Attempt to align a range of lines based on the content of the
5eabfe72
KH
7274lines. The definition of `alignment-list' determines the matching
7275order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7276is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
d2ddb974
KH
7277indentation is done before aligning."
7278 (interactive "r\np")
5eabfe72
KH
7279 (setq alignment-list (or alignment-list vhdl-align-alist))
7280 (setq spacing (or spacing 1))
d2ddb974
KH
7281 (save-excursion
7282 (let (bol indent)
7283 (goto-char end)
7284 (setq end (point-marker))
7285 (goto-char begin)
5eabfe72 7286 (setq bol (setq begin (progn (beginning-of-line) (point))))
3dcb36b7 7287; (untabify bol end)
5eabfe72
KH
7288 (when indent
7289 (indent-region bol end nil))))
3dcb36b7
JB
7290 (let ((copy (copy-alist alignment-list)))
7291 (vhdl-prepare-search-2
5eabfe72
KH
7292 (while copy
7293 (save-excursion
7294 (goto-char begin)
7295 (let (element
7296 (eol (save-excursion (progn (end-of-line) (point)))))
7297 (setq element (nth 0 copy))
7298 (when (and (or (and (listp (car element))
7299 (memq major-mode (car element)))
7300 (eq major-mode (car element)))
7301 (or vhdl-align-try-all-clauses
7302 (re-search-forward (car (cdr element)) eol t)))
3dcb36b7 7303 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
5eabfe72
KH
7304 (car (cdr (cdr (cdr element)))) spacing))
7305 (setq copy (cdr copy))))))))
7306
3dcb36b7 7307(defun vhdl-align-region-2 (begin end match &optional substr spacing)
d2ddb974
KH
7308 "Align a range of lines from BEGIN to END. The regular expression
7309MATCH must match exactly one fields: the whitespace to be
7310contracted/expanded. The alignment column will equal the
7311rightmost column of the widest whitespace block. SPACING is
7312the amount of extra spaces to add to the calculated maximum required.
7313SPACING defaults to 1 so that at least one space is inserted after
7314the token in MATCH."
5eabfe72
KH
7315 (setq spacing (or spacing 1))
7316 (setq substr (or substr 1))
d2ddb974
KH
7317 (save-excursion
7318 (let (distance (max 0) (lines 0) bol eol width)
7319 ;; Determine the greatest whitespace distance to the alignment
7320 ;; character
7321 (goto-char begin)
7322 (setq eol (progn (end-of-line) (point))
5eabfe72 7323 bol (setq begin (progn (beginning-of-line) (point))))
d2ddb974 7324 (while (< bol end)
5eabfe72
KH
7325 (save-excursion
7326 (when (and (re-search-forward match eol t)
3dcb36b7 7327 (not (vhdl-in-literal)))
5eabfe72
KH
7328 (setq distance (- (match-beginning substr) bol))
7329 (when (> distance max)
7330 (setq max distance))))
7331 (forward-line)
7332 (setq bol (point)
7333 eol (save-excursion (end-of-line) (point)))
7334 (setq lines (1+ lines)))
d2ddb974
KH
7335 ;; Now insert enough maxs to push each assignment operator to
7336 ;; the same column. We need to use 'lines' as a counter, since
7337 ;; the location of the mark may change
7338 (goto-char (setq bol begin))
5eabfe72 7339 (setq eol (save-excursion (end-of-line) (point)))
d2ddb974 7340 (while (> lines 0)
5eabfe72 7341 (when (and (re-search-forward match eol t)
3dcb36b7 7342 (not (vhdl-in-literal)))
5eabfe72
KH
7343 (setq width (- (match-end substr) (match-beginning substr)))
7344 (setq distance (- (match-beginning substr) bol))
7345 (goto-char (match-beginning substr))
7346 (delete-char width)
7347 (insert-char ? (+ (- max distance) spacing)))
7348 (beginning-of-line)
7349 (forward-line)
7350 (setq bol (point)
7351 eol (save-excursion (end-of-line) (point)))
7352 (setq lines (1- lines))))))
7353
3dcb36b7
JB
7354(defun vhdl-align-region-groups (beg end &optional spacing
7355 no-message no-comments)
7356 "Align region, treat groups of lines separately."
d2ddb974 7357 (interactive "r\nP")
5eabfe72 7358 (save-excursion
3dcb36b7 7359 (let (orig pos)
5eabfe72
KH
7360 (goto-char beg)
7361 (beginning-of-line)
3dcb36b7 7362 (setq orig (point-marker))
5eabfe72
KH
7363 (setq beg (point))
7364 (goto-char end)
7365 (setq end (point-marker))
7366 (untabify beg end)
3dcb36b7
JB
7367 (unless no-message
7368 (when vhdl-progress-interval
7369 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7370 (count-lines (point-min) end) 0))))
5eabfe72
KH
7371 (vhdl-fixup-whitespace-region beg end t)
7372 (goto-char beg)
7373 (if (not vhdl-align-groups)
7374 ;; align entire region
3dcb36b7
JB
7375 (progn (vhdl-align-region-1 beg end spacing)
7376 (unless no-comments
7377 (vhdl-align-inline-comment-region-1 beg end)))
5eabfe72
KH
7378 ;; align groups
7379 (while (and (< beg end)
3dcb36b7 7380 (re-search-forward vhdl-align-group-separate end t))
5eabfe72 7381 (setq pos (point-marker))
3dcb36b7
JB
7382 (vhdl-align-region-1 beg pos spacing)
7383 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7384 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
5eabfe72
KH
7385 (setq beg (1+ pos))
7386 (goto-char beg))
7387 ;; align last group
7388 (when (< beg end)
3dcb36b7
JB
7389 (vhdl-align-region-1 beg end spacing)
7390 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7391 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7392 (when vhdl-indent-tabs-mode
7393 (tabify orig end))
7394 (unless no-message
7395 (when vhdl-progress-interval (message "Aligning...done"))
7396 (setq vhdl-progress-info nil)))))
7397
7398(defun vhdl-align-region (beg end &optional spacing)
7399 "Align region, treat blocks with same indent and argument lists separately."
7400 (interactive "r\nP")
7401 (if (not vhdl-align-same-indent)
7402 ;; align entire region
7403 (vhdl-align-region-groups beg end spacing)
7404 ;; align blocks with same indent and argument lists
7405 (save-excursion
7406 (let ((cur-beg beg)
7407 indent cur-end)
7408 (when vhdl-progress-interval
7409 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7410 (count-lines (point-min) end) 0)))
7411 (goto-char end)
7412 (setq end (point-marker))
7413 (goto-char cur-beg)
7414 (while (< (point) end)
7415 ;; is argument list opening?
7416 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7417 (point) (vhdl-point 'eol)))))
7418 ;; determine region for argument list
7419 (progn (goto-char cur-beg)
7420 (forward-sexp)
7421 (setq cur-end (point))
7422 (beginning-of-line 2))
7423 ;; determine region with same indent
7424 (setq indent (current-indentation))
7425 (setq cur-beg (point))
7426 (setq cur-end (vhdl-point 'bonl))
7427 (beginning-of-line 2)
7428 (while (and (< (point) end)
7429 (or (looking-at "^\\s-*\\(--.*\\)?$")
7430 (= (current-indentation) indent))
7431 (<= (save-excursion
7432 (nth 0 (parse-partial-sexp
7433 (point) (vhdl-point 'eol)))) 0))
7434 (unless (looking-at "^\\s-*$")
7435 (setq cur-end (vhdl-point 'bonl)))
7436 (beginning-of-line 2)))
7437 ;; align region
7438 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7439 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7440 (when vhdl-progress-interval (message "Aligning...done"))
7441 (setq vhdl-progress-info nil)))))
5eabfe72
KH
7442
7443(defun vhdl-align-group (&optional spacing)
7444 "Align group of lines between empty lines."
7445 (interactive)
3dcb36b7 7446 (vhdl-do-group 'vhdl-align-region spacing))
5eabfe72 7447
3dcb36b7
JB
7448(defun vhdl-align-list (&optional spacing)
7449 "Align the lines of a list surrounded by a balanced group of parentheses."
5eabfe72 7450 (interactive)
3dcb36b7
JB
7451 (vhdl-do-list 'vhdl-align-region-groups spacing))
7452
7453(defun vhdl-align-same-indent (&optional spacing)
7454 "Align block of lines with same indent."
7455 (interactive)
7456 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7457
7458(defun vhdl-align-declarations (&optional spacing)
7459 "Align the lines within the declarative part of a design unit."
7460 (interactive)
7461 (let (beg end)
7462 (vhdl-prepare-search-2
7463 (save-excursion
7464 ;; search for declarative part
7465 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7466 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7467 (setq beg (point))
7468 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7469 (setq end (point)))))
7470 (if beg
7471 (vhdl-align-region-groups beg end spacing)
7472 (error "ERROR: Not within the declarative part of a design unit"))))
7473
7474(defun vhdl-align-buffer ()
7475 "Align buffer."
7476 (interactive)
7477 (vhdl-align-region (point-min) (point-max)))
7478
7479;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7480;; Align inline comments
7481
7482(defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7483 "Align inline comments in region."
7484 (save-excursion
7485 (let ((start-max comment-column)
7486 (length-max 0)
7487 comment-list start-list tmp-list start length
7488 cur-start prev-start no-code)
7489 (setq spacing (or spacing 2))
7490 (vhdl-prepare-search-2
7491 (goto-char beg)
7492 ;; search for comment start positions and lengths
7493 (while (< (point) end)
7494 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7495 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7496 (not (save-excursion (goto-char (match-beginning 2))
7497 (vhdl-in-literal))))
7498 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7499 (setq length (- (match-end 2) (match-beginning 2)))
7500 (setq start-max (max start start-max))
7501 (setq length-max (max length length-max))
7502 (setq comment-list (cons (cons start length) comment-list)))
7503 (beginning-of-line 2))
7504 (setq comment-list
7505 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7506 ;; reduce start positions
7507 (setq start-list (list (caar comment-list)))
7508 (setq comment-list (cdr comment-list))
7509 (while comment-list
7510 (unless (or (= (caar comment-list) (car start-list))
7511 (<= (+ (car start-list) (cdar comment-list))
7512 end-comment-column))
7513 (setq start-list (cons (caar comment-list) start-list)))
7514 (setq comment-list (cdr comment-list)))
7515 ;; align lines as nicely as possible
7516 (goto-char beg)
7517 (while (< (point) end)
7518 (setq cur-start nil)
7519 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7520 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7521 (not (save-excursion
7522 (goto-char (match-beginning 3))
7523 (vhdl-in-literal))))
7524 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7525 (>= (- (match-end 2) (match-beginning 2))
7526 comment-column))))
7527 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7528 (setq length (- (match-end 3) (match-beginning 3)))
7529 (setq no-code (= (match-beginning 1) (match-end 1)))
7530 ;; insert minimum whitespace
7531 (goto-char (match-end 2))
7532 (delete-region (match-beginning 2) (match-end 2))
7533 (insert-char ?\ spacing)
7534 (setq tmp-list start-list)
7535 ;; insert additional whitespace to align
7536 (setq cur-start
7537 (cond
7538 ;; align comment-only line to inline comment of previous line
7539 ((and no-code prev-start
7540 (<= length (- end-comment-column prev-start)))
7541 prev-start)
7542 ;; align all comments at `start-max' if this is possible
7543 ((<= (+ start-max length-max) end-comment-column)
7544 start-max)
7545 ;; align at `comment-column' if possible
7546 ((and (<= start comment-column)
7547 (<= length (- end-comment-column comment-column)))
7548 comment-column)
7549 ;; align at left-most possible start position otherwise
7550 (t
7551 (while (and tmp-list (< (car tmp-list) start))
7552 (setq tmp-list (cdr tmp-list)))
7553 (car tmp-list))))
7554 (indent-to cur-start))
7555 (setq prev-start cur-start)
7556 (beginning-of-line 2))))))
d2ddb974 7557
5eabfe72
KH
7558(defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7559 "Align inline comments within a region. Groups of code lines separated by
7560empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
d2ddb974 7561 (interactive "r\nP")
5eabfe72 7562 (save-excursion
3dcb36b7 7563 (let (orig pos)
5eabfe72
KH
7564 (goto-char beg)
7565 (beginning-of-line)
3dcb36b7 7566 (setq orig (point-marker))
5eabfe72
KH
7567 (setq beg (point))
7568 (goto-char end)
7569 (setq end (point-marker))
7570 (untabify beg end)
7571 (unless no-message (message "Aligning inline comments..."))
7572 (goto-char beg)
7573 (if (not vhdl-align-groups)
7574 ;; align entire region
7575 (vhdl-align-inline-comment-region-1 beg end spacing)
7576 ;; align groups
3dcb36b7
JB
7577 (while (and (< beg end)
7578 (re-search-forward vhdl-align-group-separate end t))
5eabfe72
KH
7579 (setq pos (point-marker))
7580 (vhdl-align-inline-comment-region-1 beg pos spacing)
7581 (setq beg (1+ pos))
7582 (goto-char beg))
7583 ;; align last group
7584 (when (< beg end)
3dcb36b7
JB
7585 (vhdl-align-inline-comment-region-1 beg end spacing)))
7586 (when vhdl-indent-tabs-mode
7587 (tabify orig end))
7588 (unless no-message (message "Aligning inline comments...done")))))
5eabfe72
KH
7589
7590(defun vhdl-align-inline-comment-group (&optional spacing)
7591 "Align inline comments within a group of lines between empty lines."
7592 (interactive)
7593 (save-excursion
7594 (let ((start (point))
7595 beg end)
3dcb36b7 7596 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
5eabfe72
KH
7597 (point-marker) (point-max)))
7598 (goto-char start)
3dcb36b7
JB
7599 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7600 (point) (point-min)))
5eabfe72
KH
7601 (untabify beg end)
7602 (message "Aligning inline comments...")
7603 (vhdl-align-inline-comment-region-1 beg end)
3dcb36b7
JB
7604 (when vhdl-indent-tabs-mode
7605 (tabify beg end))
5eabfe72
KH
7606 (message "Aligning inline comments...done"))))
7607
7608(defun vhdl-align-inline-comment-buffer ()
7609 "Align inline comments within buffer. Groups of code lines separated by
7610empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7611 (interactive)
7612 (vhdl-align-inline-comment-region (point-min) (point-max)))
7613
3dcb36b7
JB
7614;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7615;; Fixup whitespace
7616
5eabfe72
KH
7617(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7618 "Fixup whitespace in region. Surround operator symbols by one space,
7619eliminate multiple spaces (except at beginning of line), eliminate spaces at
3dcb36b7 7620end of line, do nothing in comments and strings."
5eabfe72
KH
7621 (interactive "r")
7622 (unless no-message (message "Fixing up whitespace..."))
7623 (save-excursion
7624 (goto-char end)
7625 (setq end (point-marker))
5eabfe72
KH
7626 ;; have no space before and one space after `,' and ';'
7627 (goto-char beg)
0a2e512a 7628 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
3dcb36b7
JB
7629 (if (match-string 1)
7630 (goto-char (match-end 1))
7631 (replace-match "\\3 " nil nil nil 3)))
7632 ;; have no space after `('
7633 (goto-char beg)
0a2e512a 7634 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
3dcb36b7
JB
7635 (if (match-string 1)
7636 (goto-char (match-end 1))
7637 (replace-match "\\2")))
7638 ;; have no space before `)'
7639 (goto-char beg)
0a2e512a 7640 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
3dcb36b7
JB
7641 (if (match-string 1)
7642 (goto-char (match-end 1))
7643 (replace-match "\\2")))
7644 ;; surround operator symbols by one space
7645 (goto-char beg)
0a2e512a 7646 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
3dcb36b7
JB
7647 (if (match-string 1)
7648 (goto-char (match-end 1))
0a2e512a
RF
7649 (replace-match "\\3 \\4 \\5")
7650 (goto-char (match-end 2))))
5eabfe72
KH
7651 ;; eliminate multiple spaces and spaces at end of line
7652 (goto-char beg)
7653 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
3dcb36b7 7654 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
5eabfe72
KH
7655 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7656 (progn (replace-match "" nil nil) t))
7657 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7658 (progn (replace-match ";" nil nil) t))
7659 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7660 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
3dcb36b7 7661 (progn (replace-match " " nil nil) t))
5eabfe72 7662 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
3dcb36b7 7663 (progn (replace-match " " nil nil) t))
0a2e512a
RF
7664; (re-search-forward "[^ \t-]+" end t))))
7665 (re-search-forward "[^ \t\"-]+" end t))))
5eabfe72
KH
7666 (unless no-message (message "Fixing up whitespace...done")))
7667
7668(defun vhdl-fixup-whitespace-buffer ()
7669 "Fixup whitespace in buffer. Surround operator symbols by one space,
7670eliminate multiple spaces (except at beginning of line), eliminate spaces at
7671end of line, do nothing in comments."
7672 (interactive)
7673 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7674
3dcb36b7
JB
7675;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7676;; Beautify
7677
5eabfe72
KH
7678(defun vhdl-beautify-region (beg end)
7679 "Beautify region by applying indentation, whitespace fixup, alignment, and
3dcb36b7
JB
7680case fixing to a region. Calls functions `vhdl-indent-buffer',
7681`vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
5eabfe72
KH
7682`vhdl-fix-case-buffer'."
7683 (interactive "r")
3dcb36b7 7684 (setq end (save-excursion (goto-char end) (point-marker)))
5eabfe72
KH
7685 (vhdl-indent-region beg end nil)
7686 (let ((vhdl-align-groups t))
3dcb36b7 7687 (vhdl-align-region beg end))
5eabfe72
KH
7688 (vhdl-fix-case-region beg end))
7689
7690(defun vhdl-beautify-buffer ()
7691 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7692case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7693buffer."
7694 (interactive)
3dcb36b7
JB
7695 (vhdl-beautify-region (point-min) (point-max))
7696 (when noninteractive (save-buffer)))
7697
7698;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7699;; Code filling
7700
7701(defun vhdl-fill-region (beg end &optional arg)
7702 "Fill lines for a region of code."
8d422bd5 7703 (interactive "r\np")
3dcb36b7
JB
7704 (save-excursion
7705 (goto-char beg)
f35aff82 7706 (let ((margin (if arg (current-indentation) (current-column))))
3dcb36b7
JB
7707 (goto-char end)
7708 (setq end (point-marker))
7709 ;; remove inline comments, newlines and whitespace
7710 (vhdl-comment-kill-region beg end)
7711 (vhdl-comment-kill-inline-region beg end)
7712 (subst-char-in-region beg (1- end) ?\n ?\ )
7713 (vhdl-fixup-whitespace-region beg end)
7714 ;; wrap and end-comment-column
7715 (goto-char beg)
7716 (while (re-search-forward "\\s-" end t)
7717 (when(> (current-column) vhdl-end-comment-column)
7718 (backward-char)
7719 (when (re-search-backward "\\s-" beg t)
7720 (replace-match "\n")
7721 (indent-to margin)))))))
7722
7723(defun vhdl-fill-group ()
7724 "Fill group of lines between empty lines."
7725 (interactive)
7726 (vhdl-do-group 'vhdl-fill-region))
7727
7728(defun vhdl-fill-list ()
7729 "Fill the lines of a list surrounded by a balanced group of parentheses."
7730 (interactive)
7731 (vhdl-do-list 'vhdl-fill-region))
7732
7733(defun vhdl-fill-same-indent ()
7734 "Fill the lines of block of lines with same indent."
7735 (interactive)
7736 (vhdl-do-same-indent 'vhdl-fill-region))
7737
7738
7739;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7740;;; Code updating/fixing
7741;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7742
7743;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7744;; Sensitivity list update
7745
7746;; Strategy:
7747;; - no sensitivity list is generated for processes with wait statements
7748;; - otherwise, do the following:
7749;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7750;; 2. scan for all signals already in the sensitivity list (in order to catch
7751;; manually entered global signals)
7752;; 3. signals from 1. and 2. form the list of visible signals
7753;; 4. search for if/elsif conditions containing an event (sequential code)
7754;; 5. scan for strings that are within syntactical regions where signals are
7755;; read but not within sequential code, and that correspond to visible
7756;; signals
7757;; 6. replace sensitivity list by list of signals from 5.
7758
7759(defun vhdl-update-sensitivity-list-process ()
7760 "Update sensitivity list of current process."
7761 (interactive)
7762 (save-excursion
7763 (vhdl-prepare-search-2
7764 (end-of-line)
7765 ;; look whether in process
7766 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7767 (equal (upcase (match-string 2)) "PROCESS")
7768 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7769 (error "ERROR: Not within a process")
7770 (message "Updating sensitivity list...")
7771 (vhdl-update-sensitivity-list)
7772 (message "Updating sensitivity list...done")))))
7773
7774(defun vhdl-update-sensitivity-list-buffer ()
7775 "Update sensitivity list of all processes in current buffer."
7776 (interactive)
7777 (save-excursion
7778 (vhdl-prepare-search-2
7779 (goto-char (point-min))
7780 (message "Updating sensitivity lists...")
7781 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7782 (goto-char (match-beginning 0))
0a2e512a 7783 (condition-case nil (vhdl-update-sensitivity-list) (error "")))
3dcb36b7
JB
7784 (message "Updating sensitivity lists...done"))))
7785
7786(defun vhdl-update-sensitivity-list ()
7787 "Update sensitivity list."
7788 (let ((proc-beg (point))
7789 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7790 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7791 seq-region-list)
7792 (cond
7793 ;; search for wait statement (no sensitivity list allowed)
7794 ((progn (goto-char proc-mid)
7795 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7796 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7797 ;; combinational process (update sensitivity list)
7798 (t
7799 (let
7800 ;; scan for visible signals
7801 ((visible-list (vhdl-get-visible-signals))
7802 ;; define syntactic regions where signals are read
7803 (scan-regions-list
7804 '(;; right-hand side of signal/variable assignment
7805 ;; (special case: "<=" is relational operator in a condition)
7806 ((re-search-forward "[<:]=" proc-end t)
7807 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7808 ;; if condition
7809 ((re-search-forward "^\\s-*if\\>" proc-end t)
7810 (re-search-forward "\\<then\\>" proc-end t))
7811 ;; elsif condition
7812 ((re-search-forward "\\<elsif\\>" proc-end t)
7813 (re-search-forward "\\<then\\>" proc-end t))
7814 ;; while loop condition
7815 ((re-search-forward "^\\s-*while\\>" proc-end t)
7816 (re-search-forward "\\<loop\\>" proc-end t))
7817 ;; exit/next condition
7818 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7819 (re-search-forward ";" proc-end t))
7820 ;; assert condition
7821 ((re-search-forward "\\<assert\\>" proc-end t)
7822 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7823 ;; case expression
7824 ((re-search-forward "^\\s-*case\\>" proc-end t)
7825 (re-search-forward "\\<is\\>" proc-end t))
7826 ;; parameter list of procedure call
0a2e512a
RF
7827 ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7828 (1- (point)))
7829 (progn (backward-char) (forward-sexp)
7830 (while (looking-at "(") (forward-sexp)) (point)))))
3dcb36b7
JB
7831 name read-list sens-list signal-list
7832 sens-beg sens-end beg end margin)
7833 ;; scan for signals in old sensitivity list
7834 (goto-char proc-beg)
7835 (re-search-forward "\\<process\\>" proc-mid t)
7836 (if (not (looking-at "[ \t\n]*("))
7837 (setq sens-beg (point))
7838 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7839 (goto-char (match-end 1))
7840 (forward-sexp)
7841 (setq sens-end (1- (point)))
7842 (goto-char sens-beg)
7843 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7844 (setq sens-list
7845 (cons (downcase (match-string 0)) sens-list))
7846 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7847 (setq signal-list (append visible-list sens-list))
7848 ;; search for sequential parts
7849 (goto-char proc-mid)
7850 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7851 (setq end (re-search-forward "\\<then\\>" proc-end t))
7852 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7853 (goto-char end)
7854 (backward-word 1)
7855 (vhdl-forward-sexp)
7856 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7857 (beginning-of-line)))
7858 ;; scan for signals read in process
7859 (while scan-regions-list
7860 (goto-char proc-mid)
7861 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7862 (setq end (eval (nth 1 (car scan-regions-list)))))
7863 (goto-char beg)
7864 (unless (or (vhdl-in-literal)
7865 (and seq-region-list
7866 (let ((tmp-list seq-region-list))
7867 (while (and tmp-list
7868 (< (point) (caar tmp-list)))
7869 (setq tmp-list (cdr tmp-list)))
7870 (and tmp-list (< (point) (cdar tmp-list))))))
0a2e512a 7871 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
3dcb36b7 7872 (setq name (match-string 1))
0a2e512a
RF
7873 (when (and (not (match-string 4)) ; not when formal parameter
7874 (not (and (match-string 3) ; not event attribute
7875 (not (member (downcase (match-string 3))
7876 '("event" "last_event" "transaction")))))
7877 (member (downcase name) signal-list))
7878 (unless (member-ignore-case name read-list)
7879 (setq read-list (cons name read-list))))
7880 (goto-char (match-end 1)))))
3dcb36b7
JB
7881 (setq scan-regions-list (cdr scan-regions-list)))
7882 ;; update sensitivity list
7883 (goto-char sens-beg)
7884 (if sens-end
7885 (delete-region sens-beg sens-end)
7886 (when read-list
7887 (insert " ()") (backward-char)))
7888 (setq read-list (sort read-list 'string<))
7889 (when read-list
7890 (setq margin (current-column))
7891 (insert (car read-list))
7892 (setq read-list (cdr read-list))
7893 (while read-list
7894 (insert ",")
7895 (if (<= (+ (current-column) (length (car read-list)) 2)
7896 end-comment-column)
7897 (insert " ")
7898 (insert "\n") (indent-to margin))
7899 (insert (car read-list))
7900 (setq read-list (cdr read-list)))))))))
7901
7902(defun vhdl-get-visible-signals ()
7903 "Get all signals visible in the current block."
0a2e512a
RF
7904 (let (beg end signal-list entity-name file-name)
7905 (vhdl-prepare-search-2
7906 ;; get entity name
7907 (save-excursion
7908 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
3dcb36b7 7909 (not (equal "END" (upcase (match-string 1))))
0a2e512a
RF
7910 (setq entity-name (match-string 2)))
7911 (error "ERROR: Not within an architecture")))
7912 ;; search for signals declared in entity port clause
7913 (save-excursion
7914 (goto-char (point-min))
7915 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7916 (setq file-name
7917 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
7918 "." (file-name-extension (buffer-file-name)))))
7919 (vhdl-visit-file
7920 file-name t
7921 (vhdl-prepare-search-2
7922 (goto-char (point-min))
7923 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7924 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7925 (when (setq beg (re-search-forward
7926 "^\\s-*port[ \t\n]*("
7927 (save-excursion
7928 (re-search-forward "^end\\>" nil t)) t))
7929 (setq end (save-excursion
7930 (backward-char) (forward-sexp) (point)))
7931 (vhdl-forward-syntactic-ws)
7932 (while (< (point) end)
7933 (when (looking-at "signal[ \t\n]+")
7934 (goto-char (match-end 0)))
7935 (while (looking-at "\\(\\w+\\)[ \t\n,]+")
7936 (setq signal-list
7937 (cons (downcase (match-string 1)) signal-list))
7938 (goto-char (match-end 0))
7939 (vhdl-forward-syntactic-ws))
7940 (re-search-forward ";" end 1)
7941 (vhdl-forward-syntactic-ws)))))))
7942 ;; search for signals declared in architecture declarative part
7943 (save-excursion
7944 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7945 (not (equal "END" (upcase (match-string 1))))
7946 (setq end (re-search-forward "^begin\\>" nil t))))
7947 (error "ERROR: No architecture declarative part found")
7948 ;; scan for all declared signal and alias names
7949 (goto-char beg)
7950 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7951 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7952 (if (match-string 2)
7953 ;; scan signal name
7954 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7955 (setq signal-list
7956 (cons (downcase (match-string 1)) signal-list))
7957 (goto-char (match-end 0)))
7958 ;; scan alias name, check is alias of (declared) signal
7959 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7960 (member (downcase (match-string 2)) signal-list))
7961 (setq signal-list
7962 (cons (downcase (match-string 1)) signal-list))
7963 (goto-char (match-end 0))))
7964 (setq beg (point))))))
7965 ;; search for signals declared in surrounding block declarative parts
7966 (save-excursion
7967 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7968 (match-string 2))
7969 (goto-char (match-end 2))
7970 (vhdl-backward-sexp)
7971 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7972 beg)
7973 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7974 ;; scan for all declared signal names
7975 (goto-char beg)
7976 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
7977 (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
7978 (if (match-string 2)
7979 ;; scan signal name
7980 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
7981 (setq signal-list
7982 (cons (downcase (match-string 1)) signal-list))
7983 (goto-char (match-end 0)))
7984 ;; scan alias name, check is alias of (declared) signal
7985 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
7986 (member (downcase (match-string 2)) signal-list))
7987 (setq signal-list
7988 (cons (downcase (match-string 1)) signal-list))
7989 (goto-char (match-end 0))))))
7990 (goto-char beg)))
7991 signal-list)))
3dcb36b7
JB
7992
7993;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7994;; Generic/port clause fixing
7995
7996(defun vhdl-fix-clause ()
7997 "Fix closing parenthesis within generic/port clause."
7998 (interactive)
7999 (save-excursion
8000 (vhdl-prepare-search-2
8001 (let ((pos (point))
8002 beg end)
8003 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
8004 (error "ERROR: Not within a generic/port clause")
8005 ;; search for end of clause
8006 (goto-char (match-end 0))
8007 (setq beg (1- (point)))
8008 (vhdl-forward-syntactic-ws)
8009 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
8010 (goto-char (1- (match-end 0)))
8011 (setq end (point-marker))
8012 (forward-char)
8013 (vhdl-forward-syntactic-ws))
8014 (goto-char end)
8015 (when (> pos (save-excursion (end-of-line) (point)))
8016 (error "ERROR: Not within a generic/port clause"))
8017 ;; delete closing parenthesis on separate line (not supported style)
8018 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8019 (vhdl-line-kill)
8020 (vhdl-backward-syntactic-ws)
8021 (setq end (point-marker))
8022 (insert ";"))
8023 ;; delete superfluous parentheses
8024 (while (progn (goto-char beg)
8025 (condition-case () (forward-sexp)
8026 (error (goto-char (point-max))))
8027 (< (point) end))
8028 (delete-backward-char 1))
8029 ;; add closing parenthesis
8030 (when (> (point) end)
8031 (goto-char end)
8032 (insert ")")))))))
8033
8034;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8035;; Miscellaneous
8036
8037(defun vhdl-remove-trailing-spaces ()
8038 "Remove trailing spaces in the whole buffer."
8039 (interactive)
8040 (save-match-data
8041 (save-excursion
8042 (goto-char (point-min))
8043 (while (re-search-forward "[ \t]+$" (point-max) t)
8044 (unless (vhdl-in-literal)
8045 (replace-match "" nil nil))))))
d2ddb974
KH
8046
8047
5eabfe72
KH
8048;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8049;;; Electrification
8050;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 8051
5eabfe72
KH
8052(defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
8053 "Syntax of prompt inserted by template generators.")
8054
8055(defvar vhdl-template-invoked-by-hook nil
8056 "Indicates whether a template has been invoked by a hook or by key or menu.
8057Used for undoing after template abortion.")
8058
8059;; correct different behavior of function `unread-command-events' in XEmacs
3dcb36b7 8060(defun vhdl-character-to-event (arg))
5eabfe72 8061(defalias 'vhdl-character-to-event
4bcb9c95 8062 (if (fboundp 'character-to-event) 'character-to-event 'identity))
3dcb36b7
JB
8063
8064(defun vhdl-work-library ()
8065 "Return the working library name of the current project or \"work\" if no
8066project is defined."
8067 (vhdl-resolve-env-variable
8068 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
5eabfe72
KH
8069
8070;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8071;; Enabling/disabling
8072
8073(defun vhdl-mode-line-update ()
8074 "Update the modeline string for VHDL major mode."
8075 (setq mode-name (concat "VHDL"
8076 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
8077 (and vhdl-electric-mode "e")
8078 (and vhdl-stutter-mode "s")))
3dcb36b7 8079 (force-mode-line-update t))
5eabfe72
KH
8080
8081(defun vhdl-electric-mode (arg)
8082 "Toggle VHDL electric mode.
8083Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8084 (interactive "P")
8085 (setq vhdl-electric-mode
8086 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
8087 ((> arg 0) t) (t nil)))
8088 (vhdl-mode-line-update))
8089
8090(defun vhdl-stutter-mode (arg)
8091 "Toggle VHDL stuttering mode.
8092Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
8093 (interactive "P")
8094 (setq vhdl-stutter-mode
8095 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
8096 ((> arg 0) t) (t nil)))
8097 (vhdl-mode-line-update))
8098
8099;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8100;; Stuttering
d2ddb974 8101
5eabfe72
KH
8102(defun vhdl-electric-dash (count)
8103 "-- starts a comment, --- draws a horizontal line,
8104---- starts a display comment"
d2ddb974 8105 (interactive "p")
3dcb36b7 8106 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
5eabfe72
KH
8107 (cond
8108 ((and abbrev-start-location (= abbrev-start-location (point)))
8109 (setq abbrev-start-location nil)
8110 (goto-char last-abbrev-location)
8111 (beginning-of-line nil)
8112 (vhdl-comment-display))
8113 ((/= (preceding-char) ?-) ; standard dash (minus)
d2ddb974 8114 (self-insert-command count))
5eabfe72
KH
8115 (t (self-insert-command count)
8116 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8117 (let ((next-input (read-char)))
8118 (if (= next-input ?-) ; triple dash
8119 (progn
8120 (vhdl-comment-display-line)
8121 (message
8122 "Enter '-' for display comment, else continue coding")
8123 (let ((next-input (read-char)))
8124 (if (= next-input ?-) ; four dashes
8125 (vhdl-comment-display t)
8126 (setq unread-command-events ; pushback the char
8127 (list (vhdl-character-to-event next-input))))))
8128 (setq unread-command-events ; pushback the char
8129 (list (vhdl-character-to-event next-input)))
8130 (vhdl-comment-insert)))))
8131 (self-insert-command count)))
8132
8133(defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
d2ddb974 8134 (interactive "p")
3dcb36b7 8135 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8136 (if (= (preceding-char) ?\()
8137 (progn (delete-char -1) (insert-char ?\[ 1))
8138 (insert-char ?\( 1))
8139 (self-insert-command count)))
d2ddb974 8140
5eabfe72 8141(defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
d2ddb974 8142 (interactive "p")
3dcb36b7 8143 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974 8144 (progn
5eabfe72
KH
8145 (if (= (preceding-char) ?\))
8146 (progn (delete-char -1) (insert-char ?\] 1))
8147 (insert-char ?\) 1))
8148 (blink-matching-open))
8149 (self-insert-command count)))
d2ddb974 8150
5eabfe72 8151(defun vhdl-electric-quote (count) "'' --> \""
d2ddb974 8152 (interactive "p")
3dcb36b7 8153 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8154 (if (= (preceding-char) last-input-char)
8155 (progn (delete-backward-char 1) (insert-char ?\" 1))
8156 (insert-char ?\' 1))
8157 (self-insert-command count)))
d2ddb974 8158
5eabfe72 8159(defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
d2ddb974 8160 (interactive "p")
3dcb36b7 8161 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8162 (cond ((= (preceding-char) last-input-char)
8163 (progn (delete-char -1)
3dcb36b7 8164 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8165 (insert ": ")
8166 (setq this-command 'vhdl-electric-colon)))
8167 ((and
8168 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
8169 (progn (delete-char -1) (insert "= ")))
8170 (t (insert-char ?\; 1)))
8171 (self-insert-command count)))
8172
8173(defun vhdl-electric-comma (count) "',,' --> ' <= '"
d2ddb974 8174 (interactive "p")
3dcb36b7 8175 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
8176 (cond ((= (preceding-char) last-input-char)
8177 (progn (delete-char -1)
3dcb36b7 8178 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8179 (insert "<= ")))
5eabfe72
KH
8180 (t (insert-char ?\, 1)))
8181 (self-insert-command count)))
d2ddb974 8182
5eabfe72 8183(defun vhdl-electric-period (count) "'..' --> ' => '"
d2ddb974 8184 (interactive "p")
3dcb36b7 8185 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
8186 (cond ((= (preceding-char) last-input-char)
8187 (progn (delete-char -1)
3dcb36b7 8188 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 8189 (insert "=> ")))
5eabfe72
KH
8190 (t (insert-char ?\. 1)))
8191 (self-insert-command count)))
d2ddb974 8192
5eabfe72 8193(defun vhdl-electric-equal (count) "'==' --> ' == '"
d2ddb974 8194 (interactive "p")
3dcb36b7 8195 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8196 (cond ((= (preceding-char) last-input-char)
8197 (progn (delete-char -1)
3dcb36b7 8198 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8199 (insert "== ")))
8200 (t (insert-char ?\= 1)))
8201 (self-insert-command count)))
d2ddb974 8202
5eabfe72 8203;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
8204;; VHDL templates
8205
5eabfe72
KH
8206(defun vhdl-template-paired-parens ()
8207 "Insert a pair of round parentheses, placing point between them."
d2ddb974 8208 (interactive)
5eabfe72
KH
8209 (insert "()")
8210 (backward-char))
d2ddb974 8211
5eabfe72
KH
8212(defun vhdl-template-alias ()
8213 "Insert alias declaration."
d2ddb974 8214 (interactive)
5eabfe72
KH
8215 (let ((start (point)))
8216 (vhdl-insert-keyword "ALIAS ")
8217 (when (vhdl-template-field "name" nil t start (point))
8218 (insert " : ")
8219 (unless (vhdl-template-field
8220 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8221 nil t)
3dcb36b7 8222 (delete-backward-char 3))
5eabfe72
KH
8223 (vhdl-insert-keyword " IS ")
8224 (vhdl-template-field "name" ";")
8225 (vhdl-comment-insert-inline))))
8226
8227(defun vhdl-template-architecture ()
8228 "Insert architecture."
8229 (interactive)
8230 (let ((margin (current-indentation))
8231 (start (point))
3dcb36b7 8232 arch-name)
d2ddb974 8233 (vhdl-insert-keyword "ARCHITECTURE ")
5eabfe72
KH
8234 (when (setq arch-name
8235 (vhdl-template-field "name" nil t start (point)))
d2ddb974 8236 (vhdl-insert-keyword " OF ")
3dcb36b7
JB
8237 (if (save-excursion
8238 (vhdl-prepare-search-1
8239 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8240 (insert (match-string 1))
5eabfe72 8241 (vhdl-template-field "entity name"))
3dcb36b7 8242 (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8243 (vhdl-template-begin-end
8244 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8245 (memq vhdl-insert-empty-lines '(unit all))))))
d2ddb974 8246
5eabfe72 8247(defun vhdl-template-array (kind &optional secondary)
d2ddb974
KH
8248 "Insert array type definition."
8249 (interactive)
5eabfe72
KH
8250 (let ((start (point)))
8251 (vhdl-insert-keyword "ARRAY (")
8252 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8253 secondary)
8254 (vhdl-insert-keyword ") OF ")
8255 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8256 (vhdl-insert-keyword ";"))))
8257
8258(defun vhdl-template-assert ()
8259 "Insert an assertion statement."
8260 (interactive)
8261 (let ((start (point)))
8262 (vhdl-insert-keyword "ASSERT ")
8263 (when vhdl-conditions-in-parenthesis (insert "("))
8264 (when (vhdl-template-field "condition (negated)" nil t start (point))
8265 (when vhdl-conditions-in-parenthesis (insert ")"))
8266 (setq start (point))
8267 (vhdl-insert-keyword " REPORT ")
8268 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8269 (delete-region start (point)))
8270 (setq start (point))
8271 (vhdl-insert-keyword " SEVERITY ")
8272 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8273 (delete-region start (point)))
8274 (insert ";"))))
8275
8276(defun vhdl-template-attribute ()
8277 "Insert an attribute declaration or specification."
8278 (interactive)
8279 (if (eq (vhdl-decision-query
8280 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8281 (vhdl-template-attribute-spec)
8282 (vhdl-template-attribute-decl)))
d2ddb974 8283
5eabfe72
KH
8284(defun vhdl-template-attribute-decl ()
8285 "Insert an attribute declaration."
d2ddb974 8286 (interactive)
5eabfe72
KH
8287 (let ((start (point)))
8288 (vhdl-insert-keyword "ATTRIBUTE ")
8289 (when (vhdl-template-field "name" " : " t start (point))
8290 (vhdl-template-field "type" ";")
8291 (vhdl-comment-insert-inline))))
8292
8293(defun vhdl-template-attribute-spec ()
8294 "Insert an attribute specification."
8295 (interactive)
8296 (let ((start (point)))
8297 (vhdl-insert-keyword "ATTRIBUTE ")
8298 (when (vhdl-template-field "name" nil t start (point))
8299 (vhdl-insert-keyword " OF ")
8300 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8301 (vhdl-template-field "entity class")
8302 (vhdl-insert-keyword " IS ")
8303 (vhdl-template-field "expression" ";"))))
d2ddb974 8304
5eabfe72
KH
8305(defun vhdl-template-block ()
8306 "Insert a block."
d2ddb974 8307 (interactive)
5eabfe72
KH
8308 (let ((margin (current-indentation))
8309 (start (point))
8310 label)
8311 (vhdl-insert-keyword ": BLOCK ")
8312 (goto-char start)
8313 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8314 (forward-word 1)
8315 (forward-char 1)
d2ddb974 8316 (insert "(")
5eabfe72
KH
8317 (if (vhdl-template-field "[guard expression]" nil t)
8318 (insert ")")
8319 (delete-char -2))
8320 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 8321 (insert "\n")
5eabfe72
KH
8322 (vhdl-template-begin-end "BLOCK" label margin)
8323 (vhdl-comment-block))))
d2ddb974 8324
5eabfe72 8325(defun vhdl-template-block-configuration ()
d2ddb974
KH
8326 "Insert a block configuration statement."
8327 (interactive)
5eabfe72
KH
8328 (let ((margin (current-indentation))
8329 (start (point)))
d2ddb974 8330 (vhdl-insert-keyword "FOR ")
5eabfe72 8331 (when (vhdl-template-field "block name" nil t start (point))
d2ddb974
KH
8332 (vhdl-insert-keyword "\n\n")
8333 (indent-to margin)
8334 (vhdl-insert-keyword "END FOR;")
8335 (end-of-line 0)
5eabfe72 8336 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8337
5eabfe72
KH
8338(defun vhdl-template-break ()
8339 "Insert a break statement."
d2ddb974 8340 (interactive)
5eabfe72
KH
8341 (let (position)
8342 (vhdl-insert-keyword "BREAK")
8343 (setq position (point))
8344 (insert " ")
8345 (while (or
8346 (progn (vhdl-insert-keyword "FOR ")
8347 (if (vhdl-template-field "[quantity name]" " USE " t)
8348 (progn (vhdl-template-field "quantity name" " => ") t)
8349 (kill-word -1) nil))
8350 (vhdl-template-field "[quantity name]" " => " t))
8351 (vhdl-template-field "expression")
8352 (setq position (point))
8353 (insert ", "))
8354 (delete-region position (point))
8355 (unless (vhdl-sequential-statement-p)
8356 (vhdl-insert-keyword " ON ")
8357 (if (vhdl-template-field "[sensitivity list]" nil t)
8358 (setq position (point))
8359 (delete-region position (point))))
8360 (vhdl-insert-keyword " WHEN ")
8361 (when vhdl-conditions-in-parenthesis (insert "("))
8362 (if (vhdl-template-field "[condition]" nil t)
8363 (when vhdl-conditions-in-parenthesis (insert ")"))
8364 (delete-region position (point)))
8365 (insert ";")))
8366
8367(defun vhdl-template-case (&optional kind)
8368 "Insert a case statement."
8369 (interactive)
8370 (let ((margin (current-indentation))
8371 (start (point))
8372 label)
8373 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8374 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8375 (vhdl-insert-keyword "CASE ")
8376 (vhdl-insert-keyword ": CASE ")
8377 (goto-char start)
8378 (setq label (vhdl-template-field "[label]" nil t))
8379 (unless label (delete-char 2))
8380 (forward-word 1)
8381 (forward-char 1))
8382 (when (vhdl-template-field "expression" nil t start (point))
8383 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
d2ddb974 8384 (indent-to margin)
5eabfe72
KH
8385 (vhdl-insert-keyword "END CASE")
8386 (when label (insert " " label))
8387 (insert ";")
d2ddb974
KH
8388 (forward-line -1)
8389 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8390 (vhdl-insert-keyword "WHEN ")
8391 (let ((position (point)))
8392 (insert " => ;\n")
8393 (indent-to (+ margin vhdl-basic-offset))
8394 (vhdl-insert-keyword "WHEN OTHERS => null;")
8395 (goto-char position)))))
d2ddb974 8396
5eabfe72
KH
8397(defun vhdl-template-case-is ()
8398 "Insert a sequential case statement."
d2ddb974 8399 (interactive)
5eabfe72
KH
8400 (vhdl-template-case 'is))
8401
8402(defun vhdl-template-case-use ()
8403 "Insert a simultaneous case statement."
8404 (interactive)
8405 (vhdl-template-case 'use))
8406
8407(defun vhdl-template-component ()
8408 "Insert a component declaration."
8409 (interactive)
8410 (vhdl-template-component-decl))
8411
8412(defun vhdl-template-component-conf ()
8413 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8414since these are almost equivalent)."
8415 (interactive)
8416 (let ((margin (current-indentation))
8417 (result (vhdl-template-configuration-spec t)))
8418 (when result
8419 (insert "\n")
8420 (indent-to margin)
8421 (vhdl-insert-keyword "END FOR;")
8422 (when (eq result 'no-use)
8423 (end-of-line -0)))))
8424
8425(defun vhdl-template-component-decl ()
8426 "Insert a component declaration."
8427 (interactive)
8428 (let ((margin (current-indentation))
8429 (start (point))
8430 name end-column)
d2ddb974 8431 (vhdl-insert-keyword "COMPONENT ")
5eabfe72 8432 (when (setq name (vhdl-template-field "name" nil t start (point)))
3dcb36b7 8433 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
d2ddb974
KH
8434 (insert "\n\n")
8435 (indent-to margin)
5eabfe72
KH
8436 (vhdl-insert-keyword "END COMPONENT")
8437 (unless (vhdl-standard-p '87) (insert " " name))
8438 (insert ";")
8439 (setq end-column (current-column))
d2ddb974
KH
8440 (end-of-line -0)
8441 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 8442 (vhdl-template-generic-list t t)
d2ddb974
KH
8443 (insert "\n")
8444 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8445 (vhdl-template-port-list t)
8446 (beginning-of-line 2)
8447 (forward-char end-column))))
d2ddb974 8448
5eabfe72
KH
8449(defun vhdl-template-component-inst ()
8450 "Insert a component instantiation statement."
d2ddb974 8451 (interactive)
5eabfe72
KH
8452 (let ((margin (current-indentation))
8453 (start (point))
8454 unit position)
8455 (when (vhdl-template-field "instance label" nil t start (point))
8456 (insert ": ")
3dcb36b7 8457 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
8458 (vhdl-template-field "component name")
8459 ;; direct instantiation
8460 (setq unit (vhdl-template-field
8461 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8462 (setq unit (upcase (or unit "")))
8463 (cond ((equal unit "ENTITY")
3dcb36b7
JB
8464 (vhdl-template-field "library name" "." nil nil nil nil
8465 (vhdl-work-library))
5eabfe72
KH
8466 (vhdl-template-field "entity name" "(")
8467 (if (vhdl-template-field "[architecture name]" nil t)
8468 (insert ")")
8469 (delete-char -1)))
8470 ((equal unit "CONFIGURATION")
3dcb36b7
JB
8471 (vhdl-template-field "library name" "." nil nil nil nil
8472 (vhdl-work-library))
5eabfe72
KH
8473 (vhdl-template-field "configuration name"))
8474 (t (vhdl-template-field "component name"))))
8475 (insert "\n")
d2ddb974 8476 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8477 (setq position (point))
8478 (vhdl-insert-keyword "GENERIC ")
8479 (when (vhdl-template-map position t t)
8480 (insert "\n")
8481 (indent-to (+ margin vhdl-basic-offset)))
8482 (setq position (point))
8483 (vhdl-insert-keyword "PORT ")
8484 (unless (vhdl-template-map position t t)
8485 (kill-line -0)
8486 (delete-char -1))
8487 (insert ";"))))
d2ddb974 8488
5eabfe72
KH
8489(defun vhdl-template-conditional-signal-asst ()
8490 "Insert a conditional signal assignment."
d2ddb974 8491 (interactive)
5eabfe72 8492 (when (vhdl-template-field "target signal")
d2ddb974 8493 (insert " <= ")
5eabfe72
KH
8494; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8495; (insert " "))
d2ddb974 8496 (let ((margin (current-column))
5eabfe72
KH
8497 (start (point))
8498 position)
8499 (vhdl-template-field "waveform")
8500 (setq position (point))
d2ddb974 8501 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8502 (when vhdl-conditions-in-parenthesis (insert "("))
8503 (while (and (vhdl-template-field "[condition]" nil t)
8504 (progn
8505 (when vhdl-conditions-in-parenthesis (insert ")"))
8506 (setq position (point))
8507 (vhdl-insert-keyword " ELSE")
8508 (insert "\n")
8509 (indent-to margin)
8510 (vhdl-template-field "[waveform]" nil t)))
8511 (setq position (point))
d2ddb974 8512 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8513 (when vhdl-conditions-in-parenthesis (insert "(")))
8514 (delete-region position (point))
d2ddb974 8515 (insert ";")
3dcb36b7 8516 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 8517
5eabfe72
KH
8518(defun vhdl-template-configuration ()
8519 "Insert a configuration specification if within an architecture,
d2ddb974
KH
8520a block or component configuration if within a configuration declaration,
8521a configuration declaration if not within a design unit."
8522 (interactive)
3dcb36b7
JB
8523 (vhdl-prepare-search-1
8524 (cond
8525 ((and (save-excursion ; architecture body
8526 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8527 (equal "ARCHITECTURE" (upcase (match-string 1))))
8528 (vhdl-template-configuration-spec))
8529 ((and (save-excursion ; configuration declaration
8530 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8531 (equal "CONFIGURATION" (upcase (match-string 1))))
8532 (if (eq (vhdl-decision-query
8533 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8534 (vhdl-template-component-conf)
8535 (vhdl-template-block-configuration)))
8536 (t (vhdl-template-configuration-decl))))) ; otherwise
5eabfe72
KH
8537
8538(defun vhdl-template-configuration-spec (&optional optional-use)
8539 "Insert a configuration specification."
d2ddb974 8540 (interactive)
5eabfe72
KH
8541 (let ((margin (current-indentation))
8542 (start (point))
8543 aspect position)
d2ddb974 8544 (vhdl-insert-keyword "FOR ")
3dcb36b7 8545 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
5eabfe72 8546 t start (point))
3dcb36b7 8547 (vhdl-template-field "component name" "\n")
d2ddb974 8548 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8549 (setq start (point))
8550 (vhdl-insert-keyword "USE ")
8551 (if (and optional-use
8552 (not (setq aspect (vhdl-template-field
8553 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8554 (progn (delete-region start (point)) 'no-use)
8555 (unless optional-use
8556 (setq aspect (vhdl-template-field
8557 "ENTITY | CONFIGURATION | OPEN" " ")))
8558 (setq aspect (upcase (or aspect "")))
8559 (cond ((equal aspect "ENTITY")
3dcb36b7
JB
8560 (vhdl-template-field "library name" "." nil nil nil nil
8561 (vhdl-work-library))
5eabfe72
KH
8562 (vhdl-template-field "entity name" "(")
8563 (if (vhdl-template-field "[architecture name]" nil t)
8564 (insert ")")
d2ddb974 8565 (delete-char -1))
5eabfe72
KH
8566 (insert "\n")
8567 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8568 (setq position (point))
8569 (vhdl-insert-keyword "GENERIC ")
8570 (when (vhdl-template-map position t t)
8571 (insert "\n")
8572 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8573 (setq position (point))
8574 (vhdl-insert-keyword "PORT ")
8575 (unless (vhdl-template-map position t t)
8576 (kill-line -0)
8577 (delete-char -1))
8578 (insert ";")
8579 t)
8580 ((equal aspect "CONFIGURATION")
3dcb36b7
JB
8581 (vhdl-template-field "library name" "." nil nil nil nil
8582 (vhdl-work-library))
5eabfe72 8583 (vhdl-template-field "configuration name" ";"))
3dcb36b7 8584 (t (delete-backward-char 1) (insert ";") t))))))
5eabfe72 8585
d2ddb974 8586
5eabfe72
KH
8587(defun vhdl-template-configuration-decl ()
8588 "Insert a configuration declaration."
d2ddb974 8589 (interactive)
5eabfe72
KH
8590 (let ((margin (current-indentation))
8591 (start (point))
5eabfe72 8592 entity-exists string name position)
d2ddb974 8593 (vhdl-insert-keyword "CONFIGURATION ")
5eabfe72 8594 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974 8595 (vhdl-insert-keyword " OF ")
5eabfe72 8596 (save-excursion
3dcb36b7
JB
8597 (vhdl-prepare-search-1
8598 (setq entity-exists (vhdl-re-search-backward
5eabfe72
KH
8599 "\\<entity \\(\\w*\\) is\\>" nil t))
8600 (setq string (match-string 1))))
d2ddb974 8601 (if (and entity-exists (not (equal string "")))
5eabfe72
KH
8602 (insert string)
8603 (vhdl-template-field "entity name"))
8604 (vhdl-insert-keyword " IS\n")
8605 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8606 (indent-to (+ margin vhdl-basic-offset))
8607 (setq position (point))
8608 (insert "\n")
8609 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
d2ddb974
KH
8610 (indent-to margin)
8611 (vhdl-insert-keyword "END ")
5eabfe72
KH
8612 (unless (vhdl-standard-p '87)
8613 (vhdl-insert-keyword "CONFIGURATION "))
d2ddb974 8614 (insert name ";")
5eabfe72 8615 (goto-char position))))
d2ddb974 8616
5eabfe72
KH
8617(defun vhdl-template-constant ()
8618 "Insert a constant declaration."
8619 (interactive)
8620 (let ((start (point))
8621 (in-arglist (vhdl-in-argument-list-p)))
8622 (vhdl-insert-keyword "CONSTANT ")
8623 (when (vhdl-template-field "name" nil t start (point))
d2ddb974 8624 (insert " : ")
5eabfe72
KH
8625 (when in-arglist (vhdl-insert-keyword "IN "))
8626 (vhdl-template-field "type")
d2ddb974 8627 (if in-arglist
5eabfe72
KH
8628 (progn (insert ";")
8629 (vhdl-comment-insert-inline))
d2ddb974
KH
8630 (let ((position (point)))
8631 (insert " := ")
5eabfe72
KH
8632 (unless (vhdl-template-field "[initialization]" nil t)
8633 (delete-region position (point)))
8634 (insert ";")
8635 (vhdl-comment-insert-inline))))))
d2ddb974 8636
5eabfe72 8637(defun vhdl-template-default ()
d2ddb974
KH
8638 "Insert nothing."
8639 (interactive)
8640 (insert " ")
8641 (unexpand-abbrev)
8642 (backward-word 1)
8643 (vhdl-case-word 1)
5eabfe72 8644 (forward-char 1))
d2ddb974 8645
5eabfe72 8646(defun vhdl-template-default-indent ()
d2ddb974
KH
8647 "Insert nothing and indent."
8648 (interactive)
8649 (insert " ")
8650 (unexpand-abbrev)
8651 (backward-word 1)
8652 (vhdl-case-word 1)
8653 (forward-char 1)
3dcb36b7 8654 (indent-according-to-mode))
d2ddb974 8655
5eabfe72 8656(defun vhdl-template-disconnect ()
d2ddb974
KH
8657 "Insert a disconnect statement."
8658 (interactive)
5eabfe72
KH
8659 (let ((start (point)))
8660 (vhdl-insert-keyword "DISCONNECT ")
8661 (when (vhdl-template-field "signal names | OTHERS | ALL"
8662 " : " t start (point))
8663 (vhdl-template-field "type")
8664 (vhdl-insert-keyword " AFTER ")
8665 (vhdl-template-field "time expression" ";"))))
8666
8667(defun vhdl-template-else ()
d2ddb974
KH
8668 "Insert an else statement."
8669 (interactive)
3dcb36b7
JB
8670 (let (margin)
8671 (vhdl-prepare-search-1
5eabfe72 8672 (vhdl-insert-keyword "ELSE")
3dcb36b7
JB
8673 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8674 (equal "WHEN" (upcase (match-string 1))))
5eabfe72 8675 (insert " ")
3dcb36b7 8676 (indent-according-to-mode)
5eabfe72
KH
8677 (setq margin (current-indentation))
8678 (insert "\n")
8679 (indent-to (+ margin vhdl-basic-offset))))))
8680
8681(defun vhdl-template-elsif ()
d2ddb974
KH
8682 "Insert an elsif statement."
8683 (interactive)
5eabfe72
KH
8684 (let ((start (point))
8685 margin)
d2ddb974 8686 (vhdl-insert-keyword "ELSIF ")
3dcb36b7
JB
8687 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8688 (when vhdl-conditions-in-parenthesis (insert "("))
8689 (when (vhdl-template-field "condition" nil t start (point))
8690 (when vhdl-conditions-in-parenthesis (insert ")"))
8691 (indent-according-to-mode)
8692 (setq margin (current-indentation))
8693 (vhdl-insert-keyword
8694 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8695 (indent-to (+ margin vhdl-basic-offset))))))
d2ddb974 8696
5eabfe72
KH
8697(defun vhdl-template-entity ()
8698 "Insert an entity."
d2ddb974 8699 (interactive)
5eabfe72
KH
8700 (let ((margin (current-indentation))
8701 (start (point))
8702 name end-column)
d2ddb974 8703 (vhdl-insert-keyword "ENTITY ")
5eabfe72 8704 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974
KH
8705 (vhdl-insert-keyword " IS\n\n")
8706 (indent-to margin)
8707 (vhdl-insert-keyword "END ")
5eabfe72
KH
8708 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8709 (insert name ";")
8710 (setq end-column (current-column))
d2ddb974
KH
8711 (end-of-line -0)
8712 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8713 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8714 (indent-to (+ margin vhdl-basic-offset))
8715 (when (vhdl-template-generic-list t)
8716 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8717 (insert "\n")
8718 (indent-to (+ margin vhdl-basic-offset))
8719 (when (vhdl-template-port-list t)
8720 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8721 (beginning-of-line 2)
8722 (forward-char end-column))))
d2ddb974 8723
5eabfe72 8724(defun vhdl-template-exit ()
d2ddb974
KH
8725 "Insert an exit statement."
8726 (interactive)
5eabfe72
KH
8727 (let ((start (point)))
8728 (vhdl-insert-keyword "EXIT ")
3dcb36b7
JB
8729 (if (vhdl-template-field "[loop label]" nil t start (point))
8730 (let ((position (point)))
8731 (vhdl-insert-keyword " WHEN ")
8732 (when vhdl-conditions-in-parenthesis (insert "("))
8733 (if (vhdl-template-field "[condition]" nil t)
8734 (when vhdl-conditions-in-parenthesis (insert ")"))
8735 (delete-region position (point))))
d2ddb974 8736 (delete-char -1))
5eabfe72
KH
8737 (insert ";")))
8738
8739(defun vhdl-template-file ()
8740 "Insert a file declaration."
8741 (interactive)
8742 (let ((start (point)))
8743 (vhdl-insert-keyword "FILE ")
8744 (when (vhdl-template-field "name" nil t start (point))
8745 (insert " : ")
8746 (vhdl-template-field "type")
8747 (unless (vhdl-standard-p '87)
8748 (vhdl-insert-keyword " OPEN ")
8749 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8750 nil t)
3dcb36b7 8751 (delete-backward-char 6)))
5eabfe72
KH
8752 (vhdl-insert-keyword " IS ")
8753 (when (vhdl-standard-p '87)
8754 (vhdl-template-field "[IN | OUT]" " " t))
8755 (vhdl-template-field "filename-string" nil nil nil nil t)
8756 (insert ";")
8757 (vhdl-comment-insert-inline))))
d2ddb974 8758
5eabfe72
KH
8759(defun vhdl-template-for ()
8760 "Insert a block or component configuration if within a configuration
8761declaration, a configuration specification if within an architecture
3dcb36b7
JB
8762declarative part (and not within a subprogram), a for-loop if within a
8763sequential statement part (subprogram or process), and a for-generate
8764otherwise."
5eabfe72 8765 (interactive)
3dcb36b7
JB
8766 (vhdl-prepare-search-1
8767 (cond
8768 ((vhdl-sequential-statement-p) ; sequential statement
8769 (vhdl-template-for-loop))
8770 ((and (save-excursion ; configuration declaration
8771 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8772 (equal "CONFIGURATION" (upcase (match-string 1))))
8773 (if (eq (vhdl-decision-query
8774 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8775 (vhdl-template-component-conf)
8776 (vhdl-template-block-configuration)))
8777 ((and (save-excursion
8778 (re-search-backward ; architecture declarative part
8779 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8780 (equal "ARCHITECTURE" (upcase (match-string 1))))
8781 (vhdl-template-configuration-spec))
8782 (t (vhdl-template-for-generate))))) ; concurrent statement
5eabfe72
KH
8783
8784(defun vhdl-template-for-generate ()
8785 "Insert a for-generate."
d2ddb974 8786 (interactive)
5eabfe72
KH
8787 (let ((margin (current-indentation))
8788 (start (point))
3dcb36b7 8789 label position)
5eabfe72
KH
8790 (vhdl-insert-keyword ": FOR ")
8791 (setq position (point-marker))
8792 (goto-char start)
8793 (when (setq label (vhdl-template-field "label" nil t start position))
8794 (goto-char position)
8795 (vhdl-template-field "loop variable")
8796 (vhdl-insert-keyword " IN ")
8797 (vhdl-template-field "range")
8798 (vhdl-template-generate-body margin label))))
d2ddb974 8799
5eabfe72
KH
8800(defun vhdl-template-for-loop ()
8801 "Insert a for loop."
d2ddb974 8802 (interactive)
5eabfe72
KH
8803 (let ((margin (current-indentation))
8804 (start (point))
8805 label index)
8806 (if (not (eq vhdl-optional-labels 'all))
8807 (vhdl-insert-keyword "FOR ")
8808 (vhdl-insert-keyword ": FOR ")
8809 (goto-char start)
8810 (setq label (vhdl-template-field "[label]" nil t))
8811 (unless label (delete-char 2))
8812 (forward-word 1)
8813 (forward-char 1))
8814 (when (setq index (vhdl-template-field "loop variable"
8815 nil t start (point)))
d2ddb974 8816 (vhdl-insert-keyword " IN ")
5eabfe72 8817 (vhdl-template-field "range")
d2ddb974
KH
8818 (vhdl-insert-keyword " LOOP\n\n")
8819 (indent-to margin)
8820 (vhdl-insert-keyword "END LOOP")
5eabfe72
KH
8821 (if label
8822 (insert " " label ";")
d2ddb974 8823 (insert ";")
5eabfe72 8824 (when vhdl-self-insert-comments (insert " -- " index)))
d2ddb974 8825 (forward-line -1)
5eabfe72 8826 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8827
5eabfe72
KH
8828(defun vhdl-template-function (&optional kind)
8829 "Insert a function declaration or body."
d2ddb974 8830 (interactive)
5eabfe72
KH
8831 (let ((margin (current-indentation))
8832 (start (point))
8833 name)
8834 (vhdl-insert-keyword "FUNCTION ")
8835 (when (setq name (vhdl-template-field "name" nil t start (point)))
8836 (vhdl-template-argument-list t)
3dcb36b7 8837 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
d2ddb974 8838 (end-of-line)
5eabfe72 8839 (insert "\n")
d2ddb974 8840 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8841 (vhdl-insert-keyword "RETURN ")
8842 (vhdl-template-field "type")
8843 (if (if kind (eq kind 'body)
8844 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
3dcb36b7 8845 (progn (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8846 (vhdl-template-begin-end
8847 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8848 (vhdl-comment-block))
8849 (insert ";")))))
8850
8851(defun vhdl-template-function-decl ()
8852 "Insert a function declaration."
8853 (interactive)
8854 (vhdl-template-function 'decl))
d2ddb974 8855
5eabfe72
KH
8856(defun vhdl-template-function-body ()
8857 "Insert a function declaration."
d2ddb974 8858 (interactive)
5eabfe72
KH
8859 (vhdl-template-function 'body))
8860
8861(defun vhdl-template-generate ()
8862 "Insert a generation scheme."
8863 (interactive)
8864 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8865 (vhdl-template-if-generate)
8866 (vhdl-template-for-generate)))
d2ddb974 8867
5eabfe72
KH
8868(defun vhdl-template-generic ()
8869 "Insert generic declaration, or generic map in instantiation statements."
8870 (interactive)
3dcb36b7
JB
8871 (let ((start (point)))
8872 (vhdl-prepare-search-1
5eabfe72
KH
8873 (cond
8874 ((and (save-excursion ; entity declaration
8875 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8876 (equal "ENTITY" (upcase (match-string 1))))
8877 (vhdl-template-generic-list nil))
8878 ((or (save-excursion
8879 (or (beginning-of-line)
8880 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 8881 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
8882 (vhdl-insert-keyword "GENERIC ")
8883 (vhdl-template-map start))
8884 (t (vhdl-template-generic-list nil t))))))
8885
8886(defun vhdl-template-group ()
8887 "Insert group or group template declaration."
8888 (interactive)
8889 (let ((start (point)))
8890 (if (eq (vhdl-decision-query
8891 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8892 (vhdl-template-group-template)
8893 (vhdl-template-group-decl))))
8894
8895(defun vhdl-template-group-decl ()
8896 "Insert group declaration."
8897 (interactive)
8898 (let ((start (point)))
8899 (vhdl-insert-keyword "GROUP ")
8900 (when (vhdl-template-field "name" " : " t start (point))
8901 (vhdl-template-field "template name" " (")
8902 (vhdl-template-field "constituent list" ");")
8903 (vhdl-comment-insert-inline))))
8904
8905(defun vhdl-template-group-template ()
8906 "Insert group template declaration."
8907 (interactive)
8908 (let ((start (point)))
8909 (vhdl-insert-keyword "GROUP ")
8910 (when (vhdl-template-field "template name" nil t start (point))
8911 (vhdl-insert-keyword " IS (")
8912 (vhdl-template-field "entity class list" ");")
8913 (vhdl-comment-insert-inline))))
8914
5eabfe72
KH
8915(defun vhdl-template-if ()
8916 "Insert a sequential if statement or an if-generate statement."
8917 (interactive)
8918 (if (vhdl-sequential-statement-p)
8919 (vhdl-template-if-then)
8920 (if (and (vhdl-standard-p 'ams)
8921 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8922 (vhdl-template-if-use)
8923 (vhdl-template-if-generate))))
8924
8925(defun vhdl-template-if-generate ()
8926 "Insert an if-generate."
8927 (interactive)
8928 (let ((margin (current-indentation))
8929 (start (point))
3dcb36b7 8930 label position)
5eabfe72
KH
8931 (vhdl-insert-keyword ": IF ")
8932 (setq position (point-marker))
8933 (goto-char start)
8934 (when (setq label (vhdl-template-field "label" nil t start position))
8935 (goto-char position)
8936 (when vhdl-conditions-in-parenthesis (insert "("))
8937 (vhdl-template-field "condition")
8938 (when vhdl-conditions-in-parenthesis (insert ")"))
8939 (vhdl-template-generate-body margin label))))
d2ddb974 8940
5eabfe72
KH
8941(defun vhdl-template-if-then-use (kind)
8942 "Insert a sequential if statement."
8943 (interactive)
8944 (let ((margin (current-indentation))
8945 (start (point))
8946 label)
8947 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8948 (vhdl-insert-keyword "IF ")
8949 (vhdl-insert-keyword ": IF ")
8950 (goto-char start)
8951 (setq label (vhdl-template-field "[label]" nil t))
8952 (unless label (delete-char 2))
8953 (forward-word 1)
8954 (forward-char 1))
8955 (when vhdl-conditions-in-parenthesis (insert "("))
8956 (when (vhdl-template-field "condition" nil t start (point))
8957 (when vhdl-conditions-in-parenthesis (insert ")"))
8958 (vhdl-insert-keyword
8959 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
d2ddb974 8960 (indent-to margin)
5eabfe72
KH
8961 (vhdl-insert-keyword "END IF")
8962 (when label (insert " " label))
8963 (insert ";")
d2ddb974 8964 (forward-line -1)
5eabfe72
KH
8965 (indent-to (+ margin vhdl-basic-offset)))))
8966
8967(defun vhdl-template-if-then ()
8968 "Insert a sequential if statement."
8969 (interactive)
8970 (vhdl-template-if-then-use 'then))
8971
8972(defun vhdl-template-if-use ()
8973 "Insert a simultaneous if statement."
8974 (interactive)
8975 (vhdl-template-if-then-use 'use))
8976
8977(defun vhdl-template-instance ()
8978 "Insert a component instantiation statement."
8979 (interactive)
8980 (vhdl-template-component-inst))
d2ddb974 8981
5eabfe72 8982(defun vhdl-template-library ()
d2ddb974
KH
8983 "Insert a library specification."
8984 (interactive)
5eabfe72
KH
8985 (let ((margin (current-indentation))
8986 (start (point))
8987 name end-pos)
d2ddb974 8988 (vhdl-insert-keyword "LIBRARY ")
5eabfe72
KH
8989 (when (setq name (vhdl-template-field "names" nil t start (point)))
8990 (insert ";")
8991 (unless (string-match "," name)
8992 (setq end-pos (point))
8993 (insert "\n")
8994 (indent-to margin)
8995 (vhdl-insert-keyword "USE ")
8996 (insert name)
8997 (vhdl-insert-keyword "..ALL;")
8998 (backward-char 5)
8999 (if (vhdl-template-field "package name")
9000 (forward-char 5)
9001 (delete-region end-pos (+ (point) 5)))))))
9002
9003(defun vhdl-template-limit ()
9004 "Insert a limit."
d2ddb974 9005 (interactive)
5eabfe72
KH
9006 (let ((start (point)))
9007 (vhdl-insert-keyword "LIMIT ")
9008 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9009 t start (point))
9010 (vhdl-template-field "type")
9011 (vhdl-insert-keyword " WITH ")
9012 (vhdl-template-field "real expression" ";"))))
9013
9014(defun vhdl-template-loop ()
9015 "Insert a loop."
9016 (interactive)
9017 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
9018 (cond ((eq char ?w)
9019 (vhdl-template-while-loop))
9020 ((eq char ?f)
9021 (vhdl-template-for-loop))
9022 (t (vhdl-template-bare-loop)))))
9023
9024(defun vhdl-template-bare-loop ()
9025 "Insert a loop."
9026 (interactive)
9027 (let ((margin (current-indentation))
9028 (start (point))
9029 label)
9030 (if (not (eq vhdl-optional-labels 'all))
9031 (vhdl-insert-keyword "LOOP ")
9032 (vhdl-insert-keyword ": LOOP ")
9033 (goto-char start)
9034 (setq label (vhdl-template-field "[label]" nil t))
9035 (unless label (delete-char 2))
9036 (forward-word 1)
9037 (delete-char 1))
d2ddb974
KH
9038 (insert "\n\n")
9039 (indent-to margin)
9040 (vhdl-insert-keyword "END LOOP")
5eabfe72 9041 (insert (if label (concat " " label ";") ";"))
d2ddb974 9042 (forward-line -1)
5eabfe72 9043 (indent-to (+ margin vhdl-basic-offset))))
d2ddb974 9044
5eabfe72
KH
9045(defun vhdl-template-map (&optional start optional secondary)
9046 "Insert a map specification with association list."
d2ddb974 9047 (interactive)
5eabfe72
KH
9048 (let ((start (or start (point)))
9049 margin end-pos)
9050 (vhdl-insert-keyword "MAP (")
9051 (if (not vhdl-association-list-with-formals)
9052 (if (vhdl-template-field
9053 (concat (and optional "[") "association list" (and optional "]"))
9054 ")" (or (not secondary) optional)
9055 (and (not secondary) start) (point))
9056 t
9057 (if (and optional secondary) (delete-region start (point)))
9058 nil)
9059 (if vhdl-argument-list-indent
9060 (setq margin (current-column))
9061 (setq margin (+ (current-indentation) vhdl-basic-offset))
9062 (insert "\n")
9063 (indent-to margin))
9064 (if (vhdl-template-field
9065 (concat (and optional "[") "formal" (and optional "]"))
9066 " => " (or (not secondary) optional)
9067 (and (not secondary) start) (point))
9068 (progn
9069 (vhdl-template-field "actual" ",")
9070 (setq end-pos (point))
9071 (insert "\n")
9072 (indent-to margin)
9073 (while (vhdl-template-field "[formal]" " => " t)
9074 (vhdl-template-field "actual" ",")
9075 (setq end-pos (point))
9076 (insert "\n")
9077 (indent-to margin))
9078 (delete-region end-pos (point))
3dcb36b7 9079 (delete-backward-char 1)
5eabfe72 9080 (insert ")")
3dcb36b7 9081 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9082 t)
9083 (when (and optional secondary) (delete-region start (point)))
9084 nil))))
d2ddb974 9085
5eabfe72 9086(defun vhdl-template-modify (&optional noerror)
d2ddb974
KH
9087 "Actualize modification date."
9088 (interactive)
3dcb36b7
JB
9089 (vhdl-prepare-search-2
9090 (save-excursion
9091 (goto-char (point-min))
9092 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
9093 (progn (delete-region (point) (progn (end-of-line) (point)))
9094 (vhdl-template-insert-date))
9095 (unless noerror
9096 (error (concat "ERROR: Modification date prefix string \""
9097 vhdl-modify-date-prefix-string "\" not found")))))))
5eabfe72
KH
9098
9099(defun vhdl-template-modify-noerror ()
9100 "Call `vhdl-template-modify' with NOERROR non-nil."
9101 (vhdl-template-modify t))
9102
9103(defun vhdl-template-nature ()
9104 "Insert a nature declaration."
9105 (interactive)
9106 (let ((start (point))
9107 name mid-pos end-pos)
9108 (vhdl-insert-keyword "NATURE ")
9109 (when (setq name (vhdl-template-field "name" nil t start (point)))
9110 (vhdl-insert-keyword " IS ")
9111 (let ((definition
9112 (upcase
9113 (or (vhdl-template-field
9114 "across type | ARRAY | RECORD")
9115 ""))))
9116 (cond ((equal definition "")
9117 (insert ";"))
9118 ((equal definition "ARRAY")
9119 (kill-word -1)
9120 (vhdl-template-array 'nature t))
9121 ((equal definition "RECORD")
9122 (setq mid-pos (point-marker))
9123 (kill-word -1)
9124 (vhdl-template-record 'nature name t))
9125 (t
9126 (vhdl-insert-keyword " ACROSS ")
9127 (vhdl-template-field "through type")
9128 (vhdl-insert-keyword " THROUGH ")
9129 (vhdl-template-field "reference name")
9130 (vhdl-insert-keyword " REFERENCE;")))
9131 (when mid-pos
9132 (setq end-pos (point-marker))
9133 (goto-char mid-pos)
9134 (end-of-line))
9135 (vhdl-comment-insert-inline)
9136 (when end-pos (goto-char end-pos))))))
9137
9138(defun vhdl-template-next ()
9139 "Insert a next statement."
d2ddb974 9140 (interactive)
3dcb36b7
JB
9141 (let ((start (point)))
9142 (vhdl-insert-keyword "NEXT ")
9143 (if (vhdl-template-field "[loop label]" nil t start (point))
9144 (let ((position (point)))
9145 (vhdl-insert-keyword " WHEN ")
9146 (when vhdl-conditions-in-parenthesis (insert "("))
9147 (if (vhdl-template-field "[condition]" nil t)
9148 (when vhdl-conditions-in-parenthesis (insert ")"))
9149 (delete-region position (point))))
9150 (delete-char -1))
5eabfe72
KH
9151 (insert ";")))
9152
9153(defun vhdl-template-others ()
9154 "Insert an others aggregate."
9155 (interactive)
3dcb36b7
JB
9156 (let ((start (point)))
9157 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
9158 (progn (unless vhdl-template-invoked-by-hook (insert "("))
9159 (vhdl-insert-keyword "OTHERS => '")
9160 (when (vhdl-template-field "value" nil t start (point))
9161 (insert "')")))
9162 (vhdl-insert-keyword "OTHERS "))))
d2ddb974 9163
5eabfe72 9164(defun vhdl-template-package (&optional kind)
d2ddb974
KH
9165 "Insert a package specification or body."
9166 (interactive)
5eabfe72
KH
9167 (let ((margin (current-indentation))
9168 (start (point))
9169 name body position)
d2ddb974 9170 (vhdl-insert-keyword "PACKAGE ")
5eabfe72
KH
9171 (setq body (if kind (eq kind 'body)
9172 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
3dcb36b7
JB
9173 (when body
9174 (vhdl-insert-keyword "BODY ")
9175 (when (save-excursion
9176 (vhdl-prepare-search-1
9177 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
9178 (insert (setq name (match-string 1)))))
9179 (when (or name
9180 (setq name (vhdl-template-field "name" nil t start (point))))
5eabfe72
KH
9181 (vhdl-insert-keyword " IS\n")
9182 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9183 (indent-to (+ margin vhdl-basic-offset))
9184 (setq position (point))
9185 (insert "\n")
9186 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
9187 (indent-to margin)
9188 (vhdl-insert-keyword "END ")
9189 (unless (vhdl-standard-p '87)
9190 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
9191 (insert (or name "") ";")
9192 (goto-char position))))
d2ddb974 9193
5eabfe72
KH
9194(defun vhdl-template-package-decl ()
9195 "Insert a package specification."
d2ddb974 9196 (interactive)
5eabfe72 9197 (vhdl-template-package 'decl))
d2ddb974 9198
5eabfe72
KH
9199(defun vhdl-template-package-body ()
9200 "Insert a package body."
d2ddb974 9201 (interactive)
5eabfe72 9202 (vhdl-template-package 'body))
d2ddb974 9203
5eabfe72
KH
9204(defun vhdl-template-port ()
9205 "Insert a port declaration, or port map in instantiation statements."
d2ddb974 9206 (interactive)
3dcb36b7
JB
9207 (let ((start (point)))
9208 (vhdl-prepare-search-1
5eabfe72
KH
9209 (cond
9210 ((and (save-excursion ; entity declaration
9211 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9212 (equal "ENTITY" (upcase (match-string 1))))
9213 (vhdl-template-port-list nil))
9214 ((or (save-excursion
9215 (or (beginning-of-line)
9216 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 9217 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
9218 (vhdl-insert-keyword "PORT ")
9219 (vhdl-template-map start))
9220 (t (vhdl-template-port-list nil))))))
9221
9222(defun vhdl-template-procedural ()
9223 "Insert a procedural."
9224 (interactive)
9225 (let ((margin (current-indentation))
9226 (start (point))
9227 (case-fold-search t)
9228 label)
9229 (vhdl-insert-keyword "PROCEDURAL ")
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 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
3dcb36b7 9239 (insert "\n")
5eabfe72
KH
9240 (vhdl-template-begin-end "PROCEDURAL" label margin)
9241 (vhdl-comment-block)))
9242
9243(defun vhdl-template-procedure (&optional kind)
9244 "Insert a procedure declaration or body."
9245 (interactive)
9246 (let ((margin (current-indentation))
9247 (start (point))
9248 name)
9249 (vhdl-insert-keyword "PROCEDURE ")
9250 (when (setq name (vhdl-template-field "name" nil t start (point)))
9251 (vhdl-template-argument-list)
9252 (if (if kind (eq kind 'body)
9253 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9254 (progn (vhdl-insert-keyword " IS")
9255 (when vhdl-auto-align
3dcb36b7
JB
9256 (vhdl-align-region-groups start (point) 1))
9257 (end-of-line) (insert "\n")
5eabfe72
KH
9258 (vhdl-template-begin-end
9259 (unless (vhdl-standard-p '87) "PROCEDURE")
9260 name margin)
9261 (vhdl-comment-block))
9262 (insert ";")
3dcb36b7 9263 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9264 (end-of-line)))))
9265
9266(defun vhdl-template-procedure-decl ()
9267 "Insert a procedure declaration."
9268 (interactive)
9269 (vhdl-template-procedure 'decl))
d2ddb974 9270
5eabfe72
KH
9271(defun vhdl-template-procedure-body ()
9272 "Insert a procedure body."
9273 (interactive)
9274 (vhdl-template-procedure 'body))
9275
9276(defun vhdl-template-process (&optional kind)
9277 "Insert a process."
9278 (interactive)
9279 (let ((margin (current-indentation))
9280 (start (point))
5eabfe72
KH
9281 label seq input-signals clock reset final-pos)
9282 (setq seq (if kind (eq kind 'seq)
9283 (eq (vhdl-decision-query
9284 "process" "(c)ombinational or (s)equential?" t) ?s)))
9285 (vhdl-insert-keyword "PROCESS ")
9286 (when (memq vhdl-optional-labels '(process all))
9287 (goto-char start)
9288 (insert ": ")
9289 (goto-char start)
9290 (setq label (vhdl-template-field "[label]" nil t))
9291 (unless label (delete-char 2))
9292 (forward-word 1)
9293 (forward-char 1))
9294 (insert "(")
9295 (if (not seq)
9296 (unless (setq input-signals
9297 (vhdl-template-field "[sensitivity list]" ")" t))
9298 (setq input-signals "")
9299 (delete-char -2))
9300 (setq clock (or (and (not (equal "" vhdl-clock-name))
9301 (progn (insert vhdl-clock-name) vhdl-clock-name))
9302 (vhdl-template-field "clock name") "<clock>"))
9303 (when (eq vhdl-reset-kind 'async)
9304 (insert ", ")
9305 (setq reset (or (and (not (equal "" vhdl-reset-name))
9306 (progn (insert vhdl-reset-name) vhdl-reset-name))
9307 (vhdl-template-field "reset name") "<reset>")))
9308 (insert ")"))
9309 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 9310 (insert "\n")
5eabfe72
KH
9311 (vhdl-template-begin-end "PROCESS" label margin)
9312 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9313 (when vhdl-prompt-for-comments
9314 (setq final-pos (point-marker))
3dcb36b7
JB
9315 (vhdl-prepare-search-2
9316 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9317 (vhdl-re-search-backward "\\<process\\>" nil t))
5eabfe72
KH
9318 (end-of-line -0)
9319 (if (bobp)
9320 (progn (insert "\n") (forward-line -1))
9321 (insert "\n"))
9322 (indent-to margin)
9323 (insert "-- purpose: ")
9324 (if (not (vhdl-template-field "[description]" nil t))
9325 (vhdl-line-kill-entire)
9326 (insert "\n")
9327 (indent-to margin)
9328 (insert "-- type : ")
9329 (insert (if seq "sequential" "combinational") "\n")
9330 (indent-to margin)
9331 (insert "-- inputs : ")
9332 (if (not seq)
9333 (insert input-signals)
9334 (insert clock ", ")
9335 (when reset (insert reset ", "))
9336 (unless (vhdl-template-field "[signal names]" nil t)
9337 (delete-char -2)))
9338 (insert "\n")
9339 (indent-to margin)
9340 (insert "-- outputs: ")
9341 (vhdl-template-field "[signal names]" nil t))))
9342 (goto-char final-pos))))
9343
9344(defun vhdl-template-process-comb ()
9345 "Insert a combinational process."
9346 (interactive)
9347 (vhdl-template-process 'comb))
9348
9349(defun vhdl-template-process-seq ()
9350 "Insert a sequential process."
9351 (interactive)
9352 (vhdl-template-process 'seq))
9353
9354(defun vhdl-template-quantity ()
9355 "Insert a quantity declaration."
9356 (interactive)
9357 (if (vhdl-in-argument-list-p)
9358 (let ((start (point)))
9359 (vhdl-insert-keyword "QUANTITY ")
9360 (when (vhdl-template-field "names" nil t start (point))
9361 (insert " : ")
9362 (vhdl-template-field "[IN | OUT]" " " t)
9363 (vhdl-template-field "type")
9364 (insert ";")
9365 (vhdl-comment-insert-inline)))
9366 (let ((char (vhdl-decision-query
9367 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9368 (cond ((eq char ?f) (vhdl-template-quantity-free))
9369 ((eq char ?b) (vhdl-template-quantity-branch))
9370 ((eq char ?s) (vhdl-template-quantity-source))
9371 (t (vhdl-template-undo (point) (point)))))))
9372
9373(defun vhdl-template-quantity-free ()
9374 "Insert a free quantity declaration."
9375 (interactive)
9376 (vhdl-insert-keyword "QUANTITY ")
9377 (vhdl-template-field "names")
9378 (insert " : ")
9379 (vhdl-template-field "type")
9380 (let ((position (point)))
9381 (insert " := ")
9382 (unless (vhdl-template-field "[initialization]" nil t)
9383 (delete-region position (point)))
9384 (insert ";")
9385 (vhdl-comment-insert-inline)))
9386
9387(defun vhdl-template-quantity-branch ()
9388 "Insert a branch quantity declaration."
9389 (interactive)
9390 (let (position)
9391 (vhdl-insert-keyword "QUANTITY ")
9392 (when (vhdl-template-field "[across names]" " " t)
9393 (vhdl-insert-keyword "ACROSS "))
9394 (when (vhdl-template-field "[through names]" " " t)
9395 (vhdl-insert-keyword "THROUGH "))
9396 (vhdl-template-field "plus terminal name")
9397 (setq position (point))
9398 (vhdl-insert-keyword " TO ")
9399 (unless (vhdl-template-field "[minus terminal name]" nil t)
9400 (delete-region position (point)))
9401 (insert ";")
9402 (vhdl-comment-insert-inline)))
9403
9404(defun vhdl-template-quantity-source ()
9405 "Insert a source quantity declaration."
9406 (interactive)
9407 (vhdl-insert-keyword "QUANTITY ")
9408 (vhdl-template-field "names")
9409 (insert " : ")
9410 (vhdl-template-field "type" " ")
9411 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9412 (progn (vhdl-insert-keyword "NOISE ")
9413 (vhdl-template-field "power expression"))
9414 (vhdl-insert-keyword "SPECTRUM ")
9415 (vhdl-template-field "magnitude expression" ", ")
9416 (vhdl-template-field "phase expression"))
9417 (insert ";")
9418 (vhdl-comment-insert-inline))
9419
9420(defun vhdl-template-record (kind &optional name secondary)
d2ddb974
KH
9421 "Insert a record type declaration."
9422 (interactive)
9423 (let ((margin (current-column))
9424 (start (point))
9425 (first t))
9426 (vhdl-insert-keyword "RECORD\n")
9427 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9428 (when (or (vhdl-template-field "element names"
9429 nil (not secondary) start (point))
9430 secondary)
9431 (while (or first (vhdl-template-field "[element names]" nil t))
9432 (insert " : ")
9433 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9434 (vhdl-comment-insert-inline)
9435 (insert "\n")
d2ddb974 9436 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 9437 (setq first nil))
d2ddb974
KH
9438 (kill-line -0)
9439 (indent-to margin)
5eabfe72
KH
9440 (vhdl-insert-keyword "END RECORD")
9441 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9442 (insert ";")
3dcb36b7 9443 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9444
5eabfe72
KH
9445(defun vhdl-template-report ()
9446 "Insert a report statement."
9447 (interactive)
9448 (let ((start (point)))
9449 (vhdl-insert-keyword "REPORT ")
9450 (if (equal "\"\"" (vhdl-template-field
9451 "string expression" nil t start (point) t))
3dcb36b7 9452 (delete-backward-char 2)
5eabfe72
KH
9453 (setq start (point))
9454 (vhdl-insert-keyword " SEVERITY ")
9455 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9456 (delete-region start (point)))
9457 (insert ";"))))
9458
9459(defun vhdl-template-return ()
d2ddb974
KH
9460 "Insert a return statement."
9461 (interactive)
3dcb36b7
JB
9462 (let ((start (point)))
9463 (vhdl-insert-keyword "RETURN ")
9464 (unless (vhdl-template-field "[expression]" nil t start (point))
9465 (delete-char -1))
9466 (insert ";")))
d2ddb974 9467
5eabfe72 9468(defun vhdl-template-selected-signal-asst ()
d2ddb974
KH
9469 "Insert a selected signal assignment."
9470 (interactive)
5eabfe72
KH
9471 (let ((margin (current-indentation))
9472 (start (point))
9473 (choices t))
d2ddb974 9474 (let ((position (point)))
5eabfe72 9475 (vhdl-insert-keyword " SELECT ")
d2ddb974
KH
9476 (goto-char position))
9477 (vhdl-insert-keyword "WITH ")
5eabfe72
KH
9478 (when (vhdl-template-field "selector expression"
9479 nil t start (+ (point) 7))
9480 (forward-word 1)
9481 (delete-char 1)
d2ddb974
KH
9482 (insert "\n")
9483 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9484 (vhdl-template-field "target signal" " <= ")
9485; (vhdl-template-field "[GUARDED] [TRANSPORT]")
d2ddb974
KH
9486 (insert "\n")
9487 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9488 (vhdl-template-field "waveform")
9489 (vhdl-insert-keyword " WHEN ")
9490 (vhdl-template-field "choices" ",")
9491 (insert "\n")
9492 (indent-to (+ margin vhdl-basic-offset))
9493 (while (and choices (vhdl-template-field "[waveform]" nil t))
d2ddb974 9494 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
9495 (if (setq choices (vhdl-template-field "[choices]" "," t))
9496 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9497 (vhdl-insert-keyword "OTHERS")))
9498 (when choices
d2ddb974
KH
9499 (fixup-whitespace)
9500 (delete-char -2))
9501 (insert ";")
3dcb36b7 9502 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9503
5eabfe72 9504(defun vhdl-template-signal ()
d2ddb974
KH
9505 "Insert a signal declaration."
9506 (interactive)
5eabfe72
KH
9507 (let ((start (point))
9508 (in-arglist (vhdl-in-argument-list-p)))
9509 (vhdl-insert-keyword "SIGNAL ")
9510 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9511 (insert " : ")
5eabfe72
KH
9512 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9513 (vhdl-template-field "type")
d2ddb974 9514 (if in-arglist
5eabfe72
KH
9515 (progn (insert ";")
9516 (vhdl-comment-insert-inline))
d2ddb974
KH
9517 (let ((position (point)))
9518 (insert " := ")
5eabfe72
KH
9519 (unless (vhdl-template-field "[initialization]" nil t)
9520 (delete-region position (point)))
9521 (insert ";")
9522 (vhdl-comment-insert-inline))))))
9523
9524(defun vhdl-template-subnature ()
9525 "Insert a subnature declaration."
9526 (interactive)
9527 (let ((start (point))
9528 position)
9529 (vhdl-insert-keyword "SUBNATURE ")
9530 (when (vhdl-template-field "name" nil t start (point))
9531 (vhdl-insert-keyword " IS ")
9532 (vhdl-template-field "nature" " (")
9533 (if (vhdl-template-field "[index range]" nil t)
9534 (insert ")")
9535 (delete-char -2))
9536 (setq position (point))
9537 (vhdl-insert-keyword " TOLERANCE ")
9538 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9539 nil t nil nil t))
9540 (delete-region position (point))
9541 (vhdl-insert-keyword " ACROSS ")
9542 (vhdl-template-field "string expression" nil nil nil nil t)
9543 (vhdl-insert-keyword " THROUGH"))
9544 (insert ";")
9545 (vhdl-comment-insert-inline))))
9546
9547(defun vhdl-template-subprogram-body ()
9548 "Insert a subprogram body."
9549 (interactive)
9550 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9551 (vhdl-template-function-body)
9552 (vhdl-template-procedure-body)))
d2ddb974 9553
5eabfe72
KH
9554(defun vhdl-template-subprogram-decl ()
9555 "Insert a subprogram declaration."
9556 (interactive)
9557 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9558 (vhdl-template-function-decl)
9559 (vhdl-template-procedure-decl)))
9560
9561(defun vhdl-template-subtype ()
d2ddb974
KH
9562 "Insert a subtype declaration."
9563 (interactive)
5eabfe72
KH
9564 (let ((start (point)))
9565 (vhdl-insert-keyword "SUBTYPE ")
9566 (when (vhdl-template-field "name" nil t start (point))
9567 (vhdl-insert-keyword " IS ")
9568 (vhdl-template-field "type" " ")
9569 (unless
9570 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
d2ddb974 9571 (delete-char -1))
5eabfe72
KH
9572 (insert ";")
9573 (vhdl-comment-insert-inline))))
d2ddb974 9574
5eabfe72
KH
9575(defun vhdl-template-terminal ()
9576 "Insert a terminal declaration."
d2ddb974 9577 (interactive)
5eabfe72
KH
9578 (let ((start (point)))
9579 (vhdl-insert-keyword "TERMINAL ")
9580 (when (vhdl-template-field "names" nil t start (point))
9581 (insert " : ")
9582 (vhdl-template-field "nature")
9583 (insert ";")
9584 (vhdl-comment-insert-inline))))
d2ddb974 9585
5eabfe72
KH
9586(defun vhdl-template-type ()
9587 "Insert a type declaration."
9588 (interactive)
9589 (let ((start (point))
9590 name mid-pos end-pos)
9591 (vhdl-insert-keyword "TYPE ")
9592 (when (setq name (vhdl-template-field "name" nil t start (point)))
9593 (vhdl-insert-keyword " IS ")
9594 (let ((definition
9595 (upcase
9596 (or (vhdl-template-field
9597 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9598 ""))))
9599 (cond ((equal definition "")
3dcb36b7 9600 (delete-backward-char 4)
5eabfe72
KH
9601 (insert ";"))
9602 ((equal definition "ARRAY")
9603 (kill-word -1)
9604 (vhdl-template-array 'type t))
9605 ((equal definition "RECORD")
9606 (setq mid-pos (point-marker))
9607 (kill-word -1)
9608 (vhdl-template-record 'type name t))
9609 ((equal definition "ACCESS")
9610 (insert " ")
9611 (vhdl-template-field "type" ";"))
9612 ((equal definition "FILE")
9613 (vhdl-insert-keyword " OF ")
9614 (vhdl-template-field "type" ";"))
9615 (t (insert ";")))
9616 (when mid-pos
9617 (setq end-pos (point-marker))
9618 (goto-char mid-pos)
9619 (end-of-line))
9620 (vhdl-comment-insert-inline)
9621 (when end-pos (goto-char end-pos))))))
9622
9623(defun vhdl-template-use ()
d2ddb974
KH
9624 "Insert a use clause."
9625 (interactive)
3dcb36b7
JB
9626 (let ((start (point)))
9627 (vhdl-prepare-search-1
5eabfe72
KH
9628 (vhdl-insert-keyword "USE ")
9629 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9630 (vhdl-insert-keyword "..ALL;")
9631 (backward-char 6)
9632 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9633 (forward-char 1)
9634 (vhdl-template-field "package name")
9635 (forward-char 5))))))
9636
9637(defun vhdl-template-variable ()
d2ddb974
KH
9638 "Insert a variable declaration."
9639 (interactive)
5eabfe72 9640 (let ((start (point))
5eabfe72 9641 (in-arglist (vhdl-in-argument-list-p)))
3dcb36b7 9642 (vhdl-prepare-search-2
5eabfe72 9643 (if (or (save-excursion
3dcb36b7 9644 (and (vhdl-re-search-backward
5eabfe72
KH
9645 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9646 nil t)
9647 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9648 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9649 (vhdl-insert-keyword "VARIABLE ")
9650 (vhdl-insert-keyword "SHARED VARIABLE ")))
9651 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9652 (insert " : ")
5eabfe72
KH
9653 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9654 (vhdl-template-field "type")
d2ddb974 9655 (if in-arglist
5eabfe72
KH
9656 (progn (insert ";")
9657 (vhdl-comment-insert-inline))
d2ddb974
KH
9658 (let ((position (point)))
9659 (insert " := ")
5eabfe72
KH
9660 (unless (vhdl-template-field "[initialization]" nil t)
9661 (delete-region position (point)))
9662 (insert ";")
9663 (vhdl-comment-insert-inline))))))
d2ddb974 9664
5eabfe72 9665(defun vhdl-template-wait ()
d2ddb974
KH
9666 "Insert a wait statement."
9667 (interactive)
9668 (vhdl-insert-keyword "WAIT ")
5eabfe72
KH
9669 (unless (vhdl-template-field
9670 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9671 nil t)
9672 (delete-char -1))
9673 (insert ";"))
d2ddb974 9674
5eabfe72 9675(defun vhdl-template-when ()
d2ddb974
KH
9676 "Indent correctly if within a case statement."
9677 (interactive)
9678 (let ((position (point))
5eabfe72 9679 margin)
3dcb36b7 9680 (vhdl-prepare-search-2
5eabfe72 9681 (if (and (= (current-column) (current-indentation))
3dcb36b7 9682 (vhdl-re-search-forward "\\<end\\>" nil t)
5eabfe72
KH
9683 (looking-at "\\s-*\\<case\\>"))
9684 (progn
9685 (setq margin (current-indentation))
9686 (goto-char position)
9687 (delete-horizontal-space)
9688 (indent-to (+ margin vhdl-basic-offset)))
9689 (goto-char position)))
9690 (vhdl-insert-keyword "WHEN ")))
9691
9692(defun vhdl-template-while-loop ()
9693 "Insert a while loop."
d2ddb974 9694 (interactive)
5eabfe72
KH
9695 (let* ((margin (current-indentation))
9696 (start (point))
9697 label)
9698 (if (not (eq vhdl-optional-labels 'all))
9699 (vhdl-insert-keyword "WHILE ")
9700 (vhdl-insert-keyword ": WHILE ")
9701 (goto-char start)
9702 (setq label (vhdl-template-field "[label]" nil t))
9703 (unless label (delete-char 2))
9704 (forward-word 1)
9705 (forward-char 1))
9706 (when vhdl-conditions-in-parenthesis (insert "("))
9707 (when (vhdl-template-field "condition" nil t start (point))
9708 (when vhdl-conditions-in-parenthesis (insert ")"))
d2ddb974
KH
9709 (vhdl-insert-keyword " LOOP\n\n")
9710 (indent-to margin)
9711 (vhdl-insert-keyword "END LOOP")
5eabfe72 9712 (insert (if label (concat " " label ";") ";"))
d2ddb974 9713 (forward-line -1)
5eabfe72 9714 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 9715
5eabfe72 9716(defun vhdl-template-with ()
d2ddb974
KH
9717 "Insert a with statement (i.e. selected signal assignment)."
9718 (interactive)
3dcb36b7
JB
9719 (vhdl-prepare-search-1
9720 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9721 (equal ";" (match-string 1)))
9722 (vhdl-template-selected-signal-asst)
9723 (vhdl-insert-keyword "WITH "))))
5eabfe72
KH
9724
9725;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9726;; Special templates
9727
9728(defun vhdl-template-clocked-wait ()
9729 "Insert a wait statement for rising/falling clock edge."
9730 (interactive)
9731 (let ((start (point))
9732 clock)
9733 (vhdl-insert-keyword "WAIT UNTIL ")
9734 (when (setq clock
9735 (or (and (not (equal "" vhdl-clock-name))
9736 (progn (insert vhdl-clock-name) vhdl-clock-name))
9737 (vhdl-template-field "clock name" nil t start (point))))
9738 (insert "'event")
9739 (vhdl-insert-keyword " AND ")
9740 (insert clock)
9741 (insert
9742 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9743 (vhdl-comment-insert-inline
9744 (concat (if vhdl-clock-rising-edge "rising" "falling")
9745 " clock edge")))))
9746
9747(defun vhdl-template-seq-process (clock reset)
9748 "Insert a template for the body of a sequential process."
9749 (let ((margin (current-indentation))
9750 position)
d2ddb974 9751 (vhdl-insert-keyword "IF ")
5eabfe72
KH
9752 (when (eq vhdl-reset-kind 'async)
9753 (insert reset " = "
9754 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9755 (vhdl-insert-keyword " THEN")
9756 (vhdl-comment-insert-inline
9757 (concat "asynchronous reset (active "
9758 (if vhdl-reset-active-high "high" "low") ")"))
9759 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9760 (setq position (point))
9761 (insert "\n") (indent-to margin)
9762 (vhdl-insert-keyword "ELSIF "))
9763 (if (eq vhdl-clock-edge-condition 'function)
9764 (insert (if vhdl-clock-rising-edge "rising" "falling")
9765 "_edge(" clock ")")
9766 (insert clock "'event")
9767 (vhdl-insert-keyword " AND ")
9768 (insert clock " = "
9769 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9770 (vhdl-insert-keyword " THEN")
9771 (vhdl-comment-insert-inline
9772 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9773 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9774 (when (eq vhdl-reset-kind 'sync)
9775 (vhdl-insert-keyword "IF ")
9776 (setq reset (or (and (not (equal "" vhdl-reset-name))
9777 (progn (insert vhdl-reset-name) vhdl-reset-name))
9778 (vhdl-template-field "reset name") "<reset>"))
9779 (insert " = "
9780 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9781 (vhdl-insert-keyword " THEN")
9782 (vhdl-comment-insert-inline
9783 (concat "synchronous reset (active "
9784 (if vhdl-reset-active-high "high" "low") ")"))
9785 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9786 (setq position (point))
9787 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9788 (vhdl-insert-keyword "ELSE")
9789 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9790 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9791 (vhdl-insert-keyword "END IF;"))
9792 (when (eq vhdl-reset-kind 'none)
9793 (setq position (point)))
9794 (insert "\n") (indent-to margin)
d2ddb974 9795 (vhdl-insert-keyword "END IF;")
5eabfe72
KH
9796 (goto-char position)
9797 reset))
d2ddb974 9798
5eabfe72
KH
9799(defun vhdl-template-standard-package (library package)
9800 "Insert specification of a standard package. Include a library
9801specification, if not already there."
3dcb36b7
JB
9802 (let ((margin (current-indentation)))
9803 (unless (equal library "std")
9804 (unless (or (save-excursion
9805 (vhdl-prepare-search-1
9806 (and (not (bobp))
9807 (re-search-backward
9808 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9809 library "\\|end\\)\\>") nil t)
9810 (match-string 2))))
9811 (equal (downcase library) "work"))
9812 (vhdl-insert-keyword "LIBRARY ")
0a2e512a
RF
9813 (insert library ";")
9814 (when package
9815 (insert "\n")
9816 (indent-to margin)))
9817 (when package
9818 (vhdl-insert-keyword "USE ")
9819 (insert library "." package)
9820 (vhdl-insert-keyword ".ALL;")))))
d2ddb974 9821
5eabfe72
KH
9822(defun vhdl-template-package-math-complex ()
9823 "Insert specification of `math_complex' package."
d2ddb974 9824 (interactive)
5eabfe72 9825 (vhdl-template-standard-package "ieee" "math_complex"))
d2ddb974 9826
5eabfe72
KH
9827(defun vhdl-template-package-math-real ()
9828 "Insert specification of `math_real' package."
d2ddb974 9829 (interactive)
5eabfe72 9830 (vhdl-template-standard-package "ieee" "math_real"))
d2ddb974 9831
5eabfe72
KH
9832(defun vhdl-template-package-numeric-bit ()
9833 "Insert specification of `numeric_bit' package."
d2ddb974 9834 (interactive)
5eabfe72 9835 (vhdl-template-standard-package "ieee" "numeric_bit"))
d2ddb974 9836
5eabfe72
KH
9837(defun vhdl-template-package-numeric-std ()
9838 "Insert specification of `numeric_std' package."
d2ddb974 9839 (interactive)
5eabfe72 9840 (vhdl-template-standard-package "ieee" "numeric_std"))
d2ddb974 9841
5eabfe72
KH
9842(defun vhdl-template-package-std-logic-1164 ()
9843 "Insert specification of `std_logic_1164' package."
9844 (interactive)
9845 (vhdl-template-standard-package "ieee" "std_logic_1164"))
d2ddb974 9846
5eabfe72
KH
9847(defun vhdl-template-package-std-logic-arith ()
9848 "Insert specification of `std_logic_arith' package."
9849 (interactive)
9850 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9851
9852(defun vhdl-template-package-std-logic-misc ()
9853 "Insert specification of `std_logic_misc' package."
9854 (interactive)
9855 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9856
9857(defun vhdl-template-package-std-logic-signed ()
9858 "Insert specification of `std_logic_signed' package."
9859 (interactive)
9860 (vhdl-template-standard-package "ieee" "std_logic_signed"))
d2ddb974 9861
5eabfe72
KH
9862(defun vhdl-template-package-std-logic-textio ()
9863 "Insert specification of `std_logic_textio' package."
9864 (interactive)
9865 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9866
9867(defun vhdl-template-package-std-logic-unsigned ()
9868 "Insert specification of `std_logic_unsigned' package."
9869 (interactive)
9870 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9871
9872(defun vhdl-template-package-textio ()
9873 "Insert specification of `textio' package."
9874 (interactive)
9875 (vhdl-template-standard-package "std" "textio"))
9876
9877(defun vhdl-template-directive (directive)
9878 "Insert directive."
9879 (unless (= (current-indentation) (current-column))
9880 (delete-horizontal-space)
9881 (insert " "))
9882 (insert "-- pragma " directive))
9883
9884(defun vhdl-template-directive-translate-on ()
9885 "Insert directive 'translate_on'."
9886 (interactive)
9887 (vhdl-template-directive "translate_on"))
9888
9889(defun vhdl-template-directive-translate-off ()
9890 "Insert directive 'translate_off'."
9891 (interactive)
9892 (vhdl-template-directive "translate_off"))
9893
9894(defun vhdl-template-directive-synthesis-on ()
9895 "Insert directive 'synthesis_on'."
9896 (interactive)
9897 (vhdl-template-directive "synthesis_on"))
9898
9899(defun vhdl-template-directive-synthesis-off ()
9900 "Insert directive 'synthesis_off'."
9901 (interactive)
9902 (vhdl-template-directive "synthesis_off"))
9903
3dcb36b7
JB
9904;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9905;; Header and footer templates
9906
9907(defun vhdl-template-header (&optional file-title)
9908 "Insert a VHDL file header."
9909 (interactive)
9910 (unless (equal vhdl-file-header "")
9911 (let (pos)
9912 (save-excursion
9913 (goto-char (point-min))
9914 (vhdl-insert-string-or-file vhdl-file-header)
9915 (setq pos (point-marker)))
9916 (vhdl-template-replace-header-keywords
9917 (point-min-marker) pos file-title))))
9918
9919(defun vhdl-template-footer ()
9920 "Insert a VHDL file footer."
9921 (interactive)
9922 (unless (equal vhdl-file-footer "")
9923 (let (pos)
9924 (save-excursion
9925 (goto-char (point-max))
9926 (setq pos (point-marker))
9927 (vhdl-insert-string-or-file vhdl-file-footer)
9928 (unless (= (preceding-char) ?\n)
9929 (insert "\n")))
9930 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9931
9932(defun vhdl-template-replace-header-keywords (beg end &optional file-title
9933 is-model)
9934 "Replace keywords in header and footer."
9935 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9936 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9937 pos)
9938 (vhdl-prepare-search-2
9939 (save-excursion
9940 (goto-char beg)
9941 (while (search-forward "<projectdesc>" end t)
9942 (replace-match project-desc t t))
9943 (goto-char beg)
9944 (while (search-forward "<filename>" end t)
9945 (replace-match (buffer-name) t t))
9946 (goto-char beg)
9947 (while (search-forward "<copyright>" end t)
9948 (replace-match vhdl-copyright-string t t))
9949 (goto-char beg)
9950 (while (search-forward "<author>" end t)
9951 (replace-match "" t t)
9952 (insert (user-full-name))
9953 (when user-mail-address (insert " <" user-mail-address ">")))
9954 (goto-char beg)
9955 (while (search-forward "<login>" end t)
9956 (replace-match (user-login-name) t t))
9957 (goto-char beg)
9958 (while (search-forward "<project>" end t)
9959 (replace-match project-title t t))
9960 (goto-char beg)
9961 (while (search-forward "<company>" end t)
9962 (replace-match vhdl-company-name t t))
9963 (goto-char beg)
9964 (while (search-forward "<platform>" end t)
9965 (replace-match vhdl-platform-spec t t))
9966 (goto-char beg)
9967 (while (search-forward "<standard>" end t)
9968 (replace-match
9969 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9970 ((vhdl-standard-p '93) "'93"))
9971 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9972 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9973 (goto-char beg)
9974 ;; Replace <RCS> with $, so that RCS for the source is
9975 ;; not over-enthusiastic with replacements
9976 (while (search-forward "<RCS>" end t)
9977 (replace-match "$" nil t))
9978 (goto-char beg)
9979 (while (search-forward "<date>" end t)
9980 (replace-match "" t t)
9981 (vhdl-template-insert-date))
9982 (goto-char beg)
9983 (while (search-forward "<year>" end t)
9984 (replace-match (format-time-string "%Y" nil) t t))
9985 (goto-char beg)
9986 (when file-title
9987 (while (search-forward "<title string>" end t)
9988 (replace-match file-title t t))
9989 (goto-char beg))
9990 (let (string)
9991 (while
9992 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9993 (setq string (read-string (concat (match-string 1) ": ")))
9994 (replace-match string t t)))
9995 (goto-char beg)
9996 (when (and (not is-model) (search-forward "<cursor>" end t))
9997 (replace-match "" t t)
9998 (setq pos (point))))
9999 (when pos (goto-char pos))
10000 (unless is-model
10001 (when (or (not project-title) (equal project-title ""))
10002 (message "You can specify a project title in user option `vhdl-project-alist'"))
10003 (when (or (not project-desc) (equal project-desc ""))
10004 (message "You can specify a project description in user option `vhdl-project-alist'"))
10005 (when (equal vhdl-platform-spec "")
10006 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10007 (when (equal vhdl-company-name "")
10008 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10009
5eabfe72
KH
10010;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10011;; Comment templates and functions
10012
10013(defun vhdl-comment-indent ()
10014 "Indent comments."
10015 (let* ((position (point))
10016 (col
10017 (progn
10018 (forward-line -1)
10019 (if (re-search-forward "--" position t)
10020 (- (current-column) 2) ; existing comment at bol stays there
10021 (goto-char position)
10022 (skip-chars-backward " \t")
10023 (max comment-column ; else indent to comment column
10024 (1+ (current-column))))))) ; except leave at least one space
10025 (goto-char position)
10026 col))
10027
10028(defun vhdl-comment-insert ()
d2ddb974 10029 "Start a comment at the end of the line.
5eabfe72
KH
10030If on line with code, indent at least `comment-column'.
10031If starting after end-comment-column, start a new line."
d2ddb974 10032 (interactive)
5eabfe72
KH
10033 (when (> (current-column) end-comment-column) (newline-and-indent))
10034 (if (or (looking-at "\\s-*$") ; end of line
d2ddb974
KH
10035 (and (not unread-command-events) ; called with key binding or menu
10036 (not (end-of-line))))
5eabfe72
KH
10037 (let (margin)
10038 (while (= (preceding-char) ?-) (delete-char -1))
d2ddb974 10039 (setq margin (current-column))
5eabfe72
KH
10040 (delete-horizontal-space)
10041 (if (bolp)
10042 (progn (indent-to margin) (insert "--"))
d2ddb974 10043 (insert " ")
5eabfe72
KH
10044 (indent-to comment-column)
10045 (insert "--"))
d2ddb974 10046 (if (not unread-command-events) (insert " ")))
5eabfe72 10047 ;; else code following current point implies commenting out code
d2ddb974
KH
10048 (let (next-input code)
10049 (while (= (preceding-char) ?-) (delete-char -2))
10050 (while (= (setq next-input (read-char)) 13) ; CR
5eabfe72 10051 (insert "--") ; or have a space after it?
d2ddb974
KH
10052 (forward-char -2)
10053 (forward-line 1)
10054 (message "Enter CR if commenting out a line of code.")
5eabfe72 10055 (setq code t))
3dcb36b7 10056 (unless code
5eabfe72 10057 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
d2ddb974 10058 (setq unread-command-events
5eabfe72 10059 (list (vhdl-character-to-event next-input)))))) ; pushback the char
d2ddb974 10060
5eabfe72 10061(defun vhdl-comment-display (&optional line-exists)
d2ddb974
KH
10062 "Add 2 comment lines at the current indent, making a display comment."
10063 (interactive)
5eabfe72 10064 (let ((margin (current-indentation)))
3dcb36b7 10065 (unless line-exists (vhdl-comment-display-line))
5eabfe72
KH
10066 (insert "\n") (indent-to margin)
10067 (insert "\n") (indent-to margin)
10068 (vhdl-comment-display-line)
10069 (end-of-line -0)
10070 (insert "-- ")))
10071
10072(defun vhdl-comment-display-line ()
d2ddb974
KH
10073 "Displays one line of dashes."
10074 (interactive)
10075 (while (= (preceding-char) ?-) (delete-char -2))
10076 (let* ((col (current-column))
10077 (len (- end-comment-column col)))
5eabfe72 10078 (insert-char ?- len)))
d2ddb974 10079
5eabfe72
KH
10080(defun vhdl-comment-append-inline ()
10081 "Append empty inline comment to current line."
10082 (interactive)
10083 (end-of-line)
10084 (delete-horizontal-space)
10085 (insert " ")
10086 (indent-to comment-column)
10087 (insert "-- "))
10088
10089(defun vhdl-comment-insert-inline (&optional string always-insert)
10090 "Insert inline comment."
10091 (when (or (and string (or vhdl-self-insert-comments always-insert))
10092 (and (not string) vhdl-prompt-for-comments))
10093 (let ((position (point)))
10094 (insert " ")
10095 (indent-to comment-column)
10096 (insert "-- ")
3dcb36b7
JB
10097 (if (not (or (and string (progn (insert string) t))
10098 (vhdl-template-field "[comment]" nil t)))
10099 (delete-region position (point))
10100 (while (= (preceding-char) ? ) (delete-backward-char 1))
10101; (when (> (current-column) end-comment-column)
10102; (setq position (point-marker))
10103; (re-search-backward "-- ")
10104; (insert "\n")
10105; (indent-to comment-column)
10106; (goto-char position))
10107 ))))
5eabfe72
KH
10108
10109(defun vhdl-comment-block ()
10110 "Insert comment for code block."
10111 (when vhdl-prompt-for-comments
3dcb36b7
JB
10112 (let ((final-pos (point-marker)))
10113 (vhdl-prepare-search-2
5eabfe72 10114 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
3dcb36b7 10115 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
5eabfe72
KH
10116 (let (margin)
10117 (back-to-indentation)
10118 (setq margin (current-column))
10119 (end-of-line -0)
10120 (if (bobp)
10121 (progn (insert "\n") (forward-line -1))
10122 (insert "\n"))
10123 (indent-to margin)
10124 (insert "-- purpose: ")
10125 (unless (vhdl-template-field "[description]" nil t)
10126 (vhdl-line-kill-entire)))))
10127 (goto-char final-pos))))
d2ddb974
KH
10128
10129(defun vhdl-comment-uncomment-region (beg end &optional arg)
5eabfe72 10130 "Comment out region if not commented out, uncomment otherwise."
d2ddb974 10131 (interactive "r\nP")
5eabfe72
KH
10132 (save-excursion
10133 (goto-char (1- end))
10134 (end-of-line)
10135 (setq end (point-marker))
10136 (goto-char beg)
10137 (beginning-of-line)
10138 (setq beg (point))
10139 (if (looking-at comment-start)
3dcb36b7 10140 (comment-region beg end '(4))
5eabfe72
KH
10141 (comment-region beg end))))
10142
10143(defun vhdl-comment-uncomment-line (&optional arg)
10144 "Comment out line if not commented out, uncomment otherwise."
d2ddb974 10145 (interactive "p")
5eabfe72
KH
10146 (save-excursion
10147 (beginning-of-line)
10148 (let ((position (point)))
10149 (forward-line (or arg 1))
10150 (vhdl-comment-uncomment-region position (point)))))
d2ddb974 10151
5eabfe72
KH
10152(defun vhdl-comment-kill-region (beg end)
10153 "Kill comments in region."
10154 (interactive "r")
10155 (save-excursion
10156 (goto-char end)
10157 (setq end (point-marker))
10158 (goto-char beg)
10159 (beginning-of-line)
10160 (while (< (point) end)
10161 (if (looking-at "^\\(\\s-*--.*\n\\)")
10162 (progn (delete-region (match-beginning 1) (match-end 1)))
10163 (beginning-of-line 2)))))
10164
10165(defun vhdl-comment-kill-inline-region (beg end)
10166 "Kill inline comments in region."
10167 (interactive "r")
10168 (save-excursion
10169 (goto-char end)
10170 (setq end (point-marker))
10171 (goto-char beg)
10172 (beginning-of-line)
10173 (while (< (point) end)
10174 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
10175 (delete-region (match-beginning 1) (match-end 1)))
10176 (beginning-of-line 2))))
10177
10178;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10179;; Subtemplates
10180
10181(defun vhdl-template-begin-end (construct name margin &optional empty-lines)
d2ddb974
KH
10182 "Insert a begin ... end pair with optional name after the end.
10183Point is left between them."
5eabfe72 10184 (let (position)
5eabfe72 10185 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10186 (indent-to margin)
10187 (vhdl-insert-keyword "BEGIN")
5eabfe72
KH
10188 (when (and (or construct name) vhdl-self-insert-comments)
10189 (insert " --")
10190 (when construct (insert " ") (vhdl-insert-keyword construct))
10191 (when name (insert " " name)))
d2ddb974 10192 (insert "\n")
5eabfe72 10193 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974 10194 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
10195 (setq position (point))
10196 (insert "\n")
10197 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10198 (indent-to margin)
10199 (vhdl-insert-keyword "END")
5eabfe72
KH
10200 (when construct (insert " ") (vhdl-insert-keyword construct))
10201 (insert (if name (concat " " name) "") ";")
10202 (goto-char position)))
d2ddb974 10203
5eabfe72 10204(defun vhdl-template-argument-list (&optional is-function)
d2ddb974
KH
10205 "Read from user a procedure or function argument list."
10206 (insert " (")
d2ddb974 10207 (let ((margin (current-column))
5eabfe72
KH
10208 (start (point))
10209 (end-pos (point))
10210 not-empty interface semicolon-pos)
3dcb36b7 10211 (unless vhdl-argument-list-indent
5eabfe72
KH
10212 (setq margin (+ (current-indentation) vhdl-basic-offset))
10213 (insert "\n")
10214 (indent-to margin))
10215 (setq interface (vhdl-template-field
10216 (concat "[CONSTANT | SIGNAL"
10217 (unless is-function " | VARIABLE") "]") " " t))
10218 (while (vhdl-template-field "[names]" nil t)
10219 (setq not-empty t)
10220 (insert " : ")
3dcb36b7 10221 (unless is-function
5eabfe72
KH
10222 (if (and interface (equal (upcase interface) "CONSTANT"))
10223 (vhdl-insert-keyword "IN ")
10224 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10225 (vhdl-template-field "type")
10226 (setq semicolon-pos (point))
10227 (insert ";")
10228 (vhdl-comment-insert-inline)
10229 (setq end-pos (point))
10230 (insert "\n")
10231 (indent-to margin)
10232 (setq interface (vhdl-template-field
10233 (concat "[CONSTANT | SIGNAL"
10234 (unless is-function " | VARIABLE") "]") " " t)))
10235 (delete-region end-pos (point))
10236 (when semicolon-pos (goto-char semicolon-pos))
10237 (if not-empty
10238 (progn (delete-char 1) (insert ")"))
3dcb36b7 10239 (delete-backward-char 2))))
5eabfe72
KH
10240
10241(defun vhdl-template-generic-list (optional &optional no-value)
d2ddb974 10242 "Read from user a generic spec argument list."
5eabfe72 10243 (let (margin
d2ddb974 10244 (start (point)))
5eabfe72
KH
10245 (vhdl-insert-keyword "GENERIC (")
10246 (setq margin (current-column))
3dcb36b7 10247 (unless vhdl-argument-list-indent
5eabfe72
KH
10248 (let ((position (point)))
10249 (back-to-indentation)
10250 (setq margin (+ (current-column) vhdl-basic-offset))
10251 (goto-char position)
10252 (insert "\n")
10253 (indent-to margin)))
10254 (let ((vhdl-generics (vhdl-template-field
10255 (concat (and optional "[") "name"
10256 (and no-value "s") (and optional "]"))
10257 nil optional)))
10258 (if (not vhdl-generics)
d2ddb974 10259 (if optional
5eabfe72 10260 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10261 (unless vhdl-argument-list-indent
5eabfe72
KH
10262 (vhdl-line-kill-entire) (end-of-line -0)))
10263 (vhdl-template-undo start (point))
d2ddb974
KH
10264 nil )
10265 (insert " : ")
5eabfe72
KH
10266 (let (semicolon-pos end-pos)
10267 (while vhdl-generics
10268 (vhdl-template-field "type")
10269 (if no-value
10270 (progn (setq semicolon-pos (point))
10271 (insert ";"))
10272 (insert " := ")
10273 (unless (vhdl-template-field "[value]" nil t)
10274 (delete-char -4))
10275 (setq semicolon-pos (point))
10276 (insert ";"))
10277 (vhdl-comment-insert-inline)
10278 (setq end-pos (point))
10279 (insert "\n")
10280 (indent-to margin)
10281 (setq vhdl-generics (vhdl-template-field
10282 (concat "[name" (and no-value "s") "]")
10283 " : " t)))
10284 (delete-region end-pos (point))
10285 (goto-char semicolon-pos)
10286 (insert ")")
10287 (end-of-line)
3dcb36b7 10288 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
10289 t)))))
10290
10291(defun vhdl-template-port-list (optional)
10292 "Read from user a port spec argument list."
10293 (let ((start (point))
10294 margin vhdl-ports object)
10295 (vhdl-insert-keyword "PORT (")
10296 (setq margin (current-column))
3dcb36b7 10297 (unless vhdl-argument-list-indent
5eabfe72
KH
10298 (let ((position (point)))
10299 (back-to-indentation)
10300 (setq margin (+ (current-column) vhdl-basic-offset))
10301 (goto-char position)
10302 (insert "\n")
10303 (indent-to margin)))
10304 (when (vhdl-standard-p 'ams)
10305 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10306 " " t)))
10307 (setq vhdl-ports (vhdl-template-field
10308 (concat (and optional "[") "names" (and optional "]"))
10309 nil optional))
10310 (if (not vhdl-ports)
10311 (if optional
10312 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10313 (unless vhdl-argument-list-indent
5eabfe72
KH
10314 (vhdl-line-kill-entire) (end-of-line -0)))
10315 (vhdl-template-undo start (point))
10316 nil)
10317 (insert " : ")
10318 (let (semicolon-pos end-pos)
10319 (while vhdl-ports
10320 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10321 (vhdl-template-field "IN | OUT | INOUT" " "))
10322 ((equal "QUANTITY" (upcase object))
10323 (vhdl-template-field "[IN | OUT]" " " t)))
10324 (vhdl-template-field
10325 (if (and object (equal "TERMINAL" (upcase object)))
10326 "nature" "type"))
10327 (setq semicolon-pos (point))
10328 (insert ";")
10329 (vhdl-comment-insert-inline)
10330 (setq end-pos (point))
10331 (insert "\n")
10332 (indent-to margin)
10333 (when (vhdl-standard-p 'ams)
10334 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10335 " " t)))
10336 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10337 (delete-region end-pos (point))
10338 (goto-char semicolon-pos)
10339 (insert ")")
10340 (end-of-line)
3dcb36b7 10341 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
5eabfe72
KH
10342 t))))
10343
10344(defun vhdl-template-generate-body (margin label)
10345 "Insert body for generate template."
10346 (vhdl-insert-keyword " GENERATE")
3dcb36b7
JB
10347; (if (not (vhdl-standard-p '87))
10348; (vhdl-template-begin-end "GENERATE" label margin)
10349 (insert "\n\n")
10350 (indent-to margin)
10351 (vhdl-insert-keyword "END GENERATE ")
10352 (insert label ";")
10353 (end-of-line 0)
10354 (indent-to (+ margin vhdl-basic-offset)))
5eabfe72
KH
10355
10356(defun vhdl-template-insert-date ()
d2ddb974
KH
10357 "Insert date in appropriate format."
10358 (interactive)
5eabfe72
KH
10359 (insert
10360 (cond
3dcb36b7 10361 ;; 'american, 'european, 'scientific kept for backward compatibility
5eabfe72
KH
10362 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10363 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10364 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10365 (t (format-time-string vhdl-date-format nil)))))
10366
10367;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10368;; Help functions
10369
10370(defun vhdl-electric-space (count)
10371 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10372if in comment and past end-comment-column."
10373 (interactive "p")
10374 (cond ((vhdl-in-comment-p)
10375 (self-insert-command count)
10376 (cond ((>= (current-column) (+ 2 end-comment-column))
3dcb36b7
JB
10377 (backward-char 1)
10378 (skip-chars-backward "^ \t\n")
5eabfe72 10379 (indent-new-comment-line)
3dcb36b7 10380 (skip-chars-forward "^ \t\n")
5eabfe72
KH
10381 (forward-char 1))
10382 ((>= (current-column) end-comment-column)
10383 (indent-new-comment-line))
10384 (t nil)))
10385 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10386 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
3dcb36b7
JB
10387 (vhdl-prepare-search-1
10388 (or (expand-abbrev) (vhdl-fix-case-word -1)))
5eabfe72
KH
10389 (self-insert-command count))
10390 (t (self-insert-command count))))
10391
10392(defun vhdl-template-field (prompt &optional follow-string optional
10393 begin end is-string default)
10394 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10395If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10396an empty string is inserted, return nil and call `vhdl-template-undo' for
10397the region between BEGIN and END. IS-STRING indicates whether a string
10398with double-quotes is to be inserted. DEFAULT specifies a default string."
10399 (let ((position (point))
10400 string)
10401 (insert "<" prompt ">")
10402 (setq string
10403 (condition-case ()
10404 (read-from-minibuffer (concat prompt ": ")
10405 (or (and is-string '("\"\"" . 2)) default)
10406 vhdl-minibuffer-local-map)
10407 (quit (if (and optional begin end)
10408 (progn (beep) "")
10409 (keyboard-quit)))))
10410 (when (or (not (equal string "")) optional)
10411 (delete-region position (point)))
10412 (when (and (equal string "") optional begin end)
10413 (vhdl-template-undo begin end)
10414 (message "Template aborted"))
3dcb36b7 10415 (unless (equal string "")
5eabfe72
KH
10416 (insert string)
10417 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
3dcb36b7
JB
10418 vhdl-keywords-regexp)
10419 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10420 vhdl-types-regexp)
10421 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10422 (concat "'" vhdl-attributes-regexp))
10423 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10424 vhdl-enum-values-regexp))
5eabfe72
KH
10425 (when (or (not (equal string "")) (not optional))
10426 (insert (or follow-string "")))
10427 (if (equal string "") nil string)))
10428
10429(defun vhdl-decision-query (string prompt &optional optional)
10430 "Query a decision from the user."
10431 (let ((start (point)))
10432 (when string (vhdl-insert-keyword (concat string " ")))
10433 (message prompt)
10434 (let ((char (read-char)))
10435 (delete-region start (point))
10436 (if (and optional (eq char ?\r))
10437 (progn (insert " ")
10438 (unexpand-abbrev)
3dcb36b7 10439 (throw 'abort "ERROR: Template aborted"))
5eabfe72 10440 char))))
d2ddb974
KH
10441
10442(defun vhdl-insert-keyword (keyword)
5eabfe72
KH
10443 "Insert KEYWORD and adjust case."
10444 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
d2ddb974
KH
10445
10446(defun vhdl-case-keyword (keyword)
5eabfe72
KH
10447 "Adjust case of KEYWORD."
10448 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
d2ddb974
KH
10449
10450(defun vhdl-case-word (num)
5eabfe72
KH
10451 "Adjust case or following NUM words."
10452 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10453
10454(defun vhdl-minibuffer-tab (&optional prefix-arg)
10455 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7 10456else insert tab (used for word completion in VHDL minibuffer)."
5eabfe72 10457 (interactive "P")
3dcb36b7
JB
10458 (cond
10459 ;; expand word
10460 ((= (char-syntax (preceding-char)) ?w)
10461 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10462 (case-replace nil)
10463 (hippie-expand-only-buffers
10464 (or (and (boundp 'hippie-expand-only-buffers)
10465 hippie-expand-only-buffers)
10466 '(vhdl-mode))))
10467 (vhdl-expand-abbrev prefix-arg)))
10468 ;; expand parenthesis
10469 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10470 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10471 (case-replace nil))
10472 (vhdl-expand-paren prefix-arg)))
10473 ;; insert tab
10474 (t (insert-tab))))
5eabfe72
KH
10475
10476(defun vhdl-template-search-prompt ()
10477 "Search for left out template prompts and query again."
10478 (interactive)
3dcb36b7
JB
10479 (vhdl-prepare-search-2
10480 (when (or (re-search-forward
10481 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10482 (re-search-backward
10483 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10484 (let ((string (match-string 1)))
10485 (replace-match "")
10486 (vhdl-template-field string)))))
5eabfe72
KH
10487
10488(defun vhdl-template-undo (begin end)
10489 "Undo aborted template by deleting region and unexpanding the keyword."
10490 (cond (vhdl-template-invoked-by-hook
10491 (goto-char end)
10492 (insert " ")
10493 (delete-region begin end)
10494 (unexpand-abbrev))
10495 (t (delete-region begin end))))
10496
10497(defun vhdl-insert-string-or-file (string)
10498 "Insert STRING or file contents if STRING is an existing file name."
10499 (unless (equal string "")
3dcb36b7
JB
10500 (let ((file-name
10501 (progn (string-match "^\\([^\n]+\\)" string)
10502 (vhdl-resolve-env-variable (match-string 1 string)))))
10503 (if (file-exists-p file-name)
10504 (forward-char (cadr (insert-file-contents file-name)))
10505 (insert string)))))
10506
10507(defun vhdl-beginning-of-block ()
10508 "Move cursor to the beginning of the enclosing block."
10509 (let (pos)
10510 (save-excursion
10511 (beginning-of-line)
10512 ;; search backward for block beginning or end
10513 (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))
10514 ;; not consider subprogram declarations
10515 (or (and (match-string 5)
10516 (save-match-data
10517 (save-excursion
10518 (goto-char (match-end 5))
0a2e512a
RF
10519 (forward-word 1)
10520 (vhdl-forward-syntactic-ws)
10521 (when (looking-at "(")
10522 (forward-sexp))
3dcb36b7
JB
10523 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10524 (match-string 1)))
10525 ;; not consider configuration specifications
10526 (and (match-string 6)
10527 (save-match-data
10528 (save-excursion
10529 (vhdl-end-of-block)
10530 (beginning-of-line)
10531 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10532 (match-string 2))
10533 ;; skip subblock if block end found
10534 (vhdl-beginning-of-block)))
10535 (when pos (goto-char pos))))
10536
10537(defun vhdl-end-of-block ()
10538 "Move cursor to the end of the enclosing block."
10539 (let (pos)
10540 (save-excursion
10541 (end-of-line)
10542 ;; search forward for block beginning or end
10543 (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))
10544 ;; not consider subprogram declarations
10545 (or (and (match-string 5)
10546 (save-match-data
10547 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10548 (match-string 1)))
10549 ;; not consider configuration specifications
10550 (and (match-string 6)
10551 (save-match-data
10552 (save-excursion
10553 (vhdl-end-of-block)
10554 (beginning-of-line)
10555 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10556 (not (match-string 2)))
10557 ;; skip subblock if block beginning found
10558 (vhdl-end-of-block)))
10559 (when pos (goto-char pos))))
5eabfe72
KH
10560
10561(defun vhdl-sequential-statement-p ()
10562 "Check if point is within sequential statement part."
3dcb36b7
JB
10563 (let ((start (point)))
10564 (save-excursion
10565 (vhdl-prepare-search-2
10566 ;; is sequential statement if ...
10567 (and (re-search-backward "^\\s-*begin\\>" nil t)
10568 ;; ... point is between "begin" and "end" of ...
10569 (progn (vhdl-end-of-block)
10570 (< start (point)))
10571 ;; ... a sequential block
10572 (progn (vhdl-beginning-of-block)
10573 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
5eabfe72
KH
10574
10575(defun vhdl-in-argument-list-p ()
10576 "Check if within an argument list."
10577 (save-excursion
3dcb36b7
JB
10578 (vhdl-prepare-search-2
10579 (or (string-match "arglist"
10580 (format "%s" (caar (vhdl-get-syntactic-context))))
10581 (progn (beginning-of-line)
10582 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
5eabfe72
KH
10583
10584;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10585;; Abbrev hooks
10586
10587(defun vhdl-hooked-abbrev (func)
10588 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10589but not if inside a comment or quote)."
3dcb36b7 10590 (if (or (vhdl-in-literal)
5eabfe72
KH
10591 (save-excursion
10592 (forward-word -1)
10593 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10594 (progn
10595 (insert " ")
10596 (unexpand-abbrev)
10597 (delete-char -1))
10598 (if (not vhdl-electric-mode)
10599 (progn
10600 (insert " ")
10601 (unexpand-abbrev)
10602 (backward-word 1)
10603 (vhdl-case-word 1)
10604 (delete-char 1))
10605 (let ((invoke-char last-command-char)
10606 (abbrev-mode -1)
10607 (vhdl-template-invoked-by-hook t))
10608 (let ((caught (catch 'abort
10609 (funcall func))))
29a4e67d 10610 (when (stringp caught) (message "%s" caught)))
5eabfe72
KH
10611 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10612 ;; delete CR which is still in event queue
4bcb9c95 10613 (if (fboundp 'enqueue-eval-event)
5eabfe72
KH
10614 (enqueue-eval-event 'delete-char -1)
10615 (setq unread-command-events ; push back a delete char
10616 (list (vhdl-character-to-event ?\177))))))))
10617
10618(defun vhdl-template-alias-hook ()
10619 (vhdl-hooked-abbrev 'vhdl-template-alias))
10620(defun vhdl-template-architecture-hook ()
10621 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10622(defun vhdl-template-assert-hook ()
10623 (vhdl-hooked-abbrev 'vhdl-template-assert))
10624(defun vhdl-template-attribute-hook ()
10625 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10626(defun vhdl-template-block-hook ()
10627 (vhdl-hooked-abbrev 'vhdl-template-block))
10628(defun vhdl-template-break-hook ()
10629 (vhdl-hooked-abbrev 'vhdl-template-break))
10630(defun vhdl-template-case-hook ()
10631 (vhdl-hooked-abbrev 'vhdl-template-case))
10632(defun vhdl-template-component-hook ()
10633 (vhdl-hooked-abbrev 'vhdl-template-component))
10634(defun vhdl-template-instance-hook ()
10635 (vhdl-hooked-abbrev 'vhdl-template-instance))
10636(defun vhdl-template-conditional-signal-asst-hook ()
10637 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10638(defun vhdl-template-configuration-hook ()
10639 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10640(defun vhdl-template-constant-hook ()
10641 (vhdl-hooked-abbrev 'vhdl-template-constant))
10642(defun vhdl-template-disconnect-hook ()
10643 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10644(defun vhdl-template-display-comment-hook ()
10645 (vhdl-hooked-abbrev 'vhdl-comment-display))
10646(defun vhdl-template-else-hook ()
10647 (vhdl-hooked-abbrev 'vhdl-template-else))
10648(defun vhdl-template-elsif-hook ()
10649 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10650(defun vhdl-template-entity-hook ()
10651 (vhdl-hooked-abbrev 'vhdl-template-entity))
10652(defun vhdl-template-exit-hook ()
10653 (vhdl-hooked-abbrev 'vhdl-template-exit))
10654(defun vhdl-template-file-hook ()
10655 (vhdl-hooked-abbrev 'vhdl-template-file))
10656(defun vhdl-template-for-hook ()
10657 (vhdl-hooked-abbrev 'vhdl-template-for))
10658(defun vhdl-template-function-hook ()
10659 (vhdl-hooked-abbrev 'vhdl-template-function))
10660(defun vhdl-template-generic-hook ()
10661 (vhdl-hooked-abbrev 'vhdl-template-generic))
10662(defun vhdl-template-group-hook ()
10663 (vhdl-hooked-abbrev 'vhdl-template-group))
10664(defun vhdl-template-library-hook ()
10665 (vhdl-hooked-abbrev 'vhdl-template-library))
10666(defun vhdl-template-limit-hook ()
10667 (vhdl-hooked-abbrev 'vhdl-template-limit))
10668(defun vhdl-template-if-hook ()
10669 (vhdl-hooked-abbrev 'vhdl-template-if))
10670(defun vhdl-template-bare-loop-hook ()
10671 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10672(defun vhdl-template-map-hook ()
10673 (vhdl-hooked-abbrev 'vhdl-template-map))
10674(defun vhdl-template-nature-hook ()
10675 (vhdl-hooked-abbrev 'vhdl-template-nature))
10676(defun vhdl-template-next-hook ()
10677 (vhdl-hooked-abbrev 'vhdl-template-next))
3dcb36b7
JB
10678(defun vhdl-template-others-hook ()
10679 (vhdl-hooked-abbrev 'vhdl-template-others))
5eabfe72
KH
10680(defun vhdl-template-package-hook ()
10681 (vhdl-hooked-abbrev 'vhdl-template-package))
10682(defun vhdl-template-port-hook ()
10683 (vhdl-hooked-abbrev 'vhdl-template-port))
10684(defun vhdl-template-procedural-hook ()
10685 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10686(defun vhdl-template-procedure-hook ()
10687 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10688(defun vhdl-template-process-hook ()
10689 (vhdl-hooked-abbrev 'vhdl-template-process))
10690(defun vhdl-template-quantity-hook ()
10691 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10692(defun vhdl-template-report-hook ()
10693 (vhdl-hooked-abbrev 'vhdl-template-report))
10694(defun vhdl-template-return-hook ()
10695 (vhdl-hooked-abbrev 'vhdl-template-return))
10696(defun vhdl-template-selected-signal-asst-hook ()
10697 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10698(defun vhdl-template-signal-hook ()
10699 (vhdl-hooked-abbrev 'vhdl-template-signal))
10700(defun vhdl-template-subnature-hook ()
10701 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10702(defun vhdl-template-subtype-hook ()
10703 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10704(defun vhdl-template-terminal-hook ()
10705 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10706(defun vhdl-template-type-hook ()
10707 (vhdl-hooked-abbrev 'vhdl-template-type))
10708(defun vhdl-template-use-hook ()
10709 (vhdl-hooked-abbrev 'vhdl-template-use))
10710(defun vhdl-template-variable-hook ()
10711 (vhdl-hooked-abbrev 'vhdl-template-variable))
10712(defun vhdl-template-wait-hook ()
10713 (vhdl-hooked-abbrev 'vhdl-template-wait))
10714(defun vhdl-template-when-hook ()
10715 (vhdl-hooked-abbrev 'vhdl-template-when))
10716(defun vhdl-template-while-loop-hook ()
10717 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10718(defun vhdl-template-with-hook ()
10719 (vhdl-hooked-abbrev 'vhdl-template-with))
10720(defun vhdl-template-and-hook ()
10721 (vhdl-hooked-abbrev 'vhdl-template-and))
10722(defun vhdl-template-or-hook ()
10723 (vhdl-hooked-abbrev 'vhdl-template-or))
10724(defun vhdl-template-nand-hook ()
10725 (vhdl-hooked-abbrev 'vhdl-template-nand))
10726(defun vhdl-template-nor-hook ()
10727 (vhdl-hooked-abbrev 'vhdl-template-nor))
10728(defun vhdl-template-xor-hook ()
10729 (vhdl-hooked-abbrev 'vhdl-template-xor))
10730(defun vhdl-template-xnor-hook ()
10731 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10732(defun vhdl-template-not-hook ()
10733 (vhdl-hooked-abbrev 'vhdl-template-not))
10734
10735(defun vhdl-template-default-hook ()
10736 (vhdl-hooked-abbrev 'vhdl-template-default))
10737(defun vhdl-template-default-indent-hook ()
10738 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10739
10740;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10741;; Template insertion from completion list
10742
10743(defun vhdl-template-insert-construct (name)
10744 "Insert the built-in construct template with NAME."
10745 (interactive
10746 (list (let ((completion-ignore-case t))
10747 (completing-read "Construct name: "
10748 vhdl-template-construct-alist nil t))))
10749 (vhdl-template-insert-fun
3dcb36b7 10750 (cadr (assoc name vhdl-template-construct-alist))))
5eabfe72
KH
10751
10752(defun vhdl-template-insert-package (name)
10753 "Insert the built-in package template with NAME."
10754 (interactive
10755 (list (let ((completion-ignore-case t))
10756 (completing-read "Package name: "
10757 vhdl-template-package-alist nil t))))
10758 (vhdl-template-insert-fun
3dcb36b7 10759 (cadr (assoc name vhdl-template-package-alist))))
5eabfe72
KH
10760
10761(defun vhdl-template-insert-directive (name)
10762 "Insert the built-in directive template with NAME."
10763 (interactive
10764 (list (let ((completion-ignore-case t))
10765 (completing-read "Directive name: "
10766 vhdl-template-directive-alist nil t))))
10767 (vhdl-template-insert-fun
3dcb36b7 10768 (cadr (assoc name vhdl-template-directive-alist))))
5eabfe72
KH
10769
10770(defun vhdl-template-insert-fun (fun)
10771 "Call FUN to insert a built-in template."
10772 (let ((caught (catch 'abort (when fun (funcall fun)))))
29a4e67d 10773 (when (stringp caught) (message "%s" caught))))
5eabfe72
KH
10774
10775
10776;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10777;;; Models
10778;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10779
10780(defun vhdl-model-insert (model-name)
10781 "Insert the user model with name MODEL-NAME."
10782 (interactive
10783 (let ((completion-ignore-case t))
10784 (list (completing-read "Model name: " vhdl-model-alist))))
3dcb36b7 10785 (indent-according-to-mode)
5eabfe72
KH
10786 (let ((start (point-marker))
10787 (margin (current-indentation))
5eabfe72 10788 model position prompt string end)
3dcb36b7 10789 (vhdl-prepare-search-2
5eabfe72
KH
10790 (when (setq model (assoc model-name vhdl-model-alist))
10791 ;; insert model
10792 (beginning-of-line)
10793 (delete-horizontal-space)
10794 (goto-char start)
10795 (vhdl-insert-string-or-file (nth 1 model))
10796 (setq end (point-marker))
10797 ;; indent code
10798 (goto-char start)
10799 (beginning-of-line)
10800 (while (< (point) end)
10801 (unless (looking-at "^$")
10802 (insert-char ? margin))
10803 (beginning-of-line 2))
10804 (goto-char start)
10805 ;; insert clock
10806 (unless (equal "" vhdl-clock-name)
10807 (while (re-search-forward "<clock>" end t)
10808 (replace-match vhdl-clock-name)))
10809 (goto-char start)
10810 ;; insert reset
10811 (unless (equal "" vhdl-reset-name)
10812 (while (re-search-forward "<reset>" end t)
10813 (replace-match vhdl-reset-name)))
3dcb36b7
JB
10814 ;; replace header prompts
10815 (vhdl-template-replace-header-keywords start end nil t)
5eabfe72 10816 (goto-char start)
3dcb36b7 10817 ;; query other prompts
5eabfe72
KH
10818 (while (re-search-forward
10819 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10820 (unless (equal "cursor" (match-string 1))
10821 (setq position (match-beginning 1))
10822 (setq prompt (match-string 1))
10823 (replace-match "")
10824 (setq string (vhdl-template-field prompt nil t))
a5a08b1f 10825 ;; replace occurrences of same prompt
5eabfe72
KH
10826 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10827 (replace-match (or string "")))
10828 (goto-char position)))
10829 (goto-char start)
10830 ;; goto final position
10831 (if (re-search-forward "<cursor>" end t)
10832 (replace-match "")
10833 (goto-char end))))))
10834
10835(defun vhdl-model-defun ()
10836 "Define help and hook functions for user models."
10837 (let ((model-alist vhdl-model-alist)
10838 model-name model-keyword)
10839 (while model-alist
10840 ;; define functions for user models that can be invoked from menu and key
10841 ;; bindings and which themselves call `vhdl-model-insert' with the model
10842 ;; name as argument
10843 (setq model-name (nth 0 (car model-alist)))
d4a5b644
GM
10844 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10845 ,(concat "Insert model for \"" model-name "\".")
10846 (interactive)
10847 (vhdl-model-insert ,model-name)))
5eabfe72
KH
10848 ;; define hooks for user models that are invoked from keyword abbrevs
10849 (setq model-keyword (nth 3 (car model-alist)))
10850 (unless (equal model-keyword "")
d4a5b644
GM
10851 (eval `(defun
10852 ,(vhdl-function-name
10853 "vhdl-model" model-name "hook") ()
10854 (vhdl-hooked-abbrev
10855 ',(vhdl-function-name "vhdl-model" model-name)))))
5eabfe72
KH
10856 (setq model-alist (cdr model-alist)))))
10857
10858(vhdl-model-defun)
10859
10860
10861;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10862;;; Port translation
10863;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10864
10865(defvar vhdl-port-list nil
3dcb36b7 10866 "Variable to hold last port map parsed.")
5eabfe72 10867;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
10868;; (ent-name
10869;; ((generic-names) generic-type generic-init generic-comment group-comment)
10870;; ((port-names) port-object port-direct port-type port-comment group-comment)
10871;; (lib-name pack-key))
5eabfe72
KH
10872
10873(defun vhdl-parse-string (string &optional optional)
3dcb36b7 10874 "Check that the text following point matches the regexp in STRING."
5eabfe72 10875 (if (looking-at string)
3dcb36b7 10876 (goto-char (match-end 0))
5eabfe72 10877 (unless optional
3dcb36b7
JB
10878 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10879 (vhdl-current-line) string)))
5eabfe72
KH
10880 nil))
10881
0a2e512a 10882(defun vhdl-replace-string (regexp-cons string &optional adjust-case)
5eabfe72 10883 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
3dcb36b7 10884 (vhdl-prepare-search-1
5eabfe72 10885 (if (string-match (car regexp-cons) string)
0a2e512a
RF
10886 (if adjust-case
10887 (funcall vhdl-file-name-case
10888 (replace-match (cdr regexp-cons) t nil string))
10889 (replace-match (cdr regexp-cons) t nil string))
5eabfe72
KH
10890 string)))
10891
3dcb36b7
JB
10892(defun vhdl-parse-group-comment ()
10893 "Parse comment and empty lines between groups of lines."
10894 (let ((start (point))
10895 string)
10896 (vhdl-forward-comment (point-max))
10897 (setq string (buffer-substring-no-properties start (point)))
0a2e512a 10898 (vhdl-forward-syntactic-ws)
3dcb36b7
JB
10899 ;; strip off leading blanks and first newline
10900 (while (string-match "^\\(\\s-+\\)" string)
10901 (setq string (concat (substring string 0 (match-beginning 1))
10902 (substring string (match-end 1)))))
10903 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10904 (substring string 1)
10905 string)))
10906
10907(defun vhdl-paste-group-comment (string indent)
10908 "Paste comment and empty lines from STRING between groups of lines
10909with INDENT."
10910 (let ((pos (point-marker)))
10911 (when (> indent 0)
10912 (while (string-match "^\\(--\\)" string)
10913 (setq string (concat (substring string 0 (match-beginning 1))
10914 (make-string indent ? )
10915 (substring string (match-beginning 1))))))
10916 (beginning-of-line)
10917 (insert string)
10918 (goto-char pos)))
10919
10920(defvar vhdl-port-flattened nil
10921 "Indicates whether a port has been flattened.")
10922
10923(defun vhdl-port-flatten (&optional as-alist)
0a2e512a
RF
10924 "Flatten port list so that only one generic/port exists per line.
10925This operation is performed on an internally stored port and is only
10926reflected in a subsequent paste operation."
5eabfe72
KH
10927 (interactive)
10928 (if (not vhdl-port-list)
3dcb36b7 10929 (error "ERROR: No port has been read")
0a2e512a 10930 (message "Flattening port for next paste...")
5eabfe72
KH
10931 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10932 (old-vhdl-port-list (cdr vhdl-port-list))
10933 old-port-list new-port-list old-port new-port names)
10934 ;; traverse port list and flatten entries
3dcb36b7 10935 (while (cdr old-vhdl-port-list)
5eabfe72
KH
10936 (setq old-port-list (car old-vhdl-port-list))
10937 (setq new-port-list nil)
10938 (while old-port-list
10939 (setq old-port (car old-port-list))
10940 (setq names (car old-port))
10941 (while names
3dcb36b7
JB
10942 (setq new-port (cons (if as-alist (car names) (list (car names)))
10943 (cdr old-port)))
5eabfe72
KH
10944 (setq new-port-list (append new-port-list (list new-port)))
10945 (setq names (cdr names)))
10946 (setq old-port-list (cdr old-port-list)))
10947 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10948 (setq new-vhdl-port-list (append new-vhdl-port-list
10949 (list new-port-list))))
3dcb36b7
JB
10950 (setq vhdl-port-list
10951 (append new-vhdl-port-list (list old-vhdl-port-list))
10952 vhdl-port-flattened t)
0a2e512a 10953 (message "Flattening port for next paste...done"))))
5eabfe72 10954
3dcb36b7
JB
10955(defvar vhdl-port-reversed-direction nil
10956 "Indicates whether port directions are reversed.")
10957
10958(defun vhdl-port-reverse-direction ()
0a2e512a
RF
10959 "Reverse direction for all ports (useful in testbenches).
10960This operation is performed on an internally stored port and is only
10961reflected in a subsequent paste operation."
3dcb36b7
JB
10962 (interactive)
10963 (if (not vhdl-port-list)
10964 (error "ERROR: No port has been read")
0a2e512a 10965 (message "Reversing port directions for next paste...")
3dcb36b7
JB
10966 (let ((port-list (nth 2 vhdl-port-list))
10967 port-dir-car port-dir)
10968 ;; traverse port list and reverse directions
10969 (while port-list
10970 (setq port-dir-car (cddr (car port-list))
10971 port-dir (car port-dir-car))
10972 (setcar port-dir-car
10973 (cond ((equal port-dir "in") "out")
10974 ((equal port-dir "out") "in")
10975 (t port-dir)))
10976 (setq port-list (cdr port-list)))
10977 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
0a2e512a 10978 (message "Reversing port directions for next paste...done"))))
3dcb36b7 10979
5eabfe72
KH
10980(defun vhdl-port-copy ()
10981 "Get generic and port information from an entity or component declaration."
10982 (interactive)
5eabfe72 10983 (save-excursion
3dcb36b7
JB
10984 (let (parse-error end-of-list
10985 decl-type name generic-list port-list context-clause
10986 object names direct type init comment group-comment)
10987 (vhdl-prepare-search-2
5eabfe72
KH
10988 (setq
10989 parse-error
10990 (catch 'parse
10991 ;; check if within entity or component declaration
3dcb36b7 10992 (end-of-line)
5eabfe72
KH
10993 (when (or (not (re-search-backward
10994 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
3dcb36b7
JB
10995 (equal "END" (upcase (match-string 1))))
10996 (throw 'parse "ERROR: Not within an entity or component declaration"))
10997 (setq decl-type (downcase (match-string-no-properties 1)))
5eabfe72 10998 (forward-word 1)
3dcb36b7
JB
10999 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11000 (setq name (match-string-no-properties 1))
11001 (message "Reading port of %s \"%s\"..." decl-type name)
5eabfe72
KH
11002 (vhdl-forward-syntactic-ws)
11003 ;; parse generic clause
11004 (when (vhdl-parse-string "generic[ \t\n]*(" t)
3dcb36b7
JB
11005 ;; parse group comment and spacing
11006 (setq group-comment (vhdl-parse-group-comment))
11007 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72 11008 (while (not end-of-list)
0a2e512a
RF
11009 ;; parse names (accept extended identifiers)
11010 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
3dcb36b7 11011 (setq names (list (match-string-no-properties 1)))
5eabfe72 11012 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
3dcb36b7
JB
11013 (setq names
11014 (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
11015 ;; parse type
11016 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
3dcb36b7 11017 (setq type (match-string-no-properties 1))
5eabfe72
KH
11018 (setq comment nil)
11019 (while (looking-at "(")
11020 (setq type
11021 (concat type
3dcb36b7 11022 (buffer-substring-no-properties
5eabfe72
KH
11023 (point) (progn (forward-sexp) (point)))
11024 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
3dcb36b7 11025 (match-string-no-properties 1)))))
5eabfe72
KH
11026 ;; special case: closing parenthesis is on separate line
11027 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11028 (setq comment (substring type (match-beginning 2)))
11029 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 11030 ;; strip of trailing group-comment
5eabfe72
KH
11031 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11032 (setq type (substring type 0 (match-end 1)))
11033 ;; parse initialization expression
11034 (setq init nil)
11035 (when (vhdl-parse-string ":=[ \t\n]*" t)
11036 (vhdl-parse-string "\\([^();\n]*\\)")
3dcb36b7 11037 (setq init (match-string-no-properties 1))
5eabfe72
KH
11038 (while (looking-at "(")
11039 (setq init
11040 (concat init
3dcb36b7 11041 (buffer-substring-no-properties
5eabfe72
KH
11042 (point) (progn (forward-sexp) (point)))
11043 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11044 (match-string-no-properties 1))))))
5eabfe72
KH
11045 ;; special case: closing parenthesis is on separate line
11046 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11047 (setq comment (substring init (match-beginning 2)))
11048 (setq init (substring init 0 (match-beginning 1)))
11049 (vhdl-forward-syntactic-ws))
11050 (skip-chars-forward " \t")
11051 ;; parse inline comment, special case: as above, no initial.
11052 (unless comment
11053 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11054 (match-string-no-properties 1))))
5eabfe72
KH
11055 (vhdl-forward-syntactic-ws)
11056 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11057 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11058 ;; parse inline comment
11059 (unless comment
11060 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11061 (match-string-no-properties 1))))
5eabfe72 11062 ;; save everything in list
3dcb36b7
JB
11063 (setq generic-list (append generic-list
11064 (list (list names type init
11065 comment group-comment))))
11066 ;; parse group comment and spacing
11067 (setq group-comment (vhdl-parse-group-comment))))
5eabfe72
KH
11068 ;; parse port clause
11069 (when (vhdl-parse-string "port[ \t\n]*(" t)
3dcb36b7
JB
11070 ;; parse group comment and spacing
11071 (setq group-comment (vhdl-parse-group-comment))
11072 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
11073 (while (not end-of-list)
11074 ;; parse object
11075 (setq object
0a2e512a 11076 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
3dcb36b7
JB
11077 (match-string-no-properties 1)))
11078 ;; parse names (accept extended identifiers)
11079 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11080 (setq names (list (match-string-no-properties 1)))
11081 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11082 (setq names (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
11083 ;; parse direction
11084 (vhdl-parse-string ":[ \t\n]*")
11085 (setq direct
0a2e512a 11086 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
3dcb36b7 11087 (match-string-no-properties 1)))
5eabfe72
KH
11088 ;; parse type
11089 (vhdl-parse-string "\\([^();\n]+\\)")
3dcb36b7 11090 (setq type (match-string-no-properties 1))
5eabfe72
KH
11091 (setq comment nil)
11092 (while (looking-at "(")
11093 (setq type (concat type
3dcb36b7 11094 (buffer-substring-no-properties
5eabfe72
KH
11095 (point) (progn (forward-sexp) (point)))
11096 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 11097 (match-string-no-properties 1)))))
5eabfe72 11098 ;; special case: closing parenthesis is on separate line
3dcb36b7 11099 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
5eabfe72
KH
11100 (setq comment (substring type (match-beginning 2)))
11101 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 11102 ;; strip of trailing group-comment
5eabfe72
KH
11103 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11104 (setq type (substring type 0 (match-end 1)))
11105 (vhdl-forward-syntactic-ws)
11106 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 11107 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
11108 ;; parse inline comment
11109 (unless comment
11110 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 11111 (match-string-no-properties 1))))
5eabfe72 11112 ;; save everything in list
3dcb36b7
JB
11113 (setq port-list (append port-list
11114 (list (list names object direct type
11115 comment group-comment))))
11116 ;; parse group comment and spacing
11117 (setq group-comment (vhdl-parse-group-comment))))
11118; (vhdl-parse-string "end\\>")
11119 ;; parse context clause
11120 (setq context-clause (vhdl-scan-context-clause))
11121; ;; add surrounding package to context clause
11122; (when (and (equal decl-type "component")
11123; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11124; (setq context-clause
11125; (append context-clause
11126; (list (cons (vhdl-work-library)
11127; (match-string-no-properties 1))))))
11128 (message "Reading port of %s \"%s\"...done" decl-type name)
5eabfe72
KH
11129 nil)))
11130 ;; finish parsing
11131 (if parse-error
11132 (error parse-error)
3dcb36b7
JB
11133 (setq vhdl-port-list (list name generic-list port-list context-clause)
11134 vhdl-port-reversed-direction nil
11135 vhdl-port-flattened nil)))))
11136
11137(defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
11138 "Paste a context clause."
11139 (let ((margin (current-indentation))
11140 (clause-list (nth 3 vhdl-port-list))
11141 clause)
11142 (while clause-list
11143 (setq clause (car clause-list))
11144 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
11145 (downcase exclude-pack-name)))
11146 (save-excursion
11147 (re-search-backward
11148 (concat "^\\s-*use\\s-+" (car clause)
11149 "\." (cdr clause) "\\>") nil t)))
11150 (vhdl-template-standard-package (car clause) (cdr clause))
11151 (insert "\n"))
11152 (setq clause-list (cdr clause-list)))))
5eabfe72
KH
11153
11154(defun vhdl-port-paste-generic (&optional no-init)
11155 "Paste a generic clause."
11156 (let ((margin (current-indentation))
3dcb36b7
JB
11157 (generic-list (nth 1 vhdl-port-list))
11158 list-margin start names generic)
5eabfe72 11159 ;; paste generic clause
3dcb36b7 11160 (when generic-list
5eabfe72
KH
11161 (setq start (point))
11162 (vhdl-insert-keyword "GENERIC (")
11163 (unless vhdl-argument-list-indent
11164 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11165 (setq list-margin (current-column))
3dcb36b7
JB
11166 (while generic-list
11167 (setq generic (car generic-list))
11168 ;; paste group comment and spacing
11169 (when (memq vhdl-include-group-comments '(decl always))
11170 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72 11171 ;; paste names
5eabfe72
KH
11172 (setq names (nth 0 generic))
11173 (while names
11174 (insert (car names))
11175 (setq names (cdr names))
11176 (when names (insert ", ")))
11177 ;; paste type
11178 (insert " : " (nth 1 generic))
11179 ;; paste initialization
11180 (when (and (not no-init) (nth 2 generic))
11181 (insert " := " (nth 2 generic)))
3dcb36b7 11182 (unless (cdr generic-list) (insert ")"))
5eabfe72
KH
11183 (insert ";")
11184 ;; paste comment
11185 (when (and vhdl-include-port-comments (nth 3 generic))
11186 (vhdl-comment-insert-inline (nth 3 generic) t))
3dcb36b7
JB
11187 (setq generic-list (cdr generic-list))
11188 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72 11189 ;; align generic clause
3dcb36b7 11190 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
5eabfe72
KH
11191
11192(defun vhdl-port-paste-port ()
11193 "Paste a port clause."
11194 (let ((margin (current-indentation))
3dcb36b7
JB
11195 (port-list (nth 2 vhdl-port-list))
11196 list-margin start names port)
5eabfe72 11197 ;; paste port clause
3dcb36b7 11198 (when port-list
5eabfe72
KH
11199 (setq start (point))
11200 (vhdl-insert-keyword "PORT (")
11201 (unless vhdl-argument-list-indent
11202 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11203 (setq list-margin (current-column))
3dcb36b7
JB
11204 (while port-list
11205 (setq port (car port-list))
11206 ;; paste group comment and spacing
11207 (when (memq vhdl-include-group-comments '(decl always))
11208 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11209 ;; paste object
11210 (when (nth 1 port) (insert (nth 1 port) " "))
11211 ;; paste names
11212 (setq names (nth 0 port))
11213 (while names
11214 (insert (car names))
11215 (setq names (cdr names))
11216 (when names (insert ", ")))
11217 ;; paste direction
11218 (insert " : ")
11219 (when (nth 2 port) (insert (nth 2 port) " "))
11220 ;; paste type
11221 (insert (nth 3 port))
3dcb36b7 11222 (unless (cdr port-list) (insert ")"))
5eabfe72
KH
11223 (insert ";")
11224 ;; paste comment
11225 (when (and vhdl-include-port-comments (nth 4 port))
11226 (vhdl-comment-insert-inline (nth 4 port) t))
3dcb36b7
JB
11227 (setq port-list (cdr port-list))
11228 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72 11229 ;; align port clause
3dcb36b7 11230 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
5eabfe72 11231
3dcb36b7 11232(defun vhdl-port-paste-declaration (kind &optional no-indent)
5eabfe72 11233 "Paste as an entity or component declaration."
3dcb36b7 11234 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11235 (let ((margin (current-indentation))
11236 (name (nth 0 vhdl-port-list)))
11237 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11238 (insert name)
3dcb36b7
JB
11239 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11240 (vhdl-insert-keyword " IS"))
11241 ;; paste generic and port clause
5eabfe72
KH
11242 (when (nth 1 vhdl-port-list)
11243 (insert "\n")
11244 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11245 (insert "\n"))
11246 (indent-to (+ margin vhdl-basic-offset))
11247 (vhdl-port-paste-generic (eq kind 'component)))
11248 (when (nth 2 vhdl-port-list)
11249 (insert "\n")
11250 (when (and (memq vhdl-insert-empty-lines '(unit all))
11251 (eq kind 'entity))
11252 (insert "\n"))
11253 (indent-to (+ margin vhdl-basic-offset)))
11254 (vhdl-port-paste-port)
11255 (insert "\n")
11256 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11257 (insert "\n"))
11258 (indent-to margin)
11259 (vhdl-insert-keyword "END")
11260 (if (eq kind 'entity)
11261 (progn
11262 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11263 (insert " " name))
11264 (vhdl-insert-keyword " COMPONENT")
11265 (unless (vhdl-standard-p '87) (insert " " name)))
11266 (insert ";")))
11267
3dcb36b7 11268(defun vhdl-port-paste-entity (&optional no-indent)
5eabfe72
KH
11269 "Paste as an entity declaration."
11270 (interactive)
11271 (if (not vhdl-port-list)
3dcb36b7
JB
11272 (error "ERROR: No port read")
11273 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11274 (vhdl-port-paste-declaration 'entity no-indent)
11275 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
5eabfe72 11276
3dcb36b7 11277(defun vhdl-port-paste-component (&optional no-indent)
5eabfe72
KH
11278 "Paste as a component declaration."
11279 (interactive)
11280 (if (not vhdl-port-list)
3dcb36b7
JB
11281 (error "ERROR: No port read")
11282 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11283 (vhdl-port-paste-declaration 'component no-indent)
11284 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
5eabfe72
KH
11285
11286(defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11287 "Paste as a generic map."
11288 (interactive)
3dcb36b7 11289 (unless secondary (indent-according-to-mode))
5eabfe72
KH
11290 (let ((margin (current-indentation))
11291 list-margin start generic
3dcb36b7
JB
11292 (generic-list (nth 1 vhdl-port-list)))
11293 (when generic-list
5eabfe72
KH
11294 (setq start (point))
11295 (vhdl-insert-keyword "GENERIC MAP (")
11296 (if (not vhdl-association-list-with-formals)
11297 ;; paste list of actual generics
3dcb36b7
JB
11298 (while generic-list
11299 (insert (if no-constants
11300 (car (nth 0 (car generic-list)))
11301 (or (nth 2 (car generic-list)) " ")))
11302 (setq generic-list (cdr generic-list))
0a2e512a
RF
11303 (insert (if generic-list ", " ")"))
11304 (when (and (not generic-list) secondary
11305 (null (nth 2 vhdl-port-list)))
11306 (insert ";")))
5eabfe72 11307 (unless vhdl-argument-list-indent
3dcb36b7 11308 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11309 (setq list-margin (current-column))
3dcb36b7
JB
11310 (while generic-list
11311 (setq generic (car generic-list))
11312 ;; paste group comment and spacing
11313 (when (eq vhdl-include-group-comments 'always)
11314 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72
KH
11315 ;; paste formal and actual generic
11316 (insert (car (nth 0 generic)) " => "
11317 (if no-constants
11318 (car (nth 0 generic))
11319 (or (nth 2 generic) "")))
3dcb36b7
JB
11320 (setq generic-list (cdr generic-list))
11321 (insert (if generic-list "," ")"))
0a2e512a
RF
11322 (when (and (not generic-list) secondary
11323 (null (nth 2 vhdl-port-list)))
11324 (insert ";"))
5eabfe72 11325 ;; paste comment
3dcb36b7
JB
11326 (when (or vhdl-include-type-comments
11327 (and vhdl-include-port-comments (nth 3 generic)))
11328 (vhdl-comment-insert-inline
11329 (concat
11330 (when vhdl-include-type-comments
11331 (concat "[" (nth 1 generic) "] "))
11332 (when vhdl-include-port-comments (nth 3 generic))) t))
11333 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11334 ;; align generic map
11335 (when vhdl-auto-align
3dcb36b7 11336 (vhdl-align-region-groups start (point) 1 t))))))
5eabfe72
KH
11337
11338(defun vhdl-port-paste-port-map ()
11339 "Paste as a port map."
11340 (let ((margin (current-indentation))
11341 list-margin start port
3dcb36b7
JB
11342 (port-list (nth 2 vhdl-port-list)))
11343 (when port-list
5eabfe72
KH
11344 (setq start (point))
11345 (vhdl-insert-keyword "PORT MAP (")
11346 (if (not vhdl-association-list-with-formals)
11347 ;; paste list of actual ports
3dcb36b7 11348 (while port-list
5eabfe72 11349 (insert (vhdl-replace-string vhdl-actual-port-name
3dcb36b7
JB
11350 (car (nth 0 (car port-list)))))
11351 (setq port-list (cdr port-list))
0a2e512a 11352 (insert (if port-list ", " ")")))
5eabfe72 11353 (unless vhdl-argument-list-indent
3dcb36b7 11354 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11355 (setq list-margin (current-column))
3dcb36b7
JB
11356 (while port-list
11357 (setq port (car port-list))
11358 ;; paste group comment and spacing
11359 (when (eq vhdl-include-group-comments 'always)
11360 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11361 ;; paste formal and actual port
11362 (insert (car (nth 0 port)) " => ")
11363 (insert (vhdl-replace-string vhdl-actual-port-name
11364 (car (nth 0 port))))
3dcb36b7
JB
11365 (setq port-list (cdr port-list))
11366 (insert (if port-list "," ");"))
5eabfe72
KH
11367 ;; paste comment
11368 (when (or vhdl-include-direction-comments
3dcb36b7 11369 vhdl-include-type-comments
5eabfe72
KH
11370 (and vhdl-include-port-comments (nth 4 port)))
11371 (vhdl-comment-insert-inline
11372 (concat
3dcb36b7
JB
11373 (cond ((and vhdl-include-direction-comments
11374 vhdl-include-type-comments)
11375 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11376 (nth 3 port) "] "))
11377 ((and vhdl-include-direction-comments (nth 2 port))
11378 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11379 (vhdl-include-direction-comments " ")
11380 (vhdl-include-type-comments
11381 (concat "[" (nth 3 port) "] ")))
11382 (when vhdl-include-port-comments (nth 4 port))) t))
11383 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11384 ;; align port clause
11385 (when vhdl-auto-align
3dcb36b7 11386 (vhdl-align-region-groups start (point) 1))))))
5eabfe72 11387
3dcb36b7 11388(defun vhdl-port-paste-instance (&optional name no-indent title)
5eabfe72
KH
11389 "Paste as an instantiation."
11390 (interactive)
11391 (if (not vhdl-port-list)
3dcb36b7 11392 (error "ERROR: No port read")
5eabfe72
KH
11393 (let ((orig-vhdl-port-list vhdl-port-list))
11394 ;; flatten local copy of port list (must be flat for port mapping)
11395 (vhdl-port-flatten)
3dcb36b7
JB
11396 (unless no-indent (indent-according-to-mode))
11397 (let ((margin (current-indentation)))
5eabfe72 11398 ;; paste instantiation
3dcb36b7
JB
11399 (cond (name
11400 (insert name))
11401 ((equal (cdr vhdl-instance-name) "")
11402 (setq name (vhdl-template-field "instance name")))
11403 ((string-match "\%d" (cdr vhdl-instance-name))
11404 (let ((n 1))
11405 (while (save-excursion
11406 (setq name (format (vhdl-replace-string
11407 vhdl-instance-name
11408 (nth 0 vhdl-port-list)) n))
11409 (goto-char (point-min))
11410 (vhdl-re-search-forward name nil t))
11411 (setq n (1+ n)))
11412 (insert name)))
11413 (t (insert (vhdl-replace-string vhdl-instance-name
11414 (nth 0 vhdl-port-list)))))
11415 (message "Pasting port as instantiation \"%s\"..." name)
11416 (insert ": ")
11417 (when title
11418 (save-excursion
11419 (beginning-of-line)
11420 (indent-to vhdl-basic-offset)
11421 (insert "-- instance \"" name "\"\n")))
11422 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
11423 (insert (nth 0 vhdl-port-list))
11424 (vhdl-insert-keyword "ENTITY ")
3dcb36b7 11425 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
5eabfe72
KH
11426 (when (nth 1 vhdl-port-list)
11427 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11428 (vhdl-port-paste-generic-map t t))
11429 (when (nth 2 vhdl-port-list)
11430 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11431 (vhdl-port-paste-port-map))
0a2e512a
RF
11432 (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
11433 (insert ";"))
3dcb36b7
JB
11434 (message "Pasting port as instantiation \"%s\"...done" name))
11435 (setq vhdl-port-list orig-vhdl-port-list))))
11436
11437(defun vhdl-port-paste-constants (&optional no-indent)
11438 "Paste generics as constants."
11439 (interactive)
11440 (if (not vhdl-port-list)
11441 (error "ERROR: No port read")
11442 (let ((orig-vhdl-port-list vhdl-port-list))
11443 (message "Pasting port as constants...")
11444 ;; flatten local copy of port list (must be flat for constant initial.)
11445 (vhdl-port-flatten)
11446 (unless no-indent (indent-according-to-mode))
11447 (let ((margin (current-indentation))
11448 start generic name
11449 (generic-list (nth 1 vhdl-port-list)))
11450 (when generic-list
11451 (setq start (point))
11452 (while generic-list
11453 (setq generic (car generic-list))
11454 ;; paste group comment and spacing
11455 (when (memq vhdl-include-group-comments '(decl always))
11456 (vhdl-paste-group-comment (nth 4 generic) margin))
11457 (vhdl-insert-keyword "CONSTANT ")
11458 ;; paste generic constants
11459 (setq name (nth 0 generic))
11460 (when name
11461 (insert (car name))
11462 ;; paste type
11463 (insert " : " (nth 1 generic))
11464 ;; paste initialization
11465 (when (nth 2 generic)
11466 (insert " := " (nth 2 generic)))
11467 (insert ";")
11468 ;; paste comment
11469 (when (and vhdl-include-port-comments (nth 3 generic))
11470 (vhdl-comment-insert-inline (nth 3 generic) t))
11471 (setq generic-list (cdr generic-list))
11472 (when generic-list (insert "\n") (indent-to margin))))
11473 ;; align signal list
11474 (when vhdl-auto-align
11475 (vhdl-align-region-groups start (point) 1))))
11476 (message "Pasting port as constants...done")
5eabfe72
KH
11477 (setq vhdl-port-list orig-vhdl-port-list))))
11478
3dcb36b7 11479(defun vhdl-port-paste-signals (&optional initialize no-indent)
5eabfe72
KH
11480 "Paste ports as internal signals."
11481 (interactive)
11482 (if (not vhdl-port-list)
3dcb36b7 11483 (error "ERROR: No port read")
5eabfe72 11484 (message "Pasting port as signals...")
3dcb36b7 11485 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11486 (let ((margin (current-indentation))
11487 start port names
3dcb36b7
JB
11488 (port-list (nth 2 vhdl-port-list)))
11489 (when port-list
5eabfe72 11490 (setq start (point))
3dcb36b7
JB
11491 (while port-list
11492 (setq port (car port-list))
11493 ;; paste group comment and spacing
11494 (when (memq vhdl-include-group-comments '(decl always))
11495 (vhdl-paste-group-comment (nth 5 port) margin))
5eabfe72
KH
11496 ;; paste object
11497 (if (nth 1 port)
11498 (insert (nth 1 port) " ")
11499 (vhdl-insert-keyword "SIGNAL "))
11500 ;; paste actual port signals
11501 (setq names (nth 0 port))
11502 (while names
11503 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11504 (setq names (cdr names))
11505 (when names (insert ", ")))
11506 ;; paste type
11507 (insert " : " (nth 3 port))
11508 ;; paste initialization (inputs only)
3dcb36b7
JB
11509 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11510 (insert " := " (if (string-match "(.+)" (nth 3 port))
11511 "(others => '0')" "'0'")))
5eabfe72
KH
11512 (insert ";")
11513 ;; paste comment
3dcb36b7
JB
11514 (when (or vhdl-include-direction-comments
11515 (and vhdl-include-port-comments (nth 4 port)))
11516 (vhdl-comment-insert-inline
11517 (concat
11518 (cond ((and vhdl-include-direction-comments (nth 2 port))
11519 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11520 (vhdl-include-direction-comments " "))
11521 (when vhdl-include-port-comments (nth 4 port))) t))
11522 (setq port-list (cdr port-list))
11523 (when port-list (insert "\n") (indent-to margin)))
5eabfe72 11524 ;; align signal list
3dcb36b7 11525 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
5eabfe72
KH
11526 (message "Pasting port as signals...done")))
11527
3dcb36b7
JB
11528(defun vhdl-port-paste-initializations (&optional no-indent)
11529 "Paste ports as signal initializations."
5eabfe72
KH
11530 (interactive)
11531 (if (not vhdl-port-list)
3dcb36b7 11532 (error "ERROR: No port read")
5eabfe72 11533 (let ((orig-vhdl-port-list vhdl-port-list))
3dcb36b7
JB
11534 (message "Pasting port as initializations...")
11535 ;; flatten local copy of port list (must be flat for signal initial.)
5eabfe72 11536 (vhdl-port-flatten)
3dcb36b7 11537 (unless no-indent (indent-according-to-mode))
5eabfe72 11538 (let ((margin (current-indentation))
3dcb36b7
JB
11539 start port name
11540 (port-list (nth 2 vhdl-port-list)))
11541 (when port-list
5eabfe72 11542 (setq start (point))
3dcb36b7
JB
11543 (while port-list
11544 (setq port (car port-list))
11545 ;; paste actual port signal (inputs only)
11546 (when (equal "IN" (upcase (nth 2 port)))
11547 (setq name (car (nth 0 port)))
11548 (insert (vhdl-replace-string vhdl-actual-port-name name))
5eabfe72 11549 ;; paste initialization
3dcb36b7
JB
11550 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11551 "(others => '0')" "'0'") ";"))
11552 (setq port-list (cdr port-list))
11553 (when (and port-list
11554 (equal "IN" (upcase (nth 2 (car port-list)))))
11555 (insert "\n") (indent-to margin)))
11556 ;; align signal list
11557 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11558 (message "Pasting port as initializations...done")
5eabfe72
KH
11559 (setq vhdl-port-list orig-vhdl-port-list))))
11560
11561(defun vhdl-port-paste-testbench ()
3dcb36b7 11562 "Paste as a bare-bones testbench."
5eabfe72
KH
11563 (interactive)
11564 (if (not vhdl-port-list)
3dcb36b7 11565 (error "ERROR: No port read")
5eabfe72
KH
11566 (let ((case-fold-search t)
11567 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11568 (nth 0 vhdl-port-list)))
11569 (source-buffer (current-buffer))
3dcb36b7
JB
11570 arch-name config-name ent-file-name arch-file-name
11571 ent-buffer arch-buffer position)
5eabfe72 11572 ;; open entity file
3dcb36b7 11573 (unless (eq vhdl-testbench-create-files 'none)
5eabfe72 11574 (setq ent-file-name
0a2e512a
RF
11575 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
11576 ent-name t)
11577 "." (file-name-extension (buffer-file-name))))
3dcb36b7 11578 (if (file-exists-p ent-file-name)
5eabfe72 11579 (if (y-or-n-p
3dcb36b7
JB
11580 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11581 (progn (find-file ent-file-name)
11582 (erase-buffer)
11583 (set-buffer-modified-p nil))
11584 (if (eq vhdl-testbench-create-files 'separate)
11585 (setq ent-file-name nil)
11586 (error "ERROR: Pasting port as testbench...aborted")))
11587 (find-file ent-file-name)))
11588 (unless (and (eq vhdl-testbench-create-files 'separate)
11589 (null ent-file-name))
11590 ;; paste entity header
11591 (if vhdl-testbench-include-header
11592 (progn (vhdl-template-header
11593 (concat "Testbench for design \""
11594 (nth 0 vhdl-port-list) "\""))
11595 (goto-char (point-max)))
11596 (vhdl-comment-display-line) (insert "\n\n"))
11597 ;; paste std_logic_1164 package
11598 (when vhdl-testbench-include-library
11599 (vhdl-template-package-std-logic-1164)
11600 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11601 ;; paste entity declaration
11602 (vhdl-insert-keyword "ENTITY ")
5eabfe72
KH
11603 (insert ent-name)
11604 (vhdl-insert-keyword " IS")
3dcb36b7 11605 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
5eabfe72 11606 (insert "\n")
3dcb36b7
JB
11607 (vhdl-insert-keyword "END ")
11608 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11609 (insert ent-name ";")
11610 (insert "\n\n")
11611 (vhdl-comment-display-line) (insert "\n"))
11612 ;; get architecture name
11613 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11614 (read-from-minibuffer "architecture name: "
11615 nil vhdl-minibuffer-local-map)
11616 (vhdl-replace-string vhdl-testbench-architecture-name
11617 (nth 0 vhdl-port-list))))
11618 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11619 ;; open architecture file
11620 (if (not (eq vhdl-testbench-create-files 'separate))
5eabfe72 11621 (insert "\n")
3dcb36b7
JB
11622 (setq ent-buffer (current-buffer))
11623 (setq arch-file-name
0a2e512a
RF
11624 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
11625 (concat ent-name " " arch-name) t)
11626 "." (file-name-extension (buffer-file-name))))
3dcb36b7
JB
11627 (when (and (file-exists-p arch-file-name)
11628 (not (y-or-n-p (concat "File \"" arch-file-name
11629 "\" exists; overwrite? "))))
11630 (error "ERROR: Pasting port as testbench...aborted"))
11631 (find-file arch-file-name)
11632 (erase-buffer)
11633 (set-buffer-modified-p nil)
11634 ;; paste architecture header
11635 (if vhdl-testbench-include-header
11636 (progn (vhdl-template-header
11637 (concat "Testbench architecture for design \""
11638 (nth 0 vhdl-port-list) "\""))
11639 (goto-char (point-max)))
11640 (vhdl-comment-display-line) (insert "\n\n")))
11641 ;; paste architecture body
11642 (vhdl-insert-keyword "ARCHITECTURE ")
11643 (insert arch-name)
11644 (vhdl-insert-keyword " OF ")
11645 (insert ent-name)
11646 (vhdl-insert-keyword " IS")
11647 (insert "\n\n") (indent-to vhdl-basic-offset)
11648 ;; paste component declaration
11649 (unless (vhdl-use-direct-instantiation)
11650 (vhdl-port-paste-component t)
11651 (insert "\n\n") (indent-to vhdl-basic-offset))
11652 ;; paste constants
11653 (when (nth 1 vhdl-port-list)
11654 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11655 (vhdl-port-paste-constants t)
11656 (insert "\n\n") (indent-to vhdl-basic-offset))
11657 ;; paste internal signals
11658 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11659 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11660 (insert "\n")
11661 ;; paste custom declarations
11662 (unless (equal "" vhdl-testbench-declarations)
5eabfe72 11663 (insert "\n")
3dcb36b7
JB
11664 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11665 (setq position (point))
11666 (insert "\n\n")
11667 (vhdl-comment-display-line) (insert "\n")
11668 (when vhdl-testbench-include-configuration
11669 (setq config-name (vhdl-replace-string
11670 vhdl-testbench-configuration-name
11671 (concat ent-name " " arch-name)))
11672 (insert "\n")
11673 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11674 (vhdl-insert-keyword " OF ") (insert ent-name)
11675 (vhdl-insert-keyword " IS\n")
11676 (indent-to vhdl-basic-offset)
11677 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11678 (indent-to vhdl-basic-offset)
11679 (vhdl-insert-keyword "END FOR;\n")
11680 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11681 (vhdl-comment-display-line) (insert "\n"))
11682 (goto-char position)
11683 (vhdl-template-begin-end
11684 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11685 ;; paste instantiation
11686 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11687 (vhdl-port-paste-instance
11688 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11689 (insert "\n")
11690 ;; paste custom statements
11691 (unless (equal "" vhdl-testbench-statements)
11692 (insert "\n")
11693 (vhdl-insert-string-or-file vhdl-testbench-statements))
11694 (insert "\n")
11695 (indent-to vhdl-basic-offset)
11696 (unless (eq vhdl-testbench-create-files 'none)
11697 (setq arch-buffer (current-buffer))
11698 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11699 (set-buffer arch-buffer) (save-buffer))
29a4e67d 11700 (message "%s"
3dcb36b7
JB
11701 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11702 ent-name arch-name)
11703 (and ent-file-name
11704 (format "\n File created: \"%s\"" ent-file-name))
11705 (and arch-file-name
11706 (format "\n File created: \"%s\"" arch-file-name)))))))
5eabfe72
KH
11707
11708
11709;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11710;;; Subprogram interface translation
5eabfe72
KH
11711;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11712
3dcb36b7
JB
11713(defvar vhdl-subprog-list nil
11714 "Variable to hold last subprogram interface parsed.")
11715;; structure: (parenthesised expression means list of such entries)
11716;; (subprog-name kind
11717;; ((names) object direct type init comment group-comment)
11718;; return-type return-comment group-comment)
5eabfe72 11719
3dcb36b7
JB
11720(defvar vhdl-subprog-flattened nil
11721 "Indicates whether an subprogram interface has been flattened.")
5eabfe72 11722
3dcb36b7
JB
11723(defun vhdl-subprog-flatten ()
11724 "Flatten interface list so that only one parameter exists per line."
11725 (interactive)
11726 (if (not vhdl-subprog-list)
11727 (error "ERROR: No subprogram interface has been read")
11728 (message "Flattening subprogram interface...")
11729 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11730 new-subprog-list old-subprog new-subprog names)
11731 ;; traverse parameter list and flatten entries
11732 (while old-subprog-list
11733 (setq old-subprog (car old-subprog-list))
11734 (setq names (car old-subprog))
11735 (while names
11736 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11737 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11738 (setq names (cdr names)))
11739 (setq old-subprog-list (cdr old-subprog-list)))
11740 (setq vhdl-subprog-list
11741 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11742 new-subprog-list (nth 3 vhdl-subprog-list)
11743 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11744 vhdl-subprog-flattened t)
11745 (message "Flattening subprogram interface...done"))))
11746
11747(defun vhdl-subprog-copy ()
11748 "Get interface information from a subprogram specification."
11749 (interactive)
11750 (save-excursion
11751 (let (parse-error pos end-of-list
11752 name kind param-list object names direct type init
11753 comment group-comment
11754 return-type return-comment return-group-comment)
11755 (vhdl-prepare-search-2
11756 (setq
11757 parse-error
11758 (catch 'parse
11759 ;; check if within function declaration
11760 (setq pos (point))
11761 (end-of-line)
11762 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11763 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11764 (goto-char (match-end 0))
11765 (save-excursion (backward-char)
11766 (forward-sexp)
11767 (<= pos (point))))
11768 (throw 'parse "ERROR: Not within a subprogram specification"))
11769 (setq name (match-string-no-properties 5))
11770 (setq kind (if (match-string 2) 'procedure 'function))
11771 (setq end-of-list (not (match-string 7)))
11772 (message "Reading interface of subprogram \"%s\"..." name)
11773 ;; parse parameter list
11774 (setq group-comment (vhdl-parse-group-comment))
11775 (setq end-of-list (or end-of-list
11776 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11777 (while (not end-of-list)
11778 ;; parse object
11779 (setq object
11780 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11781 (match-string-no-properties 1)))
11782 ;; parse names (accept extended identifiers)
11783 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11784 (setq names (list (match-string-no-properties 1)))
11785 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11786 (setq names (append names (list (match-string-no-properties 1)))))
11787 ;; parse direction
11788 (vhdl-parse-string ":[ \t\n]*")
11789 (setq direct
11790 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11791 (match-string-no-properties 1)))
11792 ;; parse type
11793 (vhdl-parse-string "\\([^():;\n]+\\)")
11794 (setq type (match-string-no-properties 1))
11795 (setq comment nil)
11796 (while (looking-at "(")
11797 (setq type
11798 (concat type
11799 (buffer-substring-no-properties
11800 (point) (progn (forward-sexp) (point)))
11801 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11802 (match-string-no-properties 1)))))
11803 ;; special case: closing parenthesis is on separate line
11804 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11805 (setq comment (substring type (match-beginning 2)))
11806 (setq type (substring type 0 (match-beginning 1))))
11807 ;; strip off trailing group-comment
11808 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11809 (setq type (substring type 0 (match-end 1)))
11810 ;; parse initialization expression
11811 (setq init nil)
11812 (when (vhdl-parse-string ":=[ \t\n]*" t)
11813 (vhdl-parse-string "\\([^();\n]*\\)")
11814 (setq init (match-string-no-properties 1))
11815 (while (looking-at "(")
11816 (setq init
11817 (concat init
11818 (buffer-substring-no-properties
11819 (point) (progn (forward-sexp) (point)))
11820 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11821 (match-string-no-properties 1))))))
11822 ;; special case: closing parenthesis is on separate line
11823 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11824 (setq comment (substring init (match-beginning 2)))
11825 (setq init (substring init 0 (match-beginning 1)))
11826 (vhdl-forward-syntactic-ws))
11827 (skip-chars-forward " \t")
11828 ;; parse inline comment, special case: as above, no initial.
11829 (unless comment
11830 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11831 (match-string-no-properties 1))))
11832 (vhdl-forward-syntactic-ws)
11833 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11834 ;; parse inline comment
11835 (unless comment
11836 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11837 (match-string-no-properties 1))))
11838 (setq return-group-comment (vhdl-parse-group-comment))
11839 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11840 ;; parse return type
11841 (when (match-string 3)
11842 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11843 (setq return-type (match-string-no-properties 1))
11844 (when (and return-type
11845 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11846 (setq return-comment (substring return-type (match-beginning 2)))
11847 (setq return-type (substring return-type 0 (match-beginning 1))))
11848 ;; strip of trailing group-comment
11849 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11850 (setq return-type (substring return-type 0 (match-end 1)))
11851 ;; parse return comment
11852 (unless return-comment
11853 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11854 (match-string-no-properties 1)))))
11855 ;; parse inline comment
11856 (unless comment
11857 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11858 (match-string-no-properties 1))))
11859 ;; save everything in list
11860 (setq param-list (append param-list
11861 (list (list names object direct type init
11862 comment group-comment))))
11863 ;; parse group comment and spacing
11864 (setq group-comment (vhdl-parse-group-comment)))
11865 (message "Reading interface of subprogram \"%s\"...done" name)
11866 nil)))
11867 ;; finish parsing
11868 (if parse-error
11869 (error parse-error)
11870 (setq vhdl-subprog-list
11871 (list name kind param-list return-type return-comment
11872 return-group-comment)
11873 vhdl-subprog-flattened nil)))))
11874
11875(defun vhdl-subprog-paste-specification (kind)
11876 "Paste as a subprogram specification."
11877 (indent-according-to-mode)
11878 (let ((margin (current-column))
11879 (param-list (nth 2 vhdl-subprog-list))
11880 list-margin start names param)
11881 ;; paste keyword and name
11882 (vhdl-insert-keyword
11883 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11884 (insert (nth 0 vhdl-subprog-list))
11885 (if (not param-list)
11886 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11887 (setq start (point))
11888 ;; paste parameter list
11889 (insert " (")
11890 (unless vhdl-argument-list-indent
11891 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11892 (setq list-margin (current-column))
11893 (while param-list
11894 (setq param (car param-list))
11895 ;; paste group comment and spacing
11896 (when (memq vhdl-include-group-comments (list kind 'always))
11897 (vhdl-paste-group-comment (nth 6 param) list-margin))
11898 ;; paste object
11899 (when (nth 1 param) (insert (nth 1 param) " "))
11900 ;; paste names
11901 (setq names (nth 0 param))
11902 (while names
11903 (insert (car names))
11904 (setq names (cdr names))
11905 (when names (insert ", ")))
11906 ;; paste direction
11907 (insert " : ")
11908 (when (nth 2 param) (insert (nth 2 param) " "))
11909 ;; paste type
11910 (insert (nth 3 param))
11911 ;; paste initialization
11912 (when (nth 4 param) (insert " := " (nth 4 param)))
11913 ;; terminate line
11914 (if (cdr param-list)
11915 (insert ";")
11916 (insert ")")
11917 (when (null (nth 3 vhdl-subprog-list))
11918 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11919 ;; paste comment
11920 (when (and vhdl-include-port-comments (nth 5 param))
11921 (vhdl-comment-insert-inline (nth 5 param) t))
11922 (setq param-list (cdr param-list))
11923 (when param-list (insert "\n") (indent-to list-margin)))
11924 (when (nth 3 vhdl-subprog-list)
11925 (insert "\n") (indent-to list-margin)
11926 ;; paste group comment and spacing
11927 (when (memq vhdl-include-group-comments (list kind 'always))
11928 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11929 ;; paste return type
11930 (insert "return " (nth 3 vhdl-subprog-list))
0a2e512a 11931 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
3dcb36b7
JB
11932 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11933 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11934 ;; align parameter list
11935 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11936 ;; paste body
11937 (when (eq kind 'body)
11938 (insert "\n")
11939 (vhdl-template-begin-end
11940 (unless (vhdl-standard-p '87)
11941 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11942 (nth 0 vhdl-subprog-list) margin))))
11943
11944(defun vhdl-subprog-paste-declaration ()
11945 "Paste as a subprogram declaration."
11946 (interactive)
11947 (if (not vhdl-subprog-list)
11948 (error "ERROR: No subprogram interface read")
11949 (message "Pasting interface as subprogram declaration \"%s\"..."
11950 (car vhdl-subprog-list))
11951 ;; paste specification
11952 (vhdl-subprog-paste-specification 'decl)
11953 (message "Pasting interface as subprogram declaration \"%s\"...done"
11954 (car vhdl-subprog-list))))
11955
11956(defun vhdl-subprog-paste-body ()
11957 "Paste as a subprogram body."
11958 (interactive)
11959 (if (not vhdl-subprog-list)
11960 (error "ERROR: No subprogram interface read")
11961 (message "Pasting interface as subprogram body \"%s\"..."
11962 (car vhdl-subprog-list))
11963 ;; paste specification and body
11964 (vhdl-subprog-paste-specification 'body)
11965 (message "Pasting interface as subprogram body \"%s\"...done"
11966 (car vhdl-subprog-list))))
11967
11968(defun vhdl-subprog-paste-call ()
11969 "Paste as a subprogram call."
11970 (interactive)
11971 (if (not vhdl-subprog-list)
11972 (error "ERROR: No subprogram interface read")
11973 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11974 param-list margin list-margin param start)
11975 ;; flatten local copy of interface list (must be flat for parameter mapping)
11976 (vhdl-subprog-flatten)
11977 (setq param-list (nth 2 vhdl-subprog-list))
11978 (indent-according-to-mode)
11979 (setq margin (current-indentation))
11980 (message "Pasting interface as subprogram call \"%s\"..."
11981 (car vhdl-subprog-list))
11982 ;; paste name
11983 (insert (nth 0 vhdl-subprog-list))
11984 (if (not param-list)
11985 (insert ";")
11986 (setq start (point))
11987 ;; paste parameter list
11988 (insert " (")
11989 (unless vhdl-argument-list-indent
11990 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11991 (setq list-margin (current-column))
11992 (while param-list
11993 (setq param (car param-list))
11994 ;; paste group comment and spacing
11995 (when (eq vhdl-include-group-comments 'always)
11996 (vhdl-paste-group-comment (nth 6 param) list-margin))
11997 ;; paste formal port
11998 (insert (car (nth 0 param)) " => ")
11999 (setq param-list (cdr param-list))
12000 (insert (if param-list "," ");"))
12001 ;; paste comment
12002 (when (and vhdl-include-port-comments (nth 5 param))
12003 (vhdl-comment-insert-inline (nth 5 param)))
12004 (when param-list (insert "\n") (indent-to list-margin)))
12005 ;; align parameter list
12006 (when vhdl-auto-align
12007 (vhdl-align-region-groups start (point) 1)))
12008 (message "Pasting interface as subprogram call \"%s\"...done"
12009 (car vhdl-subprog-list))
12010 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
12011
12012
12013;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12014;;; Miscellaneous
12015;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12016
12017;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12018;; Hippie expand customization
12019
12020(defvar vhdl-expand-upper-case nil)
12021
12022(defun vhdl-try-expand-abbrev (old)
12023 "Try expanding abbreviations from `vhdl-abbrev-list'."
12024 (unless old
12025 (he-init-string (he-dabbrev-beg) (point))
5eabfe72
KH
12026 (setq he-expand-list
12027 (let ((abbrev-list vhdl-abbrev-list)
12028 (sel-abbrev-list '()))
12029 (while abbrev-list
12030 (when (or (not (stringp (car abbrev-list)))
12031 (string-match
12032 (concat "^" he-search-string) (car abbrev-list)))
12033 (setq sel-abbrev-list
12034 (cons (car abbrev-list) sel-abbrev-list)))
12035 (setq abbrev-list (cdr abbrev-list)))
12036 (nreverse sel-abbrev-list))))
12037 (while (and he-expand-list
12038 (or (not (stringp (car he-expand-list)))
12039 (he-string-member (car he-expand-list) he-tried-table t)))
12040; (equal (car he-expand-list) he-search-string)))
12041 (unless (stringp (car he-expand-list))
12042 (setq vhdl-expand-upper-case (car he-expand-list)))
12043 (setq he-expand-list (cdr he-expand-list)))
12044 (if (null he-expand-list)
12045 (progn (when old (he-reset-string))
12046 nil)
12047 (he-substitute-string
12048 (if vhdl-expand-upper-case
12049 (upcase (car he-expand-list))
12050 (car he-expand-list))
12051 t)
12052 (setq he-expand-list (cdr he-expand-list))
12053 t))
12054
12055(defun vhdl-he-list-beg ()
12056 "Also looks at the word before `(' in order to better match parenthesized
12057expressions (e.g. for index ranges of types and signals)."
12058 (save-excursion
12059 (condition-case ()
12060 (progn (backward-up-list 1)
12061 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12062 (error ()))
12063 (point)))
12064
12065;; override `he-list-beg' from `hippie-exp'
12066(unless (and (boundp 'viper-mode) viper-mode)
5eabfe72
KH
12067 (defalias 'he-list-beg 'vhdl-he-list-beg))
12068
12069;; function for expanding abbrevs and dabbrevs
3dcb36b7 12070(defun vhdl-expand-abbrev (arg))
5eabfe72
KH
12071(fset 'vhdl-expand-abbrev (make-hippie-expand-function
12072 '(try-expand-dabbrev
12073 try-expand-dabbrev-all-buffers
12074 vhdl-try-expand-abbrev)))
12075
12076;; function for expanding parenthesis
3dcb36b7 12077(defun vhdl-expand-paren (arg))
5eabfe72
KH
12078(fset 'vhdl-expand-paren (make-hippie-expand-function
12079 '(try-expand-list
12080 try-expand-list-all-buffers)))
12081
12082;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12083;; Case fixing
d2ddb974
KH
12084
12085(defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
12086 "Convert all words matching word-regexp in region to lower or upper case,
12087depending on parameter upper-case."
3dcb36b7 12088 (let ((case-replace nil)
5eabfe72 12089 (last-update 0))
3dcb36b7 12090 (vhdl-prepare-search-2
5eabfe72
KH
12091 (save-excursion
12092 (goto-char end)
12093 (setq end (point-marker))
12094 (goto-char beg)
12095 (while (re-search-forward word-regexp end t)
3dcb36b7 12096 (or (vhdl-in-literal)
5eabfe72
KH
12097 (if upper-case
12098 (upcase-word -1)
12099 (downcase-word -1)))
3dcb36b7 12100 (when (and count vhdl-progress-interval (not noninteractive)
5eabfe72
KH
12101 (< vhdl-progress-interval
12102 (- (nth 1 (current-time)) last-update)))
12103 (message "Fixing case... (%2d%s)"
12104 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
12105 "%")
12106 (setq last-update (nth 1 (current-time)))))
3dcb36b7 12107 (goto-char end)))))
d2ddb974
KH
12108
12109(defun vhdl-fix-case-region (beg end &optional arg)
12110 "Convert all VHDL words in region to lower or upper case, depending on
3dcb36b7 12111options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974
KH
12112 (interactive "r\nP")
12113 (vhdl-fix-case-region-1
5eabfe72 12114 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
d2ddb974 12115 (vhdl-fix-case-region-1
5eabfe72 12116 beg end vhdl-upper-case-types vhdl-types-regexp 1)
d2ddb974 12117 (vhdl-fix-case-region-1
5eabfe72
KH
12118 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
12119 (vhdl-fix-case-region-1
3dcb36b7
JB
12120 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
12121 (when vhdl-progress-interval (message "Fixing case...done")))
d2ddb974 12122
5eabfe72
KH
12123(defun vhdl-fix-case-buffer ()
12124 "Convert all VHDL words in buffer to lower or upper case, depending on
3dcb36b7 12125options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974 12126 (interactive)
5eabfe72
KH
12127 (vhdl-fix-case-region (point-min) (point-max)))
12128
3dcb36b7
JB
12129(defun vhdl-fix-case-word (&optional arg)
12130 "Convert word after cursor to upper case if necessary."
12131 (interactive "p")
12132 (save-excursion
12133 (when arg (backward-word 1))
12134 (vhdl-prepare-search-1
12135 (when (and vhdl-upper-case-keywords
12136 (looking-at vhdl-keywords-regexp))
12137 (upcase-word 1))
12138 (when (and vhdl-upper-case-types
12139 (looking-at vhdl-types-regexp))
12140 (upcase-word 1))
12141 (when (and vhdl-upper-case-attributes
12142 (looking-at vhdl-attributes-regexp))
12143 (upcase-word 1))
12144 (when (and vhdl-upper-case-enum-values
12145 (looking-at vhdl-enum-values-regexp))
12146 (upcase-word 1)))))
12147
5eabfe72
KH
12148;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12149;; Line handling functions
d2ddb974
KH
12150
12151(defun vhdl-current-line ()
12152 "Return the line number of the line containing point."
12153 (save-restriction
12154 (widen)
0a2e512a
RF
12155 (save-excursion
12156 (beginning-of-line)
12157 (1+ (count-lines 1 (point))))))
d2ddb974 12158
5eabfe72 12159(defun vhdl-line-kill-entire (&optional arg)
d2ddb974 12160 "Delete entire line."
5eabfe72
KH
12161 (interactive "p")
12162 (beginning-of-line)
12163 (kill-line (or arg 1)))
12164
12165(defun vhdl-line-kill (&optional arg)
12166 "Kill current line."
12167 (interactive "p")
12168 (vhdl-line-kill-entire arg))
12169
12170(defun vhdl-line-copy (&optional arg)
12171 "Copy current line."
12172 (interactive "p")
12173 (save-excursion
12174 (beginning-of-line)
12175 (let ((position (point)))
12176 (forward-line (or arg 1))
12177 (copy-region-as-kill position (point)))))
12178
12179(defun vhdl-line-yank ()
12180 "Yank entire line."
d2ddb974 12181 (interactive)
5eabfe72
KH
12182 (beginning-of-line)
12183 (yank))
d2ddb974 12184
5eabfe72
KH
12185(defun vhdl-line-expand (&optional prefix-arg)
12186 "Hippie-expand current line."
12187 (interactive "P")
12188 (let ((case-fold-search t) (case-replace nil)
12189 (hippie-expand-try-functions-list
12190 '(try-expand-line try-expand-line-all-buffers)))
12191 (hippie-expand prefix-arg)))
12192
12193(defun vhdl-line-transpose-next (&optional arg)
12194 "Interchange this line with next line."
12195 (interactive "p")
12196 (forward-line 1)
12197 (transpose-lines (or arg 1))
12198 (forward-line -1))
12199
12200(defun vhdl-line-transpose-previous (&optional arg)
12201 "Interchange this line with previous line."
12202 (interactive "p")
12203 (forward-line 1)
12204 (transpose-lines (- 0 (or arg 0)))
12205 (forward-line -1))
12206
12207(defun vhdl-line-open ()
d2ddb974
KH
12208 "Open a new line and indent."
12209 (interactive)
5eabfe72
KH
12210 (end-of-line -0)
12211 (newline-and-indent))
d2ddb974 12212
3dcb36b7
JB
12213(defun vhdl-delete-indentation ()
12214 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12215it works within comments too."
12216 (interactive)
12217 (let ((fill-prefix "-- "))
12218 (delete-indentation)))
d2ddb974 12219
5eabfe72 12220;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12221;; Move functions
d2ddb974 12222
3dcb36b7
JB
12223(defun vhdl-forward-same-indent ()
12224 "Move forward to next line with same indent."
12225 (interactive)
12226 (let ((pos (point))
12227 (indent (current-indentation)))
12228 (beginning-of-line 2)
12229 (while (and (not (eobp))
12230 (or (looking-at "^\\s-*\\(--.*\\)?$")
12231 (> (current-indentation) indent)))
12232 (beginning-of-line 2))
12233 (if (= (current-indentation) indent)
12234 (back-to-indentation)
12235 (message "No following line with same indent found in this block")
12236 (goto-char pos)
12237 nil)))
5eabfe72 12238
3dcb36b7
JB
12239(defun vhdl-backward-same-indent ()
12240 "Move backward to previous line with same indent."
12241 (interactive)
12242 (let ((pos (point))
12243 (indent (current-indentation)))
12244 (beginning-of-line -0)
12245 (while (and (not (bobp))
12246 (or (looking-at "^\\s-*\\(--.*\\)?$")
12247 (> (current-indentation) indent)))
12248 (beginning-of-line -0))
12249 (if (= (current-indentation) indent)
12250 (back-to-indentation)
12251 (message "No preceding line with same indent found in this block")
12252 (goto-char pos)
12253 nil)))
5eabfe72
KH
12254
12255;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
12256;; Statistics
12257
12258(defun vhdl-statistics-buffer ()
12259 "Get some file statistics."
12260 (interactive)
12261 (let ((no-stats 0)
12262 (no-code-lines 0)
12263 (no-lines (count-lines (point-min) (point-max))))
12264 (save-excursion
12265 ;; count statements
12266 (goto-char (point-min))
12267 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12268 (if (match-string 1)
12269 (goto-char (match-end 1))
12270 (setq no-stats (1+ no-stats))))
12271 ;; count code lines
12272 (goto-char (point-min))
12273 (while (not (eobp))
12274 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12275 (setq no-code-lines (1+ no-code-lines)))
12276 (beginning-of-line 2)))
12277 ;; print results
12278 (message "\n\
12279File statistics: \"%s\"\n\
12280---------------------\n\
12281# statements : %5d\n\
12282# code lines : %5d\n\
12283# total lines : %5d\n\ "
0a2e512a
RF
12284 (buffer-file-name) no-stats no-code-lines no-lines)
12285 (unless vhdl-emacs-21 (vhdl-show-messages))))
3dcb36b7 12286
5eabfe72 12287;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12288;; Help functions
d2ddb974 12289
3dcb36b7
JB
12290(defun vhdl-re-search-forward (regexp &optional bound noerror count)
12291 "Like `re-search-forward', but does not match within literals."
12292 (let (pos)
12293 (save-excursion
12294 (while (and (setq pos (re-search-forward regexp bound noerror count))
12295 (vhdl-in-literal))))
12296 (when pos (goto-char pos))
12297 pos))
12298
12299(defun vhdl-re-search-backward (regexp &optional bound noerror count)
12300 "Like `re-search-backward', but does not match within literals."
12301 (let (pos)
12302 (save-excursion
12303 (while (and (setq pos (re-search-backward regexp bound noerror count))
12304 (vhdl-in-literal))))
12305 (when pos (goto-char pos))
12306 pos))
5eabfe72 12307
d2ddb974 12308
3dcb36b7
JB
12309;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12310;;; Project
12311;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12312
12313(defun vhdl-set-project (name)
12314 "Set current project to NAME."
12315 (interactive
12316 (list (let ((completion-ignore-case t))
12317 (completing-read "Project name: " vhdl-project-alist nil t))))
12318 (cond ((equal name "")
12319 (setq vhdl-project nil)
12320 (message "Current VHDL project: None"))
12321 ((assoc name vhdl-project-alist)
12322 (setq vhdl-project name)
12323 (message "Current VHDL project: \"%s\"" name))
12324 (t
12325 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12326 (vhdl-speedbar-update-current-project))
12327
0a2e512a
RF
12328(defun vhdl-set-default-project ()
12329 "Set current project as default on startup."
12330 (interactive)
12331 (customize-set-variable 'vhdl-project vhdl-project)
12332 (customize-save-customized))
12333
3dcb36b7
JB
12334(defun vhdl-toggle-project (name token indent)
12335 "Set current project to NAME or unset if NAME is current project."
12336 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12337
12338(defun vhdl-export-project (file-name)
12339 "Write project setup for current project."
12340 (interactive
12341 (let ((name (vhdl-resolve-env-variable
12342 (vhdl-replace-string
12343 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12344 (concat (subst-char-in-string
12345 ? ?_ (or (vhdl-project-p)
12346 (error "ERROR: No current project")))
12347 " " (user-login-name))))))
12348 (list (read-file-name
12349 "Write project file: "
12350 (when (file-name-absolute-p name) "") nil nil name))))
12351 (setq file-name (abbreviate-file-name file-name))
12352 (let ((orig-buffer (current-buffer)))
12353 (unless (file-exists-p (file-name-directory file-name))
12354 (make-directory (file-name-directory file-name) t))
12355 (if (not (file-writable-p file-name))
12356 (error "ERROR: File not writable: \"%s\"" file-name)
12357 (set-buffer (find-file-noselect file-name t t))
12358 (erase-buffer)
12359 (insert ";; -*- Emacs-Lisp -*-\n\n"
12360 ";;; " (file-name-nondirectory file-name)
12361 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12362 ";; Project : " vhdl-project "\n"
12363 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12364 (user-login-name) "\n\n\n"
12365 ";; project name\n"
12366 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12367 ";; project setup\n"
12368 "(aput 'vhdl-project-alist vhdl-project\n'")
12369 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12370 (insert ")\n")
12371 (save-buffer)
12372 (kill-buffer (current-buffer))
12373 (set-buffer orig-buffer))))
12374
12375(defun vhdl-import-project (file-name &optional auto not-make-current)
12376 "Read project setup and set current project."
12377 (interactive
12378 (let ((name (vhdl-resolve-env-variable
12379 (vhdl-replace-string
12380 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12381 (concat "" " " (user-login-name))))))
12382 (list (read-file-name
12383 "Read project file: " (when (file-name-absolute-p name) "") nil t
12384 (file-name-directory name)))))
12385 (when (file-exists-p file-name)
12386 (condition-case ()
12387 (let ((current-project vhdl-project))
12388 (load-file file-name)
12389 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12390 (adelete 'vhdl-project-alist vhdl-project)
0a2e512a 12391 (error ""))
3dcb36b7
JB
12392 (when not-make-current
12393 (setq vhdl-project current-project))
12394 (vhdl-update-mode-menu)
12395 (vhdl-speedbar-refresh)
12396 (unless not-make-current
12397 (message "Current VHDL project: \"%s\"%s"
12398 vhdl-project (if auto " (auto-loaded)" ""))))
12399 (error (vhdl-warning
12400 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12401
12402(defun vhdl-duplicate-project ()
12403 "Duplicate setup of current project."
5eabfe72 12404 (interactive)
3dcb36b7
JB
12405 (let ((new-name (read-from-minibuffer "New project name: "))
12406 (project-entry (aget vhdl-project-alist vhdl-project t)))
12407 (setq vhdl-project-alist
12408 (append vhdl-project-alist
12409 (list (cons new-name project-entry))))
12410 (vhdl-update-mode-menu)))
12411
12412(defun vhdl-auto-load-project ()
12413 "Automatically load project setup at startup."
12414 (let ((file-name-list vhdl-project-file-name)
12415 file-list list-length)
12416 (while file-name-list
12417 (setq file-list
12418 (append file-list
12419 (file-expand-wildcards
12420 (vhdl-resolve-env-variable
12421 (vhdl-replace-string
12422 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12423 (concat "\*" " " (user-login-name)))))))
12424 (setq list-length (or list-length (length file-list)))
12425 (setq file-name-list (cdr file-name-list)))
12426 (while file-list
12427 (vhdl-import-project (expand-file-name (car file-list)) t
12428 (not (> list-length 0)))
12429 (setq list-length (1- list-length))
12430 (setq file-list (cdr file-list)))))
12431
12432;; automatically load project setup when idle after startup
12433(when (memq 'startup vhdl-project-auto-load)
12434 (if noninteractive
12435 (vhdl-auto-load-project)
12436 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
5eabfe72
KH
12437
12438
12439;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12440;;; Hideshow
12441;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12442;; (using `hideshow.el')
d2ddb974 12443
3dcb36b7
JB
12444(defconst vhdl-hs-start-regexp
12445 (concat
12446 "\\(^\\)\\s-*\\("
12447 ;; generic/port clause
12448 "\\(generic\\|port\\)[ \t\n]*(\\|"
12449 ;; component
12450 "component\\>\\|"
12451 ;; component instantiation
12452 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12453 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12454 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12455 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12456 ;; subprogram
12457 "\\(function\\|procedure\\)\\>\\|"
12458 ;; process, block
12459 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12460 ;; configuration declaration
12461 "configuration\\>"
12462 "\\)")
12463 "Regexp to match start of construct to hide.")
12464
12465(defun vhdl-hs-forward-sexp-func (count)
12466 "Find end of construct to hide (for hideshow). Only searches forward."
12467 (let ((pos (point)))
12468 (vhdl-prepare-search-2
12469 (beginning-of-line)
12470 (cond
12471 ;; generic/port clause
12472 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12473 (goto-char (match-end 0))
12474 (backward-char)
12475 (forward-sexp))
12476 ;; component declaration
12477 ((looking-at "^\\s-*component\\>")
12478 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12479 ;; component instantiation
12480 ((looking-at
12481 (concat
12482 "^\\s-*\\w+\\s-*:[ \t\n]*"
12483 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12484 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12485 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12486 (goto-char (match-end 0))
12487 (backward-char)
12488 (forward-sexp)
12489 (setq pos (point))
12490 (vhdl-forward-syntactic-ws)
12491 (when (looking-at "port\\s-+map[ \t\n]*(")
12492 (goto-char (match-end 0))
12493 (backward-char)
12494 (forward-sexp)
12495 (setq pos (point)))
12496 (goto-char pos))
12497 ;; subprogram declaration/body
12498 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12499 (goto-char (match-end 0))
12500 (vhdl-forward-syntactic-ws)
12501 (when (looking-at "(")
12502 (forward-sexp))
12503 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12504 (vhdl-in-literal)))
12505 ;; subprogram body
12506 (when (match-string 2)
12507 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12508 (backward-word 1)
12509 (vhdl-forward-sexp)))
12510 ;; block (recursive)
12511 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12512 (goto-char (match-end 0))
12513 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12514 (match-beginning 2))
12515 (vhdl-hs-forward-sexp-func count)))
12516 ;; process
12517 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12518 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12519 ;; configuration declaration
12520 ((looking-at "^\\s-*configuration\\>")
12521 (forward-word 4)
12522 (vhdl-forward-sexp))
12523 (t (goto-char pos))))))
5eabfe72
KH
12524
12525(defun vhdl-hideshow-init ()
12526 "Initialize `hideshow'."
3dcb36b7
JB
12527 (when vhdl-hideshow-menu
12528 (vhdl-hs-minor-mode 1)))
12529
12530(defun vhdl-hs-minor-mode (&optional arg)
12531 "Toggle hideshow minor mode and update menu bar."
12532 (interactive "P")
12533 (require 'hideshow)
12534 ;; check for hideshow version 5.x
12535 (if (not (boundp 'hs-block-start-mdata-select))
12536 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12537 ;; initialize hideshow
12538 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12539 (setq hs-special-modes-alist
12540 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12541 'vhdl-hs-forward-sexp-func nil)
12542 hs-special-modes-alist)))
12543 (make-local-variable 'hs-minor-mode-hook)
12544 (if vhdl-hide-all-init
12545 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12546 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12547 (hs-minor-mode arg)
12548 (vhdl-mode-line-update))) ; hack to update menu bar
5eabfe72
KH
12549
12550
12551;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12552;;; Font locking
12553;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12554;; (using `font-lock.el')
12555
5eabfe72 12556;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12557;; Help functions
5eabfe72
KH
12558
12559(defun vhdl-within-translate-off ()
12560 "Return point if within translate-off region, else nil."
12561 (and (save-excursion
12562 (re-search-backward
12563 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12564 (equal "off" (match-string 1))
12565 (point)))
12566
12567(defun vhdl-start-translate-off (limit)
12568 "Return point before translate-off pragma if before LIMIT, else nil."
12569 (when (re-search-forward
12570 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12571 (match-beginning 0)))
12572
12573(defun vhdl-end-translate-off (limit)
12574 "Return point after translate-on pragma if before LIMIT, else nil."
12575 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12576
12577(defun vhdl-match-translate-off (limit)
12578 "Match a translate-off block, setting match-data and returning t, else nil."
12579 (when (< (point) limit)
12580 (let ((start (or (vhdl-within-translate-off)
12581 (vhdl-start-translate-off limit)))
12582 (case-fold-search t))
12583 (when start
12584 (let ((end (or (vhdl-end-translate-off limit) limit)))
12585 (set-match-data (list start end))
12586 (goto-char end))))))
12587
12588(defun vhdl-font-lock-match-item (limit)
12589 "Match, and move over, any declaration item after point. Adapted from
12590`font-lock-match-c-style-declaration-item-and-skip-to-next'."
12591 (condition-case nil
12592 (save-restriction
12593 (narrow-to-region (point-min) limit)
12594 ;; match item
3dcb36b7 12595 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5eabfe72
KH
12596 (save-match-data
12597 (goto-char (match-end 1))
12598 ;; move to next item
0a2e512a
RF
12599 (if (looking-at "\\(\\s-*,\\)")
12600 (goto-char (match-end 1))
5eabfe72
KH
12601 (end-of-line) t))))
12602 (error t)))
12603
12604;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12605;; Syntax definitions
12606
5eabfe72
KH
12607(defconst vhdl-font-lock-syntactic-keywords
12608 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12609 "Mark single quotes as having string quote syntax in 'c' instances.")
12610
d2ddb974
KH
12611(defvar vhdl-font-lock-keywords nil
12612 "Regular expressions to highlight in VHDL Mode.")
12613
3dcb36b7
JB
12614(defvar vhdl-font-lock-keywords-0
12615 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12616 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12617This does highlighting of template prompts and directives (pragmas).")
d2ddb974 12618
5eabfe72 12619(defvar vhdl-font-lock-keywords-1 nil
3dcb36b7 12620 ;; set in `vhdl-font-lock-init' because dependent on user options
5eabfe72
KH
12621 "For consideration as a value of `vhdl-font-lock-keywords'.
12622This does highlighting of keywords and standard identifiers.")
12623
12624(defconst vhdl-font-lock-keywords-2
d2ddb974
KH
12625 (list
12626 ;; highlight names of units, subprograms, and components when declared
12627 (list
12628 (concat
12629 "^\\s-*\\("
3dcb36b7
JB
12630 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12631 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
d2ddb974 12632 "\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12633 5 'font-lock-function-name-face)
12634
12635 ;; highlight entity names of architectures and configurations
12636 (list
12637 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12638 2 'font-lock-function-name-face)
d2ddb974
KH
12639
12640 ;; highlight labels of common constructs
12641 (list
12642 (concat
3dcb36b7
JB
12643 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12644 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12645 "postponed\\|process\\|"
5eabfe72
KH
12646 (when (vhdl-standard-p 'ams) "procedural\\|")
12647 "with\\|while"
0a2e512a 12648 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
d2ddb974
KH
12649 1 'font-lock-function-name-face)
12650
5eabfe72 12651 ;; highlight label and component name of component instantiations
d2ddb974 12652 (list
5eabfe72 12653 (concat
3dcb36b7
JB
12654 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12655 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12656 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12657
12658 ;; highlight label and instantiated unit of component instantiations
12659 (list
12660 (concat
12661 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12662 "\\(component\\|configuration\\|entity\\)\\s-+"
12663 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12664 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12665 '(5 font-lock-function-name-face nil t)
12666 '(7 font-lock-function-name-face nil t))
d2ddb974
KH
12667
12668 ;; highlight names and labels at end of constructs
12669 (list
12670 (concat
5eabfe72
KH
12671 "^\\s-*end\\s-+\\(\\("
12672 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
3dcb36b7
JB
12673 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12674 "procedure\\|\\(postponed\\s-+\\)?process\\|"
5eabfe72
KH
12675 (when (vhdl-standard-p 'ams) "procedural\\|")
12676 "units"
3dcb36b7 12677 "\\)\\s-+\\)?\\(\\w*\\)")
5eabfe72
KH
12678 5 'font-lock-function-name-face)
12679
12680 ;; highlight labels in exit and next statements
12681 (list
12682 (concat
12683 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12684 3 'font-lock-function-name-face)
12685
12686 ;; highlight entity name in attribute specifications
12687 (list
12688 (concat
12689 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12690 1 'font-lock-function-name-face)
12691
3dcb36b7
JB
12692 ;; highlight labels in block and component specifications
12693 (list
12694 (concat
12695 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12696 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12697 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12698
12699 ;; highlight names in library clauses
12700 (list "^\\s-*library\\>"
12701 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12702
12703 ;; highlight names in use clauses
5eabfe72
KH
12704 (list
12705 (concat
3dcb36b7
JB
12706 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12707 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12708 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12709 '(7 font-lock-function-name-face nil t))
5eabfe72
KH
12710
12711 ;; highlight attribute name in attribute declarations/specifications
12712 (list
12713 (concat
12714 "^\\s-*attribute\\s-+\\(\\w+\\)")
0a2e512a 12715 1 'vhdl-font-lock-attribute-face)
5eabfe72
KH
12716
12717 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12718 (list
12719 (concat
3dcb36b7 12720 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12721 3 'font-lock-type-face)
12722
12723 ;; highlight signal/variable/constant declaration names
12724 (list "\\(:[^=]\\)"
12725 '(vhdl-font-lock-match-item
12726 (progn (goto-char (match-beginning 1))
12727 (skip-syntax-backward " ")
12728 (skip-syntax-backward "w_")
12729 (skip-syntax-backward " ")
12730 (while (= (preceding-char) ?,)
12731 (backward-char 1)
12732 (skip-syntax-backward " ")
12733 (skip-syntax-backward "w_")
12734 (skip-syntax-backward " ")))
12735; (skip-chars-backward "^-(\n\";")
12736 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12737
3dcb36b7
JB
12738 ;; highlight formal parameters in component instantiations and subprogram
12739 ;; calls
12740 (list "\\(=>\\)"
12741 '(vhdl-font-lock-match-item
12742 (progn (goto-char (match-beginning 1))
12743 (skip-syntax-backward " ")
12744 (while (= (preceding-char) ?\)) (backward-sexp))
12745 (skip-syntax-backward "w_")
12746 (skip-syntax-backward " ")
0a2e512a 12747 (when (memq (preceding-char) '(?n ?N ?|))
3dcb36b7
JB
12748 (goto-char (point-max))))
12749 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12750
12751 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12752 ;; variables
12753 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
5eabfe72
KH
12754 '(vhdl-font-lock-match-item
12755 (progn (goto-char (match-end 1)) (match-beginning 2))
12756 nil (1 font-lock-variable-name-face)))
d2ddb974 12757 )
5eabfe72
KH
12758 "For consideration as a value of `vhdl-font-lock-keywords'.
12759This does context sensitive highlighting of names and labels.")
d2ddb974 12760
5eabfe72 12761(defvar vhdl-font-lock-keywords-3 nil
3dcb36b7 12762 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12763 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72
KH
12764This does highlighting of words with special syntax.")
12765
12766(defvar vhdl-font-lock-keywords-4 nil
3dcb36b7 12767 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12768 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12769This does highlighting of additional reserved words.")
d2ddb974 12770
5eabfe72
KH
12771(defconst vhdl-font-lock-keywords-5
12772 ;; background highlight translate-off regions
0a2e512a 12773 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
5eabfe72
KH
12774 "For consideration as a value of `vhdl-font-lock-keywords'.
12775This does background highlighting of translate-off regions.")
12776
12777;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12778;; Font and color definitions
12779
0a2e512a 12780(defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
d2ddb974
KH
12781 "Face name to use for prompts.")
12782
0a2e512a 12783(defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
5eabfe72
KH
12784 "Face name to use for standardized attributes.")
12785
0a2e512a 12786(defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
5eabfe72 12787 "Face name to use for standardized enumeration values.")
d2ddb974 12788
0a2e512a 12789(defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
5eabfe72 12790 "Face name to use for standardized functions and packages.")
d2ddb974 12791
0a2e512a 12792(defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
5eabfe72 12793 "Face name to use for directives.")
d2ddb974 12794
0a2e512a 12795(defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
5eabfe72 12796 "Face name to use for additional reserved words.")
d2ddb974 12797
0a2e512a 12798(defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
5eabfe72 12799 "Face name to use for translate-off regions.")
d2ddb974 12800
5eabfe72
KH
12801;; face names to use for words with special syntax.
12802(let ((syntax-alist vhdl-special-syntax-alist)
12803 name)
12804 (while syntax-alist
0a2e512a
RF
12805 (setq name (vhdl-function-name
12806 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
d4a5b644
GM
12807 (eval `(defvar ,name ',name
12808 ,(concat "Face name to use for "
12809 (nth 0 (car syntax-alist)) ".")))
5eabfe72
KH
12810 (setq syntax-alist (cdr syntax-alist))))
12811
3dcb36b7 12812(defgroup vhdl-highlight-faces nil
5eabfe72
KH
12813 "Faces for highlighting."
12814 :group 'vhdl-highlight)
d2ddb974 12815
3dcb36b7
JB
12816;; add faces used from `font-lock'
12817(custom-add-to-group
12818 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12819(custom-add-to-group
12820 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12821(custom-add-to-group
12822 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12823(custom-add-to-group
12824 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12825(custom-add-to-group
12826 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12827(custom-add-to-group
12828 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12829
0a2e512a 12830(defface vhdl-font-lock-prompt-face
f47877ee 12831 '((((min-colors 88) (class color) (background light))
ea81d57e 12832 (:foreground "Red1" :bold t))
f47877ee 12833 (((class color) (background light)) (:foreground "Red" :bold t))
3dcb36b7 12834 (((class color) (background dark)) (:foreground "Pink" :bold t))
d2ddb974 12835 (t (:inverse-video t)))
5eabfe72 12836 "Font lock mode face used to highlight prompts."
fa6674e3 12837 :group 'vhdl-highlight-faces)
d2ddb974 12838
0a2e512a 12839(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12840 '((((class color) (background light)) (:foreground "Orchid"))
12841 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12842 (t (:italic t :bold t)))
5eabfe72 12843 "Font lock mode face used to highlight standardized attributes."
fa6674e3 12844 :group 'vhdl-highlight-faces)
d2ddb974 12845
0a2e512a 12846(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12847 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12848 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12849 (t (:italic t :bold t)))
5eabfe72 12850 "Font lock mode face used to highlight standardized enumeration values."
fa6674e3 12851 :group 'vhdl-highlight-faces)
d2ddb974 12852
0a2e512a 12853(defface vhdl-font-lock-function-face
3dcb36b7 12854 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12855 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12856 (t (:italic t :bold t)))
5eabfe72 12857 "Font lock mode face used to highlight standardized functions and packages."
fa6674e3 12858 :group 'vhdl-highlight-faces)
d2ddb974 12859
0a2e512a 12860(defface vhdl-font-lock-directive-face
5eabfe72
KH
12861 '((((class color) (background light)) (:foreground "CadetBlue"))
12862 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12863 (t (:italic t :bold t)))
5eabfe72 12864 "Font lock mode face used to highlight directives."
fa6674e3 12865 :group 'vhdl-highlight-faces)
d2ddb974 12866
0a2e512a 12867(defface vhdl-font-lock-reserved-words-face
3dcb36b7 12868 '((((class color) (background light)) (:foreground "Orange" :bold t))
5bb5087f 12869 (((min-colors 88) (class color) (background dark))
ea81d57e 12870 (:foreground "Yellow1" :bold t))
3dcb36b7 12871 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12872 (t ()))
5eabfe72 12873 "Font lock mode face used to highlight additional reserved words."
fa6674e3 12874 :group 'vhdl-highlight-faces)
d2ddb974 12875
0a2e512a 12876(defface vhdl-font-lock-translate-off-face
5eabfe72
KH
12877 '((((class color) (background light)) (:background "LightGray"))
12878 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12879 (t ()))
5eabfe72 12880 "Font lock mode face used to background highlight translate-off regions."
fa6674e3 12881 :group 'vhdl-highlight-faces)
d2ddb974 12882
5eabfe72
KH
12883;; font lock mode faces used to highlight words with special syntax.
12884(let ((syntax-alist vhdl-special-syntax-alist))
12885 (while syntax-alist
0a2e512a
RF
12886 (eval `(defface ,(vhdl-function-name
12887 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12888 '((((class color) (background light))
12889 (:foreground ,(nth 2 (car syntax-alist))))
12890 (((class color) (background dark))
12891 (:foreground ,(nth 3 (car syntax-alist))))
12892 (t ()))
12893 ,(concat "Font lock mode face used to highlight "
12894 (nth 0 (car syntax-alist)) ".")
fa6674e3 12895 :group 'vhdl-highlight-faces))
5eabfe72
KH
12896 (setq syntax-alist (cdr syntax-alist))))
12897
12898;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12899;; Font lock initialization
12900
12901(defun vhdl-font-lock-init ()
5eabfe72 12902 "Initialize fontification."
0a2e512a 12903 ;; highlight template prompts and directives
3dcb36b7
JB
12904 (setq vhdl-font-lock-keywords-0
12905 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12906 vhdl-template-prompt-syntax ">\\)")
0a2e512a 12907 2 'vhdl-font-lock-prompt-face t)
3dcb36b7
JB
12908 (list (concat "--\\s-*"
12909 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
0a2e512a
RF
12910 2 'vhdl-font-lock-directive-face t)
12911 ;; highlight c-preprocessor directives
12912 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
12913 '(1 font-lock-builtin-face)
12914 '(3 font-lock-variable-name-face nil t))))
5eabfe72
KH
12915 ;; highlight keywords and standardized types, attributes, enumeration
12916 ;; values, and subprograms
12917 (setq vhdl-font-lock-keywords-1
12918 (list
0a2e512a
RF
12919 (list (concat "'" vhdl-attributes-regexp)
12920 1 'vhdl-font-lock-attribute-face)
5eabfe72 12921 (list vhdl-types-regexp 1 'font-lock-type-face)
0a2e512a
RF
12922 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12923 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12924 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
5eabfe72
KH
12925 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12926 ;; highlight words with special syntax.
12927 (setq vhdl-font-lock-keywords-3
12928 (let ((syntax-alist vhdl-special-syntax-alist)
12929 keywords)
12930 (while syntax-alist
12931 (setq keywords
12932 (cons
12933 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12934 (vhdl-function-name
0a2e512a 12935 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
5eabfe72
KH
12936 keywords))
12937 (setq syntax-alist (cdr syntax-alist)))
12938 keywords))
12939 ;; highlight additional reserved words
12940 (setq vhdl-font-lock-keywords-4
0a2e512a
RF
12941 (list (list vhdl-reserved-words-regexp 1
12942 'vhdl-font-lock-reserved-words-face)))
5eabfe72 12943 ;; highlight everything together
d2ddb974 12944 (setq vhdl-font-lock-keywords
5eabfe72
KH
12945 (append
12946 vhdl-font-lock-keywords-0
12947 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12948 (when (or vhdl-highlight-forbidden-words
12949 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12950 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12951 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12952 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12953
12954;; initialize fontification for VHDL Mode
12955(vhdl-font-lock-init)
12956
12957(defun vhdl-fontify-buffer ()
12958 "Re-initialize fontification and fontify buffer."
12959 (interactive)
12960 (setq font-lock-defaults
12961 (list
12962 'vhdl-font-lock-keywords nil
12963 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12964 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12965 (when (fboundp 'font-lock-unset-defaults)
12966 (font-lock-unset-defaults)) ; not implemented in XEmacs
0a2e512a 12967 (font-lock-set-defaults)
3dcb36b7
JB
12968 (font-lock-mode nil)
12969 (font-lock-mode t))
5eabfe72
KH
12970
12971;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12972;; Initialization for postscript printing
12973
12974(defun vhdl-ps-print-settings ()
12975 "Initialize custom face and page settings for postscript printing."
12976 ;; define custom face settings
12977 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12978 ps-print-color-p)
12979 (set (make-local-variable 'ps-bold-faces)
0a2e512a
RF
12980 '(font-lock-keyword-face
12981 font-lock-type-face
12982 vhdl-font-lock-attribute-face
12983 vhdl-font-lock-enumvalue-face
12984 vhdl-font-lock-directive-face))
d2ddb974
KH
12985 (set (make-local-variable 'ps-italic-faces)
12986 '(font-lock-comment-face
0a2e512a
RF
12987 font-lock-function-name-face
12988 font-lock-type-face
12989 vhdl-font-lock-attribute-face
12990 vhdl-font-lock-enumvalue-face
12991 vhdl-font-lock-directive-face))
d2ddb974
KH
12992 (set (make-local-variable 'ps-underlined-faces)
12993 '(font-lock-string-face))
5eabfe72 12994 (setq ps-always-build-face-reference t))
d2ddb974
KH
12995 ;; define page settings, so that a line containing 79 characters (default)
12996 ;; fits into one column
5eabfe72
KH
12997 (when vhdl-print-two-column
12998 (set (make-local-variable 'ps-landscape-mode) t)
12999 (set (make-local-variable 'ps-number-of-columns) 2)
13000 (set (make-local-variable 'ps-font-size) 7.0)
13001 (set (make-local-variable 'ps-header-title-font-size) 10.0)
13002 (set (make-local-variable 'ps-header-font-size) 9.0)
13003 (set (make-local-variable 'ps-header-offset) 12.0)
13004 (when (eq ps-paper-type 'letter)
13005 (set (make-local-variable 'ps-inter-column) 40.0)
13006 (set (make-local-variable 'ps-left-margin) 40.0)
13007 (set (make-local-variable 'ps-right-margin) 40.0))))
13008
13009(defun vhdl-ps-print-init ()
13010 "Initialize postscript printing."
3dcb36b7
JB
13011 (if vhdl-xemacs
13012 (when (boundp 'ps-print-color-p)
13013 (vhdl-ps-print-settings))
5eabfe72
KH
13014 (make-local-variable 'ps-print-hook)
13015 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
13016
13017
13018;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13019;;; Hierarchy browser (using `speedbar.el')
13020;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13021;; Allows displaying the hierarchy of all VHDL design units contained in a
13022;; directory by using the speedbar.
13023
13024;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13025;; Variables
13026
13027(defvar vhdl-entity-alist nil
3dcb36b7
JB
13028 "Cache with entities and corresponding architectures for each
13029project/directory.")
5eabfe72 13030;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
13031;; (cache-key
13032;; (ent-key ent-name ent-file ent-line
13033;; (arch-key arch-name arch-file arch-line
13034;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
0a2e512a
RF
13035;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13036;; (lib-name pack-key))
13037;; mra-key (lib-name pack-key))
3dcb36b7
JB
13038
13039(defvar vhdl-config-alist nil
13040 "Cache with configurations for each project/directory.")
13041;; structure: (parenthesised expression means list of such entries)
13042;; (cache-key
13043;; (conf-key conf-name conf-file conf-line ent-key arch-key
13044;; (inst-key inst-comp-name inst-ent-key inst-arch-key
0a2e512a 13045;; inst-conf-key inst-lib-key)
3dcb36b7 13046;; (lib-name pack-key)))
5eabfe72
KH
13047
13048(defvar vhdl-package-alist nil
3dcb36b7 13049 "Cache with packages for each project/directory.")
5eabfe72 13050;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
13051;; (cache-key
13052;; (pack-key pack-name pack-file pack-line
13053;; (comp-key comp-name comp-file comp-line)
13054;; (func-key func-name func-file func-line)
13055;; (lib-name pack-key)
13056;; pack-body-file pack-body-line
13057;; (func-key func-name func-body-file func-body-line)
13058;; (lib-name pack-key)))
5eabfe72
KH
13059
13060(defvar vhdl-ent-inst-alist nil
3dcb36b7 13061 "Cache with instantiated entities for each project/directory.")
5eabfe72 13062;; structure: (parenthesised expression means list of such entries)
3dcb36b7 13063;; (cache-key (inst-ent-key))
5eabfe72 13064
3dcb36b7
JB
13065(defvar vhdl-file-alist nil
13066 "Cache with design units in each file for each project/directory.")
13067;; structure: (parenthesised expression means list of such entries)
13068;; (cache-key
13069;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
0a2e512a 13070;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 13071
3dcb36b7
JB
13072(defvar vhdl-directory-alist nil
13073 "Cache with source directories for each project.")
13074;; structure: (parenthesised expression means list of such entries)
13075;; (cache-key (directory))
5eabfe72 13076
3dcb36b7 13077(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
13078 "Alist of design units simultaneously open in the current speedbar for each
13079directory and project.")
13080
3dcb36b7
JB
13081(defvar vhdl-speedbar-shown-project-list nil
13082 "List of projects simultaneously open in the current speedbar.")
5eabfe72 13083
3dcb36b7
JB
13084(defvar vhdl-updated-project-list nil
13085 "List of projects and directories with updated files.")
13086
13087(defvar vhdl-modified-file-list nil
13088 "List of modified files to be rescanned for hierarchy updating.")
13089
13090(defvar vhdl-speedbar-hierarchy-depth 0
13091 "Depth of instantiation hierarchy to display.")
13092
13093(defvar vhdl-speedbar-show-projects nil
13094 "Non-nil means project hierarchy is displayed in speedbar, directory
13095hierarchy otherwise.")
13096
13097(defun vhdl-get-end-of-unit ()
13098 "Return position of end of current unit."
13099 (let ((pos (point)))
13100 (save-excursion
13101 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
13102 (save-excursion
13103 (goto-char (match-beginning 0))
13104 (vhdl-backward-syntactic-ws)
13105 (and (/= (preceding-char) ?\;) (not (bobp))))))
13106 (re-search-backward "^[ \t]*end\\>" pos 1)
13107 (point))))
13108
13109(defun vhdl-match-string-downcase (num &optional string)
13110 "Like `match-string-no-properties' with down-casing."
13111 (let ((match (match-string-no-properties num string)))
13112 (and match (downcase match))))
5eabfe72 13113
5eabfe72
KH
13114
13115;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13116;; Scan functions
13117
3dcb36b7
JB
13118(defun vhdl-scan-context-clause ()
13119 "Scan the context clause that preceeds a design unit."
13120 (let (lib-alist)
13121 (save-excursion
13122 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
13123 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
13124 (equal "USE" (upcase (match-string 1))))
13125 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13126 (setq lib-alist (cons (cons (match-string-no-properties 1)
13127 (vhdl-match-string-downcase 2))
13128 lib-alist))))))
13129 lib-alist))
13130
13131(defun vhdl-scan-directory-contents (name &optional project update num-string
13132 non-final)
13133 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
13134 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
13135; (unless (file-directory-p (match-string 1 name))
13136; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
13137 (let* ((dir-name (match-string 1 name))
13138 (file-pattern (match-string 2 name))
13139 (is-directory (= 0 (length file-pattern)))
5eabfe72 13140 (file-list
3dcb36b7
JB
13141 (if update
13142 (list name)
13143 (if is-directory
13144 (vhdl-get-source-files t dir-name)
13145 (vhdl-directory-files
13146 dir-name t (wildcard-to-regexp file-pattern)))))
13147 (key (or project dir-name))
13148 (file-exclude-regexp
13149 (or (nth 3 (aget vhdl-project-alist project)) ""))
13150 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
13151 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
13152 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
13153 ent-alist conf-alist pack-alist ent-inst-list file-alist
13154 tmp-list tmp-entry no-files files-exist big-files)
13155 (when (or project update)
13156 (setq ent-alist (aget vhdl-entity-alist key t)
13157 conf-alist (aget vhdl-config-alist key t)
13158 pack-alist (aget vhdl-package-alist key t)
13159 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
13160 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
13161 (when (and (not is-directory) (null file-list))
13162 (message "No such file: \"%s\"" name))
3dcb36b7
JB
13163 (setq files-exist file-list)
13164 (when file-list
13165 (setq no-files (length file-list))
13166 (message "Scanning %s %s\"%s\"..."
13167 (if is-directory "directory" "files") (or num-string "") name)
13168 ;; exclude files
13169 (unless (equal file-exclude-regexp "")
13170 (let ((case-fold-search nil)
13171 file-tmp-list)
13172 (while file-list
13173 (unless (string-match file-exclude-regexp (car file-list))
13174 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
13175 (setq file-list (cdr file-list)))
13176 (setq file-list (nreverse file-tmp-list))))
13177 ;; do for all files
13178 (while file-list
13179 (unless noninteractive
5eabfe72
KH
13180 (message "Scanning %s %s\"%s\"... (%2d%s)"
13181 (if is-directory "directory" "files")
13182 (or num-string "") name
3dcb36b7
JB
13183 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
13184 (let ((file-name (abbreviate-file-name (car file-list)))
13185 ent-list arch-list arch-ent-list conf-list
13186 pack-list pack-body-list inst-list inst-ent-list)
13187 ;; scan file
13188 (vhdl-visit-file
13189 file-name nil
13190 (vhdl-prepare-search-2
13191 (save-excursion
13192 ;; scan for design units
13193 (if (and limit-design-file-size
13194 (< limit-design-file-size (buffer-size)))
13195 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
13196 (setq big-files t))
13197 ;; scan for entities
13198 (goto-char (point-min))
13199 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13200 (let* ((ent-name (match-string-no-properties 1))
13201 (ent-key (downcase ent-name))
13202 (ent-entry (aget ent-alist ent-key t))
3dcb36b7
JB
13203 (lib-alist (vhdl-scan-context-clause)))
13204 (if (nth 1 ent-entry)
13205 (vhdl-warning-when-idle
13206 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13207 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
13208 file-name (vhdl-current-line))
13209 (setq ent-list (cons ent-key ent-list))
13210 (aput 'ent-alist ent-key
13211 (list ent-name file-name (vhdl-current-line)
0a2e512a
RF
13212 (nth 3 ent-entry) (nth 4 ent-entry)
13213 lib-alist)))))
3dcb36b7
JB
13214 ;; scan for architectures
13215 (goto-char (point-min))
0a2e512a 13216 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
3dcb36b7
JB
13217 (let* ((arch-name (match-string-no-properties 1))
13218 (arch-key (downcase arch-name))
13219 (ent-name (match-string-no-properties 2))
13220 (ent-key (downcase ent-name))
13221 (ent-entry (aget ent-alist ent-key t))
13222 (arch-alist (nth 3 ent-entry))
13223 (arch-entry (aget arch-alist arch-key t))
13224 (lib-arch-alist (vhdl-scan-context-clause)))
13225 (if arch-entry
13226 (vhdl-warning-when-idle
13227 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13228 arch-name ent-name (nth 1 arch-entry)
13229 (nth 2 arch-entry) file-name (vhdl-current-line))
13230 (setq arch-list (cons arch-key arch-list)
13231 arch-ent-list (cons ent-key arch-ent-list))
13232 (aput 'arch-alist arch-key
13233 (list arch-name file-name (vhdl-current-line) nil
13234 lib-arch-alist))
13235 (aput 'ent-alist ent-key
13236 (list (or (nth 0 ent-entry) ent-name)
13237 (nth 1 ent-entry) (nth 2 ent-entry)
13238 (vhdl-sort-alist arch-alist)
0a2e512a 13239 arch-key (nth 5 ent-entry))))))
3dcb36b7
JB
13240 ;; scan for configurations
13241 (goto-char (point-min))
13242 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13243 (let* ((conf-name (match-string-no-properties 1))
13244 (conf-key (downcase conf-name))
13245 (conf-entry (aget conf-alist conf-key t))
13246 (ent-name (match-string-no-properties 2))
13247 (ent-key (downcase ent-name))
13248 (lib-alist (vhdl-scan-context-clause))
13249 (conf-line (vhdl-current-line))
13250 (end-of-unit (vhdl-get-end-of-unit))
13251 arch-key comp-conf-list inst-key-list
13252 inst-comp-key inst-ent-key inst-arch-key
13253 inst-conf-key inst-lib-key)
13254 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13255 (setq arch-key (vhdl-match-string-downcase 1)))
13256 (if conf-entry
13257 (vhdl-warning-when-idle
13258 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13259 conf-name ent-name (nth 1 conf-entry)
13260 (nth 2 conf-entry) file-name conf-line)
13261 (setq conf-list (cons conf-key conf-list))
13262 ;; scan for subconfigurations and subentities
13263 (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)
13264 (setq inst-comp-key (vhdl-match-string-downcase 3)
13265 inst-key-list (split-string
13266 (vhdl-match-string-downcase 1)
13267 "[ \t\n]*,[ \t\n]*"))
13268 (vhdl-forward-syntactic-ws)
13269 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13270 (setq
13271 inst-lib-key (vhdl-match-string-downcase 3)
13272 inst-ent-key (and (match-string 2)
13273 (vhdl-match-string-downcase 4))
13274 inst-arch-key (and (match-string 2)
13275 (vhdl-match-string-downcase 6))
13276 inst-conf-key (and (not (match-string 2))
13277 (vhdl-match-string-downcase 4)))
13278 (while inst-key-list
13279 (setq comp-conf-list
13280 (cons (list (car inst-key-list)
13281 inst-comp-key inst-ent-key
13282 inst-arch-key inst-conf-key
13283 inst-lib-key)
13284 comp-conf-list))
13285 (setq inst-key-list (cdr inst-key-list)))))
13286 (aput 'conf-alist conf-key
13287 (list conf-name file-name conf-line ent-key
13288 arch-key comp-conf-list lib-alist)))))
13289 ;; scan for packages
13290 (goto-char (point-min))
13291 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13292 (let* ((pack-name (match-string-no-properties 2))
13293 (pack-key (downcase pack-name))
13294 (is-body (match-string-no-properties 1))
13295 (pack-entry (aget pack-alist pack-key t))
13296 (pack-line (vhdl-current-line))
13297 (end-of-unit (vhdl-get-end-of-unit))
13298 comp-name func-name comp-alist func-alist lib-alist)
13299 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13300 (vhdl-warning-when-idle
13301 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13302 (if is-body " body" "") pack-name
13303 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13304 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13305 file-name (vhdl-current-line))
13306 ;; scan for context clauses
13307 (setq lib-alist (vhdl-scan-context-clause))
13308 ;; scan for component and subprogram declarations/bodies
13309 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13310 (if (equal (upcase (match-string 1)) "COMPONENT")
13311 (setq comp-name (match-string-no-properties 2)
13312 comp-alist
13313 (cons (list (downcase comp-name) comp-name
13314 file-name (vhdl-current-line))
13315 comp-alist))
13316 (setq func-name (match-string-no-properties 2)
13317 func-alist
13318 (cons (list (downcase func-name) func-name
13319 file-name (vhdl-current-line))
13320 func-alist))))
13321 (setq func-alist (nreverse func-alist))
13322 (setq comp-alist (nreverse comp-alist))
13323 (if is-body
13324 (setq pack-body-list (cons pack-key pack-body-list))
13325 (setq pack-list (cons pack-key pack-list)))
13326 (aput
13327 'pack-alist pack-key
13328 (if is-body
13329 (list (or (nth 0 pack-entry) pack-name)
13330 (nth 1 pack-entry) (nth 2 pack-entry)
13331 (nth 3 pack-entry) (nth 4 pack-entry)
13332 (nth 5 pack-entry)
13333 file-name pack-line func-alist lib-alist)
13334 (list pack-name file-name pack-line
13335 comp-alist func-alist lib-alist
13336 (nth 6 pack-entry) (nth 7 pack-entry)
13337 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13338 ;; scan for hierarchy
13339 (if (and limit-hier-file-size
13340 (< limit-hier-file-size (buffer-size)))
13341 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13342 (setq big-files t))
13343 ;; scan for architectures
13344 (goto-char (point-min))
13345 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13346 (let* ((ent-name (match-string-no-properties 2))
13347 (ent-key (downcase ent-name))
13348 (arch-name (match-string-no-properties 1))
13349 (arch-key (downcase arch-name))
13350 (ent-entry (aget ent-alist ent-key t))
13351 (arch-alist (nth 3 ent-entry))
13352 (arch-entry (aget arch-alist arch-key t))
13353 (beg-of-unit (point))
13354 (end-of-unit (vhdl-get-end-of-unit))
13355 (inst-no 0)
0a2e512a 13356 inst-alist inst-path)
3dcb36b7
JB
13357 ;; scan for contained instantiations
13358 (while (and (re-search-forward
13359 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13360 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13361 "component[ \t\n]+\\(\\w+\\)\\|"
0a2e512a
RF
13362 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
13363 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13364 "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
3dcb36b7
JB
13365 (or (not limit-hier-inst-no)
13366 (<= (setq inst-no (1+ inst-no))
13367 limit-hier-inst-no)))
0a2e512a
RF
13368 (cond
13369 ;; block/generate beginning found
13370 ((match-string 14)
13371 (setq inst-path
13372 (cons (match-string-no-properties 1) inst-path)))
13373 ;; block/generate end found
13374 ((match-string 16)
13375 (setq inst-path (cdr inst-path)))
13376 ;; instantiation found
13377 (t
13378 (let* ((inst-name (match-string-no-properties 1))
13379 (inst-key (downcase inst-name))
13380 (inst-comp-name
13381 (or (match-string-no-properties 3)
13382 (match-string-no-properties 6)))
13383 (inst-ent-key
13384 (or (and (match-string 8)
13385 (vhdl-match-string-downcase 11))
13386 (and inst-comp-name
13387 (downcase inst-comp-name))))
13388 (inst-arch-key (vhdl-match-string-downcase 13))
13389 (inst-conf-key
13390 (and (not (match-string 8))
13391 (vhdl-match-string-downcase 11)))
13392 (inst-lib-key (vhdl-match-string-downcase 10)))
13393 (goto-char (match-end 1))
13394 (setq inst-list (cons inst-key inst-list)
13395 inst-ent-list
13396 (cons inst-ent-key inst-ent-list))
13397 (setq inst-alist
13398 (append
13399 inst-alist
13400 (list (list inst-key inst-name file-name
13401 (vhdl-current-line) inst-comp-name
13402 inst-ent-key inst-arch-key
13403 inst-conf-key inst-lib-key
13404 (reverse inst-path)))))))))
3dcb36b7
JB
13405 ;; scan for contained configuration specifications
13406 (goto-char beg-of-unit)
13407 (while (re-search-forward
13408 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13409 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
0a2e512a 13410 (let* ((inst-comp-name (match-string-no-properties 3))
3dcb36b7
JB
13411 (inst-ent-key
13412 (and (match-string 6)
13413 (vhdl-match-string-downcase 9)))
13414 (inst-arch-key (vhdl-match-string-downcase 11))
13415 (inst-conf-key
13416 (and (not (match-string 6))
13417 (vhdl-match-string-downcase 9)))
13418 (inst-lib-key (vhdl-match-string-downcase 8))
13419 (inst-key-list
13420 (split-string (vhdl-match-string-downcase 1)
13421 "[ \t\n]*,[ \t\n]*"))
13422 (tmp-inst-alist inst-alist)
13423 inst-entry)
13424 (while tmp-inst-alist
13425 (when (and (or (equal "all" (car inst-key-list))
13426 (member (nth 0 (car tmp-inst-alist))
13427 inst-key-list))
13428 (equal
13429 (downcase
13430 (or (nth 4 (car tmp-inst-alist)) ""))
13431 (downcase inst-comp-name)))
13432 (setq inst-entry (car tmp-inst-alist))
13433 (setq inst-ent-list
13434 (cons (or inst-ent-key (nth 5 inst-entry))
13435 (vhdl-delete
13436 (nth 5 inst-entry) inst-ent-list)))
13437 (setq inst-entry
13438 (list (nth 0 inst-entry) (nth 1 inst-entry)
13439 (nth 2 inst-entry) (nth 3 inst-entry)
13440 (nth 4 inst-entry)
13441 (or inst-ent-key (nth 5 inst-entry))
13442 (or inst-arch-key (nth 6 inst-entry))
13443 inst-conf-key inst-lib-key))
13444 (setcar tmp-inst-alist inst-entry))
13445 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13446 ;; save in cache
13447 (aput 'arch-alist arch-key
13448 (list (nth 0 arch-entry) (nth 1 arch-entry)
13449 (nth 2 arch-entry) inst-alist
13450 (nth 4 arch-entry)))
13451 (aput 'ent-alist ent-key
13452 (list (nth 0 ent-entry) (nth 1 ent-entry)
13453 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
0a2e512a 13454 (nth 4 ent-entry) (nth 5 ent-entry)))
3dcb36b7
JB
13455 (when (and limit-hier-inst-no
13456 (> inst-no limit-hier-inst-no))
13457 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13458 (setq big-files t))
13459 (goto-char end-of-unit))))
13460 ;; remember design units for this file
13461 (aput 'file-alist file-name
13462 (list ent-list arch-list arch-ent-list conf-list
13463 pack-list pack-body-list inst-list inst-ent-list))
13464 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13465 (setq file-list (cdr file-list))))
13466 (when (or (and (not project) files-exist)
13467 (and project (not non-final)))
13468 ;; consistency checks:
13469 ;; check whether each architecture has a corresponding entity
13470 (setq tmp-list ent-alist)
13471 (while tmp-list
13472 (when (null (nth 2 (car tmp-list)))
13473 (setq tmp-entry (car (nth 4 (car tmp-list))))
13474 (vhdl-warning-when-idle
13475 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13476 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13477 (nth 3 tmp-entry)))
13478 (setq tmp-list (cdr tmp-list)))
13479 ;; check whether configuration has a corresponding entity/architecture
13480 (setq tmp-list conf-alist)
13481 (while tmp-list
13482 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13483 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13484 (setq tmp-entry (car tmp-list))
13485 (vhdl-warning-when-idle
13486 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13487 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13488 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13489 (setq tmp-entry (car tmp-list))
13490 (vhdl-warning-when-idle
13491 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13492 (nth 1 tmp-entry) (nth 4 tmp-entry)
13493 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13494 (setq tmp-list (cdr tmp-list)))
13495 ;; check whether each package body has a package declaration
13496 (setq tmp-list pack-alist)
13497 (while tmp-list
13498 (when (null (nth 2 (car tmp-list)))
13499 (setq tmp-entry (car tmp-list))
13500 (vhdl-warning-when-idle
13501 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13502 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13503 (setq tmp-list (cdr tmp-list)))
13504 ;; sort lists
13505 (setq ent-alist (vhdl-sort-alist ent-alist))
13506 (setq conf-alist (vhdl-sort-alist conf-alist))
13507 (setq pack-alist (vhdl-sort-alist pack-alist))
13508 ;; remember updated directory/project
13509 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13510 ;; clear directory alists
13511 (unless project
13512 (adelete 'vhdl-entity-alist key)
13513 (adelete 'vhdl-config-alist key)
13514 (adelete 'vhdl-package-alist key)
13515 (adelete 'vhdl-ent-inst-alist key)
13516 (adelete 'vhdl-file-alist key))
13517 ;; put directory contents into cache
13518 (aput 'vhdl-entity-alist key ent-alist)
13519 (aput 'vhdl-config-alist key conf-alist)
13520 (aput 'vhdl-package-alist key pack-alist)
13521 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13522 (aput 'vhdl-file-alist key file-alist)
13523 ;; final messages
13524 (message "Scanning %s %s\"%s\"...done"
13525 (if is-directory "directory" "files") (or num-string "") name)
13526 (unless project (message "Scanning directory...done"))
13527 (when big-files
13528 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13529 ;; save cache when scanned non-interactively
13530 (when (or (not project) (not non-final))
13531 (when (and noninteractive vhdl-speedbar-save-cache)
13532 (vhdl-save-cache key)))
13533 t))
5eabfe72 13534
3dcb36b7 13535(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13536 "Scan the contents of all VHDL files found in the directories and files
13537of PROJECT."
3dcb36b7
JB
13538 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13539 (default-dir (vhdl-resolve-env-variable
13540 (nth 1 (aget vhdl-project-alist project))))
13541 (file-exclude-regexp
13542 (or (nth 3 (aget vhdl-project-alist project)) ""))
13543 dir-list-tmp dir dir-name num-dir act-dir recursive)
13544 ;; clear project alists
13545 (adelete 'vhdl-entity-alist project)
13546 (adelete 'vhdl-config-alist project)
13547 (adelete 'vhdl-package-alist project)
13548 (adelete 'vhdl-ent-inst-alist project)
13549 (adelete 'vhdl-file-alist project)
13550 ;; expand directory names by default-directory
13551 (message "Collecting source files...")
13552 (while dir-list
13553 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13554 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13555 (setq recursive (match-string 1 dir)
13556 dir-name (match-string 3 dir))
13557 (setq dir-list-tmp
13558 (cons (concat recursive
13559 (if (file-name-absolute-p dir-name) "" default-dir)
13560 dir-name)
13561 dir-list-tmp))
13562 (setq dir-list (cdr dir-list)))
13563 ;; resolve path wildcards
5eabfe72
KH
13564 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13565 ;; expand directories
13566 (while dir-list-tmp
13567 (setq dir (car dir-list-tmp))
13568 ;; get subdirectories
3dcb36b7 13569 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13570 (setq dir-list (append dir-list (vhdl-get-subdirs
13571 (match-string 1 dir))))
13572 (setq dir-list (append dir-list (list dir))))
13573 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13574 ;; exclude files
13575 (unless (equal file-exclude-regexp "")
13576 (let ((case-fold-search nil))
13577 (while dir-list
13578 (unless (string-match file-exclude-regexp (car dir-list))
13579 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13580 (setq dir-list (cdr dir-list)))
13581 (setq dir-list (nreverse dir-list-tmp))))
13582 (message "Collecting source files...done")
13583 ;; scan for design units for each directory in DIR-LIST
13584 (setq dir-list-tmp nil
13585 num-dir (length dir-list)
5eabfe72
KH
13586 act-dir 1)
13587 (while dir-list
3dcb36b7
JB
13588 (setq dir-name (abbreviate-file-name
13589 (expand-file-name (car dir-list))))
13590 (vhdl-scan-directory-contents dir-name project nil
13591 (format "(%s/%s) " act-dir num-dir)
13592 (cdr dir-list))
13593 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13594 (setq dir-list (cdr dir-list)
13595 act-dir (1+ act-dir)))
3dcb36b7
JB
13596 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13597 (message "Scanning project \"%s\"...done" project)))
13598
13599(defun vhdl-update-file-contents (file-name)
13600 "Update hierarchy information by contents of current buffer."
13601 (setq file-name (abbreviate-file-name file-name))
13602 (let* ((dir-name (file-name-directory file-name))
13603 (directory-alist vhdl-directory-alist)
13604 updated)
13605 (while directory-alist
13606 (when (member dir-name (nth 1 (car directory-alist)))
13607 (let* ((vhdl-project (nth 0 (car directory-alist)))
13608 (project (vhdl-project-p))
13609 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13610 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13611 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13612 (ent-inst-list (car (aget vhdl-ent-inst-alist
13613 (or project dir-name) t)))
13614 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13615 (file-entry (aget file-alist file-name t))
13616 (ent-list (nth 0 file-entry))
13617 (arch-list (nth 1 file-entry))
13618 (arch-ent-list (nth 2 file-entry))
13619 (conf-list (nth 3 file-entry))
13620 (pack-list (nth 4 file-entry))
13621 (pack-body-list (nth 5 file-entry))
13622 (inst-ent-list (nth 7 file-entry))
13623 (cache-key (or project dir-name))
13624 arch-alist key ent-key entry)
13625 ;; delete design units previously contained in this file:
13626 ;; entities
13627 (while ent-list
13628 (setq key (car ent-list)
13629 entry (aget ent-alist key t))
13630 (when (equal file-name (nth 1 entry))
13631 (if (nth 3 entry)
13632 (aput 'ent-alist key
13633 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13634 (adelete 'ent-alist key)))
13635 (setq ent-list (cdr ent-list)))
13636 ;; architectures
13637 (while arch-list
13638 (setq key (car arch-list)
13639 ent-key (car arch-ent-list)
13640 entry (aget ent-alist ent-key t)
13641 arch-alist (nth 3 entry))
13642 (when (equal file-name (nth 1 (aget arch-alist key t)))
13643 (adelete 'arch-alist key)
13644 (if (or (nth 1 entry) arch-alist)
13645 (aput 'ent-alist ent-key
13646 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
0a2e512a 13647 arch-alist (nth 4 entry) (nth 5 entry)))
3dcb36b7
JB
13648 (adelete 'ent-alist ent-key)))
13649 (setq arch-list (cdr arch-list)
13650 arch-ent-list (cdr arch-ent-list)))
13651 ;; configurations
13652 (while conf-list
13653 (setq key (car conf-list))
13654 (when (equal file-name (nth 1 (aget conf-alist key t)))
13655 (adelete 'conf-alist key))
13656 (setq conf-list (cdr conf-list)))
13657 ;; package declarations
13658 (while pack-list
13659 (setq key (car pack-list)
13660 entry (aget pack-alist key t))
13661 (when (equal file-name (nth 1 entry))
13662 (if (nth 6 entry)
13663 (aput 'pack-alist key
13664 (list (nth 0 entry) nil nil nil nil nil
13665 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13666 (nth 9 entry)))
13667 (adelete 'pack-alist key)))
13668 (setq pack-list (cdr pack-list)))
13669 ;; package bodies
13670 (while pack-body-list
13671 (setq key (car pack-body-list)
13672 entry (aget pack-alist key t))
13673 (when (equal file-name (nth 6 entry))
13674 (if (nth 1 entry)
13675 (aput 'pack-alist key
13676 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13677 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13678 nil nil nil nil))
13679 (adelete 'pack-alist key)))
13680 (setq pack-body-list (cdr pack-body-list)))
13681 ;; instantiated entities
13682 (while inst-ent-list
13683 (setq ent-inst-list
13684 (vhdl-delete (car inst-ent-list) ent-inst-list))
13685 (setq inst-ent-list (cdr inst-ent-list)))
13686 ;; update caches
13687 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13688 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13689 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13690 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13691 ;; scan file
13692 (vhdl-scan-directory-contents file-name project t)
13693 (when (or (and vhdl-speedbar-show-projects project)
13694 (and (not vhdl-speedbar-show-projects) (not project)))
13695 (vhdl-speedbar-refresh project))
13696 (setq updated t)))
13697 (setq directory-alist (cdr directory-alist)))
13698 updated))
13699
13700(defun vhdl-update-hierarchy ()
13701 "Update directory and hierarchy information in speedbar."
13702 (let ((file-list (reverse vhdl-modified-file-list))
13703 updated)
13704 (when (and vhdl-speedbar-update-on-saving file-list)
13705 (while file-list
13706 (setq updated
13707 (or (vhdl-update-file-contents (car file-list))
13708 updated))
13709 (setq file-list (cdr file-list)))
13710 (setq vhdl-modified-file-list nil)
0a2e512a 13711 (vhdl-speedbar-update-current-unit)
3dcb36b7
JB
13712 (when updated (message "Updating hierarchy...done")))))
13713
13714;; structure (parenthesised expression means list of such entries)
13715;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13716;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13717;; comp-lib-name level)
13718(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13719 conf-inst-alist level indent
13720 &optional include-top ent-hier)
13721 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13722entity ENT-KEY."
13723 (let* ((ent-entry (aget ent-alist ent-key t))
13724 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13725 (cdar (last (nth 3 ent-entry)))))
13726 (inst-alist (nth 3 arch-entry))
13727 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13728 hier-list subcomp-list tmp-list inst-key inst-comp-name
13729 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13730 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13731 (when include-top
13732 (setq level (1+ level)))
13733 (when (member ent-key ent-hier)
13734 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13735 ;; check configured architecture (already checked during scanning)
13736; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13737; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13738 ;; process all instances
13739 (while inst-alist
13740 (setq inst-entry (car inst-alist)
13741 inst-key (nth 0 inst-entry)
13742 inst-comp-name (nth 4 inst-entry)
13743 inst-conf-key (nth 7 inst-entry))
13744 ;; search entry in configuration's instantiations list
13745 (setq tmp-list conf-inst-alist)
13746 (while (and tmp-list
13747 (not (and (member (nth 0 (car tmp-list))
13748 (list "all" inst-key))
13749 (equal (nth 1 (car tmp-list))
13750 (downcase (or inst-comp-name ""))))))
13751 (setq tmp-list (cdr tmp-list)))
13752 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13753 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13754 (when (and inst-conf-key (not inst-conf-entry))
13755 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13756 ;; determine entity
13757 (setq inst-ent-key
13758 (or (nth 2 (car tmp-list)) ; from configuration
13759 (nth 3 inst-conf-entry) ; from subconfiguration
13760 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13761 ; from configuration spec.
13762 (nth 5 inst-entry))) ; from direct instantiation
13763 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13764 ;; determine architecture
13765 (setq inst-arch-key
0a2e512a
RF
13766 (or (nth 3 (car tmp-list)) ; from configuration
13767 (nth 4 inst-conf-entry) ; from subconfiguration
13768 (nth 6 inst-entry) ; from direct instantiation
3dcb36b7 13769 (nth 4 (aget conf-alist (nth 7 inst-entry)))
0a2e512a
RF
13770 ; from configuration spec.
13771 (nth 4 inst-ent-entry) ; MRA
13772 (caar (nth 3 inst-ent-entry)))) ; first alphabetically
3dcb36b7
JB
13773 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13774 ;; set library
13775 (setq inst-lib-key
0a2e512a
RF
13776 (or (nth 5 (car tmp-list)) ; from configuration
13777 (nth 8 inst-entry))) ; from direct instantiation
3dcb36b7
JB
13778 ;; gather information for this instance
13779 (setq comp-entry
13780 (list (nth 1 inst-entry)
13781 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13782 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13783 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13784 (or (nth 0 inst-arch-entry) inst-arch-key)
13785 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13786 (or (nth 0 inst-conf-entry) inst-conf-key)
13787 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13788 inst-lib-key level))
13789 ;; get subcomponent hierarchy
13790 (setq subcomp-list (vhdl-get-hierarchy
13791 ent-alist conf-alist
13792 inst-ent-key inst-arch-key inst-conf-key
13793 (nth 5 inst-conf-entry)
13794 (1+ level) indent nil (cons ent-key ent-hier)))
13795 ;; add to list
13796 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13797 (setq inst-alist (cdr inst-alist)))
13798 (when include-top
5eabfe72 13799 (setq hier-list
3dcb36b7
JB
13800 (cons (list nil nil (nth 0 ent-entry)
13801 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13802 (nth 0 arch-entry)
13803 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13804 nil nil
13805 nil (1- level))
13806 hier-list)))
13807 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13808 hier-list))
13809
3dcb36b7
JB
13810(defun vhdl-get-instantiations (ent-key indent)
13811 "Get all instantiations of entity ENT-KEY."
13812 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13813 arch-alist inst-alist ent-inst-list
13814 ent-entry arch-entry inst-entry)
13815 (while ent-alist
13816 (setq ent-entry (car ent-alist))
3dcb36b7 13817 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13818 (while arch-alist
13819 (setq arch-entry (car arch-alist))
3dcb36b7 13820 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13821 (while inst-alist
13822 (setq inst-entry (car inst-alist))
3dcb36b7 13823 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13824 (setq ent-inst-list
3dcb36b7
JB
13825 (cons (list (nth 1 inst-entry)
13826 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13827 (nth 1 ent-entry)
13828 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13829 (nth 1 arch-entry)
13830 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13831 ent-inst-list)))
5eabfe72
KH
13832 (setq inst-alist (cdr inst-alist)))
13833 (setq arch-alist (cdr arch-alist)))
13834 (setq ent-alist (cdr ent-alist)))
13835 (nreverse ent-inst-list)))
13836
13837;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13838;; Caching in file
13839
13840(defun vhdl-save-caches ()
13841 "Save all updated hierarchy caches to file."
13842 (interactive)
13843 (condition-case nil
13844 (when vhdl-speedbar-save-cache
13845 ;; update hierarchy
13846 (vhdl-update-hierarchy)
13847 (let ((project-list vhdl-updated-project-list))
13848 (message "Saving hierarchy caches...")
13849 ;; write updated project caches
13850 (while project-list
13851 (vhdl-save-cache (car project-list))
13852 (setq project-list (cdr project-list)))
13853 (message "Saving hierarchy caches...done")))
13854 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13855 (sit-for 2)))))
13856
13857(defun vhdl-save-cache (key)
13858 "Save current hierarchy cache to file."
13859 (let* ((orig-buffer (current-buffer))
13860 (vhdl-project key)
13861 (project (vhdl-project-p))
13862 (default-directory key)
13863 (directory (abbreviate-file-name (vhdl-default-directory)))
13864 (file-name (vhdl-resolve-env-variable
13865 (vhdl-replace-string
13866 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13867 (concat
13868 (subst-char-in-string ? ?_ (or project "dir"))
13869 " " (user-login-name)))))
13870 (file-dir-name (expand-file-name file-name directory))
13871 (cache-key (or project directory))
13872 (key (if project "project" "directory")))
13873 (unless (file-exists-p (file-name-directory file-dir-name))
13874 (make-directory (file-name-directory file-dir-name) t))
13875 (if (not (file-writable-p file-dir-name))
13876 (progn (vhdl-warning (format "File not writable: \"%s\""
13877 (abbreviate-file-name file-dir-name)))
13878 (sit-for 2))
13879 (message "Saving cache: \"%s\"" file-dir-name)
13880 (set-buffer (find-file-noselect file-dir-name t t))
13881 (erase-buffer)
13882 (insert ";; -*- Emacs-Lisp -*-\n\n"
13883 ";;; " (file-name-nondirectory file-name)
13884 " - design hierarchy cache file for Emacs VHDL Mode "
13885 vhdl-version "\n")
13886 (insert "\n;; " (if project "Project " "Directory") " : ")
13887 (if project (insert project) (prin1 directory (current-buffer)))
13888 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13889 (user-login-name) "\n\n"
13890 "\n;; version number\n"
13891 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13892 "\n;; " (if project "project" "directory") " name"
13893 "\n(setq " key " ")
13894 (prin1 (or project directory) (current-buffer))
13895 (insert ")\n")
13896 (when (member 'hierarchy vhdl-speedbar-save-cache)
13897 (insert "\n;; entity and architecture cache\n"
13898 "(aput 'vhdl-entity-alist " key " '")
13899 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13900 (insert ")\n\n;; configuration cache\n"
13901 "(aput 'vhdl-config-alist " key " '")
13902 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13903 (insert ")\n\n;; package cache\n"
13904 "(aput 'vhdl-package-alist " key " '")
13905 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13906 (insert ")\n\n;; instantiated entities cache\n"
13907 "(aput 'vhdl-ent-inst-alist " key " '")
13908 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13909 (insert ")\n\n;; design units per file cache\n"
13910 "(aput 'vhdl-file-alist " key " '")
13911 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13912 (when project
13913 (insert ")\n\n;; source directories in project cache\n"
13914 "(aput 'vhdl-directory-alist " key " '")
13915 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13916 (insert ")\n"))
13917 (when (member 'display vhdl-speedbar-save-cache)
13918 (insert "\n;; shown design units cache\n"
13919 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13920 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13921 (current-buffer))
13922 (insert ")\n"))
13923 (setq vhdl-updated-project-list
13924 (delete cache-key vhdl-updated-project-list))
13925 (save-buffer)
13926 (kill-buffer (current-buffer))
13927 (set-buffer orig-buffer))))
13928
13929(defun vhdl-load-cache (key)
13930 "Load hierarchy cache information from file."
13931 (let* ((vhdl-project key)
13932 (default-directory key)
13933 (directory (vhdl-default-directory))
13934 (file-name (vhdl-resolve-env-variable
13935 (vhdl-replace-string
13936 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13937 (concat
13938 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13939 " " (user-login-name)))))
13940 (file-dir-name (expand-file-name file-name directory))
13941 vhdl-cache-version)
13942 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13943 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13944 (when (file-exists-p file-dir-name)
13945 (condition-case ()
13946 (progn (load-file file-dir-name)
13947 (string< (mapconcat
027a4b6b 13948 (lambda (a) (format "%3d" (string-to-number a)))
0a2e512a 13949 (split-string "3.33" "\\.") "")
3dcb36b7 13950 (mapconcat
027a4b6b 13951 (lambda (a) (format "%3d" (string-to-number a)))
3dcb36b7
JB
13952 (split-string vhdl-cache-version "\\.") "")))
13953 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13954 nil))))))
13955
13956(defun vhdl-require-hierarchy-info ()
13957 "Make sure that hierarchy information is available. Load cache or scan files
13958if required."
13959 (if (vhdl-project-p)
13960 (unless (or (assoc vhdl-project vhdl-file-alist)
13961 (vhdl-load-cache vhdl-project))
13962 (vhdl-scan-project-contents vhdl-project))
13963 (let ((directory (abbreviate-file-name default-directory)))
13964 (unless (or (assoc directory vhdl-file-alist)
13965 (vhdl-load-cache directory))
13966 (vhdl-scan-directory-contents directory)))))
13967
13968;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13969;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13970
13971(defvar vhdl-speedbar-key-map nil
13972 "Keymap used when in the VHDL hierarchy browser mode.")
13973
3dcb36b7 13974(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13975 "Additional menu-items to add to speedbar frame.")
13976
13977(defun vhdl-speedbar-initialize ()
13978 "Initialize speedbar."
13979 ;; general settings
13980; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13981 ;; VHDL file extensions (extracted from `auto-mode-alist')
13982 (let ((mode-alist auto-mode-alist))
13983 (while mode-alist
3dcb36b7
JB
13984 (when (eq (cdar mode-alist) 'vhdl-mode)
13985 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13986 (setq mode-alist (cdr mode-alist))))
13987 ;; hierarchy browser settings
13988 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13989 ;; special functions
5eabfe72 13990 (speedbar-add-mode-functions-list
3dcb36b7 13991 '("vhdl directory"
5eabfe72 13992 (speedbar-item-info . vhdl-speedbar-item-info)
7752250e 13993 (speedbar-line-directory . speedbar-files-line-path)))
3dcb36b7
JB
13994 (speedbar-add-mode-functions-list
13995 '("vhdl project"
13996 (speedbar-item-info . vhdl-speedbar-item-info)
7752250e 13997 (speedbar-line-directory . vhdl-speedbar-line-project)))
3dcb36b7 13998 ;; keymap
5eabfe72
KH
13999 (unless vhdl-speedbar-key-map
14000 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
14001 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
14002 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
14003 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
14004 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
14005 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
14006 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
14007 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
14008 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
0a2e512a
RF
14009 (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
14010 (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
3dcb36b7
JB
14011 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
14012 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
14013 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
14014 (let ((key 0))
14015 (while (<= key 9)
14016 (define-key vhdl-speedbar-key-map (int-to-string key)
14017 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
14018 (setq key (1+ key)))))
5eabfe72
KH
14019 (define-key speedbar-key-map "h"
14020 (lambda () (interactive)
3dcb36b7
JB
14021 (speedbar-change-initial-expansion-list "vhdl directory")))
14022 (define-key speedbar-key-map "H"
14023 (lambda () (interactive)
14024 (speedbar-change-initial-expansion-list "vhdl project")))
14025 ;; menu
14026 (unless vhdl-speedbar-menu-items
14027 (setq
14028 vhdl-speedbar-menu-items
14029 `(["Edit" speedbar-edit-line t]
14030 ["Expand" speedbar-expand-line
14031 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14032 ["Contract" vhdl-speedbar-contract-level t]
14033 ["Expand All" vhdl-speedbar-expand-all t]
14034 ["Contract All" vhdl-speedbar-contract-all t]
14035 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14036 (while (<= key 9)
14037 (setq menu-list
14038 (cons `[,(if (= key 0) "All" (int-to-string key))
14039 (vhdl-speedbar-set-depth ,key)
14040 :style radio
14041 :selected (= vhdl-speedbar-hierarchy-depth ,key)
14042 :keys ,(int-to-string key)]
14043 menu-list))
14044 (setq key (1+ key)))
14045 (nreverse menu-list))
14046 "--"
14047 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14048 (or (vhdl-speedbar-check-unit 'entity)
14049 (vhdl-speedbar-check-unit 'subprogram))]
14050 ["Place Component" vhdl-speedbar-place-component
14051 (vhdl-speedbar-check-unit 'entity)]
0a2e512a
RF
14052 ["Generate Configuration" vhdl-speedbar-configuration
14053 (vhdl-speedbar-check-unit 'architecture)]
14054 ["Select as MRA" vhdl-speedbar-select-mra
14055 (vhdl-speedbar-check-unit 'architecture)]
3dcb36b7
JB
14056 ["Make" vhdl-speedbar-make-design
14057 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14058 ["Generate Makefile" vhdl-speedbar-generate-makefile
14059 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14060 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14061 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14062 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
14063 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14064 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14065 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
14066 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
14067 ;; hook-ups
14068 (speedbar-add-expansion-list
14069 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14070 vhdl-speedbar-display-directory))
14071 (speedbar-add-expansion-list
14072 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
14073 vhdl-speedbar-display-projects))
5eabfe72 14074 (setq speedbar-stealthy-function-list
3dcb36b7
JB
14075 (append
14076 '(("vhdl directory" vhdl-speedbar-update-current-unit)
14077 ("vhdl project" vhdl-speedbar-update-current-project
14078 vhdl-speedbar-update-current-unit)
14079; ("files" (lambda () (setq speedbar-ignored-path-regexp
14080; (speedbar-extension-list-to-regex
14081; speedbar-ignored-path-expressions))))
14082 )
14083 speedbar-stealthy-function-list))
14084 (when (eq vhdl-speedbar-display-mode 'directory)
14085 (setq speedbar-initial-expansion-list-name "vhdl directory"))
14086 (when (eq vhdl-speedbar-display-mode 'project)
14087 (setq speedbar-initial-expansion-list-name "vhdl project"))
14088 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
14089
14090(defun vhdl-speedbar (&optional arg)
14091 "Open/close speedbar."
d2ddb974 14092 (interactive)
5eabfe72 14093 (if (not (fboundp 'speedbar))
3dcb36b7
JB
14094 (error "WARNING: Speedbar is not available or not installed")
14095 (condition-case ()
5eabfe72 14096 (speedbar-frame-mode arg)
3dcb36b7 14097 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
14098
14099;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14100;; Display functions
14101
3dcb36b7
JB
14102(defvar vhdl-speedbar-last-selected-project nil
14103 "Name of last selected project.")
14104
5eabfe72
KH
14105;; macros must be defined in the file they are used (copied from `speedbar.el')
14106(defmacro speedbar-with-writable (&rest forms)
14107 "Allow the buffer to be writable and evaluate FORMS."
14108 (list 'let '((inhibit-read-only t))
14109 (cons 'progn forms)))
14110(put 'speedbar-with-writable 'lisp-indent-function 0)
14111
3dcb36b7 14112(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 14113 "Display directory and hierarchy information in speedbar."
3dcb36b7
JB
14114 (setq vhdl-speedbar-show-projects nil)
14115 (setq speedbar-ignored-path-regexp
14116 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
5eabfe72
KH
14117 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
14118 (setq speedbar-last-selected-file nil)
14119 (speedbar-with-writable
3dcb36b7
JB
14120 (condition-case nil
14121 (progn
14122 ;; insert directory path
14123 (speedbar-directory-buttons directory depth)
14124 ;; insert subdirectories
14125 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
14126 ;; scan and insert hierarchy of current directory
14127 (vhdl-speedbar-insert-dir-hierarchy directory depth
14128 speedbar-power-click)
14129 ;; expand subdirectories
14130 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
14131 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14132
14133(defun vhdl-speedbar-display-projects (project depth &optional rescan)
14134 "Display projects and hierarchy information in speedbar."
14135 (setq vhdl-speedbar-show-projects t)
14136 (setq speedbar-ignored-path-regexp ".")
14137 (setq speedbar-last-selected-file nil)
14138 (setq vhdl-speedbar-last-selected-project nil)
14139 (speedbar-with-writable
14140 (condition-case nil
14141 ;; insert projects
14142 (vhdl-speedbar-insert-projects)
14143 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14144 (setq speedbar-full-text-cache nil)) ; prevent caching
14145
14146(defun vhdl-speedbar-insert-projects ()
14147 "Insert all projects in speedbar."
14148 (vhdl-speedbar-make-title-line "Projects:")
14149 (let ((project-alist (if vhdl-project-sort
14150 (vhdl-sort-alist (copy-alist vhdl-project-alist))
14151 vhdl-project-alist))
14152 (vhdl-speedbar-update-current-unit nil))
14153 ;; insert projects
14154 (while project-alist
14155 (speedbar-make-tag-line
14156 'angle ?+ 'vhdl-speedbar-expand-project
14157 (caar project-alist) (caar project-alist)
14158 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
14159 (setq project-alist (cdr project-alist)))
14160 (setq project-alist vhdl-project-alist)
14161 ;; expand projects
14162 (while project-alist
14163 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
14164 (goto-char (point-min))
14165 (when (re-search-forward
14166 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
14167 (goto-char (match-end 1))
14168 (speedbar-do-function-pointer)))
14169 (setq project-alist (cdr project-alist))))
14170; (vhdl-speedbar-update-current-project)
14171; (vhdl-speedbar-update-current-unit nil t)
14172 )
14173
14174(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
14175 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
14176otherwise use cached data."
14177 (when (or rescan (and (not (assoc project vhdl-file-alist))
14178 (not (vhdl-load-cache project))))
14179 (vhdl-scan-project-contents project))
14180 ;; insert design hierarchy
14181 (vhdl-speedbar-insert-hierarchy
14182 (aget vhdl-entity-alist project t)
14183 (aget vhdl-config-alist project t)
14184 (aget vhdl-package-alist project t)
14185 (car (aget vhdl-ent-inst-alist project t)) indent)
14186 (insert (int-to-string indent) ":\n")
14187 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
14188 (put-text-property (1- (point)) (point) 'invisible nil)
14189 ;; expand design units
14190 (vhdl-speedbar-expand-units project))
14191
14192(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
14193 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14194otherwise use cached data."
14195 (when (or rescan (and (not (assoc directory vhdl-file-alist))
14196 (not (vhdl-load-cache directory))))
14197 (vhdl-scan-directory-contents directory))
14198 ;; insert design hierarchy
14199 (vhdl-speedbar-insert-hierarchy
14200 (aget vhdl-entity-alist directory t)
14201 (aget vhdl-config-alist directory t)
14202 (aget vhdl-package-alist directory t)
14203 (car (aget vhdl-ent-inst-alist directory t)) depth)
14204 ;; expand design units
14205 (vhdl-speedbar-expand-units directory)
14206 (aput 'vhdl-directory-alist directory (list (list directory))))
14207
14208(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 14209 ent-inst-list depth)
3dcb36b7
JB
14210 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14211 (if (not (or ent-alist conf-alist pack-alist))
14212 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
14213 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
14214 ;; insert entities
14215 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
14216 (while ent-alist
14217 (setq ent-entry (car ent-alist))
14218 (speedbar-make-tag-line
14219 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
14220 (nth 1 ent-entry) 'vhdl-speedbar-find-file
14221 (cons (nth 2 ent-entry) (nth 3 ent-entry))
0a2e512a 14222 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
14223 (unless (nth 2 ent-entry)
14224 (end-of-line 0) (insert "!") (forward-char 1))
14225 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
14226 (end-of-line 0) (insert " (top)") (forward-char 1))
14227 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
14228 ;; insert configurations
14229 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
14230 (while conf-alist
14231 (setq conf-entry (car conf-alist))
14232 (speedbar-make-tag-line
14233 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
14234 (nth 1 conf-entry) 'vhdl-speedbar-find-file
14235 (cons (nth 2 conf-entry) (nth 3 conf-entry))
0a2e512a 14236 'vhdl-speedbar-configuration-face depth)
3dcb36b7 14237 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
14238 ;; insert packages
14239 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
14240 (while pack-alist
14241 (setq pack-entry (car pack-alist))
14242 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
14243 (nth 0 pack-entry) (nth 1 pack-entry)
14244 (cons (nth 2 pack-entry) (nth 3 pack-entry))
14245 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
14246 depth)
14247 (setq pack-alist (cdr pack-alist))))))
14248
5eabfe72 14249(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 14250 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 14251 (interactive)
3dcb36b7
JB
14252 (let (key path)
14253 (cond
14254 ;; current project
14255 (vhdl-speedbar-show-projects
14256 (setq key (vhdl-speedbar-line-project))
14257 (vhdl-scan-project-contents key))
14258 ;; top-level directory
14259 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14260 (re-search-forward "[0-9]+:" nil t)
14261 (vhdl-scan-directory-contents
7752250e 14262 (abbreviate-file-name (speedbar-line-directory))))
3dcb36b7 14263 ;; current directory
7752250e 14264 (t (setq path (speedbar-line-directory))
3dcb36b7
JB
14265 (string-match "^\\(.+[/\\]\\)" path)
14266 (vhdl-scan-directory-contents
14267 (abbreviate-file-name (match-string 1 path)))))
14268 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14269
14270(defun vhdl-speedbar-expand-dirs (directory)
14271 "Expand subdirectories in DIRECTORY according to
14272 `speedbar-shown-directories'."
14273 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14274 (let ((sf (cdr (reverse speedbar-shown-directories)))
14275 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14276 (setq speedbar-shown-directories
14277 (list (expand-file-name default-directory)))
14278 (while sf
14279 (when (speedbar-goto-this-file (car sf))
14280 (beginning-of-line)
14281 (when (looking-at "[0-9]+:\\s-*<")
14282 (goto-char (match-end 0))
3dcb36b7
JB
14283 (speedbar-do-function-pointer)))
14284 (setq sf (cdr sf))))
14285 (vhdl-speedbar-update-current-unit nil t))
14286
14287(defun vhdl-speedbar-expand-units (key)
14288 "Expand design units in directory/project KEY according to
14289`vhdl-speedbar-shown-unit-alist'."
14290 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14291 (vhdl-speedbar-update-current-unit nil)
14292 vhdl-updated-project-list)
14293 (adelete 'vhdl-speedbar-shown-unit-alist key)
14294 (vhdl-prepare-search-1
14295 (while unit-alist ; expand units
14296 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14297 (beginning-of-line)
14298 (let ((arch-alist (nth 1 (car unit-alist)))
14299 position)
14300 (when (looking-at "^[0-9]+:\\s-*\\[")
14301 (goto-char (match-end 0))
14302 (setq position (point))
14303 (speedbar-do-function-pointer)
14304 (select-frame speedbar-frame)
14305 (while arch-alist ; expand architectures
14306 (goto-char position)
14307 (when (re-search-forward
14308 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14309 (car arch-alist) "\\>\\)") nil t)
14310 (beginning-of-line)
14311 (when (looking-at "^[0-9]+:\\s-*{")
14312 (goto-char (match-end 0))
14313 (speedbar-do-function-pointer)
14314 (select-frame speedbar-frame)))
14315 (setq arch-alist (cdr arch-alist))))
14316 (setq unit-alist (cdr unit-alist))))))
14317 (vhdl-speedbar-update-current-unit nil t))
14318
14319(defun vhdl-speedbar-contract-level ()
14320 "Contract current level in current directory/project."
14321 (interactive)
14322 (when (or (save-excursion
14323 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14324 (and (save-excursion
14325 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14326 (re-search-backward
14327 (format "^[0-%d]:\\s-*[[{<]-"
027a4b6b 14328 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
3dcb36b7
JB
14329 (goto-char (match-end 0))
14330 (speedbar-do-function-pointer)
14331 (speedbar-center-buffer-smartly)))
14332
14333(defun vhdl-speedbar-contract-all ()
14334 "Contract all expanded design units in current directory/project."
14335 (interactive)
14336 (if (and vhdl-speedbar-show-projects
14337 (save-excursion (beginning-of-line) (looking-at "^0:")))
14338 (progn (setq vhdl-speedbar-shown-project-list nil)
14339 (vhdl-speedbar-refresh))
14340 (let ((key (vhdl-speedbar-line-key)))
14341 (adelete 'vhdl-speedbar-shown-unit-alist key)
14342 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14343 (when (memq 'display vhdl-speedbar-save-cache)
14344 (add-to-list 'vhdl-updated-project-list key)))))
14345
14346(defun vhdl-speedbar-expand-all ()
14347 "Expand all design units in current directory/project."
14348 (interactive)
14349 (let* ((key (vhdl-speedbar-line-key))
14350 (ent-alist (aget vhdl-entity-alist key t))
14351 (conf-alist (aget vhdl-config-alist key t))
14352 (pack-alist (aget vhdl-package-alist key t))
14353 arch-alist unit-alist subunit-alist)
14354 (add-to-list 'vhdl-speedbar-shown-project-list key)
14355 (while ent-alist
14356 (setq arch-alist (nth 4 (car ent-alist)))
14357 (setq subunit-alist nil)
14358 (while arch-alist
14359 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14360 (setq arch-alist (cdr arch-alist)))
14361 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14362 (setq ent-alist (cdr ent-alist)))
14363 (while conf-alist
14364 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14365 (setq conf-alist (cdr conf-alist)))
14366 (while pack-alist
14367 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14368 (setq pack-alist (cdr pack-alist)))
14369 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14370 (vhdl-speedbar-refresh)
14371 (when (memq 'display vhdl-speedbar-save-cache)
14372 (add-to-list 'vhdl-updated-project-list key))))
14373
14374(defun vhdl-speedbar-expand-project (text token indent)
14375 "Expand/contract the project under the cursor."
14376 (cond
14377 ((string-match "+" text) ; expand project
14378 (speedbar-change-expand-button-char ?-)
14379 (unless (member token vhdl-speedbar-shown-project-list)
14380 (setq vhdl-speedbar-shown-project-list
14381 (cons token vhdl-speedbar-shown-project-list)))
14382 (speedbar-with-writable
14383 (save-excursion
14384 (end-of-line) (forward-char 1)
14385 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14386 speedbar-power-click))))
14387 ((string-match "-" text) ; contract project
14388 (speedbar-change-expand-button-char ?+)
14389 (setq vhdl-speedbar-shown-project-list
14390 (delete token vhdl-speedbar-shown-project-list))
14391 (speedbar-delete-subblock indent))
14392 (t (error "Nothing to display")))
14393 (when (equal (selected-frame) speedbar-frame)
14394 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14395
14396(defun vhdl-speedbar-expand-entity (text token indent)
14397 "Expand/contract the entity under the cursor."
14398 (cond
14399 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14400 (let* ((key (vhdl-speedbar-line-key indent))
14401 (ent-alist (aget vhdl-entity-alist key t))
14402 (ent-entry (aget ent-alist token t))
14403 (arch-alist (nth 3 ent-entry))
5eabfe72 14404 (inst-alist (vhdl-get-instantiations token indent))
0a2e512a
RF
14405 (subpack-alist (nth 5 ent-entry))
14406 (multiple-arch (> (length arch-alist) 1))
3dcb36b7
JB
14407 arch-entry inst-entry)
14408 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14409 (speedbar-change-expand-button-char ??)
14410 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14411 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14412 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14413 (aput 'unit-alist token nil)
14414 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14415 (speedbar-with-writable
3dcb36b7
JB
14416 (save-excursion
14417 (end-of-line) (forward-char 1)
14418 ;; insert architectures
14419 (when arch-alist
14420 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14421 (while arch-alist
14422 (setq arch-entry (car arch-alist))
14423 (speedbar-make-tag-line
14424 'curly ?+ 'vhdl-speedbar-expand-architecture
14425 (cons token (nth 0 arch-entry))
14426 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14427 (cons (nth 2 arch-entry) (nth 3 arch-entry))
0a2e512a
RF
14428 'vhdl-speedbar-architecture-face (1+ indent))
14429 (when (and multiple-arch
14430 (equal (nth 0 arch-entry) (nth 4 ent-entry)))
14431 (end-of-line 0) (insert " (mra)") (forward-char 1))
3dcb36b7
JB
14432 (setq arch-alist (cdr arch-alist)))
14433 ;; insert instantiations
14434 (when inst-alist
14435 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14436 (while inst-alist
14437 (setq inst-entry (car inst-alist))
14438 (vhdl-speedbar-make-inst-line
14439 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14440 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14441 nil nil nil (1+ indent) 0 " in ")
14442 (setq inst-alist (cdr inst-alist)))
14443 ;; insert required packages
14444 (vhdl-speedbar-insert-subpackages
14445 subpack-alist (1+ indent) 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))))
5eabfe72
KH
14449 ((string-match "-" text) ; contract entity
14450 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14451 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14452 (let* ((key (vhdl-speedbar-line-key indent))
14453 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14454 (adelete 'unit-alist token)
14455 (if unit-alist
14456 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14457 (adelete 'vhdl-speedbar-shown-unit-alist key))
14458 (speedbar-delete-subblock indent)
14459 (when (memq 'display vhdl-speedbar-save-cache)
14460 (add-to-list 'vhdl-updated-project-list key))))
14461 (t (error "Nothing to display")))
14462 (when (equal (selected-frame) speedbar-frame)
14463 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14464
14465(defun vhdl-speedbar-expand-architecture (text token indent)
14466 "Expand/contract the architecture under the cursor."
14467 (cond
14468 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14469 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14470 (ent-alist (aget vhdl-entity-alist key t))
14471 (conf-alist (aget vhdl-config-alist key t))
14472 (hier-alist (vhdl-get-hierarchy
14473 ent-alist conf-alist (car token) (cdr token) nil nil
14474 0 (1- indent)))
14475 (ent-entry (aget ent-alist (car token) t))
14476 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14477 (subpack-alist (nth 4 arch-entry))
14478 entry)
14479 (if (not (or hier-alist subpack-alist))
14480 (speedbar-change-expand-button-char ??)
14481 (speedbar-change-expand-button-char ?-)
14482 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14483 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14484 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14485 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14486 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14487 (speedbar-with-writable
14488 (save-excursion
14489 (end-of-line) (forward-char 1)
14490 ;; insert instance hierarchy
14491 (when hier-alist
14492 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14493 (1+ indent)))
14494 (while hier-alist
14495 (setq entry (car hier-alist))
14496 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14497 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14498 (vhdl-speedbar-make-inst-line
14499 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14500 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14501 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14502 (setq hier-alist (cdr hier-alist)))
14503 ;; insert required packages
14504 (vhdl-speedbar-insert-subpackages
14505 subpack-alist (1+ indent) (1- indent))))
14506 (when (memq 'display vhdl-speedbar-save-cache)
14507 (add-to-list 'vhdl-updated-project-list key))
14508 (vhdl-speedbar-update-current-unit t t))))
14509 ((string-match "-" text) ; contract architecture
14510 (speedbar-change-expand-button-char ?+)
14511 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14512 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14513 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14514 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14515 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14516 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14517 (speedbar-delete-subblock indent)
14518 (when (memq 'display vhdl-speedbar-save-cache)
14519 (add-to-list 'vhdl-updated-project-list key))))
14520 (t (error "Nothing to display")))
14521 (when (equal (selected-frame) speedbar-frame)
14522 (speedbar-center-buffer-smartly)))
14523
14524(defun vhdl-speedbar-expand-config (text token indent)
14525 "Expand/contract the configuration under the cursor."
14526 (cond
14527 ((string-match "+" text) ; expand configuration
14528 (let* ((key (vhdl-speedbar-line-key indent))
14529 (conf-alist (aget vhdl-config-alist key t))
14530 (conf-entry (aget conf-alist token))
14531 (ent-alist (aget vhdl-entity-alist key t))
14532 (hier-alist (vhdl-get-hierarchy
14533 ent-alist conf-alist (nth 3 conf-entry)
14534 (nth 4 conf-entry) token (nth 5 conf-entry)
14535 0 indent t))
14536 (subpack-alist (nth 6 conf-entry))
14537 entry)
14538 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14539 (speedbar-change-expand-button-char ??)
14540 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14541 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14542 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14543 (aput 'unit-alist token nil)
14544 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14545 (speedbar-with-writable
14546 (save-excursion
14547 (end-of-line) (forward-char 1)
14548 ;; insert instance hierarchy
14549 (when hier-alist
3dcb36b7 14550 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14551 (while hier-alist
3dcb36b7
JB
14552 (setq entry (car hier-alist))
14553 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14554 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14555 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14556 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14557 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14558 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14559 (setq hier-alist (cdr hier-alist)))
14560 ;; insert required packages
14561 (vhdl-speedbar-insert-subpackages
14562 subpack-alist (1+ indent) indent)))
14563 (when (memq 'display vhdl-speedbar-save-cache)
14564 (add-to-list 'vhdl-updated-project-list key))
14565 (vhdl-speedbar-update-current-unit t t))))
14566 ((string-match "-" text) ; contract configuration
5eabfe72 14567 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14568 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14569 (let* ((key (vhdl-speedbar-line-key indent))
14570 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14571 (adelete 'unit-alist token)
14572 (if unit-alist
14573 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14574 (adelete 'vhdl-speedbar-shown-unit-alist key))
14575 (speedbar-delete-subblock indent)
14576 (when (memq 'display vhdl-speedbar-save-cache)
14577 (add-to-list 'vhdl-updated-project-list key))))
14578 (t (error "Nothing to display")))
14579 (when (equal (selected-frame) speedbar-frame)
14580 (speedbar-center-buffer-smartly)))
14581
14582(defun vhdl-speedbar-expand-package (text token indent)
14583 "Expand/contract the package under the cursor."
14584 (cond
14585 ((string-match "+" text) ; expand package
14586 (let* ((key (vhdl-speedbar-line-key indent))
14587 (pack-alist (aget vhdl-package-alist key t))
14588 (pack-entry (aget pack-alist token t))
14589 (comp-alist (nth 3 pack-entry))
14590 (func-alist (nth 4 pack-entry))
14591 (func-body-alist (nth 8 pack-entry))
14592 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14593 comp-entry func-entry func-body-entry)
14594 (if (not (or comp-alist func-alist subpack-alist))
14595 (speedbar-change-expand-button-char ??)
14596 (speedbar-change-expand-button-char ?-)
14597 ;; add package to `vhdl-speedbar-shown-unit-alist'
14598 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14599 (aput 'unit-alist token nil)
14600 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14601 (speedbar-with-writable
14602 (save-excursion
14603 (end-of-line) (forward-char 1)
14604 ;; insert components
14605 (when comp-alist
14606 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14607 (while comp-alist
14608 (setq comp-entry (car comp-alist))
14609 (speedbar-make-tag-line
14610 nil nil nil
14611 (cons token (nth 0 comp-entry))
14612 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14613 (cons (nth 2 comp-entry) (nth 3 comp-entry))
0a2e512a 14614 'vhdl-speedbar-entity-face (1+ indent))
3dcb36b7
JB
14615 (setq comp-alist (cdr comp-alist)))
14616 ;; insert subprograms
14617 (when func-alist
14618 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14619 (while func-alist
14620 (setq func-entry (car func-alist)
14621 func-body-entry (aget func-body-alist (car func-entry) t))
14622 (when (nth 2 func-entry)
14623 (vhdl-speedbar-make-subprogram-line
14624 (nth 1 func-entry)
14625 (cons (nth 2 func-entry) (nth 3 func-entry))
14626 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14627 (1+ indent)))
14628 (setq func-alist (cdr func-alist)))
14629 ;; insert required packages
14630 (vhdl-speedbar-insert-subpackages
14631 subpack-alist (1+ indent) indent)))
14632 (when (memq 'display vhdl-speedbar-save-cache)
14633 (add-to-list 'vhdl-updated-project-list key))
14634 (vhdl-speedbar-update-current-unit t t))))
14635 ((string-match "-" text) ; contract package
14636 (speedbar-change-expand-button-char ?+)
14637 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14638 (let* ((key (vhdl-speedbar-line-key indent))
14639 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14640 (adelete 'unit-alist token)
14641 (if unit-alist
14642 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14643 (adelete 'vhdl-speedbar-shown-unit-alist key))
14644 (speedbar-delete-subblock indent)
14645 (when (memq 'display vhdl-speedbar-save-cache)
14646 (add-to-list 'vhdl-updated-project-list key))))
14647 (t (error "Nothing to display")))
14648 (when (equal (selected-frame) speedbar-frame)
14649 (speedbar-center-buffer-smartly)))
14650
14651(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14652 "Insert required packages."
14653 (let* ((pack-alist (aget vhdl-package-alist
14654 (vhdl-speedbar-line-key dir-indent) t))
14655 pack-key lib-name pack-entry)
14656 (when subpack-alist
14657 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14658 (while subpack-alist
14659 (setq pack-key (cdar subpack-alist)
14660 lib-name (caar subpack-alist))
14661 (setq pack-entry (aget pack-alist pack-key t))
14662 (vhdl-speedbar-make-subpack-line
14663 (or (nth 0 pack-entry) pack-key) lib-name
0a2e512a
RF
14664 (cons (nth 1 pack-entry) (nth 2 pack-entry))
14665 (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
3dcb36b7 14666 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14667
14668;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14669;; Display help functions
14670
3dcb36b7
JB
14671(defvar vhdl-speedbar-update-current-unit t
14672 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14673
14674(defun vhdl-speedbar-update-current-project ()
14675 "Highlight project that is currently active."
14676 (when (and vhdl-speedbar-show-projects
14677 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14678 (and (boundp 'speedbar-frame)
14679 (frame-live-p speedbar-frame)))
14680 (let ((last-frame (selected-frame))
14681 (project-alist vhdl-project-alist)
14682 pos)
14683 (select-frame speedbar-frame)
14684 (speedbar-with-writable
14685 (save-excursion
14686 (while project-alist
14687 (goto-char (point-min))
14688 (when (re-search-forward
14689 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14690 (put-text-property (match-beginning 1) (match-end 1) 'face
14691 (if (equal (caar project-alist) vhdl-project)
14692 'speedbar-selected-face
14693 'speedbar-directory-face))
14694 (when (equal (caar project-alist) vhdl-project)
14695 (setq pos (1- (match-beginning 1)))))
14696 (setq project-alist (cdr project-alist))))
14697 (when pos (goto-char pos)))
14698 (select-frame last-frame)
14699 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14700 t)
14701
14702(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14703 "Highlight all design units that are contained in the current file.
14704NO-POSITION non-nil means do not re-position cursor."
14705 (let ((last-frame (selected-frame))
3dcb36b7
JB
14706 (project-list vhdl-speedbar-shown-project-list)
14707 file-alist pos file-name)
5eabfe72 14708 ;; get current file name
3dcb36b7
JB
14709 (if (fboundp 'speedbar-select-attached-frame)
14710 (speedbar-select-attached-frame)
14711 (select-frame speedbar-attached-frame))
5eabfe72 14712 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14713 (when (and vhdl-speedbar-update-current-unit
14714 (or always (not (equal file-name speedbar-last-selected-file))))
14715 (if vhdl-speedbar-show-projects
14716 (while project-list
14717 (setq file-alist (append file-alist (aget vhdl-file-alist
14718 (car project-list) t)))
14719 (setq project-list (cdr project-list)))
14720 (setq file-alist (aget vhdl-file-alist
14721 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14722 (select-frame speedbar-frame)
14723 (set-buffer speedbar-buffer)
14724 (speedbar-with-writable
3dcb36b7 14725 (vhdl-prepare-search-1
5eabfe72
KH
14726 (save-excursion
14727 ;; unhighlight last units
3dcb36b7 14728 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14729 (vhdl-speedbar-update-units
3dcb36b7 14730 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14731 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
5eabfe72 14732 (vhdl-speedbar-update-units
3dcb36b7 14733 "{.} " (nth 1 file-entry)
0a2e512a 14734 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
5eabfe72 14735 (vhdl-speedbar-update-units
3dcb36b7 14736 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14737 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
5eabfe72 14738 (vhdl-speedbar-update-units
3dcb36b7 14739 "[]>] " (nth 4 file-entry)
0a2e512a 14740 speedbar-last-selected-file 'vhdl-speedbar-package-face)
5eabfe72 14741 (vhdl-speedbar-update-units
3dcb36b7 14742 "\\[.\\].+(" '("body")
0a2e512a 14743 speedbar-last-selected-file 'vhdl-speedbar-package-face)
3dcb36b7
JB
14744 (vhdl-speedbar-update-units
14745 "> " (nth 6 file-entry)
0a2e512a 14746 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
5eabfe72 14747 ;; highlight current units
3dcb36b7
JB
14748 (let* ((file-entry (aget file-alist file-name t)))
14749 (setq
14750 pos (vhdl-speedbar-update-units
14751 "\\[.\\] " (nth 0 file-entry)
0a2e512a 14752 file-name 'vhdl-speedbar-entity-selected-face pos)
3dcb36b7
JB
14753 pos (vhdl-speedbar-update-units
14754 "{.} " (nth 1 file-entry)
0a2e512a 14755 file-name 'vhdl-speedbar-architecture-selected-face pos)
3dcb36b7
JB
14756 pos (vhdl-speedbar-update-units
14757 "\\[.\\] " (nth 3 file-entry)
0a2e512a 14758 file-name 'vhdl-speedbar-configuration-selected-face pos)
3dcb36b7
JB
14759 pos (vhdl-speedbar-update-units
14760 "[]>] " (nth 4 file-entry)
0a2e512a 14761 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14762 pos (vhdl-speedbar-update-units
14763 "\\[.\\].+(" '("body")
0a2e512a 14764 file-name 'vhdl-speedbar-package-selected-face pos)
3dcb36b7
JB
14765 pos (vhdl-speedbar-update-units
14766 "> " (nth 6 file-entry)
0a2e512a 14767 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14768 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14769 (when (and pos (not no-position))
14770 (goto-char pos)
14771 (speedbar-center-buffer-smartly)
5eabfe72
KH
14772 (speedbar-position-cursor-on-line))
14773 (setq speedbar-last-selected-file file-name))
14774 (select-frame last-frame)
14775 t))
14776
3dcb36b7
JB
14777(defun vhdl-speedbar-update-units (text unit-list file-name face
14778 &optional pos)
5eabfe72 14779 "Help function to highlight design units."
3dcb36b7
JB
14780 (while unit-list
14781 (goto-char (point-min))
14782 (while (re-search-forward
14783 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14784 (when (equal file-name (car (get-text-property
14785 (match-beginning 1) 'speedbar-token)))
14786 (setq pos (or pos (point-marker)))
14787 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14788 (setq unit-list (cdr unit-list)))
14789 pos)
5eabfe72
KH
14790
14791(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14792 ent-name ent-file-marker
14793 arch-name arch-file-marker
14794 conf-name conf-file-marker
14795 lib-name depth offset delimiter)
5eabfe72 14796 "Insert instantiation entry."
3dcb36b7
JB
14797 (let ((start (point))
14798 visible-start)
5eabfe72
KH
14799 (insert (int-to-string depth) ":")
14800 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14801 (setq visible-start (point))
14802 (insert-char ? (* depth speedbar-indentation-width))
14803 (while (> offset 0)
14804 (insert "|")
14805 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14806 (setq offset (1- offset)))
14807 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14808 (setq start (point))
3dcb36b7
JB
14809 (insert ">")
14810 (speedbar-make-button start (point) nil nil nil)
14811 (setq visible-start (point))
14812 (insert " ")
5eabfe72 14813 (setq start (point))
3dcb36b7
JB
14814 (if (not inst-name)
14815 (insert "(top)")
14816 (insert inst-name)
14817 (speedbar-make-button
0a2e512a 14818 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
3dcb36b7
JB
14819 'vhdl-speedbar-find-file inst-file-marker))
14820 (insert delimiter)
14821 (when ent-name
5eabfe72 14822 (setq start (point))
3dcb36b7 14823 (insert ent-name)
5eabfe72 14824 (speedbar-make-button
0a2e512a 14825 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
3dcb36b7
JB
14826 'vhdl-speedbar-find-file ent-file-marker)
14827 (when arch-name
14828 (insert " (")
14829 (setq start (point))
14830 (insert arch-name)
14831 (speedbar-make-button
0a2e512a 14832 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
3dcb36b7
JB
14833 'vhdl-speedbar-find-file arch-file-marker)
14834 (insert ")"))
14835 (when conf-name
14836 (insert " (")
14837 (setq start (point))
14838 (insert conf-name)
14839 (speedbar-make-button
0a2e512a 14840 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
3dcb36b7
JB
14841 'vhdl-speedbar-find-file conf-file-marker)
14842 (insert ")")))
14843 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14844 (setq start (point))
3dcb36b7
JB
14845 (insert " (" lib-name ")")
14846 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14847 'vhdl-speedbar-library-face))
5eabfe72 14848 (insert-char ?\n 1)
3dcb36b7 14849 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14850
3dcb36b7
JB
14851(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14852 body-file-marker depth)
5eabfe72 14853 "Insert package entry."
3dcb36b7
JB
14854 (let ((start (point))
14855 visible-start)
5eabfe72
KH
14856 (insert (int-to-string depth) ":")
14857 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14858 (setq visible-start (point))
14859 (insert-char ? (* depth speedbar-indentation-width))
14860 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14861 (setq start (point))
3dcb36b7
JB
14862 (insert "[+]")
14863 (speedbar-make-button
14864 start (point) 'speedbar-button-face 'speedbar-highlight-face
14865 'vhdl-speedbar-expand-package pack-key)
14866 (setq visible-start (point))
14867 (insert-char ? 1 nil)
5eabfe72
KH
14868 (setq start (point))
14869 (insert pack-name)
14870 (speedbar-make-button
0a2e512a 14871 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14872 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14873 (unless (car pack-file-marker)
14874 (insert "!"))
5eabfe72 14875 (when (car body-file-marker)
5eabfe72 14876 (insert " (")
5eabfe72
KH
14877 (setq start (point))
14878 (insert "body")
14879 (speedbar-make-button
0a2e512a 14880 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
5eabfe72 14881 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14882 (insert ")"))
5eabfe72 14883 (insert-char ?\n 1)
3dcb36b7 14884 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14885
3dcb36b7 14886(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
0a2e512a 14887 pack-body-file-marker depth)
3dcb36b7
JB
14888 "Insert used package entry."
14889 (let ((start (point))
14890 visible-start)
14891 (insert (int-to-string depth) ":")
14892 (put-text-property start (point) 'invisible t)
14893 (setq visible-start (point))
14894 (insert-char ? (* depth speedbar-indentation-width))
14895 (put-text-property visible-start (point) 'invisible nil)
14896 (setq start (point))
14897 (insert ">")
14898 (speedbar-make-button start (point) nil nil nil)
14899 (setq visible-start (point))
14900 (insert " ")
14901 (setq start (point))
14902 (insert pack-name)
14903 (speedbar-make-button
0a2e512a 14904 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
3dcb36b7 14905 'vhdl-speedbar-find-file pack-file-marker)
0a2e512a
RF
14906 (when (car pack-body-file-marker)
14907 (insert " (")
14908 (setq start (point))
14909 (insert "body")
14910 (speedbar-make-button
14911 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14912 'vhdl-speedbar-find-file pack-body-file-marker)
14913 (insert ")"))
3dcb36b7
JB
14914 (setq start (point))
14915 (insert " (" lib-name ")")
14916 (put-text-property (+ 2 start) (1- (point)) 'face
0a2e512a 14917 'vhdl-speedbar-library-face)
3dcb36b7
JB
14918 (insert-char ?\n 1)
14919 (put-text-property visible-start (point) 'invisible nil)))
14920
14921(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14922 func-body-file-marker
14923 depth)
14924 "Insert subprogram entry."
14925 (let ((start (point))
14926 visible-start)
5eabfe72
KH
14927 (insert (int-to-string depth) ":")
14928 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14929 (setq visible-start (point))
14930 (insert-char ? (* depth speedbar-indentation-width))
14931 (put-text-property visible-start (point) 'invisible nil)
14932 (setq start (point))
14933 (insert ">")
14934 (speedbar-make-button start (point) nil nil nil)
14935 (setq visible-start (point))
14936 (insert " ")
5eabfe72 14937 (setq start (point))
3dcb36b7
JB
14938 (insert func-name)
14939 (speedbar-make-button
0a2e512a 14940 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14941 'vhdl-speedbar-find-file func-file-marker)
14942 (when (car func-body-file-marker)
14943 (insert " (")
14944 (setq start (point))
14945 (insert "body")
14946 (speedbar-make-button
0a2e512a 14947 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
3dcb36b7
JB
14948 'vhdl-speedbar-find-file func-body-file-marker)
14949 (insert ")"))
14950 (insert-char ?\n 1)
14951 (put-text-property visible-start (point) 'invisible nil)))
14952
14953(defun vhdl-speedbar-make-title-line (text &optional depth)
14954 "Insert design unit title entry."
14955 (let ((start (point))
14956 visible-start)
14957 (when depth
14958 (insert (int-to-string depth) ":")
14959 (put-text-property start (point) 'invisible t))
14960 (setq visible-start (point))
14961 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14962 (setq start (point))
14963 (insert text)
14964 (speedbar-make-button start (point) nil nil nil nil)
14965 (insert-char ?\n 1)
3dcb36b7 14966 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14967
14968(defun vhdl-speedbar-insert-dirs (files level)
14969 "Insert subdirectories."
14970 (let ((dirs (car files)))
14971 (while dirs
14972 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14973 (car dirs) 'speedbar-dir-follow nil
14974 'speedbar-directory-face level)
14975 (setq dirs (cdr dirs)))))
14976
14977(defun vhdl-speedbar-dired (text token indent)
14978 "Speedbar click handler for directory expand button in hierarchy mode."
14979 (cond ((string-match "+" text) ; we have to expand this dir
14980 (setq speedbar-shown-directories
14981 (cons (expand-file-name
7752250e 14982 (concat (speedbar-line-directory indent) token "/"))
5eabfe72
KH
14983 speedbar-shown-directories))
14984 (speedbar-change-expand-button-char ?-)
14985 (speedbar-reset-scanners)
14986 (speedbar-with-writable
14987 (save-excursion
14988 (end-of-line) (forward-char 1)
14989 (vhdl-speedbar-insert-dirs
14990 (speedbar-file-lists
7752250e 14991 (concat (speedbar-line-directory indent) token "/"))
5eabfe72
KH
14992 (1+ indent))
14993 (speedbar-reset-scanners)
14994 (vhdl-speedbar-insert-dir-hierarchy
14995 (abbreviate-file-name
7752250e 14996 (concat (speedbar-line-directory indent) token "/"))
5eabfe72 14997 (1+ indent) speedbar-power-click)))
3dcb36b7 14998 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
14999 ((string-match "-" text) ; we have to contract this node
15000 (speedbar-reset-scanners)
15001 (let ((oldl speedbar-shown-directories)
15002 (newl nil)
15003 (td (expand-file-name
7752250e 15004 (concat (speedbar-line-directory indent) token))))
5eabfe72
KH
15005 (while oldl
15006 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
15007 (setq newl (cons (car oldl) newl)))
15008 (setq oldl (cdr oldl)))
15009 (setq speedbar-shown-directories (nreverse newl)))
15010 (speedbar-change-expand-button-char ?+)
15011 (speedbar-delete-subblock indent))
3dcb36b7
JB
15012 (t (error "Nothing to display")))
15013 (when (equal (selected-frame) speedbar-frame)
15014 (speedbar-center-buffer-smartly)))
5eabfe72
KH
15015
15016(defun vhdl-speedbar-item-info ()
15017 "Derive and display information about this line item."
15018 (save-excursion
15019 (beginning-of-line)
15020 ;; skip invisible number info
3dcb36b7 15021 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 15022 (cond
3dcb36b7
JB
15023 ;; project/directory entry
15024 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15025 (if vhdl-speedbar-show-projects
15026 (message "Project \"%s\"" (match-string-no-properties 1))
15027 (speedbar-files-item-info)))
5eabfe72 15028 ;; design unit entry
3dcb36b7
JB
15029 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15030 (goto-char (match-end 1))
5eabfe72
KH
15031 (let ((face (get-text-property (point) 'face)))
15032 (message
15033 "%s \"%s\" in \"%s\""
15034 ;; design unit kind
0a2e512a
RF
15035 (cond ((or (eq face 'vhdl-speedbar-entity-face)
15036 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 15037 (if (equal (match-string 2) ">") "Component" "Entity"))
0a2e512a
RF
15038 ((or (eq face 'vhdl-speedbar-architecture-face)
15039 (eq face 'vhdl-speedbar-architecture-selected-face))
5eabfe72 15040 "Architecture")
0a2e512a
RF
15041 ((or (eq face 'vhdl-speedbar-configuration-face)
15042 (eq face 'vhdl-speedbar-configuration-selected-face))
5eabfe72 15043 "Configuration")
0a2e512a
RF
15044 ((or (eq face 'vhdl-speedbar-package-face)
15045 (eq face 'vhdl-speedbar-package-selected-face))
5eabfe72 15046 "Package")
0a2e512a
RF
15047 ((or (eq face 'vhdl-speedbar-instantiation-face)
15048 (eq face 'vhdl-speedbar-instantiation-selected-face))
5eabfe72 15049 "Instantiation")
0a2e512a 15050 ((eq face 'vhdl-speedbar-subprogram-face)
3dcb36b7 15051 "Subprogram")
5eabfe72
KH
15052 (t ""))
15053 ;; design unit name
15054 (buffer-substring-no-properties
3dcb36b7
JB
15055 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15056 (match-end 1))
5eabfe72 15057 ;; file name
3dcb36b7
JB
15058 (file-relative-name
15059 (or (car (get-text-property (point) 'speedbar-token))
15060 "?")
15061 (vhdl-default-directory)))))
15062 (t (message "")))))
15063
15064(defun vhdl-speedbar-line-text ()
15065 "Calls `speedbar-line-text' and removes text properties."
15066 (let ((string (speedbar-line-text)))
15067 (set-text-properties 0 (length string) nil string)
15068 string))
5eabfe72 15069
0a2e512a
RF
15070(defun vhdl-speedbar-higher-text ()
15071 "Get speedbar-line-text of higher level."
15072 (let (depth string)
15073 (save-excursion
15074 (beginning-of-line)
15075 (looking-at "^\\([0-9]+\\):")
15076 (setq depth (string-to-number (match-string 1)))
15077 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
15078 (setq string (match-string 1))
15079 (set-text-properties 0 (length string) nil string)
15080 string))))
15081
5eabfe72
KH
15082;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15083;; Help functions
d2ddb974 15084
3dcb36b7
JB
15085(defun vhdl-speedbar-line-key (&optional indent)
15086 "Get currently displayed directory of project name."
15087 (if vhdl-speedbar-show-projects
15088 (vhdl-speedbar-line-project)
15089 (abbreviate-file-name
7752250e 15090 (file-name-as-directory (speedbar-line-directory indent)))))
3dcb36b7
JB
15091
15092(defun vhdl-speedbar-line-project (&optional indent)
15093 "Get currently displayed project name."
15094 (and vhdl-speedbar-show-projects
15095 (save-excursion
15096 (end-of-line)
15097 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
15098 (match-string-no-properties 1))))
15099
15100(defun vhdl-add-modified-file ()
15101 "Add file to `vhdl-modified-file-list'."
15102 (when vhdl-file-alist
15103 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
15104 nil)
5eabfe72
KH
15105
15106(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
15107 "Resolve path wildcards in PATH-LIST."
15108 (let (path-list-1 path-list-2 path-beg path-end dir)
15109 ;; eliminate non-existent directories
5eabfe72
KH
15110 (while path-list
15111 (setq dir (car path-list))
3dcb36b7
JB
15112 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
15113 (if (file-directory-p (match-string 2 dir))
15114 (setq path-list-1 (cons dir path-list-1))
15115 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 15116 (setq path-list (cdr path-list)))
3dcb36b7 15117 ;; resolve path wildcards
5eabfe72
KH
15118 (while path-list-1
15119 (setq dir (car path-list-1))
3dcb36b7 15120 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
15121 (progn
15122 (setq path-beg (match-string 1 dir)
15123 path-end (match-string 5 dir))
3dcb36b7 15124 (setq path-list-1
5eabfe72
KH
15125 (append
15126 (mapcar
15127 (function
15128 (lambda (var) (concat path-beg var path-end)))
15129 (let ((all-list (vhdl-directory-files
15130 (match-string 2 dir) t
15131 (concat "\\<" (wildcard-to-regexp
15132 (match-string 4 dir)))))
15133 dir-list)
15134 (while all-list
15135 (when (file-directory-p (car all-list))
15136 (setq dir-list (cons (car all-list) dir-list)))
15137 (setq all-list (cdr all-list)))
15138 dir-list))
3dcb36b7
JB
15139 (cdr path-list-1))))
15140 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 15141 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
15142 (setq path-list-2 (cons dir path-list-2)))
15143 (setq path-list-1 (cdr path-list-1))))
15144 (nreverse path-list-2)))
5eabfe72
KH
15145
15146(defun vhdl-speedbar-goto-this-unit (directory unit)
15147 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15148 (let ((dest (point)))
3dcb36b7 15149 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
15150 (progn (goto-char (point-min)) t)
15151 (speedbar-goto-this-file directory))
15152 (re-search-forward (concat "[]}] " unit "\\>") nil t))
15153 (progn (speedbar-position-cursor-on-line)
15154 t)
15155 (goto-char dest)
15156 nil)))
15157
15158(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
15159 "When user clicks on TEXT, load file with name and position in TOKEN.
15160Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15161is already shown in a buffer."
5eabfe72 15162 (if (not (car token))
3dcb36b7
JB
15163 (error "ERROR: File cannot be found")
15164 (let ((buffer (get-file-buffer (car token))))
15165 (speedbar-find-file-in-frame (car token))
15166 (when (or vhdl-speedbar-jump-to-unit buffer)
15167 (goto-line (cdr token))
15168 (recenter))
15169 (vhdl-speedbar-update-current-unit t t)
15170 (speedbar-set-timer speedbar-update-speed)
15171 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
15172
15173(defun vhdl-speedbar-port-copy ()
3dcb36b7 15174 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 15175 (interactive)
3dcb36b7
JB
15176 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
15177 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
15178 (error "ERROR: No entity/component or subprogram under cursor")
15179 (beginning-of-line)
15180 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15181 (condition-case info
15182 (let ((token (get-text-property
15183 (match-beginning 3) 'speedbar-token)))
15184 (vhdl-visit-file (car token) t
15185 (progn (goto-line (cdr token))
15186 (end-of-line)
15187 (if is-entity
15188 (vhdl-port-copy)
15189 (vhdl-subprog-copy)))))
15190 (error (error "ERROR: %s not scanned successfully\n (%s)"
15191 (if is-entity "Port" "Interface") (cadr info))))
15192 (error "ERROR: No entity/component or subprogram on current line")))))
15193
15194(defun vhdl-speedbar-place-component ()
15195 "Place the entity/component under the cursor as component."
15196 (interactive)
15197 (if (not (vhdl-speedbar-check-unit 'entity))
5bb5087f 15198 (error "ERROR: No entity/component under cursor")
3dcb36b7
JB
15199 (vhdl-speedbar-port-copy)
15200 (if (fboundp 'speedbar-select-attached-frame)
15201 (speedbar-select-attached-frame)
15202 (select-frame speedbar-attached-frame))
15203 (vhdl-compose-place-component)
15204 (select-frame speedbar-frame)))
15205
0a2e512a
RF
15206(defun vhdl-speedbar-configuration ()
15207 "Generate configuration for the architecture under the cursor."
15208 (interactive)
15209 (if (not (vhdl-speedbar-check-unit 'architecture))
15210 (error "ERROR: No architecture under cursor")
15211 (let ((arch-name (vhdl-speedbar-line-text))
15212 (ent-name (vhdl-speedbar-higher-text)))
15213 (if (fboundp 'speedbar-select-attached-frame)
15214 (speedbar-select-attached-frame)
15215 (select-frame speedbar-attached-frame))
15216 (vhdl-compose-configuration ent-name arch-name))))
15217
15218(defun vhdl-speedbar-select-mra ()
15219 "Select the architecture under the cursor as MRA."
15220 (interactive)
15221 (if (not (vhdl-speedbar-check-unit 'architecture))
15222 (error "ERROR: No architecture under cursor")
15223 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15224 (ent-key (downcase (vhdl-speedbar-higher-text)))
15225 (ent-alist (aget vhdl-entity-alist
15226 (or (vhdl-project-p) default-directory) t))
15227 (ent-entry (aget ent-alist ent-key t)))
15228 (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
15229 (speedbar-refresh))))
15230
3dcb36b7
JB
15231(defun vhdl-speedbar-make-design ()
15232 "Make (compile) design unit or directory/project under the cursor."
15233 (interactive)
15234 (if (not (save-excursion (beginning-of-line)
15235 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15236 (error "ERROR: No primary design unit or directory/project under cursor")
15237 (let ((is-unit (match-string 2))
15238 (unit-name (vhdl-speedbar-line-text))
15239 (vhdl-project (vhdl-speedbar-line-project))
15240 (directory (file-name-as-directory
7752250e 15241 (or (speedbar-line-file) (speedbar-line-directory)))))
3dcb36b7
JB
15242 (if (fboundp 'speedbar-select-attached-frame)
15243 (speedbar-select-attached-frame)
15244 (select-frame speedbar-attached-frame))
15245 (let ((default-directory directory))
15246 (vhdl-make (and is-unit unit-name))))))
15247
15248(defun vhdl-speedbar-generate-makefile ()
15249 "Generate Makefile for directory/project under the cursor."
15250 (interactive)
15251 (let ((vhdl-project (vhdl-speedbar-line-project))
15252 (default-directory (file-name-as-directory
7752250e 15253 (or (speedbar-line-file) (speedbar-line-directory)))))
3dcb36b7
JB
15254 (vhdl-generate-makefile)))
15255
15256(defun vhdl-speedbar-check-unit (design-unit)
15257 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15258expansion function)."
15259 (save-excursion
15260 (speedbar-position-cursor-on-line)
15261 (cond ((eq design-unit 'entity)
15262 (memq (get-text-property (match-end 0) 'face)
0a2e512a
RF
15263 '(vhdl-speedbar-entity-face
15264 vhdl-speedbar-entity-selected-face)))
15265 ((eq design-unit 'architecture)
15266 (memq (get-text-property (match-end 0) 'face)
15267 '(vhdl-speedbar-architecture-face
15268 vhdl-speedbar-architecture-selected-face)))
3dcb36b7
JB
15269 ((eq design-unit 'subprogram)
15270 (eq (get-text-property (match-end 0) 'face)
0a2e512a 15271 'vhdl-speedbar-subprogram-face))
3dcb36b7
JB
15272 (t nil))))
15273
15274(defun vhdl-speedbar-set-depth (depth)
15275 "Set hierarchy display depth to DEPTH and refresh speedbar."
15276 (setq vhdl-speedbar-hierarchy-depth depth)
15277 (speedbar-refresh))
5eabfe72
KH
15278
15279;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15280;; Fontification
15281
0a2e512a 15282(defface vhdl-speedbar-entity-face
5eabfe72
KH
15283 '((((class color) (background light)) (:foreground "ForestGreen"))
15284 (((class color) (background dark)) (:foreground "PaleGreen")))
15285 "Face used for displaying entity names."
15286 :group 'speedbar-faces)
15287
0a2e512a 15288(defface vhdl-speedbar-architecture-face
f47877ee
DN
15289 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
15290 (((class color) (background light)) (:foreground "Blue"))
84c98ace 15291
5eabfe72
KH
15292 (((class color) (background dark)) (:foreground "LightSkyBlue")))
15293 "Face used for displaying architecture names."
15294 :group 'speedbar-faces)
d2ddb974 15295
0a2e512a 15296(defface vhdl-speedbar-configuration-face
5eabfe72
KH
15297 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
15298 (((class color) (background dark)) (:foreground "Salmon")))
15299 "Face used for displaying configuration names."
15300 :group 'speedbar-faces)
15301
0a2e512a 15302(defface vhdl-speedbar-package-face
5eabfe72
KH
15303 '((((class color) (background light)) (:foreground "Grey50"))
15304 (((class color) (background dark)) (:foreground "Grey80")))
15305 "Face used for displaying package names."
15306 :group 'speedbar-faces)
15307
0a2e512a 15308(defface vhdl-speedbar-library-face
3dcb36b7
JB
15309 '((((class color) (background light)) (:foreground "Purple"))
15310 (((class color) (background dark)) (:foreground "Orchid1")))
15311 "Face used for displaying library names."
15312 :group 'speedbar-faces)
15313
0a2e512a 15314(defface vhdl-speedbar-instantiation-face
5eabfe72 15315 '((((class color) (background light)) (:foreground "Brown"))
ea81d57e 15316 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
5eabfe72
KH
15317 (((class color) (background dark)) (:foreground "Yellow")))
15318 "Face used for displaying instantiation names."
15319 :group 'speedbar-faces)
15320
0a2e512a 15321(defface vhdl-speedbar-subprogram-face
3dcb36b7
JB
15322 '((((class color) (background light)) (:foreground "Orchid4"))
15323 (((class color) (background dark)) (:foreground "BurlyWood2")))
15324 "Face used for displaying subprogram names."
15325 :group 'speedbar-faces)
15326
0a2e512a 15327(defface vhdl-speedbar-entity-selected-face
5eabfe72
KH
15328 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15329 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15330 "Face used for displaying entity names."
15331 :group 'speedbar-faces)
15332
0a2e512a 15333(defface vhdl-speedbar-architecture-selected-face
f47877ee
DN
15334 '((((min-colors 88) (class color) (background light)) (:foreground
15335 "Blue1" :underline t))
15336 (((class color) (background light)) (:foreground "Blue" :underline t))
5eabfe72
KH
15337 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15338 "Face used for displaying architecture names."
15339 :group 'speedbar-faces)
15340
0a2e512a 15341(defface vhdl-speedbar-configuration-selected-face
5eabfe72
KH
15342 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15343 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15344 "Face used for displaying configuration names."
15345 :group 'speedbar-faces)
15346
0a2e512a 15347(defface vhdl-speedbar-package-selected-face
5eabfe72
KH
15348 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15349 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15350 "Face used for displaying package names."
15351 :group 'speedbar-faces)
15352
0a2e512a 15353(defface vhdl-speedbar-instantiation-selected-face
5eabfe72
KH
15354 '((((class color) (background light)) (:foreground "Brown" :underline t))
15355 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15356 "Face used for displaying instantiation names."
15357 :group 'speedbar-faces)
15358
3dcb36b7
JB
15359;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15360;; Initialization
15361
15362;; add speedbar
15363(when (fboundp 'speedbar)
15364 (condition-case ()
15365 (when (and vhdl-speedbar-auto-open
15366 (not (and (boundp 'speedbar-frame)
15367 (frame-live-p speedbar-frame))))
15368 (speedbar-frame-mode 1)
15369 (if (fboundp 'speedbar-select-attached-frame)
15370 (speedbar-select-attached-frame)
15371 (select-frame speedbar-attached-frame)))
15372 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15373
15374;; initialize speedbar
15375(if (not (boundp 'speedbar-frame))
15376 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15377 (vhdl-speedbar-initialize)
15378 (when speedbar-frame (vhdl-speedbar-refresh)))
15379
15380
15381;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15382;;; Structural composition
15383;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15384
15385(defun vhdl-get-components-package-name ()
15386 "Return the name of the components package."
15387 (let ((project (vhdl-project-p)))
15388 (if project
15389 (vhdl-replace-string (car vhdl-components-package-name)
15390 (subst-char-in-string ? ?_ project))
15391 (cdr vhdl-components-package-name))))
15392
15393(defun vhdl-compose-new-component ()
15394 "Create entity and architecture for new component."
15395 (interactive)
15396 (let* ((case-fold-search t)
15397 (ent-name (read-from-minibuffer "entity name: "
15398 nil vhdl-minibuffer-local-map))
15399 (arch-name
15400 (if (equal (cdr vhdl-compose-architecture-name) "")
15401 (read-from-minibuffer "architecture name: "
15402 nil vhdl-minibuffer-local-map)
15403 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15404 ent-file-name arch-file-name ent-buffer arch-buffer project)
15405 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15406 ;; open entity file
15407 (unless (eq vhdl-compose-create-files 'none)
15408 (setq ent-file-name
0a2e512a 15409 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15410 "." (file-name-extension (buffer-file-name))))
15411 (when (and (file-exists-p ent-file-name)
15412 (not (y-or-n-p (concat "File \"" ent-file-name
15413 "\" exists; overwrite? "))))
15414 (error "ERROR: Creating component...aborted"))
15415 (find-file ent-file-name)
15416 (erase-buffer)
15417 (set-buffer-modified-p nil))
15418 ;; insert header
15419 (if vhdl-compose-include-header
15420 (progn (vhdl-template-header)
15421 (goto-char (point-max)))
15422 (vhdl-comment-display-line) (insert "\n\n"))
15423 ;; insert library clause
15424 (vhdl-template-package-std-logic-1164)
15425 (when vhdl-use-components-package
15426 (insert "\n")
15427 (vhdl-template-standard-package (vhdl-work-library)
15428 (vhdl-get-components-package-name)))
15429 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15430 ;; insert entity declaration
15431 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15432 (vhdl-insert-keyword " IS\n")
15433 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15434 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15435 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15436 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15437 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15438 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15439 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15440 (vhdl-insert-keyword "END ")
15441 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15442 (insert ent-name ";\n\n")
15443 (vhdl-comment-display-line) (insert "\n")
15444 ;; open architecture file
15445 (if (not (eq vhdl-compose-create-files 'separate))
15446 (insert "\n")
15447 (setq ent-buffer (current-buffer))
15448 (setq arch-file-name
15449 (concat (vhdl-replace-string vhdl-architecture-file-name
0a2e512a 15450 (concat ent-name " " arch-name) t)
3dcb36b7
JB
15451 "." (file-name-extension (buffer-file-name))))
15452 (when (and (file-exists-p arch-file-name)
15453 (not (y-or-n-p (concat "File \"" arch-file-name
15454 "\" exists; overwrite? "))))
15455 (error "ERROR: Creating component...aborted"))
15456 (find-file arch-file-name)
15457 (erase-buffer)
15458 (set-buffer-modified-p nil)
15459 ;; insert header
15460 (if vhdl-compose-include-header
15461 (progn (vhdl-template-header)
15462 (goto-char (point-max)))
15463 (vhdl-comment-display-line) (insert "\n\n")))
15464 ;; insert architecture body
15465 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15466 (vhdl-insert-keyword " OF ") (insert ent-name)
15467 (vhdl-insert-keyword " IS\n\n")
15468 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15469 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15470 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15471 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15472 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15473 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15474 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15475 (vhdl-insert-keyword "BEGIN")
15476 (when vhdl-self-insert-comments
15477 (insert " -- ")
15478 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15479 (insert arch-name))
15480 (insert "\n\n")
15481 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15482 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15483 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15484 (vhdl-insert-keyword "END ")
15485 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15486 (insert arch-name ";\n\n")
0a2e512a 15487 ;; insert footer and save
3dcb36b7
JB
15488 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15489 (vhdl-template-footer)
15490 (vhdl-comment-display-line) (insert "\n"))
15491 (goto-char (point-min))
15492 (setq arch-buffer (current-buffer))
15493 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15494 (set-buffer arch-buffer) (save-buffer)
29a4e67d 15495 (message "%s"
3dcb36b7
JB
15496 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15497 (and ent-file-name
15498 (format "\n File created: \"%s\"" ent-file-name))
15499 (and arch-file-name
15500 (format "\n File created: \"%s\"" arch-file-name))))))
15501
15502(defun vhdl-compose-place-component ()
15503 "Place new component by pasting current port as component declaration and
15504component instantiation."
15505 (interactive)
15506 (if (not vhdl-port-list)
15507 (error "ERROR: No port has been read")
15508 (save-excursion
15509 (vhdl-prepare-search-2
15510 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15511 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15512 (error "ERROR: No architecture found"))
15513 (let* ((ent-name (match-string 1))
15514 (ent-file-name
0a2e512a 15515 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15516 "." (file-name-extension (buffer-file-name))))
15517 (orig-buffer (current-buffer)))
15518 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15519 ;; place component declaration
15520 (unless (or vhdl-use-components-package
15521 (vhdl-use-direct-instantiation)
15522 (save-excursion
15523 (re-search-forward
15524 (concat "^\\s-*component\\s-+"
15525 (car vhdl-port-list) "\\>") nil t)))
15526 (re-search-forward "^begin\\>" nil)
15527 (beginning-of-line)
15528 (skip-chars-backward " \t\n")
15529 (insert "\n\n") (indent-to vhdl-basic-offset)
15530 (vhdl-port-paste-component t))
15531 ;; place component instantiation
15532 (re-search-forward "^end\\>" nil)
15533 (beginning-of-line)
15534 (skip-chars-backward " \t\n")
15535 (insert "\n\n") (indent-to vhdl-basic-offset)
15536 (vhdl-port-paste-instance nil t t)
15537 ;; place use clause for used packages
15538 (when (nth 3 vhdl-port-list)
15539 ;; open entity file
15540 (when (file-exists-p ent-file-name)
15541 (find-file ent-file-name))
15542 (goto-char (point-min))
15543 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15544 (error "ERROR: Entity not found: \"%s\"" ent-name))
15545 (goto-char (match-beginning 0))
15546 (if (and (save-excursion
15547 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15548 (match-string 1))
15549 (progn (goto-char (match-end 0))
15550 (beginning-of-line 2))
15551 (insert "\n")
15552 (backward-char))
15553 (vhdl-port-paste-context-clause)
15554 (switch-to-buffer orig-buffer))
15555 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15556
15557(defun vhdl-compose-wire-components ()
15558 "Connect components."
15559 (interactive)
15560 (save-excursion
15561 (vhdl-prepare-search-2
15562 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15563 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15564 (error "ERROR: No architecture found"))
15565 (let* ((ent-name (match-string 1))
15566 (ent-file-name
0a2e512a 15567 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
3dcb36b7
JB
15568 "." (file-name-extension (buffer-file-name))))
15569 (arch-decl-pos (point-marker))
15570 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15571 (arch-end-pos (re-search-forward "^end\\>" nil))
15572 (pack-name (vhdl-get-components-package-name))
15573 (pack-file-name
0a2e512a 15574 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15575 "." (file-name-extension (buffer-file-name))))
15576 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15577 port-alist generic-alist inst-alist
15578 signal-name signal-entry signal-alist local-list written-list
15579 single-in-list multi-in-list single-out-list multi-out-list
15580 constant-name constant-entry constant-alist single-list multi-list
15581 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15582 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15583 signal-beg-pos signal-pos
15584 constant-temp-pos port-temp-pos signal-temp-pos)
15585 (message "Wiring components...")
15586 ;; process all instances
15587 (goto-char arch-stat-pos)
15588 (while (re-search-forward
15589 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15590 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15591 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15592 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15593 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15594 (setq inst-name (match-string-no-properties 1)
15595 comp-name (match-string-no-properties 4)
15596 comp-ent-name (match-string-no-properties 12)
15597 has-generic (or (match-string 7) (match-string 17)))
15598 ;; get port ...
15599 (if comp-name
15600 ;; ... from component declaration
15601 (vhdl-visit-file
15602 (when vhdl-use-components-package pack-file-name) t
15603 (save-excursion
15604 (goto-char (point-min))
15605 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15606 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15607 (vhdl-port-copy)))
15608 ;; ... from entity declaration (direct instantiation)
15609 (setq comp-ent-file-name
0a2e512a 15610 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
3dcb36b7
JB
15611 "." (file-name-extension (buffer-file-name))))
15612 (vhdl-visit-file
15613 comp-ent-file-name t
15614 (save-excursion
15615 (goto-char (point-min))
15616 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15617 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15618 (vhdl-port-copy))))
15619 (vhdl-port-flatten t)
15620 (setq generic-alist (nth 1 vhdl-port-list)
0a2e512a
RF
15621 port-alist (nth 2 vhdl-port-list)
15622 vhdl-port-list nil)
3dcb36b7
JB
15623 (setq constant-alist nil
15624 signal-alist nil)
15625 (when has-generic
15626 ;; process all constants in generic map
15627 (vhdl-forward-syntactic-ws)
15628 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15629 (setq constant-name (match-string-no-properties 3))
15630 (setq constant-entry
15631 (cons constant-name
15632 (if (match-string 1)
15633 (or (aget generic-alist (match-string 2) t)
ec3ec9cc 15634 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15635 (cdar generic-alist))))
15636 (setq constant-alist (cons constant-entry constant-alist))
15637 (setq constant-name (downcase constant-name))
15638 (if (or (member constant-name single-list)
15639 (member constant-name multi-list))
15640 (progn (setq single-list (delete constant-name single-list))
15641 (add-to-list 'multi-list constant-name))
15642 (add-to-list 'single-list constant-name))
15643 (unless (match-string 1)
15644 (setq generic-alist (cdr generic-alist)))
15645 (vhdl-forward-syntactic-ws))
15646 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15647 ;; process all signals in port map
15648 (vhdl-forward-syntactic-ws)
15649 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15650 (setq signal-name (match-string-no-properties 3))
15651 (setq signal-entry (cons signal-name
15652 (if (match-string 1)
15653 (or (aget port-alist (match-string 2) t)
ec3ec9cc 15654 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
3dcb36b7
JB
15655 (cdar port-alist))))
15656 (setq signal-alist (cons signal-entry signal-alist))
15657 (setq signal-name (downcase signal-name))
15658 (if (equal (upcase (nth 2 signal-entry)) "IN")
15659 ;; input signal
15660 (cond
15661 ((member signal-name local-list)
15662 nil)
15663 ((or (member signal-name single-out-list)
15664 (member signal-name multi-out-list))
15665 (setq single-out-list (delete signal-name single-out-list))
15666 (setq multi-out-list (delete signal-name multi-out-list))
15667 (add-to-list 'local-list signal-name))
15668 ((member signal-name single-in-list)
15669 (setq single-in-list (delete signal-name single-in-list))
15670 (add-to-list 'multi-in-list signal-name))
15671 ((not (member signal-name multi-in-list))
15672 (add-to-list 'single-in-list signal-name)))
15673 ;; output signal
15674 (cond
15675 ((member signal-name local-list)
15676 nil)
15677 ((or (member signal-name single-in-list)
15678 (member signal-name multi-in-list))
15679 (setq single-in-list (delete signal-name single-in-list))
15680 (setq multi-in-list (delete signal-name multi-in-list))
15681 (add-to-list 'local-list signal-name))
15682 ((member signal-name single-out-list)
15683 (setq single-out-list (delete signal-name single-out-list))
15684 (add-to-list 'multi-out-list signal-name))
15685 ((not (member signal-name multi-out-list))
15686 (add-to-list 'single-out-list signal-name))))
15687 (unless (match-string 1)
15688 (setq port-alist (cdr port-alist)))
15689 (vhdl-forward-syntactic-ws))
15690 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15691 (nreverse signal-alist)) inst-alist)))
15692 ;; prepare signal insertion
15693 (vhdl-goto-marker arch-decl-pos)
15694 (forward-line 1)
15695 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15696 (setq signal-pos (point-marker))
15697 (while (progn (vhdl-forward-syntactic-ws)
15698 (looking-at "signal\\>"))
15699 (beginning-of-line 2)
15700 (delete-region signal-pos (point)))
15701 (setq signal-beg-pos signal-pos)
15702 ;; open entity file
15703 (when (file-exists-p ent-file-name)
15704 (find-file ent-file-name))
15705 (goto-char (point-min))
15706 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15707 (error "ERROR: Entity not found: \"%s\"" ent-name))
15708 ;; prepare generic clause insertion
15709 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15710 (match-string 1))
15711 (goto-char (match-beginning 0))
15712 (indent-to vhdl-basic-offset)
15713 (insert "generic ();\n\n")
15714 (backward-char 4))
15715 (backward-char)
15716 (setq generic-pos (point-marker))
15717 (forward-sexp) (end-of-line)
15718 (delete-region generic-pos (point)) (delete-char 1)
15719 (insert "(\n")
15720 (when multi-list
15721 (insert "\n")
15722 (indent-to (* 2 vhdl-basic-offset))
15723 (insert "-- global generics\n"))
15724 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15725 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15726 ;; prepare port clause insertion
15727 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15728 (match-string 1))
15729 (goto-char (match-beginning 0))
15730 (indent-to vhdl-basic-offset)
15731 (insert "port ();\n\n")
15732 (backward-char 4))
15733 (backward-char)
15734 (setq port-in-pos (point-marker))
15735 (forward-sexp) (end-of-line)
15736 (delete-region port-in-pos (point)) (delete-char 1)
15737 (insert "(\n")
15738 (when (or multi-in-list multi-out-list)
15739 (insert "\n")
15740 (indent-to (* 2 vhdl-basic-offset))
15741 (insert "-- global ports\n"))
15742 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15743 port-out-pos (point-marker) port-inst-pos (point-marker)
15744 port-end-pos (point-marker))
15745 ;; insert generics, ports and signals
15746 (setq inst-alist (nreverse inst-alist))
15747 (while inst-alist
15748 (setq inst-name (nth 0 (car inst-alist))
15749 constant-alist (nth 1 (car inst-alist))
15750 signal-alist (nth 2 (car inst-alist))
15751 constant-temp-pos generic-inst-pos
15752 port-temp-pos port-inst-pos
15753 signal-temp-pos signal-pos)
15754 ;; generics
15755 (while constant-alist
15756 (setq constant-name (downcase (caar constant-alist))
15757 constant-entry (car constant-alist))
15758 (cond ((member constant-name written-list)
15759 nil)
15760 ((member constant-name multi-list)
15761 (vhdl-goto-marker generic-pos)
15762 (setq generic-end-pos
15763 (vhdl-max-marker
15764 generic-end-pos
15765 (vhdl-compose-insert-generic constant-entry)))
15766 (setq generic-pos (point-marker))
15767 (add-to-list 'written-list constant-name))
15768 (t
15769 (vhdl-goto-marker
15770 (vhdl-max-marker generic-inst-pos generic-pos))
15771 (setq generic-end-pos
15772 (vhdl-compose-insert-generic constant-entry))
15773 (setq generic-inst-pos (point-marker))
15774 (add-to-list 'written-list constant-name)))
15775 (setq constant-alist (cdr constant-alist)))
15776 (when (/= constant-temp-pos generic-inst-pos)
15777 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15778 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15779 (insert "-- generics for \"" inst-name "\"\n")
15780 (vhdl-goto-marker generic-inst-pos))
15781 ;; ports and signals
15782 (while signal-alist
15783 (setq signal-name (downcase (caar signal-alist))
15784 signal-entry (car signal-alist))
15785 (cond ((member signal-name written-list)
15786 nil)
15787 ((member signal-name multi-in-list)
15788 (vhdl-goto-marker port-in-pos)
15789 (setq port-end-pos
15790 (vhdl-max-marker
15791 port-end-pos (vhdl-compose-insert-port signal-entry)))
15792 (setq port-in-pos (point-marker))
15793 (add-to-list 'written-list signal-name))
15794 ((member signal-name multi-out-list)
15795 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15796 (setq port-end-pos
15797 (vhdl-max-marker
15798 port-end-pos (vhdl-compose-insert-port signal-entry)))
15799 (setq port-out-pos (point-marker))
15800 (add-to-list 'written-list signal-name))
15801 ((or (member signal-name single-in-list)
15802 (member signal-name single-out-list))
15803 (vhdl-goto-marker
15804 (vhdl-max-marker
15805 port-inst-pos
15806 (vhdl-max-marker port-out-pos port-in-pos)))
15807 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15808 (setq port-inst-pos (point-marker))
15809 (add-to-list 'written-list signal-name))
15810 ((equal (upcase (nth 2 signal-entry)) "OUT")
15811 (vhdl-goto-marker signal-pos)
15812 (vhdl-compose-insert-signal signal-entry)
15813 (setq signal-pos (point-marker))
15814 (add-to-list 'written-list signal-name)))
15815 (setq signal-alist (cdr signal-alist)))
15816 (when (/= port-temp-pos port-inst-pos)
15817 (vhdl-goto-marker
15818 (vhdl-max-marker port-temp-pos
15819 (vhdl-max-marker port-in-pos port-out-pos)))
15820 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15821 (insert "-- ports to \"" inst-name "\"\n")
15822 (vhdl-goto-marker port-inst-pos))
15823 (when (/= signal-temp-pos signal-pos)
15824 (vhdl-goto-marker signal-temp-pos)
15825 (insert "\n") (indent-to vhdl-basic-offset)
15826 (insert "-- outputs of \"" inst-name "\"\n")
15827 (vhdl-goto-marker signal-pos))
15828 (setq inst-alist (cdr inst-alist)))
15829 ;; finalize generic/port clause
15830 (vhdl-goto-marker generic-end-pos) (backward-char)
15831 (when (= generic-beg-pos generic-end-pos)
15832 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15833 (insert ";") (backward-char))
15834 (insert ")")
15835 (vhdl-goto-marker port-end-pos) (backward-char)
15836 (when (= port-beg-pos port-end-pos)
15837 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15838 (insert ";") (backward-char))
15839 (insert ")")
15840 ;; align everything
15841 (when vhdl-auto-align
15842 (vhdl-goto-marker generic-beg-pos)
15843 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15844 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15845 (vhdl-goto-marker signal-beg-pos)
15846 (vhdl-align-region-groups signal-beg-pos signal-pos))
15847 (switch-to-buffer (marker-buffer signal-beg-pos))
15848 (message "Wiring components...done")))))
15849
15850(defun vhdl-compose-insert-generic (entry)
15851 "Insert ENTRY as generic declaration."
15852 (let (pos)
15853 (indent-to (* 2 vhdl-basic-offset))
15854 (insert (nth 0 entry) " : " (nth 1 entry))
15855 (when (nth 2 entry)
15856 (insert " := " (nth 2 entry)))
15857 (insert ";")
15858 (setq pos (point-marker))
15859 (when (and vhdl-include-port-comments (nth 3 entry))
15860 (vhdl-comment-insert-inline (nth 3 entry) t))
15861 (insert "\n")
15862 pos))
15863
15864(defun vhdl-compose-insert-port (entry)
15865 "Insert ENTRY as port declaration."
15866 (let (pos)
15867 (indent-to (* 2 vhdl-basic-offset))
15868 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15869 (setq pos (point-marker))
15870 (when (and vhdl-include-port-comments (nth 4 entry))
15871 (vhdl-comment-insert-inline (nth 4 entry) t))
15872 (insert "\n")
15873 pos))
15874
15875(defun vhdl-compose-insert-signal (entry)
15876 "Insert ENTRY as signal declaration."
15877 (indent-to vhdl-basic-offset)
15878 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15879 (when (and vhdl-include-port-comments (nth 4 entry))
15880 (vhdl-comment-insert-inline (nth 4 entry) t))
15881 (insert "\n"))
15882
15883(defun vhdl-compose-components-package ()
15884 "Generate a package containing component declarations for all entities in the
15885current project/directory."
15886 (interactive)
15887 (vhdl-require-hierarchy-info)
15888 (let* ((project (vhdl-project-p))
15889 (pack-name (vhdl-get-components-package-name))
15890 (pack-file-name
0a2e512a 15891 (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
3dcb36b7
JB
15892 "." (file-name-extension (buffer-file-name))))
15893 (ent-alist (aget vhdl-entity-alist
15894 (or project default-directory) t))
15895 (lazy-lock-minimum-size 0)
15896 clause-pos component-pos)
15897 (message "Generating components package \"%s\"..." pack-name)
15898 ;; open package file
15899 (when (and (file-exists-p pack-file-name)
15900 (not (y-or-n-p (concat "File \"" pack-file-name
15901 "\" exists; overwrite? "))))
15902 (error "ERROR: Generating components package...aborted"))
15903 (find-file pack-file-name)
15904 (erase-buffer)
15905 ;; insert header
15906 (if vhdl-compose-include-header
15907 (progn (vhdl-template-header
15908 (concat "Components package (generated by Emacs VHDL Mode "
15909 vhdl-version ")"))
15910 (goto-char (point-max)))
15911 (vhdl-comment-display-line) (insert "\n\n"))
15912 ;; insert std_logic_1164 package
15913 (vhdl-template-package-std-logic-1164)
15914 (insert "\n") (setq clause-pos (point-marker))
15915 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15916 ;; insert package declaration
15917 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15918 (vhdl-insert-keyword " IS\n\n")
15919 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15920 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15921 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15922 (indent-to vhdl-basic-offset)
15923 (setq component-pos (point-marker))
15924 (insert "\n\n") (vhdl-insert-keyword "END ")
15925 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15926 (insert pack-name ";\n\n")
15927 ;; insert footer
15928 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15929 (vhdl-template-footer)
15930 (vhdl-comment-display-line) (insert "\n"))
15931 ;; insert component declarations
15932 (while ent-alist
15933 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15934 (progn (goto-line (nth 3 (car ent-alist)))
15935 (end-of-line)
15936 (vhdl-port-copy)))
15937 (goto-char component-pos)
15938 (vhdl-port-paste-component t)
15939 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15940 (setq component-pos (point-marker))
15941 (goto-char clause-pos)
15942 (vhdl-port-paste-context-clause pack-name)
15943 (setq clause-pos (point-marker))
15944 (setq ent-alist (cdr ent-alist)))
15945 (goto-char (point-min))
15946 (save-buffer)
15947 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15948 pack-name pack-file-name)))
15949
0a2e512a
RF
15950(defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
15951 &optional insert-conf)
15952 "Generate block configuration for architecture."
15953 (let ((margin (current-indentation))
15954 (beg (save-excursion (beginning-of-line) (point)))
15955 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
15956 ;; insert block configuration (for architecture)
15957 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
15958 (setq margin (+ margin vhdl-basic-offset))
15959 ;; process all instances
15960 (while inst-alist
15961 (setq inst-entry (car inst-alist))
15962 ;; is component?
15963 (when (nth 4 inst-entry)
15964 (setq insert-conf t)
15965 (setq inst-path (nth 9 inst-entry))
15966 ;; skip common path with previous instance
15967 (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
15968 (setq inst-path (cdr inst-path)
15969 inst-prev-path (cdr inst-prev-path)))
15970 ;; insert block configuration end (for previous block/generate)
15971 (while inst-prev-path
15972 (setq margin (- margin vhdl-basic-offset))
15973 (indent-to margin)
15974 (vhdl-insert-keyword "END FOR;\n")
15975 (setq inst-prev-path (cdr inst-prev-path)))
15976 ;; insert block configuration beginning (for current block/generate)
15977 (indent-to margin)
15978 (while inst-path
15979 (setq margin (+ margin vhdl-basic-offset))
15980 (vhdl-insert-keyword "FOR ")
15981 (insert (car inst-path) "\n")
15982 (indent-to margin)
15983 (setq inst-path (cdr inst-path)))
15984 ;; insert component configuration beginning
15985 (vhdl-insert-keyword "FOR ")
15986 (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
15987 ;; find subconfiguration
15988 (setq conf-key (nth 7 inst-entry))
15989 (setq tmp-alist conf-alist)
15990 ;; use first configuration found for instance's entity
15991 (while (and tmp-alist (null conf-key))
15992 (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
15993 (setq conf-key (nth 0 (car tmp-alist))))
15994 (setq tmp-alist (cdr tmp-alist)))
15995 (setq conf-entry (aget conf-alist conf-key t))
15996 ;; insert binding indication ...
15997 ;; ... with subconfiguration (if exists)
15998 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
15999 (progn
16000 (indent-to (+ margin vhdl-basic-offset))
16001 (vhdl-insert-keyword "USE CONFIGURATION ")
16002 (insert (vhdl-work-library) "." (nth 0 conf-entry))
16003 (insert ";\n"))
16004 ;; ... with entity (if exists)
16005 (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
16006 (when ent-entry
16007 (indent-to (+ margin vhdl-basic-offset))
16008 (vhdl-insert-keyword "USE ENTITY ")
16009 (insert (vhdl-work-library) "." (nth 0 ent-entry))
16010 ;; insert architecture name (if architecture exists)
16011 (when (nth 3 ent-entry)
16012 (setq arch-name
16013 ;; choose architecture name a) from configuration,
16014 ;; b) from mra, or c) from first architecture
16015 (or (nth 0 (aget (nth 3 ent-entry)
16016 (or (nth 6 inst-entry)
16017 (nth 4 ent-entry)) t))
16018 (nth 1 (car (nth 3 ent-entry)))))
16019 (insert "(" arch-name ")"))
16020 (insert ";\n")
16021 ;; insert block configuration (for architecture of subcomponent)
16022 (when (and vhdl-compose-configuration-hierarchical
16023 (nth 3 ent-entry))
16024 (indent-to (+ margin vhdl-basic-offset))
16025 (vhdl-compose-configuration-architecture
16026 (nth 0 ent-entry) arch-name
16027 (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
16028 ;; insert component configuration end
16029 (indent-to margin)
16030 (vhdl-insert-keyword "END FOR;\n")
16031 (setq inst-prev-path (nth 9 inst-entry)))
16032 (setq inst-alist (cdr inst-alist)))
16033 ;; insert block configuration end (for block/generate)
16034 (while inst-prev-path
16035 (setq margin (- margin vhdl-basic-offset))
16036 (indent-to margin)
16037 (vhdl-insert-keyword "END FOR;\n")
16038 (setq inst-prev-path (cdr inst-prev-path)))
16039 (indent-to (- margin vhdl-basic-offset))
16040 ;; insert block configuration end or remove beginning (for architecture)
16041 (if insert-conf
16042 (vhdl-insert-keyword "END FOR;\n")
16043 (delete-region beg (point)))))
16044
16045(defun vhdl-compose-configuration (&optional ent-name arch-name)
16046 "Generate configuration declaration."
16047 (interactive)
16048 (vhdl-require-hierarchy-info)
16049 (let ((ent-alist (aget vhdl-entity-alist
16050 (or (vhdl-project-p) default-directory) t))
16051 (conf-alist (aget vhdl-config-alist
16052 (or (vhdl-project-p) default-directory) t))
16053 (from-speedbar ent-name)
16054 inst-alist conf-name conf-file-name pos)
16055 (vhdl-prepare-search-2
16056 ;; get entity and architecture name
16057 (unless ent-name
16058 (save-excursion
16059 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
16060 (not (equal "END" (upcase (match-string 1))))
16061 (setq ent-name (match-string-no-properties 3))
16062 (setq arch-name (match-string-no-properties 2)))
16063 (error "ERROR: Not within an architecture"))))
16064 (setq conf-name (vhdl-replace-string
16065 vhdl-compose-configuration-name
16066 (concat ent-name " " arch-name)))
16067 (setq inst-alist
16068 (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
16069 (downcase arch-name) t))))
16070 (message "Generating configuration \"%s\"..." conf-name)
16071 (if vhdl-compose-configuration-create-file
16072 ;; open configuration file
16073 (progn
16074 (setq conf-file-name
16075 (concat (vhdl-replace-string vhdl-configuration-file-name
16076 conf-name t)
16077 "." (file-name-extension (buffer-file-name))))
16078 (when (and (file-exists-p conf-file-name)
16079 (not (y-or-n-p (concat "File \"" conf-file-name
16080 "\" exists; overwrite? "))))
16081 (error "ERROR: Creating configuration...aborted"))
16082 (find-file conf-file-name)
16083 (erase-buffer)
16084 (set-buffer-modified-p nil)
16085 ;; insert header
16086 (if vhdl-compose-include-header
16087 (progn (vhdl-template-header
16088 (concat "Configuration declaration for design \""
16089 ent-name "(" arch-name ")\""))
16090 (goto-char (point-max)))
16091 (vhdl-comment-display-line) (insert "\n\n")))
16092 ;; goto end of architecture
16093 (unless from-speedbar
16094 (re-search-forward "^end\\>" nil)
16095 (end-of-line) (insert "\n\n")
16096 (vhdl-comment-display-line) (insert "\n\n")))
16097 ;; insert library clause
16098 (setq pos (point))
16099 (vhdl-template-standard-package (vhdl-work-library) nil)
16100 (when (/= pos (point))
16101 (insert "\n\n"))
16102 ;; insert configuration
16103 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
16104 (vhdl-insert-keyword " OF ") (insert ent-name)
16105 (vhdl-insert-keyword " IS\n")
16106 (indent-to vhdl-basic-offset)
16107 ;; insert block configuration (for architecture)
16108 (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
16109 (vhdl-insert-keyword "END ") (insert conf-name ";")
16110 (when conf-file-name
16111 ;; insert footer and save
16112 (insert "\n\n")
16113 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
16114 (vhdl-template-footer)
16115 (vhdl-comment-display-line) (insert "\n"))
16116 (save-buffer))
29a4e67d 16117 (message "%s"
0a2e512a
RF
16118 (concat (format "Generating configuration \"%s\"...done" conf-name)
16119 (and conf-file-name
16120 (format "\n File created: \"%s\"" conf-file-name))))))
16121
3dcb36b7
JB
16122
16123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16124;;; Compilation / Makefile generation
16125;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16126;; (using `compile.el')
16127
16128(defun vhdl-makefile-name ()
16129 "Return the Makefile name of the current project or the current compiler if
16130no project is defined."
16131 (let ((project-alist (aget vhdl-project-alist vhdl-project))
16132 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
16133 (vhdl-replace-string
16134 (cons "\\(.*\\)\n\\(.*\\)"
16135 (or (nth 8 project-alist) (nth 8 compiler-alist)))
16136 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
16137
16138(defun vhdl-compile-directory ()
16139 "Return the directory where compilation/make should be run."
16140 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
16141 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16142 (directory (vhdl-resolve-env-variable
16143 (if project
16144 (vhdl-replace-string
16145 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
16146 (nth 6 compiler)))))
16147 (file-name-as-directory
16148 (if (file-name-absolute-p directory)
16149 directory
16150 (expand-file-name directory (vhdl-default-directory))))))
16151
16152(defun vhdl-uniquify (in-list)
16153 "Remove duplicate elements from IN-LIST."
16154 (let (out-list)
16155 (while in-list
16156 (add-to-list 'out-list (car in-list))
16157 (setq in-list (cdr in-list)))
16158 out-list))
16159
16160(defun vhdl-set-compiler (name)
16161 "Set current compiler to NAME."
16162 (interactive
16163 (list (let ((completion-ignore-case t))
16164 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
16165 (if (assoc name vhdl-compiler-alist)
16166 (progn (setq vhdl-compiler name)
16167 (message "Current compiler: \"%s\"" vhdl-compiler))
16168 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
16169
16170;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16171;; Compilation
16172
16173(defun vhdl-compile-init ()
16174 "Initialize for compilation."
16175 (when (or (null compilation-error-regexp-alist)
16176 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
16177 compilation-error-regexp-alist)))
16178 ;; `compilation-error-regexp-alist'
16179 (let ((commands-alist vhdl-compiler-alist)
16180 regexp-alist sublist)
16181 (while commands-alist
16182 (setq sublist (nth 11 (car commands-alist)))
16183 (unless (or (equal "" (car sublist))
16184 (assoc (car sublist) regexp-alist))
16185 (setq regexp-alist (cons (list (nth 0 sublist)
16186 (if (= 0 (nth 1 sublist))
16187 (if vhdl-xemacs 9 nil)
16188 (nth 1 sublist))
16189 (nth 2 sublist) (nth 3 sublist))
16190 regexp-alist)))
16191 (setq commands-alist (cdr commands-alist)))
16192 (setq compilation-error-regexp-alist
16193 (append compilation-error-regexp-alist (nreverse regexp-alist))))
16194 ;; `compilation-file-regexp-alist'
16195 (let ((commands-alist vhdl-compiler-alist)
16196 regexp-alist sublist)
16197 ;; matches vhdl-mode file name output
16198 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
16199 (while commands-alist
16200 (setq sublist (nth 12 (car commands-alist)))
16201 (unless (or (equal "" (car sublist))
16202 (assoc (car sublist) regexp-alist))
16203 (setq regexp-alist (cons sublist regexp-alist)))
16204 (setq commands-alist (cdr commands-alist)))
16205 (setq compilation-file-regexp-alist
16206 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
16207
16208(defvar vhdl-compile-file-name nil
16209 "Name of file to be compiled.")
16210
16211(defun vhdl-compile-print-file-name ()
16212 "Function called within `compile' to print out file name for compilers that
16213do not print any file names."
16214 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
16215
16216(defun vhdl-get-compile-options (project compiler file-name
16217 &optional file-options-only)
16218 "Get compiler options. Returning nil means do not compile this file."
16219 (let* ((compiler-options (nth 1 compiler))
16220 (project-entry (aget (nth 4 project) vhdl-compiler))
16221 (project-options (nth 0 project-entry))
16222 (exception-list (and file-name (nth 2 project-entry)))
16223 (work-library (vhdl-work-library))
16224 (case-fold-search nil)
16225 file-options)
16226 (while (and exception-list
16227 (not (string-match (caar exception-list) file-name)))
16228 (setq exception-list (cdr exception-list)))
16229 (if (and exception-list (not (cdar exception-list)))
16230 nil
16231 (if (and file-options-only (not exception-list))
16232 'default
16233 (setq file-options (cdar exception-list))
16234 ;; insert library name in compiler-specific options
16235 (setq compiler-options
16236 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
16237 work-library))
16238 ;; insert compiler-specific options in project-specific options
16239 (when project-options
16240 (setq project-options
16241 (vhdl-replace-string
16242 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16243 (concat work-library "\n" compiler-options))))
16244 ;; insert project-specific options in file-specific options
16245 (when file-options
16246 (setq file-options
16247 (vhdl-replace-string
16248 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
16249 (concat work-library "\n" compiler-options "\n"
16250 project-options))))
16251 ;; return options
16252 (or file-options project-options compiler-options)))))
16253
16254(defun vhdl-get-make-options (project compiler)
16255 "Get make options."
16256 (let* ((compiler-options (nth 3 compiler))
16257 (project-entry (aget (nth 4 project) vhdl-compiler))
16258 (project-options (nth 1 project-entry))
16259 (makefile-name (vhdl-makefile-name)))
16260 ;; insert Makefile name in compiler-specific options
16261 (setq compiler-options
16262 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
16263 makefile-name))
16264 ;; insert compiler-specific options in project-specific options
16265 (when project-options
16266 (setq project-options
16267 (vhdl-replace-string
16268 (cons "\\(.*\\)\n\\(.*\\)" project-options)
16269 (concat makefile-name "\n" compiler-options))))
16270 ;; return options
16271 (or project-options compiler-options)))
16272
16273(defun vhdl-compile ()
16274 "Compile current buffer using the VHDL compiler specified in
16275`vhdl-compiler'."
16276 (interactive)
16277 (vhdl-compile-init)
16278 (let* ((project (aget vhdl-project-alist vhdl-project))
16279 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
16280 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16281 (command (nth 0 compiler))
16282 (file-name (buffer-file-name))
16283 (options (vhdl-get-compile-options project compiler file-name))
16284 (default-directory (vhdl-compile-directory))
16285 compilation-process-setup-function)
16286 (unless (file-directory-p default-directory)
16287 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16288 ;; put file name into quotes if it contains spaces
16289 (when (string-match " " file-name)
16290 (setq file-name (concat "\"" file-name "\"")))
16291 ;; print out file name if compiler does not
16292 (setq vhdl-compile-file-name (buffer-file-name))
16293 (when (and (= 0 (nth 1 (nth 10 compiler)))
16294 (= 0 (nth 1 (nth 11 compiler))))
16295 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
16296 ;; run compilation
16297 (if options
16298 (when command
16299 (compile (concat command " " options " " file-name)))
16300 (vhdl-warning "Your project settings tell me not to compile this file"))))
16301
0a2e512a
RF
16302(defvar vhdl-make-target "all"
16303 "Default target for `vhdl-make' command.")
16304
3dcb36b7
JB
16305(defun vhdl-make (&optional target)
16306 "Call make command for compilation of all updated source files (requires
16307`Makefile'). Optional argument TARGET allows to compile the design
16308specified by a target."
16309 (interactive)
0a2e512a
RF
16310 (setq vhdl-make-target
16311 (or target (read-from-minibuffer "Target: " vhdl-make-target
16312 vhdl-minibuffer-local-map)))
3dcb36b7
JB
16313 (vhdl-compile-init)
16314 (let* ((project (aget vhdl-project-alist vhdl-project))
16315 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16316 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16317 (command (nth 2 compiler))
16318 (options (vhdl-get-make-options project compiler))
16319 (default-directory (vhdl-compile-directory)))
16320 (unless (file-directory-p default-directory)
16321 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
16322 ;; run make
16323 (compile (concat (if (equal command "") "make" command)
0a2e512a 16324 " " options " " vhdl-make-target))))
3dcb36b7
JB
16325
16326;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16327;; Makefile generation
16328
16329(defun vhdl-generate-makefile ()
16330 "Generate `Makefile'."
16331 (interactive)
16332 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
16333 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
16334 (command (nth 4 compiler)))
16335 ;; generate makefile
16336 (if command
16337 (let ((default-directory (vhdl-compile-directory)))
16338 (compile (vhdl-replace-string
16339 (cons "\\(.*\\) \\(.*\\)" command)
16340 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16341 (vhdl-generate-makefile-1))))
16342
16343(defun vhdl-get-packages (lib-alist work-library)
16344 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16345 (let (pack-list)
16346 (while lib-alist
16347 (when (equal (downcase (caar lib-alist)) (downcase work-library))
16348 (setq pack-list (cons (cdar lib-alist) pack-list)))
16349 (setq lib-alist (cdr lib-alist)))
16350 pack-list))
16351
16352(defun vhdl-generate-makefile-1 ()
16353 "Generate Makefile for current project or directory."
16354 ;; scan hierarchy if required
16355 (if (vhdl-project-p)
16356 (unless (or (assoc vhdl-project vhdl-file-alist)
16357 (vhdl-load-cache vhdl-project))
16358 (vhdl-scan-project-contents vhdl-project))
16359 (let ((directory (abbreviate-file-name default-directory)))
16360 (unless (or (assoc directory vhdl-file-alist)
16361 (vhdl-load-cache directory))
16362 (vhdl-scan-directory-contents directory))))
16363 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16364 (project (vhdl-project-p))
16365 (ent-alist (aget vhdl-entity-alist (or project directory) t))
16366 (conf-alist (aget vhdl-config-alist (or project directory) t))
16367 (pack-alist (aget vhdl-package-alist (or project directory) t))
16368 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
16369 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
16370 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
16371 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
16372 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
16373 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
16374 (adjust-case (nth 5 regexp-list))
16375 (work-library (downcase (vhdl-work-library)))
16376 (compile-directory (expand-file-name (vhdl-compile-directory)
16377 default-directory))
16378 (makefile-name (vhdl-makefile-name))
16379 rule-alist arch-alist inst-alist
16380 target-list depend-list unit-list prim-list second-list subcomp-list
16381 lib-alist lib-body-alist pack-list all-pack-list
16382 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16383 conf-key conf-file-name pack-key pack-file-name
16384 ent-entry arch-entry conf-entry pack-entry inst-entry
16385 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16386 tmp-key tmp-list rule)
16387 ;; check prerequisites
16388 (unless (file-exists-p compile-directory)
16389 (make-directory compile-directory t))
16390 (unless regexp-list
16391 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16392 vhdl-compiler))
16393 (message "Generating makefile \"%s\"..." makefile-name)
16394 ;; rules for all entities
16395 (setq tmp-list ent-alist)
16396 (while ent-alist
16397 (setq ent-entry (car ent-alist)
16398 ent-key (nth 0 ent-entry))
16399 (when (nth 2 ent-entry)
16400 (setq ent-file-name (file-relative-name
16401 (nth 2 ent-entry) compile-directory)
16402 arch-alist (nth 4 ent-entry)
0a2e512a 16403 lib-alist (nth 6 ent-entry)
3dcb36b7
JB
16404 rule (aget rule-alist ent-file-name)
16405 target-list (nth 0 rule)
16406 depend-list (nth 1 rule)
16407 second-list nil
16408 subcomp-list nil)
16409 (setq tmp-key (vhdl-replace-string
16410 ent-regexp (funcall adjust-case ent-key)))
16411 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
16412 ;; rule target for this entity
16413 (setq target-list (cons ent-key target-list))
16414 ;; rule dependencies for all used packages
16415 (setq pack-list (vhdl-get-packages lib-alist work-library))
16416 (setq depend-list (append depend-list pack-list))
16417 (setq all-pack-list pack-list)
16418 ;; add rule
16419 (aput 'rule-alist ent-file-name (list target-list depend-list))
16420 ;; rules for all corresponding architectures
16421 (while arch-alist
16422 (setq arch-entry (car arch-alist)
16423 arch-key (nth 0 arch-entry)
16424 ent-arch-key (concat ent-key "-" arch-key)
16425 arch-file-name (file-relative-name (nth 2 arch-entry)
16426 compile-directory)
16427 inst-alist (nth 4 arch-entry)
16428 lib-alist (nth 5 arch-entry)
16429 rule (aget rule-alist arch-file-name)
16430 target-list (nth 0 rule)
16431 depend-list (nth 1 rule))
16432 (setq tmp-key (vhdl-replace-string
16433 arch-regexp
16434 (funcall adjust-case (concat arch-key " " ent-key))))
16435 (setq unit-list
16436 (cons (cons ent-arch-key tmp-key) unit-list))
16437 (setq second-list (cons ent-arch-key second-list))
16438 ;; rule target for this architecture
16439 (setq target-list (cons ent-arch-key target-list))
16440 ;; rule dependency for corresponding entity
16441 (setq depend-list (cons ent-key depend-list))
16442 ;; rule dependencies for contained component instantiations
16443 (while inst-alist
16444 (setq inst-entry (car inst-alist))
16445 (when (or (null (nth 8 inst-entry))
16446 (equal (downcase (nth 8 inst-entry)) work-library))
16447 (setq inst-ent-key (or (nth 7 inst-entry)
16448 (nth 5 inst-entry)))
16449 (setq depend-list (cons inst-ent-key depend-list)
16450 subcomp-list (cons inst-ent-key subcomp-list)))
16451 (setq inst-alist (cdr inst-alist)))
16452 ;; rule dependencies for all used packages
16453 (setq pack-list (vhdl-get-packages lib-alist work-library))
16454 (setq depend-list (append depend-list pack-list))
16455 (setq all-pack-list (append all-pack-list pack-list))
16456 ;; add rule
16457 (aput 'rule-alist arch-file-name (list target-list depend-list))
16458 (setq arch-alist (cdr arch-alist)))
16459 (setq prim-list (cons (list ent-key second-list
16460 (append subcomp-list all-pack-list))
16461 prim-list)))
16462 (setq ent-alist (cdr ent-alist)))
16463 (setq ent-alist tmp-list)
16464 ;; rules for all configurations
16465 (setq tmp-list conf-alist)
16466 (while conf-alist
16467 (setq conf-entry (car conf-alist)
16468 conf-key (nth 0 conf-entry)
16469 conf-file-name (file-relative-name
16470 (nth 2 conf-entry) compile-directory)
16471 ent-key (nth 4 conf-entry)
16472 arch-key (nth 5 conf-entry)
16473 inst-alist (nth 6 conf-entry)
16474 lib-alist (nth 7 conf-entry)
16475 rule (aget rule-alist conf-file-name)
16476 target-list (nth 0 rule)
16477 depend-list (nth 1 rule)
16478 subcomp-list (list ent-key))
16479 (setq tmp-key (vhdl-replace-string
16480 conf-regexp (funcall adjust-case conf-key)))
16481 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16482 ;; rule target for this configuration
16483 (setq target-list (cons conf-key target-list))
16484 ;; rule dependency for corresponding entity and architecture
16485 (setq depend-list
16486 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16487 ;; rule dependencies for used packages
16488 (setq pack-list (vhdl-get-packages lib-alist work-library))
16489 (setq depend-list (append depend-list pack-list))
16490 ;; rule dependencies for contained component configurations
16491 (while inst-alist
16492 (setq inst-entry (car inst-alist))
16493 (setq inst-ent-key (nth 2 inst-entry)
16494; comp-arch-key (nth 2 inst-entry))
16495 inst-conf-key (nth 4 inst-entry))
16496 (when (equal (downcase (nth 5 inst-entry)) work-library)
16497 (when inst-ent-key
16498 (setq depend-list (cons inst-ent-key depend-list)
16499 subcomp-list (cons inst-ent-key subcomp-list)))
16500; (when comp-arch-key
16501; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16502; depend-list)))
16503 (when inst-conf-key
16504 (setq depend-list (cons inst-conf-key depend-list)
16505 subcomp-list (cons inst-conf-key subcomp-list))))
16506 (setq inst-alist (cdr inst-alist)))
16507 ;; add rule
16508 (aput 'rule-alist conf-file-name (list target-list depend-list))
16509 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16510 prim-list))
16511 (setq conf-alist (cdr conf-alist)))
16512 (setq conf-alist tmp-list)
16513 ;; rules for all packages
16514 (setq tmp-list pack-alist)
16515 (while pack-alist
16516 (setq pack-entry (car pack-alist)
16517 pack-key (nth 0 pack-entry)
16518 pack-body-key nil)
16519 (when (nth 2 pack-entry)
16520 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16521 compile-directory)
16522 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16523 rule (aget rule-alist pack-file-name)
16524 target-list (nth 0 rule) depend-list (nth 1 rule))
16525 (setq tmp-key (vhdl-replace-string
16526 pack-regexp (funcall adjust-case pack-key)))
16527 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16528 ;; rule target for this package
16529 (setq target-list (cons pack-key target-list))
16530 ;; rule dependencies for all used packages
16531 (setq pack-list (vhdl-get-packages lib-alist work-library))
16532 (setq depend-list (append depend-list pack-list))
16533 (setq all-pack-list pack-list)
16534 ;; add rule
16535 (aput 'rule-alist pack-file-name (list target-list depend-list))
16536 ;; rules for this package's body
16537 (when (nth 7 pack-entry)
16538 (setq pack-body-key (concat pack-key "-body")
16539 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16540 compile-directory)
16541 rule (aget rule-alist pack-body-file-name)
16542 target-list (nth 0 rule)
16543 depend-list (nth 1 rule))
16544 (setq tmp-key (vhdl-replace-string
16545 pack-body-regexp (funcall adjust-case pack-key)))
16546 (setq unit-list
16547 (cons (cons pack-body-key tmp-key) unit-list))
16548 ;; rule target for this package's body
16549 (setq target-list (cons pack-body-key target-list))
16550 ;; rule dependency for corresponding package declaration
16551 (setq depend-list (cons pack-key depend-list))
16552 ;; rule dependencies for all used packages
16553 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16554 (setq depend-list (append depend-list pack-list))
16555 (setq all-pack-list (append all-pack-list pack-list))
16556 ;; add rule
16557 (aput 'rule-alist pack-body-file-name
16558 (list target-list depend-list)))
16559 (setq prim-list
16560 (cons (list pack-key (when pack-body-key (list pack-body-key))
16561 all-pack-list)
16562 prim-list)))
16563 (setq pack-alist (cdr pack-alist)))
16564 (setq pack-alist tmp-list)
16565 ;; generate Makefile
16566 (let* ((project (aget vhdl-project-alist project))
16567 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16568 (compiler-id (nth 9 compiler))
16569 (library-directory
16570 (vhdl-resolve-env-variable
16571 (vhdl-replace-string
16572 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16573 compiler-id)))
16574 (makefile-path-name (expand-file-name
16575 makefile-name compile-directory))
16576 (orig-buffer (current-buffer))
16577 cell second-list subcomp-list options unit-key unit-name)
16578 ;; sort lists
16579 (setq unit-list (vhdl-sort-alist unit-list))
16580 (setq prim-list (vhdl-sort-alist prim-list))
16581 (setq tmp-list rule-alist)
16582 (while tmp-list ; pre-sort rule targets
16583 (setq cell (cdar tmp-list))
16584 (setcar cell (sort (car cell) 'string<))
16585 (setq tmp-list (cdr tmp-list)))
16586 (setq rule-alist ; sort by first rule target
16587 (sort rule-alist
16588 (function (lambda (a b)
16589 (string< (car (cadr a)) (car (cadr b)))))))
16590 ;; open and clear Makefile
16591 (set-buffer (find-file-noselect makefile-path-name t t))
16592 (erase-buffer)
16593 (insert "# -*- Makefile -*-\n"
16594 "### " (file-name-nondirectory makefile-name)
16595 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16596 "\n")
16597 (if project
16598 (insert "\n# Project : " (nth 0 project))
16599 (insert "\n# Directory : \"" directory "\""))
16600 (insert "\n# Platform : " vhdl-compiler
16601 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16602 (user-login-name) "\n")
16603 ;; insert compile and option variable settings
16604 (insert "\n\n# Define compilation command and options\n"
16605 "\nCOMPILE = " (nth 0 compiler)
16606 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16607 "\n")
16608 ;; insert library paths
16609 (setq library-directory
16610 (directory-file-name
16611 (if (file-name-absolute-p library-directory)
16612 library-directory
16613 (file-relative-name
16614 (expand-file-name library-directory directory)
16615 compile-directory))))
16616 (insert "\n\n# Define library paths\n"
16617 "\nLIBRARY-" work-library " = " library-directory "\n")
16618 ;; insert variable definitions for all library unit files
16619 (insert "\n\n# Define library unit files\n")
16620 (setq tmp-list unit-list)
16621 (while unit-list
16622 (insert "\nUNIT-" work-library "-" (caar unit-list)
16623 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16624 (setq unit-list (cdr unit-list)))
16625 ;; insert variable definition for list of all library unit files
16626 (insert "\n\n\n# Define list of all library unit files\n"
16627 "\nALL_UNITS =")
16628 (setq unit-list tmp-list)
16629 (while unit-list
16630 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16631 (setq unit-list (cdr unit-list)))
16632 (insert "\n")
16633 (setq unit-list tmp-list)
16634 ;; insert `make all' rule
16635 (insert "\n\n\n# Rule for compiling entire design\n"
16636 "\nall :"
16637 " \\\n\t\tlibrary"
16638 " \\\n\t\t$(ALL_UNITS)\n")
16639 ;; insert `make clean' rule
16640 (insert "\n\n# Rule for cleaning entire design\n"
16641 "\nclean : "
16642 "\n\t-rm -f $(ALL_UNITS)\n")
16643 ;; insert `make library' rule
16644 (insert "\n\n# Rule for creating library directory\n"
16645 "\nlibrary :"
16646 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16647 "\n$(LIBRARY-" work-library ") :"
16648 "\n\t"
16649 (vhdl-replace-string
16650 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16651 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16652 "\n")
16653 ;; insert rule for each library unit
16654 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16655 (while prim-list
16656 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16657 (setq subcomp-list
16658 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16659 (setq unit-key (caar prim-list)
16660 unit-name (or (nth 0 (aget ent-alist unit-key t))
16661 (nth 0 (aget conf-alist unit-key t))
16662 (nth 0 (aget pack-alist unit-key t))))
16663 (insert "\n" unit-key)
16664 (unless (equal unit-key unit-name)
16665 (insert " \\\n" unit-name))
16666 (insert " :"
16667 " \\\n\t\tlibrary"
16668 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16669 (while second-list
16670 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16671 (setq second-list (cdr second-list)))
16672 (while subcomp-list
0a2e512a
RF
16673 (when (and (assoc (car subcomp-list) unit-list)
16674 (not (equal unit-key (car subcomp-list))))
3dcb36b7
JB
16675 (insert " \\\n\t\t" (car subcomp-list)))
16676 (setq subcomp-list (cdr subcomp-list)))
16677 (insert "\n")
16678 (setq prim-list (cdr prim-list)))
16679 ;; insert rule for each library unit file
16680 (insert "\n\n# Rules for compiling single library unit files\n")
16681 (while rule-alist
16682 (setq rule (car rule-alist))
16683 ;; get compiler options for this file
16684 (setq options
16685 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16686 ;; insert rule if file is supposed to be compiled
16687 (setq target-list (nth 1 rule)
16688 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16689 ;; insert targets
16690 (setq tmp-list target-list)
16691 (while target-list
16692 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16693 (if (cdr target-list) " \\" " :"))
16694 (setq target-list (cdr target-list)))
16695 (setq target-list tmp-list)
16696 ;; insert file name as first dependency
16697 (insert " \\\n\t\t" (nth 0 rule))
16698 ;; insert dependencies (except if also target or unit does not exist)
16699 (while depend-list
16700 (when (and (not (member (car depend-list) target-list))
16701 (assoc (car depend-list) unit-list))
16702 (insert " \\\n\t\t"
16703 "$(UNIT-" work-library "-" (car depend-list) ")"))
16704 (setq depend-list (cdr depend-list)))
16705 ;; insert compile command
16706 (if options
16707 (insert "\n\t$(COMPILE) "
16708 (if (eq options 'default) "$(OPTIONS)" options) " "
16709 (nth 0 rule) "\n")
16710 (setq tmp-list target-list)
16711 (while target-list
16712 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16713 (if (cdr target-list) " \\" "\n"))
16714 (setq target-list (cdr target-list)))
16715 (setq target-list tmp-list))
16716 (setq rule-alist (cdr rule-alist)))
16717 (insert "\n\n### " makefile-name " ends here\n")
16718 ;; run Makefile generation hook
16719 (run-hooks 'vhdl-makefile-generation-hook)
16720 (message "Generating makefile \"%s\"...done" makefile-name)
16721 ;; save and close file
16722 (if (file-writable-p makefile-path-name)
16723 (progn (save-buffer)
16724 (kill-buffer (current-buffer))
16725 (set-buffer orig-buffer)
16726 (setq file-name-history
16727 (cons makefile-path-name file-name-history)))
16728 (vhdl-warning-when-idle
16729 (format "File not writable: \"%s\""
16730 (abbreviate-file-name makefile-path-name)))
16731 (switch-to-buffer (current-buffer))))))
16732
5eabfe72
KH
16733
16734;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16735;;; Bug reports
16736;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16737;; (using `reporter.el')
16738
3dcb36b7
JB
16739(defconst vhdl-mode-help-address
16740 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16741 "Address for VHDL Mode bug reports.")
16742
3dcb36b7
JB
16743(defun vhdl-submit-bug-report ()
16744 "Submit via mail a bug report on VHDL Mode."
16745 (interactive)
16746 ;; load in reporter
16747 (and
16748 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16749 (let ((reporter-prompt-for-summary-p t))
16750 (reporter-submit-bug-report
16751 vhdl-mode-help-address
16752 (concat "VHDL Mode " vhdl-version)
16753 (list
16754 ;; report all important user options
16755 'vhdl-offsets-alist
16756 'vhdl-comment-only-line-offset
16757 'tab-width
16758 'vhdl-electric-mode
16759 'vhdl-stutter-mode
16760 'vhdl-indent-tabs-mode
16761 'vhdl-project-alist
16762 'vhdl-project
16763 'vhdl-project-file-name
16764 'vhdl-project-auto-load
16765 'vhdl-project-sort
16766 'vhdl-compiler-alist
16767 'vhdl-compiler
16768 'vhdl-compile-use-local-error-regexp
16769 'vhdl-makefile-generation-hook
16770 'vhdl-default-library
16771 'vhdl-standard
16772 'vhdl-basic-offset
16773 'vhdl-upper-case-keywords
16774 'vhdl-upper-case-types
16775 'vhdl-upper-case-attributes
16776 'vhdl-upper-case-enum-values
16777 'vhdl-upper-case-constants
16778 'vhdl-use-direct-instantiation
0a2e512a 16779 'vhdl-compose-configuration-name
3dcb36b7
JB
16780 'vhdl-entity-file-name
16781 'vhdl-architecture-file-name
0a2e512a 16782 'vhdl-configuration-file-name
3dcb36b7
JB
16783 'vhdl-package-file-name
16784 'vhdl-file-name-case
16785 'vhdl-electric-keywords
16786 'vhdl-optional-labels
16787 'vhdl-insert-empty-lines
16788 'vhdl-argument-list-indent
16789 'vhdl-association-list-with-formals
16790 'vhdl-conditions-in-parenthesis
16791 'vhdl-zero-string
16792 'vhdl-one-string
16793 'vhdl-file-header
16794 'vhdl-file-footer
16795 'vhdl-company-name
16796 'vhdl-copyright-string
16797 'vhdl-platform-spec
16798 'vhdl-date-format
16799 'vhdl-modify-date-prefix-string
16800 'vhdl-modify-date-on-saving
16801 'vhdl-reset-kind
16802 'vhdl-reset-active-high
16803 'vhdl-clock-rising-edge
16804 'vhdl-clock-edge-condition
16805 'vhdl-clock-name
16806 'vhdl-reset-name
16807 'vhdl-model-alist
16808 'vhdl-include-port-comments
16809 'vhdl-include-direction-comments
16810 'vhdl-include-type-comments
16811 'vhdl-include-group-comments
16812 'vhdl-actual-port-name
16813 'vhdl-instance-name
16814 'vhdl-testbench-entity-name
16815 'vhdl-testbench-architecture-name
16816 'vhdl-testbench-configuration-name
16817 'vhdl-testbench-dut-name
16818 'vhdl-testbench-include-header
16819 'vhdl-testbench-declarations
16820 'vhdl-testbench-statements
16821 'vhdl-testbench-initialize-signals
16822 'vhdl-testbench-include-library
16823 'vhdl-testbench-include-configuration
16824 'vhdl-testbench-create-files
0a2e512a
RF
16825 'vhdl-testbench-entity-file-name
16826 'vhdl-testbench-architecture-file-name
3dcb36b7 16827 'vhdl-compose-create-files
0a2e512a
RF
16828 'vhdl-compose-configuration-create-file
16829 'vhdl-compose-configuration-hierarchical
16830 'vhdl-compose-configuration-use-subconfiguration
3dcb36b7
JB
16831 'vhdl-compose-include-header
16832 'vhdl-compose-architecture-name
16833 'vhdl-components-package-name
16834 'vhdl-use-components-package
16835 'vhdl-self-insert-comments
16836 'vhdl-prompt-for-comments
16837 'vhdl-inline-comment-column
16838 'vhdl-end-comment-column
16839 'vhdl-auto-align
16840 'vhdl-align-groups
16841 'vhdl-align-group-separate
16842 'vhdl-align-same-indent
16843 'vhdl-highlight-keywords
16844 'vhdl-highlight-names
16845 'vhdl-highlight-special-words
16846 'vhdl-highlight-forbidden-words
16847 'vhdl-highlight-verilog-keywords
16848 'vhdl-highlight-translate-off
16849 'vhdl-highlight-case-sensitive
16850 'vhdl-special-syntax-alist
16851 'vhdl-forbidden-words
16852 'vhdl-forbidden-syntax
16853 'vhdl-directive-keywords
16854 'vhdl-speedbar-auto-open
16855 'vhdl-speedbar-display-mode
16856 'vhdl-speedbar-scan-limit
16857 'vhdl-speedbar-jump-to-unit
16858 'vhdl-speedbar-update-on-saving
16859 'vhdl-speedbar-save-cache
16860 'vhdl-speedbar-cache-file-name
16861 'vhdl-index-menu
16862 'vhdl-source-file-menu
16863 'vhdl-hideshow-menu
16864 'vhdl-hide-all-init
16865 'vhdl-print-two-column
16866 'vhdl-print-customize-faces
16867 'vhdl-intelligent-tab
16868 'vhdl-indent-syntax-based
16869 'vhdl-word-completion-case-sensitive
16870 'vhdl-word-completion-in-minibuffer
16871 'vhdl-underscore-is-part-of-word
16872 'vhdl-mode-hook)
16873 (function
16874 (lambda ()
16875 (insert
16876 (if vhdl-special-indent-hook
16877 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16878 "vhdl-special-indent-hook is set to '"
16879 (format "%s" vhdl-special-indent-hook)
16880 ".\nPerhaps this is your problem?\n"
16881 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16882 "\n"))))
16883 nil
16884 "Hi Reto,"))))
16885
16886
16887;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16888;;; Documentation
16889;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16890
16891(defconst vhdl-doc-release-notes nil
16892 "\
0a2e512a 16893Release Notes for VHDL Mode 3.33
3dcb36b7
JB
16894================================
16895
16896 - New Features
3dcb36b7 16897 - User Options
3dcb36b7
JB
16898
16899
16900New Features
16901------------
16902
0a2e512a
RF
16903CONFIGURATION DECLARATION GENERATION:
16904 - Automatic generation of a configuration declaration for a design.
16905 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
3dcb36b7
JB
16906
16907
16908User Options
16909------------
16910
0a2e512a
RF
16911`vhdl-configuration-file-name': (new)
16912 Specify how the configuration file name is obtained.
16913`vhdl-compose-configuration-name': (new)
16914 Specify how the configuration name is optained.
16915`vhdl-compose-configuration-create-file': (new)
16916 Specify whether a new file should be created for a configuration.
16917`vhdl-compose-configuration-hierarchical': (new)
16918 Specify whether hierarchical configurations should be created.
16919`vhdl-compose-configuration-use-subconfiguration': (new)
16920 Specify whether subconfigurations should be used inside configurations.
3dcb36b7
JB
16921")
16922
16923
16924(defconst vhdl-doc-keywords nil
16925 "\
16926Reserved words in VHDL
16927----------------------
16928
16929VHDL'93 (IEEE Std 1076-1993):
16930 `vhdl-93-keywords' : keywords
16931 `vhdl-93-types' : standardized types
16932 `vhdl-93-attributes' : standardized attributes
16933 `vhdl-93-enum-values' : standardized enumeration values
16934 `vhdl-93-functions' : standardized functions
16935 `vhdl-93-packages' : standardized packages and libraries
16936
16937VHDL-AMS (IEEE Std 1076.1):
16938 `vhdl-ams-keywords' : keywords
16939 `vhdl-ams-types' : standardized types
16940 `vhdl-ams-attributes' : standardized attributes
16941 `vhdl-ams-enum-values' : standardized enumeration values
16942 `vhdl-ams-functions' : standardized functions
16943
16944Math Packages (IEEE Std 1076.2):
16945 `vhdl-math-types' : standardized types
16946 `vhdl-math-constants' : standardized constants
16947 `vhdl-math-functions' : standardized functions
16948 `vhdl-math-packages' : standardized packages
16949
16950Forbidden words:
16951 `vhdl-verilog-keywords' : Verilog reserved words
16952
16953NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16954
16955
16956(defconst vhdl-doc-coding-style nil
16957 "\
16958For VHDL coding style and naming convention guidelines, see the following
16959references:
16960
16961\[1] Ben Cohen.
16962 \"VHDL Coding Styles and Methodologies\".
16963 Kluwer Academic Publishers, 1999.
16964 http://members.aol.com/vhdlcohen/vhdl/
16965
16966\[2] Michael Keating and Pierre Bricaud.
16967 \"Reuse Methodology Manual, Second Edition\".
16968 Kluwer Academic Publishers, 1999.
16969 http://www.openmore.com/openmore/rmm2.html
16970
16971\[3] European Space Agency.
16972 \"VHDL Modelling Guidelines\".
16973 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16974
16975Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16976to visually support naming conventions.")
16977
16978
d2ddb974
KH
16979(defun vhdl-version ()
16980 "Echo the current version of VHDL Mode in the minibuffer."
16981 (interactive)
3dcb36b7 16982 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16983 (vhdl-keep-region-active))
16984
3dcb36b7
JB
16985(defun vhdl-doc-variable (variable)
16986 "Display VARIABLE's documentation in *Help* buffer."
16987 (interactive)
4bcb9c95
SM
16988 (unless vhdl-xemacs
16989 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
0a2e512a
RF
16990 (with-output-to-temp-buffer
16991 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7 16992 (princ (documentation-property variable 'variable-documentation))
4bcb9c95 16993 (with-current-buffer standard-output
3dcb36b7
JB
16994 (help-mode))
16995 (print-help-return-message)))
d2ddb974 16996
3dcb36b7
JB
16997(defun vhdl-doc-mode ()
16998 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 16999 (interactive)
4bcb9c95
SM
17000 (unless vhdl-xemacs
17001 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
0a2e512a
RF
17002 (with-output-to-temp-buffer
17003 (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7
JB
17004 (princ mode-name)
17005 (princ " mode:\n")
17006 (princ (documentation 'vhdl-mode))
4bcb9c95 17007 (with-current-buffer standard-output
3dcb36b7
JB
17008 (help-mode))
17009 (print-help-return-message)))
d2ddb974
KH
17010
17011
5eabfe72 17012;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
17013
17014(provide 'vhdl-mode)
17015
4bcb9c95 17016;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
d2ddb974 17017;;; vhdl-mode.el ends here