idlwave-complete-class-structure-tag-help): Follow error conventions.
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
CommitLineData
d2ddb974
KH
1;;; vhdl-mode.el --- major mode for editing VHDL code
2
2e8b9c7d 3;; Copyright (C) 1992-2003, 2005 Free Software Foundation, Inc.
3dcb36b7
JB
4
5;; Authors: Reto Zimmermann <reto@gnu.org>
6;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
7;; Maintainer: Reto Zimmermann <reto@gnu.org>
5eabfe72 8;; Keywords: languages vhdl
3dcb36b7
JB
9;; WWW: http://opensource.ethz.ch/emacs/vhdl-mode.html
10
11(defconst vhdl-version "3.32.12"
12 "VHDL Mode version number.")
13
14(defconst vhdl-time-stamp "2003-02-28"
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
31;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
32;; Boston, MA 02111-1307, USA.
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
JB
46;; - Port translation / testbench generation
47;; - Sensitivity list updating
48;; - File browser
49;; - Design hierarchy browser
d2ddb974 50;; - Source file compilation (syntax analysis)
3dcb36b7
JB
51;; - Makefile generation
52;; - Code hiding
53;; - Word/keyword completion
54;; - Block commenting
55;; - Code fixing/alignment/beautification
56;; - Postscript printing
5eabfe72 57;; - VHDL'87/'93 and VHDL-AMS supported
3dcb36b7 58;; - Comprehensive menu
5eabfe72 59;; - Fully customizable
3dcb36b7 60;; - Works under GNU Emacs (recommended) and XEmacs
5eabfe72
KH
61
62;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 63;; Documentation
d2ddb974 64
3dcb36b7 65;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
d2ddb974 66
5eabfe72 67;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 68;; Emacs Versions
3dcb36b7
JB
69
70;; supported: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X
71;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
72
5eabfe72 73;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
74;; Installation
75
76;; Prerequisites: GNU Emacs 20.X/21.X, XEmacs 20.X/21.X.
77
78;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
79;; or into an arbitrary directory that is added to the load path by the
80;; following line in your Emacs start-up file `.emacs':
81
82;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
d2ddb974 83
3dcb36b7
JB
84;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
85;; directory. Otherwise, byte-compile the source file:
86;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
87;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
88
89;; Add the following lines to the `site-start.el' file in the `site-lisp'
90;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
91;; (not required in Emacs 20.X):
92
93;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
94;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
95
96;; More detailed installation instructions are included in the official
97;; VHDL Mode distribution.
d2ddb974 98
5eabfe72 99;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 100;; Acknowledgements
d2ddb974
KH
101
102;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
5eabfe72 103;; and Steve Grout.
d2ddb974 104
5eabfe72 105;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
3dcb36b7 106;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
d2ddb974
KH
107
108;; Many thanks to all the users who sent me bug reports and enhancement
3dcb36b7
JB
109;; requests.
110;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
111;; enhancement suggestions and the fruitful discussions.
5eabfe72
KH
112;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
113;; Thanks to Ulf Klaperski for the indentation speedup hint.
114
115;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
116;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
117;; giving me the opportunity to develop this code.
118;; This work has been funded in part by MICROSWISS, a Microelectronics Program
119;; of the Swiss Government.
120
3dcb36b7 121;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
122
123;;; Code:
124
3dcb36b7
JB
125;; XEmacs handling
126(defconst vhdl-xemacs (string-match "XEmacs" emacs-version)
127 "Non-nil if XEmacs is used.")
128;; Emacs 21 handling
129(defconst vhdl-emacs-21 (and (= emacs-major-version 21) (not vhdl-xemacs))
f35aff82 130 "Non-nil if Emacs 21 is used.")
3dcb36b7
JB
131
132
5eabfe72
KH
133;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134;;; Variables
135;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 136
3dcb36b7 137;; help function for user options
5eabfe72
KH
138(defun vhdl-custom-set (variable value &rest functions)
139 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
140 (if (fboundp 'custom-set-default)
141 (custom-set-default variable value)
142 (set-default variable value))
143 (while functions
144 (when (fboundp (car functions)) (funcall (car functions)))
145 (setq functions (cdr functions))))
146
3dcb36b7
JB
147(defun vhdl-widget-directory-validate (widget)
148 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
149'/' or is empty)."
150 (let ((val (widget-value widget)))
151 (unless (string-match "^\\(\\|.*/\\)$" val)
152 (widget-put widget :error "Invalid directory entry: must end with '/'")
153 widget)))
154
155;; help string for user options
156(defconst vhdl-name-doc-string "
157
158FROM REGEXP is a regular expression matching the original name:
159 \".*\" matches the entire string
160 \"\\(...\\)\" matches a substring
161TO STRING specifies the string to be inserted as new name:
162 \"\\&\" means substitute entire matched text
163 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
164Examples:
165 \".*\" \"\\&\" inserts original string
166 \".*\" \"\\&_i\" attaches \"_i\" to original string
167 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
168 \".*\" \"foo\" inserts constant string \"foo\"
169 \".*\" \"\" inserts empty string")
170
5eabfe72
KH
171;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172;; User variables
d2ddb974
KH
173
174(defgroup vhdl nil
175 "Customizations for VHDL Mode."
176 :prefix "vhdl-"
42dfe0ad 177 :group 'languages
3dcb36b7 178; :version "20.4" ; comment out for XEmacs
5eabfe72 179 )
d2ddb974
KH
180
181(defgroup vhdl-mode nil
182 "Customizations for modes."
183 :group 'vhdl)
184
185(defcustom vhdl-electric-mode t
5eabfe72
KH
186 "*Non-nil enables electrification (automatic template generation).
187If nil, template generators can still be invoked through key bindings and
3dcb36b7 188menu. Is indicated in the modeline by \"/e\" after the mode name and can be
5eabfe72 189toggled by `\\[vhdl-electric-mode]'."
d2ddb974
KH
190 :type 'boolean
191 :group 'vhdl-mode)
192
193(defcustom vhdl-stutter-mode t
5eabfe72 194 "*Non-nil enables stuttering.
3dcb36b7 195Is indicated in the modeline by \"/s\" after the mode name and can be toggled
5eabfe72 196by `\\[vhdl-stutter-mode]'."
d2ddb974
KH
197 :type 'boolean
198 :group 'vhdl-mode)
199
5eabfe72
KH
200(defcustom vhdl-indent-tabs-mode nil
201 "*Non-nil means indentation can insert tabs.
d2ddb974
KH
202Overrides local variable `indent-tabs-mode'."
203 :type 'boolean
204 :group 'vhdl-mode)
205
206
207(defgroup vhdl-compile nil
208 "Customizations for compilation."
209 :group 'vhdl)
210
5eabfe72
KH
211(defcustom vhdl-compiler-alist
212 '(
3dcb36b7 213 ;; Cadence Leapfrog: cv -file test.vhd
5eabfe72 214 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
3dcb36b7
JB
215 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
216 nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
217 ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
218 ("\\1/entity" "\\2/\\1" "\\1/configuration"
219 "\\1/package" "\\1/body" downcase))
220 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
221 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
222 ;; (PLL_400X_TOP) is not declared [10.3].
223 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
224 nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
225 ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
226 nil)
5eabfe72 227 ;; Ikos Voyager: analyze test.vhd
3dcb36b7 228 ;; analyze test.vhd
5eabfe72 229 ;; E L4/C5: this library unit is inaccessible
3dcb36b7
JB
230 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
231 nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
232 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
233 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
234 nil)
5eabfe72
KH
235 ;; ModelSim, Model Technology: vcom test.vhd
236 ;; ERROR: test.vhd(14): Unknown identifier: positiv
237 ;; WARNING[2]: test.vhd(85): Possible infinite loop
3dcb36b7
JB
238 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
239 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
240 nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
241 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
242 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
243 "\\1/_primary.dat" "\\1/body.dat" downcase))
244 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
245 ;; test.vhd:34: error message
246 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
247 nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
248 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
249 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
250 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
5eabfe72
KH
251 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
252 ;; ERROR: test.vhd(24): near "dnd": expecting: END
253 ;; WARNING[4]: test.vhd(30): A space is required between ...
3dcb36b7
JB
254 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
255 nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
256 ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
257 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
258 "\\1/_primary.dat" "\\1/body.dat" downcase))
259 ;; Savant: scram -publish-cc test.vhd
260 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
261 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
262 nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
263 ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
264 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
265 "\\1_config.vhdl" "\\1_package.vhdl"
266 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
267 ;; Simili: vhdlp -work test.vhd
268 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
269 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
270 nil "mkdir \\1" "./" "work/" "Makefile" "simili"
271 ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
272 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
273 "\\1/prim.var" "\\1/_body.var" downcase))
274 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
275 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
276 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
277 nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
278 ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
279 nil)
280 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
5eabfe72 281 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
3dcb36b7
JB
282 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
283 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
284 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
285 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
286 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
287 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
288 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
289 nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
290 ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
291 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
292 ;; Synplify:
293 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
294 ("Synplify" "n/a" "n/a" "make" "-f \\1"
295 nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
296 ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
297 nil)
5eabfe72 298 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
299 ;; Compiling "test.vhd" line 1...
300 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
301 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
302 nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
303 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
304 ("^ *Compiling \"\\(.+\\)\" " 1)
305 nil)
306 ;; VeriBest: vc vhdl test.vhd
307 ;; (no file name printed out!)
308 ;; 32: Z <= A and BitA ;
309 ;; ^^^^
310 ;; [Error] Name BITA is unknown
311 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
312 nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
313 ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
314 nil)
5eabfe72 315 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
3dcb36b7
JB
316 ;; Compiling "test.vhd" line 1...
317 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
318 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
319 nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
320 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
321 ("^ *Compiling \"\\(.+\\)\" " 1)
322 nil)
5eabfe72
KH
323 )
324 "*List of available VHDL compilers and their properties.
325Each list entry specifies the following items for a compiler:
326Compiler:
3dcb36b7
JB
327 Compiler name : name used in option `vhdl-compiler' to choose compiler
328 Compile command : command used for source file compilation
329 Compile options : compile options (\"\\1\" inserts library name)
330 Make command : command used for compilation using a Makefile
331 Make options : make options (\"\\1\" inserts Makefile name)
332 Generate Makefile: use built-in function or command to generate a Makefile
333 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
334 Library command : command to create library directory \(\"\\1\" inserts
335 library directory, \"\\2\" inserts library name)
336 Compile directory: where compilation is run and the Makefile is placed
337 Library directory: directory of default library
338 Makefile name : name of Makefile (default is \"Makefile\")
339 ID string : compiler identification string (see `vhdl-project-alist')
340Error message:
5eabfe72 341 Regexp : regular expression to match error messages
3dcb36b7
JB
342 File subexp index: index of subexpression that matches the file name
343 Line subexp index: index of subexpression that matches the line number
344 Column subexp idx: index of subexpression that matches the column number
345File message:
5eabfe72 346 Regexp : regular expression to match a file name message
3dcb36b7
JB
347 File subexp index: index of subexpression that matches the file name
348Unit-to-file name mapping: mapping of library unit names to names of files
349 generated by the compiler (used for Makefile generation)
350 To string : string a name is mapped to (\"\\1\" inserts the unit name,
351 \"\\2\" inserts the entity name for architectures)
352 Case adjustment : adjust case of inserted unit names
353
354Compile options allows insertion of the library name (see `vhdl-project-alist')
355in order to set the compilers library option (e.g. \"vcom -work my_lib\").
356
357For Makefile generation, the built-in function can be used (requires
358specification of the unit-to-file name mapping). Alternatively, an
359external command can be specified. Work directory allows specification of
360an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
361used for Makefile generation). To use another library name than \"work\",
362customize `vhdl-project-alist'. The library command is inserted in Makefiles
363to automatically create the library directory if not existent.
364
365Compile options, compile directory, library directory, and Makefile name are
366overwritten by the project settings if a project is defined (see
367`vhdl-project-alist'). Directory paths are relative to the source file
368directory.
5eabfe72
KH
369
370Some compilers do not include the file name in the error message, but print
371out a file name message in advance. In this case, set \"File Subexp Index\"
3dcb36b7
JB
372under \"Error Message\" to 0 and fill out the \"File Message\" entries.
373If no file name at all is printed out, set both \"File Message\" entries to 0
374\(a default file name message will be printed out instead, does not work in
375XEmacs).
5eabfe72
KH
376
377A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
3dcb36b7 378assigning its name to option `vhdl-compiler'.
5eabfe72 379
3dcb36b7
JB
380Please send any missing or erroneous compiler properties to the maintainer for
381updating.
382
383NOTE: Reflect the new setting in the choice list of option `vhdl-compiler'
5eabfe72 384 by restarting Emacs."
3dcb36b7
JB
385 :type '(repeat
386 (list :tag "Compiler" :indent 2
387 (string :tag "Compiler name ")
388 (string :tag "Compile command ")
389 (string :tag "Compile options " "-work \\1")
390 (string :tag "Make command " "make")
391 (string :tag "Make options " "-f \\1")
392 (choice :tag "Generate Makefile "
393 (const :tag "Built-in function" nil)
394 (string :tag "Command" "vmake \\2 > \\1"))
395 (string :tag "Library command " "mkdir \\1")
396 (directory :tag "Compile directory "
397 :validate vhdl-widget-directory-validate "./")
398 (directory :tag "Library directory "
399 :validate vhdl-widget-directory-validate "work/")
400 (file :tag "Makefile name " "Makefile")
401 (string :tag "ID string ")
402 (list :tag "Error message" :indent 4
403 (regexp :tag "Regexp ")
404 (integer :tag "File subexp index")
405 (integer :tag "Line subexp index")
406 (integer :tag "Column subexp idx"))
407 (list :tag "File message" :indent 4
408 (regexp :tag "Regexp ")
409 (integer :tag "File subexp index"))
410 (choice :tag "Unit-to-file name mapping"
411 :format "%t: %[Value Menu%] %v\n"
412 (const :tag "Not defined" nil)
413 (list :tag "To string" :indent 4
414 (string :tag "Entity " "\\1.vhd")
415 (string :tag "Architecture " "\\2_\\1.vhd")
416 (string :tag "Configuration " "\\1.vhd")
417 (string :tag "Package " "\\1.vhd")
418 (string :tag "Package Body " "\\1_body.vhd")
419 (choice :tag "Case adjustment "
420 (const :tag "None" identity)
421 (const :tag "Upcase" upcase)
422 (const :tag "Downcase" downcase))))))
5eabfe72
KH
423 :set (lambda (variable value)
424 (vhdl-custom-set variable value 'vhdl-update-mode-menu))
425 :group 'vhdl-compile)
426
427(defcustom vhdl-compiler "ModelSim"
428 "*Specifies the VHDL compiler to be used for syntax analysis.
3dcb36b7
JB
429Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
430 :type (let ((alist vhdl-compiler-alist) list)
431 (while alist
432 (setq list (cons (list 'const (caar alist)) list))
433 (setq alist (cdr alist)))
434 (append '(choice) (nreverse list)))
435 :group 'vhdl-compile)
436
437(defcustom vhdl-compile-use-local-error-regexp t
438 "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
439In this case, only error message regexps for VHDL compilers are active if
440compilation is started from a VHDL buffer. Otherwise, the error message
441regexps are appended to the predefined global regexps, and all regexps are
442active all the time. Note that by doing that, the predefined global regexps
443might result in erroneous parsing of error messages for some VHDL compilers.
444
445NOTE: Activate the new setting by restarting Emacs."
446 :type 'boolean
d2ddb974
KH
447 :group 'vhdl-compile)
448
3dcb36b7
JB
449(defcustom vhdl-makefile-generation-hook nil
450 "*Functions to run at the end of Makefile generation.
451Allows to insert user specific parts into a Makefile.
452
453Example:
454 \(lambda nil
455 \(re-search-backward \"^# Rule for compiling entire design\")
456 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
457 :type 'hook
458 :group 'vhdl-compile)
459
460(defcustom vhdl-default-library "work"
461 "*Name of default library.
462Is overwritten by project settings if a project is active."
d2ddb974
KH
463 :type 'string
464 :group 'vhdl-compile)
465
466
3dcb36b7
JB
467(defgroup vhdl-project nil
468 "Customizations for projects."
d2ddb974
KH
469 :group 'vhdl)
470
3dcb36b7
JB
471(defcustom vhdl-project-alist
472 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
473 "~/example1/" ("src/system/" "src/components/") ""
474 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
475 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
476 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
477 ("Example 2" "Individual source files, multiple compilers in different directories"
478 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
479 nil "\\1/" "work" "\\1/work/" "Makefile" "")
480 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
481 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
482 nil "./" "work" "work-\\1/" "Makefile-\\1" "\
483-------------------------------------------------------------------------------
484-- This is a multi-line project description
485-- that can be used as a project dependent part of the file header.
486"))
487 "*List of projects and their properties.
488 Name : name used in option `vhdl-project' to choose project
489 Title : title of project (single-line string)
490 Default directory: default project directory (absolute path)
491 Sources : a) source files : path + \"/\" + file name
492 b) directory : path + \"/\"
493 c) directory tree: \"-r \" + path + \"/\"
494 Exclude regexp : matches file/directory names to be excluded as sources
495 Compile options : project-specific options for each compiler
496 Compiler name : name of compiler for which these options are valid
497 Compile options: project-specific compiler options
498 (\"\\1\" inserts library name, \"\\2\" default options)
499 Make options: project-specific make options
500 (\"\\1\" inserts Makefile name, \"\\2\" default options)
501 Exceptions : file-specific exceptions
502 File name regexp: matches file names for which exceptions are valid
503 - Options : file-specific compiler options string
504 (\"\\1\" inserts library name, \"\\2\" default options,
505 \"\\3\" project-specific options)
506 - Do not compile: do not compile this file (in Makefile)
507 Compile directory: where compilation is run and the Makefile is placed
508 \(\"\\1\" inserts compiler ID string)
509 Library name : name of library (default is \"work\")
510 Library directory: path to library (\"\\1\" inserts compiler ID string)
511 Makefile name : name of Makefile
512 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
513 Description : description of project (multi-line string)
514
515Project title and description are used to insert into the file header (see
516option `vhdl-file-header').
517
518The default directory must have an absolute path (use `M-TAB' for completion).
519All other paths can be absolute or relative to the default directory. All
520paths must end with '/'.
521
522The design units found in the sources (files and directories) are shown in the
523hierarchy browser. Path and file name can contain wildcards `*' and `?' as
524well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
525Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
526specified, the default directory is taken as source directory. Otherwise,
527the default directory is only taken as source directory if there is a sources
528entry with the empty string or \"./\". Exclude regexp allows to filter out
529specific file and directory names from the list of sources (e.g. CVS
530directories).
531
532Files are compiled in the compile directory. Makefiles are also placed into
533the compile directory. Library directory specifies which directory the
534compiler compiles into (used to generate the Makefile).
535
536Since different compile/library directories and Makefiles may exist for
537different compilers within one project, these paths and names allow the
538insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
539Compile options, compile directory, library directory, and Makefile name
540overwrite the settings of the current compiler.
541
542File-specific compiler options (highest priority) overwrite project-specific
543options which overwrite default options (lowest priority). Lower priority
544options can be inserted in higher priority options. This allows to reuse
545default options (e.g. \"-file\") in project- or file-specific options (e.g.
546\"-93 -file\").
547
548NOTE: Reflect the new setting in the choice list of option `vhdl-project'
549 by restarting Emacs."
550 :type `(repeat
551 (list :tag "Project" :indent 2
552 (string :tag "Name ")
553 (string :tag "Title ")
554 (directory :tag "Default directory"
555 :validate vhdl-widget-directory-validate
556 ,(abbreviate-file-name default-directory))
557 (repeat :tag "Sources " :indent 4
558 (directory :format " %v" "./"))
559 (regexp :tag "Exclude regexp ")
560 (repeat
561 :tag "Compile options " :indent 4
562 (list :tag "Compiler" :indent 6
563 ,(let ((alist vhdl-compiler-alist) list)
564 (while alist
565 (setq list (cons (list 'const (caar alist)) list))
566 (setq alist (cdr alist)))
567 (append '(choice :tag "Compiler name")
568 (nreverse list)))
569 (string :tag "Compile options" "\\2")
570 (string :tag "Make options " "\\2")
571 (repeat
572 :tag "Exceptions " :indent 8
573 (cons :format "%v"
574 (regexp :tag "File name regexp ")
575 (choice :format "%[Value Menu%] %v"
576 (string :tag "Options" "\\3")
577 (const :tag "Do not compile" nil))))))
578 (directory :tag "Compile directory"
579 :validate vhdl-widget-directory-validate "./")
580 (string :tag "Library name " "work")
581 (directory :tag "Library directory"
582 :validate vhdl-widget-directory-validate "work/")
583 (file :tag "Makefile name " "Makefile")
584 (string :tag "Description: (type `C-j' for newline)"
585 :format "%t\n%v\n")))
586 :set (lambda (variable value)
587 (vhdl-custom-set variable value
588 'vhdl-update-mode-menu
589 'vhdl-speedbar-refresh))
590 :group 'vhdl-project)
591
592(defcustom vhdl-project nil
593 "*Specifies the default for the current project.
594Select a project name from the ones defined in option `vhdl-project-alist'.
595Is used to determine the project title and description to be inserted in file
596headers and the source files/directories to be scanned in the hierarchy
597browser. The current project can also be changed temporarily in the menu."
598 :type (let ((alist vhdl-project-alist) list)
599 (while alist
600 (setq list (cons (list 'const (caar alist)) list))
601 (setq alist (cdr alist)))
602 (append '(choice (const :tag "None" nil) (const :tag "--"))
603 (nreverse list)))
604 :group 'vhdl-project)
605
606(defcustom vhdl-project-file-name '("\\1.prj")
607 "*List of file names/paths for importing/exporting project setups.
608\"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
609replaced by the user name (allows to have user-specific project setups).
610The first entry is used as file name to import/export individual project
611setups. All entries are used to automatically import project setups at
612startup (see option `vhdl-project-auto-load'). Projects loaded from the
613first entry are automatically made current. Hint: specify local project
614setups in first entry, global setups in following entries; loading a local
615project setup will make it current, while loading the global setups
616is done without changing the current project.
617Names can also have an absolute path (i.e. project setups can be stored
618in global directories)."
619 :type '(repeat (string :tag "File name" "\\1.prj"))
620 :group 'vhdl-project)
621
622(defcustom vhdl-project-auto-load '(startup)
623 "*Automatically load project setups from files.
624All project setup files that match the file names specified in option
625`vhdl-project-file-name' are automatically loaded. The project of the
626\(alphabetically) last loaded setup of the first `vhdl-project-file-name'
627entry is activated.
628A project setup file can be obtained by exporting a project (see menu).
629 At startup: project setup file is loaded at Emacs startup"
630 :type '(set (const :tag "At startup" startup))
631 :group 'vhdl-project)
632
633(defcustom vhdl-project-sort t
634 "*Non-nil means projects are displayed in alphabetical order."
635 :type 'boolean
636 :group 'vhdl-project)
637
638
639(defgroup vhdl-style nil
640 "Customizations for coding styles."
641 :group 'vhdl
642 :group 'vhdl-template
643 :group 'vhdl-port
644 :group 'vhdl-compose)
645
5eabfe72
KH
646(defcustom vhdl-standard '(87 nil)
647 "*VHDL standards used.
648Basic standard:
649 VHDL'87 : IEEE Std 1076-1987
650 VHDL'93 : IEEE Std 1076-1993
651Additional standards:
652 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
3dcb36b7 653 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
5eabfe72 654
3dcb36b7
JB
655NOTE: Activate the new setting in a VHDL buffer by using the menu entry
656 \"Activate Options\"."
5eabfe72
KH
657 :type '(list (choice :tag "Basic standard"
658 (const :tag "VHDL'87" 87)
659 (const :tag "VHDL'93" 93))
660 (set :tag "Additional standards" :indent 2
661 (const :tag "VHDL-AMS" ams)
3dcb36b7 662 (const :tag "Math packages" math)))
5eabfe72
KH
663 :set (lambda (variable value)
664 (vhdl-custom-set variable value
665 'vhdl-template-map-init
666 'vhdl-mode-abbrev-table-init
667 'vhdl-template-construct-alist-init
668 'vhdl-template-package-alist-init
669 'vhdl-update-mode-menu
670 'vhdl-words-init 'vhdl-font-lock-init))
671 :group 'vhdl-style)
672
673(defcustom vhdl-basic-offset 2
d2ddb974
KH
674 "*Amount of basic offset used for indentation.
675This value is used by + and - symbols in `vhdl-offsets-alist'."
676 :type 'integer
677 :group 'vhdl-style)
678
d2ddb974 679(defcustom vhdl-upper-case-keywords nil
5eabfe72
KH
680 "*Non-nil means convert keywords to upper case.
681This is done when typed or expanded or by the fix case functions."
d2ddb974 682 :type 'boolean
5eabfe72
KH
683 :set (lambda (variable value)
684 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
685 :group 'vhdl-style)
d2ddb974
KH
686
687(defcustom vhdl-upper-case-types nil
5eabfe72
KH
688 "*Non-nil means convert standardized types to upper case.
689This is done when expanded or by the fix case functions."
d2ddb974 690 :type 'boolean
5eabfe72
KH
691 :set (lambda (variable value)
692 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
693 :group 'vhdl-style)
d2ddb974
KH
694
695(defcustom vhdl-upper-case-attributes nil
5eabfe72
KH
696 "*Non-nil means convert standardized attributes to upper case.
697This is done when expanded or by the fix case functions."
d2ddb974 698 :type 'boolean
5eabfe72
KH
699 :set (lambda (variable value)
700 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
701 :group 'vhdl-style)
d2ddb974
KH
702
703(defcustom vhdl-upper-case-enum-values nil
5eabfe72
KH
704 "*Non-nil means convert standardized enumeration values to upper case.
705This is done when expanded or by the fix case functions."
d2ddb974 706 :type 'boolean
5eabfe72
KH
707 :set (lambda (variable value)
708 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
709 :group 'vhdl-style)
710
711(defcustom vhdl-upper-case-constants t
712 "*Non-nil means convert standardized constants to upper case.
713This is done when expanded."
714 :type 'boolean
715 :set (lambda (variable value)
716 (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
717 :group 'vhdl-style)
d2ddb974 718
3dcb36b7
JB
719(defcustom vhdl-use-direct-instantiation 'standard
720 "*Non-nil means use VHDL'93 direct component instantiation.
721 Never : never
722 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
723 Always : always"
724 :type '(choice (const :tag "Never" never)
725 (const :tag "Standard" standard)
726 (const :tag "Always" always))
727 :group 'vhdl-style)
728
729
730(defgroup vhdl-naming nil
731 "Customizations for naming conventions."
732 :group 'vhdl)
733
734(defcustom vhdl-entity-file-name '(".*" . "\\&")
735 (concat
736 "*Specifies how the entity file name is obtained.
737The entity file name can be obtained by modifying the entity name (e.g.
738attaching or stripping off a substring). The file extension is automatically
739taken from the file name of the current buffer."
740 vhdl-name-doc-string)
741 :type '(cons (regexp :tag "From regexp")
742 (string :tag "To string "))
743 :group 'vhdl-naming
744 :group 'vhdl-compose)
d2ddb974 745
3dcb36b7
JB
746(defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
747 (concat
748 "*Specifies how the architecture file name is obtained.
749The architecture file name can be obtained by modifying the entity
750and/or architecture name (e.g. attaching or stripping off a substring). The
751string that is matched against the regexp is the concatenation of the entity
752and the architecture name separated by a space. This gives access to both
753names (see default setting as example)."
754 vhdl-name-doc-string)
755 :type '(cons (regexp :tag "From regexp")
756 (string :tag "To string "))
757 :group 'vhdl-naming
758 :group 'vhdl-compose)
759
760(defcustom vhdl-package-file-name '(".*" . "\\&")
761 (concat
762 "*Specifies how the package file name is obtained.
763The package file name can be obtained by modifying the package name (e.g.
764attaching or stripping off a substring). The file extension is automatically
765taken from the file name of the current buffer."
766 vhdl-name-doc-string)
767 :type '(cons (regexp :tag "From regexp")
768 (string :tag "To string "))
769 :group 'vhdl-naming
770 :group 'vhdl-compose)
771
772(defcustom vhdl-file-name-case 'identity
773 "*Specifies how to change case for obtaining file names.
774When deriving a file name from a VHDL unit name, case can be changed as
775follows:
776 As Is: case is not changed (taken as is)
777 Lower Case: whole name is changed to lower case
778 Upper Case: whole name is changed to upper case
779 Capitalize: first letter of each word in name is capitalized"
780 :type '(choice (const :tag "As Is" identity)
781 (const :tag "Lower Case" downcase)
782 (const :tag "Upper Case" upcase)
783 (const :tag "Capitalize" capitalize))
784 :group 'vhdl-naming
785 :group 'vhdl-compose)
786
787
788(defgroup vhdl-template nil
5eabfe72 789 "Customizations for electrification."
d2ddb974
KH
790 :group 'vhdl)
791
5eabfe72
KH
792(defcustom vhdl-electric-keywords '(vhdl user)
793 "*Type of keywords for which electrification is enabled.
794 VHDL keywords: invoke built-in templates
3dcb36b7 795 User keywords: invoke user models (see option `vhdl-model-alist')"
5eabfe72 796 :type '(set (const :tag "VHDL keywords" vhdl)
3dcb36b7 797 (const :tag "User model keywords" user))
5eabfe72
KH
798 :set (lambda (variable value)
799 (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
3dcb36b7 800 :group 'vhdl-template)
5eabfe72
KH
801
802(defcustom vhdl-optional-labels 'process
803 "*Constructs for which labels are to be queried.
804Template generators prompt for optional labels for:
805 None : no constructs
806 Processes only: processes only (also procedurals in VHDL-AMS)
807 All constructs: all constructs with optional labels and keyword END"
808 :type '(choice (const :tag "None" none)
809 (const :tag "Processes only" process)
810 (const :tag "All constructs" all))
3dcb36b7 811 :group 'vhdl-template)
d2ddb974 812
5eabfe72
KH
813(defcustom vhdl-insert-empty-lines 'unit
814 "*Specifies whether to insert empty lines in some templates.
815This improves readability of code. Empty lines are inserted in:
816 None : no constructs
817 Design units only: entities, architectures, configurations, packages only
818 All constructs : also all constructs with BEGIN...END parts
819
3dcb36b7 820Replaces option `vhdl-additional-empty-lines'."
5eabfe72
KH
821 :type '(choice (const :tag "None" none)
822 (const :tag "Design units only" unit)
823 (const :tag "All constructs" all))
3dcb36b7
JB
824 :group 'vhdl-template
825 :group 'vhdl-port
826 :group 'vhdl-compose)
5eabfe72
KH
827
828(defcustom vhdl-argument-list-indent nil
829 "*Non-nil means indent argument lists relative to opening parenthesis.
830That is, argument, association, and port lists start on the same line as the
831opening parenthesis and subsequent lines are indented accordingly.
832Otherwise, lists start on a new line and are indented as normal code."
d2ddb974 833 :type 'boolean
3dcb36b7
JB
834 :group 'vhdl-template
835 :group 'vhdl-port
836 :group 'vhdl-compose)
d2ddb974 837
5eabfe72
KH
838(defcustom vhdl-association-list-with-formals t
839 "*Non-nil means write association lists with formal parameters.
3dcb36b7
JB
840Templates prompt for formal and actual parameters (ports/generics).
841When pasting component instantiations, formals are included.
5eabfe72 842If nil, only a list of actual parameters is entered."
d2ddb974 843 :type 'boolean
3dcb36b7
JB
844 :group 'vhdl-template
845 :group 'vhdl-port
846 :group 'vhdl-compose)
d2ddb974
KH
847
848(defcustom vhdl-conditions-in-parenthesis nil
5eabfe72 849 "*Non-nil means place parenthesis around condition expressions."
d2ddb974 850 :type 'boolean
3dcb36b7 851 :group 'vhdl-template)
d2ddb974 852
5eabfe72
KH
853(defcustom vhdl-zero-string "'0'"
854 "*String to use for a logic zero."
855 :type 'string
3dcb36b7 856 :group 'vhdl-template)
5eabfe72
KH
857
858(defcustom vhdl-one-string "'1'"
859 "*String to use for a logic one."
860 :type 'string
3dcb36b7 861 :group 'vhdl-template)
5eabfe72
KH
862
863
864(defgroup vhdl-header nil
865 "Customizations for file header."
3dcb36b7
JB
866 :group 'vhdl-template
867 :group 'vhdl-compose)
d2ddb974 868
5eabfe72
KH
869(defcustom vhdl-file-header "\
870-------------------------------------------------------------------------------
871-- Title : <title string>
872-- Project : <project>
873-------------------------------------------------------------------------------
874-- File : <filename>
875-- Author : <author>
876-- Company : <company>
3dcb36b7 877-- Created : <date>
5eabfe72
KH
878-- Last update: <date>
879-- Platform : <platform>
3dcb36b7 880-- Standard : <standard>
5eabfe72
KH
881<projectdesc>-------------------------------------------------------------------------------
882-- Description: <cursor>
3dcb36b7 883<copyright>-------------------------------------------------------------------------------
5eabfe72
KH
884-- Revisions :
885-- Date Version Author Description
886-- <date> 1.0 <login>\tCreated
887-------------------------------------------------------------------------------
888
889"
890 "*String or file to insert as file header.
891If the string specifies an existing file name, the contents of the file is
892inserted, otherwise the string itself is inserted as file header.
893Type `C-j' for newlines.
d2ddb974
KH
894If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
895if the header needs to be version controlled.
896
897The following keywords for template generation are supported:
3dcb36b7
JB
898 <filename> : replaced by the name of the buffer
899 <author> : replaced by the user name and email address
900 \(`user-full-name',`mail-host-address', `user-mail-address')
901 <login> : replaced by user login name (`user-login-name')
902 <company> : replaced by contents of option `vhdl-company-name'
903 <date> : replaced by the current date
904 <year> : replaced by the current year
905 <project> : replaced by title of current project (`vhdl-project')
906 <projectdesc> : replaced by description of current project (`vhdl-project')
907 <copyright> : replaced by copyright string (`vhdl-copyright-string')
908 <platform> : replaced by contents of option `vhdl-platform-spec'
909 <standard> : replaced by the VHDL language standard(s) used
910 <... string> : replaced by a queried string (\"...\" is the prompt word)
911 <title string>: replaced by file title in automatically generated files
912 <cursor> : final cursor position
d2ddb974 913
5eabfe72
KH
914The (multi-line) project description <projectdesc> can be used as a project
915dependent part of the file header and can also contain the above keywords."
916 :type 'string
917 :group 'vhdl-header)
918
919(defcustom vhdl-file-footer ""
920 "*String or file to insert as file footer.
921If the string specifies an existing file name, the contents of the file is
922inserted, otherwise the string itself is inserted as file footer (i.e. at
923the end of the file).
3dcb36b7
JB
924Type `C-j' for newlines.
925The same keywords as in option `vhdl-file-header' can be used."
5eabfe72
KH
926 :type 'string
927 :group 'vhdl-header)
928
929(defcustom vhdl-company-name ""
3dcb36b7
JB
930 "*Name of company to insert in file header.
931See option `vhdl-file-header'."
932 :type 'string
933 :group 'vhdl-header)
934
935(defcustom vhdl-copyright-string "\
936-------------------------------------------------------------------------------
937-- Copyright (c) <year> <company>
938"
939 "*Copyright string to insert in file header.
940Can be multi-line string (type `C-j' for newline) and contain other file
941header keywords (see option `vhdl-file-header')."
5eabfe72
KH
942 :type 'string
943 :group 'vhdl-header)
944
945(defcustom vhdl-platform-spec ""
946 "*Specification of VHDL platform to insert in file header.
947The platform specification should contain names and versions of the
3dcb36b7
JB
948simulation and synthesis tools used.
949See option `vhdl-file-header'."
5eabfe72
KH
950 :type 'string
951 :group 'vhdl-header)
952
3dcb36b7 953(defcustom vhdl-date-format "%Y-%m-%d"
5eabfe72
KH
954 "*Specifies the date format to use in the header.
955This string is passed as argument to the command `format-time-string'.
956For more information on format strings, see the documentation for the
957`format-time-string' command (C-h f `format-time-string')."
958 :type 'string
959 :group 'vhdl-header)
d2ddb974 960
5eabfe72 961(defcustom vhdl-modify-date-prefix-string "-- Last update: "
d2ddb974 962 "*Prefix string of modification date in VHDL file header.
5eabfe72
KH
963If actualization of the modification date is called (menu,
964`\\[vhdl-template-modify]'), this string is searched and the rest
965of the line replaced by the current date."
d2ddb974 966 :type 'string
5eabfe72
KH
967 :group 'vhdl-header)
968
969(defcustom vhdl-modify-date-on-saving t
970 "*Non-nil means update the modification date when the buffer is saved.
971Calls function `\\[vhdl-template-modify]').
972
3dcb36b7
JB
973NOTE: Activate the new setting in a VHDL buffer by using the menu entry
974 \"Activate Options\"."
5eabfe72
KH
975 :type 'boolean
976 :group 'vhdl-header)
977
978
979(defgroup vhdl-sequential-process nil
980 "Customizations for sequential processes."
3dcb36b7 981 :group 'vhdl-template)
d2ddb974 982
5eabfe72
KH
983(defcustom vhdl-reset-kind 'async
984 "*Specifies which kind of reset to use in sequential processes."
985 :type '(choice (const :tag "None" none)
986 (const :tag "Synchronous" sync)
987 (const :tag "Asynchronous" async))
988 :group 'vhdl-sequential-process)
989
990(defcustom vhdl-reset-active-high nil
991 "*Non-nil means reset in sequential processes is active high.
3dcb36b7 992Nil means active low."
5eabfe72
KH
993 :type 'boolean
994 :group 'vhdl-sequential-process)
995
996(defcustom vhdl-clock-rising-edge t
997 "*Non-nil means rising edge of clock triggers sequential processes.
3dcb36b7 998Nil means falling edge."
5eabfe72
KH
999 :type 'boolean
1000 :group 'vhdl-sequential-process)
1001
1002(defcustom vhdl-clock-edge-condition 'standard
1003 "*Syntax of the clock edge condition.
1004 Standard: \"clk'event and clk = '1'\"
1005 Function: \"rising_edge(clk)\""
1006 :type '(choice (const :tag "Standard" standard)
1007 (const :tag "Function" function))
1008 :group 'vhdl-sequential-process)
1009
1010(defcustom vhdl-clock-name ""
1011 "*Name of clock signal to use in templates."
d2ddb974 1012 :type 'string
5eabfe72 1013 :group 'vhdl-sequential-process)
d2ddb974 1014
5eabfe72
KH
1015(defcustom vhdl-reset-name ""
1016 "*Name of reset signal to use in templates."
d2ddb974 1017 :type 'string
5eabfe72
KH
1018 :group 'vhdl-sequential-process)
1019
1020
1021(defgroup vhdl-model nil
1022 "Customizations for user models."
1023 :group 'vhdl)
1024
1025(defcustom vhdl-model-alist
3dcb36b7 1026 '(("Example Model"
5eabfe72
KH
1027 "<label> : process (<clock>, <reset>)
1028begin -- process <label>
1029 if <reset> = '0' then -- asynchronous reset (active low)
1030 <cursor>
1031 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1032 if <enable> = '1' then -- synchronous load
a1506d29 1033
5eabfe72
KH
1034 end if;
1035 end if;
1036end process <label>;"
1037 "e" ""))
1038 "*List of user models.
1039VHDL models (templates) can be specified by the user in this list. They can be
1040invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1041electrification (i.e. overriding existing or creating new keywords, see
3dcb36b7 1042option `vhdl-electric-keywords').
5eabfe72
KH
1043 Name : name of model (string of words and spaces)
1044 String : string or name of file to be inserted as model (newline: `C-j')
1045 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1046 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1047 Keyword : keyword to invoke model
1048
1049The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1050A prompt that appears several times is queried once and replaced throughout
1051the model. Special prompts are:
1052 <clock> : name specified in `vhdl-clock-name' (if not empty)
1053 <reset> : name specified in `vhdl-reset-name' (if not empty)
1054 <cursor>: final cursor position
3dcb36b7
JB
1055File header prompts (see variable `vhdl-file-header') are automatically
1056replaced, so that user models can also be used to insert different types of
1057headers.
5eabfe72
KH
1058
1059If the string specifies an existing file name, the contents of the file is
1060inserted, otherwise the string itself is inserted.
1061The code within the models should be correctly indented.
1062Type `C-j' for newlines.
1063
3dcb36b7
JB
1064NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1065 \"Activate Options\"."
5eabfe72
KH
1066 :type '(repeat (list :tag "Model" :indent 2
1067 (string :tag "Name ")
1068 (string :tag "String : (type `C-j' for newline)"
1069 :format "%t\n%v")
3dcb36b7
JB
1070 (sexp :tag "Key binding" x)
1071 (string :tag "Keyword " :format "%t: %v\n")))
5eabfe72
KH
1072 :set (lambda (variable value)
1073 (vhdl-custom-set variable value
1074 'vhdl-model-map-init
1075 'vhdl-model-defun
1076 'vhdl-mode-abbrev-table-init
1077 'vhdl-update-mode-menu))
1078 :group 'vhdl-model)
1079
3dcb36b7 1080
5eabfe72 1081(defgroup vhdl-port nil
3dcb36b7
JB
1082 "Customizations for port translation functions."
1083 :group 'vhdl
1084 :group 'vhdl-compose)
5eabfe72
KH
1085
1086(defcustom vhdl-include-port-comments nil
1087 "*Non-nil means include port comments when a port is pasted."
1088 :type 'boolean
1089 :group 'vhdl-port)
1090
1091(defcustom vhdl-include-direction-comments nil
3dcb36b7 1092 "*Non-nil means include port direction in instantiations as comments."
5eabfe72
KH
1093 :type 'boolean
1094 :group 'vhdl-port)
1095
3dcb36b7
JB
1096(defcustom vhdl-include-type-comments nil
1097 "*Non-nil means include generic/port type in instantiations as comments."
1098 :type 'boolean
1099 :group 'vhdl-port)
5eabfe72 1100
3dcb36b7
JB
1101(defcustom vhdl-include-group-comments 'never
1102 "*Specifies whether to include group comments and spacings.
1103The comments and empty lines between groups of ports are pasted:
1104 Never : never
1105 Declarations: in entity/component/constant/signal declarations only
1106 Always : also in generic/port maps"
1107 :type '(choice (const :tag "Never" never)
1108 (const :tag "Declarations" decl)
1109 (const :tag "Always" always))
1110 :group 'vhdl-port)
5eabfe72 1111
3dcb36b7 1112(defcustom vhdl-actual-port-name '(".*" . "\\&")
5eabfe72
KH
1113 (concat
1114 "*Specifies how actual port names are obtained from formal port names.
1115In a component instantiation, an actual port name can be obtained by
1116modifying the formal port name (e.g. attaching or stripping off a substring)."
1117 vhdl-name-doc-string)
3dcb36b7
JB
1118 :type '(cons (regexp :tag "From regexp")
1119 (string :tag "To string "))
5eabfe72
KH
1120 :group 'vhdl-port)
1121
3dcb36b7 1122(defcustom vhdl-instance-name '(".*" . "\\&_%d")
5eabfe72
KH
1123 (concat
1124 "*Specifies how an instance name is obtained.
1125The instance name can be obtained by modifying the name of the component to be
3dcb36b7
JB
1126instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1127by a unique number (starting with 1).
5eabfe72
KH
1128If TO STRING is empty, the instance name is queried."
1129 vhdl-name-doc-string)
3dcb36b7
JB
1130 :type '(cons (regexp :tag "From regexp")
1131 (string :tag "To string "))
1132 :group 'vhdl-port)
1133
1134
1135(defgroup vhdl-testbench nil
1136 "Customizations for testbench generation ."
5eabfe72
KH
1137 :group 'vhdl-port)
1138
1139(defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
1140 (concat
3dcb36b7
JB
1141 "*Specifies how the testbench entity name is obtained.
1142The entity name of a testbench can be obtained by modifying the name of
5eabfe72
KH
1143the component to be tested (e.g. attaching or stripping off a substring)."
1144 vhdl-name-doc-string)
3dcb36b7
JB
1145 :type '(cons (regexp :tag "From regexp")
1146 (string :tag "To string "))
1147 :group 'vhdl-testbench)
5eabfe72
KH
1148
1149(defcustom vhdl-testbench-architecture-name '(".*" . "")
1150 (concat
3dcb36b7
JB
1151 "*Specifies how the testbench architecture name is obtained.
1152The testbench architecture name can be obtained by modifying the name of
5eabfe72
KH
1153the component to be tested (e.g. attaching or stripping off a substring).
1154If TO STRING is empty, the architecture name is queried."
1155 vhdl-name-doc-string)
3dcb36b7
JB
1156 :type '(cons (regexp :tag "From regexp")
1157 (string :tag "To string "))
1158 :group 'vhdl-testbench)
1159
1160(defcustom vhdl-testbench-configuration-name
1161 '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
1162 (concat
1163 "*Specifies how the testbench configuration name is obtained.
1164The configuration name of a testbench can be obtained by modifying the entity
1165and/or architecture name (e.g. attaching or stripping off a substring). The
1166string that is matched against the regexp is the concatenation of the entity
1167and the architecture name separated by a space. This gives access to both
1168names (see default setting as example)."
1169 vhdl-name-doc-string)
1170 :type '(cons (regexp :tag "From regexp")
1171 (string :tag "To string "))
1172 :group 'vhdl-testbench)
5eabfe72
KH
1173
1174(defcustom vhdl-testbench-dut-name '(".*" . "DUT")
1175 (concat
1176 "*Specifies how a DUT instance name is obtained.
1177The design-under-test instance name (i.e. the component instantiated in the
3dcb36b7 1178testbench) can be obtained by modifying the component name (e.g. attaching
5eabfe72
KH
1179or stripping off a substring)."
1180 vhdl-name-doc-string)
3dcb36b7
JB
1181 :type '(cons (regexp :tag "From regexp")
1182 (string :tag "To string "))
1183 :group 'vhdl-testbench)
5eabfe72 1184
3dcb36b7
JB
1185(defcustom vhdl-testbench-include-header t
1186 "*Non-nil means include a header in automatically generated files."
1187 :type 'boolean
1188 :group 'vhdl-testbench)
5eabfe72 1189
3dcb36b7
JB
1190(defcustom vhdl-testbench-declarations "\
1191 -- clock
1192 signal Clk : std_logic := '1';
1193"
1194 "*String or file to be inserted in the testbench declarative part.
5eabfe72 1195If the string specifies an existing file name, the contents of the file is
3dcb36b7 1196inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1197architecture before the BEGIN keyword.
1198Type `C-j' for newlines."
1199 :type 'string
3dcb36b7
JB
1200 :group 'vhdl-testbench)
1201
1202(defcustom vhdl-testbench-statements "\
1203 -- clock generation
1204 Clk <= not Clk after 10 ns;
5eabfe72 1205
3dcb36b7
JB
1206 -- waveform generation
1207 WaveGen_Proc: process
1208 begin
1209 -- insert signal assignments here
1210
1211 wait until Clk = '1';
1212 end process WaveGen_Proc;
1213"
1214 "*String or file to be inserted in the testbench statement part.
5eabfe72 1215If the string specifies an existing file name, the contents of the file is
3dcb36b7 1216inserted, otherwise the string itself is inserted in the testbench
5eabfe72
KH
1217architecture before the END keyword.
1218Type `C-j' for newlines."
1219 :type 'string
3dcb36b7 1220 :group 'vhdl-testbench)
5eabfe72
KH
1221
1222(defcustom vhdl-testbench-initialize-signals nil
3dcb36b7 1223 "*Non-nil means initialize signals with `0' when declared in testbench."
5eabfe72 1224 :type 'boolean
3dcb36b7
JB
1225 :group 'vhdl-testbench)
1226
1227(defcustom vhdl-testbench-include-library t
1228 "*Non-nil means a library/use clause for std_logic_1164 is included."
1229 :type 'boolean
1230 :group 'vhdl-testbench)
1231
1232(defcustom vhdl-testbench-include-configuration t
1233 "*Non-nil means a testbench configuration is attached at the end."
1234 :type 'boolean
1235 :group 'vhdl-testbench)
5eabfe72
KH
1236
1237(defcustom vhdl-testbench-create-files 'single
3dcb36b7
JB
1238 "*Specifies whether new files should be created for the testbench.
1239testbench entity and architecture are inserted:
5eabfe72
KH
1240 None : in current buffer
1241 Single file : in new single file
1242 Separate files: in two separate files
1243Note that the files have the same name as the contained design unit."
1244 :type '(choice (const :tag "None" none)
1245 (const :tag "Single file" single)
1246 (const :tag "Separate files" separate))
3dcb36b7
JB
1247 :group 'vhdl-testbench)
1248
1249
1250(defgroup vhdl-compose nil
1251 "Customizations for structural composition."
1252 :group 'vhdl)
1253
1254(defcustom vhdl-compose-create-files 'single
1255 "*Specifies whether new files should be created for the new component.
1256The component's entity and architecture are inserted:
1257 None : in current buffer
1258 Single file : in new single file
1259 Separate files: in two separate files
1260The file names are obtained from variables `vhdl-entity-file-name' and
1261`vhdl-architecture-file-name'."
1262 :type '(choice (const :tag "None" none)
1263 (const :tag "Single file" single)
1264 (const :tag "Separate files" separate))
1265 :group 'vhdl-compose)
1266
1267(defcustom vhdl-compose-include-header t
1268 "*Non-nil means include a header in automatically generated files."
1269 :type 'boolean
1270 :group 'vhdl-compose)
1271
1272(defcustom vhdl-compose-architecture-name '(".*" . "str")
1273 (concat
1274 "*Specifies how the component architecture name is obtained.
1275The component architecture name can be obtained by modifying the entity name
1276\(e.g. attaching or stripping off a substring).
1277If TO STRING is empty, the architecture name is queried."
1278 vhdl-name-doc-string)
1279 :type '(cons (regexp :tag "From regexp")
1280 (string :tag "To string "))
1281 :group 'vhdl-compose)
1282
1283(defcustom vhdl-components-package-name
1284 '((".*" . "\\&_components") . "components")
1285 (concat
1286 "*Specifies how the name for the components package is obtained.
1287The components package is a package containing all component declarations for
1288the current design. Its name can be obtained by modifying the project name
1289\(e.g. attaching or stripping off a substring). If no project is defined, the
1290DIRECTORY entry is chosen."
1291 vhdl-name-doc-string)
1292 :type '(cons (cons :tag "Project" :indent 2
1293 (regexp :tag "From regexp")
1294 (string :tag "To string "))
1295 (string :tag "Directory:\n String "))
1296 :group 'vhdl-compose)
1297
1298(defcustom vhdl-use-components-package nil
1299 "*Non-nil means use a separate components package for component declarations.
1300Otherwise, component declarations are inserted and searched for in the
1301architecture declarative parts."
1302 :type 'boolean
1303 :group 'vhdl-compose)
d2ddb974
KH
1304
1305
1306(defgroup vhdl-comment nil
1307 "Customizations for comments."
5eabfe72 1308 :group 'vhdl)
d2ddb974
KH
1309
1310(defcustom vhdl-self-insert-comments t
5eabfe72 1311 "*Non-nil means various templates automatically insert help comments."
d2ddb974
KH
1312 :type 'boolean
1313 :group 'vhdl-comment)
1314
1315(defcustom vhdl-prompt-for-comments t
5eabfe72 1316 "*Non-nil means various templates prompt for user definable comments."
d2ddb974
KH
1317 :type 'boolean
1318 :group 'vhdl-comment)
1319
5eabfe72 1320(defcustom vhdl-inline-comment-column 40
3dcb36b7
JB
1321 "*Column to indent and align inline comments to.
1322Overrides local option `comment-column'.
5eabfe72 1323
3dcb36b7
JB
1324NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1325 \"Activate Options\"."
d2ddb974
KH
1326 :type 'integer
1327 :group 'vhdl-comment)
1328
1329(defcustom vhdl-end-comment-column 79
5eabfe72
KH
1330 "*End of comment column.
1331Comments that exceed this column number are wrapped.
1332
3dcb36b7
JB
1333NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1334 \"Activate Options\"."
d2ddb974
KH
1335 :type 'integer
1336 :group 'vhdl-comment)
1337
5eabfe72 1338(defvar end-comment-column)
d2ddb974
KH
1339
1340
5eabfe72
KH
1341(defgroup vhdl-align nil
1342 "Customizations for alignment."
d2ddb974
KH
1343 :group 'vhdl)
1344
5eabfe72
KH
1345(defcustom vhdl-auto-align t
1346 "*Non-nil means align some templates automatically after generation."
d2ddb974 1347 :type 'boolean
5eabfe72
KH
1348 :group 'vhdl-align)
1349
1350(defcustom vhdl-align-groups t
1351 "*Non-nil means align groups of code lines separately.
3dcb36b7
JB
1352A group of code lines is a region of consecutive lines between two lines that
1353match the regexp in option `vhdl-align-group-separate'."
1354 :type 'boolean
1355 :group 'vhdl-align)
1356
1357(defcustom vhdl-align-group-separate "^\\s-*$"
1358 "*Regexp for matching a line that separates groups of lines for alignment.
1359Examples:
1360 \"^\\s-*$\": matches an empty line
1361 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1362 :type 'regexp
1363 :group 'vhdl-align)
1364
1365(defcustom vhdl-align-same-indent t
1366 "*Non-nil means align blocks with same indent separately.
1367When a region or the entire buffer is aligned, the code is divided into
1368blocks of same indent which are aligned separately (except for argument/port
1369lists). This gives nicer alignment in most cases.
1370Option `vhdl-align-groups' still applies within these blocks."
5eabfe72
KH
1371 :type 'boolean
1372 :group 'vhdl-align)
1373
1374
1375(defgroup vhdl-highlight nil
1376 "Customizations for highlighting."
1377 :group 'vhdl)
d2ddb974
KH
1378
1379(defcustom vhdl-highlight-keywords t
5eabfe72
KH
1380 "*Non-nil means highlight VHDL keywords and other standardized words.
1381The following faces are used:
3dcb36b7
JB
1382 `font-lock-keyword-face' : keywords
1383 `font-lock-type-face' : standardized types
1384 `vhdl-font-lock-attribute-face': standardized attributes
1385 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1386 `vhdl-font-lock-function-face' : standardized function and package names
5eabfe72
KH
1387
1388NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1389 entry \"Fontify Buffer\")."
d2ddb974 1390 :type 'boolean
5eabfe72
KH
1391 :set (lambda (variable value)
1392 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1393 :group 'vhdl-highlight)
1394
5eabfe72
KH
1395(defcustom vhdl-highlight-names t
1396 "*Non-nil means highlight declaration names and construct labels.
1397The following faces are used:
3dcb36b7 1398 `font-lock-function-name-face' : names in declarations of units,
5eabfe72 1399 subprograms, components, as well as labels of VHDL constructs
3dcb36b7
JB
1400 `font-lock-type-face' : names in type/nature declarations
1401 `vhdl-font-lock-attribute-face': names in attribute declarations
1402 `font-lock-variable-name-face' : names in declarations of signals,
5eabfe72
KH
1403 variables, constants, subprogram parameters, generics, and ports
1404
1405NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1406 entry \"Fontify Buffer\")."
d2ddb974 1407 :type 'boolean
5eabfe72
KH
1408 :set (lambda (variable value)
1409 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1410 :group 'vhdl-highlight)
1411
5eabfe72
KH
1412(defcustom vhdl-highlight-special-words nil
1413 "*Non-nil means highlight words with special syntax.
3dcb36b7
JB
1414The words with syntax and color specified in option `vhdl-special-syntax-alist'
1415are highlighted accordingly.
5eabfe72
KH
1416Can be used for visual support of naming conventions.
1417
1418NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1419 entry \"Fontify Buffer\")."
d2ddb974 1420 :type 'boolean
5eabfe72
KH
1421 :set (lambda (variable value)
1422 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1423 :group 'vhdl-highlight)
1424
5eabfe72
KH
1425(defcustom vhdl-highlight-forbidden-words nil
1426 "*Non-nil means highlight forbidden words.
3dcb36b7
JB
1427The reserved words specified in option `vhdl-forbidden-words' or having the
1428syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
5eabfe72
KH
1429warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1430use them.
1431
1432NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1433 entry \"Fontify Buffer\")."
d2ddb974 1434 :type 'boolean
5eabfe72
KH
1435 :set (lambda (variable value)
1436 (vhdl-custom-set variable value
1437 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1438 :group 'vhdl-highlight)
1439
5eabfe72
KH
1440(defcustom vhdl-highlight-verilog-keywords nil
1441 "*Non-nil means highlight Verilog keywords as reserved words.
1442Verilog keywords are highlighted in a warning color (face
1443`vhdl-font-lock-reserved-words-face') to indicate not to use them.
2f402702 1444
5eabfe72 1445NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1446 entry \"Fontify Buffer\")."
d2ddb974 1447 :type 'boolean
5eabfe72
KH
1448 :set (lambda (variable value)
1449 (vhdl-custom-set variable value
1450 'vhdl-words-init 'vhdl-font-lock-init))
d2ddb974
KH
1451 :group 'vhdl-highlight)
1452
5eabfe72
KH
1453(defcustom vhdl-highlight-translate-off nil
1454 "*Non-nil means background-highlight code excluded from translation.
1455That is, all code between \"-- pragma translate_off\" and
1456\"-- pragma translate_on\" is highlighted using a different background color
1457\(face `vhdl-font-lock-translate-off-face').
1458Note: this might slow down on-the-fly fontification (and thus editing).
d2ddb974 1459
5eabfe72 1460NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1461 entry \"Fontify Buffer\")."
5eabfe72
KH
1462 :type 'boolean
1463 :set (lambda (variable value)
1464 (vhdl-custom-set variable value 'vhdl-font-lock-init))
d2ddb974
KH
1465 :group 'vhdl-highlight)
1466
5eabfe72
KH
1467(defcustom vhdl-highlight-case-sensitive nil
1468 "*Non-nil means consider case for highlighting.
1469Possible trade-off:
1470 non-nil also upper-case VHDL words are highlighted, but case of words with
1471 special syntax is not considered
1472 nil only lower-case VHDL words are highlighted, but case of words with
1473 special syntax is considered
3dcb36b7 1474Overrides local option `font-lock-keywords-case-fold-search'.
5eabfe72
KH
1475
1476NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1477 entry \"Fontify Buffer\")."
5eabfe72
KH
1478 :type 'boolean
1479 :group 'vhdl-highlight)
d2ddb974 1480
3dcb36b7
JB
1481(defcustom vhdl-special-syntax-alist
1482 '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
1483 ("type" "\\w+_t" "ForestGreen" "PaleGreen")
1484 ("variable" "\\w+_v" "Grey50" "Grey80"))
5eabfe72 1485 "*List of special syntax to be highlighted.
3dcb36b7 1486If option `vhdl-highlight-special-words' is non-nil, words with the specified
5eabfe72
KH
1487syntax (as regular expression) are highlighted in the corresponding color.
1488
1489 Name : string of words and spaces
1490 Regexp : regular expression describing word syntax
1491 (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
1492 Color (light): foreground color for light background
1493 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1494 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1495 Color (dark) : foreground color for dark background
1496 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1497 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1498
1499Can be used for visual support of naming conventions, such as highlighting
3dcb36b7 1500different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
5eabfe72 1501\"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
3dcb36b7 1502common substrings or name suffices.
5eabfe72
KH
1503For each entry, a new face is generated with the specified colors and name
1504\"vhdl-font-lock-\" + name + \"-face\".
1505
1506NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1507 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
5eabfe72
KH
1508 :type '(repeat (list :tag "Face" :indent 2
1509 (string :tag "Name ")
1510 (regexp :tag "Regexp " "\\w+_")
1511 (string :tag "Color (light)")
1512 (string :tag "Color (dark) ")))
1513 :set (lambda (variable value)
1514 (vhdl-custom-set variable value 'vhdl-font-lock-init))
1515 :group 'vhdl-highlight)
d2ddb974 1516
5eabfe72
KH
1517(defcustom vhdl-forbidden-words '()
1518 "*List of forbidden words to be highlighted.
3dcb36b7 1519If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
5eabfe72
KH
1520words are highlighted in a warning color to indicate not to use them.
1521
1522NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1523 entry \"Fontify Buffer\")."
5eabfe72
KH
1524 :type '(repeat (string :format "%v"))
1525 :set (lambda (variable value)
1526 (vhdl-custom-set variable value
1527 'vhdl-words-init 'vhdl-font-lock-init))
1528 :group 'vhdl-highlight)
d2ddb974 1529
5eabfe72
KH
1530(defcustom vhdl-forbidden-syntax ""
1531 "*Syntax of forbidden words to be highlighted.
3dcb36b7 1532If option `vhdl-highlight-forbidden-words' is non-nil, words with this
5eabfe72
KH
1533syntax are highlighted in a warning color to indicate not to use them.
1534Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1535highlights identifiers with 10 or more characters).
d2ddb974 1536
5eabfe72 1537NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
3dcb36b7 1538 entry \"Fontify Buffer\")."
d2ddb974 1539 :type 'regexp
5eabfe72
KH
1540 :set (lambda (variable value)
1541 (vhdl-custom-set variable value
1542 'vhdl-words-init 'vhdl-font-lock-init))
1543 :group 'vhdl-highlight)
d2ddb974 1544
3dcb36b7
JB
1545(defcustom vhdl-directive-keywords '("pragma" "synopsys")
1546 "*List of compiler directive keywords recognized for highlighting.
d2ddb974 1547
3dcb36b7
JB
1548NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1549 entry \"Fontify Buffer\")."
1550 :type '(repeat (string :format "%v"))
1551 :set (lambda (variable value)
1552 (vhdl-custom-set variable value
1553 'vhdl-words-init 'vhdl-font-lock-init))
1554 :group 'vhdl-highlight)
1555
1556
1557(defgroup vhdl-speedbar nil
1558 "Customizations for speedbar."
d2ddb974
KH
1559 :group 'vhdl)
1560
3dcb36b7
JB
1561(defcustom vhdl-speedbar-auto-open nil
1562 "*Non-nil means automatically open speedbar at startup.
5eabfe72 1563Alternatively, the speedbar can be opened from the VHDL menu."
d2ddb974 1564 :type 'boolean
3dcb36b7
JB
1565 :group 'vhdl-speedbar)
1566
1567(defcustom vhdl-speedbar-display-mode 'files
1568 "*Specifies the default displaying mode when opening speedbar.
1569Alternatively, the displaying mode can be selected from the speedbar menu or
1570by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1571 :type '(choice (const :tag "Files" files)
1572 (const :tag "Directory hierarchy" directory)
1573 (const :tag "Project hierarchy" project))
1574 :group 'vhdl-speedbar)
1575
1576(defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
1577 "*Limits scanning of large files and netlists.
1578Design units: maximum file size to scan for design units
1579Hierarchy (instances of subcomponents):
1580 File size: maximum file size to scan for instances (in bytes)
1581 Instances per arch: maximum number of instances to scan per architecture
1582
1583\"None\" always means that there is no limit.
1584In case of files not or incompletely scanned, a warning message and the file
1585names are printed out.
1586Background: scanning for instances is considerably slower than scanning for
1587design units, especially when there are many instances. These limits should
1588prevent the scanning of large netlists."
1589 :type '(list (choice :tag "Design units"
1590 :format "%t : %[Value Menu%] %v"
1591 (const :tag "None" nil)
1592 (integer :tag "File size"))
1593 (list :tag "Hierarchy" :indent 2
1594 (choice :tag "File size"
1595 :format "%t : %[Value Menu%] %v"
1596 (const :tag "None" nil)
1597 (integer :tag "Size "))
1598 (choice :tag "Instances per arch"
1599 (const :tag "None" nil)
1600 (integer :tag "Number "))))
1601 :group 'vhdl-speedbar)
1602
1603(defcustom vhdl-speedbar-jump-to-unit t
1604 "*Non-nil means jump to the design unit code when opened in a buffer.
1605The buffer cursor position is left unchanged otherwise."
1606 :type 'boolean
1607 :group 'vhdl-speedbar)
d2ddb974 1608
3dcb36b7
JB
1609(defcustom vhdl-speedbar-update-on-saving t
1610 "*Automatically update design hierarchy when buffer is saved."
d2ddb974 1611 :type 'boolean
3dcb36b7
JB
1612 :group 'vhdl-speedbar)
1613
1614(defcustom vhdl-speedbar-save-cache '(hierarchy display)
1615 "*Automatically save modified hierarchy caches when exiting Emacs.
1616 Hierarchy: design hierarchy information
1617 Display: displaying information (which design units to expand)"
1618 :type '(set (const :tag "Hierarchy" hierarchy)
1619 (const :tag "Display" display))
1620 :group 'vhdl-speedbar)
1621
1622(defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
1623 "*Name of file for saving hierarchy cache.
1624\"\\1\" is replaced by the project name if a project is specified,
1625\"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1626different users to have cache files in the same directory). Can also have
1627an absolute path (i.e. all caches can be stored in one global directory)."
1628 :type 'string
1629 :group 'vhdl-speedbar)
d2ddb974 1630
3dcb36b7
JB
1631
1632(defgroup vhdl-menu nil
1633 "Customizations for menues."
1634 :group 'vhdl)
5eabfe72
KH
1635
1636(defcustom vhdl-index-menu nil
1637 "*Non-nil means add an index menu for a source file when loading.
1638Alternatively, the speedbar can be used. Note that the index menu scans a file
3dcb36b7 1639when it is opened, while speedbar only scans the file upon request."
5eabfe72
KH
1640 :type 'boolean
1641 :group 'vhdl-menu)
1642
1643(defcustom vhdl-source-file-menu nil
1644 "*Non-nil means add a menu of all source files in current directory.
1645Alternatively, the speedbar can be used."
1646 :type 'boolean
1647 :group 'vhdl-menu)
1648
1649(defcustom vhdl-hideshow-menu nil
3dcb36b7
JB
1650 "*Non-nil means add hideshow menu and functionality at startup.
1651Hideshow can also be enabled from the VHDL Mode menu.
1652Hideshow allows hiding code of various VHDL constructs.
5eabfe72 1653
3dcb36b7
JB
1654NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1655 \"Activate Options\"."
5eabfe72
KH
1656 :type 'boolean
1657 :group 'vhdl-menu)
1658
1659(defcustom vhdl-hide-all-init nil
1660 "*Non-nil means hide all design units initially after a file is loaded."
d2ddb974
KH
1661 :type 'boolean
1662 :group 'vhdl-menu)
1663
1664
1665(defgroup vhdl-print nil
1666 "Customizations for printing."
1667 :group 'vhdl)
1668
1669(defcustom vhdl-print-two-column t
5eabfe72 1670 "*Non-nil means print code in two columns and landscape format.
3dcb36b7
JB
1671Adjusts settings in a way that postscript printing (\"File\" menu, `ps-print')
1672prints VHDL files in a nice two-column landscape style.
5eabfe72
KH
1673
1674NOTE: Activate the new setting by restarting Emacs.
1675 Overrides `ps-print' settings locally."
1676 :type 'boolean
1677 :group 'vhdl-print)
1678
1679(defcustom vhdl-print-customize-faces t
1680 "*Non-nil means use an optimized set of faces for postscript printing.
1681
1682NOTE: Activate the new setting by restarting Emacs.
1683 Overrides `ps-print' settings locally."
d2ddb974
KH
1684 :type 'boolean
1685 :group 'vhdl-print)
1686
1687
1688(defgroup vhdl-misc nil
1689 "Miscellaneous customizations."
1690 :group 'vhdl)
1691
1692(defcustom vhdl-intelligent-tab t
5eabfe72 1693 "*Non-nil means `TAB' does indentation, word completion and tab insertion.
d2ddb974
KH
1694That is, if preceeding character is part of a word then complete word,
1695else if not at beginning of line then insert tab,
1696else if last command was a `TAB' or `RET' then dedent one step,
5eabfe72 1697else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
d2ddb974 1698If nil, TAB always indents current line (i.e. `TAB' is bound to
3dcb36b7
JB
1699`indent-according-to-mode').
1700
1701NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1702 \"Activate Options\"."
1703 :type 'boolean
1704 :group 'vhdl-misc)
5eabfe72 1705
3dcb36b7
JB
1706(defcustom vhdl-indent-syntax-based t
1707 "*Non-nil means indent lines of code based on their syntactic context.
1708Otherwise, a line is indented like the previous nonblank line. This can be
1709useful in large files where syntax-based indentation gets very slow."
d2ddb974
KH
1710 :type 'boolean
1711 :group 'vhdl-misc)
1712
5eabfe72
KH
1713(defcustom vhdl-word-completion-case-sensitive nil
1714 "*Non-nil means word completion using `TAB' is case sensitive.
1715That is, `TAB' completes words that start with the same letters and case.
1716Otherwise, case is ignored."
1717 :type 'boolean
d2ddb974
KH
1718 :group 'vhdl-misc)
1719
1720(defcustom vhdl-word-completion-in-minibuffer t
5eabfe72
KH
1721 "*Non-nil enables word completion in minibuffer (for template prompts).
1722
1723NOTE: Activate the new setting by restarting Emacs."
d2ddb974
KH
1724 :type 'boolean
1725 :group 'vhdl-misc)
1726
1727(defcustom vhdl-underscore-is-part-of-word nil
5eabfe72 1728 "*Non-nil means consider the underscore character `_' as part of word.
d2ddb974 1729An identifier containing underscores is then treated as a single word in
5eabfe72
KH
1730select and move operations. All parts of an identifier separated by underscore
1731are treated as single words otherwise.
1732
3dcb36b7
JB
1733NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1734 \"Activate Options\"."
d2ddb974 1735 :type 'boolean
5eabfe72
KH
1736 :set (lambda (variable value)
1737 (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
d2ddb974
KH
1738 :group 'vhdl-misc)
1739
3dcb36b7
JB
1740
1741(defgroup vhdl-related nil
5eabfe72
KH
1742 "Related general customizations."
1743 :group 'vhdl)
1744
3dcb36b7
JB
1745;; add related general customizations
1746(custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
1747(if vhdl-xemacs
1748 (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
1749 (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
1750(custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
1751(custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
1752(custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
1753(unless vhdl-xemacs
1754 (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
1755(custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
1756(custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
1757(custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
1758
5eabfe72
KH
1759;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1760;; Internal variables
1761
3dcb36b7
JB
1762(defvar vhdl-menu-max-size 20
1763 "*Specifies the maximum size of a menu before splitting it into submenues.")
5eabfe72
KH
1764
1765(defvar vhdl-progress-interval 1
1766 "*Interval used to update progress status during long operations.
1767If a number, percentage complete gets updated after each interval of
3dcb36b7 1768that many seconds. To inhibit all messages, set this option to nil.")
d2ddb974
KH
1769
1770(defvar vhdl-inhibit-startup-warnings-p nil
1771 "*If non-nil, inhibits start up compatibility warnings.")
1772
1773(defvar vhdl-strict-syntax-p nil
1774 "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1775If the syntactic symbol for a particular line does not match a symbol
1776in the offsets alist, an error is generated, otherwise no error is
1777reported and the syntactic symbol is ignored.")
1778
1779(defvar vhdl-echo-syntactic-information-p nil
1780 "*If non-nil, syntactic info is echoed when the line is indented.")
1781
1782(defconst vhdl-offsets-alist-default
1783 '((string . -1000)
1784 (block-open . 0)
1785 (block-close . 0)
1786 (statement . 0)
1787 (statement-cont . vhdl-lineup-statement-cont)
1788 (statement-block-intro . +)
1789 (statement-case-intro . +)
1790 (case-alternative . +)
1791 (comment . vhdl-lineup-comment)
1792 (arglist-intro . +)
1793 (arglist-cont . 0)
1794 (arglist-cont-nonempty . vhdl-lineup-arglist)
1795 (arglist-close . vhdl-lineup-arglist)
1796 (entity . 0)
1797 (configuration . 0)
1798 (package . 0)
1799 (architecture . 0)
1800 (package-body . 0)
1801 )
1802 "Default settings for offsets of syntactic elements.
1803Do not change this constant! See the variable `vhdl-offsets-alist' for
1804more information.")
1805
1806(defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
1807 "*Association list of syntactic element symbols and indentation offsets.
1808As described below, each cons cell in this list has the form:
1809
1810 (SYNTACTIC-SYMBOL . OFFSET)
1811
5eabfe72 1812When a line is indented, `vhdl-mode' first determines the syntactic
d2ddb974
KH
1813context of the line by generating a list of symbols called syntactic
1814elements. This list can contain more than one syntactic element and
1815the global variable `vhdl-syntactic-context' contains the context list
1816for the line being indented. Each element in this list is actually a
1817cons cell of the syntactic symbol and a buffer position. This buffer
1818position is call the relative indent point for the line. Some
1819syntactic symbols may not have a relative indent point associated with
1820them.
1821
5eabfe72 1822After the syntactic context list for a line is generated, `vhdl-mode'
d2ddb974
KH
1823calculates the absolute indentation for the line by looking at each
1824syntactic element in the list. First, it compares the syntactic
1825element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
1826finds a match, it adds the OFFSET to the column of the relative indent
1827point. The sum of this calculation for each element in the syntactic
1828list is the absolute offset for line being indented.
1829
1830If the syntactic element does not match any in the `vhdl-offsets-alist',
1831an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
1832the element is ignored.
1833
1834Actually, OFFSET can be an integer, a function, a variable, or one of
1835the following symbols: `+', `-', `++', or `--'. These latter
1836designate positive or negative multiples of `vhdl-basic-offset',
5eabfe72 1837respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
d2ddb974
KH
1838called with a single argument containing the cons of the syntactic
1839element symbol and the relative indent point. The function should
1840return an integer offset.
1841
1842Here is the current list of valid syntactic element symbols:
1843
1844 string -- inside multi-line string
1845 block-open -- statement block open
1846 block-close -- statement block close
1847 statement -- a VHDL statement
1848 statement-cont -- a continuation of a VHDL statement
1849 statement-block-intro -- the first line in a new statement block
1850 statement-case-intro -- the first line in a case alternative block
1851 case-alternative -- a case statement alternative clause
1852 comment -- a line containing only a comment
1853 arglist-intro -- the first line in an argument list
1854 arglist-cont -- subsequent argument list lines when no
1855 arguments follow on the same line as the
1856 the arglist opening paren
1857 arglist-cont-nonempty -- subsequent argument list lines when at
1858 least one argument follows on the same
1859 line as the arglist opening paren
1860 arglist-close -- the solo close paren of an argument list
1861 entity -- inside an entity declaration
1862 configuration -- inside a configuration declaration
1863 package -- inside a package declaration
1864 architecture -- inside an architecture body
5eabfe72 1865 package-body -- inside a package body")
d2ddb974
KH
1866
1867(defvar vhdl-comment-only-line-offset 0
1868 "*Extra offset for line which contains only the start of a comment.
1869Can contain an integer or a cons cell of the form:
1870
1871 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
1872
1873Where NON-ANCHORED-OFFSET is the amount of offset given to
1874non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
1875the amount of offset to give column-zero anchored comment-only lines.
1876Just an integer as value is equivalent to (<val> . 0)")
1877
1878(defvar vhdl-special-indent-hook nil
1879 "*Hook for user defined special indentation adjustments.
1880This hook gets called after a line is indented by the mode.")
1881
1882(defvar vhdl-style-alist
1883 '(("IEEE"
1884 (vhdl-basic-offset . 4)
3dcb36b7 1885 (vhdl-offsets-alist . ())))
d2ddb974
KH
1886 "Styles of Indentation.
1887Elements of this alist are of the form:
1888
1889 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
1890
1891where STYLE-STRING is a short descriptive string used to select a
5eabfe72 1892style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
d2ddb974
KH
1893value for that variable when using the selected style.
1894
1895There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
1896case, the VALUE is a list containing elements of the form:
1897
1898 (SYNTACTIC-SYMBOL . VALUE)
1899
1900as described in `vhdl-offsets-alist'. These are passed directly to
1901`vhdl-set-offset' so there is no need to set every syntactic symbol in
1902your style, only those that are different from the default.")
1903
1904;; dynamically append the default value of most variables
1905(or (assoc "Default" vhdl-style-alist)
1906 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
1907 vhdl-strict-syntax-p
1908 vhdl-echo-syntactic-information-p
1909 vhdl-basic-offset
1910 vhdl-offsets-alist
1911 vhdl-comment-only-line-offset))
1912 (default (cons "Default"
1913 (mapcar
1914 (function
1915 (lambda (var)
5eabfe72 1916 (cons var (symbol-value var))))
d2ddb974
KH
1917 varlist))))
1918 (setq vhdl-style-alist (cons default vhdl-style-alist))))
1919
1920(defvar vhdl-mode-hook nil
1921 "*Hook called by `vhdl-mode'.")
1922
1923
5eabfe72 1924;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 1925;;; Required packages
5eabfe72 1926;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5eabfe72 1927
3dcb36b7 1928;; mandatory
5eabfe72 1929(require 'assoc)
3dcb36b7
JB
1930(require 'compile) ; XEmacs
1931(require 'easymenu)
1932(require 'hippie-exp)
1933
1934;; optional (minimize warning messages during compile)
1935(eval-when-compile
1936 (require 'font-lock)
1937 (require 'ps-print)
1938 (require 'speedbar))
5eabfe72
KH
1939
1940
1941;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 1942;;; Compatibility
5eabfe72 1943;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 1944
3dcb36b7
JB
1945;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1946;; XEmacs compatibility
d2ddb974 1947
3dcb36b7 1948;; active regions
d2ddb974 1949(defun vhdl-keep-region-active ()
5eabfe72
KH
1950 "Do whatever is necessary to keep the region active in XEmacs.
1951Ignore byte-compiler warnings you might see."
d2ddb974
KH
1952 (and (boundp 'zmacs-region-stays)
1953 (setq zmacs-region-stays t)))
1954
3dcb36b7 1955;; `wildcard-to-regexp' is included only in XEmacs 21
5eabfe72
KH
1956(unless (fboundp 'wildcard-to-regexp)
1957 (defun wildcard-to-regexp (wildcard)
1958 "Simplified version of `wildcard-to-regexp' from Emacs' `files.el'."
1959 (let* ((i (string-match "[*?]" wildcard))
1960 (result (substring wildcard 0 i))
1961 (len (length wildcard)))
1962 (when i
1963 (while (< i len)
1964 (let ((ch (aref wildcard i)))
1965 (setq result (concat result
1966 (cond ((eq ch ?*) "[^\000]*")
1967 ((eq ch ??) "[^\000]")
1968 (t (char-to-string ch)))))
1969 (setq i (1+ i)))))
1970 (concat "\\`" result "\\'"))))
1971
3dcb36b7
JB
1972;; `regexp-opt' undefined (`xemacs-devel' not installed)
1973;; `regexp-opt' accelerates fontification by 10-20%
1974(unless (fboundp 'regexp-opt)
1975; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
1976 (defun regexp-opt (strings &optional paren)
1977 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
1978 (concat open (mapconcat 'regexp-quote strings "\\|") close))))
1979
1980;; `match-string-no-properties' undefined (XEmacs, what else?)
1981(unless (fboundp 'match-string-no-properties)
1982 (defalias 'match-string-no-properties 'match-string))
1983
1984;; `subst-char-in-string' undefined (XEmacs)
1985(unless (fboundp 'subst-char-in-string)
1986 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1987 (let ((i (length string))
1988 (newstr (if inplace string (copy-sequence string))))
1989 (while (> i 0)
1990 (setq i (1- i))
1991 (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
1992 newstr)))
1993
1994;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
1995(when (and vhdl-xemacs (string< itimer-version "1.09")
1996 (not noninteractive))
1997 (load "itimer")
1998 (when (string< itimer-version "1.09")
1999 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2000 (beep) (sit-for 5)))
2001
2002;; `file-expand-wildcards' undefined (XEmacs)
2003(unless (fboundp 'file-expand-wildcards)
2004 (defun file-expand-wildcards (pattern &optional full)
2005 "Taken from Emacs' `files.el'."
2006 (let* ((nondir (file-name-nondirectory pattern))
2007 (dirpart (file-name-directory pattern))
2008 (dirs (if (and dirpart (string-match "[[*?]" dirpart))
2009 (mapcar 'file-name-as-directory
2010 (file-expand-wildcards (directory-file-name dirpart)))
2011 (list dirpart)))
2012 contents)
2013 (while dirs
2014 (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
2015 (file-directory-p (directory-file-name (car dirs))))
2016 (let ((this-dir-contents
2017 (delq nil
2018 (mapcar #'(lambda (name)
2019 (unless (string-match "\\`\\.\\.?\\'"
2020 (file-name-nondirectory name))
2021 name))
2022 (directory-files (or (car dirs) ".") full
2023 (wildcard-to-regexp nondir))))))
2024 (setq contents
2025 (nconc
2026 (if (and (car dirs) (not full))
2027 (mapcar (function (lambda (name) (concat (car dirs) name)))
2028 this-dir-contents)
2029 this-dir-contents)
2030 contents))))
2031 (setq dirs (cdr dirs)))
2032 contents)))
5eabfe72
KH
2033
2034;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2035;; Compatibility with older VHDL Mode versions
5eabfe72 2036
3dcb36b7
JB
2037(defvar vhdl-warnings nil
2038 "Warnings to tell the user during start up.")
d2ddb974 2039
3dcb36b7
JB
2040(defun vhdl-run-when-idle (secs repeat function)
2041 "Wait until idle, then run FUNCTION."
4bcb9c95 2042 (if (fboundp 'start-itimer)
3dcb36b7
JB
2043 (start-itimer "vhdl-mode" function secs repeat t)
2044; (run-with-idle-timer secs repeat function)))
2045 ;; explicitely activate timer (necessary when Emacs is already idle)
2046 (aset (run-with-idle-timer secs repeat function) 0 nil)))
2047
2048(defun vhdl-warning-when-idle (&rest args)
2049 "Wait until idle, then print out warning STRING and beep."
2050 (if noninteractive
2051 (vhdl-warning (apply 'format args) t)
2052 (unless vhdl-warnings
2053 (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
2054 (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
2055
2056(defun vhdl-warning (string &optional nobeep)
2057 "Print out warning STRING and beep."
2058 (message (concat "WARNING: " string))
2059 (unless (or nobeep noninteractive) (beep)))
d2ddb974 2060
3dcb36b7
JB
2061(defun vhdl-print-warnings ()
2062 "Print out messages in variable `vhdl-warnings'."
2063 (let ((no-warnings (length vhdl-warnings)))
2064 (setq vhdl-warnings (nreverse vhdl-warnings))
2065 (while vhdl-warnings
2066 (message (concat "WARNING: " (car vhdl-warnings)))
2067 (setq vhdl-warnings (cdr vhdl-warnings)))
2068 (beep)
2069 (when (> no-warnings 1)
2070 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2071
2072;; Backward compatibility checks and fixes
2073;; option `vhdl-compiler' changed format
2074(unless (stringp vhdl-compiler)
2075 (setq vhdl-compiler "ModelSim")
2076 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2077
2078;; option `vhdl-standard' changed format
2079(unless (listp vhdl-standard)
2080 (setq vhdl-standard '(87 nil))
2081 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2082
2083;; option `vhdl-model-alist' changed format
2084(when (= (length (car vhdl-model-alist)) 3)
2085 (let ((old-alist vhdl-model-alist)
2086 new-alist)
2087 (while old-alist
2088 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2089 (setq old-alist (cdr old-alist)))
2090 (setq vhdl-model-alist (nreverse new-alist)))
2091 (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
2092
2093;; option `vhdl-project-alist' changed format
2094(when (= (length (car vhdl-project-alist)) 3)
2095 (let ((old-alist vhdl-project-alist)
2096 new-alist)
2097 (while old-alist
2098 (setq new-alist (cons (append (car old-alist) '("")) new-alist))
2099 (setq old-alist (cdr old-alist)))
2100 (setq vhdl-project-alist (nreverse new-alist)))
2101 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2102
2103;; option `vhdl-project-alist' changed format (3.31.1)
2104(when (= (length (car vhdl-project-alist)) 4)
2105 (let ((old-alist vhdl-project-alist)
2106 new-alist elem)
2107 (while old-alist
2108 (setq elem (car old-alist))
2109 (setq new-alist
2110 (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
2111 nil "./" "work" "work/" "Makefile" (nth 3 elem))
2112 new-alist))
2113 (setq old-alist (cdr old-alist)))
2114 (setq vhdl-project-alist (nreverse new-alist)))
2115 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2116
2117;; option `vhdl-project-alist' changed format (3.31.12)
2118(when (= (length (car vhdl-project-alist)) 10)
2119 (let ((tmp-alist vhdl-project-alist))
2120 (while tmp-alist
2121 (setcdr (nthcdr 3 (car tmp-alist))
2122 (cons "" (nthcdr 4 (car tmp-alist))))
2123 (setq tmp-alist (cdr tmp-alist))))
2124 (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
2125
2126;; option `vhdl-compiler-alist' changed format (3.31.1)
2127(when (= (length (car vhdl-compiler-alist)) 7)
2128 (let ((old-alist vhdl-compiler-alist)
2129 new-alist elem)
2130 (while old-alist
2131 (setq elem (car old-alist))
2132 (setq new-alist
2133 (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
2134 (if (equal (nth 3 elem) "") nil (nth 3 elem))
2135 (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
2136 (nth 5 elem) (nth 6 elem) nil)
2137 new-alist))
2138 (setq old-alist (cdr old-alist)))
2139 (setq vhdl-compiler-alist (nreverse new-alist)))
2140 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2141
2142;; option `vhdl-compiler-alist' changed format (3.31.10)
2143(when (= (length (car vhdl-compiler-alist)) 12)
2144 (let ((tmp-alist vhdl-compiler-alist))
2145 (while tmp-alist
2146 (setcdr (nthcdr 4 (car tmp-alist))
2147 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
2148 (setq tmp-alist (cdr tmp-alist))))
2149 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2150
2151;; option `vhdl-compiler-alist' changed format (3.31.11)
2152(when (= (length (car vhdl-compiler-alist)) 13)
2153 (let ((tmp-alist vhdl-compiler-alist))
2154 (while tmp-alist
2155 (setcdr (nthcdr 3 (car tmp-alist))
2156 (cons "" (nthcdr 4 (car tmp-alist))))
2157 (setq tmp-alist (cdr tmp-alist))))
2158 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2159
2160;; option `vhdl-compiler-alist' changed format (3.32.7)
2161(when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
2162 (let ((tmp-alist vhdl-compiler-alist))
2163 (while tmp-alist
2164 (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
2165 '(0 . nil))
2166 (setq tmp-alist (cdr tmp-alist))))
2167 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
2168
2169;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2170(when (equal vhdl-project "")
2171 (setq vhdl-project nil)
2172 (customize-save-variable 'vhdl-project vhdl-project))
2173
2174;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2175(when (stringp vhdl-project-file-name)
2176 (setq vhdl-project-file-name (list vhdl-project-file-name))
2177 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
2178
2179;; option `speedbar-indentation-width': introduced in speedbar 0.10
2180(if (not (boundp 'speedbar-indentation-width))
2181 (defvar speedbar-indentation-width 2)
2182 ;; set default to 2 if not already customized
2183 (unless (get 'speedbar-indentation-width 'saved-value)
2184 (setq speedbar-indentation-width 2)))
2185
2186
2187;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2188;;; Help functions / inline substitutions / macros
2189;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190
2191(defun vhdl-standard-p (standard)
2192 "Check if STANDARD is specified as used standard."
2193 (or (eq standard (car vhdl-standard))
2194 (memq standard (cadr vhdl-standard))))
2195
2196(defun vhdl-project-p (&optional warning)
2197 "Return non-nil if a project is displayed, i.e. directories or files are
2198specified."
2199 (if (assoc vhdl-project vhdl-project-alist)
2200 vhdl-project
2201 (when (and vhdl-project warning)
2202 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
2203 nil))
2204
2205(defun vhdl-resolve-env-variable (string)
2206 "Resolve environment variables in STRING."
2207 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
2208 (setq string (concat (match-string 1 string)
2209 (getenv (match-string 2 string))
2210 (match-string 4 string))))
2211 string)
2212
2213(defun vhdl-default-directory ()
2214 "Return the default directory of the current project or the directory of the
2215current buffer if no project is defined."
2216 (if (vhdl-project-p)
2217 (expand-file-name (vhdl-resolve-env-variable
2218 (nth 1 (aget vhdl-project-alist vhdl-project))))
2219 default-directory))
2220
2221(defmacro vhdl-prepare-search-1 (&rest body)
2222 "Enable case insensitive search and switch to syntax table that includes '_',
2223then execute BODY, and finally restore the old environment. Used for
2224consistent searching."
2225 `(let ((case-fold-search t) ; case insensitive search
2226 (current-syntax-table (syntax-table))
2227 result
2228 (restore-prog ; program to restore enviroment
2229 '(progn
2230 ;; restore syntax table
2231 (set-syntax-table current-syntax-table))))
2232 ;; use extended syntax table
2233 (set-syntax-table vhdl-mode-ext-syntax-table)
2234 ;; execute BODY safely
2235 (setq result
2236 (condition-case info
2237 (progn ,@body)
2238 (error (eval restore-prog) ; restore environment on error
2239 (error (cadr info))))) ; pass error up
2240 ;; restore environment
2241 (eval restore-prog)
2242 result))
2243
2244(defmacro vhdl-prepare-search-2 (&rest body)
2245 "Enable case insensitive search, switch to syntax table that includes '_',
2246and remove `intangible' overlays, then execute BODY, and finally restore the
2247old environment. Used for consistent searching."
2248 `(let ((case-fold-search t) ; case insensitive search
2249 (current-syntax-table (syntax-table))
2250 result overlay-all-list overlay-intangible-list overlay
2251 (restore-prog ; program to restore enviroment
2252 '(progn
2253 ;; restore syntax table
2254 (set-syntax-table current-syntax-table)
2255 ;; restore `intangible' overlays
2256 (when (fboundp 'overlay-lists)
2257 (while overlay-intangible-list
2258 (overlay-put (car overlay-intangible-list) 'intangible t)
2259 (setq overlay-intangible-list
2260 (cdr overlay-intangible-list)))))))
2261 ;; use extended syntax table
2262 (set-syntax-table vhdl-mode-ext-syntax-table)
2263 ;; remove `intangible' overlays
2264 (when (fboundp 'overlay-lists)
2265 (setq overlay-all-list (overlay-lists))
2266 (setq overlay-all-list
2267 (append (car overlay-all-list) (cdr overlay-all-list)))
2268 (while overlay-all-list
2269 (setq overlay (car overlay-all-list))
2270 (when (memq 'intangible (overlay-properties overlay))
2271 (setq overlay-intangible-list
2272 (cons overlay overlay-intangible-list))
2273 (overlay-put overlay 'intangible nil))
2274 (setq overlay-all-list (cdr overlay-all-list))))
2275 ;; execute BODY safely
2276 (setq result
2277 (condition-case info
2278 (progn ,@body)
2279 (error (eval restore-prog) ; restore environment on error
2280 (error (cadr info))))) ; pass error up
2281 ;; restore environment
2282 (eval restore-prog)
2283 result))
2284
2285(defmacro vhdl-visit-file (file-name issue-error &rest body)
2286 "Visit file FILE-NAME and execute BODY."
2287 `(if (null ,file-name)
2288 (progn ,@body)
2289 (unless (file-directory-p ,file-name)
2290 (let ((source-buffer (current-buffer))
2291 (visiting-buffer (find-buffer-visiting ,file-name))
2292 file-opened)
2293 (when (or (and visiting-buffer (set-buffer visiting-buffer))
2294 (condition-case ()
2295 (progn (set-buffer (create-file-buffer ,file-name))
2296 (setq file-opened t)
2297 (vhdl-insert-file-contents ,file-name)
2298 (modify-syntax-entry ?\- ". 12" (syntax-table))
2299 (modify-syntax-entry ?\n ">" (syntax-table))
2300 (modify-syntax-entry ?\^M ">" (syntax-table))
2301 (modify-syntax-entry ?_ "w" (syntax-table))
2302 t)
2303 (error
2304 (if ,issue-error
2305 (progn
2306 (when file-opened (kill-buffer (current-buffer)))
2307 (set-buffer source-buffer)
2308 (error (format "ERROR: File cannot be opened: \"%s\"" ,file-name)))
2309 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
2310 nil))))
2311 (condition-case info
2312 (progn ,@body)
2313 (error
2314 (if ,issue-error
2315 (progn
2316 (when file-opened (kill-buffer (current-buffer)))
2317 (set-buffer source-buffer)
2318 (error (cadr info)))
2319 (vhdl-warning (cadr info))))))
2320 (when file-opened (kill-buffer (current-buffer)))
2321 (set-buffer source-buffer)))))
2322
2323(defun vhdl-insert-file-contents (filename)
2324 "Nicked from `insert-file-contents-literally', but allow coding system
2325conversion."
2326 (let ((format-alist nil)
2327 (after-insert-file-functions nil)
2328 (jka-compr-compression-info-list nil))
2329 (insert-file-contents filename t)))
2330
2331(defun vhdl-sort-alist (alist)
2332 "Sort alist."
2333 (sort alist (function (lambda (a b) (string< (car a) (car b))))))
2334
2335(defun vhdl-get-subdirs (directory)
2336 "Recursively get subdirectories of DIRECTORY."
2337 (let ((dir-list (list (file-name-as-directory directory)))
2338 file-list)
2339 (setq file-list (vhdl-directory-files directory t "\\w.*"))
2340 (while file-list
2341 (when (file-directory-p (car file-list))
2342 (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
2343 (setq file-list (cdr file-list)))
2344 dir-list))
2345
2346(defun vhdl-aput (alist-symbol key &optional value)
2347 "As `aput', but delete key-value pair if VALUE is nil."
2348 (if value
2349 (aput alist-symbol key value)
2350 (adelete alist-symbol key)))
2351
2352(defun vhdl-delete (elt list)
2353 "Delete by side effect the first occurrence of ELT as a member of LIST."
2354 (setq list (cons nil list))
2355 (let ((list1 list))
2356 (while (and (cdr list1) (not (equal elt (cadr list1))))
2357 (setq list1 (cdr list1)))
2358 (when list
2359 (setcdr list1 (cddr list1))))
2360 (cdr list))
2361
2362(defun vhdl-speedbar-refresh (&optional key)
2363 "Refresh directory or project with name KEY."
2364 (when (and (boundp 'speedbar-frame)
2365 (frame-live-p speedbar-frame))
2366 (let ((pos (point))
2367 (last-frame (selected-frame)))
2368 (if (null key)
2369 (speedbar-refresh)
2370 (select-frame speedbar-frame)
2371 (when (save-excursion
2372 (goto-char (point-min))
2373 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
2374 (goto-char (match-end 1))
2375 (speedbar-do-function-pointer)
2376 (backward-char 2)
2377 (speedbar-do-function-pointer)
2378 (message "Refreshing speedbar...done"))
2379 (select-frame last-frame)))))
2380
2381(defun vhdl-show-messages ()
2382 "Get *Messages* buffer to show recent messages."
2383 (interactive)
2384 (display-buffer (if vhdl-xemacs " *Message-Log*" "*Messages*")))
2385
2386(defun vhdl-use-direct-instantiation ()
2387 "Return whether direct instantiation is used."
2388 (or (eq vhdl-use-direct-instantiation 'always)
2389 (and (eq vhdl-use-direct-instantiation 'standard)
2390 (not (vhdl-standard-p '87)))))
2391
2392(defun vhdl-max-marker (marker1 marker2)
2393 "Return larger marker."
2394 (if (> marker1 marker2) marker1 marker2))
2395
2396(defun vhdl-goto-marker (marker)
2397 "Goto marker in appropriate buffer."
2398 (when (markerp marker)
2399 (set-buffer (marker-buffer marker)))
2400 (goto-char marker))
2401
2402(defun vhdl-menu-split (list title)
2403 "Split menu LIST into several submenues, if number of
2404elements > `vhdl-menu-max-size'."
2405 (if (> (length list) vhdl-menu-max-size)
2406 (let ((remain list)
2407 (result '())
2408 (sublist '())
2409 (menuno 1)
2410 (i 0))
2411 (while remain
2412 (setq sublist (cons (car remain) sublist))
2413 (setq remain (cdr remain))
2414 (setq i (+ i 1))
2415 (if (= i vhdl-menu-max-size)
2416 (progn
2417 (setq result (cons (cons (format "%s %s" title menuno)
2418 (nreverse sublist)) result))
2419 (setq i 0)
2420 (setq menuno (+ menuno 1))
2421 (setq sublist '()))))
2422 (and sublist
2423 (setq result (cons (cons (format "%s %s" title menuno)
2424 (nreverse sublist)) result)))
2425 (nreverse result))
2426 list))
2427
2428
2429;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2430;;; Bindings
2431;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2432
2433;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2434;; Key bindings
2435
2436(defvar vhdl-template-map nil
2437 "Keymap for VHDL templates.")
2438
2439(defun vhdl-template-map-init ()
2440 "Initialize `vhdl-template-map'."
2441 (setq vhdl-template-map (make-sparse-keymap))
2442 ;; key bindings for VHDL templates
2443 (define-key vhdl-template-map "al" 'vhdl-template-alias)
2444 (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
2445 (define-key vhdl-template-map "at" 'vhdl-template-assert)
2446 (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
2447 (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
2448 (define-key vhdl-template-map "bl" 'vhdl-template-block)
2449 (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
2450 (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
2451 (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
5eabfe72
KH
2452 (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
2453 (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
2454 (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
2455 (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
2456 (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
2457 (define-key vhdl-template-map "co" 'vhdl-template-constant)
2458 (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
2459 (define-key vhdl-template-map "el" 'vhdl-template-else)
2460 (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
2461 (define-key vhdl-template-map "en" 'vhdl-template-entity)
2462 (define-key vhdl-template-map "ex" 'vhdl-template-exit)
2463 (define-key vhdl-template-map "fi" 'vhdl-template-file)
2464 (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
2465 (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
2466 (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
2467 (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
2468 (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
2469 (define-key vhdl-template-map "ge" 'vhdl-template-generic)
2470 (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
2471 (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
2472 (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
2473 (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
2474 (define-key vhdl-template-map "it" 'vhdl-template-if-then)
2475 (define-key vhdl-template-map "li" 'vhdl-template-library)
2476 (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
2477 (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
2478 (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
2479 (define-key vhdl-template-map "ma" 'vhdl-template-map)
2480 (define-key vhdl-template-map "ne" 'vhdl-template-next)
2481 (define-key vhdl-template-map "ot" 'vhdl-template-others)
2482 (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
2483 (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
2484 (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
2485 (define-key vhdl-template-map "po" 'vhdl-template-port)
2486 (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
2487 (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
2488 (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
2489 (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
2490 (define-key vhdl-template-map "rp" 'vhdl-template-report)
2491 (define-key vhdl-template-map "rt" 'vhdl-template-return)
2492 (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
2493 (define-key vhdl-template-map "si" 'vhdl-template-signal)
2494 (define-key vhdl-template-map "su" 'vhdl-template-subtype)
2495 (define-key vhdl-template-map "ty" 'vhdl-template-type)
2496 (define-key vhdl-template-map "us" 'vhdl-template-use)
2497 (define-key vhdl-template-map "va" 'vhdl-template-variable)
2498 (define-key vhdl-template-map "wa" 'vhdl-template-wait)
2499 (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
2500 (define-key vhdl-template-map "wi" 'vhdl-template-with)
2501 (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
2502 (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
2503 (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
2504 (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
2505 (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
2506 (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
2507 (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
2508 (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
2509 (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
2510 (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
2511 (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
2512 (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
2513 (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
2514 (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
2515 (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
2516 (when (vhdl-standard-p 'ams)
2517 (define-key vhdl-template-map "br" 'vhdl-template-break)
2518 (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
2519 (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
2520 (define-key vhdl-template-map "lm" 'vhdl-template-limit)
2521 (define-key vhdl-template-map "na" 'vhdl-template-nature)
2522 (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
2523 (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
2524 (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
2525 (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
2526 (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
2527 (define-key vhdl-template-map "te" 'vhdl-template-terminal)
2528 )
2529 (when (vhdl-standard-p 'math)
2530 (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
2531 (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
2532 ))
2533
2534;; initialize template map for VHDL Mode
2535(vhdl-template-map-init)
2536
2537(defun vhdl-function-name (prefix string &optional postfix)
2538 "Generate a Lisp function name.
2539PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2540STRING are replaced by `-' and substrings are converted to lower case."
2541 (let ((name prefix))
2542 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
2543 (setq name
2544 (concat name "-" (downcase (substring string 0 (match-end 1)))))
2545 (setq string (substring string (match-beginning 2))))
2546 (when postfix (setq name (concat name "-" postfix)))
2547 (intern name)))
2548
3dcb36b7 2549(defvar vhdl-model-map nil
5eabfe72
KH
2550 "Keymap for VHDL models.")
2551
2552(defun vhdl-model-map-init ()
2553 "Initialize `vhdl-model-map'."
2554 (setq vhdl-model-map (make-sparse-keymap))
2555 ;; key bindings for VHDL models
2556 (let ((model-alist vhdl-model-alist) model)
2557 (while model-alist
2558 (setq model (car model-alist))
2559 (define-key vhdl-model-map (nth 2 model)
2560 (vhdl-function-name "vhdl-model" (nth 0 model)))
2561 (setq model-alist (cdr model-alist)))))
2562
2563;; initialize user model map for VHDL Mode
2564(vhdl-model-map-init)
d2ddb974 2565
3dcb36b7 2566(defvar vhdl-mode-map nil
d2ddb974
KH
2567 "Keymap for VHDL Mode.")
2568
5eabfe72
KH
2569(defun vhdl-mode-map-init ()
2570 "Initialize `vhdl-mode-map'."
d2ddb974 2571 (setq vhdl-mode-map (make-sparse-keymap))
5eabfe72
KH
2572 ;; template key bindings
2573 (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
2574 ;; model key bindings
2575 (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
d2ddb974 2576 ;; standard key bindings
5eabfe72
KH
2577 (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
2578 (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
2579 (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
2580 (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
2581 (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
3dcb36b7
JB
2582 (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
2583 (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
2584 (unless vhdl-xemacs ; would override `M-backspace' in XEmacs
2585 (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
5eabfe72 2586 (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
3dcb36b7 2587 (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
5eabfe72
KH
2588 ;; backspace/delete key bindings
2589 (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
3dcb36b7
JB
2590 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
2591 (define-key vhdl-mode-map [delete] 'delete-char)
2592 (define-key vhdl-mode-map [(meta delete)] 'kill-word))
5eabfe72 2593 ;; mode specific key bindings
3dcb36b7
JB
2594 (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
2595 (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
2596 (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
2597 (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
2598 (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
2599 (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
2600 (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
5eabfe72
KH
2601 (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
2602 (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
3dcb36b7 2603 (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
5eabfe72
KH
2604 (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
2605 (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
2606 (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
2607 (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
2608 (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
2609 (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
2610 (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
3dcb36b7 2611 (if vhdl-xemacs ; `... C-g' not allowed in XEmacs
5eabfe72
KH
2612 (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
2613 (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
3dcb36b7 2614 (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
5eabfe72
KH
2615 (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
2616 (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
3dcb36b7
JB
2617 (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
2618 (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
2619 (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
2620 (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
2621 (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
2622 (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
2623 (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
2624 (define-key vhdl-mode-map "\C-c\C-c\C-n" 'vhdl-compose-new-component)
2625 (define-key vhdl-mode-map "\C-c\C-c\C-p" 'vhdl-compose-place-component)
2626 (define-key vhdl-mode-map "\C-c\C-c\C-w" 'vhdl-compose-wire-components)
2627 (define-key vhdl-mode-map "\C-c\C-c\C-k" 'vhdl-compose-components-package)
2628 (define-key vhdl-mode-map "\C-cc" 'vhdl-comment-uncomment-region)
5eabfe72
KH
2629 (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
2630 (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
3dcb36b7
JB
2631 (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
2632 (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
5eabfe72 2633 (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
3dcb36b7
JB
2634 (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
2635 (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
2636 (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
2637 (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
2638 (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
2639 (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
2640 (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
2641 (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
2642 (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
2643 (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
2644 (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
2645 (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
2646 (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
2647 (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
2648 (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
5eabfe72
KH
2649 (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
2650 (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
2651 (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
2652 (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
2653 (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
2654 (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
2655 (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
2656 (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
2657 (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
3dcb36b7
JB
2658 (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
2659 (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
2660 (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
2661 (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
2662 (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
2663 (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
2664 (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
2665 (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
2666 (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
2667 (define-key vhdl-mode-map "\C-cf" 'vhdl-fontify-buffer)
2668 (define-key vhdl-mode-map "\C-cs" 'vhdl-statistics-buffer)
2669 (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
5eabfe72
KH
2670 (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
2671 (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
3dcb36b7 2672 (define-key vhdl-mode-map "\M-\t" 'insert-tab)
5eabfe72 2673 ;; insert commands bindings
3dcb36b7 2674 (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
5eabfe72
KH
2675 (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
2676 (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
2677 (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
2678 ;; electric key bindings
2679 (define-key vhdl-mode-map " " 'vhdl-electric-space)
d2ddb974 2680 (if vhdl-intelligent-tab
5eabfe72 2681 (define-key vhdl-mode-map "\t" 'vhdl-electric-tab)
4bcb9c95
SM
2682 ;; The default binding of TAB already calls `indent-according-to-mode'.
2683 ;; (define-key vhdl-mode-map "\t" 'indent-according-to-mode)
2684 )
5eabfe72
KH
2685 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2686 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2687 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2688 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2689 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2690 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2691 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2692 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2693 (when (vhdl-standard-p 'ams)
2694 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2695
2696;; initialize mode map for VHDL Mode
2697(vhdl-mode-map-init)
d2ddb974
KH
2698
2699;; define special minibuffer keymap for enabling word completion in minibuffer
2700;; (useful in template generator prompts)
4bcb9c95
SM
2701(defvar vhdl-minibuffer-local-map
2702 (let ((map (make-sparse-keymap)))
2703 (set-keymap-parent map minibuffer-local-map)
2704 (when vhdl-word-completion-in-minibuffer
2705 (define-key map "\t" 'vhdl-minibuffer-tab))
2706 map)
d2ddb974
KH
2707 "Keymap for minibuffer used in VHDL Mode.")
2708
5eabfe72
KH
2709;; set up electric character functions to work with
2710;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2711(mapcar
2712 (function
2713 (lambda (sym)
2714 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2715 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2716 '(vhdl-electric-space
2717 vhdl-electric-tab
2718 vhdl-electric-return
2719 vhdl-electric-dash
2720 vhdl-electric-open-bracket
2721 vhdl-electric-close-bracket
2722 vhdl-electric-quote
2723 vhdl-electric-semicolon
2724 vhdl-electric-comma
2725 vhdl-electric-period
2726 vhdl-electric-equal))
2727
3dcb36b7
JB
2728;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2729;; Syntax table
2730
d2ddb974 2731(defvar vhdl-mode-syntax-table nil
5eabfe72 2732 "Syntax table used in `vhdl-mode' buffers.")
d2ddb974 2733
3dcb36b7
JB
2734(defvar vhdl-mode-ext-syntax-table nil
2735 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2736
5eabfe72
KH
2737(defun vhdl-mode-syntax-table-init ()
2738 "Initialize `vhdl-mode-syntax-table'."
d2ddb974 2739 (setq vhdl-mode-syntax-table (make-syntax-table))
5eabfe72
KH
2740 ;; define punctuation
2741 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2742 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2743 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2744 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
2745 (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
2746 (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
2747 (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
2748 (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
2749 (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
2750 (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
2751 (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
2752 (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
2753 (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
2754 (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
2755 (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
2756 (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
2757 ;; define string
2758 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2759 ;; define underscore
2760 (when vhdl-underscore-is-part-of-word
3dcb36b7 2761 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
5eabfe72
KH
2762 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2763 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2764 ;; and \n and \^M end a comment
2765 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2766 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2767 ;; define parentheses to match
2768 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2769 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2770 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2771 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2772 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
3dcb36b7
JB
2773 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2774 ;; extended syntax table including '_' (for simpler search regexps)
2775 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2776 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
5eabfe72
KH
2777
2778;; initialize syntax table for VHDL Mode
2779(vhdl-mode-syntax-table-init)
2780
d2ddb974
KH
2781(defvar vhdl-syntactic-context nil
2782 "Buffer local variable containing syntactic analysis list.")
2783(make-variable-buffer-local 'vhdl-syntactic-context)
2784
5eabfe72 2785;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2786;; Abbrev ook bindings
d2ddb974
KH
2787
2788(defvar vhdl-mode-abbrev-table nil
5eabfe72
KH
2789 "Abbrev table to use in `vhdl-mode' buffers.")
2790
2791(defun vhdl-mode-abbrev-table-init ()
2792 "Initialize `vhdl-mode-abbrev-table'."
2793 (when vhdl-mode-abbrev-table (clear-abbrev-table vhdl-mode-abbrev-table))
2794 (define-abbrev-table 'vhdl-mode-abbrev-table
2795 (append
2796 (when (memq 'vhdl vhdl-electric-keywords)
2797 ;; VHDL'93 keywords
2798 '(
4bcb9c95
SM
2799 ("--" "" vhdl-template-display-comment-hook 0 t)
2800 ("abs" "" vhdl-template-default-hook 0 t)
2801 ("access" "" vhdl-template-default-hook 0 t)
2802 ("after" "" vhdl-template-default-hook 0 t)
2803 ("alias" "" vhdl-template-alias-hook 0 t)
2804 ("all" "" vhdl-template-default-hook 0 t)
2805 ("and" "" vhdl-template-default-hook 0 t)
2806 ("arch" "" vhdl-template-architecture-hook 0 t)
2807 ("architecture" "" vhdl-template-architecture-hook 0 t)
2808 ("array" "" vhdl-template-default-hook 0 t)
2809 ("assert" "" vhdl-template-assert-hook 0 t)
2810 ("attr" "" vhdl-template-attribute-hook 0 t)
2811 ("attribute" "" vhdl-template-attribute-hook 0 t)
2812 ("begin" "" vhdl-template-default-indent-hook 0 t)
2813 ("block" "" vhdl-template-block-hook 0 t)
2814 ("body" "" vhdl-template-default-hook 0 t)
2815 ("buffer" "" vhdl-template-default-hook 0 t)
2816 ("bus" "" vhdl-template-default-hook 0 t)
2817 ("case" "" vhdl-template-case-hook 0 t)
2818 ("comp" "" vhdl-template-component-hook 0 t)
2819 ("component" "" vhdl-template-component-hook 0 t)
2820 ("cond" "" vhdl-template-conditional-signal-asst-hook 0 t)
2821 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0 t)
2822 ("conf" "" vhdl-template-configuration-hook 0 t)
2823 ("configuration" "" vhdl-template-configuration-hook 0 t)
2824 ("cons" "" vhdl-template-constant-hook 0 t)
2825 ("constant" "" vhdl-template-constant-hook 0 t)
2826 ("disconnect" "" vhdl-template-disconnect-hook 0 t)
2827 ("downto" "" vhdl-template-default-hook 0 t)
2828 ("else" "" vhdl-template-else-hook 0 t)
2829 ("elseif" "" vhdl-template-elsif-hook 0 t)
2830 ("elsif" "" vhdl-template-elsif-hook 0 t)
2831 ("end" "" vhdl-template-default-indent-hook 0 t)
2832 ("entity" "" vhdl-template-entity-hook 0 t)
2833 ("exit" "" vhdl-template-exit-hook 0 t)
2834 ("file" "" vhdl-template-file-hook 0 t)
2835 ("for" "" vhdl-template-for-hook 0 t)
2836 ("func" "" vhdl-template-function-hook 0 t)
2837 ("function" "" vhdl-template-function-hook 0 t)
2838 ("generic" "" vhdl-template-generic-hook 0 t)
2839 ("group" "" vhdl-template-group-hook 0 t)
2840 ("guarded" "" vhdl-template-default-hook 0 t)
2841 ("if" "" vhdl-template-if-hook 0 t)
2842 ("impure" "" vhdl-template-default-hook 0 t)
2843 ("in" "" vhdl-template-default-hook 0 t)
2844 ("inertial" "" vhdl-template-default-hook 0 t)
2845 ("inout" "" vhdl-template-default-hook 0 t)
2846 ("inst" "" vhdl-template-instance-hook 0 t)
2847 ("instance" "" vhdl-template-instance-hook 0 t)
2848 ("is" "" vhdl-template-default-hook 0 t)
2849 ("label" "" vhdl-template-default-hook 0 t)
2850 ("library" "" vhdl-template-library-hook 0 t)
2851 ("linkage" "" vhdl-template-default-hook 0 t)
2852 ("literal" "" vhdl-template-default-hook 0 t)
2853 ("loop" "" vhdl-template-bare-loop-hook 0 t)
2854 ("map" "" vhdl-template-map-hook 0 t)
2855 ("mod" "" vhdl-template-default-hook 0 t)
2856 ("nand" "" vhdl-template-default-hook 0 t)
2857 ("new" "" vhdl-template-default-hook 0 t)
2858 ("next" "" vhdl-template-next-hook 0 t)
2859 ("nor" "" vhdl-template-default-hook 0 t)
2860 ("not" "" vhdl-template-default-hook 0 t)
2861 ("null" "" vhdl-template-default-hook 0 t)
2862 ("of" "" vhdl-template-default-hook 0 t)
2863 ("on" "" vhdl-template-default-hook 0 t)
2864 ("open" "" vhdl-template-default-hook 0 t)
2865 ("or" "" vhdl-template-default-hook 0 t)
2866 ("others" "" vhdl-template-others-hook 0 t)
2867 ("out" "" vhdl-template-default-hook 0 t)
2868 ("pack" "" vhdl-template-package-hook 0 t)
2869 ("package" "" vhdl-template-package-hook 0 t)
2870 ("port" "" vhdl-template-port-hook 0 t)
2871 ("postponed" "" vhdl-template-default-hook 0 t)
2872 ("procedure" "" vhdl-template-procedure-hook 0 t)
2873 ("process" "" vhdl-template-process-hook 0 t)
2874 ("pure" "" vhdl-template-default-hook 0 t)
2875 ("range" "" vhdl-template-default-hook 0 t)
2876 ("record" "" vhdl-template-default-hook 0 t)
2877 ("register" "" vhdl-template-default-hook 0 t)
2878 ("reject" "" vhdl-template-default-hook 0 t)
2879 ("rem" "" vhdl-template-default-hook 0 t)
2880 ("report" "" vhdl-template-report-hook 0 t)
2881 ("return" "" vhdl-template-return-hook 0 t)
2882 ("rol" "" vhdl-template-default-hook 0 t)
2883 ("ror" "" vhdl-template-default-hook 0 t)
2884 ("select" "" vhdl-template-selected-signal-asst-hook 0 t)
2885 ("severity" "" vhdl-template-default-hook 0 t)
2886 ("shared" "" vhdl-template-default-hook 0 t)
2887 ("sig" "" vhdl-template-signal-hook 0 t)
2888 ("signal" "" vhdl-template-signal-hook 0 t)
2889 ("sla" "" vhdl-template-default-hook 0 t)
2890 ("sll" "" vhdl-template-default-hook 0 t)
2891 ("sra" "" vhdl-template-default-hook 0 t)
2892 ("srl" "" vhdl-template-default-hook 0 t)
2893 ("subtype" "" vhdl-template-subtype-hook 0 t)
2894 ("then" "" vhdl-template-default-hook 0 t)
2895 ("to" "" vhdl-template-default-hook 0 t)
2896 ("transport" "" vhdl-template-default-hook 0 t)
2897 ("type" "" vhdl-template-type-hook 0 t)
2898 ("unaffected" "" vhdl-template-default-hook 0 t)
2899 ("units" "" vhdl-template-default-hook 0 t)
2900 ("until" "" vhdl-template-default-hook 0 t)
2901 ("use" "" vhdl-template-use-hook 0 t)
2902 ("var" "" vhdl-template-variable-hook 0 t)
2903 ("variable" "" vhdl-template-variable-hook 0 t)
2904 ("wait" "" vhdl-template-wait-hook 0 t)
2905 ("when" "" vhdl-template-when-hook 0 t)
2906 ("while" "" vhdl-template-while-loop-hook 0 t)
2907 ("with" "" vhdl-template-with-hook 0 t)
2908 ("xnor" "" vhdl-template-default-hook 0 t)
2909 ("xor" "" vhdl-template-default-hook 0 t)
5eabfe72
KH
2910 ))
2911 ;; VHDL-AMS keywords
2912 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2913 '(
4bcb9c95
SM
2914 ("across" "" vhdl-template-default-hook 0 t)
2915 ("break" "" vhdl-template-break-hook 0 t)
2916 ("limit" "" vhdl-template-limit-hook 0 t)
2917 ("nature" "" vhdl-template-nature-hook 0 t)
2918 ("noise" "" vhdl-template-default-hook 0 t)
2919 ("procedural" "" vhdl-template-procedural-hook 0 t)
2920 ("quantity" "" vhdl-template-quantity-hook 0 t)
2921 ("reference" "" vhdl-template-default-hook 0 t)
2922 ("spectrum" "" vhdl-template-default-hook 0 t)
2923 ("subnature" "" vhdl-template-subnature-hook 0 t)
2924 ("terminal" "" vhdl-template-terminal-hook 0 t)
2925 ("through" "" vhdl-template-default-hook 0 t)
2926 ("tolerance" "" vhdl-template-default-hook 0 t)
5eabfe72
KH
2927 ))
2928 ;; user model keywords
2929 (when (memq 'user vhdl-electric-keywords)
2930 (let ((alist vhdl-model-alist)
2931 abbrev-list keyword)
2932 (while alist
2933 (setq keyword (nth 3 (car alist)))
2934 (unless (equal keyword "")
2935 (setq abbrev-list
2936 (cons (list keyword ""
2937 (vhdl-function-name
4bcb9c95 2938 "vhdl-model" (nth 0 (car alist)) "hook") 0 t)
5eabfe72
KH
2939 abbrev-list)))
2940 (setq alist (cdr alist)))
2941 abbrev-list)))))
2942
2943;; initialize abbrev table for VHDL Mode
2944(vhdl-mode-abbrev-table-init)
2945
2946;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2947;; Template completion lists
2948
2949(defvar vhdl-template-construct-alist nil
2950 "List of built-in construct templates.")
2951
2952(defun vhdl-template-construct-alist-init ()
2953 "Initialize `vhdl-template-construct-alist'."
2954 (setq
2955 vhdl-template-construct-alist
2956 (append
2957 '(
2958 ("alias declaration" vhdl-template-alias)
2959 ("architecture body" vhdl-template-architecture)
2960 ("assertion" vhdl-template-assert)
2961 ("attribute declaration" vhdl-template-attribute-decl)
2962 ("attribute specification" vhdl-template-attribute-spec)
2963 ("block configuration" vhdl-template-block-configuration)
2964 ("block statement" vhdl-template-block)
2965 ("case statement" vhdl-template-case-is)
2966 ("component configuration" vhdl-template-component-conf)
2967 ("component declaration" vhdl-template-component-decl)
2968 ("component instantiation statement" vhdl-template-component-inst)
2969 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
2970 ("configuration declaration" vhdl-template-configuration-decl)
2971 ("configuration specification" vhdl-template-configuration-spec)
2972 ("constant declaration" vhdl-template-constant)
2973 ("disconnection specification" vhdl-template-disconnect)
2974 ("entity declaration" vhdl-template-entity)
2975 ("exit statement" vhdl-template-exit)
2976 ("file declaration" vhdl-template-file)
2977 ("generate statement" vhdl-template-generate)
2978 ("generic clause" vhdl-template-generic)
2979 ("group declaration" vhdl-template-group-decl)
2980 ("group template declaration" vhdl-template-group-template)
2981 ("if statement" vhdl-template-if-then)
2982 ("library clause" vhdl-template-library)
2983 ("loop statement" vhdl-template-loop)
2984 ("next statement" vhdl-template-next)
2985 ("package declaration" vhdl-template-package-decl)
2986 ("package body" vhdl-template-package-body)
2987 ("port clause" vhdl-template-port)
2988 ("process statement" vhdl-template-process)
2989 ("report statement" vhdl-template-report)
2990 ("return statement" vhdl-template-return)
2991 ("selected signal assignment" vhdl-template-selected-signal-asst)
2992 ("signal declaration" vhdl-template-signal)
2993 ("subprogram declaration" vhdl-template-subprogram-decl)
2994 ("subprogram body" vhdl-template-subprogram-body)
2995 ("subtype declaration" vhdl-template-subtype)
2996 ("type declaration" vhdl-template-type)
2997 ("use clause" vhdl-template-use)
2998 ("variable declaration" vhdl-template-variable)
2999 ("wait statement" vhdl-template-wait)
3000 )
3001 (when (vhdl-standard-p 'ams)
3002 '(
3003 ("break statement" vhdl-template-break)
3004 ("nature declaration" vhdl-template-nature)
3005 ("quantity declaration" vhdl-template-quantity)
3006 ("simultaneous case statement" vhdl-template-case-use)
3007 ("simultaneous if statement" vhdl-template-if-use)
3008 ("simultaneous procedural statement" vhdl-template-procedural)
3009 ("step limit specification" vhdl-template-limit)
3010 ("subnature declaration" vhdl-template-subnature)
3011 ("terminal declaration" vhdl-template-terminal)
3012 )))))
d2ddb974 3013
5eabfe72
KH
3014;; initialize for VHDL Mode
3015(vhdl-template-construct-alist-init)
3016
3017(defvar vhdl-template-package-alist nil
3018 "List of built-in package templates.")
3019
3020(defun vhdl-template-package-alist-init ()
3021 "Initialize `vhdl-template-package-alist'."
3022 (setq
3023 vhdl-template-package-alist
3024 (append
3025 '(
3026 ("numeric_bit" vhdl-template-package-numeric-bit)
3027 ("numeric_std" vhdl-template-package-numeric-std)
3028 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3029 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3030 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3031 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3032 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3033 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3034 ("textio" vhdl-template-package-textio)
3035 )
3036 (when (vhdl-standard-p 'math)
3037 '(
3038 ("math_complex" vhdl-template-package-math-complex)
3039 ("math_real" vhdl-template-package-math-real)
3040 )))))
d2ddb974 3041
5eabfe72
KH
3042;; initialize for VHDL Mode
3043(vhdl-template-package-alist-init)
d2ddb974 3044
5eabfe72 3045(defvar vhdl-template-directive-alist
3dcb36b7
JB
3046 '(
3047 ("translate_on" vhdl-template-directive-translate-on)
3048 ("translate_off" vhdl-template-directive-translate-off)
3049 ("synthesis_on" vhdl-template-directive-synthesis-on)
3050 ("synthesis_off" vhdl-template-directive-synthesis-off)
3051 )
5eabfe72 3052 "List of built-in directive templates.")
d2ddb974 3053
5eabfe72
KH
3054
3055;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3056;;; Menues
3057;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3058
3059;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
3060;; VHDL menu (using `easy-menu.el')
3061
5eabfe72
KH
3062(defun vhdl-customize ()
3063 "Call the customize function with `vhdl' as argument."
3064 (interactive)
3065 (customize-browse 'vhdl))
3066
5eabfe72
KH
3067(defun vhdl-create-mode-menu ()
3068 "Create VHDL Mode menu."
3dcb36b7
JB
3069 `("VHDL"
3070 ,(append
3071 '("Project"
3072 ["None" (vhdl-set-project "")
3073 :style radio :selected (null vhdl-project)]
3074 "--")
3075 ;; add menu entries for defined projects
3076 (let ((project-alist vhdl-project-alist) menu-list name)
3077 (while project-alist
3078 (setq name (caar project-alist))
3079 (setq menu-list
3080 (cons `[,name (vhdl-set-project ,name)
3081 :style radio :selected (equal ,name vhdl-project)]
3082 menu-list))
3083 (setq project-alist (cdr project-alist)))
3084 (setq menu-list
3085 (if vhdl-project-sort
3086 (sort menu-list
3087 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3088 (nreverse menu-list)))
3089 (vhdl-menu-split menu-list "Project"))
3090 '("--" "--"
3091 ["Select Project..." vhdl-set-project t]
3092 "--"
3093 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3094 ["Import Project..." vhdl-import-project
3095 :keys "C-c C-p C-m" :active t]
3096 ["Export Project" vhdl-export-project vhdl-project]
3097 "--"
3098 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
d2ddb974 3099 "--"
3dcb36b7
JB
3100 ("Compile"
3101 ["Compile Buffer" vhdl-compile t]
3102 ["Stop Compilation" kill-compilation t]
3103 "--"
3104 ["Make" vhdl-make t]
3105 ["Generate Makefile" vhdl-generate-makefile t]
3106 "--"
3107 ["Next Error" next-error t]
3108 ["Previous Error" previous-error t]
3109 ["First Error" first-error t]
3110 "--"
3111 ,(append
3112 '("Compiler")
3113 ;; add menu entries for defined compilers
3114 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3115 (while comp-alist
3116 (setq name (caar comp-alist))
3117 (setq menu-list
3118 (cons `[,name (setq vhdl-compiler ,name)
3119 :style radio :selected (equal ,name vhdl-compiler)]
3120 menu-list))
3121 (setq comp-alist (cdr comp-alist)))
3122 (setq menu-list (nreverse menu-list))
3123 (vhdl-menu-split menu-list "Compiler"))
3124 '("--" "--"
3125 ["Select Compiler..." vhdl-set-compiler t]
3126 "--"
3127 ["Customize Compiler..."
3128 (customize-option 'vhdl-compiler-alist) t])))
5eabfe72 3129 "--"
3dcb36b7
JB
3130 ,(append
3131 '("Template"
3132 ("VHDL Construct 1"
3133 ["Alias" vhdl-template-alias t]
3134 ["Architecture" vhdl-template-architecture t]
3135 ["Assert" vhdl-template-assert t]
3136 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3137 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3138 ["Block" vhdl-template-block t]
3139 ["Case" vhdl-template-case-is t]
3140 ["Component (Decl)" vhdl-template-component-decl t]
3141 ["(Component) Instance" vhdl-template-component-inst t]
3142 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3143 ["Configuration (Block)" vhdl-template-block-configuration t]
3144 ["Configuration (Comp)" vhdl-template-component-conf t]
3145 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3146 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3147 ["Constant" vhdl-template-constant t]
3148 ["Disconnect" vhdl-template-disconnect t]
3149 ["Else" vhdl-template-else t]
3150 ["Elsif" vhdl-template-elsif t]
3151 ["Entity" vhdl-template-entity t]
3152 ["Exit" vhdl-template-exit t]
3153 ["File" vhdl-template-file t]
3154 ["For (Generate)" vhdl-template-for-generate t]
3155 ["For (Loop)" vhdl-template-for-loop t]
3156 ["Function (Body)" vhdl-template-function-body t]
3157 ["Function (Decl)" vhdl-template-function-decl t]
3158 ["Generic" vhdl-template-generic t]
3159 ["Group (Decl)" vhdl-template-group-decl t]
3160 ["Group (Template)" vhdl-template-group-template t])
3161 ("VHDL Construct 2"
3162 ["If (Generate)" vhdl-template-if-generate t]
3163 ["If (Then)" vhdl-template-if-then t]
3164 ["Library" vhdl-template-library t]
3165 ["Loop" vhdl-template-bare-loop t]
3166 ["Map" vhdl-template-map t]
3167 ["Next" vhdl-template-next t]
3168 ["Others (Aggregate)" vhdl-template-others t]
3169 ["Package (Decl)" vhdl-template-package-decl t]
3170 ["Package (Body)" vhdl-template-package-body t]
3171 ["Port" vhdl-template-port t]
3172 ["Procedure (Body)" vhdl-template-procedure-body t]
3173 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3174 ["Process (Comb)" vhdl-template-process-comb t]
3175 ["Process (Seq)" vhdl-template-process-seq t]
3176 ["Report" vhdl-template-report t]
3177 ["Return" vhdl-template-return t]
3178 ["Select" vhdl-template-selected-signal-asst t]
3179 ["Signal" vhdl-template-signal t]
3180 ["Subtype" vhdl-template-subtype t]
3181 ["Type" vhdl-template-type t]
3182 ["Use" vhdl-template-use t]
3183 ["Variable" vhdl-template-variable t]
3184 ["Wait" vhdl-template-wait t]
3185 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3186 ["When" vhdl-template-when t]
3187 ["While (Loop)" vhdl-template-while-loop t]
3188 ["With" vhdl-template-with t]))
3189 (when (vhdl-standard-p 'ams)
3190 '(("VHDL-AMS Construct"
3191 ["Break" vhdl-template-break t]
3192 ["Case (Use)" vhdl-template-case-use t]
3193 ["If (Use)" vhdl-template-if-use t]
3194 ["Limit" vhdl-template-limit t]
3195 ["Nature" vhdl-template-nature t]
3196 ["Procedural" vhdl-template-procedural t]
3197 ["Quantity (Free)" vhdl-template-quantity-free t]
3198 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3199 ["Quantity (Source)" vhdl-template-quantity-source t]
3200 ["Subnature" vhdl-template-subnature t]
3201 ["Terminal" vhdl-template-terminal t])))
3202 '(["Insert Construct..." vhdl-template-insert-construct
3203 :keys "C-c C-i C-t"]
3204 "--")
3205 (list
3206 (append
3207 '("Package")
3208 (when (vhdl-standard-p 'math)
3209 '(["math_complex" vhdl-template-package-math-complex t]
3210 ["math_real" vhdl-template-package-math-real t]))
3211 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3212 ["numeric_std" vhdl-template-package-numeric-std t]
3213 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3214 ["textio" vhdl-template-package-textio t]
3215 "--"
3216 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3217 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3218 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3219 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3220 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3221 "--"
3222 ["Insert Package..." vhdl-template-insert-package
3223 :keys "C-c C-i C-p"])))
3224 '(("Directive"
3225 ["translate_on" vhdl-template-directive-translate-on t]
3226 ["translate_off" vhdl-template-directive-translate-off t]
3227 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3228 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3229 "--"
3230 ["Insert Directive..." vhdl-template-insert-directive
3231 :keys "C-c C-i C-d"])
5eabfe72 3232 "--"
3dcb36b7
JB
3233 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3234 ["Insert Footer" vhdl-template-footer t]
3235 ["Insert Date" vhdl-template-insert-date t]
3236 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
5eabfe72 3237 "--"
3dcb36b7
JB
3238 ["Query Next Prompt" vhdl-template-search-prompt t]))
3239 ,(append
3240 '("Model")
3241 ;; add menu entries for defined models
3242 (let ((model-alist vhdl-model-alist) menu-list model)
3243 (while model-alist
3244 (setq model (car model-alist))
3245 (setq menu-list
3246 (cons
3247 (vector
3248 (nth 0 model)
3249 (vhdl-function-name "vhdl-model" (nth 0 model))
3250 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3251 menu-list))
3252 (setq model-alist (cdr model-alist)))
3253 (setq menu-list (nreverse menu-list))
3254 (vhdl-menu-split menu-list "Model"))
3255 '("--" "--"
3256 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3257 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3258 ("Port"
5eabfe72 3259 ["Copy" vhdl-port-copy t]
d2ddb974 3260 "--"
5eabfe72
KH
3261 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3262 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3263 ["Paste As Instance" vhdl-port-paste-instance
3264 :keys "C-c C-p C-i" :active vhdl-port-list]
3265 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3266 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3267 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3dcb36b7 3268 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
d2ddb974 3269 "--"
3dcb36b7
JB
3270 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3271 "--"
3272 ["Flatten" vhdl-port-flatten
3273 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3274 ["Reverse Direction" vhdl-port-reverse-direction
3275 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3276 ("Compose"
3277 ["New Component" vhdl-compose-new-component t]
3278 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3279 ["Wire Components" vhdl-compose-wire-components t]
3280 "--"
3281 ["Generate Components Package" vhdl-compose-components-package t])
3282 ("Subprogram"
3283 ["Copy" vhdl-subprog-copy t]
3284 "--"
3285 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3286 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3287 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3288 "--"
3289 ["Flatten" vhdl-subprog-flatten
3290 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3291 "--"
3292 ("Comment"
5eabfe72
KH
3293 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3294 "--"
3295 ["Insert Inline Comment" vhdl-comment-append-inline t]
3296 ["Insert Horizontal Line" vhdl-comment-display-line t]
3297 ["Insert Display Comment" vhdl-comment-display t]
3298 "--"
3299 ["Fill Comment" fill-paragraph t]
3300 ["Fill Comment Region" fill-region (mark)]
3301 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3dcb36b7
JB
3302 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3303 ("Line"
5eabfe72
KH
3304 ["Kill" vhdl-line-kill t]
3305 ["Copy" vhdl-line-copy t]
3306 ["Yank" vhdl-line-yank t]
3307 ["Expand" vhdl-line-expand t]
3308 "--"
3309 ["Transpose Next" vhdl-line-transpose-next t]
3310 ["Transpose Prev" vhdl-line-transpose-previous t]
3311 ["Open" vhdl-line-open t]
3dcb36b7 3312 ["Join" vhdl-delete-indentation t]
5eabfe72
KH
3313 "--"
3314 ["Goto" goto-line t]
3dcb36b7
JB
3315 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3316 ("Move"
5eabfe72
KH
3317 ["Forward Statement" vhdl-end-of-statement t]
3318 ["Backward Statement" vhdl-beginning-of-statement t]
3319 ["Forward Expression" vhdl-forward-sexp t]
3320 ["Backward Expression" vhdl-backward-sexp t]
3dcb36b7
JB
3321 ["Forward Same Indent" vhdl-forward-same-indent t]
3322 ["Backward Same Indent" vhdl-backward-same-indent t]
5eabfe72
KH
3323 ["Forward Function" vhdl-end-of-defun t]
3324 ["Backward Function" vhdl-beginning-of-defun t]
3dcb36b7
JB
3325 ["Mark Function" vhdl-mark-defun t])
3326 "--"
3327 ("Indent"
3328 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3329 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
5eabfe72 3330 ["Region" vhdl-indent-region (mark)]
3dcb36b7
JB
3331 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3332 ("Align"
5eabfe72 3333 ["Group" vhdl-align-group t]
3dcb36b7
JB
3334 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3335 ["List" vhdl-align-list t]
3336 ["Declarations" vhdl-align-declarations t]
3337 ["Region" vhdl-align-region (mark)]
3338 ["Buffer" vhdl-align-buffer t]
5eabfe72
KH
3339 "--"
3340 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3341 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3dcb36b7
JB
3342 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3343 ("Fill"
3344 ["List" vhdl-fill-list t]
3345 ["Group" vhdl-fill-group t]
3346 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3347 ["Region" vhdl-fill-region (mark)])
3348 ("Beautify"
3349 ["Region" vhdl-beautify-region (mark)]
3350 ["Buffer" vhdl-beautify-buffer t])
3351 ("Fix"
3352 ["Generic/Port Clause" vhdl-fix-clause t]
5eabfe72 3353 "--"
3dcb36b7
JB
3354 ["Case Region" vhdl-fix-case-region (mark)]
3355 ["Case Buffer" vhdl-fix-case-buffer t]
3356 "--"
3357 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3358 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3359 "--"
3360 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3361 ("Update"
3362 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3363 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3364 "--"
3365 ["Fontify Buffer" vhdl-fontify-buffer t]
3366 ["Statistics Buffer" vhdl-statistics-buffer t]
3367 ["Show Messages" vhdl-show-messages t]
3368 ["Syntactic Info" vhdl-show-syntactic-information t]
3369 "--"
3370 ["Speedbar" vhdl-speedbar t]
3371 ["Hide/Show" vhdl-hs-minor-mode t]
3372 "--"
3373 ("Documentation"
5eabfe72 3374 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3dcb36b7 3375 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
5eabfe72 3376 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3dcb36b7
JB
3377 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3378 ["Version" vhdl-version t]
3379 ["Bug Report..." vhdl-submit-bug-report t]
3380 "--"
3381 ("Options"
3382 ("Mode"
3383 ["Electric Mode"
3384 (progn (customize-set-variable 'vhdl-electric-mode
3385 (not vhdl-electric-mode))
3386 (vhdl-mode-line-update))
3387 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3388 ["Stutter Mode"
3389 (progn (customize-set-variable 'vhdl-stutter-mode
3390 (not vhdl-stutter-mode))
3391 (vhdl-mode-line-update))
3392 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3393 ["Indent Tabs Mode"
3394 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3395 (not vhdl-indent-tabs-mode))
3396 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3397 :style toggle :selected vhdl-indent-tabs-mode]
3398 "--"
3399 ["Customize Group..." (customize-group 'vhdl-mode) t])
3400 ("Project"
3401 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3402 ,(append
3403 '("Selected Project at Startup"
3404 ["None" (progn (customize-set-variable 'vhdl-project nil)
3405 (vhdl-set-project ""))
3406 :style radio :selected (null vhdl-project)]
3407 "--")
3408 ;; add menu entries for defined projects
3409 (let ((project-alist vhdl-project-alist) menu-list name)
3410 (while project-alist
3411 (setq name (caar project-alist))
3412 (setq menu-list
3413 (cons `[,name (progn (customize-set-variable
3414 'vhdl-project ,name)
3415 (vhdl-set-project ,name))
3416 :style radio :selected (equal ,name vhdl-project)]
3417 menu-list))
3418 (setq project-alist (cdr project-alist)))
3419 (setq menu-list (nreverse menu-list))
3420 (vhdl-menu-split menu-list "Project")))
3421 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3422 ("Auto Load Setup File"
3423 ["At Startup"
3424 (customize-set-variable 'vhdl-project-auto-load
3425 (if (memq 'startup vhdl-project-auto-load)
3426 (delq 'startup vhdl-project-auto-load)
3427 (cons 'startup vhdl-project-auto-load)))
3428 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3429 ["Sort Projects"
3430 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3431 :style toggle :selected vhdl-project-sort]
3432 "--"
3433 ["Customize Group..." (customize-group 'vhdl-project) t])
3434 ("Compiler"
3435 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3436 ,(append
3437 '("Selected Compiler at Startup")
3438 ;; add menu entries for defined compilers
3439 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3440 (while comp-alist
3441 (setq name (caar comp-alist))
3442 (setq menu-list
3443 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3444 :style radio :selected (equal ,name vhdl-compiler)]
3445 menu-list))
3446 (setq comp-alist (cdr comp-alist)))
3447 (setq menu-list (nreverse menu-list))
3448 (vhdl-menu-split menu-list "Compler")))
3449 ["Use Local Error Regexp"
3450 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3451 (not vhdl-compile-use-local-error-regexp))
3452 :style toggle :selected vhdl-compile-use-local-error-regexp]
3453 ["Makefile Generation Hook..."
3454 (customize-option 'vhdl-makefile-generation-hook) t]
3455 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3456 "--"
3457 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3458 ("Style"
3459 ("VHDL Standard"
3460 ["VHDL'87"
3461 (progn (customize-set-variable 'vhdl-standard
3462 (list '87 (cadr vhdl-standard)))
3463 (vhdl-activate-customizations))
3464 :style radio :selected (eq '87 (car vhdl-standard))]
3465 ["VHDL'93"
3466 (progn (customize-set-variable 'vhdl-standard
3467 (list '93 (cadr vhdl-standard)))
3468 (vhdl-activate-customizations))
3469 :style radio :selected (eq '93 (car vhdl-standard))]
3470 "--"
3471 ["VHDL-AMS"
3472 (progn (customize-set-variable
3473 'vhdl-standard (list (car vhdl-standard)
3474 (if (memq 'ams (cadr vhdl-standard))
3475 (delq 'ams (cadr vhdl-standard))
3476 (cons 'ams (cadr vhdl-standard)))))
3477 (vhdl-activate-customizations))
3478 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3479 ["Math Packages"
3480 (progn (customize-set-variable
3481 'vhdl-standard (list (car vhdl-standard)
3482 (if (memq 'math (cadr vhdl-standard))
3483 (delq 'math (cadr vhdl-standard))
3484 (cons 'math (cadr vhdl-standard)))))
3485 (vhdl-activate-customizations))
3486 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3487 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3488 ["Upper Case Keywords"
3489 (customize-set-variable 'vhdl-upper-case-keywords
3490 (not vhdl-upper-case-keywords))
3491 :style toggle :selected vhdl-upper-case-keywords]
3492 ["Upper Case Types"
3493 (customize-set-variable 'vhdl-upper-case-types
3494 (not vhdl-upper-case-types))
3495 :style toggle :selected vhdl-upper-case-types]
3496 ["Upper Case Attributes"
3497 (customize-set-variable 'vhdl-upper-case-attributes
3498 (not vhdl-upper-case-attributes))
3499 :style toggle :selected vhdl-upper-case-attributes]
3500 ["Upper Case Enumeration Values"
3501 (customize-set-variable 'vhdl-upper-case-enum-values
3502 (not vhdl-upper-case-enum-values))
3503 :style toggle :selected vhdl-upper-case-enum-values]
3504 ["Upper Case Constants"
3505 (customize-set-variable 'vhdl-upper-case-constants
3506 (not vhdl-upper-case-constants))
3507 :style toggle :selected vhdl-upper-case-constants]
3508 ("Use Direct Instantiation"
3509 ["Never"
3510 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3511 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3512 ["Standard"
3513 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3514 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3515 ["Always"
3516 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3517 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3518 "--"
3519 ["Customize Group..." (customize-group 'vhdl-style) t])
3520 ("Naming"
3521 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3522 ["Architecture File Name..."
3523 (customize-option 'vhdl-architecture-file-name) t]
3524 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3525 ("File Name Case"
3526 ["As Is"
3527 (customize-set-variable 'vhdl-file-name-case 'identity)
3528 :style radio :selected (eq 'identity vhdl-file-name-case)]
3529 ["Lower Case"
3530 (customize-set-variable 'vhdl-file-name-case 'downcase)
3531 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3532 ["Upper Case"
3533 (customize-set-variable 'vhdl-file-name-case 'upcase)
3534 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3535 ["Capitalize"
3536 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3537 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3538 "--"
3539 ["Customize Group..." (customize-group 'vhdl-naming) t])
3540 ("Template"
3541 ("Electric Keywords"
3542 ["VHDL Keywords"
3543 (customize-set-variable 'vhdl-electric-keywords
3544 (if (memq 'vhdl vhdl-electric-keywords)
3545 (delq 'vhdl vhdl-electric-keywords)
3546 (cons 'vhdl vhdl-electric-keywords)))
3547 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3548 ["User Model Keywords"
3549 (customize-set-variable 'vhdl-electric-keywords
3550 (if (memq 'user vhdl-electric-keywords)
3551 (delq 'user vhdl-electric-keywords)
3552 (cons 'user vhdl-electric-keywords)))
3553 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3554 ("Insert Optional Labels"
3555 ["None"
3556 (customize-set-variable 'vhdl-optional-labels 'none)
3557 :style radio :selected (eq 'none vhdl-optional-labels)]
3558 ["Processes Only"
3559 (customize-set-variable 'vhdl-optional-labels 'process)
3560 :style radio :selected (eq 'process vhdl-optional-labels)]
3561 ["All Constructs"
3562 (customize-set-variable 'vhdl-optional-labels 'all)
3563 :style radio :selected (eq 'all vhdl-optional-labels)])
3564 ("Insert Empty Lines"
3565 ["None"
3566 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3567 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3568 ["Design Units Only"
3569 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3570 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3571 ["All Constructs"
3572 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3573 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3574 ["Argument List Indent"
3575 (customize-set-variable 'vhdl-argument-list-indent
3576 (not vhdl-argument-list-indent))
3577 :style toggle :selected vhdl-argument-list-indent]
3578 ["Association List with Formals"
3579 (customize-set-variable 'vhdl-association-list-with-formals
3580 (not vhdl-association-list-with-formals))
3581 :style toggle :selected vhdl-association-list-with-formals]
3582 ["Conditions in Parenthesis"
3583 (customize-set-variable 'vhdl-conditions-in-parenthesis
3584 (not vhdl-conditions-in-parenthesis))
3585 :style toggle :selected vhdl-conditions-in-parenthesis]
3586 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3587 ["One String..." (customize-option 'vhdl-one-string) t]
3588 ("File Header"
3589 ["Header String..." (customize-option 'vhdl-file-header) t]
3590 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3591 ["Company Name..." (customize-option 'vhdl-company-name) t]
3592 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3593 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3594 ["Date Format..." (customize-option 'vhdl-date-format) t]
3595 ["Modify Date Prefix String..."
3596 (customize-option 'vhdl-modify-date-prefix-string) t]
3597 ["Modify Date on Saving"
3598 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3599 (not vhdl-modify-date-on-saving))
3600 (vhdl-activate-customizations))
3601 :style toggle :selected vhdl-modify-date-on-saving])
3602 ("Sequential Process"
3603 ("Kind of Reset"
3604 ["None"
3605 (customize-set-variable 'vhdl-reset-kind 'none)
3606 :style radio :selected (eq 'none vhdl-reset-kind)]
3607 ["Synchronous"
3608 (customize-set-variable 'vhdl-reset-kind 'sync)
3609 :style radio :selected (eq 'sync vhdl-reset-kind)]
3610 ["Asynchronous"
3611 (customize-set-variable 'vhdl-reset-kind 'async)
3612 :style radio :selected (eq 'async vhdl-reset-kind)])
3613 ["Reset is Active High"
3614 (customize-set-variable 'vhdl-reset-active-high
3615 (not vhdl-reset-active-high))
3616 :style toggle :selected vhdl-reset-active-high]
3617 ["Use Rising Clock Edge"
3618 (customize-set-variable 'vhdl-clock-rising-edge
3619 (not vhdl-clock-rising-edge))
3620 :style toggle :selected vhdl-clock-rising-edge]
3621 ("Clock Edge Condition"
3622 ["Standard"
3623 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3624 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3625 ["Function \"rising_edge\""
3626 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3627 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3628 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3629 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3630 "--"
3631 ["Customize Group..." (customize-group 'vhdl-template) t])
3632 ("Model"
3633 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3634 ("Port"
3635 ["Include Port Comments"
3636 (customize-set-variable 'vhdl-include-port-comments
3637 (not vhdl-include-port-comments))
3638 :style toggle :selected vhdl-include-port-comments]
3639 ["Include Direction Comments"
3640 (customize-set-variable 'vhdl-include-direction-comments
3641 (not vhdl-include-direction-comments))
3642 :style toggle :selected vhdl-include-direction-comments]
3643 ["Include Type Comments"
3644 (customize-set-variable 'vhdl-include-type-comments
3645 (not vhdl-include-type-comments))
3646 :style toggle :selected vhdl-include-type-comments]
3647 ("Include Group Comments"
3648 ["Never"
3649 (customize-set-variable 'vhdl-include-group-comments 'never)
3650 :style radio :selected (eq 'never vhdl-include-group-comments)]
3651 ["Declarations"
3652 (customize-set-variable 'vhdl-include-group-comments 'decl)
3653 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3654 ["Always"
3655 (customize-set-variable 'vhdl-include-group-comments 'always)
3656 :style radio :selected (eq 'always vhdl-include-group-comments)])
3657 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3658 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3659 ("Testbench"
3660 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3661 ["Architecture Name..."
3662 (customize-option 'vhdl-testbench-architecture-name) t]
3663 ["Configuration Name..."
3664 (customize-option 'vhdl-testbench-configuration-name) t]
3665 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3666 ["Include Header"
3667 (customize-set-variable 'vhdl-testbench-include-header
3668 (not vhdl-testbench-include-header))
3669 :style toggle :selected vhdl-testbench-include-header]
3670 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3671 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3672 ["Initialize Signals"
3673 (customize-set-variable 'vhdl-testbench-initialize-signals
3674 (not vhdl-testbench-initialize-signals))
3675 :style toggle :selected vhdl-testbench-initialize-signals]
3676 ["Include Library Clause"
3677 (customize-set-variable 'vhdl-testbench-include-library
3678 (not vhdl-testbench-include-library))
3679 :style toggle :selected vhdl-testbench-include-library]
3680 ["Include Configuration"
3681 (customize-set-variable 'vhdl-testbench-include-configuration
3682 (not vhdl-testbench-include-configuration))
3683 :style toggle :selected vhdl-testbench-include-configuration]
3684 ("Create Files"
3685 ["None"
3686 (customize-set-variable 'vhdl-testbench-create-files 'none)
3687 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3688 ["Single"
3689 (customize-set-variable 'vhdl-testbench-create-files 'single)
3690 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3691 ["Separate"
3692 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3693 :style radio :selected (eq 'separate vhdl-testbench-create-files)]))
3694 "--"
3695 ["Customize Group..." (customize-group 'vhdl-port) t])
3696 ("Compose"
3697 ("Create Files"
3698 ["None"
3699 (customize-set-variable 'vhdl-compose-create-files 'none)
3700 :style radio :selected (eq 'none vhdl-compose-create-files)]
3701 ["Single"
3702 (customize-set-variable 'vhdl-compose-create-files 'single)
3703 :style radio :selected (eq 'single vhdl-compose-create-files)]
3704 ["Separate"
3705 (customize-set-variable 'vhdl-compose-create-files 'separate)
3706 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3707 ["Include Header"
3708 (customize-set-variable 'vhdl-compose-include-header
3709 (not vhdl-compose-include-header))
3710 :style toggle :selected vhdl-compose-include-header]
3711 ["Architecture Name..."
3712 (customize-option 'vhdl-compose-architecture-name) t]
3713 ["Components Package Name..."
3714 (customize-option 'vhdl-components-package-name) t]
3715 ["Use Components Package"
3716 (customize-set-variable 'vhdl-use-components-package
3717 (not vhdl-use-components-package))
3718 :style toggle :selected vhdl-use-components-package]
3719 "--"
3720 ["Customize Group..." (customize-group 'vhdl-compose) t])
3721 ("Comment"
3722 ["Self Insert Comments"
3723 (customize-set-variable 'vhdl-self-insert-comments
3724 (not vhdl-self-insert-comments))
3725 :style toggle :selected vhdl-self-insert-comments]
3726 ["Prompt for Comments"
3727 (customize-set-variable 'vhdl-prompt-for-comments
3728 (not vhdl-prompt-for-comments))
3729 :style toggle :selected vhdl-prompt-for-comments]
3730 ["Inline Comment Column..."
3731 (customize-option 'vhdl-inline-comment-column) t]
3732 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3733 "--"
3734 ["Customize Group..." (customize-group 'vhdl-comment) t])
3735 ("Align"
3736 ["Auto Align Templates"
3737 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3738 :style toggle :selected vhdl-auto-align]
3739 ["Align Line Groups"
3740 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3741 :style toggle :selected vhdl-align-groups]
3742 ["Group Separation String..."
3743 (customize-set-variable 'vhdl-align-group-separate) t]
3744 ["Align Lines with Same Indent"
3745 (customize-set-variable 'vhdl-align-same-indent
3746 (not vhdl-align-same-indent))
3747 :style toggle :selected vhdl-align-same-indent]
3748 "--"
3749 ["Customize Group..." (customize-group 'vhdl-align) t])
3750 ("Highlight"
3751 ["Highlighting On/Off..."
3752 (customize-option
4bcb9c95
SM
3753 (if (fboundp 'global-font-lock-mode)
3754 'global-font-lock-mode 'font-lock-auto-fontify)) t]
3dcb36b7
JB
3755 ["Highlight Keywords"
3756 (progn (customize-set-variable 'vhdl-highlight-keywords
3757 (not vhdl-highlight-keywords))
3758 (vhdl-fontify-buffer))
3759 :style toggle :selected vhdl-highlight-keywords]
3760 ["Highlight Names"
3761 (progn (customize-set-variable 'vhdl-highlight-names
3762 (not vhdl-highlight-names))
3763 (vhdl-fontify-buffer))
3764 :style toggle :selected vhdl-highlight-names]
3765 ["Highlight Special Words"
3766 (progn (customize-set-variable 'vhdl-highlight-special-words
3767 (not vhdl-highlight-special-words))
3768 (vhdl-fontify-buffer))
3769 :style toggle :selected vhdl-highlight-special-words]
3770 ["Highlight Forbidden Words"
3771 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3772 (not vhdl-highlight-forbidden-words))
3773 (vhdl-fontify-buffer))
3774 :style toggle :selected vhdl-highlight-forbidden-words]
3775 ["Highlight Verilog Keywords"
3776 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3777 (not vhdl-highlight-verilog-keywords))
3778 (vhdl-fontify-buffer))
3779 :style toggle :selected vhdl-highlight-verilog-keywords]
3780 ["Highlight \"translate_off\""
3781 (progn (customize-set-variable 'vhdl-highlight-translate-off
3782 (not vhdl-highlight-translate-off))
3783 (vhdl-fontify-buffer))
3784 :style toggle :selected vhdl-highlight-translate-off]
3785 ["Case Sensitive Highlighting"
3786 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3787 (not vhdl-highlight-case-sensitive))
3788 (vhdl-fontify-buffer))
3789 :style toggle :selected vhdl-highlight-case-sensitive]
3790 ["Special Syntax Definition..."
3791 (customize-option 'vhdl-special-syntax-alist) t]
3792 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3793 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3794 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3795 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3796 "--"
3797 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3798 ("Speedbar"
3799 ["Auto Open at Startup"
3800 (customize-set-variable 'vhdl-speedbar-auto-open
3801 (not vhdl-speedbar-auto-open))
3802 :style toggle :selected vhdl-speedbar-auto-open]
3803 ("Default Displaying Mode"
3804 ["Files"
3805 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3806 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3807 ["Directory Hierarchy"
3808 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3809 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3810 ["Project Hierarchy"
3811 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3812 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3813 ["Indentation Offset..."
3814 (customize-option 'speedbar-indentation-width) t]
3815 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3816 ["Jump to Unit when Opening"
3817 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3818 (not vhdl-speedbar-jump-to-unit))
3819 :style toggle :selected vhdl-speedbar-jump-to-unit]
3820 ["Update Hierarchy on File Saving"
3821 (customize-set-variable 'vhdl-speedbar-update-on-saving
3822 (not vhdl-speedbar-update-on-saving))
3823 :style toggle :selected vhdl-speedbar-update-on-saving]
3824 ("Save in Cache File"
3825 ["Hierarchy Information"
3826 (customize-set-variable 'vhdl-speedbar-save-cache
3827 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3828 (delq 'hierarchy vhdl-speedbar-save-cache)
3829 (cons 'hierarchy vhdl-speedbar-save-cache)))
3830 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3831 ["Displaying Status"
3832 (customize-set-variable 'vhdl-speedbar-save-cache
3833 (if (memq 'display vhdl-speedbar-save-cache)
3834 (delq 'display vhdl-speedbar-save-cache)
3835 (cons 'display vhdl-speedbar-save-cache)))
3836 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3837 ["Cache File Name..."
3838 (customize-option 'vhdl-speedbar-cache-file-name) t]
3839 "--"
3840 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3841 ("Menu"
3842 ["Add Index Menu when Loading File"
3843 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3844 (vhdl-index-menu-init))
3845 :style toggle :selected vhdl-index-menu]
3846 ["Add Source File Menu when Loading File"
3847 (progn (customize-set-variable 'vhdl-source-file-menu
3848 (not vhdl-source-file-menu))
3849 (vhdl-add-source-files-menu))
3850 :style toggle :selected vhdl-source-file-menu]
3851 ["Add Hideshow Menu at Startup"
3852 (progn (customize-set-variable 'vhdl-hideshow-menu
3853 (not vhdl-hideshow-menu))
3854 (vhdl-activate-customizations))
3855 :style toggle :selected vhdl-hideshow-menu]
3856 ["Hide Everything Initially"
3857 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3858 :style toggle :selected vhdl-hide-all-init]
3859 "--"
3860 ["Customize Group..." (customize-group 'vhdl-menu) t])
3861 ("Print"
3862 ["In Two Column Format"
3863 (progn (customize-set-variable 'vhdl-print-two-column
3864 (not vhdl-print-two-column))
3865 (message "Activate new setting by saving options and restarting Emacs"))
3866 :style toggle :selected vhdl-print-two-column]
3867 ["Use Customized Faces"
3868 (progn (customize-set-variable 'vhdl-print-customize-faces
3869 (not vhdl-print-customize-faces))
3870 (message "Activate new setting by saving options and restarting Emacs"))
3871 :style toggle :selected vhdl-print-customize-faces]
3872 "--"
3873 ["Customize Group..." (customize-group 'vhdl-print) t])
3874 ("Miscellaneous"
3875 ["Use Intelligent Tab"
3876 (progn (customize-set-variable 'vhdl-intelligent-tab
3877 (not vhdl-intelligent-tab))
3878 (vhdl-activate-customizations))
3879 :style toggle :selected vhdl-intelligent-tab]
3880 ["Indent Syntax-Based"
3881 (customize-set-variable 'vhdl-indent-syntax-based
3882 (not vhdl-indent-syntax-based))
3883 :style toggle :selected vhdl-indent-syntax-based]
3884 ["Word Completion is Case Sensitive"
3885 (customize-set-variable 'vhdl-word-completion-case-sensitive
3886 (not vhdl-word-completion-case-sensitive))
3887 :style toggle :selected vhdl-word-completion-case-sensitive]
3888 ["Word Completion in Minibuffer"
3889 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3890 (not vhdl-word-completion-in-minibuffer))
3891 (message "Activate new setting by saving options and restarting Emacs"))
3892 :style toggle :selected vhdl-word-completion-in-minibuffer]
3893 ["Underscore is Part of Word"
3894 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3895 (not vhdl-underscore-is-part-of-word))
3896 (vhdl-activate-customizations))
3897 :style toggle :selected vhdl-underscore-is-part-of-word]
3898 "--"
3899 ["Customize Group..." (customize-group 'vhdl-misc) t])
3900 ["Related..." (customize-browse 'vhdl-related) t]
d2ddb974 3901 "--"
3dcb36b7
JB
3902 ["Save Options" customize-save-customized t]
3903 ["Activate Options" vhdl-activate-customizations t]
3904 ["Browse Options..." vhdl-customize t])))
5eabfe72
KH
3905
3906(defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3907 "VHDL Mode menu.")
3908
3909(defun vhdl-update-mode-menu ()
3dcb36b7 3910 "Update VHDL Mode menu."
5eabfe72
KH
3911 (interactive)
3912 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
3913 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
3914 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
3915 (easy-menu-define vhdl-mode-menu vhdl-mode-map
3916 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
d2ddb974 3917
5eabfe72
KH
3918;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3919;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
d2ddb974 3920
3dcb36b7 3921(defconst vhdl-imenu-generic-expression
d2ddb974 3922 '(
5eabfe72
KH
3923 ("Subprogram"
3924 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
3925 4)
3926 ("Instance"
3927 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
3928 1)
3929 ("Component"
3930 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 3931 2)
5eabfe72
KH
3932 ("Procedural"
3933 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
3934 1)
3935 ("Process"
3936 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
3937 1)
3938 ("Block"
3939 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
3940 1)
3941 ("Package"
3942 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3943 3)
d2ddb974
KH
3944 ("Configuration"
3945 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3946 2)
5eabfe72
KH
3947 ("Architecture"
3948 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
d2ddb974 3949 2)
5eabfe72
KH
3950 ("Entity"
3951 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 3952 2)
d2ddb974
KH
3953 )
3954 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
3955
5eabfe72
KH
3956(defun vhdl-index-menu-init ()
3957 "Initialize index menu."
3958 (set (make-local-variable 'imenu-case-fold-search) t)
3959 (set (make-local-variable 'imenu-generic-expression)
3960 vhdl-imenu-generic-expression)
3dcb36b7 3961 (when (and vhdl-index-menu (fboundp 'imenu))
5eabfe72
KH
3962 (if (or (not (boundp 'font-lock-maximum-size))
3963 (> font-lock-maximum-size (buffer-size)))
3964 (imenu-add-to-menubar "Index")
3965 (message "Scanning buffer for index...buffer too big"))))
d2ddb974 3966
3dcb36b7 3967;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
3968;; Source file menu (using `easy-menu.el')
3969
5eabfe72
KH
3970(defvar vhdl-sources-menu nil)
3971
3972(defun vhdl-directory-files (directory &optional full match)
3973 "Call `directory-files' if DIRECTORY exists, otherwise generate error
3974message."
3dcb36b7
JB
3975 (if (not (file-directory-p directory))
3976 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
3977 (let ((dir (directory-files directory full match)))
3978 (setq dir (delete "." dir))
3979 (setq dir (delete ".." dir))
3980 dir)))
5eabfe72
KH
3981
3982(defun vhdl-get-source-files (&optional full directory)
3983 "Get list of VHDL source files in DIRECTORY or current directory."
3984 (let ((mode-alist auto-mode-alist)
3985 filename-regexp)
3986 ;; create regular expressions for matching file names
3dcb36b7 3987 (setq filename-regexp "\\`[^.].*\\(")
5eabfe72 3988 (while mode-alist
3dcb36b7 3989 (when (eq (cdar mode-alist) 'vhdl-mode)
5eabfe72 3990 (setq filename-regexp
3dcb36b7 3991 (concat filename-regexp (caar mode-alist) "\\|")))
5eabfe72
KH
3992 (setq mode-alist (cdr mode-alist)))
3993 (setq filename-regexp
3994 (concat (substring filename-regexp 0
3995 (string-match "\\\\|$" filename-regexp)) "\\)"))
3996 ;; find files
3dcb36b7
JB
3997 (vhdl-directory-files
3998 (or directory default-directory) full filename-regexp)))
d2ddb974
KH
3999
4000(defun vhdl-add-source-files-menu ()
5eabfe72
KH
4001 "Scan directory for all VHDL source files and generate menu.
4002The directory of the current source file is scanned."
d2ddb974
KH
4003 (interactive)
4004 (message "Scanning directory for source files ...")
5eabfe72 4005 (let ((newmap (current-local-map))
5eabfe72
KH
4006 (file-list (vhdl-get-source-files))
4007 menu-list found)
4008 ;; Create list for menu
4009 (setq found nil)
4010 (while file-list
4011 (setq found t)
4012 (setq menu-list (cons (vector (car file-list)
4013 (list 'find-file (car file-list)) t)
4014 menu-list))
4015 (setq file-list (cdr file-list)))
3dcb36b7 4016 (setq menu-list (vhdl-menu-split menu-list "Sources"))
5eabfe72
KH
4017 (when found (setq menu-list (cons "--" menu-list)))
4018 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4019 (setq menu-list (cons "Sources" menu-list))
d2ddb974 4020 ;; Create menu
5eabfe72
KH
4021 (easy-menu-add menu-list)
4022 (easy-menu-define vhdl-sources-menu newmap
4023 "VHDL source files menu" menu-list))
d2ddb974
KH
4024 (message ""))
4025
d2ddb974 4026
5eabfe72 4027;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4028;;; Mode definition
5eabfe72
KH
4029;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4030;; performs all buffer local initializations
4031
1c36bac6 4032;;;###autoload
d2ddb974
KH
4033(defun vhdl-mode ()
4034 "Major mode for editing VHDL code.
4035
4036Usage:
4037------
4038
3dcb36b7
JB
4039 TEMPLATE INSERTION (electrification):
4040 After typing a VHDL keyword and entering `SPC', you are prompted for
4041 arguments while a template is generated for that VHDL construct. Typing
4042 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4043 template generation. Optional arguments are indicated by square
4044 brackets and removed if the queried string is left empty. Prompts for
4045 mandatory arguments remain in the code if the queried string is left
4046 empty. They can be queried again by `C-c C-t C-q'. Enabled
4047 electrification is indicated by `/e' in the modeline.
4048
4049 Typing `M-SPC' after a keyword inserts a space without calling the
4050 template generator. Automatic template generation (i.e.
4051 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4052 setting option `vhdl-electric-mode' (see OPTIONS).
4053
4054 Template generators can be invoked from the VHDL menu, by key
4055 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4056 the keyword (i.e. first word of menu entry not in parenthesis) and
4057 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4058 conf, comp, cons, func, inst, pack, sig, var.
4059
4060 Template styles can be customized in customization group
4061 `vhdl-template' \(see OPTIONS).
4062
4063
4064 HEADER INSERTION:
4065 A file header can be inserted by `C-c C-t C-h'. A file footer
4066 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4067 See customization group `vhdl-header'.
4068
4069
4070 STUTTERING:
4071 Double striking of some keys inserts cumbersome VHDL syntax elements.
4072 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4073 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4074 the modeline. The stuttering keys and their effects are:
4075
4076 ;; --> \" : \" [ --> ( -- --> comment
4077 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4078 .. --> \" => \" ] --> ) --- --> horizontal line
4079 ,, --> \" <= \" ]] --> ] ---- --> display comment
4080 == --> \" == \" '' --> \\\"
4081
4082
4083 WORD COMPLETION:
4084 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4085 word in the buffer that starts alike, inserts it and adjusts case.
4086 Re-typing `TAB' toggles through alternative word completions. This also
4087 works in the minibuffer (i.e. in template generator prompts).
4088
4089 Typing `TAB' after `(' looks for and inserts complete parenthesized
4090 expressions (e.g. for array index ranges). All keywords as well as
4091 standard types and subprograms of VHDL have predefined abbreviations
4092 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4093 beginning with \"std\").
4094
4095 Typing `TAB' after a non-word character indents the line if at the
4096 beginning of a line (i.e. no preceding non-blank characters), and
4097 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4098 stop.
4099
4100
4101 COMMENTS:
4102 `--' puts a single comment.
4103 `---' draws a horizontal line for separating code segments.
4104 `----' inserts a display comment, i.e. two horizontal lines
4105 with a comment in between.
4106 `--CR' comments out code on that line. Re-hitting CR comments
4107 out following lines.
4108 `C-c c' comments out a region if not commented out,
4109 uncomments a region if already commented out.
4110
4111 You are prompted for comments after object definitions (i.e. signals,
4112 variables, constants, ports) and after subprogram and process
4113 specifications if option `vhdl-prompt-for-comments' is non-nil.
4114 Comments are automatically inserted as additional labels (e.g. after
4115 begin statements) and as help comments if `vhdl-self-insert-comments' is
4116 non-nil.
4117
4118 Inline comments (i.e. comments after a piece of code on the same line)
4119 are indented at least to `vhdl-inline-comment-column'. Comments go at
4120 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4121 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4122 in a comment automatically opens a new comment line. `M-q' re-fills
4123 multi-line comments.
4124
4125
4126 INDENTATION:
4127 `TAB' indents a line if at the beginning of the line. The amount of
4128 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4129 always indents the current line (is bound to `TAB' if option
4130 `vhdl-intelligent-tab' is nil).
4131
4132 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4133 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4134 indented normally (nil) or relative to the opening parenthesis (non-nil)
4135 according to option `vhdl-argument-list-indent'.
4136
4137 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4138 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4139 and vice versa.
4140
4141 Syntax-based indentation can be very slow in large files. Option
4142 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4143
4144
4145 ALIGNMENT:
4146 The alignment functions align operators, keywords, and inline comments
4147 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4148 separated by blank lines, `C-c C-a C-i' a block of lines with same
4149 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4150 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4151 C-a C-d' all lines within the declarative part of a design unit. `C-c
4152 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4153 for a group of lines, and `C-c C-a M-c' for a region.
4154
4155 If option `vhdl-align-groups' is non-nil, groups of code lines
4156 separated by special lines (see option `vhdl-align-group-separate') are
4157 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4158 blocks of lines with same indent are aligned separately. Some templates
4159 are automatically aligned after generation if option `vhdl-auto-align'
4160 is non-nil.
4161
4162 Alignment tries to align inline comments at
4163 `vhdl-inline-comment-column' and tries inline comment not to exceed
4164 `vhdl-end-comment-column'.
4165
4166 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4167 symbols are surrounded by one space, and multiple spaces are eliminated.
4168
4169
4170| CODE FILLING:
4171| Code filling allows to condens code (e.g. sensitivity lists or port
4172| maps) by removing comments and newlines and re-wrapping so that all
4173| lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4174| enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4175| blank lines, `C-c C-f C-i' a block of lines with same indent, and
4176| `C-c C-f M-f' an entire region.
4177
4178
4179 CODE BEAUTIFICATION:
4180 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4181 buffer respectively. This inludes indentation, alignment, and case
4182 fixing. Code beautification can also be run non-interactively using the
4183 command:
4184
4185 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4186
4187
4188 PORT TRANSLATION:
4189 Generic and port clauses from entity or component declarations can be
4190 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4191 as component instantiations and corresponding internal constants and
4192 signals, as a generic map with constants as actual generics, and as
4193 internal signal initializations (menu).
4194
4195 To include formals in component instantiations, see option
4196 `vhdl-association-list-with-formals'. To include comments in pasting,
4197 see options `vhdl-include-...-comments'.
4198
4199 A clause with several generic/port names on the same line can be
4200 flattened (`C-c C-p C-f') so that only one name per line exists. The
4201| direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4202| outputs and vice versa, which can be useful in testbenches. (This
4203| reversion is done on the internal data structure and is only reflected
4204| in subsequent paste operations.)
4205
4206 Names for actual ports, instances, testbenches, and
4207 design-under-test instances can be derived from existing names according
4208 to options `vhdl-...-name'. See customization group `vhdl-port'.
4209
4210
4211| SUBPROGRAM TRANSLATION:
4212| Similar functionality exists for copying/pasting the interface of
4213| subprograms (function/procedure). A subprogram interface can be copied
4214| and then pasted as a subprogram declaration, body or call (uses
4215| association list with formals).
4216
4217
4218 TESTBENCH GENERATION:
4219 A copied port can also be pasted as a testbench. The generated
4220 testbench includes an entity, an architecture, and an optional
4221 configuration. The architecture contains the component declaration and
4222 instantiation of the DUT as well as internal constant and signal
4223 declarations. Additional user-defined templates can be inserted. The
4224 names used for entity/architecture/configuration/DUT as well as the file
4225 structure to be generated can be customized. See customization group
4226 `vhdl-testbench'.
4227
4228
4229 KEY BINDINGS:
4230 Key bindings (`C-c ...') exist for most commands (see in menu).
4231
4232
4233 VHDL MENU:
4234 All commands can be found in the VHDL menu including their key bindings.
4235
4236
4237 FILE BROWSER:
4238 The speedbar allows browsing of directories and file contents. It can
4239 be accessed from the VHDL menu and is automatically opened if option
4240 `vhdl-speedbar-auto-open' is non-nil.
4241
4242 In speedbar, open files and directories with `mouse-2' on the name and
4243 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4244
4245
4246 DESIGN HIERARCHY BROWSER:
4247 The speedbar can also be used for browsing the hierarchy of design units
4248 contained in the source files of the current directory or the specified
4249 projects (see option `vhdl-project-alist').
4250
4251 The speedbar can be switched between file, directory hierarchy and
4252 project hierarchy browsing mode in the speedbar menu or by typing `f',
4253 `h' or `H' in speedbar.
4254
4255 In speedbar, open design units with `mouse-2' on the name and browse
4256 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4257 from entities and components (in packages). Individual design units and
4258 complete designs can directly be compiled (\"Make\" menu entry).
4259
4260 The hierarchy is automatically updated upon saving a modified source
4261 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4262 hierarchy is only updated for projects that have been opened once in the
4263 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4264 options in group `vhdl-speedbar').
4265
4266 Simple design consistency checks are done during scanning, such as
4267 multiple declarations of the same unit or missing primary units that are
4268 required by secondary units.
4269
4270
4271| STRUCTURAL COMPOSITION:
4272| Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4273| for a new component. Subcomponents (i.e. component declaration and
4274| instantiation) can be automatically placed from a previously read port
4275| \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4276| all subcomponents can be automatically connected using internal signals
4277| and ports (`C-c C-c C-w') following these rules:
4278| - subcomponent actual ports with same name are considered to be
4279| connected by a signal (internal signal or port)
4280| - signals that are only inputs to subcomponents are considered as
4281| inputs to this component -> input port created
4282| - signals that are only outputs from subcomponents are considered as
4283| outputs from this component -> output port created
4284| - signals that are inputs to AND outputs from subcomponents are
4285| considered as internal connections -> internal signal created
4286|
4287| Component declarations can be placed in a components package (option
4288| `vhdl-use-components-package') which can be automatically generated for
4289| an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4290| component instantiation is also supported (option
4291| `vhdl-use-direct-instantiation').
4292|
4293| Purpose: With appropriate naming conventions it is possible to
4294| create higher design levels with only a few mouse clicks or key
4295| strokes. A new design level can be created by simply generating a new
4296| component, placing the required subcomponents from the hierarchy
4297| browser, and wiring everything automatically.
4298|
4299| Note: Automatic wiring only works reliably on templates of new
4300| components and component instantiations that were created by VHDL mode.
4301|
4302| See the options group `vhdl-compose' for all relevant user options.
4303
4304
4305 SOURCE FILE COMPILATION:
4306 The syntax of the current buffer can be analyzed by calling a VHDL
4307 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4308 option `vhdl-compiler'. The available compilers are listed in option
4309 `vhdl-compiler-alist' including all required compilation command,
4310 command options, compilation directory, and error message syntax
4311 information. New compilers can be added.
4312
4313 All the source files of an entire design can be compiled by the `make'
4314 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4315
4316
4317 MAKEFILE GENERATION:
4318 Makefiles can be generated automatically by an internal generation
4319 routine (`C-c M-k'). The library unit dependency information is
4320 obtained from the hierarchy browser. Makefile generation can be
4321 customized for each compiler in option `vhdl-compiler-alist'.
4322
4323 Makefile generation can also be run non-interactively using the
4324 command:
4325
4326 emacs -batch -l ~/.emacs -l vhdl-mode
4327 [-compiler compilername] [-project projectname]
4328 -f vhdl-generate-makefile
4329
4330 The Makefile's default target \"all\" compiles the entire design, the
4331 target \"clean\" removes it and the target \"library\" creates the
4332 library directory if not existent. The Makefile also includes a target
4333 for each primary library unit which allows selective compilation of this
4334 unit, its secondary units and its subhierarchy (example: compilation of
4335 a design specified by a configuration). User specific parts can be
4336 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4337
4338 Limitations:
4339 - Only library units and dependencies within the current library are
4340 considered. Makefiles for designs that span multiple libraries are
4341 not (yet) supported.
4342 - Only one-level configurations are supported (also hierarchical),
4343 but configurations that go down several levels are not.
4344 - The \"others\" keyword in configurations is not supported.
4345
4346
4347 PROJECTS:
4348 Projects can be defined in option `vhdl-project-alist' and a current
4349 project be selected using option `vhdl-project' (permanently) or from
4350 the menu or speedbar (temporarily). For each project, title and
4351 description strings (for the file headers), source files/directories
4352 (for the hierarchy browser and Makefile generation), library name, and
4353 compiler-dependent options, exceptions and compilation directory can be
4354 specified. Compilation settings overwrite the settings of option
4355 `vhdl-compiler-alist'.
4356
4357 Project setups can be exported (i.e. written to a file) and imported.
4358 Imported setups are not automatically saved in `vhdl-project-alist' but
4359 can be saved afterwards in its customization buffer. When starting
4360 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4361 vhdl-mode\") in a directory with an existing project setup file, it is
4362 automatically loaded and its project activated if option
4363 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4364 files can be specified in option `vhdl-project-file-name'. Multiple
4365 project setups can be automatically loaded from global directories.
4366 This is an alternative to specifying project setups with option
4367 `vhdl-project-alist'.
4368
4369
4370 SPECIAL MENUES:
4371 As an alternative to the speedbar, an index menu can be added (set
4372 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4373 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4374 file) for browsing the file contents (is not populated if buffer is
4375 larger than `font-lock-maximum-size'). Also, a source file menu can be
4376 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4377 current directory for VHDL source files.
4378
4379
4380 VHDL STANDARDS:
4381 The VHDL standards to be used are specified in option `vhdl-standard'.
4382 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4383
4384
4385 KEYWORD CASE:
4386 Lower and upper case for keywords and standardized types, attributes,
4387 and enumeration values is supported. If the option
4388 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4389 lower case and are converted into upper case automatically (not for
4390 types, attributes, and enumeration values). The case of keywords,
4391 types, attributes,and enumeration values can be fixed for an entire
4392 region (menu) or buffer (`C-c C-x C-c') according to the options
4393 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4394
4395
4396 HIGHLIGHTING (fontification):
4397 Keywords and standardized types, attributes, enumeration values, and
4398 function names (controlled by option `vhdl-highlight-keywords'), as well
4399 as comments, strings, and template prompts are highlighted using
4400 different colors. Unit, subprogram, signal, variable, constant,
4401 parameter and generic/port names in declarations as well as labels are
4402 highlighted if option `vhdl-highlight-names' is non-nil.
4403
4404 Additional reserved words or words with a forbidden syntax (e.g. words
4405 that should be avoided) can be specified in option
4406 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4407 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4408 keywords are highlighted as forbidden words if option
4409 `vhdl-highlight-verilog-keywords' is non-nil.
4410
4411 Words with special syntax can be highlighted by specifying their
4412 syntax and color in option `vhdl-special-syntax-alist' and by setting
4413 option `vhdl-highlight-special-words' to non-nil. This allows to
4414 establish some naming conventions (e.g. to distinguish different kinds
4415 of signals or other objects by using name suffices) and to support them
4416 visually.
4417
4418 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4419 to support case-sensitive highlighting. However, keywords are then only
4420 highlighted if written in lower case.
4421
4422 Code between \"translate_off\" and \"translate_on\" pragmas is
4423 highlighted using a different background color if option
4424 `vhdl-highlight-translate-off' is non-nil.
4425
4426 For documentation and customization of the used colors see
4427 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4428 highlighting of matching parenthesis, see customization group
4429 `paren-showing'. Automatic buffer highlighting is turned on/off by
4430 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4431
4432
4433 USER MODELS:
4434 VHDL models (templates) can be specified by the user and made accessible
4435 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4436 electrification. See option `vhdl-model-alist'.
4437
4438
4439 HIDE/SHOW:
4440 The code of blocks, processes, subprograms, component declarations and
4441 instantiations, generic/port clauses, and configuration declarations can
4442 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4443 the code (see customization group `vhdl-menu'). XEmacs: limited
4444 functionality due to old `hideshow.el' package.
4445
4446
4447 CODE UPDATING:
4448 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4449 current process, `C-c C-u M-s' of all processes in the current buffer.
4450 Limitations:
4451 - Only declared local signals (ports, signals declared in
4452 architecture and blocks) are automatically inserted.
4453 - Global signals declared in packages are not automatically inserted.
4454 Insert them once manually (will be kept afterwards).
4455 - Out parameters of procedures are considered to be read.
4456 Use option `vhdl-entity-file-name' to specify the entity file name
4457 \(used to obtain the port names).
4458
4459
4460 CODE FIXING:
4461 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4462 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4463
4464
4465 PRINTING:
4466 Postscript printing with different faces (an optimized set of faces is
4467 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4468 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4469 postscript printing commands. Option `vhdl-print-two-column' defines
4470 appropriate default settings for nice landscape two-column printing.
4471 The paper format can be set by option `ps-paper-type'. Do not forget to
4472 switch `ps-print-color-p' to nil for printing on black-and-white
4473 printers.
4474
4475
4476 OPTIONS:
4477 User options allow customization of VHDL Mode. All options are
4478 accessible from the \"Options\" menu entry. Simple options (switches
4479 and choices) can directly be changed, while for complex options a
4480 customization buffer is opened. Changed options can be saved for future
4481 sessions using the \"Save Options\" menu entry.
4482
4483 Options and their detailed descriptions can also be accessed by using
4484 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4485 customize-group' for groups). Some customizations only take effect
4486 after some action (read the NOTE in the option documentation).
4487 Customization can also be done globally (i.e. site-wide, read the
4488 INSTALL file).
4489
4490 Not all options are described in this documentation, so go and see
4491 what other useful user options there are (`M-x vhdl-customize' or menu)!
4492
4493
4494 FILE EXTENSIONS:
4495 As default, files with extensions \".vhd\" and \".vhdl\" are
4496 automatically recognized as VHDL source files. To add an extension
4497 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4498
4499 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4500
4501
4502 HINTS:
4503 - To start Emacs with open VHDL hierarchy browser without having to load
4504 a VHDL file first, use the command:
4505
4506 emacs -l vhdl-mode -f speedbar-frame-mode
4507
4508 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4509
4510 - Some features only work on properly indented code.
4511
4512
4513 RELEASE NOTES:
4514 See also the release notes (menu) for added features in new releases.
d2ddb974
KH
4515
4516
4517Maintenance:
4518------------
4519
3dcb36b7 4520To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
d2ddb974
KH
4521Add a description of the problem and include a reproducible test case.
4522
3dcb36b7 4523Questions and enhancement requests can be sent to <reto@gnu.org>.
d2ddb974
KH
4524
4525The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
3dcb36b7
JB
4526The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4527releases. You are kindly invited to participate in beta testing. Subscribe
4528to above mailing lists by sending an email to <reto@gnu.org>.
d2ddb974 4529
3dcb36b7
JB
4530VHDL Mode is officially distributed at
4531http://opensource.ethz.ch/emacs/vhdl-mode.html
4532where the latest version can be found.
d2ddb974
KH
4533
4534
3dcb36b7
JB
4535Known problems:
4536---------------
d2ddb974 4537
5eabfe72 4538- Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
3dcb36b7
JB
4539- XEmacs: Incorrect start-up when automatically opening speedbar.
4540- XEmacs: Indentation in XEmacs 21.4 (and higher).
d2ddb974
KH
4541
4542
3dcb36b7
JB
4543 The VHDL Mode Authors
4544 Reto Zimmermann and Rod Whitby
5eabfe72 4545
d2ddb974
KH
4546Key bindings:
4547-------------
4548
4549\\{vhdl-mode-map}"
4550 (interactive)
4551 (kill-all-local-variables)
d2ddb974
KH
4552 (setq major-mode 'vhdl-mode)
4553 (setq mode-name "VHDL")
5eabfe72
KH
4554
4555 ;; set maps and tables
d2ddb974 4556 (use-local-map vhdl-mode-map)
5eabfe72
KH
4557 (set-syntax-table vhdl-mode-syntax-table)
4558 (setq local-abbrev-table vhdl-mode-abbrev-table)
4559
3dcb36b7 4560 ;; set local variables
5eabfe72
KH
4561 (set (make-local-variable 'paragraph-start)
4562 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
d2ddb974
KH
4563 (set (make-local-variable 'paragraph-separate) paragraph-start)
4564 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
cf98062a
RS
4565 (set (make-local-variable 'require-final-newline)
4566 mode-require-final-newline)
d2ddb974
KH
4567 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4568 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4569 (set (make-local-variable 'comment-start) "--")
4570 (set (make-local-variable 'comment-end) "")
f35aff82 4571 (set (make-local-variable 'comment-padding) "")
5eabfe72 4572 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
d2ddb974
KH
4573 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4574 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
5eabfe72 4575 (set (make-local-variable 'comment-multi-line) nil)
d2ddb974 4576 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
5eabfe72 4577 (set (make-local-variable 'hippie-expand-verbose) nil)
d2ddb974
KH
4578
4579 ;; setup the comment indent variable in a Emacs version portable way
4580 ;; ignore any byte compiler warnings you might get here
5eabfe72
KH
4581 (when (boundp 'comment-indent-function)
4582 (make-local-variable 'comment-indent-function)
4583 (setq comment-indent-function 'vhdl-comment-indent))
d2ddb974
KH
4584
4585 ;; initialize font locking
5eabfe72
KH
4586 (set (make-local-variable 'font-lock-defaults)
4587 (list
3dcb36b7 4588 '(nil vhdl-font-lock-keywords) nil
5eabfe72
KH
4589 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4590 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
3dcb36b7
JB
4591 (unless vhdl-emacs-21
4592 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4593 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4594 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4595; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4596 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4597; (turn-on-font-lock)
d2ddb974
KH
4598
4599 ;; variables for source file compilation
3dcb36b7
JB
4600 (when vhdl-compile-use-local-error-regexp
4601 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4602 (set (make-local-variable 'compilation-file-regexp-alist) nil))
5eabfe72
KH
4603
4604 ;; add index menu
4605 (vhdl-index-menu-init)
4606 ;; add source file menu
d2ddb974 4607 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
5eabfe72
KH
4608 ;; add VHDL menu
4609 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4610 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4611 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4612 ;; initialize hideshow and add menu
5eabfe72 4613 (vhdl-hideshow-init)
d2ddb974
KH
4614 (run-hooks 'menu-bar-update-hook)
4615
5eabfe72
KH
4616 ;; miscellaneous
4617 (vhdl-ps-print-init)
3dcb36b7 4618 (vhdl-write-file-hooks-init)
5eabfe72 4619 (vhdl-mode-line-update)
3dcb36b7
JB
4620 (message "VHDL Mode %s.%s" vhdl-version
4621 (if noninteractive "" " See menu for documentation and release notes."))
5eabfe72
KH
4622
4623 ;; run hooks
9a969196 4624 (run-mode-hooks 'vhdl-mode-hook))
5eabfe72
KH
4625
4626(defun vhdl-activate-customizations ()
4627 "Activate all customizations on local variables."
4628 (interactive)
4629 (vhdl-mode-map-init)
4630 (use-local-map vhdl-mode-map)
4631 (set-syntax-table vhdl-mode-syntax-table)
4632 (setq comment-column vhdl-inline-comment-column)
4633 (setq end-comment-column vhdl-end-comment-column)
3dcb36b7 4634 (vhdl-write-file-hooks-init)
5eabfe72
KH
4635 (vhdl-update-mode-menu)
4636 (vhdl-hideshow-init)
4637 (run-hooks 'menu-bar-update-hook)
4638 (vhdl-mode-line-update))
4639
3dcb36b7
JB
4640(defun vhdl-write-file-hooks-init ()
4641 "Add/remove hooks when buffer is saved."
5eabfe72
KH
4642 (if vhdl-modify-date-on-saving
4643 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
3dcb36b7
JB
4644 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4645 (make-local-variable 'after-save-hook)
4646 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4647
4648(defun vhdl-process-command-line-option (option)
4649 "Process command line options for VHDL Mode."
4650 (cond
4651 ;; set compiler
4652 ((equal option "-compiler")
4653 (vhdl-set-compiler (car command-line-args-left))
4654 (setq command-line-args-left (cdr command-line-args-left)))
4655 ;; set project
4656 ((equal option "-project")
4657 (vhdl-set-project (car command-line-args-left))
4658 (setq command-line-args-left (cdr command-line-args-left)))))
4659
4660;; make Emacs process VHDL Mode options
4661(setq command-switch-alist
4662 (append command-switch-alist
4663 '(("-compiler" . vhdl-process-command-line-option)
4664 ("-project" . vhdl-process-command-line-option))))
5eabfe72
KH
4665
4666
4667;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4668;;; Keywords and standardized words
5eabfe72
KH
4669;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4670
3dcb36b7
JB
4671(defconst vhdl-93-keywords
4672 '(
4673 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4674 "assert" "attribute"
4675 "begin" "block" "body" "buffer" "bus"
4676 "case" "component" "configuration" "constant"
4677 "disconnect" "downto"
4678 "else" "elsif" "end" "entity" "exit"
4679 "file" "for" "function"
4680 "generate" "generic" "group" "guarded"
4681 "if" "impure" "in" "inertial" "inout" "is"
4682 "label" "library" "linkage" "literal" "loop"
4683 "map" "mod"
4684 "nand" "new" "next" "nor" "not" "null"
4685 "of" "on" "open" "or" "others" "out"
4686 "package" "port" "postponed" "procedure" "process" "pure"
4687 "range" "record" "register" "reject" "rem" "report" "return"
4688 "rol" "ror"
4689 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4690 "then" "to" "transport" "type"
4691 "unaffected" "units" "until" "use"
4692 "variable"
4693 "wait" "when" "while" "with"
4694 "xnor" "xor"
4695 )
4696 "List of VHDL'93 keywords.")
d2ddb974 4697
5eabfe72
KH
4698(defconst vhdl-ams-keywords
4699 '(
4700 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4701 "reference" "spectrum" "subnature" "terminal" "through"
4702 "tolerance"
4703 )
4704 "List of VHDL-AMS keywords.")
d2ddb974 4705
5eabfe72
KH
4706(defconst vhdl-verilog-keywords
4707 '(
4708 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4709 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4710 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4711 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4712 "endprimitive" "endspecify" "endtable" "endtask" "event"
4713 "for" "force" "forever" "fork" "function"
4714 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4715 "macromodule" "makefile" "medium" "module"
4716 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4717 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4718 "pullup"
4719 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4720 "rtranif0" "rtranif1"
4721 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4722 "strong1" "supply" "supply0" "supply1"
4723 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4724 "triand" "trior" "trireg"
4725 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4726 )
4727 "List of Verilog keywords as candidate for additional reserved words.")
d2ddb974 4728
5eabfe72
KH
4729(defconst vhdl-93-types
4730 '(
4731 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4732 "real" "time" "natural" "positive" "string" "line" "text" "side"
4733 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4734 "std_logic" "std_logic_vector"
4735 "std_ulogic" "std_ulogic_vector"
4736 )
4737 "List of VHDL'93 standardized types.")
d2ddb974 4738
5eabfe72
KH
4739(defconst vhdl-ams-types
4740 '(
4741 "domain_type" "real_vector"
3dcb36b7
JB
4742 ;; from `nature_pkg' package
4743 "voltage" "current" "electrical" "position" "velocity" "force"
4744 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4745 "pressure" "flowrate" "fluid"
4746 )
5eabfe72 4747 "List of VHDL-AMS standardized types.")
d2ddb974 4748
5eabfe72
KH
4749(defconst vhdl-math-types
4750 '(
4751 "complex" "complex_polar"
4752 )
4753 "List of Math Packages standardized types.")
d2ddb974 4754
5eabfe72
KH
4755(defconst vhdl-93-attributes
4756 '(
4757 "base" "left" "right" "high" "low" "pos" "val" "succ"
4758 "pred" "leftof" "rightof" "range" "reverse_range"
4759 "length" "delayed" "stable" "quiet" "transaction"
4760 "event" "active" "last_event" "last_active" "last_value"
4761 "driving" "driving_value" "ascending" "value" "image"
4762 "simple_name" "instance_name" "path_name"
4763 "foreign"
4764 )
4765 "List of VHDL'93 standardized attributes.")
d2ddb974 4766
5eabfe72
KH
4767(defconst vhdl-ams-attributes
4768 '(
4769 "across" "through"
4770 "reference" "contribution" "tolerance"
4771 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4772 "ramp" "slew"
4773 )
4774 "List of VHDL-AMS standardized attributes.")
d2ddb974 4775
5eabfe72
KH
4776(defconst vhdl-93-enum-values
4777 '(
4778 "true" "false"
4779 "note" "warning" "error" "failure"
4780 "read_mode" "write_mode" "append_mode"
4781 "open_ok" "status_error" "name_error" "mode_error"
4782 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4783 "right" "left"
4784 )
4785 "List of VHDL'93 standardized enumeration values.")
d2ddb974 4786
5eabfe72
KH
4787(defconst vhdl-ams-enum-values
4788 '(
4789 "quiescent_domain" "time_domain" "frequency_domain"
3dcb36b7
JB
4790 ;; from `nature_pkg' package
4791 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5eabfe72
KH
4792 )
4793 "List of VHDL-AMS standardized enumeration values.")
4794
4795(defconst vhdl-math-constants
4796 '(
4797 "math_e" "math_1_over_e"
4798 "math_pi" "math_two_pi" "math_1_over_pi"
4799 "math_half_pi" "math_q_pi" "math_3_half_pi"
4800 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4801 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4802 "math_deg_to_rad" "math_rad_to_deg"
4803 "cbase_1" "cbase_j" "czero"
4804 )
4805 "List of Math Packages standardized constants.")
4806
4807(defconst vhdl-93-functions
4808 '(
4809 "now" "resolved" "rising_edge" "falling_edge"
4810 "read" "readline" "write" "writeline" "endfile"
4811 "resize" "is_X" "std_match"
4812 "shift_left" "shift_right" "rotate_left" "rotate_right"
4813 "to_unsigned" "to_signed" "to_integer"
4814 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4815 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4816 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4817 "shl" "shr" "ext" "sxt"
3dcb36b7 4818 "deallocate"
5eabfe72
KH
4819 )
4820 "List of VHDL'93 standardized functions.")
4821
4822(defconst vhdl-ams-functions
4823 '(
4824 "frequency"
4825 )
4826 "List of VHDL-AMS standardized functions.")
4827
4828(defconst vhdl-math-functions
4829 '(
4830 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4831 "sqrt" "cbrt" "exp" "log"
4832 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4833 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4834 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4835 )
4836 "List of Math Packages standardized functions.")
4837
4838(defconst vhdl-93-packages
4839 '(
4840 "std_logic_1164" "numeric_std" "numeric_bit"
4841 "standard" "textio"
4842 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4843 "std_logic_misc" "std_logic_textio"
4844 "ieee" "std" "work"
4845 )
4846 "List of VHDL'93 standardized packages and libraries.")
4847
3dcb36b7
JB
4848(defconst vhdl-ams-packages
4849 '(
4850 ;; from `nature_pkg' package
4851 "nature_pkg"
4852 )
4853 "List of VHDL-AMS standardized packages and libraries.")
4854
5eabfe72
KH
4855(defconst vhdl-math-packages
4856 '(
4857 "math_real" "math_complex"
4858 )
4859 "List of Math Packages standardized packages and libraries.")
4860
4861(defvar vhdl-keywords nil
4862 "List of VHDL keywords.")
4863
4864(defvar vhdl-types nil
4865 "List of VHDL standardized types.")
4866
4867(defvar vhdl-attributes nil
4868 "List of VHDL standardized attributes.")
4869
4870(defvar vhdl-enum-values nil
4871 "List of VHDL standardized enumeration values.")
4872
4873(defvar vhdl-constants nil
4874 "List of VHDL standardized constants.")
4875
4876(defvar vhdl-functions nil
4877 "List of VHDL standardized functions.")
4878
4879(defvar vhdl-packages nil
4880 "List of VHDL standardized packages and libraries.")
4881
4882(defvar vhdl-reserved-words nil
4883 "List of additional reserved words.")
4884
4885(defvar vhdl-keywords-regexp nil
4886 "Regexp for VHDL keywords.")
4887
4888(defvar vhdl-types-regexp nil
4889 "Regexp for VHDL standardized types.")
4890
4891(defvar vhdl-attributes-regexp nil
4892 "Regexp for VHDL standardized attributes.")
4893
4894(defvar vhdl-enum-values-regexp nil
4895 "Regexp for VHDL standardized enumeration values.")
4896
4897(defvar vhdl-functions-regexp nil
4898 "Regexp for VHDL standardized functions.")
4899
4900(defvar vhdl-packages-regexp nil
4901 "Regexp for VHDL standardized packages and libraries.")
4902
4903(defvar vhdl-reserved-words-regexp nil
4904 "Regexp for additional reserved words.")
4905
3dcb36b7
JB
4906(defvar vhdl-directive-keywords-regexp nil
4907 "Regexp for compiler directive keywords.")
4908
5eabfe72
KH
4909(defun vhdl-words-init ()
4910 "Initialize reserved words."
4911 (setq vhdl-keywords
4912 (append vhdl-93-keywords
4913 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
4914 (setq vhdl-types
4915 (append vhdl-93-types
4916 (when (vhdl-standard-p 'ams) vhdl-ams-types)
4917 (when (vhdl-standard-p 'math) vhdl-math-types)))
4918 (setq vhdl-attributes
4919 (append vhdl-93-attributes
4920 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
4921 (setq vhdl-enum-values
4922 (append vhdl-93-enum-values
4923 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
4924 (setq vhdl-constants
4925 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
4926 (setq vhdl-functions
4927 (append vhdl-93-functions
4928 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
4929 (when (vhdl-standard-p 'math) vhdl-math-functions)))
4930 (setq vhdl-packages
4931 (append vhdl-93-packages
3dcb36b7 4932 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5eabfe72
KH
4933 (when (vhdl-standard-p 'math) vhdl-math-packages)))
4934 (setq vhdl-reserved-words
4935 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
4936 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
4937 '("")))
4938 (setq vhdl-keywords-regexp
4939 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
4940 (setq vhdl-types-regexp
4941 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
4942 (setq vhdl-attributes-regexp
4943 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
4944 (setq vhdl-enum-values-regexp
4945 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
4946 (setq vhdl-functions-regexp
4947 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
4948 (setq vhdl-packages-regexp
4949 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
4950 (setq vhdl-reserved-words-regexp
4951 (concat "\\<\\("
4952 (unless (equal vhdl-forbidden-syntax "")
4953 (concat vhdl-forbidden-syntax "\\|"))
4954 (regexp-opt vhdl-reserved-words)
4955 "\\)\\>"))
3dcb36b7
JB
4956 (setq vhdl-directive-keywords-regexp
4957 (concat "\\<\\(" (mapconcat 'regexp-quote
4958 vhdl-directive-keywords "\\|") "\\)\\>"))
5eabfe72
KH
4959 (vhdl-abbrev-list-init))
4960
4961;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4962;; Words to expand
4963
4964(defvar vhdl-abbrev-list nil
4965 "Predefined abbreviations for VHDL.")
4966
4967(defun vhdl-abbrev-list-init ()
4968 (setq vhdl-abbrev-list
4969 (append
4970 (list vhdl-upper-case-keywords) vhdl-keywords
4971 (list vhdl-upper-case-types) vhdl-types
4972 (list vhdl-upper-case-attributes) vhdl-attributes
4973 (list vhdl-upper-case-enum-values) vhdl-enum-values
4974 (list vhdl-upper-case-constants) vhdl-constants
4975 (list nil) vhdl-functions
4976 (list nil) vhdl-packages)))
4977
4978;; initialize reserved words for VHDL Mode
4979(vhdl-words-init)
4980
4981
4982;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4983;;; Indentation
5eabfe72
KH
4984;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4985
4986;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
4987;; Syntax analysis
4988
4989;; constant regular expressions for looking at various constructs
4990
4991(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
4992 "Regexp describing a VHDL symbol.
4993We cannot use just `word' syntax class since `_' cannot be in word
4994class. Putting underscore in word class breaks forward word movement
4995behavior that users are familiar with.")
4996
4997(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
4998 "Regexp describing a case statement header key.")
4999
5000(defconst vhdl-label-key
5001 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
5002 "Regexp describing a VHDL label.")
5003
5004;; Macro definitions:
5005
5006(defmacro vhdl-point (position)
5eabfe72
KH
5007 "Return the value of point at certain commonly referenced POSITIONs.
5008POSITION can be one of the following symbols:
5009
5010bol -- beginning of line
5011eol -- end of line
5012bod -- beginning of defun
5013boi -- back to indentation
5014eoi -- last whitespace on line
5015ionl -- indentation of next line
5016iopl -- indentation of previous line
5017bonl -- beginning of next line
5018bopl -- beginning of previous line
5019
5020This function does not modify point or mark."
d2ddb974 5021 (or (and (eq 'quote (car-safe position))
3dcb36b7
JB
5022 (null (cddr position)))
5023 (error "ERROR: Bad buffer position requested: %s" position))
d2ddb974 5024 (setq position (nth 1 position))
d4a5b644
GM
5025 `(let ((here (point)))
5026 ,@(cond
5027 ((eq position 'bol) '((beginning-of-line)))
5028 ((eq position 'eol) '((end-of-line)))
5029 ((eq position 'bod) '((save-match-data
5030 (vhdl-beginning-of-defun))))
5031 ((eq position 'boi) '((back-to-indentation)))
3dcb36b7 5032 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
d4a5b644
GM
5033 ((eq position 'bonl) '((forward-line 1)))
5034 ((eq position 'bopl) '((forward-line -1)))
5035 ((eq position 'iopl)
5036 '((forward-line -1)
5037 (back-to-indentation)))
5038 ((eq position 'ionl)
5039 '((forward-line 1)
5040 (back-to-indentation)))
3dcb36b7 5041 (t (error "ERROR: Unknown buffer position requested: %s" position))
d4a5b644
GM
5042 )
5043 (prog1
5044 (point)
5045 (goto-char here))
5046 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5047 ;; doesn't hurt for v19
5048 ,@nil
5049 ))
d2ddb974
KH
5050
5051(defmacro vhdl-safe (&rest body)
5eabfe72 5052 "Safely execute BODY, return nil if an error occurred."
d4a5b644
GM
5053 `(condition-case nil
5054 (progn ,@body)
5055 (error nil)))
d2ddb974
KH
5056
5057(defmacro vhdl-add-syntax (symbol &optional relpos)
5eabfe72
KH
5058 "A simple macro to append the syntax in SYMBOL to the syntax list.
5059Try to increase performance by using this macro."
d4a5b644
GM
5060 `(setq vhdl-syntactic-context
5061 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
d2ddb974
KH
5062
5063(defmacro vhdl-has-syntax (symbol)
5eabfe72
KH
5064 "A simple macro to return check the syntax list.
5065Try to increase performance by using this macro."
d4a5b644 5066 `(assoc ,symbol vhdl-syntactic-context))
d2ddb974
KH
5067
5068;; Syntactic element offset manipulation:
5069
5070(defun vhdl-read-offset (langelem)
5eabfe72 5071 "Read new offset value for LANGELEM from minibuffer.
2e8b9c7d 5072Return a valid value only."
d2ddb974
KH
5073 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5074 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5075 (prompt "Offset: ")
5076 offset input interned)
5077 (while (not offset)
5078 (setq input (read-string prompt oldoff)
5079 offset (cond ((string-equal "+" input) '+)
5080 ((string-equal "-" input) '-)
5081 ((string-equal "++" input) '++)
5082 ((string-equal "--" input) '--)
5083 ((string-match "^-?[0-9]+$" input)
027a4b6b 5084 (string-to-number input))
d2ddb974
KH
5085 ((fboundp (setq interned (intern input)))
5086 interned)
5087 ((boundp interned) interned)
5088 ;; error, but don't signal one, keep trying
5089 ;; to read an input value
5090 (t (ding)
5091 (setq prompt errmsg)
5092 nil))))
5093 offset))
5094
5095(defun vhdl-set-offset (symbol offset &optional add-p)
5096 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5097SYMBOL is the syntactic element symbol to change and OFFSET is the new
5098offset for that syntactic element. Optional ADD says to add SYMBOL to
5099`vhdl-offsets-alist' if it doesn't already appear there."
5100 (interactive
5101 (let* ((langelem
5102 (intern (completing-read
5103 (concat "Syntactic symbol to change"
5104 (if current-prefix-arg " or add" "")
5105 ": ")
5106 (mapcar
5107 (function
5108 (lambda (langelem)
5109 (cons (format "%s" (car langelem)) nil)))
5110 vhdl-offsets-alist)
5111 nil (not current-prefix-arg)
5112 ;; initial contents tries to be the last element
5113 ;; on the syntactic analysis list for the current
5114 ;; line
5115 (let* ((syntax (vhdl-get-syntactic-context))
5116 (len (length syntax))
5117 (ic (format "%s" (car (nth (1- len) syntax)))))
5eabfe72 5118 ic)
d2ddb974
KH
5119 )))
5120 (offset (vhdl-read-offset langelem)))
5121 (list langelem offset current-prefix-arg)))
5122 ;; sanity check offset
5123 (or (eq offset '+)
5124 (eq offset '-)
5125 (eq offset '++)
5126 (eq offset '--)
5127 (integerp offset)
5128 (fboundp offset)
5129 (boundp offset)
3dcb36b7 5130 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
d2ddb974
KH
5131 offset))
5132 (let ((entry (assq symbol vhdl-offsets-alist)))
5133 (if entry
5134 (setcdr entry offset)
5135 (if add-p
5eabfe72
KH
5136 (setq vhdl-offsets-alist
5137 (cons (cons symbol offset) vhdl-offsets-alist))
3dcb36b7 5138 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
d2ddb974
KH
5139 (vhdl-keep-region-active))
5140
5141(defun vhdl-set-style (style &optional local)
5eabfe72 5142 "Set `vhdl-mode' variables to use one of several different indentation styles.
d2ddb974
KH
5143STYLE is a string representing the desired style and optional LOCAL is
5144a flag which, if non-nil, means to make the style variables being
5145changed buffer local, instead of the default, which is to set the
5146global variables. Interactively, the flag comes from the prefix
5147argument. The styles are chosen from the `vhdl-style-alist' variable."
5148 (interactive (list (completing-read "Use which VHDL indentation style? "
5eabfe72 5149 vhdl-style-alist nil t)
d2ddb974
KH
5150 current-prefix-arg))
5151 (let ((vars (cdr (assoc style vhdl-style-alist))))
5152 (or vars
3dcb36b7 5153 (error "ERROR: Invalid VHDL indentation style `%s'" style))
d2ddb974
KH
5154 ;; set all the variables
5155 (mapcar
5156 (function
5157 (lambda (varentry)
5158 (let ((var (car varentry))
5159 (val (cdr varentry)))
5160 (and local
5161 (make-local-variable var))
5162 ;; special case for vhdl-offsets-alist
5163 (if (not (eq var 'vhdl-offsets-alist))
5164 (set var val)
5165 ;; reset vhdl-offsets-alist to the default value first
5166 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5167 ;; now set the langelems that are different
5168 (mapcar
5169 (function
5170 (lambda (langentry)
5171 (let ((langelem (car langentry))
5172 (offset (cdr langentry)))
5173 (vhdl-set-offset langelem offset)
5174 )))
5175 val))
5176 )))
5177 vars))
5178 (vhdl-keep-region-active))
5179
5180(defun vhdl-get-offset (langelem)
5eabfe72
KH
5181 "Get offset from LANGELEM which is a cons cell of the form:
5182\(SYMBOL . RELPOS). The symbol is matched against
5183vhdl-offsets-alist and the offset found there is either returned,
5184or added to the indentation at RELPOS. If RELPOS is nil, then
5185the offset is simply returned."
d2ddb974
KH
5186 (let* ((symbol (car langelem))
5187 (relpos (cdr langelem))
5188 (match (assq symbol vhdl-offsets-alist))
5189 (offset (cdr-safe match)))
5190 ;; offset can be a number, a function, a variable, or one of the
5191 ;; symbols + or -
5192 (cond
5193 ((not match)
5194 (if vhdl-strict-syntax-p
3dcb36b7 5195 (error "ERROR: Don't know how to indent a %s" symbol)
d2ddb974
KH
5196 (setq offset 0
5197 relpos 0)))
5198 ((eq offset '+) (setq offset vhdl-basic-offset))
5199 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5200 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5201 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5202 ((and (not (numberp offset))
5203 (fboundp offset))
5204 (setq offset (funcall offset langelem)))
5205 ((not (numberp offset))
5206 (setq offset (eval offset)))
5207 )
5208 (+ (if (and relpos
5209 (< relpos (vhdl-point 'bol)))
5210 (save-excursion
5211 (goto-char relpos)
5212 (current-column))
5213 0)
5214 offset)))
5215
5216;; Syntactic support functions:
5217
3dcb36b7
JB
5218(defun vhdl-in-comment-p ()
5219 "Check if point is in a comment."
5220 (eq (vhdl-in-literal) 'comment))
5221
5222(defun vhdl-in-string-p ()
5223 "Check if point is in a string."
5224 (eq (vhdl-in-literal) 'string))
d2ddb974 5225
3dcb36b7 5226(defun vhdl-in-literal ()
5eabfe72 5227 "Determine if point is in a VHDL literal."
d2ddb974 5228 (save-excursion
5eabfe72 5229 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
d2ddb974
KH
5230 (cond
5231 ((nth 3 state) 'string)
5232 ((nth 4 state) 'comment)
5eabfe72 5233 (t nil)))))
d2ddb974 5234
3dcb36b7
JB
5235(defun vhdl-forward-comment (&optional direction)
5236 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5237negative, skip forward otherwise."
5238 (interactive "p")
5239 (if (and direction (< direction 0))
5240 ;; skip backwards
5241 (progn
5242 (skip-chars-backward " \t\n")
5243 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5244 (goto-char (match-beginning 3))
5245 (skip-chars-backward " \t\n")))
5246 ;; skip forwards
5247 (skip-chars-forward " \t\n")
5248 (while (looking-at "--.*")
5249 (goto-char (match-end 0))
5250 (skip-chars-forward " \t\n"))))
5251
5252;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5253(unless (and vhdl-xemacs (string< "21.2" emacs-version))
5254 (defalias 'vhdl-forward-comment 'forward-comment))
5255
d2ddb974
KH
5256;; This is the best we can do in Win-Emacs.
5257(defun vhdl-win-il (&optional lim)
5eabfe72 5258 "Determine if point is in a VHDL literal."
d2ddb974
KH
5259 (save-excursion
5260 (let* ((here (point))
5261 (state nil)
5262 (match nil)
5263 (lim (or lim (vhdl-point 'bod))))
5264 (goto-char lim )
5265 (while (< (point) here)
5266 (setq match
5267 (and (re-search-forward "--\\|[\"']"
5268 here 'move)
5269 (buffer-substring (match-beginning 0) (match-end 0))))
5270 (setq state
5271 (cond
5272 ;; no match
5273 ((null match) nil)
5274 ;; looking at the opening of a VHDL style comment
5275 ((string= "--" match)
5276 (if (<= here (progn (end-of-line) (point))) 'comment))
5277 ;; looking at the opening of a double quote string
5278 ((string= "\"" match)
5279 (if (not (save-restriction
5280 ;; this seems to be necessary since the
5281 ;; re-search-forward will not work without it
5282 (narrow-to-region (point) here)
5283 (re-search-forward
5284 ;; this regexp matches a double quote
5285 ;; which is preceded by an even number
5286 ;; of backslashes, including zero
5287 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5288 'string))
5289 ;; looking at the opening of a single quote string
5290 ((string= "'" match)
5291 (if (not (save-restriction
5292 ;; see comments from above
5293 (narrow-to-region (point) here)
5294 (re-search-forward
5295 ;; this matches a single quote which is
5296 ;; preceded by zero or two backslashes.
5297 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5298 here 'move)))
5299 'string))
5300 (t nil)))
5301 ) ; end-while
5302 state)))
5303
5eabfe72 5304(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5305 (fset 'vhdl-in-literal 'vhdl-win-il))
5306
5307;; Skipping of "syntactic whitespace". Syntactic whitespace is
5308;; defined as lexical whitespace or comments. Search no farther back
5309;; or forward than optional LIM. If LIM is omitted, (point-min) is
5310;; used for backward skipping, (point-max) is used for forward
5311;; skipping.
5312
5313(defun vhdl-forward-syntactic-ws (&optional lim)
5eabfe72 5314 "Forward skip of syntactic whitespace."
d2ddb974
KH
5315 (save-restriction
5316 (let* ((lim (or lim (point-max)))
5317 (here lim)
5318 (hugenum (point-max)))
5319 (narrow-to-region lim (point))
5320 (while (/= here (point))
5321 (setq here (point))
3dcb36b7 5322 (vhdl-forward-comment hugenum)))))
d2ddb974
KH
5323
5324;; This is the best we can do in Win-Emacs.
5325(defun vhdl-win-fsws (&optional lim)
5eabfe72 5326 "Forward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5327 (let ((lim (or lim (point-max)))
5328 stop)
5329 (while (not stop)
5330 (skip-chars-forward " \t\n\r\f" lim)
5331 (cond
5332 ;; vhdl comment
5333 ((looking-at "--") (end-of-line))
5334 ;; none of the above
3dcb36b7 5335 (t (setq stop t))))))
d2ddb974 5336
5eabfe72 5337(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5338 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5339
5340(defun vhdl-backward-syntactic-ws (&optional lim)
5eabfe72 5341 "Backward skip over syntactic whitespace."
d2ddb974
KH
5342 (save-restriction
5343 (let* ((lim (or lim (point-min)))
5344 (here lim)
5345 (hugenum (- (point-max))))
5346 (if (< lim (point))
5347 (progn
5348 (narrow-to-region lim (point))
5349 (while (/= here (point))
5350 (setq here (point))
3dcb36b7 5351 (vhdl-forward-comment hugenum)))))))
d2ddb974
KH
5352
5353;; This is the best we can do in Win-Emacs.
5354(defun vhdl-win-bsws (&optional lim)
5eabfe72 5355 "Backward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5356 (let ((lim (or lim (vhdl-point 'bod)))
5357 stop)
5358 (while (not stop)
5359 (skip-chars-backward " \t\n\r\f" lim)
5360 (cond
5361 ;; vhdl comment
3dcb36b7 5362 ((eq (vhdl-in-literal) 'comment)
d2ddb974
KH
5363 (skip-chars-backward "^-" lim)
5364 (skip-chars-backward "-" lim)
5365 (while (not (or (and (= (following-char) ?-)
5366 (= (char-after (1+ (point))) ?-))
5367 (<= (point) lim)))
5368 (skip-chars-backward "^-" lim)
5369 (skip-chars-backward "-" lim)))
5370 ;; none of the above
3dcb36b7 5371 (t (setq stop t))))))
d2ddb974 5372
5eabfe72 5373(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5374 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5375
5376;; Functions to help finding the correct indentation column:
5377
5378(defun vhdl-first-word (point)
5379 "If the keyword at POINT is at boi, then return (current-column) at
5380that point, else nil."
5381 (save-excursion
5382 (and (goto-char point)
5383 (eq (point) (vhdl-point 'boi))
5384 (current-column))))
5385
5386(defun vhdl-last-word (point)
5387 "If the keyword at POINT is at eoi, then return (current-column) at
5388that point, else nil."
5389 (save-excursion
5390 (and (goto-char point)
5391 (save-excursion (or (eq (progn (forward-sexp) (point))
5392 (vhdl-point 'eoi))
5393 (looking-at "\\s-*\\(--\\)?")))
5394 (current-column))))
5395
5396;; Core syntactic evaluation functions:
5397
5398(defconst vhdl-libunit-re
5399 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5400
5401(defun vhdl-libunit-p ()
5402 (and
5403 (save-excursion
5404 (forward-sexp)
5405 (skip-chars-forward " \t\n")
5406 (not (looking-at "is\\b[^_]")))
5407 (save-excursion
5408 (backward-sexp)
5409 (and (not (looking-at "use\\b[^_]"))
5410 (progn
5411 (forward-sexp)
5412 (vhdl-forward-syntactic-ws)
5413 (/= (following-char) ?:))))
5414 ))
5415
5416(defconst vhdl-defun-re
5eabfe72 5417 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
d2ddb974
KH
5418
5419(defun vhdl-defun-p ()
5420 (save-excursion
5eabfe72
KH
5421 (if (looking-at "block\\|process\\|procedural")
5422 ;; "block", "process", "procedural":
d2ddb974
KH
5423 (save-excursion
5424 (backward-sexp)
5425 (not (looking-at "end\\s-+\\w")))
5426 ;; "architecture", "configuration", "entity",
5427 ;; "package", "procedure", "function":
5428 t)))
5429
5430(defun vhdl-corresponding-defun ()
5431 "If the word at the current position corresponds to a \"defun\"
5432keyword, then return a string that can be used to find the
5433corresponding \"begin\" keyword, else return nil."
5434 (save-excursion
5435 (and (looking-at vhdl-defun-re)
5436 (vhdl-defun-p)
5eabfe72
KH
5437 (if (looking-at "block\\|process\\|procedural")
5438 ;; "block", "process". "procedural:
d2ddb974
KH
5439 (buffer-substring (match-beginning 0) (match-end 0))
5440 ;; "architecture", "configuration", "entity", "package",
5441 ;; "procedure", "function":
5442 "is"))))
5443
5444(defconst vhdl-begin-fwd-re
5eabfe72 5445 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
d2ddb974
KH
5446 "A regular expression for searching forward that matches all known
5447\"begin\" keywords.")
5448
5449(defconst vhdl-begin-bwd-re
5eabfe72 5450 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
d2ddb974
KH
5451 "A regular expression for searching backward that matches all known
5452\"begin\" keywords.")
5453
5454(defun vhdl-begin-p (&optional lim)
5455 "Return t if we are looking at a real \"begin\" keyword.
5456Assumes that the caller will make sure that we are looking at
5457vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5458the middle of an identifier that just happens to contain a \"begin\"
5459keyword."
5460 (cond
5461 ;; "[architecture|case|configuration|entity|package|
5462 ;; procedure|function] ... is":
5463 ((and (looking-at "i")
5464 (save-excursion
5465 ;; Skip backward over first sexp (needed to skip over a
5466 ;; procedure interface list, and is harmless in other
5467 ;; situations). Note that we need "return" in the
5468 ;; following search list so that we don't run into
5469 ;; semicolons in the function interface list.
5470 (backward-sexp)
5471 (let (foundp)
5472 (while (and (not foundp)
5473 (re-search-backward
5eabfe72 5474 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
d2ddb974
KH
5475 lim 'move))
5476 (if (or (= (preceding-char) ?_)
3dcb36b7 5477 (vhdl-in-literal))
d2ddb974
KH
5478 (backward-char)
5479 (setq foundp t))))
5480 (and (/= (following-char) ?\;)
5eabfe72 5481 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
d2ddb974
KH
5482 t)
5483 ;; "begin", "then":
5484 ((looking-at "be\\|t")
5485 t)
5486 ;; "else":
5487 ((and (looking-at "e")
5488 ;; make sure that the "else" isn't inside a
5489 ;; conditional signal assignment.
5490 (save-excursion
5491 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5492 (or (eq (following-char) ?\;)
5493 (eq (point) lim))))
5494 t)
5eabfe72 5495 ;; "block", "generate", "loop", "process", "procedural",
d2ddb974
KH
5496 ;; "units", "record":
5497 ((and (looking-at "bl\\|[glpur]")
5498 (save-excursion
5499 (backward-sexp)
5500 (not (looking-at "end\\s-+\\w"))))
5501 t)
5502 ;; "component":
5503 ((and (looking-at "c")
5504 (save-excursion
5505 (backward-sexp)
5506 (not (looking-at "end\\s-+\\w")))
5507 ;; look out for the dreaded entity class in an attribute
5508 (save-excursion
5509 (vhdl-backward-syntactic-ws lim)
5510 (/= (preceding-char) ?:)))
5511 t)
5512 ;; "for" (inside configuration declaration):
5513 ((and (looking-at "f")
5514 (save-excursion
5515 (backward-sexp)
5516 (not (looking-at "end\\s-+\\w")))
5517 (vhdl-has-syntax 'configuration))
5518 t)
5519 ))
5520
5521(defun vhdl-corresponding-mid (&optional lim)
5522 (cond
5eabfe72 5523 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
d2ddb974
KH
5524 "begin")
5525 ((looking-at "then")
5526 "<else>")
5527 (t
5528 "end")))
5529
5530(defun vhdl-corresponding-end (&optional lim)
5531 "If the word at the current position corresponds to a \"begin\"
5532keyword, then return a vector containing enough information to find
5533the corresponding \"end\" keyword, else return nil. The keyword to
5534search forward for is aref 0. The column in which the keyword must
5535appear is aref 1 or nil if any column is suitable.
5536Assumes that the caller will make sure that we are not in the middle
5537of an identifier that just happens to contain a \"begin\" keyword."
5538 (save-excursion
5539 (and (looking-at vhdl-begin-fwd-re)
5540 (/= (preceding-char) ?_)
3dcb36b7 5541 (not (vhdl-in-literal))
d2ddb974
KH
5542 (vhdl-begin-p lim)
5543 (cond
5544 ;; "is", "generate", "loop":
5545 ((looking-at "[igl]")
5546 (vector "end"
5547 (and (vhdl-last-word (point))
5548 (or (vhdl-first-word (point))
5549 (save-excursion
5550 (vhdl-beginning-of-statement-1 lim)
5551 (vhdl-backward-skip-label lim)
5552 (vhdl-first-word (point)))))))
5553 ;; "begin", "else", "for":
5554 ((looking-at "be\\|[ef]")
5555 (vector "end"
5556 (and (vhdl-last-word (point))
5557 (or (vhdl-first-word (point))
5558 (save-excursion
5559 (vhdl-beginning-of-statement-1 lim)
5560 (vhdl-backward-skip-label lim)
5561 (vhdl-first-word (point)))))))
5562 ;; "component", "units", "record":
5563 ((looking-at "[cur]")
5564 ;; The first end found will close the block
5565 (vector "end" nil))
5eabfe72 5566 ;; "block", "process", "procedural":
d2ddb974
KH
5567 ((looking-at "bl\\|p")
5568 (vector "end"
5569 (or (vhdl-first-word (point))
5570 (save-excursion
5571 (vhdl-beginning-of-statement-1 lim)
5572 (vhdl-backward-skip-label lim)
5573 (vhdl-first-word (point))))))
5574 ;; "then":
5575 ((looking-at "t")
5576 (vector "elsif\\|else\\|end\\s-+if"
5577 (and (vhdl-last-word (point))
5578 (or (vhdl-first-word (point))
5579 (save-excursion
5580 (vhdl-beginning-of-statement-1 lim)
5581 (vhdl-backward-skip-label lim)
5582 (vhdl-first-word (point)))))))
5583 ))))
5584
5585(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5586
5587(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5588
5589(defun vhdl-end-p (&optional lim)
5590 "Return t if we are looking at a real \"end\" keyword.
5591Assumes that the caller will make sure that we are looking at
5592vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5593the middle of an identifier that just happens to contain an \"end\"
5594keyword."
5595 (or (not (looking-at "else"))
5596 ;; make sure that the "else" isn't inside a conditional signal
5597 ;; assignment.
5598 (save-excursion
5599 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5600 (or (eq (following-char) ?\;)
5601 (eq (point) lim)))))
5602
5603(defun vhdl-corresponding-begin (&optional lim)
5604 "If the word at the current position corresponds to an \"end\"
5605keyword, then return a vector containing enough information to find
5606the corresponding \"begin\" keyword, else return nil. The keyword to
3dcb36b7 5607search backward for is aref 0. The column in which the keyword must
d2ddb974
KH
5608appear is aref 1 or nil if any column is suitable. The supplementary
5609keyword to search forward for is aref 2 or nil if this is not
5610required. If aref 3 is t, then the \"begin\" keyword may be found in
5611the middle of a statement.
5612Assumes that the caller will make sure that we are not in the middle
5613of an identifier that just happens to contain an \"end\" keyword."
5614 (save-excursion
5615 (let (pos)
5616 (if (and (looking-at vhdl-end-fwd-re)
3dcb36b7 5617 (not (vhdl-in-literal))
d2ddb974
KH
5618 (vhdl-end-p lim))
5619 (if (looking-at "el")
5620 ;; "else", "elsif":
5621 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5622 ;; "end ...":
5623 (setq pos (point))
5624 (forward-sexp)
5625 (skip-chars-forward " \t\n")
5626 (cond
5627 ;; "end if":
5628 ((looking-at "if\\b[^_]")
5629 (vector "else\\|elsif\\|if"
5630 (vhdl-first-word pos)
5631 "else\\|then" nil))
5632 ;; "end component":
5633 ((looking-at "component\\b[^_]")
5634 (vector (buffer-substring (match-beginning 1)
5635 (match-end 1))
5636 (vhdl-first-word pos)
5637 nil nil))
5638 ;; "end units", "end record":
5639 ((looking-at "\\(units\\|record\\)\\b[^_]")
5640 (vector (buffer-substring (match-beginning 1)
5641 (match-end 1))
5642 (vhdl-first-word pos)
5643 nil t))
5eabfe72
KH
5644 ;; "end block", "end process", "end procedural":
5645 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
d2ddb974
KH
5646 (vector "begin" (vhdl-first-word pos) nil nil))
5647 ;; "end case":
5648 ((looking-at "case\\b[^_]")
5649 (vector "case" (vhdl-first-word pos) "is" nil))
5650 ;; "end generate":
5651 ((looking-at "generate\\b[^_]")
5652 (vector "generate\\|for\\|if"
5653 (vhdl-first-word pos)
5654 "generate" nil))
5655 ;; "end loop":
5656 ((looking-at "loop\\b[^_]")
5657 (vector "loop\\|while\\|for"
5658 (vhdl-first-word pos)
5659 "loop" nil))
5660 ;; "end for" (inside configuration declaration):
5661 ((looking-at "for\\b[^_]")
5662 (vector "for" (vhdl-first-word pos) nil nil))
5663 ;; "end [id]":
5664 (t
5665 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5666 (vhdl-first-word pos)
5667 ;; return an alist of (statement . keyword) mappings
5668 '(
5669 ;; "begin ... end [id]":
5670 ("begin" . nil)
5671 ;; "architecture ... is ... begin ... end [id]":
5672 ("architecture" . "is")
5673 ;; "configuration ... is ... end [id]":
5674 ("configuration" . "is")
5675 ;; "entity ... is ... end [id]":
5676 ("entity" . "is")
5677 ;; "package ... is ... end [id]":
5678 ("package" . "is")
5679 ;; "procedure ... is ... begin ... end [id]":
5680 ("procedure" . "is")
5681 ;; "function ... is ... begin ... end [id]":
5682 ("function" . "is")
5683 )
5684 nil))
5685 ))) ; "end ..."
5686 )))
5687
5688(defconst vhdl-leader-re
5eabfe72 5689 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
d2ddb974
KH
5690
5691(defun vhdl-end-of-leader ()
5692 (save-excursion
5eabfe72 5693 (cond ((looking-at "block\\|process\\|procedural")
d2ddb974
KH
5694 (if (save-excursion
5695 (forward-sexp)
5696 (skip-chars-forward " \t\n")
5697 (= (following-char) ?\())
5698 (forward-sexp 2)
5699 (forward-sexp))
3dcb36b7
JB
5700 (when (looking-at "[ \t\n]*is")
5701 (goto-char (match-end 0)))
d2ddb974
KH
5702 (point))
5703 ((looking-at "component")
5704 (forward-sexp 2)
3dcb36b7
JB
5705 (when (looking-at "[ \t\n]*is")
5706 (goto-char (match-end 0)))
d2ddb974
KH
5707 (point))
5708 ((looking-at "for")
5709 (forward-sexp 2)
5710 (skip-chars-forward " \t\n")
5711 (while (looking-at "[,:(]")
5712 (forward-sexp)
5713 (skip-chars-forward " \t\n"))
5714 (point))
5715 (t nil)
5716 )))
5717
5718(defconst vhdl-trailer-re
5719 "\\b\\(is\\|then\\|generate\\|loop\\)\\b[^_]")
5720
5721(defconst vhdl-statement-fwd-re
5722 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5723 "A regular expression for searching forward that matches all known
5724\"statement\" keywords.")
5725
5726(defconst vhdl-statement-bwd-re
5727 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5728 "A regular expression for searching backward that matches all known
5729\"statement\" keywords.")
5730
5731(defun vhdl-statement-p (&optional lim)
5732 "Return t if we are looking at a real \"statement\" keyword.
5733Assumes that the caller will make sure that we are looking at
5eabfe72
KH
5734vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5735in the middle of an identifier that just happens to contain a
5736\"statement\" keyword."
d2ddb974
KH
5737 (cond
5738 ;; "for" ... "generate":
5739 ((and (looking-at "f")
5740 ;; Make sure it's the start of a parameter specification.
5741 (save-excursion
5742 (forward-sexp 2)
5743 (skip-chars-forward " \t\n")
5744 (looking-at "in\\b[^_]"))
5745 ;; Make sure it's not an "end for".
5746 (save-excursion
5747 (backward-sexp)
5748 (not (looking-at "end\\s-+\\w"))))
5749 t)
5750 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5751 ((and (looking-at "i")
5752 ;; Make sure it's not an "end if".
5753 (save-excursion
5754 (backward-sexp)
5755 (not (looking-at "end\\s-+\\w"))))
5756 t)
5757 ;; "while" ... "loop":
5758 ((looking-at "w")
5759 t)
5760 ))
5761
5762(defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5763 "Regexp describing a case statement alternative key.")
5764
5765(defun vhdl-case-alternative-p (&optional lim)
5766 "Return t if we are looking at a real case alternative.
5767Assumes that the caller will make sure that we are looking at
5768vhdl-case-alternative-re, and are not inside a literal, and that
5769we are not in the middle of an identifier that just happens to
5770contain a \"when\" keyword."
5771 (save-excursion
5772 (let (foundp)
5773 (while (and (not foundp)
5774 (re-search-backward ";\\|<=" lim 'move))
5775 (if (or (= (preceding-char) ?_)
3dcb36b7 5776 (vhdl-in-literal))
d2ddb974
KH
5777 (backward-char)
5778 (setq foundp t)))
5779 (or (eq (following-char) ?\;)
5780 (eq (point) lim)))
5781 ))
5782
5783;; Core syntactic movement functions:
5784
5785(defconst vhdl-b-t-b-re
5786 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5787
5788(defun vhdl-backward-to-block (&optional lim)
5789 "Move backward to the previous \"begin\" or \"end\" keyword."
5790 (let (foundp)
5791 (while (and (not foundp)
5792 (re-search-backward vhdl-b-t-b-re lim 'move))
5793 (if (or (= (preceding-char) ?_)
3dcb36b7 5794 (vhdl-in-literal))
d2ddb974
KH
5795 (backward-char)
5796 (cond
5797 ;; "begin" keyword:
5798 ((and (looking-at vhdl-begin-fwd-re)
5799 (/= (preceding-char) ?_)
5800 (vhdl-begin-p lim))
5801 (setq foundp 'begin))
5802 ;; "end" keyword:
5803 ((and (looking-at vhdl-end-fwd-re)
5804 (/= (preceding-char) ?_)
5805 (vhdl-end-p lim))
5806 (setq foundp 'end))
5807 ))
5808 )
5809 foundp
5810 ))
5811
5812(defun vhdl-forward-sexp (&optional count lim)
5813 "Move forward across one balanced expression (sexp).
5814With COUNT, do it that many times."
5815 (interactive "p")
5816 (let ((count (or count 1))
5817 (case-fold-search t)
5818 end-vec target)
5819 (save-excursion
5820 (while (> count 0)
5821 ;; skip whitespace
5822 (skip-chars-forward " \t\n")
5823 ;; Check for an unbalanced "end" keyword
5824 (if (and (looking-at vhdl-end-fwd-re)
5825 (/= (preceding-char) ?_)
3dcb36b7 5826 (not (vhdl-in-literal))
d2ddb974
KH
5827 (vhdl-end-p lim)
5828 (not (looking-at "else")))
5829 (error
3dcb36b7 5830 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
d2ddb974
KH
5831 ;; If the current keyword is a "begin" keyword, then find the
5832 ;; corresponding "end" keyword.
5833 (if (setq end-vec (vhdl-corresponding-end lim))
5834 (let (
5835 ;; end-re is the statement keyword to search for
5836 (end-re
5837 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5838 ;; column is either the statement keyword target column
5839 ;; or nil
5840 (column (aref end-vec 1))
5841 (eol (vhdl-point 'eol))
5842 foundp literal placeholder)
5843 ;; Look for the statement keyword.
5844 (while (and (not foundp)
5845 (re-search-forward end-re nil t)
5846 (setq placeholder (match-end 1))
5847 (goto-char (match-beginning 0)))
5848 ;; If we are in a literal, or not in the right target
5849 ;; column and not on the same line as the begin, then
5850 ;; try again.
5851 (if (or (and column
5852 (/= (current-indentation) column)
5853 (> (point) eol))
5854 (= (preceding-char) ?_)
3dcb36b7 5855 (setq literal (vhdl-in-literal)))
d2ddb974
KH
5856 (if (eq literal 'comment)
5857 (end-of-line)
5858 (forward-char))
5859 ;; An "else" keyword corresponds to both the opening brace
5860 ;; of the following sexp and the closing brace of the
5861 ;; previous sexp.
5862 (if (not (looking-at "else"))
5863 (goto-char placeholder))
5864 (setq foundp t))
5865 )
5866 (if (not foundp)
3dcb36b7 5867 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
d2ddb974
KH
5868 )
5869 ;; If the current keyword is not a "begin" keyword, then just
5870 ;; perform the normal forward-sexp.
5871 (forward-sexp)
5872 )
5873 (setq count (1- count))
5874 )
5875 (setq target (point)))
5876 (goto-char target)
5877 nil))
5878
5879(defun vhdl-backward-sexp (&optional count lim)
5880 "Move backward across one balanced expression (sexp).
5881With COUNT, do it that many times. LIM bounds any required backward
5882searches."
5883 (interactive "p")
5884 (let ((count (or count 1))
5885 (case-fold-search t)
5886 begin-vec target)
5887 (save-excursion
5888 (while (> count 0)
5889 ;; Perform the normal backward-sexp, unless we are looking at
5890 ;; "else" - an "else" keyword corresponds to both the opening brace
5891 ;; of the following sexp and the closing brace of the previous sexp.
5892 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
5893 (/= (preceding-char) ?_)
3dcb36b7 5894 (not (vhdl-in-literal)))
d2ddb974
KH
5895 nil
5896 (backward-sexp)
5897 (if (and (looking-at vhdl-begin-fwd-re)
5898 (/= (preceding-char) ?_)
3dcb36b7 5899 (not (vhdl-in-literal))
d2ddb974 5900 (vhdl-begin-p lim))
3dcb36b7 5901 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
d2ddb974
KH
5902 ;; If the current keyword is an "end" keyword, then find the
5903 ;; corresponding "begin" keyword.
5904 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
5905 (/= (preceding-char) ?_))
5906 (let (
5907 ;; begin-re is the statement keyword to search for
5908 (begin-re
5909 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
5910 ;; column is either the statement keyword target column
5911 ;; or nil
5912 (column (aref begin-vec 1))
5913 ;; internal-p controls where the statement keyword can
5914 ;; be found.
5915 (internal-p (aref begin-vec 3))
5916 (last-backward (point)) last-forward
5917 foundp literal keyword)
5918 ;; Look for the statement keyword.
5919 (while (and (not foundp)
5920 (re-search-backward begin-re lim t)
5921 (setq keyword
5922 (buffer-substring (match-beginning 1)
5923 (match-end 1))))
5924 ;; If we are in a literal or in the wrong column,
5925 ;; then try again.
5926 (if (or (and column
5927 (and (/= (current-indentation) column)
5928 ;; possibly accept current-column as
5929 ;; well as current-indentation.
5930 (or (not internal-p)
5931 (/= (current-column) column))))
5932 (= (preceding-char) ?_)
3dcb36b7 5933 (vhdl-in-literal))
d2ddb974
KH
5934 (backward-char)
5935 ;; If there is a supplementary keyword, then
5936 ;; search forward for it.
5937 (if (and (setq begin-re (aref begin-vec 2))
5938 (or (not (listp begin-re))
5939 ;; If begin-re is an alist, then find the
5940 ;; element corresponding to the actual
5941 ;; keyword that we found.
5942 (progn
5943 (setq begin-re
5944 (assoc keyword begin-re))
5945 (and begin-re
5946 (setq begin-re (cdr begin-re))))))
5947 (and
5948 (setq begin-re
5949 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
5950 (save-excursion
5951 (setq last-forward (point))
5952 ;; Look for the supplementary keyword
5953 ;; (bounded by the backward search start
5954 ;; point).
5955 (while (and (not foundp)
5956 (re-search-forward begin-re
5957 last-backward t)
5958 (goto-char (match-beginning 1)))
5959 ;; If we are in a literal, then try again.
5960 (if (or (= (preceding-char) ?_)
5961 (setq literal
3dcb36b7 5962 (vhdl-in-literal)))
d2ddb974
KH
5963 (if (eq literal 'comment)
5964 (goto-char
5965 (min (vhdl-point 'eol) last-backward))
5966 (forward-char))
5967 ;; We have found the supplementary keyword.
5968 ;; Save the position of the keyword in foundp.
5969 (setq foundp (point)))
5970 )
5971 foundp)
5972 ;; If the supplementary keyword was found, then
5973 ;; move point to the supplementary keyword.
5974 (goto-char foundp))
5975 ;; If there was no supplementary keyword, then
5976 ;; point is already at the statement keyword.
5977 (setq foundp t)))
5978 ) ; end of the search for the statement keyword
5979 (if (not foundp)
3dcb36b7 5980 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
d2ddb974
KH
5981 ))
5982 (setq count (1- count))
5983 )
5984 (setq target (point)))
5985 (goto-char target)
5986 nil))
5987
5988(defun vhdl-backward-up-list (&optional count limit)
5989 "Move backward out of one level of blocks.
5990With argument, do this that many times."
5991 (interactive "p")
5992 (let ((count (or count 1))
5993 target)
5994 (save-excursion
5995 (while (> count 0)
5996 (if (looking-at vhdl-defun-re)
3dcb36b7 5997 (error "ERROR: Unbalanced blocks"))
d2ddb974
KH
5998 (vhdl-backward-to-block limit)
5999 (setq count (1- count)))
6000 (setq target (point)))
6001 (goto-char target)))
6002
6003(defun vhdl-end-of-defun (&optional count)
6004 "Move forward to the end of a VHDL defun."
6005 (interactive)
6006 (let ((case-fold-search t))
6007 (vhdl-beginning-of-defun)
5eabfe72 6008 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6009 (re-search-forward "\\bis\\b"))
6010 (vhdl-forward-sexp)))
6011
6012(defun vhdl-mark-defun ()
6013 "Put mark at end of this \"defun\", point at beginning."
6014 (interactive)
6015 (let ((case-fold-search t))
6016 (push-mark)
6017 (vhdl-beginning-of-defun)
6018 (push-mark)
5eabfe72 6019 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6020 (re-search-forward "\\bis\\b"))
6021 (vhdl-forward-sexp)
6022 (exchange-point-and-mark)))
6023
6024(defun vhdl-beginning-of-libunit ()
6025 "Move backward to the beginning of a VHDL library unit.
6026Returns the location of the corresponding begin keyword, unless search
5eabfe72
KH
6027stops due to beginning or end of buffer.
6028Note that if point is between the \"libunit\" keyword and the
6029corresponding \"begin\" keyword, then that libunit will not be
6030recognised, and the search will continue backwards. If point is
6031at the \"begin\" keyword, then the defun will be recognised. The
6032returned point is at the first character of the \"libunit\" keyword."
d2ddb974
KH
6033 (let ((last-forward (point))
6034 (last-backward
6035 ;; Just in case we are actually sitting on the "begin"
6036 ;; keyword, allow for the keyword and an extra character,
6037 ;; as this will be used when looking forward for the
6038 ;; "begin" keyword.
6039 (save-excursion (forward-word 1) (1+ (point))))
6040 foundp literal placeholder)
6041 ;; Find the "libunit" keyword.
6042 (while (and (not foundp)
6043 (re-search-backward vhdl-libunit-re nil 'move))
6044 ;; If we are in a literal, or not at a real libunit, then try again.
6045 (if (or (= (preceding-char) ?_)
3dcb36b7 6046 (vhdl-in-literal)
d2ddb974
KH
6047 (not (vhdl-libunit-p)))
6048 (backward-char)
6049 ;; Find the corresponding "begin" keyword.
6050 (setq last-forward (point))
6051 (while (and (not foundp)
6052 (re-search-forward "\\bis\\b[^_]" last-backward t)
6053 (setq placeholder (match-beginning 0)))
6054 (if (or (= (preceding-char) ?_)
3dcb36b7 6055 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6056 ;; It wasn't a real keyword, so keep searching.
6057 (if (eq literal 'comment)
6058 (goto-char
6059 (min (vhdl-point 'eol) last-backward))
6060 (forward-char))
6061 ;; We have found the begin keyword, loop will exit.
6062 (setq foundp placeholder)))
6063 ;; Go back to the libunit keyword
6064 (goto-char last-forward)))
6065 foundp))
6066
6067(defun vhdl-beginning-of-defun (&optional count)
6068 "Move backward to the beginning of a VHDL defun.
6069With argument, do it that many times.
6070Returns the location of the corresponding begin keyword, unless search
6071stops due to beginning or end of buffer."
6072 ;; Note that if point is between the "defun" keyword and the
6073 ;; corresponding "begin" keyword, then that defun will not be
6074 ;; recognised, and the search will continue backwards. If point is
6075 ;; at the "begin" keyword, then the defun will be recognised. The
6076 ;; returned point is at the first character of the "defun" keyword.
6077 (interactive "p")
6078 (let ((count (or count 1))
6079 (case-fold-search t)
6080 (last-forward (point))
6081 foundp)
6082 (while (> count 0)
6083 (setq foundp nil)
6084 (goto-char last-forward)
6085 (let ((last-backward
6086 ;; Just in case we are actually sitting on the "begin"
6087 ;; keyword, allow for the keyword and an extra character,
6088 ;; as this will be used when looking forward for the
6089 ;; "begin" keyword.
6090 (save-excursion (forward-word 1) (1+ (point))))
6091 begin-string literal)
6092 (while (and (not foundp)
6093 (re-search-backward vhdl-defun-re nil 'move))
6094 ;; If we are in a literal, then try again.
6095 (if (or (= (preceding-char) ?_)
3dcb36b7 6096 (vhdl-in-literal))
d2ddb974
KH
6097 (backward-char)
6098 (if (setq begin-string (vhdl-corresponding-defun))
6099 ;; This is a real defun keyword.
6100 ;; Find the corresponding "begin" keyword.
6101 ;; Look for the begin keyword.
6102 (progn
6103 ;; Save the search start point.
6104 (setq last-forward (point))
6105 (while (and (not foundp)
6106 (search-forward begin-string last-backward t))
6107 (if (or (= (preceding-char) ?_)
6108 (save-match-data
3dcb36b7 6109 (setq literal (vhdl-in-literal))))
d2ddb974
KH
6110 ;; It wasn't a real keyword, so keep searching.
6111 (if (eq literal 'comment)
6112 (goto-char
6113 (min (vhdl-point 'eol) last-backward))
6114 (forward-char))
6115 ;; We have found the begin keyword, loop will exit.
6116 (setq foundp (match-beginning 0)))
6117 )
6118 ;; Go back to the defun keyword
6119 (goto-char last-forward)) ; end search for begin keyword
6120 ))
6121 ) ; end of the search for the defun keyword
6122 )
6123 (setq count (1- count))
6124 )
6125 (vhdl-keep-region-active)
6126 foundp))
6127
8d422bd5 6128(defun vhdl-beginning-of-statement (&optional count lim interactive)
d2ddb974
KH
6129 "Go to the beginning of the innermost VHDL statement.
6130With prefix arg, go back N - 1 statements. If already at the
6131beginning of a statement then go to the beginning of the preceding
6132one. If within a string or comment, or next to a comment (only
6133whitespace between), move by sentences instead of statements.
6134
8d422bd5 6135When called from a program, this function takes 3 optional args: the
d2ddb974 6136prefix arg, and a buffer position limit which is the farthest back to
8d422bd5
RS
6137search, and something whose meaning I don't understand."
6138 (interactive "p\np")
d2ddb974
KH
6139 (let ((count (or count 1))
6140 (case-fold-search t)
6141 (lim (or lim (point-min)))
6142 (here (point))
6143 state)
6144 (save-excursion
6145 (goto-char lim)
6146 (setq state (parse-partial-sexp (point) here nil nil)))
8d422bd5 6147 (if (and interactive
d2ddb974
KH
6148 (or (nth 3 state)
6149 (nth 4 state)
6150 (looking-at (concat "[ \t]*" comment-start-skip))))
6151 (forward-sentence (- count))
6152 (while (> count 0)
6153 (vhdl-beginning-of-statement-1 lim)
6154 (setq count (1- count))))
6155 ;; its possible we've been left up-buf of lim
6156 (goto-char (max (point) lim))
6157 )
6158 (vhdl-keep-region-active))
6159
6160(defconst vhdl-e-o-s-re
6161 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6162
6163(defun vhdl-end-of-statement ()
6164 "Very simple implementation."
6165 (interactive)
6166 (re-search-forward vhdl-e-o-s-re))
6167
6168(defconst vhdl-b-o-s-re
6169 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6170 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6171
6172(defun vhdl-beginning-of-statement-1 (&optional lim)
5eabfe72
KH
6173 "Move to the start of the current statement, or the previous
6174statement if already at the beginning of one."
d2ddb974
KH
6175 (let ((lim (or lim (point-min)))
6176 (here (point))
6177 (pos (point))
6178 donep)
6179 ;; go backwards one balanced expression, but be careful of
6180 ;; unbalanced paren being reached
6181 (if (not (vhdl-safe (progn (backward-sexp) t)))
6182 (progn
6183 (backward-up-list 1)
6184 (forward-char)
6185 (vhdl-forward-syntactic-ws here)
6186 (setq donep t)))
6187 (while (and (not donep)
6188 (not (bobp))
6189 ;; look backwards for a statement boundary
6190 (re-search-backward vhdl-b-o-s-re lim 'move))
6191 (if (or (= (preceding-char) ?_)
3dcb36b7 6192 (vhdl-in-literal))
d2ddb974
KH
6193 (backward-char)
6194 (cond
6195 ;; If we are looking at an open paren, then stop after it
6196 ((eq (following-char) ?\()
6197 (forward-char)
6198 (vhdl-forward-syntactic-ws here)
6199 (setq donep t))
6200 ;; If we are looking at a close paren, then skip it
6201 ((eq (following-char) ?\))
6202 (forward-char)
6203 (setq pos (point))
6204 (backward-sexp)
6205 (if (< (point) lim)
6206 (progn (goto-char pos)
6207 (vhdl-forward-syntactic-ws here)
6208 (setq donep t))))
6209 ;; If we are looking at a semicolon, then stop
6210 ((eq (following-char) ?\;)
6211 (progn
6212 (forward-char)
6213 (vhdl-forward-syntactic-ws here)
6214 (setq donep t)))
6215 ;; If we are looking at a "begin", then stop
6216 ((and (looking-at vhdl-begin-fwd-re)
6217 (/= (preceding-char) ?_)
6218 (vhdl-begin-p nil))
6219 ;; If it's a leader "begin", then find the
6220 ;; right place
6221 (if (looking-at vhdl-leader-re)
6222 (save-excursion
6223 ;; set a default stop point at the begin
6224 (setq pos (point))
6225 ;; is the start point inside the leader area ?
6226 (goto-char (vhdl-end-of-leader))
6227 (vhdl-forward-syntactic-ws here)
6228 (if (< (point) here)
6229 ;; start point was not inside leader area
6230 ;; set stop point at word after leader
6231 (setq pos (point))))
6232 (forward-word 1)
6233 (vhdl-forward-syntactic-ws here)
6234 (setq pos (point)))
6235 (goto-char pos)
6236 (setq donep t))
6237 ;; If we are looking at a "statement", then stop
6238 ((and (looking-at vhdl-statement-fwd-re)
6239 (/= (preceding-char) ?_)
6240 (vhdl-statement-p nil))
6241 (setq donep t))
6242 ;; If we are looking at a case alternative key, then stop
5eabfe72
KH
6243 ((and (looking-at vhdl-case-alternative-re)
6244 (vhdl-case-alternative-p lim))
d2ddb974
KH
6245 (save-excursion
6246 ;; set a default stop point at the when
6247 (setq pos (point))
6248 ;; is the start point inside the case alternative key ?
6249 (looking-at vhdl-case-alternative-re)
6250 (goto-char (match-end 0))
6251 (vhdl-forward-syntactic-ws here)
6252 (if (< (point) here)
6253 ;; start point was not inside the case alternative key
6254 ;; set stop point at word after case alternative keyleader
6255 (setq pos (point))))
6256 (goto-char pos)
6257 (setq donep t))
6258 ;; Bogus find, continue
6259 (t
6260 (backward-char)))))
6261 ))
6262
6263;; Defuns for calculating the current syntactic state:
6264
6265(defun vhdl-get-library-unit (bod placeholder)
5eabfe72
KH
6266 "If there is an enclosing library unit at bod, with it's \"begin\"
6267keyword at placeholder, then return the library unit type."
d2ddb974
KH
6268 (let ((here (vhdl-point 'bol)))
6269 (if (save-excursion
6270 (goto-char placeholder)
6271 (vhdl-safe (vhdl-forward-sexp 1 bod))
6272 (<= here (point)))
6273 (save-excursion
6274 (goto-char bod)
6275 (cond
6276 ((looking-at "e") 'entity)
6277 ((looking-at "a") 'architecture)
6278 ((looking-at "c") 'configuration)
6279 ((looking-at "p")
6280 (save-excursion
6281 (goto-char bod)
6282 (forward-sexp)
6283 (vhdl-forward-syntactic-ws here)
6284 (if (looking-at "body\\b[^_]")
6285 'package-body 'package))))))
6286 ))
6287
6288(defun vhdl-get-block-state (&optional lim)
5eabfe72
KH
6289 "Finds and records all the closest opens.
6290lim is the furthest back we need to search (it should be the
6291previous libunit keyword)."
d2ddb974
KH
6292 (let ((here (point))
6293 (lim (or lim (point-min)))
6294 keyword sexp-start sexp-mid sexp-end
6295 preceding-sexp containing-sexp
6296 containing-begin containing-mid containing-paren)
6297 (save-excursion
6298 ;; Find the containing-paren, and use that as the limit
6299 (if (setq containing-paren
6300 (save-restriction
6301 (narrow-to-region lim (point))
6302 (vhdl-safe (scan-lists (point) -1 1))))
6303 (setq lim containing-paren))
6304 ;; Look backwards for "begin" and "end" keywords.
6305 (while (and (> (point) lim)
6306 (not containing-sexp))
6307 (setq keyword (vhdl-backward-to-block lim))
6308 (cond
6309 ((eq keyword 'begin)
6310 ;; Found a "begin" keyword
6311 (setq sexp-start (point))
6312 (setq sexp-mid (vhdl-corresponding-mid lim))
6313 (setq sexp-end (vhdl-safe
6314 (save-excursion
6315 (vhdl-forward-sexp 1 lim) (point))))
6316 (if (and sexp-end (<= sexp-end here))
6317 ;; we want to record this sexp, but we only want to
6318 ;; record the last-most of any of them before here
6319 (or preceding-sexp
6320 (setq preceding-sexp sexp-start))
6321 ;; we're contained in this sexp so put sexp-start on
6322 ;; front of list
6323 (setq containing-sexp sexp-start)
6324 (setq containing-mid sexp-mid)
6325 (setq containing-begin t)))
6326 ((eq keyword 'end)
6327 ;; Found an "end" keyword
6328 (forward-sexp)
6329 (setq sexp-end (point))
6330 (setq sexp-mid nil)
6331 (setq sexp-start
6332 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6333 (progn (backward-sexp) (point))))
6334 ;; we want to record this sexp, but we only want to
6335 ;; record the last-most of any of them before here
6336 (or preceding-sexp
6337 (setq preceding-sexp sexp-start)))
6338 )))
6339 ;; Check if the containing-paren should be the containing-sexp
6340 (if (and containing-paren
6341 (or (null containing-sexp)
6342 (< containing-sexp containing-paren)))
6343 (setq containing-sexp containing-paren
6344 preceding-sexp nil
6345 containing-begin nil
6346 containing-mid nil))
6347 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6348 ))
6349
6350
6351(defconst vhdl-s-c-a-re
6352 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6353
6354(defun vhdl-skip-case-alternative (&optional lim)
5eabfe72
KH
6355 "Skip forward over case/when bodies, with optional maximal
6356limit. If no next case alternative is found, nil is returned and point
6357is not moved."
d2ddb974
KH
6358 (let ((lim (or lim (point-max)))
6359 (here (point))
6360 donep foundp)
6361 (while (and (< (point) lim)
6362 (not donep))
6363 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6364 (save-match-data
6365 (not (vhdl-in-literal)))
6366 (/= (match-beginning 0) here))
6367 (progn
6368 (goto-char (match-beginning 0))
6369 (cond
6370 ((and (looking-at "case")
6371 (re-search-forward "\\bis[^_]" lim t))
6372 (backward-sexp)
6373 (vhdl-forward-sexp))
6374 (t
6375 (setq donep t
6376 foundp t))))))
6377 (if (not foundp)
6378 (goto-char here))
6379 foundp))
6380
6381(defun vhdl-backward-skip-label (&optional lim)
5eabfe72
KH
6382 "Skip backward over a label, with optional maximal
6383limit. If label is not found, nil is returned and point
6384is not moved."
d2ddb974
KH
6385 (let ((lim (or lim (point-min)))
6386 placeholder)
6387 (if (save-excursion
6388 (vhdl-backward-syntactic-ws lim)
6389 (and (eq (preceding-char) ?:)
6390 (progn
6391 (backward-sexp)
6392 (setq placeholder (point))
6393 (looking-at vhdl-label-key))))
6394 (goto-char placeholder))
6395 ))
6396
6397(defun vhdl-forward-skip-label (&optional lim)
5eabfe72
KH
6398 "Skip forward over a label, with optional maximal
6399limit. If label is not found, nil is returned and point
6400is not moved."
d2ddb974
KH
6401 (let ((lim (or lim (point-max))))
6402 (if (looking-at vhdl-label-key)
6403 (progn
6404 (goto-char (match-end 0))
6405 (vhdl-forward-syntactic-ws lim)))
6406 ))
6407
6408(defun vhdl-get-syntactic-context ()
5eabfe72 6409 "Guess the syntactic description of the current line of VHDL code."
d2ddb974
KH
6410 (save-excursion
6411 (save-restriction
6412 (beginning-of-line)
6413 (let* ((indent-point (point))
6414 (case-fold-search t)
6415 vec literal containing-sexp preceding-sexp
6416 containing-begin containing-mid containing-leader
6417 char-before-ip char-after-ip begin-after-ip end-after-ip
6418 placeholder lim library-unit
6419 )
6420
6421 ;; Reset the syntactic context
6422 (setq vhdl-syntactic-context nil)
6423
6424 (save-excursion
6425 ;; Move to the start of the previous library unit, and
6426 ;; record the position of the "begin" keyword.
6427 (setq placeholder (vhdl-beginning-of-libunit))
6428 ;; The position of the "libunit" keyword gives us a gross
6429 ;; limit point.
6430 (setq lim (point))
6431 )
6432
6433 ;; If there is a previous library unit, and we are enclosed by
6434 ;; it, then set the syntax accordingly.
6435 (and placeholder
6436 (setq library-unit (vhdl-get-library-unit lim placeholder))
6437 (vhdl-add-syntax library-unit lim))
6438
6439 ;; Find the surrounding state.
6440 (if (setq vec (vhdl-get-block-state lim))
6441 (progn
6442 (setq containing-sexp (aref vec 0))
6443 (setq preceding-sexp (aref vec 1))
6444 (setq containing-begin (aref vec 2))
6445 (setq containing-mid (aref vec 3))
6446 ))
6447
6448 ;; set the limit on the farthest back we need to search
6449 (setq lim (if containing-sexp
6450 (save-excursion
6451 (goto-char containing-sexp)
6452 ;; set containing-leader if required
6453 (if (looking-at vhdl-leader-re)
6454 (setq containing-leader (vhdl-end-of-leader)))
6455 (vhdl-point 'bol))
6456 (point-min)))
6457
6458 ;; cache char before and after indent point, and move point to
6459 ;; the most likely position to perform the majority of tests
6460 (goto-char indent-point)
6461 (skip-chars-forward " \t")
3dcb36b7 6462 (setq literal (vhdl-in-literal))
d2ddb974
KH
6463 (setq char-after-ip (following-char))
6464 (setq begin-after-ip (and
6465 (not literal)
6466 (looking-at vhdl-begin-fwd-re)
6467 (vhdl-begin-p)))
6468 (setq end-after-ip (and
6469 (not literal)
6470 (looking-at vhdl-end-fwd-re)
6471 (vhdl-end-p)))
6472 (vhdl-backward-syntactic-ws lim)
6473 (setq char-before-ip (preceding-char))
6474 (goto-char indent-point)
6475 (skip-chars-forward " \t")
6476
6477 ;; now figure out syntactic qualities of the current line
6478 (cond
6479 ;; CASE 1: in a string or comment.
6480 ((memq literal '(string comment))
6481 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6482 ;; CASE 2: Line is at top level.
6483 ((null containing-sexp)
6484 ;; Find the point to which indentation will be relative
6485 (save-excursion
6486 (if (null preceding-sexp)
6487 ;; CASE 2X.1
6488 ;; no preceding-sexp -> use the preceding statement
6489 (vhdl-beginning-of-statement-1 lim)
6490 ;; CASE 2X.2
6491 ;; if there is a preceding-sexp then indent relative to it
6492 (goto-char preceding-sexp)
6493 ;; if not at boi, then the block-opening keyword is
6494 ;; probably following a label, so we need a different
6495 ;; relpos
6496 (if (/= (point) (vhdl-point 'boi))
6497 ;; CASE 2X.3
6498 (vhdl-beginning-of-statement-1 lim)))
6499 ;; v-b-o-s could have left us at point-min
6500 (and (bobp)
6501 ;; CASE 2X.4
6502 (vhdl-forward-syntactic-ws indent-point))
6503 (setq placeholder (point)))
6504 (cond
6505 ;; CASE 2A : we are looking at a block-open
6506 (begin-after-ip
6507 (vhdl-add-syntax 'block-open placeholder))
6508 ;; CASE 2B: we are looking at a block-close
6509 (end-after-ip
6510 (vhdl-add-syntax 'block-close placeholder))
6511 ;; CASE 2C: we are looking at a top-level statement
6512 ((progn
6513 (vhdl-backward-syntactic-ws lim)
6514 (or (bobp)
6515 (= (preceding-char) ?\;)))
6516 (vhdl-add-syntax 'statement placeholder))
6517 ;; CASE 2D: we are looking at a top-level statement-cont
6518 (t
6519 (vhdl-beginning-of-statement-1 lim)
6520 ;; v-b-o-s could have left us at point-min
6521 (and (bobp)
6522 ;; CASE 2D.1
6523 (vhdl-forward-syntactic-ws indent-point))
6524 (vhdl-add-syntax 'statement-cont (point)))
6525 )) ; end CASE 2
6526 ;; CASE 3: line is inside parentheses. Most likely we are
6527 ;; either in a subprogram argument (interface) list, or a
6528 ;; continued expression containing parentheses.
6529 ((null containing-begin)
6530 (vhdl-backward-syntactic-ws containing-sexp)
6531 (cond
6532 ;; CASE 3A: we are looking at the arglist closing paren
6533 ((eq char-after-ip ?\))
6534 (goto-char containing-sexp)
6535 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6536 ;; CASE 3B: we are looking at the first argument in an empty
6537 ;; argument list.
6538 ((eq char-before-ip ?\()
6539 (goto-char containing-sexp)
6540 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6541 ;; CASE 3C: we are looking at an arglist continuation line,
6542 ;; but the preceding argument is on the same line as the
6543 ;; opening paren. This case includes multi-line
6544 ;; expression paren groupings.
6545 ((and (save-excursion
6546 (goto-char (1+ containing-sexp))
6547 (skip-chars-forward " \t")
6548 (not (eolp))
6549 (not (looking-at "--")))
6550 (save-excursion
6551 (vhdl-beginning-of-statement-1 containing-sexp)
6552 (skip-chars-backward " \t(")
6553 (<= (point) containing-sexp)))
6554 (goto-char containing-sexp)
6555 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6556 ;; CASE 3D: we are looking at just a normal arglist
6557 ;; continuation line
6558 (t (vhdl-beginning-of-statement-1 containing-sexp)
6559 (vhdl-forward-syntactic-ws indent-point)
6560 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6561 ))
6562 ;; CASE 4: A block mid open
6563 ((and begin-after-ip
6564 (looking-at containing-mid))
6565 (goto-char containing-sexp)
6566 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6567 (if (looking-at vhdl-trailer-re)
6568 ;; CASE 4.1
6569 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6570 (vhdl-backward-skip-label (vhdl-point 'boi))
6571 (vhdl-add-syntax 'block-open (point)))
6572 ;; CASE 5: block close brace
6573 (end-after-ip
6574 (goto-char containing-sexp)
6575 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6576 (if (looking-at vhdl-trailer-re)
6577 ;; CASE 5.1
6578 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6579 (vhdl-backward-skip-label (vhdl-point 'boi))
6580 (vhdl-add-syntax 'block-close (point)))
6581 ;; CASE 6: A continued statement
6582 ((and (/= char-before-ip ?\;)
6583 ;; check it's not a trailer begin keyword, or a begin
6584 ;; keyword immediately following a label.
6585 (not (and begin-after-ip
6586 (or (looking-at vhdl-trailer-re)
6587 (save-excursion
6588 (vhdl-backward-skip-label containing-sexp)))))
6589 ;; check it's not a statement keyword
6590 (not (and (looking-at vhdl-statement-fwd-re)
6591 (vhdl-statement-p)))
6592 ;; see if the b-o-s is before the indent point
6593 (> indent-point
6594 (save-excursion
6595 (vhdl-beginning-of-statement-1 containing-sexp)
6596 ;; If we ended up after a leader, then this will
6597 ;; move us forward to the start of the first
6598 ;; statement. Note that a containing sexp here is
6599 ;; always a keyword, not a paren, so this will
6600 ;; have no effect if we hit the containing-sexp.
6601 (vhdl-forward-syntactic-ws indent-point)
6602 (setq placeholder (point))))
6603 ;; check it's not a block-intro
6604 (/= placeholder containing-sexp)
6605 ;; check it's not a case block-intro
6606 (save-excursion
6607 (goto-char placeholder)
6608 (or (not (looking-at vhdl-case-alternative-re))
6609 (> (match-end 0) indent-point))))
6610 ;; Make placeholder skip a label, but only if it puts us
6611 ;; before the indent point at the start of a line.
6612 (let ((new placeholder))
6613 (if (and (> indent-point
6614 (save-excursion
6615 (goto-char placeholder)
6616 (vhdl-forward-skip-label indent-point)
6617 (setq new (point))))
6618 (save-excursion
6619 (goto-char new)
6620 (eq new (progn (back-to-indentation) (point)))))
6621 (setq placeholder new)))
6622 (vhdl-add-syntax 'statement-cont placeholder)
6623 (if begin-after-ip
6624 (vhdl-add-syntax 'block-open)))
6625 ;; Statement. But what kind?
6626 ;; CASE 7: A case alternative key
6627 ((and (looking-at vhdl-case-alternative-re)
6628 (vhdl-case-alternative-p containing-sexp))
6629 ;; for a case alternative key, we set relpos to the first
6630 ;; non-whitespace char on the line containing the "case"
6631 ;; keyword.
6632 (goto-char containing-sexp)
6633 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6634 (if (looking-at vhdl-trailer-re)
6635 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6636 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6637 ;; CASE 8: statement catchall
6638 (t
6639 ;; we know its a statement, but we need to find out if it is
6640 ;; the first statement in a block
6641 (if containing-leader
6642 (goto-char containing-leader)
6643 (goto-char containing-sexp)
6644 ;; Note that a containing sexp here is always a keyword,
6645 ;; not a paren, so skip over the keyword.
6646 (forward-sexp))
6647 ;; move to the start of the first statement
6648 (vhdl-forward-syntactic-ws indent-point)
6649 (setq placeholder (point))
6650 ;; we want to ignore case alternatives keys when skipping forward
6651 (let (incase-p)
6652 (while (looking-at vhdl-case-alternative-re)
6653 (setq incase-p (point))
6654 ;; we also want to skip over the body of the
6655 ;; case/when statement if that doesn't put us at
6656 ;; after the indent-point
6657 (while (vhdl-skip-case-alternative indent-point))
6658 ;; set up the match end
6659 (looking-at vhdl-case-alternative-re)
6660 (goto-char (match-end 0))
6661 ;; move to the start of the first case alternative statement
6662 (vhdl-forward-syntactic-ws indent-point)
6663 (setq placeholder (point)))
6664 (cond
6665 ;; CASE 8A: we saw a case/when statement so we must be
6666 ;; in a switch statement. find out if we are at the
6667 ;; statement just after a case alternative key
6668 ((and incase-p
6669 (= (point) indent-point))
6670 ;; relpos is the "when" keyword
6671 (vhdl-add-syntax 'statement-case-intro incase-p))
6672 ;; CASE 8B: any old statement
6673 ((< (point) indent-point)
6674 ;; relpos is the first statement of the block
6675 (vhdl-add-syntax 'statement placeholder)
6676 (if begin-after-ip
6677 (vhdl-add-syntax 'block-open)))
6678 ;; CASE 8C: first statement in a block
6679 (t
6680 (goto-char containing-sexp)
6681 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6682 (if (looking-at vhdl-trailer-re)
6683 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6684 (vhdl-backward-skip-label (vhdl-point 'boi))
6685 (vhdl-add-syntax 'statement-block-intro (point))
6686 (if begin-after-ip
6687 (vhdl-add-syntax 'block-open)))
6688 )))
6689 )
6690
6691 ;; now we need to look at any modifiers
6692 (goto-char indent-point)
6693 (skip-chars-forward " \t")
6694 (if (looking-at "--")
6695 (vhdl-add-syntax 'comment))
6696 ;; return the syntax
6697 vhdl-syntactic-context))))
6698
6699;; Standard indentation line-ups:
6700
6701(defun vhdl-lineup-arglist (langelem)
5eabfe72
KH
6702 "Lineup the current arglist line with the arglist appearing just
6703after the containing paren which starts the arglist."
d2ddb974
KH
6704 (save-excursion
6705 (let* ((containing-sexp
6706 (save-excursion
6707 ;; arglist-cont-nonempty gives relpos ==
6708 ;; to boi of containing-sexp paren. This
6709 ;; is good when offset is +, but bad
6710 ;; when it is vhdl-lineup-arglist, so we
6711 ;; have to special case a kludge here.
6712 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6713 (progn
6714 (beginning-of-line)
6715 (backward-up-list 1)
6716 (skip-chars-forward " \t" (vhdl-point 'eol)))
6717 (goto-char (cdr langelem)))
6718 (point)))
6719 (cs-curcol (save-excursion
6720 (goto-char (cdr langelem))
6721 (current-column))))
6722 (if (save-excursion
6723 (beginning-of-line)
6724 (looking-at "[ \t]*)"))
6725 (progn (goto-char (match-end 0))
6726 (backward-sexp)
6727 (forward-char)
6728 (vhdl-forward-syntactic-ws)
6729 (- (current-column) cs-curcol))
6730 (goto-char containing-sexp)
6731 (or (eolp)
6732 (let ((eol (vhdl-point 'eol))
6733 (here (progn
6734 (forward-char)
6735 (skip-chars-forward " \t")
6736 (point))))
6737 (vhdl-forward-syntactic-ws)
6738 (if (< (point) eol)
6739 (goto-char here))))
6740 (- (current-column) cs-curcol)
6741 ))))
6742
6743(defun vhdl-lineup-arglist-intro (langelem)
5eabfe72 6744 "Lineup an arglist-intro line to just after the open paren."
d2ddb974
KH
6745 (save-excursion
6746 (let ((cs-curcol (save-excursion
6747 (goto-char (cdr langelem))
6748 (current-column)))
6749 (ce-curcol (save-excursion
6750 (beginning-of-line)
6751 (backward-up-list 1)
6752 (skip-chars-forward " \t" (vhdl-point 'eol))
6753 (current-column))))
6754 (- ce-curcol cs-curcol -1))))
6755
6756(defun vhdl-lineup-comment (langelem)
5eabfe72
KH
6757 "Support old behavior for comment indentation. We look at
6758vhdl-comment-only-line-offset to decide how to indent comment
6759only-lines."
d2ddb974
KH
6760 (save-excursion
6761 (back-to-indentation)
6762 ;; at or to the right of comment-column
6763 (if (>= (current-column) comment-column)
6764 (vhdl-comment-indent)
6765 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6766 (if (not (bolp))
6767 (or (car-safe vhdl-comment-only-line-offset)
6768 vhdl-comment-only-line-offset)
6769 (or (cdr-safe vhdl-comment-only-line-offset)
6770 (car-safe vhdl-comment-only-line-offset)
5eabfe72 6771 -1000 ;jam it against the left side
d2ddb974
KH
6772 )))))
6773
6774(defun vhdl-lineup-statement-cont (langelem)
5eabfe72 6775 "Line up statement-cont after the assignment operator."
d2ddb974
KH
6776 (save-excursion
6777 (let* ((relpos (cdr langelem))
6778 (assignp (save-excursion
6779 (goto-char (vhdl-point 'boi))
6780 (and (re-search-forward "\\(<\\|:\\)="
6781 (vhdl-point 'eol) t)
6782 (- (point) (vhdl-point 'boi)))))
6783 (curcol (progn
6784 (goto-char relpos)
6785 (current-column)))
6786 foundp)
6787 (while (and (not foundp)
6788 (< (point) (vhdl-point 'eol)))
6789 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
3dcb36b7 6790 (if (vhdl-in-literal)
d2ddb974
KH
6791 (forward-char)
6792 (if (= (preceding-char) ?\()
6793 ;; skip over any parenthesized expressions
6794 (goto-char (min (vhdl-point 'eol)
6795 (scan-lists (point) 1 1)))
6796 ;; found an assignment operator (not at eol)
6797 (setq foundp (not (looking-at "\\s-*$"))))))
6798 (if (not foundp)
6799 ;; there's no assignment operator on the line
6800 vhdl-basic-offset
6801 ;; calculate indentation column after assign and ws, unless
6802 ;; our line contains an assignment operator
6803 (if (not assignp)
6804 (progn
6805 (forward-char)
6806 (skip-chars-forward " \t")
6807 (setq assignp 0)))
6808 (- (current-column) assignp curcol))
6809 )))
6810
5eabfe72 6811;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 6812;; Progress reporting
d2ddb974 6813
3dcb36b7
JB
6814(defvar vhdl-progress-info nil
6815 "Array variable for progress information: 0 begin, 1 end, 2 time.")
5eabfe72 6816
3dcb36b7
JB
6817(defun vhdl-update-progress-info (string pos)
6818 "Update progress information."
6819 (when (and vhdl-progress-info (not noninteractive)
6820 (< vhdl-progress-interval
6821 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6822 (message (concat string "... (%2d%s)")
6823 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6824 (- (aref vhdl-progress-info 1)
6825 (aref vhdl-progress-info 0))) "%")
6826 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
5eabfe72 6827
3dcb36b7
JB
6828;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6829;; Indentation commands
5eabfe72
KH
6830
6831(defun vhdl-electric-tab (&optional prefix-arg)
6832 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7
JB
6833else if right of non whitespace on line then insert tab,
6834else if last command was a tab or return then dedent one step or if a comment
6835toggle between normal indent and inline comment indent,
d2ddb974
KH
6836else indent `correctly'."
6837 (interactive "*P")
3dcb36b7
JB
6838 (vhdl-prepare-search-2
6839 (cond
6840 ;; expand word
6841 ((= (char-syntax (preceding-char)) ?w)
6842 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6843 (case-replace nil)
6844 (hippie-expand-only-buffers
6845 (or (and (boundp 'hippie-expand-only-buffers)
6846 hippie-expand-only-buffers)
6847 '(vhdl-mode))))
6848 (vhdl-expand-abbrev prefix-arg)))
6849 ;; expand parenthesis
6850 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6851 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6852 (case-replace nil))
6853 (vhdl-expand-paren prefix-arg)))
6854 ;; insert tab
6855 ((> (current-column) (current-indentation))
6856 (insert-tab))
6857 ;; toggle comment indent
6858 ((and (looking-at "--")
6859 (or (eq last-command 'vhdl-electric-tab)
6860 (eq last-command 'vhdl-electric-return)))
6861 (cond ((= (current-indentation) 0) ; no indent
6862 (indent-to 1)
6863 (indent-according-to-mode))
6864 ((< (current-indentation) comment-column) ; normal indent
6865 (indent-to comment-column)
6866 (indent-according-to-mode))
6867 (t ; inline comment indent
6868 (kill-line -0))))
6869 ;; dedent
6870 ((and (>= (current-indentation) vhdl-basic-offset)
6871 (or (eq last-command 'vhdl-electric-tab)
6872 (eq last-command 'vhdl-electric-return)))
6873 (backward-delete-char-untabify vhdl-basic-offset nil))
6874 ;; indent line
6875 (t (indent-according-to-mode)))
5eabfe72
KH
6876 (setq this-command 'vhdl-electric-tab)))
6877
6878(defun vhdl-electric-return ()
d2ddb974
KH
6879 "newline-and-indent or indent-new-comment-line if in comment and preceding
6880character is a space."
6881 (interactive)
6882 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
6883 (indent-new-comment-line)
3dcb36b7
JB
6884 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
6885 (vhdl-fix-case-word -1))
5eabfe72
KH
6886 (newline-and-indent)))
6887
d2ddb974 6888(defun vhdl-indent-line ()
5eabfe72 6889 "Indent the current line as VHDL code. Returns the amount of
d2ddb974
KH
6890indentation change."
6891 (interactive)
3dcb36b7 6892 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
d2ddb974 6893 (pos (- (point-max) (point)))
3dcb36b7
JB
6894 (indent
6895 (if syntax
6896 ;; indent syntax-based
6897 (if (and (eq (caar syntax) 'comment)
6898 (>= (vhdl-get-offset (car syntax)) comment-column))
6899 ;; special case: comments at or right of comment-column
6900 (vhdl-get-offset (car syntax))
6901 (apply '+ (mapcar 'vhdl-get-offset syntax)))
6902 ;; indent like previous nonblank line
6903 (save-excursion (beginning-of-line)
6904 (re-search-backward "^[^\n]" nil t)
6905 (current-indentation))))
5eabfe72 6906 (shift-amt (- indent (current-indentation))))
d2ddb974
KH
6907 (and vhdl-echo-syntactic-information-p
6908 (message "syntax: %s, indent= %d" syntax indent))
5eabfe72 6909 (unless (zerop shift-amt)
d2ddb974
KH
6910 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
6911 (beginning-of-line)
6912 (indent-to indent))
6913 (if (< (point) (vhdl-point 'boi))
6914 (back-to-indentation)
6915 ;; If initial point was within line's indentation, position after
6916 ;; the indentation. Else stay at same point in text.
5eabfe72
KH
6917 (when (> (- (point-max) pos) (point))
6918 (goto-char (- (point-max) pos))))
d2ddb974 6919 (run-hooks 'vhdl-special-indent-hook)
3dcb36b7 6920 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
d2ddb974
KH
6921 shift-amt))
6922
3dcb36b7 6923(defun vhdl-indent-region (beg end column)
5eabfe72
KH
6924 "Indent region as VHDL code.
6925Adds progress reporting to `indent-region'."
6926 (interactive "r\nP")
3dcb36b7
JB
6927 (when vhdl-progress-interval
6928 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
6929 (count-lines (point-min) end) 0)))
6930 (indent-region beg end column)
5eabfe72
KH
6931 (when vhdl-progress-interval (message "Indenting...done"))
6932 (setq vhdl-progress-info nil))
d2ddb974 6933
3dcb36b7
JB
6934(defun vhdl-indent-buffer ()
6935 "Indent whole buffer as VHDL code.
6936Calls `indent-region' for whole buffer and adds progress reporting."
6937 (interactive)
6938 (vhdl-indent-region (point-min) (point-max) nil))
6939
6940(defun vhdl-indent-group ()
6941 "Indent group of lines between empty lines."
6942 (interactive)
6943 (let ((beg (save-excursion
6944 (if (re-search-backward vhdl-align-group-separate nil t)
6945 (point-marker)
6946 (point-min-marker))))
6947 (end (save-excursion
6948 (if (re-search-forward vhdl-align-group-separate nil t)
6949 (point-marker)
6950 (point-max-marker)))))
6951 (vhdl-indent-region beg end nil)))
6952
d2ddb974
KH
6953(defun vhdl-indent-sexp (&optional endpos)
6954 "Indent each line of the list starting just after point.
6955If optional arg ENDPOS is given, indent each line, stopping when
6956ENDPOS is encountered."
6957 (interactive)
6958 (save-excursion
6959 (let ((beg (point))
5eabfe72 6960 (end (progn (vhdl-forward-sexp nil endpos) (point))))
d2ddb974
KH
6961 (indent-region beg end nil))))
6962
5eabfe72 6963;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
6964;; Miscellaneous commands
6965
6966(defun vhdl-show-syntactic-information ()
6967 "Show syntactic information for current line."
6968 (interactive)
3dcb36b7 6969 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
d2ddb974
KH
6970 (vhdl-keep-region-active))
6971
6972;; Verification and regression functions:
6973
6974(defun vhdl-regress-line (&optional arg)
6975 "Check syntactic information for current line."
6976 (interactive "P")
6977 (let ((expected (save-excursion
6978 (end-of-line)
5eabfe72
KH
6979 (when (search-backward " -- ((" (vhdl-point 'bol) t)
6980 (forward-char 4)
6981 (read (current-buffer)))))
d2ddb974
KH
6982 (actual (vhdl-get-syntactic-context))
6983 (expurgated))
6984 ;; remove the library unit symbols
6985 (mapcar
6986 (function
6987 (lambda (elt)
6988 (if (memq (car elt) '(entity configuration package
6989 package-body architecture))
6990 nil
6991 (setq expurgated (append expurgated (list elt))))))
6992 actual)
6993 (if (and (not arg) expected (listp expected))
6994 (if (not (equal expected expurgated))
3dcb36b7 6995 (error "ERROR: Should be: %s, is: %s" expected expurgated))
d2ddb974
KH
6996 (save-excursion
6997 (beginning-of-line)
5eabfe72
KH
6998 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
6999 (end-of-line)
7000 (if (search-backward " -- ((" (vhdl-point 'bol) t)
7001 (kill-line))
7002 (insert " -- ")
7003 (insert (format "%s" expurgated))))))
d2ddb974
KH
7004 (vhdl-keep-region-active))
7005
7006
5eabfe72
KH
7007;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7008;;; Alignment, whitespace fixup, beautifying
7009;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7010
3dcb36b7 7011(defconst vhdl-align-alist
d2ddb974
KH
7012 '(
7013 ;; after some keywords
3dcb36b7
JB
7014 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7015 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
d2ddb974 7016 ;; before ':'
5eabfe72 7017 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
d2ddb974 7018 ;; after direction specifications
5eabfe72
KH
7019 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7020 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7021 ;; before "==", ":=", "=>", and "<="
3dcb36b7 7022 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
5eabfe72 7023 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
3dcb36b7 7024 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
d2ddb974
KH
7025 ;; before some keywords
7026 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
d2ddb974
KH
7027 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7028 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
3dcb36b7
JB
7029 ;; before "=>" since "when/else ... =>" can occur
7030 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
d2ddb974 7031 )
5eabfe72 7032 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
d2ddb974
KH
7033It is searched in order. If REGEXP is found anywhere in the first
7034line of a region to be aligned, ALIGN-PATTERN will be used for that
7035region. ALIGN-PATTERN must include the whitespace to be expanded or
5eabfe72
KH
7036contracted. It may also provide regexps for the text surrounding the
7037whitespace. SUBEXP specifies which sub-expression of
d2ddb974
KH
7038ALIGN-PATTERN matches the white space to be expanded/contracted.")
7039
3dcb36b7
JB
7040;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7041;; Align code
7042
d2ddb974
KH
7043(defvar vhdl-align-try-all-clauses t
7044 "If REGEXP is not found on the first line of the region that clause
5eabfe72 7045is ignored. If this variable is non-nil, then the clause is tried anyway.")
d2ddb974 7046
3dcb36b7
JB
7047(defun vhdl-do-group (function &optional spacing)
7048 "Apply FUNCTION on group of lines between empty lines."
7049 (let
7050 ;; search for group beginning
7051 ((beg (save-excursion
7052 (if (re-search-backward vhdl-align-group-separate nil t)
7053 (progn (beginning-of-line 2) (back-to-indentation) (point))
7054 (point-min))))
7055 ;; search for group end
7056 (end (save-excursion
7057 (if (re-search-forward vhdl-align-group-separate nil t)
7058 (progn (beginning-of-line) (point))
7059 (point-max)))))
7060 ;; run FUNCTION
7061 (funcall function beg end spacing)))
7062
7063(defun vhdl-do-list (function &optional spacing)
7064 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7065parentheses."
7066 (let (beg end)
7067 (save-excursion
7068 ;; search for beginning of balanced group of parentheses
7069 (setq beg (vhdl-re-search-backward "[()]" nil t))
7070 (while (looking-at ")")
7071 (forward-char) (backward-sexp)
7072 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7073 ;; search for end of balanced group of parentheses
7074 (when beg
7075 (forward-list)
7076 (setq end (point))
7077 (goto-char (1+ beg))
7078 (skip-chars-forward " \t\n")
7079 (setq beg (point))))
7080 ;; run FUNCTION
7081 (if beg
7082 (funcall function beg end spacing)
7083 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7084
7085(defun vhdl-do-same-indent (function &optional spacing)
7086 "Apply FUNCTION to block of lines with same indent."
7087 (let ((indent (current-indentation))
7088 beg end)
7089 ;; search for first line with same indent
7090 (save-excursion
7091 (while (and (not (bobp))
7092 (or (looking-at "^\\s-*\\(--.*\\)?$")
7093 (= (current-indentation) indent)))
7094 (unless (looking-at "^\\s-*$")
7095 (back-to-indentation) (setq beg (point)))
7096 (beginning-of-line -0)))
7097 ;; search for last line with same indent
7098 (save-excursion
7099 (while (and (not (eobp))
7100 (or (looking-at "^\\s-*\\(--.*\\)?$")
7101 (= (current-indentation) indent)))
7102 (if (looking-at "^\\s-*$")
7103 (beginning-of-line 2)
7104 (beginning-of-line 2)
7105 (setq end (point)))))
7106 ;; run FUNCTION
7107 (funcall function beg end spacing)))
7108
7109(defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
d2ddb974 7110 "Attempt to align a range of lines based on the content of the
5eabfe72
KH
7111lines. The definition of `alignment-list' determines the matching
7112order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7113is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
d2ddb974
KH
7114indentation is done before aligning."
7115 (interactive "r\np")
5eabfe72
KH
7116 (setq alignment-list (or alignment-list vhdl-align-alist))
7117 (setq spacing (or spacing 1))
d2ddb974
KH
7118 (save-excursion
7119 (let (bol indent)
7120 (goto-char end)
7121 (setq end (point-marker))
7122 (goto-char begin)
5eabfe72 7123 (setq bol (setq begin (progn (beginning-of-line) (point))))
3dcb36b7 7124; (untabify bol end)
5eabfe72
KH
7125 (when indent
7126 (indent-region bol end nil))))
3dcb36b7
JB
7127 (let ((copy (copy-alist alignment-list)))
7128 (vhdl-prepare-search-2
5eabfe72
KH
7129 (while copy
7130 (save-excursion
7131 (goto-char begin)
7132 (let (element
7133 (eol (save-excursion (progn (end-of-line) (point)))))
7134 (setq element (nth 0 copy))
7135 (when (and (or (and (listp (car element))
7136 (memq major-mode (car element)))
7137 (eq major-mode (car element)))
7138 (or vhdl-align-try-all-clauses
7139 (re-search-forward (car (cdr element)) eol t)))
3dcb36b7 7140 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
5eabfe72
KH
7141 (car (cdr (cdr (cdr element)))) spacing))
7142 (setq copy (cdr copy))))))))
7143
3dcb36b7 7144(defun vhdl-align-region-2 (begin end match &optional substr spacing)
d2ddb974
KH
7145 "Align a range of lines from BEGIN to END. The regular expression
7146MATCH must match exactly one fields: the whitespace to be
7147contracted/expanded. The alignment column will equal the
7148rightmost column of the widest whitespace block. SPACING is
7149the amount of extra spaces to add to the calculated maximum required.
7150SPACING defaults to 1 so that at least one space is inserted after
7151the token in MATCH."
5eabfe72
KH
7152 (setq spacing (or spacing 1))
7153 (setq substr (or substr 1))
d2ddb974
KH
7154 (save-excursion
7155 (let (distance (max 0) (lines 0) bol eol width)
7156 ;; Determine the greatest whitespace distance to the alignment
7157 ;; character
7158 (goto-char begin)
7159 (setq eol (progn (end-of-line) (point))
5eabfe72 7160 bol (setq begin (progn (beginning-of-line) (point))))
d2ddb974 7161 (while (< bol end)
5eabfe72
KH
7162 (save-excursion
7163 (when (and (re-search-forward match eol t)
3dcb36b7 7164 (not (vhdl-in-literal)))
5eabfe72
KH
7165 (setq distance (- (match-beginning substr) bol))
7166 (when (> distance max)
7167 (setq max distance))))
7168 (forward-line)
7169 (setq bol (point)
7170 eol (save-excursion (end-of-line) (point)))
7171 (setq lines (1+ lines)))
d2ddb974
KH
7172 ;; Now insert enough maxs to push each assignment operator to
7173 ;; the same column. We need to use 'lines' as a counter, since
7174 ;; the location of the mark may change
7175 (goto-char (setq bol begin))
5eabfe72 7176 (setq eol (save-excursion (end-of-line) (point)))
d2ddb974 7177 (while (> lines 0)
5eabfe72 7178 (when (and (re-search-forward match eol t)
3dcb36b7 7179 (not (vhdl-in-literal)))
5eabfe72
KH
7180 (setq width (- (match-end substr) (match-beginning substr)))
7181 (setq distance (- (match-beginning substr) bol))
7182 (goto-char (match-beginning substr))
7183 (delete-char width)
7184 (insert-char ? (+ (- max distance) spacing)))
7185 (beginning-of-line)
7186 (forward-line)
7187 (setq bol (point)
7188 eol (save-excursion (end-of-line) (point)))
7189 (setq lines (1- lines))))))
7190
3dcb36b7
JB
7191(defun vhdl-align-region-groups (beg end &optional spacing
7192 no-message no-comments)
7193 "Align region, treat groups of lines separately."
d2ddb974 7194 (interactive "r\nP")
5eabfe72 7195 (save-excursion
3dcb36b7 7196 (let (orig pos)
5eabfe72
KH
7197 (goto-char beg)
7198 (beginning-of-line)
3dcb36b7 7199 (setq orig (point-marker))
5eabfe72
KH
7200 (setq beg (point))
7201 (goto-char end)
7202 (setq end (point-marker))
7203 (untabify beg end)
3dcb36b7
JB
7204 (unless no-message
7205 (when vhdl-progress-interval
7206 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7207 (count-lines (point-min) end) 0))))
5eabfe72
KH
7208 (vhdl-fixup-whitespace-region beg end t)
7209 (goto-char beg)
7210 (if (not vhdl-align-groups)
7211 ;; align entire region
3dcb36b7
JB
7212 (progn (vhdl-align-region-1 beg end spacing)
7213 (unless no-comments
7214 (vhdl-align-inline-comment-region-1 beg end)))
5eabfe72
KH
7215 ;; align groups
7216 (while (and (< beg end)
3dcb36b7 7217 (re-search-forward vhdl-align-group-separate end t))
5eabfe72 7218 (setq pos (point-marker))
3dcb36b7
JB
7219 (vhdl-align-region-1 beg pos spacing)
7220 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7221 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
5eabfe72
KH
7222 (setq beg (1+ pos))
7223 (goto-char beg))
7224 ;; align last group
7225 (when (< beg end)
3dcb36b7
JB
7226 (vhdl-align-region-1 beg end spacing)
7227 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7228 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7229 (when vhdl-indent-tabs-mode
7230 (tabify orig end))
7231 (unless no-message
7232 (when vhdl-progress-interval (message "Aligning...done"))
7233 (setq vhdl-progress-info nil)))))
7234
7235(defun vhdl-align-region (beg end &optional spacing)
7236 "Align region, treat blocks with same indent and argument lists separately."
7237 (interactive "r\nP")
7238 (if (not vhdl-align-same-indent)
7239 ;; align entire region
7240 (vhdl-align-region-groups beg end spacing)
7241 ;; align blocks with same indent and argument lists
7242 (save-excursion
7243 (let ((cur-beg beg)
7244 indent cur-end)
7245 (when vhdl-progress-interval
7246 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7247 (count-lines (point-min) end) 0)))
7248 (goto-char end)
7249 (setq end (point-marker))
7250 (goto-char cur-beg)
7251 (while (< (point) end)
7252 ;; is argument list opening?
7253 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7254 (point) (vhdl-point 'eol)))))
7255 ;; determine region for argument list
7256 (progn (goto-char cur-beg)
7257 (forward-sexp)
7258 (setq cur-end (point))
7259 (beginning-of-line 2))
7260 ;; determine region with same indent
7261 (setq indent (current-indentation))
7262 (setq cur-beg (point))
7263 (setq cur-end (vhdl-point 'bonl))
7264 (beginning-of-line 2)
7265 (while (and (< (point) end)
7266 (or (looking-at "^\\s-*\\(--.*\\)?$")
7267 (= (current-indentation) indent))
7268 (<= (save-excursion
7269 (nth 0 (parse-partial-sexp
7270 (point) (vhdl-point 'eol)))) 0))
7271 (unless (looking-at "^\\s-*$")
7272 (setq cur-end (vhdl-point 'bonl)))
7273 (beginning-of-line 2)))
7274 ;; align region
7275 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7276 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7277 (when vhdl-progress-interval (message "Aligning...done"))
7278 (setq vhdl-progress-info nil)))))
5eabfe72
KH
7279
7280(defun vhdl-align-group (&optional spacing)
7281 "Align group of lines between empty lines."
7282 (interactive)
3dcb36b7 7283 (vhdl-do-group 'vhdl-align-region spacing))
5eabfe72 7284
3dcb36b7
JB
7285(defun vhdl-align-list (&optional spacing)
7286 "Align the lines of a list surrounded by a balanced group of parentheses."
5eabfe72 7287 (interactive)
3dcb36b7
JB
7288 (vhdl-do-list 'vhdl-align-region-groups spacing))
7289
7290(defun vhdl-align-same-indent (&optional spacing)
7291 "Align block of lines with same indent."
7292 (interactive)
7293 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7294
7295(defun vhdl-align-declarations (&optional spacing)
7296 "Align the lines within the declarative part of a design unit."
7297 (interactive)
7298 (let (beg end)
7299 (vhdl-prepare-search-2
7300 (save-excursion
7301 ;; search for declarative part
7302 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7303 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7304 (setq beg (point))
7305 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7306 (setq end (point)))))
7307 (if beg
7308 (vhdl-align-region-groups beg end spacing)
7309 (error "ERROR: Not within the declarative part of a design unit"))))
7310
7311(defun vhdl-align-buffer ()
7312 "Align buffer."
7313 (interactive)
7314 (vhdl-align-region (point-min) (point-max)))
7315
7316;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7317;; Align inline comments
7318
7319(defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7320 "Align inline comments in region."
7321 (save-excursion
7322 (let ((start-max comment-column)
7323 (length-max 0)
7324 comment-list start-list tmp-list start length
7325 cur-start prev-start no-code)
7326 (setq spacing (or spacing 2))
7327 (vhdl-prepare-search-2
7328 (goto-char beg)
7329 ;; search for comment start positions and lengths
7330 (while (< (point) end)
7331 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7332 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7333 (not (save-excursion (goto-char (match-beginning 2))
7334 (vhdl-in-literal))))
7335 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7336 (setq length (- (match-end 2) (match-beginning 2)))
7337 (setq start-max (max start start-max))
7338 (setq length-max (max length length-max))
7339 (setq comment-list (cons (cons start length) comment-list)))
7340 (beginning-of-line 2))
7341 (setq comment-list
7342 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7343 ;; reduce start positions
7344 (setq start-list (list (caar comment-list)))
7345 (setq comment-list (cdr comment-list))
7346 (while comment-list
7347 (unless (or (= (caar comment-list) (car start-list))
7348 (<= (+ (car start-list) (cdar comment-list))
7349 end-comment-column))
7350 (setq start-list (cons (caar comment-list) start-list)))
7351 (setq comment-list (cdr comment-list)))
7352 ;; align lines as nicely as possible
7353 (goto-char beg)
7354 (while (< (point) end)
7355 (setq cur-start nil)
7356 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7357 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7358 (not (save-excursion
7359 (goto-char (match-beginning 3))
7360 (vhdl-in-literal))))
7361 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7362 (>= (- (match-end 2) (match-beginning 2))
7363 comment-column))))
7364 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7365 (setq length (- (match-end 3) (match-beginning 3)))
7366 (setq no-code (= (match-beginning 1) (match-end 1)))
7367 ;; insert minimum whitespace
7368 (goto-char (match-end 2))
7369 (delete-region (match-beginning 2) (match-end 2))
7370 (insert-char ?\ spacing)
7371 (setq tmp-list start-list)
7372 ;; insert additional whitespace to align
7373 (setq cur-start
7374 (cond
7375 ;; align comment-only line to inline comment of previous line
7376 ((and no-code prev-start
7377 (<= length (- end-comment-column prev-start)))
7378 prev-start)
7379 ;; align all comments at `start-max' if this is possible
7380 ((<= (+ start-max length-max) end-comment-column)
7381 start-max)
7382 ;; align at `comment-column' if possible
7383 ((and (<= start comment-column)
7384 (<= length (- end-comment-column comment-column)))
7385 comment-column)
7386 ;; align at left-most possible start position otherwise
7387 (t
7388 (while (and tmp-list (< (car tmp-list) start))
7389 (setq tmp-list (cdr tmp-list)))
7390 (car tmp-list))))
7391 (indent-to cur-start))
7392 (setq prev-start cur-start)
7393 (beginning-of-line 2))))))
d2ddb974 7394
5eabfe72
KH
7395(defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7396 "Align inline comments within a region. Groups of code lines separated by
7397empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
d2ddb974 7398 (interactive "r\nP")
5eabfe72 7399 (save-excursion
3dcb36b7 7400 (let (orig pos)
5eabfe72
KH
7401 (goto-char beg)
7402 (beginning-of-line)
3dcb36b7 7403 (setq orig (point-marker))
5eabfe72
KH
7404 (setq beg (point))
7405 (goto-char end)
7406 (setq end (point-marker))
7407 (untabify beg end)
7408 (unless no-message (message "Aligning inline comments..."))
7409 (goto-char beg)
7410 (if (not vhdl-align-groups)
7411 ;; align entire region
7412 (vhdl-align-inline-comment-region-1 beg end spacing)
7413 ;; align groups
3dcb36b7
JB
7414 (while (and (< beg end)
7415 (re-search-forward vhdl-align-group-separate end t))
5eabfe72
KH
7416 (setq pos (point-marker))
7417 (vhdl-align-inline-comment-region-1 beg pos spacing)
7418 (setq beg (1+ pos))
7419 (goto-char beg))
7420 ;; align last group
7421 (when (< beg end)
3dcb36b7
JB
7422 (vhdl-align-inline-comment-region-1 beg end spacing)))
7423 (when vhdl-indent-tabs-mode
7424 (tabify orig end))
7425 (unless no-message (message "Aligning inline comments...done")))))
5eabfe72
KH
7426
7427(defun vhdl-align-inline-comment-group (&optional spacing)
7428 "Align inline comments within a group of lines between empty lines."
7429 (interactive)
7430 (save-excursion
7431 (let ((start (point))
7432 beg end)
3dcb36b7 7433 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
5eabfe72
KH
7434 (point-marker) (point-max)))
7435 (goto-char start)
3dcb36b7
JB
7436 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7437 (point) (point-min)))
5eabfe72
KH
7438 (untabify beg end)
7439 (message "Aligning inline comments...")
7440 (vhdl-align-inline-comment-region-1 beg end)
3dcb36b7
JB
7441 (when vhdl-indent-tabs-mode
7442 (tabify beg end))
5eabfe72
KH
7443 (message "Aligning inline comments...done"))))
7444
7445(defun vhdl-align-inline-comment-buffer ()
7446 "Align inline comments within buffer. Groups of code lines separated by
7447empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7448 (interactive)
7449 (vhdl-align-inline-comment-region (point-min) (point-max)))
7450
3dcb36b7
JB
7451;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7452;; Fixup whitespace
7453
5eabfe72
KH
7454(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7455 "Fixup whitespace in region. Surround operator symbols by one space,
7456eliminate multiple spaces (except at beginning of line), eliminate spaces at
3dcb36b7 7457end of line, do nothing in comments and strings."
5eabfe72
KH
7458 (interactive "r")
7459 (unless no-message (message "Fixing up whitespace..."))
7460 (save-excursion
7461 (goto-char end)
7462 (setq end (point-marker))
5eabfe72
KH
7463 ;; have no space before and one space after `,' and ';'
7464 (goto-char beg)
3dcb36b7
JB
7465 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7466 (if (match-string 1)
7467 (goto-char (match-end 1))
7468 (replace-match "\\3 " nil nil nil 3)))
7469 ;; have no space after `('
7470 (goto-char beg)
7471 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\((\\)\\s-+" end t)
7472 (if (match-string 1)
7473 (goto-char (match-end 1))
7474 (replace-match "\\2")))
7475 ;; have no space before `)'
7476 (goto-char beg)
7477 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7478 (if (match-string 1)
7479 (goto-char (match-end 1))
7480 (replace-match "\\2")))
7481 ;; surround operator symbols by one space
7482 (goto-char beg)
7483 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7484 (if (match-string 1)
7485 (goto-char (match-end 1))
f35aff82
RS
7486 (save-excursion
7487 (goto-char (match-beginning 4))
7488 (unless (eq (preceding-char) ?\ )
7489 (insert " "))
7490 (goto-char (match-end 4))
7491 (unless (eq (following-char) ?\ )
7492 (insert " ")))
3dcb36b7 7493 (goto-char (match-end 4))))
5eabfe72
KH
7494 ;; eliminate multiple spaces and spaces at end of line
7495 (goto-char beg)
7496 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
3dcb36b7 7497 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
5eabfe72
KH
7498 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7499 (progn (replace-match "" nil nil) t))
7500 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7501 (progn (replace-match ";" nil nil) t))
7502 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7503 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
3dcb36b7 7504 (progn (replace-match " " nil nil) t))
5eabfe72 7505 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
3dcb36b7
JB
7506 (progn (replace-match " " nil nil) t))
7507 (re-search-forward "[^ \t-]+" end t))))
5eabfe72
KH
7508 (unless no-message (message "Fixing up whitespace...done")))
7509
7510(defun vhdl-fixup-whitespace-buffer ()
7511 "Fixup whitespace in buffer. Surround operator symbols by one space,
7512eliminate multiple spaces (except at beginning of line), eliminate spaces at
7513end of line, do nothing in comments."
7514 (interactive)
7515 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7516
3dcb36b7
JB
7517;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7518;; Beautify
7519
5eabfe72
KH
7520(defun vhdl-beautify-region (beg end)
7521 "Beautify region by applying indentation, whitespace fixup, alignment, and
3dcb36b7
JB
7522case fixing to a region. Calls functions `vhdl-indent-buffer',
7523`vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
5eabfe72
KH
7524`vhdl-fix-case-buffer'."
7525 (interactive "r")
3dcb36b7 7526 (setq end (save-excursion (goto-char end) (point-marker)))
5eabfe72
KH
7527 (vhdl-indent-region beg end nil)
7528 (let ((vhdl-align-groups t))
3dcb36b7 7529 (vhdl-align-region beg end))
5eabfe72
KH
7530 (vhdl-fix-case-region beg end))
7531
7532(defun vhdl-beautify-buffer ()
7533 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7534case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7535buffer."
7536 (interactive)
3dcb36b7
JB
7537 (vhdl-beautify-region (point-min) (point-max))
7538 (when noninteractive (save-buffer)))
7539
7540;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7541;; Code filling
7542
7543(defun vhdl-fill-region (beg end &optional arg)
7544 "Fill lines for a region of code."
8d422bd5 7545 (interactive "r\np")
3dcb36b7
JB
7546 (save-excursion
7547 (goto-char beg)
f35aff82 7548 (let ((margin (if arg (current-indentation) (current-column))))
3dcb36b7
JB
7549 (goto-char end)
7550 (setq end (point-marker))
7551 ;; remove inline comments, newlines and whitespace
7552 (vhdl-comment-kill-region beg end)
7553 (vhdl-comment-kill-inline-region beg end)
7554 (subst-char-in-region beg (1- end) ?\n ?\ )
7555 (vhdl-fixup-whitespace-region beg end)
7556 ;; wrap and end-comment-column
7557 (goto-char beg)
7558 (while (re-search-forward "\\s-" end t)
7559 (when(> (current-column) vhdl-end-comment-column)
7560 (backward-char)
7561 (when (re-search-backward "\\s-" beg t)
7562 (replace-match "\n")
7563 (indent-to margin)))))))
7564
7565(defun vhdl-fill-group ()
7566 "Fill group of lines between empty lines."
7567 (interactive)
7568 (vhdl-do-group 'vhdl-fill-region))
7569
7570(defun vhdl-fill-list ()
7571 "Fill the lines of a list surrounded by a balanced group of parentheses."
7572 (interactive)
7573 (vhdl-do-list 'vhdl-fill-region))
7574
7575(defun vhdl-fill-same-indent ()
7576 "Fill the lines of block of lines with same indent."
7577 (interactive)
7578 (vhdl-do-same-indent 'vhdl-fill-region))
7579
7580
7581;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7582;;; Code updating/fixing
7583;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7584
7585;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7586;; Sensitivity list update
7587
7588;; Strategy:
7589;; - no sensitivity list is generated for processes with wait statements
7590;; - otherwise, do the following:
7591;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7592;; 2. scan for all signals already in the sensitivity list (in order to catch
7593;; manually entered global signals)
7594;; 3. signals from 1. and 2. form the list of visible signals
7595;; 4. search for if/elsif conditions containing an event (sequential code)
7596;; 5. scan for strings that are within syntactical regions where signals are
7597;; read but not within sequential code, and that correspond to visible
7598;; signals
7599;; 6. replace sensitivity list by list of signals from 5.
7600
7601(defun vhdl-update-sensitivity-list-process ()
7602 "Update sensitivity list of current process."
7603 (interactive)
7604 (save-excursion
7605 (vhdl-prepare-search-2
7606 (end-of-line)
7607 ;; look whether in process
7608 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7609 (equal (upcase (match-string 2)) "PROCESS")
7610 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7611 (error "ERROR: Not within a process")
7612 (message "Updating sensitivity list...")
7613 (vhdl-update-sensitivity-list)
7614 (message "Updating sensitivity list...done")))))
7615
7616(defun vhdl-update-sensitivity-list-buffer ()
7617 "Update sensitivity list of all processes in current buffer."
7618 (interactive)
7619 (save-excursion
7620 (vhdl-prepare-search-2
7621 (goto-char (point-min))
7622 (message "Updating sensitivity lists...")
7623 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7624 (goto-char (match-beginning 0))
7625 (condition-case nil (vhdl-update-sensitivity-list) (error)))
7626 (message "Updating sensitivity lists...done"))))
7627
7628(defun vhdl-update-sensitivity-list ()
7629 "Update sensitivity list."
7630 (let ((proc-beg (point))
7631 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7632 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7633 seq-region-list)
7634 (cond
7635 ;; search for wait statement (no sensitivity list allowed)
7636 ((progn (goto-char proc-mid)
7637 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7638 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7639 ;; combinational process (update sensitivity list)
7640 (t
7641 (let
7642 ;; scan for visible signals
7643 ((visible-list (vhdl-get-visible-signals))
7644 ;; define syntactic regions where signals are read
7645 (scan-regions-list
7646 '(;; right-hand side of signal/variable assignment
7647 ;; (special case: "<=" is relational operator in a condition)
7648 ((re-search-forward "[<:]=" proc-end t)
7649 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7650 ;; if condition
7651 ((re-search-forward "^\\s-*if\\>" proc-end t)
7652 (re-search-forward "\\<then\\>" proc-end t))
7653 ;; elsif condition
7654 ((re-search-forward "\\<elsif\\>" proc-end t)
7655 (re-search-forward "\\<then\\>" proc-end t))
7656 ;; while loop condition
7657 ((re-search-forward "^\\s-*while\\>" proc-end t)
7658 (re-search-forward "\\<loop\\>" proc-end t))
7659 ;; exit/next condition
7660 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7661 (re-search-forward ";" proc-end t))
7662 ;; assert condition
7663 ((re-search-forward "\\<assert\\>" proc-end t)
7664 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7665 ;; case expression
7666 ((re-search-forward "^\\s-*case\\>" proc-end t)
7667 (re-search-forward "\\<is\\>" proc-end t))
7668 ;; parameter list of procedure call
7669 ((re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7670 (progn (backward-char) (forward-sexp) (point)))))
7671 name read-list sens-list signal-list
7672 sens-beg sens-end beg end margin)
7673 ;; scan for signals in old sensitivity list
7674 (goto-char proc-beg)
7675 (re-search-forward "\\<process\\>" proc-mid t)
7676 (if (not (looking-at "[ \t\n]*("))
7677 (setq sens-beg (point))
7678 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7679 (goto-char (match-end 1))
7680 (forward-sexp)
7681 (setq sens-end (1- (point)))
7682 (goto-char sens-beg)
7683 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7684 (setq sens-list
7685 (cons (downcase (match-string 0)) sens-list))
7686 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7687 (setq signal-list (append visible-list sens-list))
7688 ;; search for sequential parts
7689 (goto-char proc-mid)
7690 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7691 (setq end (re-search-forward "\\<then\\>" proc-end t))
7692 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7693 (goto-char end)
7694 (backward-word 1)
7695 (vhdl-forward-sexp)
7696 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7697 (beginning-of-line)))
7698 ;; scan for signals read in process
7699 (while scan-regions-list
7700 (goto-char proc-mid)
7701 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7702 (setq end (eval (nth 1 (car scan-regions-list)))))
7703 (goto-char beg)
7704 (unless (or (vhdl-in-literal)
7705 (and seq-region-list
7706 (let ((tmp-list seq-region-list))
7707 (while (and tmp-list
7708 (< (point) (caar tmp-list)))
7709 (setq tmp-list (cdr tmp-list)))
7710 (and tmp-list (< (point) (cdar tmp-list))))))
7711 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>" end t)
7712 (setq name (match-string 1))
7713 (when (member (downcase name) signal-list)
7714 (add-to-list 'read-list name)))))
7715 (setq scan-regions-list (cdr scan-regions-list)))
7716 ;; update sensitivity list
7717 (goto-char sens-beg)
7718 (if sens-end
7719 (delete-region sens-beg sens-end)
7720 (when read-list
7721 (insert " ()") (backward-char)))
7722 (setq read-list (sort read-list 'string<))
7723 (when read-list
7724 (setq margin (current-column))
7725 (insert (car read-list))
7726 (setq read-list (cdr read-list))
7727 (while read-list
7728 (insert ",")
7729 (if (<= (+ (current-column) (length (car read-list)) 2)
7730 end-comment-column)
7731 (insert " ")
7732 (insert "\n") (indent-to margin))
7733 (insert (car read-list))
7734 (setq read-list (cdr read-list)))))))))
7735
7736(defun vhdl-get-visible-signals ()
7737 "Get all signals visible in the current block."
7738 (save-excursion
7739 (let (beg end signal-list entity-name file-name)
7740 ;; search for signals declared in surrounding block declarative parts
7741 (save-excursion
7742 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7743 (match-string 2))
7744 (goto-char (match-end 2))
7745 (vhdl-backward-sexp)
7746 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7747 beg)
7748 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7749 ;; scan for all declared signal names
7750 (goto-char beg)
7751 (while (re-search-forward "^\\s-*signal\\>" end t)
7752 (while (and (not (looking-at "[ \t\n]*:"))
7753 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7754 (setq signal-list
7755 (cons (downcase (match-string 1)) signal-list))))
7756 (goto-char beg)))
7757 ;; search for signals declared in architecture declarative part
7758 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7759 (not (equal "END" (upcase (match-string 1))))
7760 (setq entity-name (match-string 2))
7761 (setq end (re-search-forward "^begin\\>" nil t))))
7762 (error "ERROR: No architecture declarative part found")
7763 ;; scan for all declared signal names
7764 (goto-char beg)
7765 (while (re-search-forward "^\\s-*signal\\>" end t)
7766 (while (and (not (looking-at "[ \t\n]*:"))
7767 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7768 (setq signal-list
7769 (cons (downcase (match-string 1)) signal-list)))))
7770 ;; search for signals declared in entity port clause
7771 (goto-char (point-min))
7772 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7773 (setq file-name
7774 (concat (vhdl-replace-string vhdl-entity-file-name entity-name)
7775 "." (file-name-extension (buffer-file-name)))))
7776 (vhdl-visit-file
7777 file-name t
7778 (vhdl-prepare-search-2
7779 (goto-char (point-min))
7780 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7781 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7782 (when (setq beg (re-search-forward
7783 "^\\s-*port[ \t\n]*("
7784 (save-excursion
7785 (re-search-forward "^end\\>" nil t)) t))
7786 (setq end (save-excursion
7787 (backward-char) (forward-sexp) (point)))
7788 (vhdl-forward-syntactic-ws)
7789 (while (< (point) end)
7790 (while (and (not (looking-at "[ \t\n]*:"))
7791 (re-search-forward "[ \t\n,]*\\(\\w+\\)" end t))
7792 (setq signal-list
7793 (cons (downcase (match-string 1)) signal-list)))
7794 (re-search-forward ";" end 1)
7795 (vhdl-forward-syntactic-ws))))))
7796 signal-list)))
7797
7798;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7799;; Generic/port clause fixing
7800
7801(defun vhdl-fix-clause ()
7802 "Fix closing parenthesis within generic/port clause."
7803 (interactive)
7804 (save-excursion
7805 (vhdl-prepare-search-2
7806 (let ((pos (point))
7807 beg end)
7808 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7809 (error "ERROR: Not within a generic/port clause")
7810 ;; search for end of clause
7811 (goto-char (match-end 0))
7812 (setq beg (1- (point)))
7813 (vhdl-forward-syntactic-ws)
7814 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7815 (goto-char (1- (match-end 0)))
7816 (setq end (point-marker))
7817 (forward-char)
7818 (vhdl-forward-syntactic-ws))
7819 (goto-char end)
7820 (when (> pos (save-excursion (end-of-line) (point)))
7821 (error "ERROR: Not within a generic/port clause"))
7822 ;; delete closing parenthesis on separate line (not supported style)
7823 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7824 (vhdl-line-kill)
7825 (vhdl-backward-syntactic-ws)
7826 (setq end (point-marker))
7827 (insert ";"))
7828 ;; delete superfluous parentheses
7829 (while (progn (goto-char beg)
7830 (condition-case () (forward-sexp)
7831 (error (goto-char (point-max))))
7832 (< (point) end))
7833 (delete-backward-char 1))
7834 ;; add closing parenthesis
7835 (when (> (point) end)
7836 (goto-char end)
7837 (insert ")")))))))
7838
7839;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7840;; Miscellaneous
7841
7842(defun vhdl-remove-trailing-spaces ()
7843 "Remove trailing spaces in the whole buffer."
7844 (interactive)
7845 (save-match-data
7846 (save-excursion
7847 (goto-char (point-min))
7848 (while (re-search-forward "[ \t]+$" (point-max) t)
7849 (unless (vhdl-in-literal)
7850 (replace-match "" nil nil))))))
d2ddb974
KH
7851
7852
5eabfe72
KH
7853;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7854;;; Electrification
7855;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7856
5eabfe72
KH
7857(defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
7858 "Syntax of prompt inserted by template generators.")
7859
7860(defvar vhdl-template-invoked-by-hook nil
7861 "Indicates whether a template has been invoked by a hook or by key or menu.
7862Used for undoing after template abortion.")
7863
7864;; correct different behavior of function `unread-command-events' in XEmacs
3dcb36b7 7865(defun vhdl-character-to-event (arg))
5eabfe72 7866(defalias 'vhdl-character-to-event
4bcb9c95 7867 (if (fboundp 'character-to-event) 'character-to-event 'identity))
3dcb36b7
JB
7868
7869(defun vhdl-work-library ()
7870 "Return the working library name of the current project or \"work\" if no
7871project is defined."
7872 (vhdl-resolve-env-variable
7873 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
5eabfe72
KH
7874
7875;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7876;; Enabling/disabling
7877
7878(defun vhdl-mode-line-update ()
7879 "Update the modeline string for VHDL major mode."
7880 (setq mode-name (concat "VHDL"
7881 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
7882 (and vhdl-electric-mode "e")
7883 (and vhdl-stutter-mode "s")))
3dcb36b7 7884 (force-mode-line-update t))
5eabfe72
KH
7885
7886(defun vhdl-electric-mode (arg)
7887 "Toggle VHDL electric mode.
7888Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7889 (interactive "P")
7890 (setq vhdl-electric-mode
7891 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
7892 ((> arg 0) t) (t nil)))
7893 (vhdl-mode-line-update))
7894
7895(defun vhdl-stutter-mode (arg)
7896 "Toggle VHDL stuttering mode.
7897Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7898 (interactive "P")
7899 (setq vhdl-stutter-mode
7900 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
7901 ((> arg 0) t) (t nil)))
7902 (vhdl-mode-line-update))
7903
7904;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7905;; Stuttering
d2ddb974 7906
5eabfe72
KH
7907(defun vhdl-electric-dash (count)
7908 "-- starts a comment, --- draws a horizontal line,
7909---- starts a display comment"
d2ddb974 7910 (interactive "p")
3dcb36b7 7911 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
5eabfe72
KH
7912 (cond
7913 ((and abbrev-start-location (= abbrev-start-location (point)))
7914 (setq abbrev-start-location nil)
7915 (goto-char last-abbrev-location)
7916 (beginning-of-line nil)
7917 (vhdl-comment-display))
7918 ((/= (preceding-char) ?-) ; standard dash (minus)
d2ddb974 7919 (self-insert-command count))
5eabfe72
KH
7920 (t (self-insert-command count)
7921 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
7922 (let ((next-input (read-char)))
7923 (if (= next-input ?-) ; triple dash
7924 (progn
7925 (vhdl-comment-display-line)
7926 (message
7927 "Enter '-' for display comment, else continue coding")
7928 (let ((next-input (read-char)))
7929 (if (= next-input ?-) ; four dashes
7930 (vhdl-comment-display t)
7931 (setq unread-command-events ; pushback the char
7932 (list (vhdl-character-to-event next-input))))))
7933 (setq unread-command-events ; pushback the char
7934 (list (vhdl-character-to-event next-input)))
7935 (vhdl-comment-insert)))))
7936 (self-insert-command count)))
7937
7938(defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
d2ddb974 7939 (interactive "p")
3dcb36b7 7940 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7941 (if (= (preceding-char) ?\()
7942 (progn (delete-char -1) (insert-char ?\[ 1))
7943 (insert-char ?\( 1))
7944 (self-insert-command count)))
d2ddb974 7945
5eabfe72 7946(defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
d2ddb974 7947 (interactive "p")
3dcb36b7 7948 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974 7949 (progn
5eabfe72
KH
7950 (if (= (preceding-char) ?\))
7951 (progn (delete-char -1) (insert-char ?\] 1))
7952 (insert-char ?\) 1))
7953 (blink-matching-open))
7954 (self-insert-command count)))
d2ddb974 7955
5eabfe72 7956(defun vhdl-electric-quote (count) "'' --> \""
d2ddb974 7957 (interactive "p")
3dcb36b7 7958 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7959 (if (= (preceding-char) last-input-char)
7960 (progn (delete-backward-char 1) (insert-char ?\" 1))
7961 (insert-char ?\' 1))
7962 (self-insert-command count)))
d2ddb974 7963
5eabfe72 7964(defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
d2ddb974 7965 (interactive "p")
3dcb36b7 7966 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7967 (cond ((= (preceding-char) last-input-char)
7968 (progn (delete-char -1)
3dcb36b7 7969 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
7970 (insert ": ")
7971 (setq this-command 'vhdl-electric-colon)))
7972 ((and
7973 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
7974 (progn (delete-char -1) (insert "= ")))
7975 (t (insert-char ?\; 1)))
7976 (self-insert-command count)))
7977
7978(defun vhdl-electric-comma (count) "',,' --> ' <= '"
d2ddb974 7979 (interactive "p")
3dcb36b7 7980 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
7981 (cond ((= (preceding-char) last-input-char)
7982 (progn (delete-char -1)
3dcb36b7 7983 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 7984 (insert "<= ")))
5eabfe72
KH
7985 (t (insert-char ?\, 1)))
7986 (self-insert-command count)))
d2ddb974 7987
5eabfe72 7988(defun vhdl-electric-period (count) "'..' --> ' => '"
d2ddb974 7989 (interactive "p")
3dcb36b7 7990 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
7991 (cond ((= (preceding-char) last-input-char)
7992 (progn (delete-char -1)
3dcb36b7 7993 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 7994 (insert "=> ")))
5eabfe72
KH
7995 (t (insert-char ?\. 1)))
7996 (self-insert-command count)))
d2ddb974 7997
5eabfe72 7998(defun vhdl-electric-equal (count) "'==' --> ' == '"
d2ddb974 7999 (interactive "p")
3dcb36b7 8000 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
8001 (cond ((= (preceding-char) last-input-char)
8002 (progn (delete-char -1)
3dcb36b7 8003 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
8004 (insert "== ")))
8005 (t (insert-char ?\= 1)))
8006 (self-insert-command count)))
d2ddb974 8007
5eabfe72 8008;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
8009;; VHDL templates
8010
5eabfe72
KH
8011(defun vhdl-template-paired-parens ()
8012 "Insert a pair of round parentheses, placing point between them."
d2ddb974 8013 (interactive)
5eabfe72
KH
8014 (insert "()")
8015 (backward-char))
d2ddb974 8016
5eabfe72
KH
8017(defun vhdl-template-alias ()
8018 "Insert alias declaration."
d2ddb974 8019 (interactive)
5eabfe72
KH
8020 (let ((start (point)))
8021 (vhdl-insert-keyword "ALIAS ")
8022 (when (vhdl-template-field "name" nil t start (point))
8023 (insert " : ")
8024 (unless (vhdl-template-field
8025 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8026 nil t)
3dcb36b7 8027 (delete-backward-char 3))
5eabfe72
KH
8028 (vhdl-insert-keyword " IS ")
8029 (vhdl-template-field "name" ";")
8030 (vhdl-comment-insert-inline))))
8031
8032(defun vhdl-template-architecture ()
8033 "Insert architecture."
8034 (interactive)
8035 (let ((margin (current-indentation))
8036 (start (point))
3dcb36b7 8037 arch-name)
d2ddb974 8038 (vhdl-insert-keyword "ARCHITECTURE ")
5eabfe72
KH
8039 (when (setq arch-name
8040 (vhdl-template-field "name" nil t start (point)))
d2ddb974 8041 (vhdl-insert-keyword " OF ")
3dcb36b7
JB
8042 (if (save-excursion
8043 (vhdl-prepare-search-1
8044 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8045 (insert (match-string 1))
5eabfe72 8046 (vhdl-template-field "entity name"))
3dcb36b7 8047 (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8048 (vhdl-template-begin-end
8049 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8050 (memq vhdl-insert-empty-lines '(unit all))))))
d2ddb974 8051
5eabfe72 8052(defun vhdl-template-array (kind &optional secondary)
d2ddb974
KH
8053 "Insert array type definition."
8054 (interactive)
5eabfe72
KH
8055 (let ((start (point)))
8056 (vhdl-insert-keyword "ARRAY (")
8057 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8058 secondary)
8059 (vhdl-insert-keyword ") OF ")
8060 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8061 (vhdl-insert-keyword ";"))))
8062
8063(defun vhdl-template-assert ()
8064 "Insert an assertion statement."
8065 (interactive)
8066 (let ((start (point)))
8067 (vhdl-insert-keyword "ASSERT ")
8068 (when vhdl-conditions-in-parenthesis (insert "("))
8069 (when (vhdl-template-field "condition (negated)" nil t start (point))
8070 (when vhdl-conditions-in-parenthesis (insert ")"))
8071 (setq start (point))
8072 (vhdl-insert-keyword " REPORT ")
8073 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8074 (delete-region start (point)))
8075 (setq start (point))
8076 (vhdl-insert-keyword " SEVERITY ")
8077 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8078 (delete-region start (point)))
8079 (insert ";"))))
8080
8081(defun vhdl-template-attribute ()
8082 "Insert an attribute declaration or specification."
8083 (interactive)
8084 (if (eq (vhdl-decision-query
8085 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8086 (vhdl-template-attribute-spec)
8087 (vhdl-template-attribute-decl)))
d2ddb974 8088
5eabfe72
KH
8089(defun vhdl-template-attribute-decl ()
8090 "Insert an attribute declaration."
d2ddb974 8091 (interactive)
5eabfe72
KH
8092 (let ((start (point)))
8093 (vhdl-insert-keyword "ATTRIBUTE ")
8094 (when (vhdl-template-field "name" " : " t start (point))
8095 (vhdl-template-field "type" ";")
8096 (vhdl-comment-insert-inline))))
8097
8098(defun vhdl-template-attribute-spec ()
8099 "Insert an attribute specification."
8100 (interactive)
8101 (let ((start (point)))
8102 (vhdl-insert-keyword "ATTRIBUTE ")
8103 (when (vhdl-template-field "name" nil t start (point))
8104 (vhdl-insert-keyword " OF ")
8105 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8106 (vhdl-template-field "entity class")
8107 (vhdl-insert-keyword " IS ")
8108 (vhdl-template-field "expression" ";"))))
d2ddb974 8109
5eabfe72
KH
8110(defun vhdl-template-block ()
8111 "Insert a block."
d2ddb974 8112 (interactive)
5eabfe72
KH
8113 (let ((margin (current-indentation))
8114 (start (point))
8115 label)
8116 (vhdl-insert-keyword ": BLOCK ")
8117 (goto-char start)
8118 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8119 (forward-word 1)
8120 (forward-char 1)
d2ddb974 8121 (insert "(")
5eabfe72
KH
8122 (if (vhdl-template-field "[guard expression]" nil t)
8123 (insert ")")
8124 (delete-char -2))
8125 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 8126 (insert "\n")
5eabfe72
KH
8127 (vhdl-template-begin-end "BLOCK" label margin)
8128 (vhdl-comment-block))))
d2ddb974 8129
5eabfe72 8130(defun vhdl-template-block-configuration ()
d2ddb974
KH
8131 "Insert a block configuration statement."
8132 (interactive)
5eabfe72
KH
8133 (let ((margin (current-indentation))
8134 (start (point)))
d2ddb974 8135 (vhdl-insert-keyword "FOR ")
5eabfe72 8136 (when (vhdl-template-field "block name" nil t start (point))
d2ddb974
KH
8137 (vhdl-insert-keyword "\n\n")
8138 (indent-to margin)
8139 (vhdl-insert-keyword "END FOR;")
8140 (end-of-line 0)
5eabfe72 8141 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8142
5eabfe72
KH
8143(defun vhdl-template-break ()
8144 "Insert a break statement."
d2ddb974 8145 (interactive)
5eabfe72
KH
8146 (let (position)
8147 (vhdl-insert-keyword "BREAK")
8148 (setq position (point))
8149 (insert " ")
8150 (while (or
8151 (progn (vhdl-insert-keyword "FOR ")
8152 (if (vhdl-template-field "[quantity name]" " USE " t)
8153 (progn (vhdl-template-field "quantity name" " => ") t)
8154 (kill-word -1) nil))
8155 (vhdl-template-field "[quantity name]" " => " t))
8156 (vhdl-template-field "expression")
8157 (setq position (point))
8158 (insert ", "))
8159 (delete-region position (point))
8160 (unless (vhdl-sequential-statement-p)
8161 (vhdl-insert-keyword " ON ")
8162 (if (vhdl-template-field "[sensitivity list]" nil t)
8163 (setq position (point))
8164 (delete-region position (point))))
8165 (vhdl-insert-keyword " WHEN ")
8166 (when vhdl-conditions-in-parenthesis (insert "("))
8167 (if (vhdl-template-field "[condition]" nil t)
8168 (when vhdl-conditions-in-parenthesis (insert ")"))
8169 (delete-region position (point)))
8170 (insert ";")))
8171
8172(defun vhdl-template-case (&optional kind)
8173 "Insert a case statement."
8174 (interactive)
8175 (let ((margin (current-indentation))
8176 (start (point))
8177 label)
8178 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8179 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8180 (vhdl-insert-keyword "CASE ")
8181 (vhdl-insert-keyword ": CASE ")
8182 (goto-char start)
8183 (setq label (vhdl-template-field "[label]" nil t))
8184 (unless label (delete-char 2))
8185 (forward-word 1)
8186 (forward-char 1))
8187 (when (vhdl-template-field "expression" nil t start (point))
8188 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
d2ddb974 8189 (indent-to margin)
5eabfe72
KH
8190 (vhdl-insert-keyword "END CASE")
8191 (when label (insert " " label))
8192 (insert ";")
d2ddb974
KH
8193 (forward-line -1)
8194 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8195 (vhdl-insert-keyword "WHEN ")
8196 (let ((position (point)))
8197 (insert " => ;\n")
8198 (indent-to (+ margin vhdl-basic-offset))
8199 (vhdl-insert-keyword "WHEN OTHERS => null;")
8200 (goto-char position)))))
d2ddb974 8201
5eabfe72
KH
8202(defun vhdl-template-case-is ()
8203 "Insert a sequential case statement."
d2ddb974 8204 (interactive)
5eabfe72
KH
8205 (vhdl-template-case 'is))
8206
8207(defun vhdl-template-case-use ()
8208 "Insert a simultaneous case statement."
8209 (interactive)
8210 (vhdl-template-case 'use))
8211
8212(defun vhdl-template-component ()
8213 "Insert a component declaration."
8214 (interactive)
8215 (vhdl-template-component-decl))
8216
8217(defun vhdl-template-component-conf ()
8218 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8219since these are almost equivalent)."
8220 (interactive)
8221 (let ((margin (current-indentation))
8222 (result (vhdl-template-configuration-spec t)))
8223 (when result
8224 (insert "\n")
8225 (indent-to margin)
8226 (vhdl-insert-keyword "END FOR;")
8227 (when (eq result 'no-use)
8228 (end-of-line -0)))))
8229
8230(defun vhdl-template-component-decl ()
8231 "Insert a component declaration."
8232 (interactive)
8233 (let ((margin (current-indentation))
8234 (start (point))
8235 name end-column)
d2ddb974 8236 (vhdl-insert-keyword "COMPONENT ")
5eabfe72 8237 (when (setq name (vhdl-template-field "name" nil t start (point)))
3dcb36b7 8238 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
d2ddb974
KH
8239 (insert "\n\n")
8240 (indent-to margin)
5eabfe72
KH
8241 (vhdl-insert-keyword "END COMPONENT")
8242 (unless (vhdl-standard-p '87) (insert " " name))
8243 (insert ";")
8244 (setq end-column (current-column))
d2ddb974
KH
8245 (end-of-line -0)
8246 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 8247 (vhdl-template-generic-list t t)
d2ddb974
KH
8248 (insert "\n")
8249 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8250 (vhdl-template-port-list t)
8251 (beginning-of-line 2)
8252 (forward-char end-column))))
d2ddb974 8253
5eabfe72
KH
8254(defun vhdl-template-component-inst ()
8255 "Insert a component instantiation statement."
d2ddb974 8256 (interactive)
5eabfe72
KH
8257 (let ((margin (current-indentation))
8258 (start (point))
8259 unit position)
8260 (when (vhdl-template-field "instance label" nil t start (point))
8261 (insert ": ")
3dcb36b7 8262 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
8263 (vhdl-template-field "component name")
8264 ;; direct instantiation
8265 (setq unit (vhdl-template-field
8266 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8267 (setq unit (upcase (or unit "")))
8268 (cond ((equal unit "ENTITY")
3dcb36b7
JB
8269 (vhdl-template-field "library name" "." nil nil nil nil
8270 (vhdl-work-library))
5eabfe72
KH
8271 (vhdl-template-field "entity name" "(")
8272 (if (vhdl-template-field "[architecture name]" nil t)
8273 (insert ")")
8274 (delete-char -1)))
8275 ((equal unit "CONFIGURATION")
3dcb36b7
JB
8276 (vhdl-template-field "library name" "." nil nil nil nil
8277 (vhdl-work-library))
5eabfe72
KH
8278 (vhdl-template-field "configuration name"))
8279 (t (vhdl-template-field "component name"))))
8280 (insert "\n")
d2ddb974 8281 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8282 (setq position (point))
8283 (vhdl-insert-keyword "GENERIC ")
8284 (when (vhdl-template-map position t t)
8285 (insert "\n")
8286 (indent-to (+ margin vhdl-basic-offset)))
8287 (setq position (point))
8288 (vhdl-insert-keyword "PORT ")
8289 (unless (vhdl-template-map position t t)
8290 (kill-line -0)
8291 (delete-char -1))
8292 (insert ";"))))
d2ddb974 8293
5eabfe72
KH
8294(defun vhdl-template-conditional-signal-asst ()
8295 "Insert a conditional signal assignment."
d2ddb974 8296 (interactive)
5eabfe72 8297 (when (vhdl-template-field "target signal")
d2ddb974 8298 (insert " <= ")
5eabfe72
KH
8299; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8300; (insert " "))
d2ddb974 8301 (let ((margin (current-column))
5eabfe72
KH
8302 (start (point))
8303 position)
8304 (vhdl-template-field "waveform")
8305 (setq position (point))
d2ddb974 8306 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8307 (when vhdl-conditions-in-parenthesis (insert "("))
8308 (while (and (vhdl-template-field "[condition]" nil t)
8309 (progn
8310 (when vhdl-conditions-in-parenthesis (insert ")"))
8311 (setq position (point))
8312 (vhdl-insert-keyword " ELSE")
8313 (insert "\n")
8314 (indent-to margin)
8315 (vhdl-template-field "[waveform]" nil t)))
8316 (setq position (point))
d2ddb974 8317 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8318 (when vhdl-conditions-in-parenthesis (insert "(")))
8319 (delete-region position (point))
d2ddb974 8320 (insert ";")
3dcb36b7 8321 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 8322
5eabfe72
KH
8323(defun vhdl-template-configuration ()
8324 "Insert a configuration specification if within an architecture,
d2ddb974
KH
8325a block or component configuration if within a configuration declaration,
8326a configuration declaration if not within a design unit."
8327 (interactive)
3dcb36b7
JB
8328 (vhdl-prepare-search-1
8329 (cond
8330 ((and (save-excursion ; architecture body
8331 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8332 (equal "ARCHITECTURE" (upcase (match-string 1))))
8333 (vhdl-template-configuration-spec))
8334 ((and (save-excursion ; configuration declaration
8335 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8336 (equal "CONFIGURATION" (upcase (match-string 1))))
8337 (if (eq (vhdl-decision-query
8338 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8339 (vhdl-template-component-conf)
8340 (vhdl-template-block-configuration)))
8341 (t (vhdl-template-configuration-decl))))) ; otherwise
5eabfe72
KH
8342
8343(defun vhdl-template-configuration-spec (&optional optional-use)
8344 "Insert a configuration specification."
d2ddb974 8345 (interactive)
5eabfe72
KH
8346 (let ((margin (current-indentation))
8347 (start (point))
8348 aspect position)
d2ddb974 8349 (vhdl-insert-keyword "FOR ")
3dcb36b7 8350 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
5eabfe72 8351 t start (point))
3dcb36b7 8352 (vhdl-template-field "component name" "\n")
d2ddb974 8353 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8354 (setq start (point))
8355 (vhdl-insert-keyword "USE ")
8356 (if (and optional-use
8357 (not (setq aspect (vhdl-template-field
8358 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8359 (progn (delete-region start (point)) 'no-use)
8360 (unless optional-use
8361 (setq aspect (vhdl-template-field
8362 "ENTITY | CONFIGURATION | OPEN" " ")))
8363 (setq aspect (upcase (or aspect "")))
8364 (cond ((equal aspect "ENTITY")
3dcb36b7
JB
8365 (vhdl-template-field "library name" "." nil nil nil nil
8366 (vhdl-work-library))
5eabfe72
KH
8367 (vhdl-template-field "entity name" "(")
8368 (if (vhdl-template-field "[architecture name]" nil t)
8369 (insert ")")
d2ddb974 8370 (delete-char -1))
5eabfe72
KH
8371 (insert "\n")
8372 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8373 (setq position (point))
8374 (vhdl-insert-keyword "GENERIC ")
8375 (when (vhdl-template-map position t t)
8376 (insert "\n")
8377 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8378 (setq position (point))
8379 (vhdl-insert-keyword "PORT ")
8380 (unless (vhdl-template-map position t t)
8381 (kill-line -0)
8382 (delete-char -1))
8383 (insert ";")
8384 t)
8385 ((equal aspect "CONFIGURATION")
3dcb36b7
JB
8386 (vhdl-template-field "library name" "." nil nil nil nil
8387 (vhdl-work-library))
5eabfe72 8388 (vhdl-template-field "configuration name" ";"))
3dcb36b7 8389 (t (delete-backward-char 1) (insert ";") t))))))
5eabfe72 8390
d2ddb974 8391
5eabfe72
KH
8392(defun vhdl-template-configuration-decl ()
8393 "Insert a configuration declaration."
d2ddb974 8394 (interactive)
5eabfe72
KH
8395 (let ((margin (current-indentation))
8396 (start (point))
5eabfe72 8397 entity-exists string name position)
d2ddb974 8398 (vhdl-insert-keyword "CONFIGURATION ")
5eabfe72 8399 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974 8400 (vhdl-insert-keyword " OF ")
5eabfe72 8401 (save-excursion
3dcb36b7
JB
8402 (vhdl-prepare-search-1
8403 (setq entity-exists (vhdl-re-search-backward
5eabfe72
KH
8404 "\\<entity \\(\\w*\\) is\\>" nil t))
8405 (setq string (match-string 1))))
d2ddb974 8406 (if (and entity-exists (not (equal string "")))
5eabfe72
KH
8407 (insert string)
8408 (vhdl-template-field "entity name"))
8409 (vhdl-insert-keyword " IS\n")
8410 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8411 (indent-to (+ margin vhdl-basic-offset))
8412 (setq position (point))
8413 (insert "\n")
8414 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
d2ddb974
KH
8415 (indent-to margin)
8416 (vhdl-insert-keyword "END ")
5eabfe72
KH
8417 (unless (vhdl-standard-p '87)
8418 (vhdl-insert-keyword "CONFIGURATION "))
d2ddb974 8419 (insert name ";")
5eabfe72 8420 (goto-char position))))
d2ddb974 8421
5eabfe72
KH
8422(defun vhdl-template-constant ()
8423 "Insert a constant declaration."
8424 (interactive)
8425 (let ((start (point))
8426 (in-arglist (vhdl-in-argument-list-p)))
8427 (vhdl-insert-keyword "CONSTANT ")
8428 (when (vhdl-template-field "name" nil t start (point))
d2ddb974 8429 (insert " : ")
5eabfe72
KH
8430 (when in-arglist (vhdl-insert-keyword "IN "))
8431 (vhdl-template-field "type")
d2ddb974 8432 (if in-arglist
5eabfe72
KH
8433 (progn (insert ";")
8434 (vhdl-comment-insert-inline))
d2ddb974
KH
8435 (let ((position (point)))
8436 (insert " := ")
5eabfe72
KH
8437 (unless (vhdl-template-field "[initialization]" nil t)
8438 (delete-region position (point)))
8439 (insert ";")
8440 (vhdl-comment-insert-inline))))))
d2ddb974 8441
5eabfe72 8442(defun vhdl-template-default ()
d2ddb974
KH
8443 "Insert nothing."
8444 (interactive)
8445 (insert " ")
8446 (unexpand-abbrev)
8447 (backward-word 1)
8448 (vhdl-case-word 1)
5eabfe72 8449 (forward-char 1))
d2ddb974 8450
5eabfe72 8451(defun vhdl-template-default-indent ()
d2ddb974
KH
8452 "Insert nothing and indent."
8453 (interactive)
8454 (insert " ")
8455 (unexpand-abbrev)
8456 (backward-word 1)
8457 (vhdl-case-word 1)
8458 (forward-char 1)
3dcb36b7 8459 (indent-according-to-mode))
d2ddb974 8460
5eabfe72 8461(defun vhdl-template-disconnect ()
d2ddb974
KH
8462 "Insert a disconnect statement."
8463 (interactive)
5eabfe72
KH
8464 (let ((start (point)))
8465 (vhdl-insert-keyword "DISCONNECT ")
8466 (when (vhdl-template-field "signal names | OTHERS | ALL"
8467 " : " t start (point))
8468 (vhdl-template-field "type")
8469 (vhdl-insert-keyword " AFTER ")
8470 (vhdl-template-field "time expression" ";"))))
8471
8472(defun vhdl-template-else ()
d2ddb974
KH
8473 "Insert an else statement."
8474 (interactive)
3dcb36b7
JB
8475 (let (margin)
8476 (vhdl-prepare-search-1
5eabfe72 8477 (vhdl-insert-keyword "ELSE")
3dcb36b7
JB
8478 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8479 (equal "WHEN" (upcase (match-string 1))))
5eabfe72 8480 (insert " ")
3dcb36b7 8481 (indent-according-to-mode)
5eabfe72
KH
8482 (setq margin (current-indentation))
8483 (insert "\n")
8484 (indent-to (+ margin vhdl-basic-offset))))))
8485
8486(defun vhdl-template-elsif ()
d2ddb974
KH
8487 "Insert an elsif statement."
8488 (interactive)
5eabfe72
KH
8489 (let ((start (point))
8490 margin)
d2ddb974 8491 (vhdl-insert-keyword "ELSIF ")
3dcb36b7
JB
8492 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8493 (when vhdl-conditions-in-parenthesis (insert "("))
8494 (when (vhdl-template-field "condition" nil t start (point))
8495 (when vhdl-conditions-in-parenthesis (insert ")"))
8496 (indent-according-to-mode)
8497 (setq margin (current-indentation))
8498 (vhdl-insert-keyword
8499 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8500 (indent-to (+ margin vhdl-basic-offset))))))
d2ddb974 8501
5eabfe72
KH
8502(defun vhdl-template-entity ()
8503 "Insert an entity."
d2ddb974 8504 (interactive)
5eabfe72
KH
8505 (let ((margin (current-indentation))
8506 (start (point))
8507 name end-column)
d2ddb974 8508 (vhdl-insert-keyword "ENTITY ")
5eabfe72 8509 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974
KH
8510 (vhdl-insert-keyword " IS\n\n")
8511 (indent-to margin)
8512 (vhdl-insert-keyword "END ")
5eabfe72
KH
8513 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8514 (insert name ";")
8515 (setq end-column (current-column))
d2ddb974
KH
8516 (end-of-line -0)
8517 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8518 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8519 (indent-to (+ margin vhdl-basic-offset))
8520 (when (vhdl-template-generic-list t)
8521 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8522 (insert "\n")
8523 (indent-to (+ margin vhdl-basic-offset))
8524 (when (vhdl-template-port-list t)
8525 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8526 (beginning-of-line 2)
8527 (forward-char end-column))))
d2ddb974 8528
5eabfe72 8529(defun vhdl-template-exit ()
d2ddb974
KH
8530 "Insert an exit statement."
8531 (interactive)
5eabfe72
KH
8532 (let ((start (point)))
8533 (vhdl-insert-keyword "EXIT ")
3dcb36b7
JB
8534 (if (vhdl-template-field "[loop label]" nil t start (point))
8535 (let ((position (point)))
8536 (vhdl-insert-keyword " WHEN ")
8537 (when vhdl-conditions-in-parenthesis (insert "("))
8538 (if (vhdl-template-field "[condition]" nil t)
8539 (when vhdl-conditions-in-parenthesis (insert ")"))
8540 (delete-region position (point))))
d2ddb974 8541 (delete-char -1))
5eabfe72
KH
8542 (insert ";")))
8543
8544(defun vhdl-template-file ()
8545 "Insert a file declaration."
8546 (interactive)
8547 (let ((start (point)))
8548 (vhdl-insert-keyword "FILE ")
8549 (when (vhdl-template-field "name" nil t start (point))
8550 (insert " : ")
8551 (vhdl-template-field "type")
8552 (unless (vhdl-standard-p '87)
8553 (vhdl-insert-keyword " OPEN ")
8554 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8555 nil t)
3dcb36b7 8556 (delete-backward-char 6)))
5eabfe72
KH
8557 (vhdl-insert-keyword " IS ")
8558 (when (vhdl-standard-p '87)
8559 (vhdl-template-field "[IN | OUT]" " " t))
8560 (vhdl-template-field "filename-string" nil nil nil nil t)
8561 (insert ";")
8562 (vhdl-comment-insert-inline))))
d2ddb974 8563
5eabfe72
KH
8564(defun vhdl-template-for ()
8565 "Insert a block or component configuration if within a configuration
8566declaration, a configuration specification if within an architecture
3dcb36b7
JB
8567declarative part (and not within a subprogram), a for-loop if within a
8568sequential statement part (subprogram or process), and a for-generate
8569otherwise."
5eabfe72 8570 (interactive)
3dcb36b7
JB
8571 (vhdl-prepare-search-1
8572 (cond
8573 ((vhdl-sequential-statement-p) ; sequential statement
8574 (vhdl-template-for-loop))
8575 ((and (save-excursion ; configuration declaration
8576 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8577 (equal "CONFIGURATION" (upcase (match-string 1))))
8578 (if (eq (vhdl-decision-query
8579 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8580 (vhdl-template-component-conf)
8581 (vhdl-template-block-configuration)))
8582 ((and (save-excursion
8583 (re-search-backward ; architecture declarative part
8584 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8585 (equal "ARCHITECTURE" (upcase (match-string 1))))
8586 (vhdl-template-configuration-spec))
8587 (t (vhdl-template-for-generate))))) ; concurrent statement
5eabfe72
KH
8588
8589(defun vhdl-template-for-generate ()
8590 "Insert a for-generate."
d2ddb974 8591 (interactive)
5eabfe72
KH
8592 (let ((margin (current-indentation))
8593 (start (point))
3dcb36b7 8594 label position)
5eabfe72
KH
8595 (vhdl-insert-keyword ": FOR ")
8596 (setq position (point-marker))
8597 (goto-char start)
8598 (when (setq label (vhdl-template-field "label" nil t start position))
8599 (goto-char position)
8600 (vhdl-template-field "loop variable")
8601 (vhdl-insert-keyword " IN ")
8602 (vhdl-template-field "range")
8603 (vhdl-template-generate-body margin label))))
d2ddb974 8604
5eabfe72
KH
8605(defun vhdl-template-for-loop ()
8606 "Insert a for loop."
d2ddb974 8607 (interactive)
5eabfe72
KH
8608 (let ((margin (current-indentation))
8609 (start (point))
8610 label index)
8611 (if (not (eq vhdl-optional-labels 'all))
8612 (vhdl-insert-keyword "FOR ")
8613 (vhdl-insert-keyword ": FOR ")
8614 (goto-char start)
8615 (setq label (vhdl-template-field "[label]" nil t))
8616 (unless label (delete-char 2))
8617 (forward-word 1)
8618 (forward-char 1))
8619 (when (setq index (vhdl-template-field "loop variable"
8620 nil t start (point)))
d2ddb974 8621 (vhdl-insert-keyword " IN ")
5eabfe72 8622 (vhdl-template-field "range")
d2ddb974
KH
8623 (vhdl-insert-keyword " LOOP\n\n")
8624 (indent-to margin)
8625 (vhdl-insert-keyword "END LOOP")
5eabfe72
KH
8626 (if label
8627 (insert " " label ";")
d2ddb974 8628 (insert ";")
5eabfe72 8629 (when vhdl-self-insert-comments (insert " -- " index)))
d2ddb974 8630 (forward-line -1)
5eabfe72 8631 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8632
5eabfe72
KH
8633(defun vhdl-template-function (&optional kind)
8634 "Insert a function declaration or body."
d2ddb974 8635 (interactive)
5eabfe72
KH
8636 (let ((margin (current-indentation))
8637 (start (point))
8638 name)
8639 (vhdl-insert-keyword "FUNCTION ")
8640 (when (setq name (vhdl-template-field "name" nil t start (point)))
8641 (vhdl-template-argument-list t)
3dcb36b7 8642 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
d2ddb974 8643 (end-of-line)
5eabfe72 8644 (insert "\n")
d2ddb974 8645 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8646 (vhdl-insert-keyword "RETURN ")
8647 (vhdl-template-field "type")
8648 (if (if kind (eq kind 'body)
8649 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
3dcb36b7 8650 (progn (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8651 (vhdl-template-begin-end
8652 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8653 (vhdl-comment-block))
8654 (insert ";")))))
8655
8656(defun vhdl-template-function-decl ()
8657 "Insert a function declaration."
8658 (interactive)
8659 (vhdl-template-function 'decl))
d2ddb974 8660
5eabfe72
KH
8661(defun vhdl-template-function-body ()
8662 "Insert a function declaration."
d2ddb974 8663 (interactive)
5eabfe72
KH
8664 (vhdl-template-function 'body))
8665
8666(defun vhdl-template-generate ()
8667 "Insert a generation scheme."
8668 (interactive)
8669 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8670 (vhdl-template-if-generate)
8671 (vhdl-template-for-generate)))
d2ddb974 8672
5eabfe72
KH
8673(defun vhdl-template-generic ()
8674 "Insert generic declaration, or generic map in instantiation statements."
8675 (interactive)
3dcb36b7
JB
8676 (let ((start (point)))
8677 (vhdl-prepare-search-1
5eabfe72
KH
8678 (cond
8679 ((and (save-excursion ; entity declaration
8680 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8681 (equal "ENTITY" (upcase (match-string 1))))
8682 (vhdl-template-generic-list nil))
8683 ((or (save-excursion
8684 (or (beginning-of-line)
8685 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 8686 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
8687 (vhdl-insert-keyword "GENERIC ")
8688 (vhdl-template-map start))
8689 (t (vhdl-template-generic-list nil t))))))
8690
8691(defun vhdl-template-group ()
8692 "Insert group or group template declaration."
8693 (interactive)
8694 (let ((start (point)))
8695 (if (eq (vhdl-decision-query
8696 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8697 (vhdl-template-group-template)
8698 (vhdl-template-group-decl))))
8699
8700(defun vhdl-template-group-decl ()
8701 "Insert group declaration."
8702 (interactive)
8703 (let ((start (point)))
8704 (vhdl-insert-keyword "GROUP ")
8705 (when (vhdl-template-field "name" " : " t start (point))
8706 (vhdl-template-field "template name" " (")
8707 (vhdl-template-field "constituent list" ");")
8708 (vhdl-comment-insert-inline))))
8709
8710(defun vhdl-template-group-template ()
8711 "Insert group template declaration."
8712 (interactive)
8713 (let ((start (point)))
8714 (vhdl-insert-keyword "GROUP ")
8715 (when (vhdl-template-field "template name" nil t start (point))
8716 (vhdl-insert-keyword " IS (")
8717 (vhdl-template-field "entity class list" ");")
8718 (vhdl-comment-insert-inline))))
8719
5eabfe72
KH
8720(defun vhdl-template-if ()
8721 "Insert a sequential if statement or an if-generate statement."
8722 (interactive)
8723 (if (vhdl-sequential-statement-p)
8724 (vhdl-template-if-then)
8725 (if (and (vhdl-standard-p 'ams)
8726 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8727 (vhdl-template-if-use)
8728 (vhdl-template-if-generate))))
8729
8730(defun vhdl-template-if-generate ()
8731 "Insert an if-generate."
8732 (interactive)
8733 (let ((margin (current-indentation))
8734 (start (point))
3dcb36b7 8735 label position)
5eabfe72
KH
8736 (vhdl-insert-keyword ": IF ")
8737 (setq position (point-marker))
8738 (goto-char start)
8739 (when (setq label (vhdl-template-field "label" nil t start position))
8740 (goto-char position)
8741 (when vhdl-conditions-in-parenthesis (insert "("))
8742 (vhdl-template-field "condition")
8743 (when vhdl-conditions-in-parenthesis (insert ")"))
8744 (vhdl-template-generate-body margin label))))
d2ddb974 8745
5eabfe72
KH
8746(defun vhdl-template-if-then-use (kind)
8747 "Insert a sequential if statement."
8748 (interactive)
8749 (let ((margin (current-indentation))
8750 (start (point))
8751 label)
8752 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8753 (vhdl-insert-keyword "IF ")
8754 (vhdl-insert-keyword ": IF ")
8755 (goto-char start)
8756 (setq label (vhdl-template-field "[label]" nil t))
8757 (unless label (delete-char 2))
8758 (forward-word 1)
8759 (forward-char 1))
8760 (when vhdl-conditions-in-parenthesis (insert "("))
8761 (when (vhdl-template-field "condition" nil t start (point))
8762 (when vhdl-conditions-in-parenthesis (insert ")"))
8763 (vhdl-insert-keyword
8764 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
d2ddb974 8765 (indent-to margin)
5eabfe72
KH
8766 (vhdl-insert-keyword "END IF")
8767 (when label (insert " " label))
8768 (insert ";")
d2ddb974 8769 (forward-line -1)
5eabfe72
KH
8770 (indent-to (+ margin vhdl-basic-offset)))))
8771
8772(defun vhdl-template-if-then ()
8773 "Insert a sequential if statement."
8774 (interactive)
8775 (vhdl-template-if-then-use 'then))
8776
8777(defun vhdl-template-if-use ()
8778 "Insert a simultaneous if statement."
8779 (interactive)
8780 (vhdl-template-if-then-use 'use))
8781
8782(defun vhdl-template-instance ()
8783 "Insert a component instantiation statement."
8784 (interactive)
8785 (vhdl-template-component-inst))
d2ddb974 8786
5eabfe72 8787(defun vhdl-template-library ()
d2ddb974
KH
8788 "Insert a library specification."
8789 (interactive)
5eabfe72
KH
8790 (let ((margin (current-indentation))
8791 (start (point))
8792 name end-pos)
d2ddb974 8793 (vhdl-insert-keyword "LIBRARY ")
5eabfe72
KH
8794 (when (setq name (vhdl-template-field "names" nil t start (point)))
8795 (insert ";")
8796 (unless (string-match "," name)
8797 (setq end-pos (point))
8798 (insert "\n")
8799 (indent-to margin)
8800 (vhdl-insert-keyword "USE ")
8801 (insert name)
8802 (vhdl-insert-keyword "..ALL;")
8803 (backward-char 5)
8804 (if (vhdl-template-field "package name")
8805 (forward-char 5)
8806 (delete-region end-pos (+ (point) 5)))))))
8807
8808(defun vhdl-template-limit ()
8809 "Insert a limit."
d2ddb974 8810 (interactive)
5eabfe72
KH
8811 (let ((start (point)))
8812 (vhdl-insert-keyword "LIMIT ")
8813 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8814 t start (point))
8815 (vhdl-template-field "type")
8816 (vhdl-insert-keyword " WITH ")
8817 (vhdl-template-field "real expression" ";"))))
8818
8819(defun vhdl-template-loop ()
8820 "Insert a loop."
8821 (interactive)
8822 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8823 (cond ((eq char ?w)
8824 (vhdl-template-while-loop))
8825 ((eq char ?f)
8826 (vhdl-template-for-loop))
8827 (t (vhdl-template-bare-loop)))))
8828
8829(defun vhdl-template-bare-loop ()
8830 "Insert a loop."
8831 (interactive)
8832 (let ((margin (current-indentation))
8833 (start (point))
8834 label)
8835 (if (not (eq vhdl-optional-labels 'all))
8836 (vhdl-insert-keyword "LOOP ")
8837 (vhdl-insert-keyword ": LOOP ")
8838 (goto-char start)
8839 (setq label (vhdl-template-field "[label]" nil t))
8840 (unless label (delete-char 2))
8841 (forward-word 1)
8842 (delete-char 1))
d2ddb974
KH
8843 (insert "\n\n")
8844 (indent-to margin)
8845 (vhdl-insert-keyword "END LOOP")
5eabfe72 8846 (insert (if label (concat " " label ";") ";"))
d2ddb974 8847 (forward-line -1)
5eabfe72 8848 (indent-to (+ margin vhdl-basic-offset))))
d2ddb974 8849
5eabfe72
KH
8850(defun vhdl-template-map (&optional start optional secondary)
8851 "Insert a map specification with association list."
d2ddb974 8852 (interactive)
5eabfe72
KH
8853 (let ((start (or start (point)))
8854 margin end-pos)
8855 (vhdl-insert-keyword "MAP (")
8856 (if (not vhdl-association-list-with-formals)
8857 (if (vhdl-template-field
8858 (concat (and optional "[") "association list" (and optional "]"))
8859 ")" (or (not secondary) optional)
8860 (and (not secondary) start) (point))
8861 t
8862 (if (and optional secondary) (delete-region start (point)))
8863 nil)
8864 (if vhdl-argument-list-indent
8865 (setq margin (current-column))
8866 (setq margin (+ (current-indentation) vhdl-basic-offset))
8867 (insert "\n")
8868 (indent-to margin))
8869 (if (vhdl-template-field
8870 (concat (and optional "[") "formal" (and optional "]"))
8871 " => " (or (not secondary) optional)
8872 (and (not secondary) start) (point))
8873 (progn
8874 (vhdl-template-field "actual" ",")
8875 (setq end-pos (point))
8876 (insert "\n")
8877 (indent-to margin)
8878 (while (vhdl-template-field "[formal]" " => " t)
8879 (vhdl-template-field "actual" ",")
8880 (setq end-pos (point))
8881 (insert "\n")
8882 (indent-to margin))
8883 (delete-region end-pos (point))
3dcb36b7 8884 (delete-backward-char 1)
5eabfe72 8885 (insert ")")
3dcb36b7 8886 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
8887 t)
8888 (when (and optional secondary) (delete-region start (point)))
8889 nil))))
d2ddb974 8890
5eabfe72 8891(defun vhdl-template-modify (&optional noerror)
d2ddb974
KH
8892 "Actualize modification date."
8893 (interactive)
3dcb36b7
JB
8894 (vhdl-prepare-search-2
8895 (save-excursion
8896 (goto-char (point-min))
8897 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
8898 (progn (delete-region (point) (progn (end-of-line) (point)))
8899 (vhdl-template-insert-date))
8900 (unless noerror
8901 (error (concat "ERROR: Modification date prefix string \""
8902 vhdl-modify-date-prefix-string "\" not found")))))))
5eabfe72
KH
8903
8904(defun vhdl-template-modify-noerror ()
8905 "Call `vhdl-template-modify' with NOERROR non-nil."
8906 (vhdl-template-modify t))
8907
8908(defun vhdl-template-nature ()
8909 "Insert a nature declaration."
8910 (interactive)
8911 (let ((start (point))
8912 name mid-pos end-pos)
8913 (vhdl-insert-keyword "NATURE ")
8914 (when (setq name (vhdl-template-field "name" nil t start (point)))
8915 (vhdl-insert-keyword " IS ")
8916 (let ((definition
8917 (upcase
8918 (or (vhdl-template-field
8919 "across type | ARRAY | RECORD")
8920 ""))))
8921 (cond ((equal definition "")
8922 (insert ";"))
8923 ((equal definition "ARRAY")
8924 (kill-word -1)
8925 (vhdl-template-array 'nature t))
8926 ((equal definition "RECORD")
8927 (setq mid-pos (point-marker))
8928 (kill-word -1)
8929 (vhdl-template-record 'nature name t))
8930 (t
8931 (vhdl-insert-keyword " ACROSS ")
8932 (vhdl-template-field "through type")
8933 (vhdl-insert-keyword " THROUGH ")
8934 (vhdl-template-field "reference name")
8935 (vhdl-insert-keyword " REFERENCE;")))
8936 (when mid-pos
8937 (setq end-pos (point-marker))
8938 (goto-char mid-pos)
8939 (end-of-line))
8940 (vhdl-comment-insert-inline)
8941 (when end-pos (goto-char end-pos))))))
8942
8943(defun vhdl-template-next ()
8944 "Insert a next statement."
d2ddb974 8945 (interactive)
3dcb36b7
JB
8946 (let ((start (point)))
8947 (vhdl-insert-keyword "NEXT ")
8948 (if (vhdl-template-field "[loop label]" nil t start (point))
8949 (let ((position (point)))
8950 (vhdl-insert-keyword " WHEN ")
8951 (when vhdl-conditions-in-parenthesis (insert "("))
8952 (if (vhdl-template-field "[condition]" nil t)
8953 (when vhdl-conditions-in-parenthesis (insert ")"))
8954 (delete-region position (point))))
8955 (delete-char -1))
5eabfe72
KH
8956 (insert ";")))
8957
8958(defun vhdl-template-others ()
8959 "Insert an others aggregate."
8960 (interactive)
3dcb36b7
JB
8961 (let ((start (point)))
8962 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
8963 (progn (unless vhdl-template-invoked-by-hook (insert "("))
8964 (vhdl-insert-keyword "OTHERS => '")
8965 (when (vhdl-template-field "value" nil t start (point))
8966 (insert "')")))
8967 (vhdl-insert-keyword "OTHERS "))))
d2ddb974 8968
5eabfe72 8969(defun vhdl-template-package (&optional kind)
d2ddb974
KH
8970 "Insert a package specification or body."
8971 (interactive)
5eabfe72
KH
8972 (let ((margin (current-indentation))
8973 (start (point))
8974 name body position)
d2ddb974 8975 (vhdl-insert-keyword "PACKAGE ")
5eabfe72
KH
8976 (setq body (if kind (eq kind 'body)
8977 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
3dcb36b7
JB
8978 (when body
8979 (vhdl-insert-keyword "BODY ")
8980 (when (save-excursion
8981 (vhdl-prepare-search-1
8982 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
8983 (insert (setq name (match-string 1)))))
8984 (when (or name
8985 (setq name (vhdl-template-field "name" nil t start (point))))
5eabfe72
KH
8986 (vhdl-insert-keyword " IS\n")
8987 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8988 (indent-to (+ margin vhdl-basic-offset))
8989 (setq position (point))
8990 (insert "\n")
8991 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8992 (indent-to margin)
8993 (vhdl-insert-keyword "END ")
8994 (unless (vhdl-standard-p '87)
8995 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
8996 (insert (or name "") ";")
8997 (goto-char position))))
d2ddb974 8998
5eabfe72
KH
8999(defun vhdl-template-package-decl ()
9000 "Insert a package specification."
d2ddb974 9001 (interactive)
5eabfe72 9002 (vhdl-template-package 'decl))
d2ddb974 9003
5eabfe72
KH
9004(defun vhdl-template-package-body ()
9005 "Insert a package body."
d2ddb974 9006 (interactive)
5eabfe72 9007 (vhdl-template-package 'body))
d2ddb974 9008
5eabfe72
KH
9009(defun vhdl-template-port ()
9010 "Insert a port declaration, or port map in instantiation statements."
d2ddb974 9011 (interactive)
3dcb36b7
JB
9012 (let ((start (point)))
9013 (vhdl-prepare-search-1
5eabfe72
KH
9014 (cond
9015 ((and (save-excursion ; entity declaration
9016 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9017 (equal "ENTITY" (upcase (match-string 1))))
9018 (vhdl-template-port-list nil))
9019 ((or (save-excursion
9020 (or (beginning-of-line)
9021 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 9022 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
9023 (vhdl-insert-keyword "PORT ")
9024 (vhdl-template-map start))
9025 (t (vhdl-template-port-list nil))))))
9026
9027(defun vhdl-template-procedural ()
9028 "Insert a procedural."
9029 (interactive)
9030 (let ((margin (current-indentation))
9031 (start (point))
9032 (case-fold-search t)
9033 label)
9034 (vhdl-insert-keyword "PROCEDURAL ")
9035 (when (memq vhdl-optional-labels '(process all))
9036 (goto-char start)
9037 (insert ": ")
9038 (goto-char start)
9039 (setq label (vhdl-template-field "[label]" nil t))
9040 (unless label (delete-char 2))
9041 (forward-word 1)
9042 (forward-char 1))
9043 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
3dcb36b7 9044 (insert "\n")
5eabfe72
KH
9045 (vhdl-template-begin-end "PROCEDURAL" label margin)
9046 (vhdl-comment-block)))
9047
9048(defun vhdl-template-procedure (&optional kind)
9049 "Insert a procedure declaration or body."
9050 (interactive)
9051 (let ((margin (current-indentation))
9052 (start (point))
9053 name)
9054 (vhdl-insert-keyword "PROCEDURE ")
9055 (when (setq name (vhdl-template-field "name" nil t start (point)))
9056 (vhdl-template-argument-list)
9057 (if (if kind (eq kind 'body)
9058 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9059 (progn (vhdl-insert-keyword " IS")
9060 (when vhdl-auto-align
3dcb36b7
JB
9061 (vhdl-align-region-groups start (point) 1))
9062 (end-of-line) (insert "\n")
5eabfe72
KH
9063 (vhdl-template-begin-end
9064 (unless (vhdl-standard-p '87) "PROCEDURE")
9065 name margin)
9066 (vhdl-comment-block))
9067 (insert ";")
3dcb36b7 9068 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9069 (end-of-line)))))
9070
9071(defun vhdl-template-procedure-decl ()
9072 "Insert a procedure declaration."
9073 (interactive)
9074 (vhdl-template-procedure 'decl))
d2ddb974 9075
5eabfe72
KH
9076(defun vhdl-template-procedure-body ()
9077 "Insert a procedure body."
9078 (interactive)
9079 (vhdl-template-procedure 'body))
9080
9081(defun vhdl-template-process (&optional kind)
9082 "Insert a process."
9083 (interactive)
9084 (let ((margin (current-indentation))
9085 (start (point))
5eabfe72
KH
9086 label seq input-signals clock reset final-pos)
9087 (setq seq (if kind (eq kind 'seq)
9088 (eq (vhdl-decision-query
9089 "process" "(c)ombinational or (s)equential?" t) ?s)))
9090 (vhdl-insert-keyword "PROCESS ")
9091 (when (memq vhdl-optional-labels '(process all))
9092 (goto-char start)
9093 (insert ": ")
9094 (goto-char start)
9095 (setq label (vhdl-template-field "[label]" nil t))
9096 (unless label (delete-char 2))
9097 (forward-word 1)
9098 (forward-char 1))
9099 (insert "(")
9100 (if (not seq)
9101 (unless (setq input-signals
9102 (vhdl-template-field "[sensitivity list]" ")" t))
9103 (setq input-signals "")
9104 (delete-char -2))
9105 (setq clock (or (and (not (equal "" vhdl-clock-name))
9106 (progn (insert vhdl-clock-name) vhdl-clock-name))
9107 (vhdl-template-field "clock name") "<clock>"))
9108 (when (eq vhdl-reset-kind 'async)
9109 (insert ", ")
9110 (setq reset (or (and (not (equal "" vhdl-reset-name))
9111 (progn (insert vhdl-reset-name) vhdl-reset-name))
9112 (vhdl-template-field "reset name") "<reset>")))
9113 (insert ")"))
9114 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 9115 (insert "\n")
5eabfe72
KH
9116 (vhdl-template-begin-end "PROCESS" label margin)
9117 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9118 (when vhdl-prompt-for-comments
9119 (setq final-pos (point-marker))
3dcb36b7
JB
9120 (vhdl-prepare-search-2
9121 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9122 (vhdl-re-search-backward "\\<process\\>" nil t))
5eabfe72
KH
9123 (end-of-line -0)
9124 (if (bobp)
9125 (progn (insert "\n") (forward-line -1))
9126 (insert "\n"))
9127 (indent-to margin)
9128 (insert "-- purpose: ")
9129 (if (not (vhdl-template-field "[description]" nil t))
9130 (vhdl-line-kill-entire)
9131 (insert "\n")
9132 (indent-to margin)
9133 (insert "-- type : ")
9134 (insert (if seq "sequential" "combinational") "\n")
9135 (indent-to margin)
9136 (insert "-- inputs : ")
9137 (if (not seq)
9138 (insert input-signals)
9139 (insert clock ", ")
9140 (when reset (insert reset ", "))
9141 (unless (vhdl-template-field "[signal names]" nil t)
9142 (delete-char -2)))
9143 (insert "\n")
9144 (indent-to margin)
9145 (insert "-- outputs: ")
9146 (vhdl-template-field "[signal names]" nil t))))
9147 (goto-char final-pos))))
9148
9149(defun vhdl-template-process-comb ()
9150 "Insert a combinational process."
9151 (interactive)
9152 (vhdl-template-process 'comb))
9153
9154(defun vhdl-template-process-seq ()
9155 "Insert a sequential process."
9156 (interactive)
9157 (vhdl-template-process 'seq))
9158
9159(defun vhdl-template-quantity ()
9160 "Insert a quantity declaration."
9161 (interactive)
9162 (if (vhdl-in-argument-list-p)
9163 (let ((start (point)))
9164 (vhdl-insert-keyword "QUANTITY ")
9165 (when (vhdl-template-field "names" nil t start (point))
9166 (insert " : ")
9167 (vhdl-template-field "[IN | OUT]" " " t)
9168 (vhdl-template-field "type")
9169 (insert ";")
9170 (vhdl-comment-insert-inline)))
9171 (let ((char (vhdl-decision-query
9172 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9173 (cond ((eq char ?f) (vhdl-template-quantity-free))
9174 ((eq char ?b) (vhdl-template-quantity-branch))
9175 ((eq char ?s) (vhdl-template-quantity-source))
9176 (t (vhdl-template-undo (point) (point)))))))
9177
9178(defun vhdl-template-quantity-free ()
9179 "Insert a free quantity declaration."
9180 (interactive)
9181 (vhdl-insert-keyword "QUANTITY ")
9182 (vhdl-template-field "names")
9183 (insert " : ")
9184 (vhdl-template-field "type")
9185 (let ((position (point)))
9186 (insert " := ")
9187 (unless (vhdl-template-field "[initialization]" nil t)
9188 (delete-region position (point)))
9189 (insert ";")
9190 (vhdl-comment-insert-inline)))
9191
9192(defun vhdl-template-quantity-branch ()
9193 "Insert a branch quantity declaration."
9194 (interactive)
9195 (let (position)
9196 (vhdl-insert-keyword "QUANTITY ")
9197 (when (vhdl-template-field "[across names]" " " t)
9198 (vhdl-insert-keyword "ACROSS "))
9199 (when (vhdl-template-field "[through names]" " " t)
9200 (vhdl-insert-keyword "THROUGH "))
9201 (vhdl-template-field "plus terminal name")
9202 (setq position (point))
9203 (vhdl-insert-keyword " TO ")
9204 (unless (vhdl-template-field "[minus terminal name]" nil t)
9205 (delete-region position (point)))
9206 (insert ";")
9207 (vhdl-comment-insert-inline)))
9208
9209(defun vhdl-template-quantity-source ()
9210 "Insert a source quantity declaration."
9211 (interactive)
9212 (vhdl-insert-keyword "QUANTITY ")
9213 (vhdl-template-field "names")
9214 (insert " : ")
9215 (vhdl-template-field "type" " ")
9216 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9217 (progn (vhdl-insert-keyword "NOISE ")
9218 (vhdl-template-field "power expression"))
9219 (vhdl-insert-keyword "SPECTRUM ")
9220 (vhdl-template-field "magnitude expression" ", ")
9221 (vhdl-template-field "phase expression"))
9222 (insert ";")
9223 (vhdl-comment-insert-inline))
9224
9225(defun vhdl-template-record (kind &optional name secondary)
d2ddb974
KH
9226 "Insert a record type declaration."
9227 (interactive)
9228 (let ((margin (current-column))
9229 (start (point))
9230 (first t))
9231 (vhdl-insert-keyword "RECORD\n")
9232 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9233 (when (or (vhdl-template-field "element names"
9234 nil (not secondary) start (point))
9235 secondary)
9236 (while (or first (vhdl-template-field "[element names]" nil t))
9237 (insert " : ")
9238 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9239 (vhdl-comment-insert-inline)
9240 (insert "\n")
d2ddb974 9241 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 9242 (setq first nil))
d2ddb974
KH
9243 (kill-line -0)
9244 (indent-to margin)
5eabfe72
KH
9245 (vhdl-insert-keyword "END RECORD")
9246 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9247 (insert ";")
3dcb36b7 9248 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9249
5eabfe72
KH
9250(defun vhdl-template-report ()
9251 "Insert a report statement."
9252 (interactive)
9253 (let ((start (point)))
9254 (vhdl-insert-keyword "REPORT ")
9255 (if (equal "\"\"" (vhdl-template-field
9256 "string expression" nil t start (point) t))
3dcb36b7 9257 (delete-backward-char 2)
5eabfe72
KH
9258 (setq start (point))
9259 (vhdl-insert-keyword " SEVERITY ")
9260 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9261 (delete-region start (point)))
9262 (insert ";"))))
9263
9264(defun vhdl-template-return ()
d2ddb974
KH
9265 "Insert a return statement."
9266 (interactive)
3dcb36b7
JB
9267 (let ((start (point)))
9268 (vhdl-insert-keyword "RETURN ")
9269 (unless (vhdl-template-field "[expression]" nil t start (point))
9270 (delete-char -1))
9271 (insert ";")))
d2ddb974 9272
5eabfe72 9273(defun vhdl-template-selected-signal-asst ()
d2ddb974
KH
9274 "Insert a selected signal assignment."
9275 (interactive)
5eabfe72
KH
9276 (let ((margin (current-indentation))
9277 (start (point))
9278 (choices t))
d2ddb974 9279 (let ((position (point)))
5eabfe72 9280 (vhdl-insert-keyword " SELECT ")
d2ddb974
KH
9281 (goto-char position))
9282 (vhdl-insert-keyword "WITH ")
5eabfe72
KH
9283 (when (vhdl-template-field "selector expression"
9284 nil t start (+ (point) 7))
9285 (forward-word 1)
9286 (delete-char 1)
d2ddb974
KH
9287 (insert "\n")
9288 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9289 (vhdl-template-field "target signal" " <= ")
9290; (vhdl-template-field "[GUARDED] [TRANSPORT]")
d2ddb974
KH
9291 (insert "\n")
9292 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9293 (vhdl-template-field "waveform")
9294 (vhdl-insert-keyword " WHEN ")
9295 (vhdl-template-field "choices" ",")
9296 (insert "\n")
9297 (indent-to (+ margin vhdl-basic-offset))
9298 (while (and choices (vhdl-template-field "[waveform]" nil t))
d2ddb974 9299 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
9300 (if (setq choices (vhdl-template-field "[choices]" "," t))
9301 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9302 (vhdl-insert-keyword "OTHERS")))
9303 (when choices
d2ddb974
KH
9304 (fixup-whitespace)
9305 (delete-char -2))
9306 (insert ";")
3dcb36b7 9307 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9308
5eabfe72 9309(defun vhdl-template-signal ()
d2ddb974
KH
9310 "Insert a signal declaration."
9311 (interactive)
5eabfe72
KH
9312 (let ((start (point))
9313 (in-arglist (vhdl-in-argument-list-p)))
9314 (vhdl-insert-keyword "SIGNAL ")
9315 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9316 (insert " : ")
5eabfe72
KH
9317 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9318 (vhdl-template-field "type")
d2ddb974 9319 (if in-arglist
5eabfe72
KH
9320 (progn (insert ";")
9321 (vhdl-comment-insert-inline))
d2ddb974
KH
9322 (let ((position (point)))
9323 (insert " := ")
5eabfe72
KH
9324 (unless (vhdl-template-field "[initialization]" nil t)
9325 (delete-region position (point)))
9326 (insert ";")
9327 (vhdl-comment-insert-inline))))))
9328
9329(defun vhdl-template-subnature ()
9330 "Insert a subnature declaration."
9331 (interactive)
9332 (let ((start (point))
9333 position)
9334 (vhdl-insert-keyword "SUBNATURE ")
9335 (when (vhdl-template-field "name" nil t start (point))
9336 (vhdl-insert-keyword " IS ")
9337 (vhdl-template-field "nature" " (")
9338 (if (vhdl-template-field "[index range]" nil t)
9339 (insert ")")
9340 (delete-char -2))
9341 (setq position (point))
9342 (vhdl-insert-keyword " TOLERANCE ")
9343 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9344 nil t nil nil t))
9345 (delete-region position (point))
9346 (vhdl-insert-keyword " ACROSS ")
9347 (vhdl-template-field "string expression" nil nil nil nil t)
9348 (vhdl-insert-keyword " THROUGH"))
9349 (insert ";")
9350 (vhdl-comment-insert-inline))))
9351
9352(defun vhdl-template-subprogram-body ()
9353 "Insert a subprogram body."
9354 (interactive)
9355 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9356 (vhdl-template-function-body)
9357 (vhdl-template-procedure-body)))
d2ddb974 9358
5eabfe72
KH
9359(defun vhdl-template-subprogram-decl ()
9360 "Insert a subprogram declaration."
9361 (interactive)
9362 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9363 (vhdl-template-function-decl)
9364 (vhdl-template-procedure-decl)))
9365
9366(defun vhdl-template-subtype ()
d2ddb974
KH
9367 "Insert a subtype declaration."
9368 (interactive)
5eabfe72
KH
9369 (let ((start (point)))
9370 (vhdl-insert-keyword "SUBTYPE ")
9371 (when (vhdl-template-field "name" nil t start (point))
9372 (vhdl-insert-keyword " IS ")
9373 (vhdl-template-field "type" " ")
9374 (unless
9375 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
d2ddb974 9376 (delete-char -1))
5eabfe72
KH
9377 (insert ";")
9378 (vhdl-comment-insert-inline))))
d2ddb974 9379
5eabfe72
KH
9380(defun vhdl-template-terminal ()
9381 "Insert a terminal declaration."
d2ddb974 9382 (interactive)
5eabfe72
KH
9383 (let ((start (point)))
9384 (vhdl-insert-keyword "TERMINAL ")
9385 (when (vhdl-template-field "names" nil t start (point))
9386 (insert " : ")
9387 (vhdl-template-field "nature")
9388 (insert ";")
9389 (vhdl-comment-insert-inline))))
d2ddb974 9390
5eabfe72
KH
9391(defun vhdl-template-type ()
9392 "Insert a type declaration."
9393 (interactive)
9394 (let ((start (point))
9395 name mid-pos end-pos)
9396 (vhdl-insert-keyword "TYPE ")
9397 (when (setq name (vhdl-template-field "name" nil t start (point)))
9398 (vhdl-insert-keyword " IS ")
9399 (let ((definition
9400 (upcase
9401 (or (vhdl-template-field
9402 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9403 ""))))
9404 (cond ((equal definition "")
3dcb36b7 9405 (delete-backward-char 4)
5eabfe72
KH
9406 (insert ";"))
9407 ((equal definition "ARRAY")
9408 (kill-word -1)
9409 (vhdl-template-array 'type t))
9410 ((equal definition "RECORD")
9411 (setq mid-pos (point-marker))
9412 (kill-word -1)
9413 (vhdl-template-record 'type name t))
9414 ((equal definition "ACCESS")
9415 (insert " ")
9416 (vhdl-template-field "type" ";"))
9417 ((equal definition "FILE")
9418 (vhdl-insert-keyword " OF ")
9419 (vhdl-template-field "type" ";"))
9420 (t (insert ";")))
9421 (when mid-pos
9422 (setq end-pos (point-marker))
9423 (goto-char mid-pos)
9424 (end-of-line))
9425 (vhdl-comment-insert-inline)
9426 (when end-pos (goto-char end-pos))))))
9427
9428(defun vhdl-template-use ()
d2ddb974
KH
9429 "Insert a use clause."
9430 (interactive)
3dcb36b7
JB
9431 (let ((start (point)))
9432 (vhdl-prepare-search-1
5eabfe72
KH
9433 (vhdl-insert-keyword "USE ")
9434 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9435 (vhdl-insert-keyword "..ALL;")
9436 (backward-char 6)
9437 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9438 (forward-char 1)
9439 (vhdl-template-field "package name")
9440 (forward-char 5))))))
9441
9442(defun vhdl-template-variable ()
d2ddb974
KH
9443 "Insert a variable declaration."
9444 (interactive)
5eabfe72 9445 (let ((start (point))
5eabfe72 9446 (in-arglist (vhdl-in-argument-list-p)))
3dcb36b7 9447 (vhdl-prepare-search-2
5eabfe72 9448 (if (or (save-excursion
3dcb36b7 9449 (and (vhdl-re-search-backward
5eabfe72
KH
9450 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9451 nil t)
9452 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9453 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9454 (vhdl-insert-keyword "VARIABLE ")
9455 (vhdl-insert-keyword "SHARED VARIABLE ")))
9456 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9457 (insert " : ")
5eabfe72
KH
9458 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9459 (vhdl-template-field "type")
d2ddb974 9460 (if in-arglist
5eabfe72
KH
9461 (progn (insert ";")
9462 (vhdl-comment-insert-inline))
d2ddb974
KH
9463 (let ((position (point)))
9464 (insert " := ")
5eabfe72
KH
9465 (unless (vhdl-template-field "[initialization]" nil t)
9466 (delete-region position (point)))
9467 (insert ";")
9468 (vhdl-comment-insert-inline))))))
d2ddb974 9469
5eabfe72 9470(defun vhdl-template-wait ()
d2ddb974
KH
9471 "Insert a wait statement."
9472 (interactive)
9473 (vhdl-insert-keyword "WAIT ")
5eabfe72
KH
9474 (unless (vhdl-template-field
9475 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9476 nil t)
9477 (delete-char -1))
9478 (insert ";"))
d2ddb974 9479
5eabfe72 9480(defun vhdl-template-when ()
d2ddb974
KH
9481 "Indent correctly if within a case statement."
9482 (interactive)
9483 (let ((position (point))
5eabfe72 9484 margin)
3dcb36b7 9485 (vhdl-prepare-search-2
5eabfe72 9486 (if (and (= (current-column) (current-indentation))
3dcb36b7 9487 (vhdl-re-search-forward "\\<end\\>" nil t)
5eabfe72
KH
9488 (looking-at "\\s-*\\<case\\>"))
9489 (progn
9490 (setq margin (current-indentation))
9491 (goto-char position)
9492 (delete-horizontal-space)
9493 (indent-to (+ margin vhdl-basic-offset)))
9494 (goto-char position)))
9495 (vhdl-insert-keyword "WHEN ")))
9496
9497(defun vhdl-template-while-loop ()
9498 "Insert a while loop."
d2ddb974 9499 (interactive)
5eabfe72
KH
9500 (let* ((margin (current-indentation))
9501 (start (point))
9502 label)
9503 (if (not (eq vhdl-optional-labels 'all))
9504 (vhdl-insert-keyword "WHILE ")
9505 (vhdl-insert-keyword ": WHILE ")
9506 (goto-char start)
9507 (setq label (vhdl-template-field "[label]" nil t))
9508 (unless label (delete-char 2))
9509 (forward-word 1)
9510 (forward-char 1))
9511 (when vhdl-conditions-in-parenthesis (insert "("))
9512 (when (vhdl-template-field "condition" nil t start (point))
9513 (when vhdl-conditions-in-parenthesis (insert ")"))
d2ddb974
KH
9514 (vhdl-insert-keyword " LOOP\n\n")
9515 (indent-to margin)
9516 (vhdl-insert-keyword "END LOOP")
5eabfe72 9517 (insert (if label (concat " " label ";") ";"))
d2ddb974 9518 (forward-line -1)
5eabfe72 9519 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 9520
5eabfe72 9521(defun vhdl-template-with ()
d2ddb974
KH
9522 "Insert a with statement (i.e. selected signal assignment)."
9523 (interactive)
3dcb36b7
JB
9524 (vhdl-prepare-search-1
9525 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9526 (equal ";" (match-string 1)))
9527 (vhdl-template-selected-signal-asst)
9528 (vhdl-insert-keyword "WITH "))))
5eabfe72
KH
9529
9530;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9531;; Special templates
9532
9533(defun vhdl-template-clocked-wait ()
9534 "Insert a wait statement for rising/falling clock edge."
9535 (interactive)
9536 (let ((start (point))
9537 clock)
9538 (vhdl-insert-keyword "WAIT UNTIL ")
9539 (when (setq clock
9540 (or (and (not (equal "" vhdl-clock-name))
9541 (progn (insert vhdl-clock-name) vhdl-clock-name))
9542 (vhdl-template-field "clock name" nil t start (point))))
9543 (insert "'event")
9544 (vhdl-insert-keyword " AND ")
9545 (insert clock)
9546 (insert
9547 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9548 (vhdl-comment-insert-inline
9549 (concat (if vhdl-clock-rising-edge "rising" "falling")
9550 " clock edge")))))
9551
9552(defun vhdl-template-seq-process (clock reset)
9553 "Insert a template for the body of a sequential process."
9554 (let ((margin (current-indentation))
9555 position)
d2ddb974 9556 (vhdl-insert-keyword "IF ")
5eabfe72
KH
9557 (when (eq vhdl-reset-kind 'async)
9558 (insert reset " = "
9559 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9560 (vhdl-insert-keyword " THEN")
9561 (vhdl-comment-insert-inline
9562 (concat "asynchronous reset (active "
9563 (if vhdl-reset-active-high "high" "low") ")"))
9564 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9565 (setq position (point))
9566 (insert "\n") (indent-to margin)
9567 (vhdl-insert-keyword "ELSIF "))
9568 (if (eq vhdl-clock-edge-condition 'function)
9569 (insert (if vhdl-clock-rising-edge "rising" "falling")
9570 "_edge(" clock ")")
9571 (insert clock "'event")
9572 (vhdl-insert-keyword " AND ")
9573 (insert clock " = "
9574 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9575 (vhdl-insert-keyword " THEN")
9576 (vhdl-comment-insert-inline
9577 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9578 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9579 (when (eq vhdl-reset-kind 'sync)
9580 (vhdl-insert-keyword "IF ")
9581 (setq reset (or (and (not (equal "" vhdl-reset-name))
9582 (progn (insert vhdl-reset-name) vhdl-reset-name))
9583 (vhdl-template-field "reset name") "<reset>"))
9584 (insert " = "
9585 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9586 (vhdl-insert-keyword " THEN")
9587 (vhdl-comment-insert-inline
9588 (concat "synchronous reset (active "
9589 (if vhdl-reset-active-high "high" "low") ")"))
9590 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9591 (setq position (point))
9592 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9593 (vhdl-insert-keyword "ELSE")
9594 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9595 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9596 (vhdl-insert-keyword "END IF;"))
9597 (when (eq vhdl-reset-kind 'none)
9598 (setq position (point)))
9599 (insert "\n") (indent-to margin)
d2ddb974 9600 (vhdl-insert-keyword "END IF;")
5eabfe72
KH
9601 (goto-char position)
9602 reset))
d2ddb974 9603
5eabfe72
KH
9604(defun vhdl-template-standard-package (library package)
9605 "Insert specification of a standard package. Include a library
9606specification, if not already there."
3dcb36b7
JB
9607 (let ((margin (current-indentation)))
9608 (unless (equal library "std")
9609 (unless (or (save-excursion
9610 (vhdl-prepare-search-1
9611 (and (not (bobp))
9612 (re-search-backward
9613 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9614 library "\\|end\\)\\>") nil t)
9615 (match-string 2))))
9616 (equal (downcase library) "work"))
9617 (vhdl-insert-keyword "LIBRARY ")
9618 (insert library ";\n")
9619 (indent-to margin))
9620 (vhdl-insert-keyword "USE ")
9621 (insert library "." package)
9622 (vhdl-insert-keyword ".ALL;"))))
d2ddb974 9623
5eabfe72
KH
9624(defun vhdl-template-package-math-complex ()
9625 "Insert specification of `math_complex' package."
d2ddb974 9626 (interactive)
5eabfe72 9627 (vhdl-template-standard-package "ieee" "math_complex"))
d2ddb974 9628
5eabfe72
KH
9629(defun vhdl-template-package-math-real ()
9630 "Insert specification of `math_real' package."
d2ddb974 9631 (interactive)
5eabfe72 9632 (vhdl-template-standard-package "ieee" "math_real"))
d2ddb974 9633
5eabfe72
KH
9634(defun vhdl-template-package-numeric-bit ()
9635 "Insert specification of `numeric_bit' package."
d2ddb974 9636 (interactive)
5eabfe72 9637 (vhdl-template-standard-package "ieee" "numeric_bit"))
d2ddb974 9638
5eabfe72
KH
9639(defun vhdl-template-package-numeric-std ()
9640 "Insert specification of `numeric_std' package."
d2ddb974 9641 (interactive)
5eabfe72 9642 (vhdl-template-standard-package "ieee" "numeric_std"))
d2ddb974 9643
5eabfe72
KH
9644(defun vhdl-template-package-std-logic-1164 ()
9645 "Insert specification of `std_logic_1164' package."
9646 (interactive)
9647 (vhdl-template-standard-package "ieee" "std_logic_1164"))
d2ddb974 9648
5eabfe72
KH
9649(defun vhdl-template-package-std-logic-arith ()
9650 "Insert specification of `std_logic_arith' package."
9651 (interactive)
9652 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9653
9654(defun vhdl-template-package-std-logic-misc ()
9655 "Insert specification of `std_logic_misc' package."
9656 (interactive)
9657 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9658
9659(defun vhdl-template-package-std-logic-signed ()
9660 "Insert specification of `std_logic_signed' package."
9661 (interactive)
9662 (vhdl-template-standard-package "ieee" "std_logic_signed"))
d2ddb974 9663
5eabfe72
KH
9664(defun vhdl-template-package-std-logic-textio ()
9665 "Insert specification of `std_logic_textio' package."
9666 (interactive)
9667 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9668
9669(defun vhdl-template-package-std-logic-unsigned ()
9670 "Insert specification of `std_logic_unsigned' package."
9671 (interactive)
9672 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9673
9674(defun vhdl-template-package-textio ()
9675 "Insert specification of `textio' package."
9676 (interactive)
9677 (vhdl-template-standard-package "std" "textio"))
9678
9679(defun vhdl-template-directive (directive)
9680 "Insert directive."
9681 (unless (= (current-indentation) (current-column))
9682 (delete-horizontal-space)
9683 (insert " "))
9684 (insert "-- pragma " directive))
9685
9686(defun vhdl-template-directive-translate-on ()
9687 "Insert directive 'translate_on'."
9688 (interactive)
9689 (vhdl-template-directive "translate_on"))
9690
9691(defun vhdl-template-directive-translate-off ()
9692 "Insert directive 'translate_off'."
9693 (interactive)
9694 (vhdl-template-directive "translate_off"))
9695
9696(defun vhdl-template-directive-synthesis-on ()
9697 "Insert directive 'synthesis_on'."
9698 (interactive)
9699 (vhdl-template-directive "synthesis_on"))
9700
9701(defun vhdl-template-directive-synthesis-off ()
9702 "Insert directive 'synthesis_off'."
9703 (interactive)
9704 (vhdl-template-directive "synthesis_off"))
9705
3dcb36b7
JB
9706;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9707;; Header and footer templates
9708
9709(defun vhdl-template-header (&optional file-title)
9710 "Insert a VHDL file header."
9711 (interactive)
9712 (unless (equal vhdl-file-header "")
9713 (let (pos)
9714 (save-excursion
9715 (goto-char (point-min))
9716 (vhdl-insert-string-or-file vhdl-file-header)
9717 (setq pos (point-marker)))
9718 (vhdl-template-replace-header-keywords
9719 (point-min-marker) pos file-title))))
9720
9721(defun vhdl-template-footer ()
9722 "Insert a VHDL file footer."
9723 (interactive)
9724 (unless (equal vhdl-file-footer "")
9725 (let (pos)
9726 (save-excursion
9727 (goto-char (point-max))
9728 (setq pos (point-marker))
9729 (vhdl-insert-string-or-file vhdl-file-footer)
9730 (unless (= (preceding-char) ?\n)
9731 (insert "\n")))
9732 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9733
9734(defun vhdl-template-replace-header-keywords (beg end &optional file-title
9735 is-model)
9736 "Replace keywords in header and footer."
9737 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9738 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9739 pos)
9740 (vhdl-prepare-search-2
9741 (save-excursion
9742 (goto-char beg)
9743 (while (search-forward "<projectdesc>" end t)
9744 (replace-match project-desc t t))
9745 (goto-char beg)
9746 (while (search-forward "<filename>" end t)
9747 (replace-match (buffer-name) t t))
9748 (goto-char beg)
9749 (while (search-forward "<copyright>" end t)
9750 (replace-match vhdl-copyright-string t t))
9751 (goto-char beg)
9752 (while (search-forward "<author>" end t)
9753 (replace-match "" t t)
9754 (insert (user-full-name))
9755 (when user-mail-address (insert " <" user-mail-address ">")))
9756 (goto-char beg)
9757 (while (search-forward "<login>" end t)
9758 (replace-match (user-login-name) t t))
9759 (goto-char beg)
9760 (while (search-forward "<project>" end t)
9761 (replace-match project-title t t))
9762 (goto-char beg)
9763 (while (search-forward "<company>" end t)
9764 (replace-match vhdl-company-name t t))
9765 (goto-char beg)
9766 (while (search-forward "<platform>" end t)
9767 (replace-match vhdl-platform-spec t t))
9768 (goto-char beg)
9769 (while (search-forward "<standard>" end t)
9770 (replace-match
9771 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9772 ((vhdl-standard-p '93) "'93"))
9773 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9774 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9775 (goto-char beg)
9776 ;; Replace <RCS> with $, so that RCS for the source is
9777 ;; not over-enthusiastic with replacements
9778 (while (search-forward "<RCS>" end t)
9779 (replace-match "$" nil t))
9780 (goto-char beg)
9781 (while (search-forward "<date>" end t)
9782 (replace-match "" t t)
9783 (vhdl-template-insert-date))
9784 (goto-char beg)
9785 (while (search-forward "<year>" end t)
9786 (replace-match (format-time-string "%Y" nil) t t))
9787 (goto-char beg)
9788 (when file-title
9789 (while (search-forward "<title string>" end t)
9790 (replace-match file-title t t))
9791 (goto-char beg))
9792 (let (string)
9793 (while
9794 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9795 (setq string (read-string (concat (match-string 1) ": ")))
9796 (replace-match string t t)))
9797 (goto-char beg)
9798 (when (and (not is-model) (search-forward "<cursor>" end t))
9799 (replace-match "" t t)
9800 (setq pos (point))))
9801 (when pos (goto-char pos))
9802 (unless is-model
9803 (when (or (not project-title) (equal project-title ""))
9804 (message "You can specify a project title in user option `vhdl-project-alist'"))
9805 (when (or (not project-desc) (equal project-desc ""))
9806 (message "You can specify a project description in user option `vhdl-project-alist'"))
9807 (when (equal vhdl-platform-spec "")
9808 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9809 (when (equal vhdl-company-name "")
9810 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9811
5eabfe72
KH
9812;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9813;; Comment templates and functions
9814
9815(defun vhdl-comment-indent ()
9816 "Indent comments."
9817 (let* ((position (point))
9818 (col
9819 (progn
9820 (forward-line -1)
9821 (if (re-search-forward "--" position t)
9822 (- (current-column) 2) ; existing comment at bol stays there
9823 (goto-char position)
9824 (skip-chars-backward " \t")
9825 (max comment-column ; else indent to comment column
9826 (1+ (current-column))))))) ; except leave at least one space
9827 (goto-char position)
9828 col))
9829
9830(defun vhdl-comment-insert ()
d2ddb974 9831 "Start a comment at the end of the line.
5eabfe72
KH
9832If on line with code, indent at least `comment-column'.
9833If starting after end-comment-column, start a new line."
d2ddb974 9834 (interactive)
5eabfe72
KH
9835 (when (> (current-column) end-comment-column) (newline-and-indent))
9836 (if (or (looking-at "\\s-*$") ; end of line
d2ddb974
KH
9837 (and (not unread-command-events) ; called with key binding or menu
9838 (not (end-of-line))))
5eabfe72
KH
9839 (let (margin)
9840 (while (= (preceding-char) ?-) (delete-char -1))
d2ddb974 9841 (setq margin (current-column))
5eabfe72
KH
9842 (delete-horizontal-space)
9843 (if (bolp)
9844 (progn (indent-to margin) (insert "--"))
d2ddb974 9845 (insert " ")
5eabfe72
KH
9846 (indent-to comment-column)
9847 (insert "--"))
d2ddb974 9848 (if (not unread-command-events) (insert " ")))
5eabfe72 9849 ;; else code following current point implies commenting out code
d2ddb974
KH
9850 (let (next-input code)
9851 (while (= (preceding-char) ?-) (delete-char -2))
9852 (while (= (setq next-input (read-char)) 13) ; CR
5eabfe72 9853 (insert "--") ; or have a space after it?
d2ddb974
KH
9854 (forward-char -2)
9855 (forward-line 1)
9856 (message "Enter CR if commenting out a line of code.")
5eabfe72 9857 (setq code t))
3dcb36b7 9858 (unless code
5eabfe72 9859 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
d2ddb974 9860 (setq unread-command-events
5eabfe72 9861 (list (vhdl-character-to-event next-input)))))) ; pushback the char
d2ddb974 9862
5eabfe72 9863(defun vhdl-comment-display (&optional line-exists)
d2ddb974
KH
9864 "Add 2 comment lines at the current indent, making a display comment."
9865 (interactive)
5eabfe72 9866 (let ((margin (current-indentation)))
3dcb36b7 9867 (unless line-exists (vhdl-comment-display-line))
5eabfe72
KH
9868 (insert "\n") (indent-to margin)
9869 (insert "\n") (indent-to margin)
9870 (vhdl-comment-display-line)
9871 (end-of-line -0)
9872 (insert "-- ")))
9873
9874(defun vhdl-comment-display-line ()
d2ddb974
KH
9875 "Displays one line of dashes."
9876 (interactive)
9877 (while (= (preceding-char) ?-) (delete-char -2))
9878 (let* ((col (current-column))
9879 (len (- end-comment-column col)))
5eabfe72 9880 (insert-char ?- len)))
d2ddb974 9881
5eabfe72
KH
9882(defun vhdl-comment-append-inline ()
9883 "Append empty inline comment to current line."
9884 (interactive)
9885 (end-of-line)
9886 (delete-horizontal-space)
9887 (insert " ")
9888 (indent-to comment-column)
9889 (insert "-- "))
9890
9891(defun vhdl-comment-insert-inline (&optional string always-insert)
9892 "Insert inline comment."
9893 (when (or (and string (or vhdl-self-insert-comments always-insert))
9894 (and (not string) vhdl-prompt-for-comments))
9895 (let ((position (point)))
9896 (insert " ")
9897 (indent-to comment-column)
9898 (insert "-- ")
3dcb36b7
JB
9899 (if (not (or (and string (progn (insert string) t))
9900 (vhdl-template-field "[comment]" nil t)))
9901 (delete-region position (point))
9902 (while (= (preceding-char) ? ) (delete-backward-char 1))
9903; (when (> (current-column) end-comment-column)
9904; (setq position (point-marker))
9905; (re-search-backward "-- ")
9906; (insert "\n")
9907; (indent-to comment-column)
9908; (goto-char position))
9909 ))))
5eabfe72
KH
9910
9911(defun vhdl-comment-block ()
9912 "Insert comment for code block."
9913 (when vhdl-prompt-for-comments
3dcb36b7
JB
9914 (let ((final-pos (point-marker)))
9915 (vhdl-prepare-search-2
5eabfe72 9916 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
3dcb36b7 9917 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
5eabfe72
KH
9918 (let (margin)
9919 (back-to-indentation)
9920 (setq margin (current-column))
9921 (end-of-line -0)
9922 (if (bobp)
9923 (progn (insert "\n") (forward-line -1))
9924 (insert "\n"))
9925 (indent-to margin)
9926 (insert "-- purpose: ")
9927 (unless (vhdl-template-field "[description]" nil t)
9928 (vhdl-line-kill-entire)))))
9929 (goto-char final-pos))))
d2ddb974
KH
9930
9931(defun vhdl-comment-uncomment-region (beg end &optional arg)
5eabfe72 9932 "Comment out region if not commented out, uncomment otherwise."
d2ddb974 9933 (interactive "r\nP")
5eabfe72
KH
9934 (save-excursion
9935 (goto-char (1- end))
9936 (end-of-line)
9937 (setq end (point-marker))
9938 (goto-char beg)
9939 (beginning-of-line)
9940 (setq beg (point))
9941 (if (looking-at comment-start)
3dcb36b7 9942 (comment-region beg end '(4))
5eabfe72
KH
9943 (comment-region beg end))))
9944
9945(defun vhdl-comment-uncomment-line (&optional arg)
9946 "Comment out line if not commented out, uncomment otherwise."
d2ddb974 9947 (interactive "p")
5eabfe72
KH
9948 (save-excursion
9949 (beginning-of-line)
9950 (let ((position (point)))
9951 (forward-line (or arg 1))
9952 (vhdl-comment-uncomment-region position (point)))))
d2ddb974 9953
5eabfe72
KH
9954(defun vhdl-comment-kill-region (beg end)
9955 "Kill comments in region."
9956 (interactive "r")
9957 (save-excursion
9958 (goto-char end)
9959 (setq end (point-marker))
9960 (goto-char beg)
9961 (beginning-of-line)
9962 (while (< (point) end)
9963 (if (looking-at "^\\(\\s-*--.*\n\\)")
9964 (progn (delete-region (match-beginning 1) (match-end 1)))
9965 (beginning-of-line 2)))))
9966
9967(defun vhdl-comment-kill-inline-region (beg end)
9968 "Kill inline comments in region."
9969 (interactive "r")
9970 (save-excursion
9971 (goto-char end)
9972 (setq end (point-marker))
9973 (goto-char beg)
9974 (beginning-of-line)
9975 (while (< (point) end)
9976 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
9977 (delete-region (match-beginning 1) (match-end 1)))
9978 (beginning-of-line 2))))
9979
9980;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9981;; Subtemplates
9982
9983(defun vhdl-template-begin-end (construct name margin &optional empty-lines)
d2ddb974
KH
9984 "Insert a begin ... end pair with optional name after the end.
9985Point is left between them."
5eabfe72 9986 (let (position)
5eabfe72 9987 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
9988 (indent-to margin)
9989 (vhdl-insert-keyword "BEGIN")
5eabfe72
KH
9990 (when (and (or construct name) vhdl-self-insert-comments)
9991 (insert " --")
9992 (when construct (insert " ") (vhdl-insert-keyword construct))
9993 (when name (insert " " name)))
d2ddb974 9994 (insert "\n")
5eabfe72 9995 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974 9996 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9997 (setq position (point))
9998 (insert "\n")
9999 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
10000 (indent-to margin)
10001 (vhdl-insert-keyword "END")
5eabfe72
KH
10002 (when construct (insert " ") (vhdl-insert-keyword construct))
10003 (insert (if name (concat " " name) "") ";")
10004 (goto-char position)))
d2ddb974 10005
5eabfe72 10006(defun vhdl-template-argument-list (&optional is-function)
d2ddb974
KH
10007 "Read from user a procedure or function argument list."
10008 (insert " (")
d2ddb974 10009 (let ((margin (current-column))
5eabfe72
KH
10010 (start (point))
10011 (end-pos (point))
10012 not-empty interface semicolon-pos)
3dcb36b7 10013 (unless vhdl-argument-list-indent
5eabfe72
KH
10014 (setq margin (+ (current-indentation) vhdl-basic-offset))
10015 (insert "\n")
10016 (indent-to margin))
10017 (setq interface (vhdl-template-field
10018 (concat "[CONSTANT | SIGNAL"
10019 (unless is-function " | VARIABLE") "]") " " t))
10020 (while (vhdl-template-field "[names]" nil t)
10021 (setq not-empty t)
10022 (insert " : ")
3dcb36b7 10023 (unless is-function
5eabfe72
KH
10024 (if (and interface (equal (upcase interface) "CONSTANT"))
10025 (vhdl-insert-keyword "IN ")
10026 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10027 (vhdl-template-field "type")
10028 (setq semicolon-pos (point))
10029 (insert ";")
10030 (vhdl-comment-insert-inline)
10031 (setq end-pos (point))
10032 (insert "\n")
10033 (indent-to margin)
10034 (setq interface (vhdl-template-field
10035 (concat "[CONSTANT | SIGNAL"
10036 (unless is-function " | VARIABLE") "]") " " t)))
10037 (delete-region end-pos (point))
10038 (when semicolon-pos (goto-char semicolon-pos))
10039 (if not-empty
10040 (progn (delete-char 1) (insert ")"))
3dcb36b7 10041 (delete-backward-char 2))))
5eabfe72
KH
10042
10043(defun vhdl-template-generic-list (optional &optional no-value)
d2ddb974 10044 "Read from user a generic spec argument list."
5eabfe72 10045 (let (margin
d2ddb974 10046 (start (point)))
5eabfe72
KH
10047 (vhdl-insert-keyword "GENERIC (")
10048 (setq margin (current-column))
3dcb36b7 10049 (unless vhdl-argument-list-indent
5eabfe72
KH
10050 (let ((position (point)))
10051 (back-to-indentation)
10052 (setq margin (+ (current-column) vhdl-basic-offset))
10053 (goto-char position)
10054 (insert "\n")
10055 (indent-to margin)))
10056 (let ((vhdl-generics (vhdl-template-field
10057 (concat (and optional "[") "name"
10058 (and no-value "s") (and optional "]"))
10059 nil optional)))
10060 (if (not vhdl-generics)
d2ddb974 10061 (if optional
5eabfe72 10062 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10063 (unless vhdl-argument-list-indent
5eabfe72
KH
10064 (vhdl-line-kill-entire) (end-of-line -0)))
10065 (vhdl-template-undo start (point))
d2ddb974
KH
10066 nil )
10067 (insert " : ")
5eabfe72
KH
10068 (let (semicolon-pos end-pos)
10069 (while vhdl-generics
10070 (vhdl-template-field "type")
10071 (if no-value
10072 (progn (setq semicolon-pos (point))
10073 (insert ";"))
10074 (insert " := ")
10075 (unless (vhdl-template-field "[value]" nil t)
10076 (delete-char -4))
10077 (setq semicolon-pos (point))
10078 (insert ";"))
10079 (vhdl-comment-insert-inline)
10080 (setq end-pos (point))
10081 (insert "\n")
10082 (indent-to margin)
10083 (setq vhdl-generics (vhdl-template-field
10084 (concat "[name" (and no-value "s") "]")
10085 " : " t)))
10086 (delete-region end-pos (point))
10087 (goto-char semicolon-pos)
10088 (insert ")")
10089 (end-of-line)
3dcb36b7 10090 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
10091 t)))))
10092
10093(defun vhdl-template-port-list (optional)
10094 "Read from user a port spec argument list."
10095 (let ((start (point))
10096 margin vhdl-ports object)
10097 (vhdl-insert-keyword "PORT (")
10098 (setq margin (current-column))
3dcb36b7 10099 (unless vhdl-argument-list-indent
5eabfe72
KH
10100 (let ((position (point)))
10101 (back-to-indentation)
10102 (setq margin (+ (current-column) vhdl-basic-offset))
10103 (goto-char position)
10104 (insert "\n")
10105 (indent-to margin)))
10106 (when (vhdl-standard-p 'ams)
10107 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10108 " " t)))
10109 (setq vhdl-ports (vhdl-template-field
10110 (concat (and optional "[") "names" (and optional "]"))
10111 nil optional))
10112 (if (not vhdl-ports)
10113 (if optional
10114 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10115 (unless vhdl-argument-list-indent
5eabfe72
KH
10116 (vhdl-line-kill-entire) (end-of-line -0)))
10117 (vhdl-template-undo start (point))
10118 nil)
10119 (insert " : ")
10120 (let (semicolon-pos end-pos)
10121 (while vhdl-ports
10122 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10123 (vhdl-template-field "IN | OUT | INOUT" " "))
10124 ((equal "QUANTITY" (upcase object))
10125 (vhdl-template-field "[IN | OUT]" " " t)))
10126 (vhdl-template-field
10127 (if (and object (equal "TERMINAL" (upcase object)))
10128 "nature" "type"))
10129 (setq semicolon-pos (point))
10130 (insert ";")
10131 (vhdl-comment-insert-inline)
10132 (setq end-pos (point))
10133 (insert "\n")
10134 (indent-to margin)
10135 (when (vhdl-standard-p 'ams)
10136 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10137 " " t)))
10138 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10139 (delete-region end-pos (point))
10140 (goto-char semicolon-pos)
10141 (insert ")")
10142 (end-of-line)
3dcb36b7 10143 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
5eabfe72
KH
10144 t))))
10145
10146(defun vhdl-template-generate-body (margin label)
10147 "Insert body for generate template."
10148 (vhdl-insert-keyword " GENERATE")
3dcb36b7
JB
10149; (if (not (vhdl-standard-p '87))
10150; (vhdl-template-begin-end "GENERATE" label margin)
10151 (insert "\n\n")
10152 (indent-to margin)
10153 (vhdl-insert-keyword "END GENERATE ")
10154 (insert label ";")
10155 (end-of-line 0)
10156 (indent-to (+ margin vhdl-basic-offset)))
5eabfe72
KH
10157
10158(defun vhdl-template-insert-date ()
d2ddb974
KH
10159 "Insert date in appropriate format."
10160 (interactive)
5eabfe72
KH
10161 (insert
10162 (cond
3dcb36b7 10163 ;; 'american, 'european, 'scientific kept for backward compatibility
5eabfe72
KH
10164 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10165 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10166 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10167 (t (format-time-string vhdl-date-format nil)))))
10168
10169;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10170;; Help functions
10171
10172(defun vhdl-electric-space (count)
10173 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10174if in comment and past end-comment-column."
10175 (interactive "p")
10176 (cond ((vhdl-in-comment-p)
10177 (self-insert-command count)
10178 (cond ((>= (current-column) (+ 2 end-comment-column))
3dcb36b7
JB
10179 (backward-char 1)
10180 (skip-chars-backward "^ \t\n")
5eabfe72 10181 (indent-new-comment-line)
3dcb36b7 10182 (skip-chars-forward "^ \t\n")
5eabfe72
KH
10183 (forward-char 1))
10184 ((>= (current-column) end-comment-column)
10185 (indent-new-comment-line))
10186 (t nil)))
10187 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10188 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
3dcb36b7
JB
10189 (vhdl-prepare-search-1
10190 (or (expand-abbrev) (vhdl-fix-case-word -1)))
5eabfe72
KH
10191 (self-insert-command count))
10192 (t (self-insert-command count))))
10193
10194(defun vhdl-template-field (prompt &optional follow-string optional
10195 begin end is-string default)
10196 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10197If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10198an empty string is inserted, return nil and call `vhdl-template-undo' for
10199the region between BEGIN and END. IS-STRING indicates whether a string
10200with double-quotes is to be inserted. DEFAULT specifies a default string."
10201 (let ((position (point))
10202 string)
10203 (insert "<" prompt ">")
10204 (setq string
10205 (condition-case ()
10206 (read-from-minibuffer (concat prompt ": ")
10207 (or (and is-string '("\"\"" . 2)) default)
10208 vhdl-minibuffer-local-map)
10209 (quit (if (and optional begin end)
10210 (progn (beep) "")
10211 (keyboard-quit)))))
10212 (when (or (not (equal string "")) optional)
10213 (delete-region position (point)))
10214 (when (and (equal string "") optional begin end)
10215 (vhdl-template-undo begin end)
10216 (message "Template aborted"))
3dcb36b7 10217 (unless (equal string "")
5eabfe72
KH
10218 (insert string)
10219 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
3dcb36b7
JB
10220 vhdl-keywords-regexp)
10221 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10222 vhdl-types-regexp)
10223 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10224 (concat "'" vhdl-attributes-regexp))
10225 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10226 vhdl-enum-values-regexp))
5eabfe72
KH
10227 (when (or (not (equal string "")) (not optional))
10228 (insert (or follow-string "")))
10229 (if (equal string "") nil string)))
10230
10231(defun vhdl-decision-query (string prompt &optional optional)
10232 "Query a decision from the user."
10233 (let ((start (point)))
10234 (when string (vhdl-insert-keyword (concat string " ")))
10235 (message prompt)
10236 (let ((char (read-char)))
10237 (delete-region start (point))
10238 (if (and optional (eq char ?\r))
10239 (progn (insert " ")
10240 (unexpand-abbrev)
3dcb36b7 10241 (throw 'abort "ERROR: Template aborted"))
5eabfe72 10242 char))))
d2ddb974
KH
10243
10244(defun vhdl-insert-keyword (keyword)
5eabfe72
KH
10245 "Insert KEYWORD and adjust case."
10246 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
d2ddb974
KH
10247
10248(defun vhdl-case-keyword (keyword)
5eabfe72
KH
10249 "Adjust case of KEYWORD."
10250 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
d2ddb974
KH
10251
10252(defun vhdl-case-word (num)
5eabfe72
KH
10253 "Adjust case or following NUM words."
10254 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10255
10256(defun vhdl-minibuffer-tab (&optional prefix-arg)
10257 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7 10258else insert tab (used for word completion in VHDL minibuffer)."
5eabfe72 10259 (interactive "P")
3dcb36b7
JB
10260 (cond
10261 ;; expand word
10262 ((= (char-syntax (preceding-char)) ?w)
10263 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10264 (case-replace nil)
10265 (hippie-expand-only-buffers
10266 (or (and (boundp 'hippie-expand-only-buffers)
10267 hippie-expand-only-buffers)
10268 '(vhdl-mode))))
10269 (vhdl-expand-abbrev prefix-arg)))
10270 ;; expand parenthesis
10271 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10272 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10273 (case-replace nil))
10274 (vhdl-expand-paren prefix-arg)))
10275 ;; insert tab
10276 (t (insert-tab))))
5eabfe72
KH
10277
10278(defun vhdl-template-search-prompt ()
10279 "Search for left out template prompts and query again."
10280 (interactive)
3dcb36b7
JB
10281 (vhdl-prepare-search-2
10282 (when (or (re-search-forward
10283 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10284 (re-search-backward
10285 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10286 (let ((string (match-string 1)))
10287 (replace-match "")
10288 (vhdl-template-field string)))))
5eabfe72
KH
10289
10290(defun vhdl-template-undo (begin end)
10291 "Undo aborted template by deleting region and unexpanding the keyword."
10292 (cond (vhdl-template-invoked-by-hook
10293 (goto-char end)
10294 (insert " ")
10295 (delete-region begin end)
10296 (unexpand-abbrev))
10297 (t (delete-region begin end))))
10298
10299(defun vhdl-insert-string-or-file (string)
10300 "Insert STRING or file contents if STRING is an existing file name."
10301 (unless (equal string "")
3dcb36b7
JB
10302 (let ((file-name
10303 (progn (string-match "^\\([^\n]+\\)" string)
10304 (vhdl-resolve-env-variable (match-string 1 string)))))
10305 (if (file-exists-p file-name)
10306 (forward-char (cadr (insert-file-contents file-name)))
10307 (insert string)))))
10308
10309(defun vhdl-beginning-of-block ()
10310 "Move cursor to the beginning of the enclosing block."
10311 (let (pos)
10312 (save-excursion
10313 (beginning-of-line)
10314 ;; search backward for block beginning or end
10315 (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))
10316 ;; not consider subprogram declarations
10317 (or (and (match-string 5)
10318 (save-match-data
10319 (save-excursion
10320 (goto-char (match-end 5))
10321 (forward-word 1) (forward-sexp)
10322 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10323 (match-string 1)))
10324 ;; not consider configuration specifications
10325 (and (match-string 6)
10326 (save-match-data
10327 (save-excursion
10328 (vhdl-end-of-block)
10329 (beginning-of-line)
10330 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10331 (match-string 2))
10332 ;; skip subblock if block end found
10333 (vhdl-beginning-of-block)))
10334 (when pos (goto-char pos))))
10335
10336(defun vhdl-end-of-block ()
10337 "Move cursor to the end of the enclosing block."
10338 (let (pos)
10339 (save-excursion
10340 (end-of-line)
10341 ;; search forward for block beginning or end
10342 (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))
10343 ;; not consider subprogram declarations
10344 (or (and (match-string 5)
10345 (save-match-data
10346 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10347 (match-string 1)))
10348 ;; not consider configuration specifications
10349 (and (match-string 6)
10350 (save-match-data
10351 (save-excursion
10352 (vhdl-end-of-block)
10353 (beginning-of-line)
10354 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10355 (not (match-string 2)))
10356 ;; skip subblock if block beginning found
10357 (vhdl-end-of-block)))
10358 (when pos (goto-char pos))))
5eabfe72
KH
10359
10360(defun vhdl-sequential-statement-p ()
10361 "Check if point is within sequential statement part."
3dcb36b7
JB
10362 (let ((start (point)))
10363 (save-excursion
10364 (vhdl-prepare-search-2
10365 ;; is sequential statement if ...
10366 (and (re-search-backward "^\\s-*begin\\>" nil t)
10367 ;; ... point is between "begin" and "end" of ...
10368 (progn (vhdl-end-of-block)
10369 (< start (point)))
10370 ;; ... a sequential block
10371 (progn (vhdl-beginning-of-block)
10372 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
5eabfe72
KH
10373
10374(defun vhdl-in-argument-list-p ()
10375 "Check if within an argument list."
10376 (save-excursion
3dcb36b7
JB
10377 (vhdl-prepare-search-2
10378 (or (string-match "arglist"
10379 (format "%s" (caar (vhdl-get-syntactic-context))))
10380 (progn (beginning-of-line)
10381 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
5eabfe72
KH
10382
10383;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10384;; Abbrev hooks
10385
10386(defun vhdl-hooked-abbrev (func)
10387 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10388but not if inside a comment or quote)."
3dcb36b7 10389 (if (or (vhdl-in-literal)
5eabfe72
KH
10390 (save-excursion
10391 (forward-word -1)
10392 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10393 (progn
10394 (insert " ")
10395 (unexpand-abbrev)
10396 (delete-char -1))
10397 (if (not vhdl-electric-mode)
10398 (progn
10399 (insert " ")
10400 (unexpand-abbrev)
10401 (backward-word 1)
10402 (vhdl-case-word 1)
10403 (delete-char 1))
10404 (let ((invoke-char last-command-char)
10405 (abbrev-mode -1)
10406 (vhdl-template-invoked-by-hook t))
10407 (let ((caught (catch 'abort
10408 (funcall func))))
10409 (when (stringp caught) (message caught)))
10410 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10411 ;; delete CR which is still in event queue
4bcb9c95 10412 (if (fboundp 'enqueue-eval-event)
5eabfe72
KH
10413 (enqueue-eval-event 'delete-char -1)
10414 (setq unread-command-events ; push back a delete char
10415 (list (vhdl-character-to-event ?\177))))))))
10416
10417(defun vhdl-template-alias-hook ()
10418 (vhdl-hooked-abbrev 'vhdl-template-alias))
10419(defun vhdl-template-architecture-hook ()
10420 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10421(defun vhdl-template-assert-hook ()
10422 (vhdl-hooked-abbrev 'vhdl-template-assert))
10423(defun vhdl-template-attribute-hook ()
10424 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10425(defun vhdl-template-block-hook ()
10426 (vhdl-hooked-abbrev 'vhdl-template-block))
10427(defun vhdl-template-break-hook ()
10428 (vhdl-hooked-abbrev 'vhdl-template-break))
10429(defun vhdl-template-case-hook ()
10430 (vhdl-hooked-abbrev 'vhdl-template-case))
10431(defun vhdl-template-component-hook ()
10432 (vhdl-hooked-abbrev 'vhdl-template-component))
10433(defun vhdl-template-instance-hook ()
10434 (vhdl-hooked-abbrev 'vhdl-template-instance))
10435(defun vhdl-template-conditional-signal-asst-hook ()
10436 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10437(defun vhdl-template-configuration-hook ()
10438 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10439(defun vhdl-template-constant-hook ()
10440 (vhdl-hooked-abbrev 'vhdl-template-constant))
10441(defun vhdl-template-disconnect-hook ()
10442 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10443(defun vhdl-template-display-comment-hook ()
10444 (vhdl-hooked-abbrev 'vhdl-comment-display))
10445(defun vhdl-template-else-hook ()
10446 (vhdl-hooked-abbrev 'vhdl-template-else))
10447(defun vhdl-template-elsif-hook ()
10448 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10449(defun vhdl-template-entity-hook ()
10450 (vhdl-hooked-abbrev 'vhdl-template-entity))
10451(defun vhdl-template-exit-hook ()
10452 (vhdl-hooked-abbrev 'vhdl-template-exit))
10453(defun vhdl-template-file-hook ()
10454 (vhdl-hooked-abbrev 'vhdl-template-file))
10455(defun vhdl-template-for-hook ()
10456 (vhdl-hooked-abbrev 'vhdl-template-for))
10457(defun vhdl-template-function-hook ()
10458 (vhdl-hooked-abbrev 'vhdl-template-function))
10459(defun vhdl-template-generic-hook ()
10460 (vhdl-hooked-abbrev 'vhdl-template-generic))
10461(defun vhdl-template-group-hook ()
10462 (vhdl-hooked-abbrev 'vhdl-template-group))
10463(defun vhdl-template-library-hook ()
10464 (vhdl-hooked-abbrev 'vhdl-template-library))
10465(defun vhdl-template-limit-hook ()
10466 (vhdl-hooked-abbrev 'vhdl-template-limit))
10467(defun vhdl-template-if-hook ()
10468 (vhdl-hooked-abbrev 'vhdl-template-if))
10469(defun vhdl-template-bare-loop-hook ()
10470 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10471(defun vhdl-template-map-hook ()
10472 (vhdl-hooked-abbrev 'vhdl-template-map))
10473(defun vhdl-template-nature-hook ()
10474 (vhdl-hooked-abbrev 'vhdl-template-nature))
10475(defun vhdl-template-next-hook ()
10476 (vhdl-hooked-abbrev 'vhdl-template-next))
3dcb36b7
JB
10477(defun vhdl-template-others-hook ()
10478 (vhdl-hooked-abbrev 'vhdl-template-others))
5eabfe72
KH
10479(defun vhdl-template-package-hook ()
10480 (vhdl-hooked-abbrev 'vhdl-template-package))
10481(defun vhdl-template-port-hook ()
10482 (vhdl-hooked-abbrev 'vhdl-template-port))
10483(defun vhdl-template-procedural-hook ()
10484 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10485(defun vhdl-template-procedure-hook ()
10486 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10487(defun vhdl-template-process-hook ()
10488 (vhdl-hooked-abbrev 'vhdl-template-process))
10489(defun vhdl-template-quantity-hook ()
10490 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10491(defun vhdl-template-report-hook ()
10492 (vhdl-hooked-abbrev 'vhdl-template-report))
10493(defun vhdl-template-return-hook ()
10494 (vhdl-hooked-abbrev 'vhdl-template-return))
10495(defun vhdl-template-selected-signal-asst-hook ()
10496 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10497(defun vhdl-template-signal-hook ()
10498 (vhdl-hooked-abbrev 'vhdl-template-signal))
10499(defun vhdl-template-subnature-hook ()
10500 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10501(defun vhdl-template-subtype-hook ()
10502 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10503(defun vhdl-template-terminal-hook ()
10504 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10505(defun vhdl-template-type-hook ()
10506 (vhdl-hooked-abbrev 'vhdl-template-type))
10507(defun vhdl-template-use-hook ()
10508 (vhdl-hooked-abbrev 'vhdl-template-use))
10509(defun vhdl-template-variable-hook ()
10510 (vhdl-hooked-abbrev 'vhdl-template-variable))
10511(defun vhdl-template-wait-hook ()
10512 (vhdl-hooked-abbrev 'vhdl-template-wait))
10513(defun vhdl-template-when-hook ()
10514 (vhdl-hooked-abbrev 'vhdl-template-when))
10515(defun vhdl-template-while-loop-hook ()
10516 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10517(defun vhdl-template-with-hook ()
10518 (vhdl-hooked-abbrev 'vhdl-template-with))
10519(defun vhdl-template-and-hook ()
10520 (vhdl-hooked-abbrev 'vhdl-template-and))
10521(defun vhdl-template-or-hook ()
10522 (vhdl-hooked-abbrev 'vhdl-template-or))
10523(defun vhdl-template-nand-hook ()
10524 (vhdl-hooked-abbrev 'vhdl-template-nand))
10525(defun vhdl-template-nor-hook ()
10526 (vhdl-hooked-abbrev 'vhdl-template-nor))
10527(defun vhdl-template-xor-hook ()
10528 (vhdl-hooked-abbrev 'vhdl-template-xor))
10529(defun vhdl-template-xnor-hook ()
10530 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10531(defun vhdl-template-not-hook ()
10532 (vhdl-hooked-abbrev 'vhdl-template-not))
10533
10534(defun vhdl-template-default-hook ()
10535 (vhdl-hooked-abbrev 'vhdl-template-default))
10536(defun vhdl-template-default-indent-hook ()
10537 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10538
10539;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10540;; Template insertion from completion list
10541
10542(defun vhdl-template-insert-construct (name)
10543 "Insert the built-in construct template with NAME."
10544 (interactive
10545 (list (let ((completion-ignore-case t))
10546 (completing-read "Construct name: "
10547 vhdl-template-construct-alist nil t))))
10548 (vhdl-template-insert-fun
3dcb36b7 10549 (cadr (assoc name vhdl-template-construct-alist))))
5eabfe72
KH
10550
10551(defun vhdl-template-insert-package (name)
10552 "Insert the built-in package template with NAME."
10553 (interactive
10554 (list (let ((completion-ignore-case t))
10555 (completing-read "Package name: "
10556 vhdl-template-package-alist nil t))))
10557 (vhdl-template-insert-fun
3dcb36b7 10558 (cadr (assoc name vhdl-template-package-alist))))
5eabfe72
KH
10559
10560(defun vhdl-template-insert-directive (name)
10561 "Insert the built-in directive template with NAME."
10562 (interactive
10563 (list (let ((completion-ignore-case t))
10564 (completing-read "Directive name: "
10565 vhdl-template-directive-alist nil t))))
10566 (vhdl-template-insert-fun
3dcb36b7 10567 (cadr (assoc name vhdl-template-directive-alist))))
5eabfe72
KH
10568
10569(defun vhdl-template-insert-fun (fun)
10570 "Call FUN to insert a built-in template."
10571 (let ((caught (catch 'abort (when fun (funcall fun)))))
10572 (when (stringp caught) (message caught))))
10573
10574
10575;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10576;;; Models
10577;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10578
10579(defun vhdl-model-insert (model-name)
10580 "Insert the user model with name MODEL-NAME."
10581 (interactive
10582 (let ((completion-ignore-case t))
10583 (list (completing-read "Model name: " vhdl-model-alist))))
3dcb36b7 10584 (indent-according-to-mode)
5eabfe72
KH
10585 (let ((start (point-marker))
10586 (margin (current-indentation))
5eabfe72 10587 model position prompt string end)
3dcb36b7 10588 (vhdl-prepare-search-2
5eabfe72
KH
10589 (when (setq model (assoc model-name vhdl-model-alist))
10590 ;; insert model
10591 (beginning-of-line)
10592 (delete-horizontal-space)
10593 (goto-char start)
10594 (vhdl-insert-string-or-file (nth 1 model))
10595 (setq end (point-marker))
10596 ;; indent code
10597 (goto-char start)
10598 (beginning-of-line)
10599 (while (< (point) end)
10600 (unless (looking-at "^$")
10601 (insert-char ? margin))
10602 (beginning-of-line 2))
10603 (goto-char start)
10604 ;; insert clock
10605 (unless (equal "" vhdl-clock-name)
10606 (while (re-search-forward "<clock>" end t)
10607 (replace-match vhdl-clock-name)))
10608 (goto-char start)
10609 ;; insert reset
10610 (unless (equal "" vhdl-reset-name)
10611 (while (re-search-forward "<reset>" end t)
10612 (replace-match vhdl-reset-name)))
3dcb36b7
JB
10613 ;; replace header prompts
10614 (vhdl-template-replace-header-keywords start end nil t)
5eabfe72 10615 (goto-char start)
3dcb36b7 10616 ;; query other prompts
5eabfe72
KH
10617 (while (re-search-forward
10618 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10619 (unless (equal "cursor" (match-string 1))
10620 (setq position (match-beginning 1))
10621 (setq prompt (match-string 1))
10622 (replace-match "")
10623 (setq string (vhdl-template-field prompt nil t))
a5a08b1f 10624 ;; replace occurrences of same prompt
5eabfe72
KH
10625 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10626 (replace-match (or string "")))
10627 (goto-char position)))
10628 (goto-char start)
10629 ;; goto final position
10630 (if (re-search-forward "<cursor>" end t)
10631 (replace-match "")
10632 (goto-char end))))))
10633
10634(defun vhdl-model-defun ()
10635 "Define help and hook functions for user models."
10636 (let ((model-alist vhdl-model-alist)
10637 model-name model-keyword)
10638 (while model-alist
10639 ;; define functions for user models that can be invoked from menu and key
10640 ;; bindings and which themselves call `vhdl-model-insert' with the model
10641 ;; name as argument
10642 (setq model-name (nth 0 (car model-alist)))
d4a5b644
GM
10643 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10644 ,(concat "Insert model for \"" model-name "\".")
10645 (interactive)
10646 (vhdl-model-insert ,model-name)))
5eabfe72
KH
10647 ;; define hooks for user models that are invoked from keyword abbrevs
10648 (setq model-keyword (nth 3 (car model-alist)))
10649 (unless (equal model-keyword "")
d4a5b644
GM
10650 (eval `(defun
10651 ,(vhdl-function-name
10652 "vhdl-model" model-name "hook") ()
10653 (vhdl-hooked-abbrev
10654 ',(vhdl-function-name "vhdl-model" model-name)))))
5eabfe72
KH
10655 (setq model-alist (cdr model-alist)))))
10656
10657(vhdl-model-defun)
10658
10659
10660;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10661;;; Port translation
10662;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10663
10664(defvar vhdl-port-list nil
3dcb36b7 10665 "Variable to hold last port map parsed.")
5eabfe72 10666;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
10667;; (ent-name
10668;; ((generic-names) generic-type generic-init generic-comment group-comment)
10669;; ((port-names) port-object port-direct port-type port-comment group-comment)
10670;; (lib-name pack-key))
5eabfe72
KH
10671
10672(defun vhdl-parse-string (string &optional optional)
3dcb36b7 10673 "Check that the text following point matches the regexp in STRING."
5eabfe72 10674 (if (looking-at string)
3dcb36b7 10675 (goto-char (match-end 0))
5eabfe72 10676 (unless optional
3dcb36b7
JB
10677 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10678 (vhdl-current-line) string)))
5eabfe72
KH
10679 nil))
10680
10681(defun vhdl-replace-string (regexp-cons string)
10682 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
3dcb36b7 10683 (vhdl-prepare-search-1
5eabfe72 10684 (if (string-match (car regexp-cons) string)
3dcb36b7
JB
10685 (funcall vhdl-file-name-case
10686 (replace-match (cdr regexp-cons) t nil string))
5eabfe72
KH
10687 string)))
10688
3dcb36b7
JB
10689(defun vhdl-parse-group-comment ()
10690 "Parse comment and empty lines between groups of lines."
10691 (let ((start (point))
10692 string)
10693 (vhdl-forward-comment (point-max))
10694 (setq string (buffer-substring-no-properties start (point)))
10695 ;; strip off leading blanks and first newline
10696 (while (string-match "^\\(\\s-+\\)" string)
10697 (setq string (concat (substring string 0 (match-beginning 1))
10698 (substring string (match-end 1)))))
10699 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10700 (substring string 1)
10701 string)))
10702
10703(defun vhdl-paste-group-comment (string indent)
10704 "Paste comment and empty lines from STRING between groups of lines
10705with INDENT."
10706 (let ((pos (point-marker)))
10707 (when (> indent 0)
10708 (while (string-match "^\\(--\\)" string)
10709 (setq string (concat (substring string 0 (match-beginning 1))
10710 (make-string indent ? )
10711 (substring string (match-beginning 1))))))
10712 (beginning-of-line)
10713 (insert string)
10714 (goto-char pos)))
10715
10716(defvar vhdl-port-flattened nil
10717 "Indicates whether a port has been flattened.")
10718
10719(defun vhdl-port-flatten (&optional as-alist)
5eabfe72
KH
10720 "Flatten port list so that only one generic/port exists per line."
10721 (interactive)
10722 (if (not vhdl-port-list)
3dcb36b7 10723 (error "ERROR: No port has been read")
5eabfe72
KH
10724 (message "Flattening port...")
10725 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10726 (old-vhdl-port-list (cdr vhdl-port-list))
10727 old-port-list new-port-list old-port new-port names)
10728 ;; traverse port list and flatten entries
3dcb36b7 10729 (while (cdr old-vhdl-port-list)
5eabfe72
KH
10730 (setq old-port-list (car old-vhdl-port-list))
10731 (setq new-port-list nil)
10732 (while old-port-list
10733 (setq old-port (car old-port-list))
10734 (setq names (car old-port))
10735 (while names
3dcb36b7
JB
10736 (setq new-port (cons (if as-alist (car names) (list (car names)))
10737 (cdr old-port)))
5eabfe72
KH
10738 (setq new-port-list (append new-port-list (list new-port)))
10739 (setq names (cdr names)))
10740 (setq old-port-list (cdr old-port-list)))
10741 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10742 (setq new-vhdl-port-list (append new-vhdl-port-list
10743 (list new-port-list))))
3dcb36b7
JB
10744 (setq vhdl-port-list
10745 (append new-vhdl-port-list (list old-vhdl-port-list))
10746 vhdl-port-flattened t)
5eabfe72
KH
10747 (message "Flattening port...done"))))
10748
3dcb36b7
JB
10749(defvar vhdl-port-reversed-direction nil
10750 "Indicates whether port directions are reversed.")
10751
10752(defun vhdl-port-reverse-direction ()
10753 "Reverse direction for all ports (useful in testbenches)."
10754 (interactive)
10755 (if (not vhdl-port-list)
10756 (error "ERROR: No port has been read")
10757 (message "Reversing port directions...")
10758 (let ((port-list (nth 2 vhdl-port-list))
10759 port-dir-car port-dir)
10760 ;; traverse port list and reverse directions
10761 (while port-list
10762 (setq port-dir-car (cddr (car port-list))
10763 port-dir (car port-dir-car))
10764 (setcar port-dir-car
10765 (cond ((equal port-dir "in") "out")
10766 ((equal port-dir "out") "in")
10767 (t port-dir)))
10768 (setq port-list (cdr port-list)))
10769 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10770 (message "Reversing port directions...done"))))
10771
5eabfe72
KH
10772(defun vhdl-port-copy ()
10773 "Get generic and port information from an entity or component declaration."
10774 (interactive)
5eabfe72 10775 (save-excursion
3dcb36b7
JB
10776 (let (parse-error end-of-list
10777 decl-type name generic-list port-list context-clause
10778 object names direct type init comment group-comment)
10779 (vhdl-prepare-search-2
5eabfe72
KH
10780 (setq
10781 parse-error
10782 (catch 'parse
10783 ;; check if within entity or component declaration
3dcb36b7 10784 (end-of-line)
5eabfe72
KH
10785 (when (or (not (re-search-backward
10786 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
3dcb36b7
JB
10787 (equal "END" (upcase (match-string 1))))
10788 (throw 'parse "ERROR: Not within an entity or component declaration"))
10789 (setq decl-type (downcase (match-string-no-properties 1)))
5eabfe72 10790 (forward-word 1)
3dcb36b7
JB
10791 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10792 (setq name (match-string-no-properties 1))
10793 (message "Reading port of %s \"%s\"..." decl-type name)
5eabfe72
KH
10794 (vhdl-forward-syntactic-ws)
10795 ;; parse generic clause
10796 (when (vhdl-parse-string "generic[ \t\n]*(" t)
3dcb36b7
JB
10797 ;; parse group comment and spacing
10798 (setq group-comment (vhdl-parse-group-comment))
10799 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
10800 (while (not end-of-list)
10801 ;; parse names
10802 (vhdl-parse-string "\\(\\w+\\)[ \t\n]*")
3dcb36b7 10803 (setq names (list (match-string-no-properties 1)))
5eabfe72 10804 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
3dcb36b7
JB
10805 (setq names
10806 (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10807 ;; parse type
10808 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
3dcb36b7 10809 (setq type (match-string-no-properties 1))
5eabfe72
KH
10810 (setq comment nil)
10811 (while (looking-at "(")
10812 (setq type
10813 (concat type
3dcb36b7 10814 (buffer-substring-no-properties
5eabfe72
KH
10815 (point) (progn (forward-sexp) (point)))
10816 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
3dcb36b7 10817 (match-string-no-properties 1)))))
5eabfe72
KH
10818 ;; special case: closing parenthesis is on separate line
10819 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10820 (setq comment (substring type (match-beginning 2)))
10821 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10822 ;; strip of trailing group-comment
5eabfe72
KH
10823 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10824 (setq type (substring type 0 (match-end 1)))
10825 ;; parse initialization expression
10826 (setq init nil)
10827 (when (vhdl-parse-string ":=[ \t\n]*" t)
10828 (vhdl-parse-string "\\([^();\n]*\\)")
3dcb36b7 10829 (setq init (match-string-no-properties 1))
5eabfe72
KH
10830 (while (looking-at "(")
10831 (setq init
10832 (concat init
3dcb36b7 10833 (buffer-substring-no-properties
5eabfe72
KH
10834 (point) (progn (forward-sexp) (point)))
10835 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 10836 (match-string-no-properties 1))))))
5eabfe72
KH
10837 ;; special case: closing parenthesis is on separate line
10838 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10839 (setq comment (substring init (match-beginning 2)))
10840 (setq init (substring init 0 (match-beginning 1)))
10841 (vhdl-forward-syntactic-ws))
10842 (skip-chars-forward " \t")
10843 ;; parse inline comment, special case: as above, no initial.
10844 (unless comment
10845 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10846 (match-string-no-properties 1))))
5eabfe72
KH
10847 (vhdl-forward-syntactic-ws)
10848 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 10849 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
10850 ;; parse inline comment
10851 (unless comment
10852 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10853 (match-string-no-properties 1))))
5eabfe72 10854 ;; save everything in list
3dcb36b7
JB
10855 (setq generic-list (append generic-list
10856 (list (list names type init
10857 comment group-comment))))
10858 ;; parse group comment and spacing
10859 (setq group-comment (vhdl-parse-group-comment))))
5eabfe72
KH
10860 ;; parse port clause
10861 (when (vhdl-parse-string "port[ \t\n]*(" t)
3dcb36b7
JB
10862 ;; parse group comment and spacing
10863 (setq group-comment (vhdl-parse-group-comment))
10864 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
10865 (while (not end-of-list)
10866 ;; parse object
10867 (setq object
3dcb36b7
JB
10868 (and (vhdl-parse-string "\\(signal\\|quantity\\|terminal\\)[ \t\n]*" t)
10869 (match-string-no-properties 1)))
10870 ;; parse names (accept extended identifiers)
10871 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10872 (setq names (list (match-string-no-properties 1)))
10873 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
10874 (setq names (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10875 ;; parse direction
10876 (vhdl-parse-string ":[ \t\n]*")
10877 (setq direct
3dcb36b7
JB
10878 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
10879 (match-string-no-properties 1)))
5eabfe72
KH
10880 ;; parse type
10881 (vhdl-parse-string "\\([^();\n]+\\)")
3dcb36b7 10882 (setq type (match-string-no-properties 1))
5eabfe72
KH
10883 (setq comment nil)
10884 (while (looking-at "(")
10885 (setq type (concat type
3dcb36b7 10886 (buffer-substring-no-properties
5eabfe72
KH
10887 (point) (progn (forward-sexp) (point)))
10888 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 10889 (match-string-no-properties 1)))))
5eabfe72 10890 ;; special case: closing parenthesis is on separate line
3dcb36b7 10891 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
5eabfe72
KH
10892 (setq comment (substring type (match-beginning 2)))
10893 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10894 ;; strip of trailing group-comment
5eabfe72
KH
10895 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10896 (setq type (substring type 0 (match-end 1)))
10897 (vhdl-forward-syntactic-ws)
10898 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 10899 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
10900 ;; parse inline comment
10901 (unless comment
10902 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10903 (match-string-no-properties 1))))
5eabfe72 10904 ;; save everything in list
3dcb36b7
JB
10905 (setq port-list (append port-list
10906 (list (list names object direct type
10907 comment group-comment))))
10908 ;; parse group comment and spacing
10909 (setq group-comment (vhdl-parse-group-comment))))
10910; (vhdl-parse-string "end\\>")
10911 ;; parse context clause
10912 (setq context-clause (vhdl-scan-context-clause))
10913; ;; add surrounding package to context clause
10914; (when (and (equal decl-type "component")
10915; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
10916; (setq context-clause
10917; (append context-clause
10918; (list (cons (vhdl-work-library)
10919; (match-string-no-properties 1))))))
10920 (message "Reading port of %s \"%s\"...done" decl-type name)
5eabfe72
KH
10921 nil)))
10922 ;; finish parsing
10923 (if parse-error
10924 (error parse-error)
3dcb36b7
JB
10925 (setq vhdl-port-list (list name generic-list port-list context-clause)
10926 vhdl-port-reversed-direction nil
10927 vhdl-port-flattened nil)))))
10928
10929(defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
10930 "Paste a context clause."
10931 (let ((margin (current-indentation))
10932 (clause-list (nth 3 vhdl-port-list))
10933 clause)
10934 (while clause-list
10935 (setq clause (car clause-list))
10936 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
10937 (downcase exclude-pack-name)))
10938 (save-excursion
10939 (re-search-backward
10940 (concat "^\\s-*use\\s-+" (car clause)
10941 "\." (cdr clause) "\\>") nil t)))
10942 (vhdl-template-standard-package (car clause) (cdr clause))
10943 (insert "\n"))
10944 (setq clause-list (cdr clause-list)))))
5eabfe72
KH
10945
10946(defun vhdl-port-paste-generic (&optional no-init)
10947 "Paste a generic clause."
10948 (let ((margin (current-indentation))
3dcb36b7
JB
10949 (generic-list (nth 1 vhdl-port-list))
10950 list-margin start names generic)
5eabfe72 10951 ;; paste generic clause
3dcb36b7 10952 (when generic-list
5eabfe72
KH
10953 (setq start (point))
10954 (vhdl-insert-keyword "GENERIC (")
10955 (unless vhdl-argument-list-indent
10956 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10957 (setq list-margin (current-column))
3dcb36b7
JB
10958 (while generic-list
10959 (setq generic (car generic-list))
10960 ;; paste group comment and spacing
10961 (when (memq vhdl-include-group-comments '(decl always))
10962 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72 10963 ;; paste names
5eabfe72
KH
10964 (setq names (nth 0 generic))
10965 (while names
10966 (insert (car names))
10967 (setq names (cdr names))
10968 (when names (insert ", ")))
10969 ;; paste type
10970 (insert " : " (nth 1 generic))
10971 ;; paste initialization
10972 (when (and (not no-init) (nth 2 generic))
10973 (insert " := " (nth 2 generic)))
3dcb36b7 10974 (unless (cdr generic-list) (insert ")"))
5eabfe72
KH
10975 (insert ";")
10976 ;; paste comment
10977 (when (and vhdl-include-port-comments (nth 3 generic))
10978 (vhdl-comment-insert-inline (nth 3 generic) t))
3dcb36b7
JB
10979 (setq generic-list (cdr generic-list))
10980 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72 10981 ;; align generic clause
3dcb36b7 10982 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
5eabfe72
KH
10983
10984(defun vhdl-port-paste-port ()
10985 "Paste a port clause."
10986 (let ((margin (current-indentation))
3dcb36b7
JB
10987 (port-list (nth 2 vhdl-port-list))
10988 list-margin start names port)
5eabfe72 10989 ;; paste port clause
3dcb36b7 10990 (when port-list
5eabfe72
KH
10991 (setq start (point))
10992 (vhdl-insert-keyword "PORT (")
10993 (unless vhdl-argument-list-indent
10994 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10995 (setq list-margin (current-column))
3dcb36b7
JB
10996 (while port-list
10997 (setq port (car port-list))
10998 ;; paste group comment and spacing
10999 (when (memq vhdl-include-group-comments '(decl always))
11000 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11001 ;; paste object
11002 (when (nth 1 port) (insert (nth 1 port) " "))
11003 ;; paste names
11004 (setq names (nth 0 port))
11005 (while names
11006 (insert (car names))
11007 (setq names (cdr names))
11008 (when names (insert ", ")))
11009 ;; paste direction
11010 (insert " : ")
11011 (when (nth 2 port) (insert (nth 2 port) " "))
11012 ;; paste type
11013 (insert (nth 3 port))
3dcb36b7 11014 (unless (cdr port-list) (insert ")"))
5eabfe72
KH
11015 (insert ";")
11016 ;; paste comment
11017 (when (and vhdl-include-port-comments (nth 4 port))
11018 (vhdl-comment-insert-inline (nth 4 port) t))
3dcb36b7
JB
11019 (setq port-list (cdr port-list))
11020 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72 11021 ;; align port clause
3dcb36b7 11022 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
5eabfe72 11023
3dcb36b7 11024(defun vhdl-port-paste-declaration (kind &optional no-indent)
5eabfe72 11025 "Paste as an entity or component declaration."
3dcb36b7 11026 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11027 (let ((margin (current-indentation))
11028 (name (nth 0 vhdl-port-list)))
11029 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11030 (insert name)
3dcb36b7
JB
11031 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11032 (vhdl-insert-keyword " IS"))
11033 ;; paste generic and port clause
5eabfe72
KH
11034 (when (nth 1 vhdl-port-list)
11035 (insert "\n")
11036 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11037 (insert "\n"))
11038 (indent-to (+ margin vhdl-basic-offset))
11039 (vhdl-port-paste-generic (eq kind 'component)))
11040 (when (nth 2 vhdl-port-list)
11041 (insert "\n")
11042 (when (and (memq vhdl-insert-empty-lines '(unit all))
11043 (eq kind 'entity))
11044 (insert "\n"))
11045 (indent-to (+ margin vhdl-basic-offset)))
11046 (vhdl-port-paste-port)
11047 (insert "\n")
11048 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11049 (insert "\n"))
11050 (indent-to margin)
11051 (vhdl-insert-keyword "END")
11052 (if (eq kind 'entity)
11053 (progn
11054 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11055 (insert " " name))
11056 (vhdl-insert-keyword " COMPONENT")
11057 (unless (vhdl-standard-p '87) (insert " " name)))
11058 (insert ";")))
11059
3dcb36b7 11060(defun vhdl-port-paste-entity (&optional no-indent)
5eabfe72
KH
11061 "Paste as an entity declaration."
11062 (interactive)
11063 (if (not vhdl-port-list)
3dcb36b7
JB
11064 (error "ERROR: No port read")
11065 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11066 (vhdl-port-paste-declaration 'entity no-indent)
11067 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
5eabfe72 11068
3dcb36b7 11069(defun vhdl-port-paste-component (&optional no-indent)
5eabfe72
KH
11070 "Paste as a component declaration."
11071 (interactive)
11072 (if (not vhdl-port-list)
3dcb36b7
JB
11073 (error "ERROR: No port read")
11074 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11075 (vhdl-port-paste-declaration 'component no-indent)
11076 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
5eabfe72
KH
11077
11078(defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11079 "Paste as a generic map."
11080 (interactive)
3dcb36b7 11081 (unless secondary (indent-according-to-mode))
5eabfe72
KH
11082 (let ((margin (current-indentation))
11083 list-margin start generic
3dcb36b7
JB
11084 (generic-list (nth 1 vhdl-port-list)))
11085 (when generic-list
5eabfe72
KH
11086 (setq start (point))
11087 (vhdl-insert-keyword "GENERIC MAP (")
11088 (if (not vhdl-association-list-with-formals)
11089 ;; paste list of actual generics
3dcb36b7
JB
11090 (while generic-list
11091 (insert (if no-constants
11092 (car (nth 0 (car generic-list)))
11093 (or (nth 2 (car generic-list)) " ")))
11094 (setq generic-list (cdr generic-list))
11095 (insert (if generic-list ", " ")")))
5eabfe72 11096 (unless vhdl-argument-list-indent
3dcb36b7 11097 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11098 (setq list-margin (current-column))
3dcb36b7
JB
11099 (while generic-list
11100 (setq generic (car generic-list))
11101 ;; paste group comment and spacing
11102 (when (eq vhdl-include-group-comments 'always)
11103 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72
KH
11104 ;; paste formal and actual generic
11105 (insert (car (nth 0 generic)) " => "
11106 (if no-constants
11107 (car (nth 0 generic))
11108 (or (nth 2 generic) "")))
3dcb36b7
JB
11109 (setq generic-list (cdr generic-list))
11110 (insert (if generic-list "," ")"))
5eabfe72 11111 ;; paste comment
3dcb36b7
JB
11112 (when (or vhdl-include-type-comments
11113 (and vhdl-include-port-comments (nth 3 generic)))
11114 (vhdl-comment-insert-inline
11115 (concat
11116 (when vhdl-include-type-comments
11117 (concat "[" (nth 1 generic) "] "))
11118 (when vhdl-include-port-comments (nth 3 generic))) t))
11119 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11120 ;; align generic map
11121 (when vhdl-auto-align
3dcb36b7 11122 (vhdl-align-region-groups start (point) 1 t))))))
5eabfe72
KH
11123
11124(defun vhdl-port-paste-port-map ()
11125 "Paste as a port map."
11126 (let ((margin (current-indentation))
11127 list-margin start port
3dcb36b7
JB
11128 (port-list (nth 2 vhdl-port-list)))
11129 (when port-list
5eabfe72
KH
11130 (setq start (point))
11131 (vhdl-insert-keyword "PORT MAP (")
11132 (if (not vhdl-association-list-with-formals)
11133 ;; paste list of actual ports
3dcb36b7 11134 (while port-list
5eabfe72 11135 (insert (vhdl-replace-string vhdl-actual-port-name
3dcb36b7
JB
11136 (car (nth 0 (car port-list)))))
11137 (setq port-list (cdr port-list))
11138 (insert (if port-list ", " ");")))
5eabfe72 11139 (unless vhdl-argument-list-indent
3dcb36b7 11140 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11141 (setq list-margin (current-column))
3dcb36b7
JB
11142 (while port-list
11143 (setq port (car port-list))
11144 ;; paste group comment and spacing
11145 (when (eq vhdl-include-group-comments 'always)
11146 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11147 ;; paste formal and actual port
11148 (insert (car (nth 0 port)) " => ")
11149 (insert (vhdl-replace-string vhdl-actual-port-name
11150 (car (nth 0 port))))
3dcb36b7
JB
11151 (setq port-list (cdr port-list))
11152 (insert (if port-list "," ");"))
5eabfe72
KH
11153 ;; paste comment
11154 (when (or vhdl-include-direction-comments
3dcb36b7 11155 vhdl-include-type-comments
5eabfe72
KH
11156 (and vhdl-include-port-comments (nth 4 port)))
11157 (vhdl-comment-insert-inline
11158 (concat
3dcb36b7
JB
11159 (cond ((and vhdl-include-direction-comments
11160 vhdl-include-type-comments)
11161 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11162 (nth 3 port) "] "))
11163 ((and vhdl-include-direction-comments (nth 2 port))
11164 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11165 (vhdl-include-direction-comments " ")
11166 (vhdl-include-type-comments
11167 (concat "[" (nth 3 port) "] ")))
11168 (when vhdl-include-port-comments (nth 4 port))) t))
11169 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11170 ;; align port clause
11171 (when vhdl-auto-align
3dcb36b7 11172 (vhdl-align-region-groups start (point) 1))))))
5eabfe72 11173
3dcb36b7 11174(defun vhdl-port-paste-instance (&optional name no-indent title)
5eabfe72
KH
11175 "Paste as an instantiation."
11176 (interactive)
11177 (if (not vhdl-port-list)
3dcb36b7 11178 (error "ERROR: No port read")
5eabfe72
KH
11179 (let ((orig-vhdl-port-list vhdl-port-list))
11180 ;; flatten local copy of port list (must be flat for port mapping)
11181 (vhdl-port-flatten)
3dcb36b7
JB
11182 (unless no-indent (indent-according-to-mode))
11183 (let ((margin (current-indentation)))
5eabfe72 11184 ;; paste instantiation
3dcb36b7
JB
11185 (cond (name
11186 (insert name))
11187 ((equal (cdr vhdl-instance-name) "")
11188 (setq name (vhdl-template-field "instance name")))
11189 ((string-match "\%d" (cdr vhdl-instance-name))
11190 (let ((n 1))
11191 (while (save-excursion
11192 (setq name (format (vhdl-replace-string
11193 vhdl-instance-name
11194 (nth 0 vhdl-port-list)) n))
11195 (goto-char (point-min))
11196 (vhdl-re-search-forward name nil t))
11197 (setq n (1+ n)))
11198 (insert name)))
11199 (t (insert (vhdl-replace-string vhdl-instance-name
11200 (nth 0 vhdl-port-list)))))
11201 (message "Pasting port as instantiation \"%s\"..." name)
11202 (insert ": ")
11203 (when title
11204 (save-excursion
11205 (beginning-of-line)
11206 (indent-to vhdl-basic-offset)
11207 (insert "-- instance \"" name "\"\n")))
11208 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
11209 (insert (nth 0 vhdl-port-list))
11210 (vhdl-insert-keyword "ENTITY ")
3dcb36b7 11211 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
5eabfe72
KH
11212 (when (nth 1 vhdl-port-list)
11213 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11214 (vhdl-port-paste-generic-map t t))
11215 (when (nth 2 vhdl-port-list)
11216 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11217 (vhdl-port-paste-port-map))
3dcb36b7
JB
11218 (message "Pasting port as instantiation \"%s\"...done" name))
11219 (setq vhdl-port-list orig-vhdl-port-list))))
11220
11221(defun vhdl-port-paste-constants (&optional no-indent)
11222 "Paste generics as constants."
11223 (interactive)
11224 (if (not vhdl-port-list)
11225 (error "ERROR: No port read")
11226 (let ((orig-vhdl-port-list vhdl-port-list))
11227 (message "Pasting port as constants...")
11228 ;; flatten local copy of port list (must be flat for constant initial.)
11229 (vhdl-port-flatten)
11230 (unless no-indent (indent-according-to-mode))
11231 (let ((margin (current-indentation))
11232 start generic name
11233 (generic-list (nth 1 vhdl-port-list)))
11234 (when generic-list
11235 (setq start (point))
11236 (while generic-list
11237 (setq generic (car generic-list))
11238 ;; paste group comment and spacing
11239 (when (memq vhdl-include-group-comments '(decl always))
11240 (vhdl-paste-group-comment (nth 4 generic) margin))
11241 (vhdl-insert-keyword "CONSTANT ")
11242 ;; paste generic constants
11243 (setq name (nth 0 generic))
11244 (when name
11245 (insert (car name))
11246 ;; paste type
11247 (insert " : " (nth 1 generic))
11248 ;; paste initialization
11249 (when (nth 2 generic)
11250 (insert " := " (nth 2 generic)))
11251 (insert ";")
11252 ;; paste comment
11253 (when (and vhdl-include-port-comments (nth 3 generic))
11254 (vhdl-comment-insert-inline (nth 3 generic) t))
11255 (setq generic-list (cdr generic-list))
11256 (when generic-list (insert "\n") (indent-to margin))))
11257 ;; align signal list
11258 (when vhdl-auto-align
11259 (vhdl-align-region-groups start (point) 1))))
11260 (message "Pasting port as constants...done")
5eabfe72
KH
11261 (setq vhdl-port-list orig-vhdl-port-list))))
11262
3dcb36b7 11263(defun vhdl-port-paste-signals (&optional initialize no-indent)
5eabfe72
KH
11264 "Paste ports as internal signals."
11265 (interactive)
11266 (if (not vhdl-port-list)
3dcb36b7 11267 (error "ERROR: No port read")
5eabfe72 11268 (message "Pasting port as signals...")
3dcb36b7 11269 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11270 (let ((margin (current-indentation))
11271 start port names
3dcb36b7
JB
11272 (port-list (nth 2 vhdl-port-list)))
11273 (when port-list
5eabfe72 11274 (setq start (point))
3dcb36b7
JB
11275 (while port-list
11276 (setq port (car port-list))
11277 ;; paste group comment and spacing
11278 (when (memq vhdl-include-group-comments '(decl always))
11279 (vhdl-paste-group-comment (nth 5 port) margin))
5eabfe72
KH
11280 ;; paste object
11281 (if (nth 1 port)
11282 (insert (nth 1 port) " ")
11283 (vhdl-insert-keyword "SIGNAL "))
11284 ;; paste actual port signals
11285 (setq names (nth 0 port))
11286 (while names
11287 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11288 (setq names (cdr names))
11289 (when names (insert ", ")))
11290 ;; paste type
11291 (insert " : " (nth 3 port))
11292 ;; paste initialization (inputs only)
3dcb36b7
JB
11293 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11294 (insert " := " (if (string-match "(.+)" (nth 3 port))
11295 "(others => '0')" "'0'")))
5eabfe72
KH
11296 (insert ";")
11297 ;; paste comment
3dcb36b7
JB
11298 (when (or vhdl-include-direction-comments
11299 (and vhdl-include-port-comments (nth 4 port)))
11300 (vhdl-comment-insert-inline
11301 (concat
11302 (cond ((and vhdl-include-direction-comments (nth 2 port))
11303 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11304 (vhdl-include-direction-comments " "))
11305 (when vhdl-include-port-comments (nth 4 port))) t))
11306 (setq port-list (cdr port-list))
11307 (when port-list (insert "\n") (indent-to margin)))
5eabfe72 11308 ;; align signal list
3dcb36b7 11309 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
5eabfe72
KH
11310 (message "Pasting port as signals...done")))
11311
3dcb36b7
JB
11312(defun vhdl-port-paste-initializations (&optional no-indent)
11313 "Paste ports as signal initializations."
5eabfe72
KH
11314 (interactive)
11315 (if (not vhdl-port-list)
3dcb36b7 11316 (error "ERROR: No port read")
5eabfe72 11317 (let ((orig-vhdl-port-list vhdl-port-list))
3dcb36b7
JB
11318 (message "Pasting port as initializations...")
11319 ;; flatten local copy of port list (must be flat for signal initial.)
5eabfe72 11320 (vhdl-port-flatten)
3dcb36b7 11321 (unless no-indent (indent-according-to-mode))
5eabfe72 11322 (let ((margin (current-indentation))
3dcb36b7
JB
11323 start port name
11324 (port-list (nth 2 vhdl-port-list)))
11325 (when port-list
5eabfe72 11326 (setq start (point))
3dcb36b7
JB
11327 (while port-list
11328 (setq port (car port-list))
11329 ;; paste actual port signal (inputs only)
11330 (when (equal "IN" (upcase (nth 2 port)))
11331 (setq name (car (nth 0 port)))
11332 (insert (vhdl-replace-string vhdl-actual-port-name name))
5eabfe72 11333 ;; paste initialization
3dcb36b7
JB
11334 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11335 "(others => '0')" "'0'") ";"))
11336 (setq port-list (cdr port-list))
11337 (when (and port-list
11338 (equal "IN" (upcase (nth 2 (car port-list)))))
11339 (insert "\n") (indent-to margin)))
11340 ;; align signal list
11341 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11342 (message "Pasting port as initializations...done")
5eabfe72
KH
11343 (setq vhdl-port-list orig-vhdl-port-list))))
11344
11345(defun vhdl-port-paste-testbench ()
3dcb36b7 11346 "Paste as a bare-bones testbench."
5eabfe72
KH
11347 (interactive)
11348 (if (not vhdl-port-list)
3dcb36b7 11349 (error "ERROR: No port read")
5eabfe72
KH
11350 (let ((case-fold-search t)
11351 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11352 (nth 0 vhdl-port-list)))
11353 (source-buffer (current-buffer))
3dcb36b7
JB
11354 arch-name config-name ent-file-name arch-file-name
11355 ent-buffer arch-buffer position)
5eabfe72 11356 ;; open entity file
3dcb36b7 11357 (unless (eq vhdl-testbench-create-files 'none)
5eabfe72 11358 (setq ent-file-name
3dcb36b7
JB
11359 (concat ent-name "." (file-name-extension (buffer-file-name))))
11360 (if (file-exists-p ent-file-name)
5eabfe72 11361 (if (y-or-n-p
3dcb36b7
JB
11362 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11363 (progn (find-file ent-file-name)
11364 (erase-buffer)
11365 (set-buffer-modified-p nil))
11366 (if (eq vhdl-testbench-create-files 'separate)
11367 (setq ent-file-name nil)
11368 (error "ERROR: Pasting port as testbench...aborted")))
11369 (find-file ent-file-name)))
11370 (unless (and (eq vhdl-testbench-create-files 'separate)
11371 (null ent-file-name))
11372 ;; paste entity header
11373 (if vhdl-testbench-include-header
11374 (progn (vhdl-template-header
11375 (concat "Testbench for design \""
11376 (nth 0 vhdl-port-list) "\""))
11377 (goto-char (point-max)))
11378 (vhdl-comment-display-line) (insert "\n\n"))
11379 ;; paste std_logic_1164 package
11380 (when vhdl-testbench-include-library
11381 (vhdl-template-package-std-logic-1164)
11382 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11383 ;; paste entity declaration
11384 (vhdl-insert-keyword "ENTITY ")
5eabfe72
KH
11385 (insert ent-name)
11386 (vhdl-insert-keyword " IS")
3dcb36b7 11387 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
5eabfe72 11388 (insert "\n")
3dcb36b7
JB
11389 (vhdl-insert-keyword "END ")
11390 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11391 (insert ent-name ";")
11392 (insert "\n\n")
11393 (vhdl-comment-display-line) (insert "\n"))
11394 ;; get architecture name
11395 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11396 (read-from-minibuffer "architecture name: "
11397 nil vhdl-minibuffer-local-map)
11398 (vhdl-replace-string vhdl-testbench-architecture-name
11399 (nth 0 vhdl-port-list))))
11400 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11401 ;; open architecture file
11402 (if (not (eq vhdl-testbench-create-files 'separate))
5eabfe72 11403 (insert "\n")
3dcb36b7
JB
11404 (setq ent-buffer (current-buffer))
11405 (setq arch-file-name
11406 (concat ent-name "_" arch-name "."
11407 (file-name-extension (buffer-file-name))))
11408 (when (and (file-exists-p arch-file-name)
11409 (not (y-or-n-p (concat "File \"" arch-file-name
11410 "\" exists; overwrite? "))))
11411 (error "ERROR: Pasting port as testbench...aborted"))
11412 (find-file arch-file-name)
11413 (erase-buffer)
11414 (set-buffer-modified-p nil)
11415 ;; paste architecture header
11416 (if vhdl-testbench-include-header
11417 (progn (vhdl-template-header
11418 (concat "Testbench architecture for design \""
11419 (nth 0 vhdl-port-list) "\""))
11420 (goto-char (point-max)))
11421 (vhdl-comment-display-line) (insert "\n\n")))
11422 ;; paste architecture body
11423 (vhdl-insert-keyword "ARCHITECTURE ")
11424 (insert arch-name)
11425 (vhdl-insert-keyword " OF ")
11426 (insert ent-name)
11427 (vhdl-insert-keyword " IS")
11428 (insert "\n\n") (indent-to vhdl-basic-offset)
11429 ;; paste component declaration
11430 (unless (vhdl-use-direct-instantiation)
11431 (vhdl-port-paste-component t)
11432 (insert "\n\n") (indent-to vhdl-basic-offset))
11433 ;; paste constants
11434 (when (nth 1 vhdl-port-list)
11435 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11436 (vhdl-port-paste-constants t)
11437 (insert "\n\n") (indent-to vhdl-basic-offset))
11438 ;; paste internal signals
11439 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11440 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11441 (insert "\n")
11442 ;; paste custom declarations
11443 (unless (equal "" vhdl-testbench-declarations)
5eabfe72 11444 (insert "\n")
3dcb36b7
JB
11445 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11446 (setq position (point))
11447 (insert "\n\n")
11448 (vhdl-comment-display-line) (insert "\n")
11449 (when vhdl-testbench-include-configuration
11450 (setq config-name (vhdl-replace-string
11451 vhdl-testbench-configuration-name
11452 (concat ent-name " " arch-name)))
11453 (insert "\n")
11454 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11455 (vhdl-insert-keyword " OF ") (insert ent-name)
11456 (vhdl-insert-keyword " IS\n")
11457 (indent-to vhdl-basic-offset)
11458 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11459 (indent-to vhdl-basic-offset)
11460 (vhdl-insert-keyword "END FOR;\n")
11461 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11462 (vhdl-comment-display-line) (insert "\n"))
11463 (goto-char position)
11464 (vhdl-template-begin-end
11465 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11466 ;; paste instantiation
11467 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11468 (vhdl-port-paste-instance
11469 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11470 (insert "\n")
11471 ;; paste custom statements
11472 (unless (equal "" vhdl-testbench-statements)
11473 (insert "\n")
11474 (vhdl-insert-string-or-file vhdl-testbench-statements))
11475 (insert "\n")
11476 (indent-to vhdl-basic-offset)
11477 (unless (eq vhdl-testbench-create-files 'none)
11478 (setq arch-buffer (current-buffer))
11479 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11480 (set-buffer arch-buffer) (save-buffer))
11481 (message
11482 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11483 ent-name arch-name)
11484 (and ent-file-name
11485 (format "\n File created: \"%s\"" ent-file-name))
11486 (and arch-file-name
11487 (format "\n File created: \"%s\"" arch-file-name)))))))
5eabfe72
KH
11488
11489
11490;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11491;;; Subprogram interface translation
5eabfe72
KH
11492;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11493
3dcb36b7
JB
11494(defvar vhdl-subprog-list nil
11495 "Variable to hold last subprogram interface parsed.")
11496;; structure: (parenthesised expression means list of such entries)
11497;; (subprog-name kind
11498;; ((names) object direct type init comment group-comment)
11499;; return-type return-comment group-comment)
5eabfe72 11500
3dcb36b7
JB
11501(defvar vhdl-subprog-flattened nil
11502 "Indicates whether an subprogram interface has been flattened.")
5eabfe72 11503
3dcb36b7
JB
11504(defun vhdl-subprog-flatten ()
11505 "Flatten interface list so that only one parameter exists per line."
11506 (interactive)
11507 (if (not vhdl-subprog-list)
11508 (error "ERROR: No subprogram interface has been read")
11509 (message "Flattening subprogram interface...")
11510 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11511 new-subprog-list old-subprog new-subprog names)
11512 ;; traverse parameter list and flatten entries
11513 (while old-subprog-list
11514 (setq old-subprog (car old-subprog-list))
11515 (setq names (car old-subprog))
11516 (while names
11517 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11518 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11519 (setq names (cdr names)))
11520 (setq old-subprog-list (cdr old-subprog-list)))
11521 (setq vhdl-subprog-list
11522 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11523 new-subprog-list (nth 3 vhdl-subprog-list)
11524 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11525 vhdl-subprog-flattened t)
11526 (message "Flattening subprogram interface...done"))))
11527
11528(defun vhdl-subprog-copy ()
11529 "Get interface information from a subprogram specification."
11530 (interactive)
11531 (save-excursion
11532 (let (parse-error pos end-of-list
11533 name kind param-list object names direct type init
11534 comment group-comment
11535 return-type return-comment return-group-comment)
11536 (vhdl-prepare-search-2
11537 (setq
11538 parse-error
11539 (catch 'parse
11540 ;; check if within function declaration
11541 (setq pos (point))
11542 (end-of-line)
11543 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11544 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11545 (goto-char (match-end 0))
11546 (save-excursion (backward-char)
11547 (forward-sexp)
11548 (<= pos (point))))
11549 (throw 'parse "ERROR: Not within a subprogram specification"))
11550 (setq name (match-string-no-properties 5))
11551 (setq kind (if (match-string 2) 'procedure 'function))
11552 (setq end-of-list (not (match-string 7)))
11553 (message "Reading interface of subprogram \"%s\"..." name)
11554 ;; parse parameter list
11555 (setq group-comment (vhdl-parse-group-comment))
11556 (setq end-of-list (or end-of-list
11557 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11558 (while (not end-of-list)
11559 ;; parse object
11560 (setq object
11561 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11562 (match-string-no-properties 1)))
11563 ;; parse names (accept extended identifiers)
11564 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11565 (setq names (list (match-string-no-properties 1)))
11566 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11567 (setq names (append names (list (match-string-no-properties 1)))))
11568 ;; parse direction
11569 (vhdl-parse-string ":[ \t\n]*")
11570 (setq direct
11571 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11572 (match-string-no-properties 1)))
11573 ;; parse type
11574 (vhdl-parse-string "\\([^():;\n]+\\)")
11575 (setq type (match-string-no-properties 1))
11576 (setq comment nil)
11577 (while (looking-at "(")
11578 (setq type
11579 (concat type
11580 (buffer-substring-no-properties
11581 (point) (progn (forward-sexp) (point)))
11582 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11583 (match-string-no-properties 1)))))
11584 ;; special case: closing parenthesis is on separate line
11585 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11586 (setq comment (substring type (match-beginning 2)))
11587 (setq type (substring type 0 (match-beginning 1))))
11588 ;; strip off trailing group-comment
11589 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11590 (setq type (substring type 0 (match-end 1)))
11591 ;; parse initialization expression
11592 (setq init nil)
11593 (when (vhdl-parse-string ":=[ \t\n]*" t)
11594 (vhdl-parse-string "\\([^();\n]*\\)")
11595 (setq init (match-string-no-properties 1))
11596 (while (looking-at "(")
11597 (setq init
11598 (concat init
11599 (buffer-substring-no-properties
11600 (point) (progn (forward-sexp) (point)))
11601 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11602 (match-string-no-properties 1))))))
11603 ;; special case: closing parenthesis is on separate line
11604 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11605 (setq comment (substring init (match-beginning 2)))
11606 (setq init (substring init 0 (match-beginning 1)))
11607 (vhdl-forward-syntactic-ws))
11608 (skip-chars-forward " \t")
11609 ;; parse inline comment, special case: as above, no initial.
11610 (unless comment
11611 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11612 (match-string-no-properties 1))))
11613 (vhdl-forward-syntactic-ws)
11614 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11615 ;; parse inline comment
11616 (unless comment
11617 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11618 (match-string-no-properties 1))))
11619 (setq return-group-comment (vhdl-parse-group-comment))
11620 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11621 ;; parse return type
11622 (when (match-string 3)
11623 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11624 (setq return-type (match-string-no-properties 1))
11625 (when (and return-type
11626 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11627 (setq return-comment (substring return-type (match-beginning 2)))
11628 (setq return-type (substring return-type 0 (match-beginning 1))))
11629 ;; strip of trailing group-comment
11630 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11631 (setq return-type (substring return-type 0 (match-end 1)))
11632 ;; parse return comment
11633 (unless return-comment
11634 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11635 (match-string-no-properties 1)))))
11636 ;; parse inline comment
11637 (unless comment
11638 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11639 (match-string-no-properties 1))))
11640 ;; save everything in list
11641 (setq param-list (append param-list
11642 (list (list names object direct type init
11643 comment group-comment))))
11644 ;; parse group comment and spacing
11645 (setq group-comment (vhdl-parse-group-comment)))
11646 (message "Reading interface of subprogram \"%s\"...done" name)
11647 nil)))
11648 ;; finish parsing
11649 (if parse-error
11650 (error parse-error)
11651 (setq vhdl-subprog-list
11652 (list name kind param-list return-type return-comment
11653 return-group-comment)
11654 vhdl-subprog-flattened nil)))))
11655
11656(defun vhdl-subprog-paste-specification (kind)
11657 "Paste as a subprogram specification."
11658 (indent-according-to-mode)
11659 (let ((margin (current-column))
11660 (param-list (nth 2 vhdl-subprog-list))
11661 list-margin start names param)
11662 ;; paste keyword and name
11663 (vhdl-insert-keyword
11664 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11665 (insert (nth 0 vhdl-subprog-list))
11666 (if (not param-list)
11667 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11668 (setq start (point))
11669 ;; paste parameter list
11670 (insert " (")
11671 (unless vhdl-argument-list-indent
11672 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11673 (setq list-margin (current-column))
11674 (while param-list
11675 (setq param (car param-list))
11676 ;; paste group comment and spacing
11677 (when (memq vhdl-include-group-comments (list kind 'always))
11678 (vhdl-paste-group-comment (nth 6 param) list-margin))
11679 ;; paste object
11680 (when (nth 1 param) (insert (nth 1 param) " "))
11681 ;; paste names
11682 (setq names (nth 0 param))
11683 (while names
11684 (insert (car names))
11685 (setq names (cdr names))
11686 (when names (insert ", ")))
11687 ;; paste direction
11688 (insert " : ")
11689 (when (nth 2 param) (insert (nth 2 param) " "))
11690 ;; paste type
11691 (insert (nth 3 param))
11692 ;; paste initialization
11693 (when (nth 4 param) (insert " := " (nth 4 param)))
11694 ;; terminate line
11695 (if (cdr param-list)
11696 (insert ";")
11697 (insert ")")
11698 (when (null (nth 3 vhdl-subprog-list))
11699 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11700 ;; paste comment
11701 (when (and vhdl-include-port-comments (nth 5 param))
11702 (vhdl-comment-insert-inline (nth 5 param) t))
11703 (setq param-list (cdr param-list))
11704 (when param-list (insert "\n") (indent-to list-margin)))
11705 (when (nth 3 vhdl-subprog-list)
11706 (insert "\n") (indent-to list-margin)
11707 ;; paste group comment and spacing
11708 (when (memq vhdl-include-group-comments (list kind 'always))
11709 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11710 ;; paste return type
11711 (insert "return " (nth 3 vhdl-subprog-list))
11712 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11713 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11714 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11715 ;; align parameter list
11716 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11717 ;; paste body
11718 (when (eq kind 'body)
11719 (insert "\n")
11720 (vhdl-template-begin-end
11721 (unless (vhdl-standard-p '87)
11722 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11723 (nth 0 vhdl-subprog-list) margin))))
11724
11725(defun vhdl-subprog-paste-declaration ()
11726 "Paste as a subprogram declaration."
11727 (interactive)
11728 (if (not vhdl-subprog-list)
11729 (error "ERROR: No subprogram interface read")
11730 (message "Pasting interface as subprogram declaration \"%s\"..."
11731 (car vhdl-subprog-list))
11732 ;; paste specification
11733 (vhdl-subprog-paste-specification 'decl)
11734 (message "Pasting interface as subprogram declaration \"%s\"...done"
11735 (car vhdl-subprog-list))))
11736
11737(defun vhdl-subprog-paste-body ()
11738 "Paste as a subprogram body."
11739 (interactive)
11740 (if (not vhdl-subprog-list)
11741 (error "ERROR: No subprogram interface read")
11742 (message "Pasting interface as subprogram body \"%s\"..."
11743 (car vhdl-subprog-list))
11744 ;; paste specification and body
11745 (vhdl-subprog-paste-specification 'body)
11746 (message "Pasting interface as subprogram body \"%s\"...done"
11747 (car vhdl-subprog-list))))
11748
11749(defun vhdl-subprog-paste-call ()
11750 "Paste as a subprogram call."
11751 (interactive)
11752 (if (not vhdl-subprog-list)
11753 (error "ERROR: No subprogram interface read")
11754 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11755 param-list margin list-margin param start)
11756 ;; flatten local copy of interface list (must be flat for parameter mapping)
11757 (vhdl-subprog-flatten)
11758 (setq param-list (nth 2 vhdl-subprog-list))
11759 (indent-according-to-mode)
11760 (setq margin (current-indentation))
11761 (message "Pasting interface as subprogram call \"%s\"..."
11762 (car vhdl-subprog-list))
11763 ;; paste name
11764 (insert (nth 0 vhdl-subprog-list))
11765 (if (not param-list)
11766 (insert ";")
11767 (setq start (point))
11768 ;; paste parameter list
11769 (insert " (")
11770 (unless vhdl-argument-list-indent
11771 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11772 (setq list-margin (current-column))
11773 (while param-list
11774 (setq param (car param-list))
11775 ;; paste group comment and spacing
11776 (when (eq vhdl-include-group-comments 'always)
11777 (vhdl-paste-group-comment (nth 6 param) list-margin))
11778 ;; paste formal port
11779 (insert (car (nth 0 param)) " => ")
11780 (setq param-list (cdr param-list))
11781 (insert (if param-list "," ");"))
11782 ;; paste comment
11783 (when (and vhdl-include-port-comments (nth 5 param))
11784 (vhdl-comment-insert-inline (nth 5 param)))
11785 (when param-list (insert "\n") (indent-to list-margin)))
11786 ;; align parameter list
11787 (when vhdl-auto-align
11788 (vhdl-align-region-groups start (point) 1)))
11789 (message "Pasting interface as subprogram call \"%s\"...done"
11790 (car vhdl-subprog-list))
11791 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11792
11793
11794;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11795;;; Miscellaneous
11796;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11797
11798;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11799;; Hippie expand customization
11800
11801(defvar vhdl-expand-upper-case nil)
11802
11803(defun vhdl-try-expand-abbrev (old)
11804 "Try expanding abbreviations from `vhdl-abbrev-list'."
11805 (unless old
11806 (he-init-string (he-dabbrev-beg) (point))
5eabfe72
KH
11807 (setq he-expand-list
11808 (let ((abbrev-list vhdl-abbrev-list)
11809 (sel-abbrev-list '()))
11810 (while abbrev-list
11811 (when (or (not (stringp (car abbrev-list)))
11812 (string-match
11813 (concat "^" he-search-string) (car abbrev-list)))
11814 (setq sel-abbrev-list
11815 (cons (car abbrev-list) sel-abbrev-list)))
11816 (setq abbrev-list (cdr abbrev-list)))
11817 (nreverse sel-abbrev-list))))
11818 (while (and he-expand-list
11819 (or (not (stringp (car he-expand-list)))
11820 (he-string-member (car he-expand-list) he-tried-table t)))
11821; (equal (car he-expand-list) he-search-string)))
11822 (unless (stringp (car he-expand-list))
11823 (setq vhdl-expand-upper-case (car he-expand-list)))
11824 (setq he-expand-list (cdr he-expand-list)))
11825 (if (null he-expand-list)
11826 (progn (when old (he-reset-string))
11827 nil)
11828 (he-substitute-string
11829 (if vhdl-expand-upper-case
11830 (upcase (car he-expand-list))
11831 (car he-expand-list))
11832 t)
11833 (setq he-expand-list (cdr he-expand-list))
11834 t))
11835
11836(defun vhdl-he-list-beg ()
11837 "Also looks at the word before `(' in order to better match parenthesized
11838expressions (e.g. for index ranges of types and signals)."
11839 (save-excursion
11840 (condition-case ()
11841 (progn (backward-up-list 1)
11842 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
11843 (error ()))
11844 (point)))
11845
11846;; override `he-list-beg' from `hippie-exp'
11847(unless (and (boundp 'viper-mode) viper-mode)
5eabfe72
KH
11848 (defalias 'he-list-beg 'vhdl-he-list-beg))
11849
11850;; function for expanding abbrevs and dabbrevs
3dcb36b7 11851(defun vhdl-expand-abbrev (arg))
5eabfe72
KH
11852(fset 'vhdl-expand-abbrev (make-hippie-expand-function
11853 '(try-expand-dabbrev
11854 try-expand-dabbrev-all-buffers
11855 vhdl-try-expand-abbrev)))
11856
11857;; function for expanding parenthesis
3dcb36b7 11858(defun vhdl-expand-paren (arg))
5eabfe72
KH
11859(fset 'vhdl-expand-paren (make-hippie-expand-function
11860 '(try-expand-list
11861 try-expand-list-all-buffers)))
11862
11863;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11864;; Case fixing
d2ddb974
KH
11865
11866(defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
11867 "Convert all words matching word-regexp in region to lower or upper case,
11868depending on parameter upper-case."
3dcb36b7 11869 (let ((case-replace nil)
5eabfe72 11870 (last-update 0))
3dcb36b7 11871 (vhdl-prepare-search-2
5eabfe72
KH
11872 (save-excursion
11873 (goto-char end)
11874 (setq end (point-marker))
11875 (goto-char beg)
11876 (while (re-search-forward word-regexp end t)
3dcb36b7 11877 (or (vhdl-in-literal)
5eabfe72
KH
11878 (if upper-case
11879 (upcase-word -1)
11880 (downcase-word -1)))
3dcb36b7 11881 (when (and count vhdl-progress-interval (not noninteractive)
5eabfe72
KH
11882 (< vhdl-progress-interval
11883 (- (nth 1 (current-time)) last-update)))
11884 (message "Fixing case... (%2d%s)"
11885 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
11886 "%")
11887 (setq last-update (nth 1 (current-time)))))
3dcb36b7 11888 (goto-char end)))))
d2ddb974
KH
11889
11890(defun vhdl-fix-case-region (beg end &optional arg)
11891 "Convert all VHDL words in region to lower or upper case, depending on
3dcb36b7 11892options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974
KH
11893 (interactive "r\nP")
11894 (vhdl-fix-case-region-1
5eabfe72 11895 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
d2ddb974 11896 (vhdl-fix-case-region-1
5eabfe72 11897 beg end vhdl-upper-case-types vhdl-types-regexp 1)
d2ddb974 11898 (vhdl-fix-case-region-1
5eabfe72
KH
11899 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
11900 (vhdl-fix-case-region-1
3dcb36b7
JB
11901 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
11902 (when vhdl-progress-interval (message "Fixing case...done")))
d2ddb974 11903
5eabfe72
KH
11904(defun vhdl-fix-case-buffer ()
11905 "Convert all VHDL words in buffer to lower or upper case, depending on
3dcb36b7 11906options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974 11907 (interactive)
5eabfe72
KH
11908 (vhdl-fix-case-region (point-min) (point-max)))
11909
3dcb36b7
JB
11910(defun vhdl-fix-case-word (&optional arg)
11911 "Convert word after cursor to upper case if necessary."
11912 (interactive "p")
11913 (save-excursion
11914 (when arg (backward-word 1))
11915 (vhdl-prepare-search-1
11916 (when (and vhdl-upper-case-keywords
11917 (looking-at vhdl-keywords-regexp))
11918 (upcase-word 1))
11919 (when (and vhdl-upper-case-types
11920 (looking-at vhdl-types-regexp))
11921 (upcase-word 1))
11922 (when (and vhdl-upper-case-attributes
11923 (looking-at vhdl-attributes-regexp))
11924 (upcase-word 1))
11925 (when (and vhdl-upper-case-enum-values
11926 (looking-at vhdl-enum-values-regexp))
11927 (upcase-word 1)))))
11928
5eabfe72
KH
11929;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11930;; Line handling functions
d2ddb974
KH
11931
11932(defun vhdl-current-line ()
11933 "Return the line number of the line containing point."
11934 (save-restriction
11935 (widen)
4bcb9c95 11936 (1+ (count-lines (point-min) (line-beginning-position)))))
d2ddb974 11937
5eabfe72 11938(defun vhdl-line-kill-entire (&optional arg)
d2ddb974 11939 "Delete entire line."
5eabfe72
KH
11940 (interactive "p")
11941 (beginning-of-line)
11942 (kill-line (or arg 1)))
11943
11944(defun vhdl-line-kill (&optional arg)
11945 "Kill current line."
11946 (interactive "p")
11947 (vhdl-line-kill-entire arg))
11948
11949(defun vhdl-line-copy (&optional arg)
11950 "Copy current line."
11951 (interactive "p")
11952 (save-excursion
11953 (beginning-of-line)
11954 (let ((position (point)))
11955 (forward-line (or arg 1))
11956 (copy-region-as-kill position (point)))))
11957
11958(defun vhdl-line-yank ()
11959 "Yank entire line."
d2ddb974 11960 (interactive)
5eabfe72
KH
11961 (beginning-of-line)
11962 (yank))
d2ddb974 11963
5eabfe72
KH
11964(defun vhdl-line-expand (&optional prefix-arg)
11965 "Hippie-expand current line."
11966 (interactive "P")
11967 (let ((case-fold-search t) (case-replace nil)
11968 (hippie-expand-try-functions-list
11969 '(try-expand-line try-expand-line-all-buffers)))
11970 (hippie-expand prefix-arg)))
11971
11972(defun vhdl-line-transpose-next (&optional arg)
11973 "Interchange this line with next line."
11974 (interactive "p")
11975 (forward-line 1)
11976 (transpose-lines (or arg 1))
11977 (forward-line -1))
11978
11979(defun vhdl-line-transpose-previous (&optional arg)
11980 "Interchange this line with previous line."
11981 (interactive "p")
11982 (forward-line 1)
11983 (transpose-lines (- 0 (or arg 0)))
11984 (forward-line -1))
11985
11986(defun vhdl-line-open ()
d2ddb974
KH
11987 "Open a new line and indent."
11988 (interactive)
5eabfe72
KH
11989 (end-of-line -0)
11990 (newline-and-indent))
d2ddb974 11991
3dcb36b7
JB
11992(defun vhdl-delete-indentation ()
11993 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
11994it works within comments too."
11995 (interactive)
11996 (let ((fill-prefix "-- "))
11997 (delete-indentation)))
d2ddb974 11998
5eabfe72 11999;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12000;; Move functions
d2ddb974 12001
3dcb36b7
JB
12002(defun vhdl-forward-same-indent ()
12003 "Move forward to next line with same indent."
12004 (interactive)
12005 (let ((pos (point))
12006 (indent (current-indentation)))
12007 (beginning-of-line 2)
12008 (while (and (not (eobp))
12009 (or (looking-at "^\\s-*\\(--.*\\)?$")
12010 (> (current-indentation) indent)))
12011 (beginning-of-line 2))
12012 (if (= (current-indentation) indent)
12013 (back-to-indentation)
12014 (message "No following line with same indent found in this block")
12015 (goto-char pos)
12016 nil)))
5eabfe72 12017
3dcb36b7
JB
12018(defun vhdl-backward-same-indent ()
12019 "Move backward to previous line with same indent."
12020 (interactive)
12021 (let ((pos (point))
12022 (indent (current-indentation)))
12023 (beginning-of-line -0)
12024 (while (and (not (bobp))
12025 (or (looking-at "^\\s-*\\(--.*\\)?$")
12026 (> (current-indentation) indent)))
12027 (beginning-of-line -0))
12028 (if (= (current-indentation) indent)
12029 (back-to-indentation)
12030 (message "No preceding line with same indent found in this block")
12031 (goto-char pos)
12032 nil)))
5eabfe72
KH
12033
12034;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
12035;; Statistics
12036
12037(defun vhdl-statistics-buffer ()
12038 "Get some file statistics."
12039 (interactive)
12040 (let ((no-stats 0)
12041 (no-code-lines 0)
12042 (no-lines (count-lines (point-min) (point-max))))
12043 (save-excursion
12044 ;; count statements
12045 (goto-char (point-min))
12046 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12047 (if (match-string 1)
12048 (goto-char (match-end 1))
12049 (setq no-stats (1+ no-stats))))
12050 ;; count code lines
12051 (goto-char (point-min))
12052 (while (not (eobp))
12053 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12054 (setq no-code-lines (1+ no-code-lines)))
12055 (beginning-of-line 2)))
12056 ;; print results
12057 (message "\n\
12058File statistics: \"%s\"\n\
12059---------------------\n\
12060# statements : %5d\n\
12061# code lines : %5d\n\
12062# total lines : %5d\n\ "
f35aff82 12063 (buffer-file-name) no-stats no-code-lines no-lines)))
3dcb36b7 12064
5eabfe72 12065;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12066;; Help functions
d2ddb974 12067
3dcb36b7
JB
12068(defun vhdl-re-search-forward (regexp &optional bound noerror count)
12069 "Like `re-search-forward', but does not match within literals."
12070 (let (pos)
12071 (save-excursion
12072 (while (and (setq pos (re-search-forward regexp bound noerror count))
12073 (vhdl-in-literal))))
12074 (when pos (goto-char pos))
12075 pos))
12076
12077(defun vhdl-re-search-backward (regexp &optional bound noerror count)
12078 "Like `re-search-backward', but does not match within literals."
12079 (let (pos)
12080 (save-excursion
12081 (while (and (setq pos (re-search-backward regexp bound noerror count))
12082 (vhdl-in-literal))))
12083 (when pos (goto-char pos))
12084 pos))
5eabfe72 12085
d2ddb974 12086
3dcb36b7
JB
12087;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12088;;; Project
12089;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12090
12091(defun vhdl-set-project (name)
12092 "Set current project to NAME."
12093 (interactive
12094 (list (let ((completion-ignore-case t))
12095 (completing-read "Project name: " vhdl-project-alist nil t))))
12096 (cond ((equal name "")
12097 (setq vhdl-project nil)
12098 (message "Current VHDL project: None"))
12099 ((assoc name vhdl-project-alist)
12100 (setq vhdl-project name)
12101 (message "Current VHDL project: \"%s\"" name))
12102 (t
12103 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12104 (vhdl-speedbar-update-current-project))
12105
12106(defun vhdl-toggle-project (name token indent)
12107 "Set current project to NAME or unset if NAME is current project."
12108 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12109
12110(defun vhdl-export-project (file-name)
12111 "Write project setup for current project."
12112 (interactive
12113 (let ((name (vhdl-resolve-env-variable
12114 (vhdl-replace-string
12115 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12116 (concat (subst-char-in-string
12117 ? ?_ (or (vhdl-project-p)
12118 (error "ERROR: No current project")))
12119 " " (user-login-name))))))
12120 (list (read-file-name
12121 "Write project file: "
12122 (when (file-name-absolute-p name) "") nil nil name))))
12123 (setq file-name (abbreviate-file-name file-name))
12124 (let ((orig-buffer (current-buffer)))
12125 (unless (file-exists-p (file-name-directory file-name))
12126 (make-directory (file-name-directory file-name) t))
12127 (if (not (file-writable-p file-name))
12128 (error "ERROR: File not writable: \"%s\"" file-name)
12129 (set-buffer (find-file-noselect file-name t t))
12130 (erase-buffer)
12131 (insert ";; -*- Emacs-Lisp -*-\n\n"
12132 ";;; " (file-name-nondirectory file-name)
12133 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12134 ";; Project : " vhdl-project "\n"
12135 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12136 (user-login-name) "\n\n\n"
12137 ";; project name\n"
12138 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12139 ";; project setup\n"
12140 "(aput 'vhdl-project-alist vhdl-project\n'")
12141 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12142 (insert ")\n")
12143 (save-buffer)
12144 (kill-buffer (current-buffer))
12145 (set-buffer orig-buffer))))
12146
12147(defun vhdl-import-project (file-name &optional auto not-make-current)
12148 "Read project setup and set current project."
12149 (interactive
12150 (let ((name (vhdl-resolve-env-variable
12151 (vhdl-replace-string
12152 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12153 (concat "" " " (user-login-name))))))
12154 (list (read-file-name
12155 "Read project file: " (when (file-name-absolute-p name) "") nil t
12156 (file-name-directory name)))))
12157 (when (file-exists-p file-name)
12158 (condition-case ()
12159 (let ((current-project vhdl-project))
12160 (load-file file-name)
12161 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12162 (adelete 'vhdl-project-alist vhdl-project)
12163 (error))
12164 (when not-make-current
12165 (setq vhdl-project current-project))
12166 (vhdl-update-mode-menu)
12167 (vhdl-speedbar-refresh)
12168 (unless not-make-current
12169 (message "Current VHDL project: \"%s\"%s"
12170 vhdl-project (if auto " (auto-loaded)" ""))))
12171 (error (vhdl-warning
12172 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12173
12174(defun vhdl-duplicate-project ()
12175 "Duplicate setup of current project."
5eabfe72 12176 (interactive)
3dcb36b7
JB
12177 (let ((new-name (read-from-minibuffer "New project name: "))
12178 (project-entry (aget vhdl-project-alist vhdl-project t)))
12179 (setq vhdl-project-alist
12180 (append vhdl-project-alist
12181 (list (cons new-name project-entry))))
12182 (vhdl-update-mode-menu)))
12183
12184(defun vhdl-auto-load-project ()
12185 "Automatically load project setup at startup."
12186 (let ((file-name-list vhdl-project-file-name)
12187 file-list list-length)
12188 (while file-name-list
12189 (setq file-list
12190 (append file-list
12191 (file-expand-wildcards
12192 (vhdl-resolve-env-variable
12193 (vhdl-replace-string
12194 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12195 (concat "\*" " " (user-login-name)))))))
12196 (setq list-length (or list-length (length file-list)))
12197 (setq file-name-list (cdr file-name-list)))
12198 (while file-list
12199 (vhdl-import-project (expand-file-name (car file-list)) t
12200 (not (> list-length 0)))
12201 (setq list-length (1- list-length))
12202 (setq file-list (cdr file-list)))))
12203
12204;; automatically load project setup when idle after startup
12205(when (memq 'startup vhdl-project-auto-load)
12206 (if noninteractive
12207 (vhdl-auto-load-project)
12208 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
5eabfe72
KH
12209
12210
12211;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12212;;; Hideshow
12213;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12214;; (using `hideshow.el')
d2ddb974 12215
3dcb36b7
JB
12216(defconst vhdl-hs-start-regexp
12217 (concat
12218 "\\(^\\)\\s-*\\("
12219 ;; generic/port clause
12220 "\\(generic\\|port\\)[ \t\n]*(\\|"
12221 ;; component
12222 "component\\>\\|"
12223 ;; component instantiation
12224 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12225 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12226 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12227 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12228 ;; subprogram
12229 "\\(function\\|procedure\\)\\>\\|"
12230 ;; process, block
12231 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12232 ;; configuration declaration
12233 "configuration\\>"
12234 "\\)")
12235 "Regexp to match start of construct to hide.")
12236
12237(defun vhdl-hs-forward-sexp-func (count)
12238 "Find end of construct to hide (for hideshow). Only searches forward."
12239 (let ((pos (point)))
12240 (vhdl-prepare-search-2
12241 (beginning-of-line)
12242 (cond
12243 ;; generic/port clause
12244 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12245 (goto-char (match-end 0))
12246 (backward-char)
12247 (forward-sexp))
12248 ;; component declaration
12249 ((looking-at "^\\s-*component\\>")
12250 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12251 ;; component instantiation
12252 ((looking-at
12253 (concat
12254 "^\\s-*\\w+\\s-*:[ \t\n]*"
12255 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12256 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12257 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12258 (goto-char (match-end 0))
12259 (backward-char)
12260 (forward-sexp)
12261 (setq pos (point))
12262 (vhdl-forward-syntactic-ws)
12263 (when (looking-at "port\\s-+map[ \t\n]*(")
12264 (goto-char (match-end 0))
12265 (backward-char)
12266 (forward-sexp)
12267 (setq pos (point)))
12268 (goto-char pos))
12269 ;; subprogram declaration/body
12270 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12271 (goto-char (match-end 0))
12272 (vhdl-forward-syntactic-ws)
12273 (when (looking-at "(")
12274 (forward-sexp))
12275 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12276 (vhdl-in-literal)))
12277 ;; subprogram body
12278 (when (match-string 2)
12279 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12280 (backward-word 1)
12281 (vhdl-forward-sexp)))
12282 ;; block (recursive)
12283 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12284 (goto-char (match-end 0))
12285 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12286 (match-beginning 2))
12287 (vhdl-hs-forward-sexp-func count)))
12288 ;; process
12289 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12290 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12291 ;; configuration declaration
12292 ((looking-at "^\\s-*configuration\\>")
12293 (forward-word 4)
12294 (vhdl-forward-sexp))
12295 (t (goto-char pos))))))
5eabfe72
KH
12296
12297(defun vhdl-hideshow-init ()
12298 "Initialize `hideshow'."
3dcb36b7
JB
12299 (when vhdl-hideshow-menu
12300 (vhdl-hs-minor-mode 1)))
12301
12302(defun vhdl-hs-minor-mode (&optional arg)
12303 "Toggle hideshow minor mode and update menu bar."
12304 (interactive "P")
12305 (require 'hideshow)
12306 ;; check for hideshow version 5.x
12307 (if (not (boundp 'hs-block-start-mdata-select))
12308 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12309 ;; initialize hideshow
12310 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12311 (setq hs-special-modes-alist
12312 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12313 'vhdl-hs-forward-sexp-func nil)
12314 hs-special-modes-alist)))
12315 (make-local-variable 'hs-minor-mode-hook)
12316 (if vhdl-hide-all-init
12317 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12318 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12319 (hs-minor-mode arg)
12320 (vhdl-mode-line-update))) ; hack to update menu bar
5eabfe72
KH
12321
12322
12323;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12324;;; Font locking
12325;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12326;; (using `font-lock.el')
12327
5eabfe72 12328;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12329;; Help functions
5eabfe72
KH
12330
12331(defun vhdl-within-translate-off ()
12332 "Return point if within translate-off region, else nil."
12333 (and (save-excursion
12334 (re-search-backward
12335 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12336 (equal "off" (match-string 1))
12337 (point)))
12338
12339(defun vhdl-start-translate-off (limit)
12340 "Return point before translate-off pragma if before LIMIT, else nil."
12341 (when (re-search-forward
12342 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12343 (match-beginning 0)))
12344
12345(defun vhdl-end-translate-off (limit)
12346 "Return point after translate-on pragma if before LIMIT, else nil."
12347 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12348
12349(defun vhdl-match-translate-off (limit)
12350 "Match a translate-off block, setting match-data and returning t, else nil."
12351 (when (< (point) limit)
12352 (let ((start (or (vhdl-within-translate-off)
12353 (vhdl-start-translate-off limit)))
12354 (case-fold-search t))
12355 (when start
12356 (let ((end (or (vhdl-end-translate-off limit) limit)))
12357 (set-match-data (list start end))
12358 (goto-char end))))))
12359
12360(defun vhdl-font-lock-match-item (limit)
12361 "Match, and move over, any declaration item after point. Adapted from
12362`font-lock-match-c-style-declaration-item-and-skip-to-next'."
12363 (condition-case nil
12364 (save-restriction
12365 (narrow-to-region (point-min) limit)
12366 ;; match item
3dcb36b7 12367 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5eabfe72
KH
12368 (save-match-data
12369 (goto-char (match-end 1))
12370 ;; move to next item
4e19eff0
SM
12371 (if (looking-at "\\s-*,")
12372 (goto-char (match-end 0))
5eabfe72
KH
12373 (end-of-line) t))))
12374 (error t)))
12375
12376;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12377;; Syntax definitions
12378
5eabfe72
KH
12379(defconst vhdl-font-lock-syntactic-keywords
12380 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12381 "Mark single quotes as having string quote syntax in 'c' instances.")
12382
d2ddb974
KH
12383(defvar vhdl-font-lock-keywords nil
12384 "Regular expressions to highlight in VHDL Mode.")
12385
3dcb36b7
JB
12386(defvar vhdl-font-lock-keywords-0
12387 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12388 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12389This does highlighting of template prompts and directives (pragmas).")
d2ddb974 12390
5eabfe72 12391(defvar vhdl-font-lock-keywords-1 nil
3dcb36b7 12392 ;; set in `vhdl-font-lock-init' because dependent on user options
5eabfe72
KH
12393 "For consideration as a value of `vhdl-font-lock-keywords'.
12394This does highlighting of keywords and standard identifiers.")
12395
12396(defconst vhdl-font-lock-keywords-2
d2ddb974
KH
12397 (list
12398 ;; highlight names of units, subprograms, and components when declared
12399 (list
12400 (concat
12401 "^\\s-*\\("
3dcb36b7
JB
12402 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12403 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
d2ddb974 12404 "\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12405 5 'font-lock-function-name-face)
12406
12407 ;; highlight entity names of architectures and configurations
12408 (list
12409 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12410 2 'font-lock-function-name-face)
d2ddb974
KH
12411
12412 ;; highlight labels of common constructs
12413 (list
12414 (concat
3dcb36b7
JB
12415 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12416 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12417 "postponed\\|process\\|"
5eabfe72
KH
12418 (when (vhdl-standard-p 'ams) "procedural\\|")
12419 "with\\|while"
3dcb36b7 12420 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\)*\\s-*<=\\)")
d2ddb974
KH
12421 1 'font-lock-function-name-face)
12422
5eabfe72 12423 ;; highlight label and component name of component instantiations
d2ddb974 12424 (list
5eabfe72 12425 (concat
3dcb36b7
JB
12426 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12427 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12428 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12429
12430 ;; highlight label and instantiated unit of component instantiations
12431 (list
12432 (concat
12433 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12434 "\\(component\\|configuration\\|entity\\)\\s-+"
12435 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12436 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12437 '(5 font-lock-function-name-face nil t)
12438 '(7 font-lock-function-name-face nil t))
d2ddb974
KH
12439
12440 ;; highlight names and labels at end of constructs
12441 (list
12442 (concat
5eabfe72
KH
12443 "^\\s-*end\\s-+\\(\\("
12444 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
3dcb36b7
JB
12445 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12446 "procedure\\|\\(postponed\\s-+\\)?process\\|"
5eabfe72
KH
12447 (when (vhdl-standard-p 'ams) "procedural\\|")
12448 "units"
3dcb36b7 12449 "\\)\\s-+\\)?\\(\\w*\\)")
5eabfe72
KH
12450 5 'font-lock-function-name-face)
12451
12452 ;; highlight labels in exit and next statements
12453 (list
12454 (concat
12455 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12456 3 'font-lock-function-name-face)
12457
12458 ;; highlight entity name in attribute specifications
12459 (list
12460 (concat
12461 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12462 1 'font-lock-function-name-face)
12463
3dcb36b7
JB
12464 ;; highlight labels in block and component specifications
12465 (list
12466 (concat
12467 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12468 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12469 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12470
12471 ;; highlight names in library clauses
12472 (list "^\\s-*library\\>"
12473 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12474
12475 ;; highlight names in use clauses
5eabfe72
KH
12476 (list
12477 (concat
3dcb36b7
JB
12478 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12479 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12480 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12481 '(7 font-lock-function-name-face nil t))
5eabfe72
KH
12482
12483 ;; highlight attribute name in attribute declarations/specifications
12484 (list
12485 (concat
12486 "^\\s-*attribute\\s-+\\(\\w+\\)")
12487 1 'vhdl-font-lock-attribute-face)
12488
12489 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12490 (list
12491 (concat
3dcb36b7 12492 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12493 3 'font-lock-type-face)
12494
12495 ;; highlight signal/variable/constant declaration names
12496 (list "\\(:[^=]\\)"
12497 '(vhdl-font-lock-match-item
12498 (progn (goto-char (match-beginning 1))
12499 (skip-syntax-backward " ")
12500 (skip-syntax-backward "w_")
12501 (skip-syntax-backward " ")
12502 (while (= (preceding-char) ?,)
12503 (backward-char 1)
12504 (skip-syntax-backward " ")
12505 (skip-syntax-backward "w_")
12506 (skip-syntax-backward " ")))
12507; (skip-chars-backward "^-(\n\";")
12508 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12509
3dcb36b7
JB
12510 ;; highlight formal parameters in component instantiations and subprogram
12511 ;; calls
12512 (list "\\(=>\\)"
12513 '(vhdl-font-lock-match-item
12514 (progn (goto-char (match-beginning 1))
12515 (skip-syntax-backward " ")
12516 (while (= (preceding-char) ?\)) (backward-sexp))
12517 (skip-syntax-backward "w_")
12518 (skip-syntax-backward " ")
12519 (when (memq (preceding-char) '(?n ?N))
12520 (goto-char (point-max))))
12521 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12522
12523 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12524 ;; variables
12525 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
5eabfe72
KH
12526 '(vhdl-font-lock-match-item
12527 (progn (goto-char (match-end 1)) (match-beginning 2))
12528 nil (1 font-lock-variable-name-face)))
d2ddb974 12529 )
5eabfe72
KH
12530 "For consideration as a value of `vhdl-font-lock-keywords'.
12531This does context sensitive highlighting of names and labels.")
d2ddb974 12532
5eabfe72 12533(defvar vhdl-font-lock-keywords-3 nil
3dcb36b7 12534 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12535 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72
KH
12536This does highlighting of words with special syntax.")
12537
12538(defvar vhdl-font-lock-keywords-4 nil
3dcb36b7 12539 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12540 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12541This does highlighting of additional reserved words.")
d2ddb974 12542
5eabfe72
KH
12543(defconst vhdl-font-lock-keywords-5
12544 ;; background highlight translate-off regions
12545 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12546 "For consideration as a value of `vhdl-font-lock-keywords'.
12547This does background highlighting of translate-off regions.")
12548
12549;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12550;; Font and color definitions
12551
5eabfe72 12552(defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
d2ddb974
KH
12553 "Face name to use for prompts.")
12554
5eabfe72
KH
12555(defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12556 "Face name to use for standardized attributes.")
12557
12558(defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12559 "Face name to use for standardized enumeration values.")
d2ddb974 12560
5eabfe72
KH
12561(defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12562 "Face name to use for standardized functions and packages.")
d2ddb974 12563
5eabfe72
KH
12564(defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12565 "Face name to use for directives.")
d2ddb974 12566
5eabfe72
KH
12567(defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12568 "Face name to use for additional reserved words.")
d2ddb974 12569
5eabfe72
KH
12570(defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12571 "Face name to use for translate-off regions.")
d2ddb974 12572
5eabfe72
KH
12573;; face names to use for words with special syntax.
12574(let ((syntax-alist vhdl-special-syntax-alist)
12575 name)
12576 (while syntax-alist
12577 (setq name (vhdl-function-name
12578 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
d4a5b644
GM
12579 (eval `(defvar ,name ',name
12580 ,(concat "Face name to use for "
12581 (nth 0 (car syntax-alist)) ".")))
5eabfe72
KH
12582 (setq syntax-alist (cdr syntax-alist))))
12583
3dcb36b7 12584(defgroup vhdl-highlight-faces nil
5eabfe72
KH
12585 "Faces for highlighting."
12586 :group 'vhdl-highlight)
d2ddb974 12587
3dcb36b7
JB
12588;; add faces used from `font-lock'
12589(custom-add-to-group
12590 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12591(custom-add-to-group
12592 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12593(custom-add-to-group
12594 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12595(custom-add-to-group
12596 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12597(custom-add-to-group
12598 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12599(custom-add-to-group
12600 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12601
d2ddb974 12602(defface vhdl-font-lock-prompt-face
ea81d57e
DN
12603 '((((min-colors 88) (class color) (background light))
12604 (:foreground "Red1" :bold t))
12605 (((class color) (background light)) (:foreground "Red" :bold t))
3dcb36b7 12606 (((class color) (background dark)) (:foreground "Pink" :bold t))
d2ddb974 12607 (t (:inverse-video t)))
5eabfe72
KH
12608 "Font lock mode face used to highlight prompts."
12609 :group 'vhdl-highlight-faces
d2ddb974
KH
12610 :group 'font-lock-highlighting-faces)
12611
12612(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12613 '((((class color) (background light)) (:foreground "Orchid"))
12614 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12615 (t (:italic t :bold t)))
5eabfe72
KH
12616 "Font lock mode face used to highlight standardized attributes."
12617 :group 'vhdl-highlight-faces
d2ddb974
KH
12618 :group 'font-lock-highlighting-faces)
12619
5eabfe72 12620(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12621 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12622 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12623 (t (:italic t :bold t)))
5eabfe72
KH
12624 "Font lock mode face used to highlight standardized enumeration values."
12625 :group 'vhdl-highlight-faces
d2ddb974
KH
12626 :group 'font-lock-highlighting-faces)
12627
5eabfe72 12628(defface vhdl-font-lock-function-face
3dcb36b7 12629 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12630 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12631 (t (:italic t :bold t)))
5eabfe72
KH
12632 "Font lock mode face used to highlight standardized functions and packages."
12633 :group 'vhdl-highlight-faces
d2ddb974
KH
12634 :group 'font-lock-highlighting-faces)
12635
5eabfe72
KH
12636(defface vhdl-font-lock-directive-face
12637 '((((class color) (background light)) (:foreground "CadetBlue"))
12638 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12639 (t (:italic t :bold t)))
5eabfe72
KH
12640 "Font lock mode face used to highlight directives."
12641 :group 'vhdl-highlight-faces
d2ddb974
KH
12642 :group 'font-lock-highlighting-faces)
12643
5eabfe72 12644(defface vhdl-font-lock-reserved-words-face
3dcb36b7 12645 '((((class color) (background light)) (:foreground "Orange" :bold t))
ea81d57e
DN
12646 (((min-colors 88) (class color) (background dark))
12647 (:foreground "Yellow1" :bold t))
3dcb36b7 12648 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12649 (t ()))
5eabfe72
KH
12650 "Font lock mode face used to highlight additional reserved words."
12651 :group 'vhdl-highlight-faces
d2ddb974
KH
12652 :group 'font-lock-highlighting-faces)
12653
5eabfe72
KH
12654(defface vhdl-font-lock-translate-off-face
12655 '((((class color) (background light)) (:background "LightGray"))
12656 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12657 (t ()))
5eabfe72
KH
12658 "Font lock mode face used to background highlight translate-off regions."
12659 :group 'vhdl-highlight-faces
d2ddb974
KH
12660 :group 'font-lock-highlighting-faces)
12661
5eabfe72
KH
12662;; font lock mode faces used to highlight words with special syntax.
12663(let ((syntax-alist vhdl-special-syntax-alist))
12664 (while syntax-alist
d4a5b644 12665 (eval `(defface ,(vhdl-function-name
3dcb36b7 12666 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12667 '((((class color) (background light))
12668 (:foreground ,(nth 2 (car syntax-alist))))
12669 (((class color) (background dark))
12670 (:foreground ,(nth 3 (car syntax-alist))))
12671 (t ()))
12672 ,(concat "Font lock mode face used to highlight "
12673 (nth 0 (car syntax-alist)) ".")
12674 :group 'vhdl-highlight-faces
12675 :group 'font-lock-highlighting-faces))
5eabfe72
KH
12676 (setq syntax-alist (cdr syntax-alist))))
12677
12678;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12679;; Font lock initialization
12680
12681(defun vhdl-font-lock-init ()
5eabfe72 12682 "Initialize fontification."
3dcb36b7
JB
12683 ;; highlight template prompts and directives
12684 (setq vhdl-font-lock-keywords-0
12685 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12686 vhdl-template-prompt-syntax ">\\)")
12687 2 'vhdl-font-lock-prompt-face t)
12688 (list (concat "--\\s-*"
12689 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12690 2 'vhdl-font-lock-directive-face t)))
5eabfe72
KH
12691 ;; highlight keywords and standardized types, attributes, enumeration
12692 ;; values, and subprograms
12693 (setq vhdl-font-lock-keywords-1
12694 (list
12695 (list (concat "'" vhdl-attributes-regexp)
12696 1 'vhdl-font-lock-attribute-face)
12697 (list vhdl-types-regexp 1 'font-lock-type-face)
12698 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12699 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12700 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12701 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12702 ;; highlight words with special syntax.
12703 (setq vhdl-font-lock-keywords-3
12704 (let ((syntax-alist vhdl-special-syntax-alist)
12705 keywords)
12706 (while syntax-alist
12707 (setq keywords
12708 (cons
12709 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12710 (vhdl-function-name
12711 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12712 keywords))
12713 (setq syntax-alist (cdr syntax-alist)))
12714 keywords))
12715 ;; highlight additional reserved words
12716 (setq vhdl-font-lock-keywords-4
12717 (list (list vhdl-reserved-words-regexp 1
12718 'vhdl-font-lock-reserved-words-face)))
12719 ;; highlight everything together
d2ddb974 12720 (setq vhdl-font-lock-keywords
5eabfe72
KH
12721 (append
12722 vhdl-font-lock-keywords-0
12723 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12724 (when (or vhdl-highlight-forbidden-words
12725 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12726 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12727 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12728 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12729
12730;; initialize fontification for VHDL Mode
12731(vhdl-font-lock-init)
12732
12733(defun vhdl-fontify-buffer ()
12734 "Re-initialize fontification and fontify buffer."
12735 (interactive)
12736 (setq font-lock-defaults
12737 (list
12738 'vhdl-font-lock-keywords nil
12739 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12740 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12741 (when (fboundp 'font-lock-unset-defaults)
12742 (font-lock-unset-defaults)) ; not implemented in XEmacs
4e19eff0 12743 (font-lock-set-defaults) ;What for? --Stef
3dcb36b7
JB
12744 (font-lock-mode nil)
12745 (font-lock-mode t))
5eabfe72
KH
12746
12747;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12748;; Initialization for postscript printing
12749
12750(defun vhdl-ps-print-settings ()
12751 "Initialize custom face and page settings for postscript printing."
12752 ;; define custom face settings
12753 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12754 ps-print-color-p)
12755 (set (make-local-variable 'ps-bold-faces)
12756 '(font-lock-keyword-face
12757 font-lock-type-face
12758 vhdl-font-lock-attribute-face
5eabfe72
KH
12759 vhdl-font-lock-enumvalue-face
12760 vhdl-font-lock-directive-face))
d2ddb974
KH
12761 (set (make-local-variable 'ps-italic-faces)
12762 '(font-lock-comment-face
12763 font-lock-function-name-face
12764 font-lock-type-face
d2ddb974 12765 vhdl-font-lock-attribute-face
5eabfe72
KH
12766 vhdl-font-lock-enumvalue-face
12767 vhdl-font-lock-directive-face))
d2ddb974
KH
12768 (set (make-local-variable 'ps-underlined-faces)
12769 '(font-lock-string-face))
5eabfe72 12770 (setq ps-always-build-face-reference t))
d2ddb974
KH
12771 ;; define page settings, so that a line containing 79 characters (default)
12772 ;; fits into one column
5eabfe72
KH
12773 (when vhdl-print-two-column
12774 (set (make-local-variable 'ps-landscape-mode) t)
12775 (set (make-local-variable 'ps-number-of-columns) 2)
12776 (set (make-local-variable 'ps-font-size) 7.0)
12777 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12778 (set (make-local-variable 'ps-header-font-size) 9.0)
12779 (set (make-local-variable 'ps-header-offset) 12.0)
12780 (when (eq ps-paper-type 'letter)
12781 (set (make-local-variable 'ps-inter-column) 40.0)
12782 (set (make-local-variable 'ps-left-margin) 40.0)
12783 (set (make-local-variable 'ps-right-margin) 40.0))))
12784
12785(defun vhdl-ps-print-init ()
12786 "Initialize postscript printing."
3dcb36b7
JB
12787 (if vhdl-xemacs
12788 (when (boundp 'ps-print-color-p)
12789 (vhdl-ps-print-settings))
5eabfe72
KH
12790 (make-local-variable 'ps-print-hook)
12791 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12792
12793
12794;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12795;;; Hierarchy browser (using `speedbar.el')
12796;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12797;; Allows displaying the hierarchy of all VHDL design units contained in a
12798;; directory by using the speedbar.
12799
12800;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12801;; Variables
12802
12803(defvar vhdl-entity-alist nil
3dcb36b7
JB
12804 "Cache with entities and corresponding architectures for each
12805project/directory.")
5eabfe72 12806;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12807;; (cache-key
12808;; (ent-key ent-name ent-file ent-line
12809;; (arch-key arch-name arch-file arch-line
12810;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12811;; inst-arch-key inst-conf-key inst-lib-key)
12812;; (lib-name pack-key))
12813;; (lib-name pack-key))
12814
12815(defvar vhdl-config-alist nil
12816 "Cache with configurations for each project/directory.")
12817;; structure: (parenthesised expression means list of such entries)
12818;; (cache-key
12819;; (conf-key conf-name conf-file conf-line ent-key arch-key
12820;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12821;; inst-conf-key inst-lib-key)
12822;; (lib-name pack-key)))
5eabfe72
KH
12823
12824(defvar vhdl-package-alist nil
3dcb36b7 12825 "Cache with packages for each project/directory.")
5eabfe72 12826;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12827;; (cache-key
12828;; (pack-key pack-name pack-file pack-line
12829;; (comp-key comp-name comp-file comp-line)
12830;; (func-key func-name func-file func-line)
12831;; (lib-name pack-key)
12832;; pack-body-file pack-body-line
12833;; (func-key func-name func-body-file func-body-line)
12834;; (lib-name pack-key)))
5eabfe72
KH
12835
12836(defvar vhdl-ent-inst-alist nil
3dcb36b7 12837 "Cache with instantiated entities for each project/directory.")
5eabfe72 12838;; structure: (parenthesised expression means list of such entries)
3dcb36b7 12839;; (cache-key (inst-ent-key))
5eabfe72 12840
3dcb36b7
JB
12841(defvar vhdl-file-alist nil
12842 "Cache with design units in each file for each project/directory.")
12843;; structure: (parenthesised expression means list of such entries)
12844;; (cache-key
12845;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
12846;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 12847
3dcb36b7
JB
12848(defvar vhdl-directory-alist nil
12849 "Cache with source directories for each project.")
12850;; structure: (parenthesised expression means list of such entries)
12851;; (cache-key (directory))
5eabfe72 12852
3dcb36b7 12853(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
12854 "Alist of design units simultaneously open in the current speedbar for each
12855directory and project.")
12856
3dcb36b7
JB
12857(defvar vhdl-speedbar-shown-project-list nil
12858 "List of projects simultaneously open in the current speedbar.")
5eabfe72 12859
3dcb36b7
JB
12860(defvar vhdl-updated-project-list nil
12861 "List of projects and directories with updated files.")
12862
12863(defvar vhdl-modified-file-list nil
12864 "List of modified files to be rescanned for hierarchy updating.")
12865
12866(defvar vhdl-speedbar-hierarchy-depth 0
12867 "Depth of instantiation hierarchy to display.")
12868
12869(defvar vhdl-speedbar-show-projects nil
12870 "Non-nil means project hierarchy is displayed in speedbar, directory
12871hierarchy otherwise.")
12872
12873(defun vhdl-get-end-of-unit ()
12874 "Return position of end of current unit."
12875 (let ((pos (point)))
12876 (save-excursion
12877 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
12878 (save-excursion
12879 (goto-char (match-beginning 0))
12880 (vhdl-backward-syntactic-ws)
12881 (and (/= (preceding-char) ?\;) (not (bobp))))))
12882 (re-search-backward "^[ \t]*end\\>" pos 1)
12883 (point))))
12884
12885(defun vhdl-match-string-downcase (num &optional string)
12886 "Like `match-string-no-properties' with down-casing."
12887 (let ((match (match-string-no-properties num string)))
12888 (and match (downcase match))))
5eabfe72 12889
5eabfe72
KH
12890
12891;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12892;; Scan functions
12893
3dcb36b7
JB
12894(defun vhdl-scan-context-clause ()
12895 "Scan the context clause that preceeds a design unit."
12896 (let (lib-alist)
12897 (save-excursion
12898 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
12899 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
12900 (equal "USE" (upcase (match-string 1))))
12901 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
12902 (setq lib-alist (cons (cons (match-string-no-properties 1)
12903 (vhdl-match-string-downcase 2))
12904 lib-alist))))))
12905 lib-alist))
12906
12907(defun vhdl-scan-directory-contents (name &optional project update num-string
12908 non-final)
12909 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
12910 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
12911; (unless (file-directory-p (match-string 1 name))
12912; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
12913 (let* ((dir-name (match-string 1 name))
12914 (file-pattern (match-string 2 name))
12915 (is-directory (= 0 (length file-pattern)))
5eabfe72 12916 (file-list
3dcb36b7
JB
12917 (if update
12918 (list name)
12919 (if is-directory
12920 (vhdl-get-source-files t dir-name)
12921 (vhdl-directory-files
12922 dir-name t (wildcard-to-regexp file-pattern)))))
12923 (key (or project dir-name))
12924 (file-exclude-regexp
12925 (or (nth 3 (aget vhdl-project-alist project)) ""))
12926 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
12927 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
12928 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
12929 ent-alist conf-alist pack-alist ent-inst-list file-alist
12930 tmp-list tmp-entry no-files files-exist big-files)
12931 (when (or project update)
12932 (setq ent-alist (aget vhdl-entity-alist key t)
12933 conf-alist (aget vhdl-config-alist key t)
12934 pack-alist (aget vhdl-package-alist key t)
12935 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
12936 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
12937 (when (and (not is-directory) (null file-list))
12938 (message "No such file: \"%s\"" name))
3dcb36b7
JB
12939 (setq files-exist file-list)
12940 (when file-list
12941 (setq no-files (length file-list))
12942 (message "Scanning %s %s\"%s\"..."
12943 (if is-directory "directory" "files") (or num-string "") name)
12944 ;; exclude files
12945 (unless (equal file-exclude-regexp "")
12946 (let ((case-fold-search nil)
12947 file-tmp-list)
12948 (while file-list
12949 (unless (string-match file-exclude-regexp (car file-list))
12950 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
12951 (setq file-list (cdr file-list)))
12952 (setq file-list (nreverse file-tmp-list))))
12953 ;; do for all files
12954 (while file-list
12955 (unless noninteractive
5eabfe72
KH
12956 (message "Scanning %s %s\"%s\"... (%2d%s)"
12957 (if is-directory "directory" "files")
12958 (or num-string "") name
3dcb36b7
JB
12959 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
12960 (let ((file-name (abbreviate-file-name (car file-list)))
12961 ent-list arch-list arch-ent-list conf-list
12962 pack-list pack-body-list inst-list inst-ent-list)
12963 ;; scan file
12964 (vhdl-visit-file
12965 file-name nil
12966 (vhdl-prepare-search-2
12967 (save-excursion
12968 ;; scan for design units
12969 (if (and limit-design-file-size
12970 (< limit-design-file-size (buffer-size)))
12971 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
12972 (setq big-files t))
12973 ;; scan for entities
12974 (goto-char (point-min))
12975 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12976 (let* ((ent-name (match-string-no-properties 1))
12977 (ent-key (downcase ent-name))
12978 (ent-entry (aget ent-alist ent-key t))
12979 (arch-alist (nth 3 ent-entry))
12980 (lib-alist (vhdl-scan-context-clause)))
12981 (if (nth 1 ent-entry)
12982 (vhdl-warning-when-idle
12983 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12984 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
12985 file-name (vhdl-current-line))
12986 (setq ent-list (cons ent-key ent-list))
12987 (aput 'ent-alist ent-key
12988 (list ent-name file-name (vhdl-current-line)
12989 arch-alist lib-alist)))))
12990 ;; scan for architectures
12991 (goto-char (point-min))
12992 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12993 (let* ((arch-name (match-string-no-properties 1))
12994 (arch-key (downcase arch-name))
12995 (ent-name (match-string-no-properties 2))
12996 (ent-key (downcase ent-name))
12997 (ent-entry (aget ent-alist ent-key t))
12998 (arch-alist (nth 3 ent-entry))
12999 (arch-entry (aget arch-alist arch-key t))
13000 (lib-arch-alist (vhdl-scan-context-clause)))
13001 (if arch-entry
13002 (vhdl-warning-when-idle
13003 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13004 arch-name ent-name (nth 1 arch-entry)
13005 (nth 2 arch-entry) file-name (vhdl-current-line))
13006 (setq arch-list (cons arch-key arch-list)
13007 arch-ent-list (cons ent-key arch-ent-list))
13008 (aput 'arch-alist arch-key
13009 (list arch-name file-name (vhdl-current-line) nil
13010 lib-arch-alist))
13011 (aput 'ent-alist ent-key
13012 (list (or (nth 0 ent-entry) ent-name)
13013 (nth 1 ent-entry) (nth 2 ent-entry)
13014 (vhdl-sort-alist arch-alist)
13015 (nth 4 ent-entry))))))
13016 ;; scan for configurations
13017 (goto-char (point-min))
13018 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13019 (let* ((conf-name (match-string-no-properties 1))
13020 (conf-key (downcase conf-name))
13021 (conf-entry (aget conf-alist conf-key t))
13022 (ent-name (match-string-no-properties 2))
13023 (ent-key (downcase ent-name))
13024 (lib-alist (vhdl-scan-context-clause))
13025 (conf-line (vhdl-current-line))
13026 (end-of-unit (vhdl-get-end-of-unit))
13027 arch-key comp-conf-list inst-key-list
13028 inst-comp-key inst-ent-key inst-arch-key
13029 inst-conf-key inst-lib-key)
13030 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13031 (setq arch-key (vhdl-match-string-downcase 1)))
13032 (if conf-entry
13033 (vhdl-warning-when-idle
13034 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13035 conf-name ent-name (nth 1 conf-entry)
13036 (nth 2 conf-entry) file-name conf-line)
13037 (setq conf-list (cons conf-key conf-list))
13038 ;; scan for subconfigurations and subentities
13039 (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)
13040 (setq inst-comp-key (vhdl-match-string-downcase 3)
13041 inst-key-list (split-string
13042 (vhdl-match-string-downcase 1)
13043 "[ \t\n]*,[ \t\n]*"))
13044 (vhdl-forward-syntactic-ws)
13045 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13046 (setq
13047 inst-lib-key (vhdl-match-string-downcase 3)
13048 inst-ent-key (and (match-string 2)
13049 (vhdl-match-string-downcase 4))
13050 inst-arch-key (and (match-string 2)
13051 (vhdl-match-string-downcase 6))
13052 inst-conf-key (and (not (match-string 2))
13053 (vhdl-match-string-downcase 4)))
13054 (while inst-key-list
13055 (setq comp-conf-list
13056 (cons (list (car inst-key-list)
13057 inst-comp-key inst-ent-key
13058 inst-arch-key inst-conf-key
13059 inst-lib-key)
13060 comp-conf-list))
13061 (setq inst-key-list (cdr inst-key-list)))))
13062 (aput 'conf-alist conf-key
13063 (list conf-name file-name conf-line ent-key
13064 arch-key comp-conf-list lib-alist)))))
13065 ;; scan for packages
13066 (goto-char (point-min))
13067 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13068 (let* ((pack-name (match-string-no-properties 2))
13069 (pack-key (downcase pack-name))
13070 (is-body (match-string-no-properties 1))
13071 (pack-entry (aget pack-alist pack-key t))
13072 (pack-line (vhdl-current-line))
13073 (end-of-unit (vhdl-get-end-of-unit))
13074 comp-name func-name comp-alist func-alist lib-alist)
13075 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13076 (vhdl-warning-when-idle
13077 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13078 (if is-body " body" "") pack-name
13079 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13080 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13081 file-name (vhdl-current-line))
13082 ;; scan for context clauses
13083 (setq lib-alist (vhdl-scan-context-clause))
13084 ;; scan for component and subprogram declarations/bodies
13085 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13086 (if (equal (upcase (match-string 1)) "COMPONENT")
13087 (setq comp-name (match-string-no-properties 2)
13088 comp-alist
13089 (cons (list (downcase comp-name) comp-name
13090 file-name (vhdl-current-line))
13091 comp-alist))
13092 (setq func-name (match-string-no-properties 2)
13093 func-alist
13094 (cons (list (downcase func-name) func-name
13095 file-name (vhdl-current-line))
13096 func-alist))))
13097 (setq func-alist (nreverse func-alist))
13098 (setq comp-alist (nreverse comp-alist))
13099 (if is-body
13100 (setq pack-body-list (cons pack-key pack-body-list))
13101 (setq pack-list (cons pack-key pack-list)))
13102 (aput
13103 'pack-alist pack-key
13104 (if is-body
13105 (list (or (nth 0 pack-entry) pack-name)
13106 (nth 1 pack-entry) (nth 2 pack-entry)
13107 (nth 3 pack-entry) (nth 4 pack-entry)
13108 (nth 5 pack-entry)
13109 file-name pack-line func-alist lib-alist)
13110 (list pack-name file-name pack-line
13111 comp-alist func-alist lib-alist
13112 (nth 6 pack-entry) (nth 7 pack-entry)
13113 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13114 ;; scan for hierarchy
13115 (if (and limit-hier-file-size
13116 (< limit-hier-file-size (buffer-size)))
13117 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13118 (setq big-files t))
13119 ;; scan for architectures
13120 (goto-char (point-min))
13121 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13122 (let* ((ent-name (match-string-no-properties 2))
13123 (ent-key (downcase ent-name))
13124 (arch-name (match-string-no-properties 1))
13125 (arch-key (downcase arch-name))
13126 (ent-entry (aget ent-alist ent-key t))
13127 (arch-alist (nth 3 ent-entry))
13128 (arch-entry (aget arch-alist arch-key t))
13129 (beg-of-unit (point))
13130 (end-of-unit (vhdl-get-end-of-unit))
13131 (inst-no 0)
13132 inst-alist)
13133 ;; scan for contained instantiations
13134 (while (and (re-search-forward
13135 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13136 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13137 "component[ \t\n]+\\(\\w+\\)\\|"
13138 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\)") end-of-unit t)
13139 (or (not limit-hier-inst-no)
13140 (<= (setq inst-no (1+ inst-no))
13141 limit-hier-inst-no)))
13142 (let* ((inst-name (match-string-no-properties 1))
13143 (inst-key (downcase inst-name))
13144 (inst-comp-name
13145 (or (match-string-no-properties 3)
13146 (match-string-no-properties 6)))
13147 (inst-ent-key
13148 (or (and (match-string 8)
13149 (vhdl-match-string-downcase 11))
13150 (and inst-comp-name
13151 (downcase inst-comp-name))))
13152 (inst-arch-key (vhdl-match-string-downcase 13))
13153 (inst-conf-key
13154 (and (not (match-string 8))
13155 (vhdl-match-string-downcase 11)))
13156 (inst-lib-key (vhdl-match-string-downcase 10)))
13157 (goto-char (match-end 1))
13158 (setq inst-list (cons inst-key inst-list)
13159 inst-ent-list (cons inst-ent-key inst-ent-list))
13160 (setq inst-alist
13161 (append
13162 inst-alist
13163 (list (list inst-key inst-name file-name
13164 (vhdl-current-line) inst-comp-name
13165 inst-ent-key inst-arch-key
13166 inst-conf-key inst-lib-key))))))
13167 ;; scan for contained configuration specifications
13168 (goto-char beg-of-unit)
13169 (while (re-search-forward
13170 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13171 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13172 (let* ((inst-comp-name (match-string-no-properties 3))
13173 (inst-ent-key
13174 (and (match-string 6)
13175 (vhdl-match-string-downcase 9)))
13176 (inst-arch-key (vhdl-match-string-downcase 11))
13177 (inst-conf-key
13178 (and (not (match-string 6))
13179 (vhdl-match-string-downcase 9)))
13180 (inst-lib-key (vhdl-match-string-downcase 8))
13181 (inst-key-list
13182 (split-string (vhdl-match-string-downcase 1)
13183 "[ \t\n]*,[ \t\n]*"))
13184 (tmp-inst-alist inst-alist)
13185 inst-entry)
13186 (while tmp-inst-alist
13187 (when (and (or (equal "all" (car inst-key-list))
13188 (member (nth 0 (car tmp-inst-alist))
13189 inst-key-list))
13190 (equal
13191 (downcase
13192 (or (nth 4 (car tmp-inst-alist)) ""))
13193 (downcase inst-comp-name)))
13194 (setq inst-entry (car tmp-inst-alist))
13195 (setq inst-ent-list
13196 (cons (or inst-ent-key (nth 5 inst-entry))
13197 (vhdl-delete
13198 (nth 5 inst-entry) inst-ent-list)))
13199 (setq inst-entry
13200 (list (nth 0 inst-entry) (nth 1 inst-entry)
13201 (nth 2 inst-entry) (nth 3 inst-entry)
13202 (nth 4 inst-entry)
13203 (or inst-ent-key (nth 5 inst-entry))
13204 (or inst-arch-key (nth 6 inst-entry))
13205 inst-conf-key inst-lib-key))
13206 (setcar tmp-inst-alist inst-entry))
13207 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13208 ;; save in cache
13209 (aput 'arch-alist arch-key
13210 (list (nth 0 arch-entry) (nth 1 arch-entry)
13211 (nth 2 arch-entry) inst-alist
13212 (nth 4 arch-entry)))
13213 (aput 'ent-alist ent-key
13214 (list (nth 0 ent-entry) (nth 1 ent-entry)
13215 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13216 (nth 4 ent-entry)))
13217 (when (and limit-hier-inst-no
13218 (> inst-no limit-hier-inst-no))
13219 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13220 (setq big-files t))
13221 (goto-char end-of-unit))))
13222 ;; remember design units for this file
13223 (aput 'file-alist file-name
13224 (list ent-list arch-list arch-ent-list conf-list
13225 pack-list pack-body-list inst-list inst-ent-list))
13226 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13227 (setq file-list (cdr file-list))))
13228 (when (or (and (not project) files-exist)
13229 (and project (not non-final)))
13230 ;; consistency checks:
13231 ;; check whether each architecture has a corresponding entity
13232 (setq tmp-list ent-alist)
13233 (while tmp-list
13234 (when (null (nth 2 (car tmp-list)))
13235 (setq tmp-entry (car (nth 4 (car tmp-list))))
13236 (vhdl-warning-when-idle
13237 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13238 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13239 (nth 3 tmp-entry)))
13240 (setq tmp-list (cdr tmp-list)))
13241 ;; check whether configuration has a corresponding entity/architecture
13242 (setq tmp-list conf-alist)
13243 (while tmp-list
13244 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13245 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13246 (setq tmp-entry (car tmp-list))
13247 (vhdl-warning-when-idle
13248 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13249 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13250 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13251 (setq tmp-entry (car tmp-list))
13252 (vhdl-warning-when-idle
13253 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13254 (nth 1 tmp-entry) (nth 4 tmp-entry)
13255 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13256 (setq tmp-list (cdr tmp-list)))
13257 ;; check whether each package body has a package declaration
13258 (setq tmp-list pack-alist)
13259 (while tmp-list
13260 (when (null (nth 2 (car tmp-list)))
13261 (setq tmp-entry (car tmp-list))
13262 (vhdl-warning-when-idle
13263 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13264 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13265 (setq tmp-list (cdr tmp-list)))
13266 ;; sort lists
13267 (setq ent-alist (vhdl-sort-alist ent-alist))
13268 (setq conf-alist (vhdl-sort-alist conf-alist))
13269 (setq pack-alist (vhdl-sort-alist pack-alist))
13270 ;; remember updated directory/project
13271 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13272 ;; clear directory alists
13273 (unless project
13274 (adelete 'vhdl-entity-alist key)
13275 (adelete 'vhdl-config-alist key)
13276 (adelete 'vhdl-package-alist key)
13277 (adelete 'vhdl-ent-inst-alist key)
13278 (adelete 'vhdl-file-alist key))
13279 ;; put directory contents into cache
13280 (aput 'vhdl-entity-alist key ent-alist)
13281 (aput 'vhdl-config-alist key conf-alist)
13282 (aput 'vhdl-package-alist key pack-alist)
13283 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13284 (aput 'vhdl-file-alist key file-alist)
13285 ;; final messages
13286 (message "Scanning %s %s\"%s\"...done"
13287 (if is-directory "directory" "files") (or num-string "") name)
13288 (unless project (message "Scanning directory...done"))
13289 (when big-files
13290 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13291 ;; save cache when scanned non-interactively
13292 (when (or (not project) (not non-final))
13293 (when (and noninteractive vhdl-speedbar-save-cache)
13294 (vhdl-save-cache key)))
13295 t))
5eabfe72 13296
3dcb36b7 13297(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13298 "Scan the contents of all VHDL files found in the directories and files
13299of PROJECT."
3dcb36b7
JB
13300 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13301 (default-dir (vhdl-resolve-env-variable
13302 (nth 1 (aget vhdl-project-alist project))))
13303 (file-exclude-regexp
13304 (or (nth 3 (aget vhdl-project-alist project)) ""))
13305 dir-list-tmp dir dir-name num-dir act-dir recursive)
13306 ;; clear project alists
13307 (adelete 'vhdl-entity-alist project)
13308 (adelete 'vhdl-config-alist project)
13309 (adelete 'vhdl-package-alist project)
13310 (adelete 'vhdl-ent-inst-alist project)
13311 (adelete 'vhdl-file-alist project)
13312 ;; expand directory names by default-directory
13313 (message "Collecting source files...")
13314 (while dir-list
13315 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13316 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13317 (setq recursive (match-string 1 dir)
13318 dir-name (match-string 3 dir))
13319 (setq dir-list-tmp
13320 (cons (concat recursive
13321 (if (file-name-absolute-p dir-name) "" default-dir)
13322 dir-name)
13323 dir-list-tmp))
13324 (setq dir-list (cdr dir-list)))
13325 ;; resolve path wildcards
5eabfe72
KH
13326 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13327 ;; expand directories
13328 (while dir-list-tmp
13329 (setq dir (car dir-list-tmp))
13330 ;; get subdirectories
3dcb36b7 13331 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13332 (setq dir-list (append dir-list (vhdl-get-subdirs
13333 (match-string 1 dir))))
13334 (setq dir-list (append dir-list (list dir))))
13335 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13336 ;; exclude files
13337 (unless (equal file-exclude-regexp "")
13338 (let ((case-fold-search nil))
13339 (while dir-list
13340 (unless (string-match file-exclude-regexp (car dir-list))
13341 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13342 (setq dir-list (cdr dir-list)))
13343 (setq dir-list (nreverse dir-list-tmp))))
13344 (message "Collecting source files...done")
13345 ;; scan for design units for each directory in DIR-LIST
13346 (setq dir-list-tmp nil
13347 num-dir (length dir-list)
5eabfe72
KH
13348 act-dir 1)
13349 (while dir-list
3dcb36b7
JB
13350 (setq dir-name (abbreviate-file-name
13351 (expand-file-name (car dir-list))))
13352 (vhdl-scan-directory-contents dir-name project nil
13353 (format "(%s/%s) " act-dir num-dir)
13354 (cdr dir-list))
13355 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13356 (setq dir-list (cdr dir-list)
13357 act-dir (1+ act-dir)))
3dcb36b7
JB
13358 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13359 (message "Scanning project \"%s\"...done" project)))
13360
13361(defun vhdl-update-file-contents (file-name)
13362 "Update hierarchy information by contents of current buffer."
13363 (setq file-name (abbreviate-file-name file-name))
13364 (let* ((dir-name (file-name-directory file-name))
13365 (directory-alist vhdl-directory-alist)
13366 updated)
13367 (while directory-alist
13368 (when (member dir-name (nth 1 (car directory-alist)))
13369 (let* ((vhdl-project (nth 0 (car directory-alist)))
13370 (project (vhdl-project-p))
13371 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13372 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13373 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13374 (ent-inst-list (car (aget vhdl-ent-inst-alist
13375 (or project dir-name) t)))
13376 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13377 (file-entry (aget file-alist file-name t))
13378 (ent-list (nth 0 file-entry))
13379 (arch-list (nth 1 file-entry))
13380 (arch-ent-list (nth 2 file-entry))
13381 (conf-list (nth 3 file-entry))
13382 (pack-list (nth 4 file-entry))
13383 (pack-body-list (nth 5 file-entry))
13384 (inst-ent-list (nth 7 file-entry))
13385 (cache-key (or project dir-name))
13386 arch-alist key ent-key entry)
13387 ;; delete design units previously contained in this file:
13388 ;; entities
13389 (while ent-list
13390 (setq key (car ent-list)
13391 entry (aget ent-alist key t))
13392 (when (equal file-name (nth 1 entry))
13393 (if (nth 3 entry)
13394 (aput 'ent-alist key
13395 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13396 (adelete 'ent-alist key)))
13397 (setq ent-list (cdr ent-list)))
13398 ;; architectures
13399 (while arch-list
13400 (setq key (car arch-list)
13401 ent-key (car arch-ent-list)
13402 entry (aget ent-alist ent-key t)
13403 arch-alist (nth 3 entry))
13404 (when (equal file-name (nth 1 (aget arch-alist key t)))
13405 (adelete 'arch-alist key)
13406 (if (or (nth 1 entry) arch-alist)
13407 (aput 'ent-alist ent-key
13408 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13409 arch-alist (nth 4 entry)))
13410 (adelete 'ent-alist ent-key)))
13411 (setq arch-list (cdr arch-list)
13412 arch-ent-list (cdr arch-ent-list)))
13413 ;; configurations
13414 (while conf-list
13415 (setq key (car conf-list))
13416 (when (equal file-name (nth 1 (aget conf-alist key t)))
13417 (adelete 'conf-alist key))
13418 (setq conf-list (cdr conf-list)))
13419 ;; package declarations
13420 (while pack-list
13421 (setq key (car pack-list)
13422 entry (aget pack-alist key t))
13423 (when (equal file-name (nth 1 entry))
13424 (if (nth 6 entry)
13425 (aput 'pack-alist key
13426 (list (nth 0 entry) nil nil nil nil nil
13427 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13428 (nth 9 entry)))
13429 (adelete 'pack-alist key)))
13430 (setq pack-list (cdr pack-list)))
13431 ;; package bodies
13432 (while pack-body-list
13433 (setq key (car pack-body-list)
13434 entry (aget pack-alist key t))
13435 (when (equal file-name (nth 6 entry))
13436 (if (nth 1 entry)
13437 (aput 'pack-alist key
13438 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13439 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13440 nil nil nil nil))
13441 (adelete 'pack-alist key)))
13442 (setq pack-body-list (cdr pack-body-list)))
13443 ;; instantiated entities
13444 (while inst-ent-list
13445 (setq ent-inst-list
13446 (vhdl-delete (car inst-ent-list) ent-inst-list))
13447 (setq inst-ent-list (cdr inst-ent-list)))
13448 ;; update caches
13449 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13450 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13451 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13452 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13453 ;; scan file
13454 (vhdl-scan-directory-contents file-name project t)
13455 (when (or (and vhdl-speedbar-show-projects project)
13456 (and (not vhdl-speedbar-show-projects) (not project)))
13457 (vhdl-speedbar-refresh project))
13458 (setq updated t)))
13459 (setq directory-alist (cdr directory-alist)))
13460 updated))
13461
13462(defun vhdl-update-hierarchy ()
13463 "Update directory and hierarchy information in speedbar."
13464 (let ((file-list (reverse vhdl-modified-file-list))
13465 updated)
13466 (when (and vhdl-speedbar-update-on-saving file-list)
13467 (while file-list
13468 (setq updated
13469 (or (vhdl-update-file-contents (car file-list))
13470 updated))
13471 (setq file-list (cdr file-list)))
13472 (setq vhdl-modified-file-list nil)
13473 (when updated (message "Updating hierarchy...done")))))
13474
13475;; structure (parenthesised expression means list of such entries)
13476;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13477;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13478;; comp-lib-name level)
13479(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13480 conf-inst-alist level indent
13481 &optional include-top ent-hier)
13482 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13483entity ENT-KEY."
13484 (let* ((ent-entry (aget ent-alist ent-key t))
13485 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13486 (cdar (last (nth 3 ent-entry)))))
13487 (inst-alist (nth 3 arch-entry))
13488 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13489 hier-list subcomp-list tmp-list inst-key inst-comp-name
13490 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13491 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13492 (when include-top
13493 (setq level (1+ level)))
13494 (when (member ent-key ent-hier)
13495 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13496 ;; check configured architecture (already checked during scanning)
13497; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13498; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13499 ;; process all instances
13500 (while inst-alist
13501 (setq inst-entry (car inst-alist)
13502 inst-key (nth 0 inst-entry)
13503 inst-comp-name (nth 4 inst-entry)
13504 inst-conf-key (nth 7 inst-entry))
13505 ;; search entry in configuration's instantiations list
13506 (setq tmp-list conf-inst-alist)
13507 (while (and tmp-list
13508 (not (and (member (nth 0 (car tmp-list))
13509 (list "all" inst-key))
13510 (equal (nth 1 (car tmp-list))
13511 (downcase (or inst-comp-name ""))))))
13512 (setq tmp-list (cdr tmp-list)))
13513 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13514 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13515 (when (and inst-conf-key (not inst-conf-entry))
13516 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13517 ;; determine entity
13518 (setq inst-ent-key
13519 (or (nth 2 (car tmp-list)) ; from configuration
13520 (nth 3 inst-conf-entry) ; from subconfiguration
13521 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13522 ; from configuration spec.
13523 (nth 5 inst-entry))) ; from direct instantiation
13524 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13525 ;; determine architecture
13526 (setq inst-arch-key
13527 (or (nth 3 (car tmp-list)) ; from configuration
13528 (nth 4 inst-conf-entry) ; from subconfiguration
13529 (nth 6 inst-entry) ; from direct instantiation
13530 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13531 ; from configuration spec.
13532 (caar (nth 3 inst-ent-entry)))) ; random (simplified MRA)
13533 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13534 ;; set library
13535 (setq inst-lib-key
13536 (or (nth 5 (car tmp-list)) ; from configuration
13537 (nth 8 inst-entry))) ; from direct instantiation
13538 ;; gather information for this instance
13539 (setq comp-entry
13540 (list (nth 1 inst-entry)
13541 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13542 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13543 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13544 (or (nth 0 inst-arch-entry) inst-arch-key)
13545 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13546 (or (nth 0 inst-conf-entry) inst-conf-key)
13547 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13548 inst-lib-key level))
13549 ;; get subcomponent hierarchy
13550 (setq subcomp-list (vhdl-get-hierarchy
13551 ent-alist conf-alist
13552 inst-ent-key inst-arch-key inst-conf-key
13553 (nth 5 inst-conf-entry)
13554 (1+ level) indent nil (cons ent-key ent-hier)))
13555 ;; add to list
13556 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13557 (setq inst-alist (cdr inst-alist)))
13558 (when include-top
5eabfe72 13559 (setq hier-list
3dcb36b7
JB
13560 (cons (list nil nil (nth 0 ent-entry)
13561 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13562 (nth 0 arch-entry)
13563 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13564 nil nil
13565 nil (1- level))
13566 hier-list)))
13567 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13568 hier-list))
13569
3dcb36b7
JB
13570(defun vhdl-get-instantiations (ent-key indent)
13571 "Get all instantiations of entity ENT-KEY."
13572 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13573 arch-alist inst-alist ent-inst-list
13574 ent-entry arch-entry inst-entry)
13575 (while ent-alist
13576 (setq ent-entry (car ent-alist))
3dcb36b7 13577 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13578 (while arch-alist
13579 (setq arch-entry (car arch-alist))
3dcb36b7 13580 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13581 (while inst-alist
13582 (setq inst-entry (car inst-alist))
3dcb36b7 13583 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13584 (setq ent-inst-list
3dcb36b7
JB
13585 (cons (list (nth 1 inst-entry)
13586 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13587 (nth 1 ent-entry)
13588 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13589 (nth 1 arch-entry)
13590 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13591 ent-inst-list)))
5eabfe72
KH
13592 (setq inst-alist (cdr inst-alist)))
13593 (setq arch-alist (cdr arch-alist)))
13594 (setq ent-alist (cdr ent-alist)))
13595 (nreverse ent-inst-list)))
13596
13597;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13598;; Caching in file
13599
13600(defun vhdl-save-caches ()
13601 "Save all updated hierarchy caches to file."
13602 (interactive)
13603 (condition-case nil
13604 (when vhdl-speedbar-save-cache
13605 ;; update hierarchy
13606 (vhdl-update-hierarchy)
13607 (let ((project-list vhdl-updated-project-list))
13608 (message "Saving hierarchy caches...")
13609 ;; write updated project caches
13610 (while project-list
13611 (vhdl-save-cache (car project-list))
13612 (setq project-list (cdr project-list)))
13613 (message "Saving hierarchy caches...done")))
13614 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13615 (sit-for 2)))))
13616
13617(defun vhdl-save-cache (key)
13618 "Save current hierarchy cache to file."
13619 (let* ((orig-buffer (current-buffer))
13620 (vhdl-project key)
13621 (project (vhdl-project-p))
13622 (default-directory key)
13623 (directory (abbreviate-file-name (vhdl-default-directory)))
13624 (file-name (vhdl-resolve-env-variable
13625 (vhdl-replace-string
13626 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13627 (concat
13628 (subst-char-in-string ? ?_ (or project "dir"))
13629 " " (user-login-name)))))
13630 (file-dir-name (expand-file-name file-name directory))
13631 (cache-key (or project directory))
13632 (key (if project "project" "directory")))
13633 (unless (file-exists-p (file-name-directory file-dir-name))
13634 (make-directory (file-name-directory file-dir-name) t))
13635 (if (not (file-writable-p file-dir-name))
13636 (progn (vhdl-warning (format "File not writable: \"%s\""
13637 (abbreviate-file-name file-dir-name)))
13638 (sit-for 2))
13639 (message "Saving cache: \"%s\"" file-dir-name)
13640 (set-buffer (find-file-noselect file-dir-name t t))
13641 (erase-buffer)
13642 (insert ";; -*- Emacs-Lisp -*-\n\n"
13643 ";;; " (file-name-nondirectory file-name)
13644 " - design hierarchy cache file for Emacs VHDL Mode "
13645 vhdl-version "\n")
13646 (insert "\n;; " (if project "Project " "Directory") " : ")
13647 (if project (insert project) (prin1 directory (current-buffer)))
13648 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13649 (user-login-name) "\n\n"
13650 "\n;; version number\n"
13651 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13652 "\n;; " (if project "project" "directory") " name"
13653 "\n(setq " key " ")
13654 (prin1 (or project directory) (current-buffer))
13655 (insert ")\n")
13656 (when (member 'hierarchy vhdl-speedbar-save-cache)
13657 (insert "\n;; entity and architecture cache\n"
13658 "(aput 'vhdl-entity-alist " key " '")
13659 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13660 (insert ")\n\n;; configuration cache\n"
13661 "(aput 'vhdl-config-alist " key " '")
13662 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13663 (insert ")\n\n;; package cache\n"
13664 "(aput 'vhdl-package-alist " key " '")
13665 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13666 (insert ")\n\n;; instantiated entities cache\n"
13667 "(aput 'vhdl-ent-inst-alist " key " '")
13668 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13669 (insert ")\n\n;; design units per file cache\n"
13670 "(aput 'vhdl-file-alist " key " '")
13671 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13672 (when project
13673 (insert ")\n\n;; source directories in project cache\n"
13674 "(aput 'vhdl-directory-alist " key " '")
13675 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13676 (insert ")\n"))
13677 (when (member 'display vhdl-speedbar-save-cache)
13678 (insert "\n;; shown design units cache\n"
13679 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13680 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13681 (current-buffer))
13682 (insert ")\n"))
13683 (setq vhdl-updated-project-list
13684 (delete cache-key vhdl-updated-project-list))
13685 (save-buffer)
13686 (kill-buffer (current-buffer))
13687 (set-buffer orig-buffer))))
13688
13689(defun vhdl-load-cache (key)
13690 "Load hierarchy cache information from file."
13691 (let* ((vhdl-project key)
13692 (default-directory key)
13693 (directory (vhdl-default-directory))
13694 (file-name (vhdl-resolve-env-variable
13695 (vhdl-replace-string
13696 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13697 (concat
13698 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13699 " " (user-login-name)))))
13700 (file-dir-name (expand-file-name file-name directory))
13701 vhdl-cache-version)
13702 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13703 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13704 (when (file-exists-p file-dir-name)
13705 (condition-case ()
13706 (progn (load-file file-dir-name)
13707 (string< (mapconcat
027a4b6b 13708 (lambda (a) (format "%3d" (string-to-number a)))
3dcb36b7
JB
13709 (split-string "3.31.14" "\\.") "")
13710 (mapconcat
027a4b6b 13711 (lambda (a) (format "%3d" (string-to-number a)))
3dcb36b7
JB
13712 (split-string vhdl-cache-version "\\.") "")))
13713 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13714 nil))))))
13715
13716(defun vhdl-require-hierarchy-info ()
13717 "Make sure that hierarchy information is available. Load cache or scan files
13718if required."
13719 (if (vhdl-project-p)
13720 (unless (or (assoc vhdl-project vhdl-file-alist)
13721 (vhdl-load-cache vhdl-project))
13722 (vhdl-scan-project-contents vhdl-project))
13723 (let ((directory (abbreviate-file-name default-directory)))
13724 (unless (or (assoc directory vhdl-file-alist)
13725 (vhdl-load-cache directory))
13726 (vhdl-scan-directory-contents directory)))))
13727
13728;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13729;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13730
13731(defvar vhdl-speedbar-key-map nil
13732 "Keymap used when in the VHDL hierarchy browser mode.")
13733
3dcb36b7 13734(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13735 "Additional menu-items to add to speedbar frame.")
13736
13737(defun vhdl-speedbar-initialize ()
13738 "Initialize speedbar."
13739 ;; general settings
13740; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13741 ;; VHDL file extensions (extracted from `auto-mode-alist')
13742 (let ((mode-alist auto-mode-alist))
13743 (while mode-alist
3dcb36b7
JB
13744 (when (eq (cdar mode-alist) 'vhdl-mode)
13745 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13746 (setq mode-alist (cdr mode-alist))))
13747 ;; hierarchy browser settings
13748 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13749 ;; special functions
5eabfe72 13750 (speedbar-add-mode-functions-list
3dcb36b7 13751 '("vhdl directory"
5eabfe72
KH
13752 (speedbar-item-info . vhdl-speedbar-item-info)
13753 (speedbar-line-path . speedbar-files-line-path)))
3dcb36b7
JB
13754 (speedbar-add-mode-functions-list
13755 '("vhdl project"
13756 (speedbar-item-info . vhdl-speedbar-item-info)
13757 (speedbar-line-path . vhdl-speedbar-line-project)))
13758 ;; keymap
5eabfe72
KH
13759 (unless vhdl-speedbar-key-map
13760 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13761 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13762 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13763 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
13764 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13765 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13766 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13767 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13768 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13769 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13770 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13771 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13772 (let ((key 0))
13773 (while (<= key 9)
13774 (define-key vhdl-speedbar-key-map (int-to-string key)
13775 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13776 (setq key (1+ key)))))
5eabfe72
KH
13777 (define-key speedbar-key-map "h"
13778 (lambda () (interactive)
3dcb36b7
JB
13779 (speedbar-change-initial-expansion-list "vhdl directory")))
13780 (define-key speedbar-key-map "H"
13781 (lambda () (interactive)
13782 (speedbar-change-initial-expansion-list "vhdl project")))
13783 ;; menu
13784 (unless vhdl-speedbar-menu-items
13785 (setq
13786 vhdl-speedbar-menu-items
13787 `(["Edit" speedbar-edit-line t]
13788 ["Expand" speedbar-expand-line
13789 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13790 ["Contract" vhdl-speedbar-contract-level t]
13791 ["Expand All" vhdl-speedbar-expand-all t]
13792 ["Contract All" vhdl-speedbar-contract-all t]
13793 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13794 (while (<= key 9)
13795 (setq menu-list
13796 (cons `[,(if (= key 0) "All" (int-to-string key))
13797 (vhdl-speedbar-set-depth ,key)
13798 :style radio
13799 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13800 :keys ,(int-to-string key)]
13801 menu-list))
13802 (setq key (1+ key)))
13803 (nreverse menu-list))
13804 "--"
13805 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13806 (or (vhdl-speedbar-check-unit 'entity)
13807 (vhdl-speedbar-check-unit 'subprogram))]
13808 ["Place Component" vhdl-speedbar-place-component
13809 (vhdl-speedbar-check-unit 'entity)]
13810 ["Make" vhdl-speedbar-make-design
13811 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13812 ["Generate Makefile" vhdl-speedbar-generate-makefile
13813 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
13814 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
13815 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13816 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
13817 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
13818 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13819 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
13820 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
13821 ;; hook-ups
13822 (speedbar-add-expansion-list
13823 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13824 vhdl-speedbar-display-directory))
13825 (speedbar-add-expansion-list
13826 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13827 vhdl-speedbar-display-projects))
5eabfe72 13828 (setq speedbar-stealthy-function-list
3dcb36b7
JB
13829 (append
13830 '(("vhdl directory" vhdl-speedbar-update-current-unit)
13831 ("vhdl project" vhdl-speedbar-update-current-project
13832 vhdl-speedbar-update-current-unit)
13833; ("files" (lambda () (setq speedbar-ignored-path-regexp
13834; (speedbar-extension-list-to-regex
13835; speedbar-ignored-path-expressions))))
13836 )
13837 speedbar-stealthy-function-list))
13838 (when (eq vhdl-speedbar-display-mode 'directory)
13839 (setq speedbar-initial-expansion-list-name "vhdl directory"))
13840 (when (eq vhdl-speedbar-display-mode 'project)
13841 (setq speedbar-initial-expansion-list-name "vhdl project"))
13842 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
13843
13844(defun vhdl-speedbar (&optional arg)
13845 "Open/close speedbar."
d2ddb974 13846 (interactive)
5eabfe72 13847 (if (not (fboundp 'speedbar))
3dcb36b7
JB
13848 (error "WARNING: Speedbar is not available or not installed")
13849 (condition-case ()
5eabfe72 13850 (speedbar-frame-mode arg)
3dcb36b7 13851 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
13852
13853;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13854;; Display functions
13855
3dcb36b7
JB
13856(defvar vhdl-speedbar-last-selected-project nil
13857 "Name of last selected project.")
13858
5eabfe72
KH
13859;; macros must be defined in the file they are used (copied from `speedbar.el')
13860(defmacro speedbar-with-writable (&rest forms)
13861 "Allow the buffer to be writable and evaluate FORMS."
13862 (list 'let '((inhibit-read-only t))
13863 (cons 'progn forms)))
13864(put 'speedbar-with-writable 'lisp-indent-function 0)
13865
3dcb36b7 13866(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 13867 "Display directory and hierarchy information in speedbar."
3dcb36b7
JB
13868 (setq vhdl-speedbar-show-projects nil)
13869 (setq speedbar-ignored-path-regexp
13870 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
5eabfe72
KH
13871 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
13872 (setq speedbar-last-selected-file nil)
13873 (speedbar-with-writable
3dcb36b7
JB
13874 (condition-case nil
13875 (progn
13876 ;; insert directory path
13877 (speedbar-directory-buttons directory depth)
13878 ;; insert subdirectories
13879 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
13880 ;; scan and insert hierarchy of current directory
13881 (vhdl-speedbar-insert-dir-hierarchy directory depth
13882 speedbar-power-click)
13883 ;; expand subdirectories
13884 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
13885 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
13886
13887(defun vhdl-speedbar-display-projects (project depth &optional rescan)
13888 "Display projects and hierarchy information in speedbar."
13889 (setq vhdl-speedbar-show-projects t)
13890 (setq speedbar-ignored-path-regexp ".")
13891 (setq speedbar-last-selected-file nil)
13892 (setq vhdl-speedbar-last-selected-project nil)
13893 (speedbar-with-writable
13894 (condition-case nil
13895 ;; insert projects
13896 (vhdl-speedbar-insert-projects)
13897 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
13898 (setq speedbar-full-text-cache nil)) ; prevent caching
13899
13900(defun vhdl-speedbar-insert-projects ()
13901 "Insert all projects in speedbar."
13902 (vhdl-speedbar-make-title-line "Projects:")
13903 (let ((project-alist (if vhdl-project-sort
13904 (vhdl-sort-alist (copy-alist vhdl-project-alist))
13905 vhdl-project-alist))
13906 (vhdl-speedbar-update-current-unit nil))
13907 ;; insert projects
13908 (while project-alist
13909 (speedbar-make-tag-line
13910 'angle ?+ 'vhdl-speedbar-expand-project
13911 (caar project-alist) (caar project-alist)
13912 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
13913 (setq project-alist (cdr project-alist)))
13914 (setq project-alist vhdl-project-alist)
13915 ;; expand projects
13916 (while project-alist
13917 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
13918 (goto-char (point-min))
13919 (when (re-search-forward
13920 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
13921 (goto-char (match-end 1))
13922 (speedbar-do-function-pointer)))
13923 (setq project-alist (cdr project-alist))))
13924; (vhdl-speedbar-update-current-project)
13925; (vhdl-speedbar-update-current-unit nil t)
13926 )
13927
13928(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
13929 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
13930otherwise use cached data."
13931 (when (or rescan (and (not (assoc project vhdl-file-alist))
13932 (not (vhdl-load-cache project))))
13933 (vhdl-scan-project-contents project))
13934 ;; insert design hierarchy
13935 (vhdl-speedbar-insert-hierarchy
13936 (aget vhdl-entity-alist project t)
13937 (aget vhdl-config-alist project t)
13938 (aget vhdl-package-alist project t)
13939 (car (aget vhdl-ent-inst-alist project t)) indent)
13940 (insert (int-to-string indent) ":\n")
13941 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
13942 (put-text-property (1- (point)) (point) 'invisible nil)
13943 ;; expand design units
13944 (vhdl-speedbar-expand-units project))
13945
13946(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
13947 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
13948otherwise use cached data."
13949 (when (or rescan (and (not (assoc directory vhdl-file-alist))
13950 (not (vhdl-load-cache directory))))
13951 (vhdl-scan-directory-contents directory))
13952 ;; insert design hierarchy
13953 (vhdl-speedbar-insert-hierarchy
13954 (aget vhdl-entity-alist directory t)
13955 (aget vhdl-config-alist directory t)
13956 (aget vhdl-package-alist directory t)
13957 (car (aget vhdl-ent-inst-alist directory t)) depth)
13958 ;; expand design units
13959 (vhdl-speedbar-expand-units directory)
13960 (aput 'vhdl-directory-alist directory (list (list directory))))
13961
13962(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 13963 ent-inst-list depth)
3dcb36b7
JB
13964 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
13965 (if (not (or ent-alist conf-alist pack-alist))
13966 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
13967 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
13968 ;; insert entities
13969 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
13970 (while ent-alist
13971 (setq ent-entry (car ent-alist))
13972 (speedbar-make-tag-line
13973 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
13974 (nth 1 ent-entry) 'vhdl-speedbar-find-file
13975 (cons (nth 2 ent-entry) (nth 3 ent-entry))
5eabfe72 13976 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
13977 (unless (nth 2 ent-entry)
13978 (end-of-line 0) (insert "!") (forward-char 1))
13979 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
13980 (end-of-line 0) (insert " (top)") (forward-char 1))
13981 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
13982 ;; insert configurations
13983 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
13984 (while conf-alist
13985 (setq conf-entry (car conf-alist))
13986 (speedbar-make-tag-line
13987 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
13988 (nth 1 conf-entry) 'vhdl-speedbar-find-file
13989 (cons (nth 2 conf-entry) (nth 3 conf-entry))
13990 'vhdl-speedbar-configuration-face depth)
13991 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
13992 ;; insert packages
13993 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
13994 (while pack-alist
13995 (setq pack-entry (car pack-alist))
13996 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
13997 (nth 0 pack-entry) (nth 1 pack-entry)
13998 (cons (nth 2 pack-entry) (nth 3 pack-entry))
13999 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
14000 depth)
14001 (setq pack-alist (cdr pack-alist))))))
14002
5eabfe72 14003(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 14004 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 14005 (interactive)
3dcb36b7
JB
14006 (let (key path)
14007 (cond
14008 ;; current project
14009 (vhdl-speedbar-show-projects
14010 (setq key (vhdl-speedbar-line-project))
14011 (vhdl-scan-project-contents key))
14012 ;; top-level directory
14013 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14014 (re-search-forward "[0-9]+:" nil t)
14015 (vhdl-scan-directory-contents
14016 (abbreviate-file-name (speedbar-line-path))))
14017 ;; current directory
14018 (t (setq path (speedbar-line-path))
14019 (string-match "^\\(.+[/\\]\\)" path)
14020 (vhdl-scan-directory-contents
14021 (abbreviate-file-name (match-string 1 path)))))
14022 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14023
14024(defun vhdl-speedbar-expand-dirs (directory)
14025 "Expand subdirectories in DIRECTORY according to
14026 `speedbar-shown-directories'."
14027 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14028 (let ((sf (cdr (reverse speedbar-shown-directories)))
14029 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14030 (setq speedbar-shown-directories
14031 (list (expand-file-name default-directory)))
14032 (while sf
14033 (when (speedbar-goto-this-file (car sf))
14034 (beginning-of-line)
14035 (when (looking-at "[0-9]+:\\s-*<")
14036 (goto-char (match-end 0))
3dcb36b7
JB
14037 (speedbar-do-function-pointer)))
14038 (setq sf (cdr sf))))
14039 (vhdl-speedbar-update-current-unit nil t))
14040
14041(defun vhdl-speedbar-expand-units (key)
14042 "Expand design units in directory/project KEY according to
14043`vhdl-speedbar-shown-unit-alist'."
14044 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14045 (vhdl-speedbar-update-current-unit nil)
14046 vhdl-updated-project-list)
14047 (adelete 'vhdl-speedbar-shown-unit-alist key)
14048 (vhdl-prepare-search-1
14049 (while unit-alist ; expand units
14050 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14051 (beginning-of-line)
14052 (let ((arch-alist (nth 1 (car unit-alist)))
14053 position)
14054 (when (looking-at "^[0-9]+:\\s-*\\[")
14055 (goto-char (match-end 0))
14056 (setq position (point))
14057 (speedbar-do-function-pointer)
14058 (select-frame speedbar-frame)
14059 (while arch-alist ; expand architectures
14060 (goto-char position)
14061 (when (re-search-forward
14062 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14063 (car arch-alist) "\\>\\)") nil t)
14064 (beginning-of-line)
14065 (when (looking-at "^[0-9]+:\\s-*{")
14066 (goto-char (match-end 0))
14067 (speedbar-do-function-pointer)
14068 (select-frame speedbar-frame)))
14069 (setq arch-alist (cdr arch-alist))))
14070 (setq unit-alist (cdr unit-alist))))))
14071 (vhdl-speedbar-update-current-unit nil t))
14072
14073(defun vhdl-speedbar-contract-level ()
14074 "Contract current level in current directory/project."
14075 (interactive)
14076 (when (or (save-excursion
14077 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14078 (and (save-excursion
14079 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14080 (re-search-backward
14081 (format "^[0-%d]:\\s-*[[{<]-"
027a4b6b 14082 (max (1- (string-to-number (match-string 1))) 0)) nil t)))
3dcb36b7
JB
14083 (goto-char (match-end 0))
14084 (speedbar-do-function-pointer)
14085 (speedbar-center-buffer-smartly)))
14086
14087(defun vhdl-speedbar-contract-all ()
14088 "Contract all expanded design units in current directory/project."
14089 (interactive)
14090 (if (and vhdl-speedbar-show-projects
14091 (save-excursion (beginning-of-line) (looking-at "^0:")))
14092 (progn (setq vhdl-speedbar-shown-project-list nil)
14093 (vhdl-speedbar-refresh))
14094 (let ((key (vhdl-speedbar-line-key)))
14095 (adelete 'vhdl-speedbar-shown-unit-alist key)
14096 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14097 (when (memq 'display vhdl-speedbar-save-cache)
14098 (add-to-list 'vhdl-updated-project-list key)))))
14099
14100(defun vhdl-speedbar-expand-all ()
14101 "Expand all design units in current directory/project."
14102 (interactive)
14103 (let* ((key (vhdl-speedbar-line-key))
14104 (ent-alist (aget vhdl-entity-alist key t))
14105 (conf-alist (aget vhdl-config-alist key t))
14106 (pack-alist (aget vhdl-package-alist key t))
14107 arch-alist unit-alist subunit-alist)
14108 (add-to-list 'vhdl-speedbar-shown-project-list key)
14109 (while ent-alist
14110 (setq arch-alist (nth 4 (car ent-alist)))
14111 (setq subunit-alist nil)
14112 (while arch-alist
14113 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14114 (setq arch-alist (cdr arch-alist)))
14115 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14116 (setq ent-alist (cdr ent-alist)))
14117 (while conf-alist
14118 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14119 (setq conf-alist (cdr conf-alist)))
14120 (while pack-alist
14121 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14122 (setq pack-alist (cdr pack-alist)))
14123 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14124 (vhdl-speedbar-refresh)
14125 (when (memq 'display vhdl-speedbar-save-cache)
14126 (add-to-list 'vhdl-updated-project-list key))))
14127
14128(defun vhdl-speedbar-expand-project (text token indent)
14129 "Expand/contract the project under the cursor."
14130 (cond
14131 ((string-match "+" text) ; expand project
14132 (speedbar-change-expand-button-char ?-)
14133 (unless (member token vhdl-speedbar-shown-project-list)
14134 (setq vhdl-speedbar-shown-project-list
14135 (cons token vhdl-speedbar-shown-project-list)))
14136 (speedbar-with-writable
14137 (save-excursion
14138 (end-of-line) (forward-char 1)
14139 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14140 speedbar-power-click))))
14141 ((string-match "-" text) ; contract project
14142 (speedbar-change-expand-button-char ?+)
14143 (setq vhdl-speedbar-shown-project-list
14144 (delete token vhdl-speedbar-shown-project-list))
14145 (speedbar-delete-subblock indent))
14146 (t (error "Nothing to display")))
14147 (when (equal (selected-frame) speedbar-frame)
14148 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14149
14150(defun vhdl-speedbar-expand-entity (text token indent)
14151 "Expand/contract the entity under the cursor."
14152 (cond
14153 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14154 (let* ((key (vhdl-speedbar-line-key indent))
14155 (ent-alist (aget vhdl-entity-alist key t))
14156 (ent-entry (aget ent-alist token t))
14157 (arch-alist (nth 3 ent-entry))
5eabfe72 14158 (inst-alist (vhdl-get-instantiations token indent))
3dcb36b7
JB
14159 (subpack-alist (nth 4 ent-entry))
14160 arch-entry inst-entry)
14161 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14162 (speedbar-change-expand-button-char ??)
14163 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14164 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14165 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14166 (aput 'unit-alist token nil)
14167 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14168 (speedbar-with-writable
3dcb36b7
JB
14169 (save-excursion
14170 (end-of-line) (forward-char 1)
14171 ;; insert architectures
14172 (when arch-alist
14173 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14174 (while arch-alist
14175 (setq arch-entry (car arch-alist))
14176 (speedbar-make-tag-line
14177 'curly ?+ 'vhdl-speedbar-expand-architecture
14178 (cons token (nth 0 arch-entry))
14179 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14180 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14181 'vhdl-speedbar-architecture-face (1+ indent))
14182 (setq arch-alist (cdr arch-alist)))
14183 ;; insert instantiations
14184 (when inst-alist
14185 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14186 (while inst-alist
14187 (setq inst-entry (car inst-alist))
14188 (vhdl-speedbar-make-inst-line
14189 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14190 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14191 nil nil nil (1+ indent) 0 " in ")
14192 (setq inst-alist (cdr inst-alist)))
14193 ;; insert required packages
14194 (vhdl-speedbar-insert-subpackages
14195 subpack-alist (1+ indent) indent)))
14196 (when (memq 'display vhdl-speedbar-save-cache)
14197 (add-to-list 'vhdl-updated-project-list key))
14198 (vhdl-speedbar-update-current-unit t t))))
5eabfe72
KH
14199 ((string-match "-" text) ; contract entity
14200 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14201 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14202 (let* ((key (vhdl-speedbar-line-key indent))
14203 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14204 (adelete 'unit-alist token)
14205 (if unit-alist
14206 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14207 (adelete 'vhdl-speedbar-shown-unit-alist key))
14208 (speedbar-delete-subblock indent)
14209 (when (memq 'display vhdl-speedbar-save-cache)
14210 (add-to-list 'vhdl-updated-project-list key))))
14211 (t (error "Nothing to display")))
14212 (when (equal (selected-frame) speedbar-frame)
14213 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14214
14215(defun vhdl-speedbar-expand-architecture (text token indent)
14216 "Expand/contract the architecture under the cursor."
14217 (cond
14218 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14219 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14220 (ent-alist (aget vhdl-entity-alist key t))
14221 (conf-alist (aget vhdl-config-alist key t))
14222 (hier-alist (vhdl-get-hierarchy
14223 ent-alist conf-alist (car token) (cdr token) nil nil
14224 0 (1- indent)))
14225 (ent-entry (aget ent-alist (car token) t))
14226 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14227 (subpack-alist (nth 4 arch-entry))
14228 entry)
14229 (if (not (or hier-alist subpack-alist))
14230 (speedbar-change-expand-button-char ??)
14231 (speedbar-change-expand-button-char ?-)
14232 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14233 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14234 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14235 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14236 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14237 (speedbar-with-writable
14238 (save-excursion
14239 (end-of-line) (forward-char 1)
14240 ;; insert instance hierarchy
14241 (when hier-alist
14242 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14243 (1+ indent)))
14244 (while hier-alist
14245 (setq entry (car hier-alist))
14246 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14247 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14248 (vhdl-speedbar-make-inst-line
14249 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14250 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14251 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14252 (setq hier-alist (cdr hier-alist)))
14253 ;; insert required packages
14254 (vhdl-speedbar-insert-subpackages
14255 subpack-alist (1+ indent) (1- indent))))
14256 (when (memq 'display vhdl-speedbar-save-cache)
14257 (add-to-list 'vhdl-updated-project-list key))
14258 (vhdl-speedbar-update-current-unit t t))))
14259 ((string-match "-" text) ; contract architecture
14260 (speedbar-change-expand-button-char ?+)
14261 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14262 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14263 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14264 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14265 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14266 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14267 (speedbar-delete-subblock indent)
14268 (when (memq 'display vhdl-speedbar-save-cache)
14269 (add-to-list 'vhdl-updated-project-list key))))
14270 (t (error "Nothing to display")))
14271 (when (equal (selected-frame) speedbar-frame)
14272 (speedbar-center-buffer-smartly)))
14273
14274(defun vhdl-speedbar-expand-config (text token indent)
14275 "Expand/contract the configuration under the cursor."
14276 (cond
14277 ((string-match "+" text) ; expand configuration
14278 (let* ((key (vhdl-speedbar-line-key indent))
14279 (conf-alist (aget vhdl-config-alist key t))
14280 (conf-entry (aget conf-alist token))
14281 (ent-alist (aget vhdl-entity-alist key t))
14282 (hier-alist (vhdl-get-hierarchy
14283 ent-alist conf-alist (nth 3 conf-entry)
14284 (nth 4 conf-entry) token (nth 5 conf-entry)
14285 0 indent t))
14286 (subpack-alist (nth 6 conf-entry))
14287 entry)
14288 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14289 (speedbar-change-expand-button-char ??)
14290 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14291 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14292 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14293 (aput 'unit-alist token nil)
14294 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14295 (speedbar-with-writable
14296 (save-excursion
14297 (end-of-line) (forward-char 1)
14298 ;; insert instance hierarchy
14299 (when hier-alist
3dcb36b7 14300 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14301 (while hier-alist
3dcb36b7
JB
14302 (setq entry (car hier-alist))
14303 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14304 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14305 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14306 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14307 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14308 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14309 (setq hier-alist (cdr hier-alist)))
14310 ;; insert required packages
14311 (vhdl-speedbar-insert-subpackages
14312 subpack-alist (1+ indent) indent)))
14313 (when (memq 'display vhdl-speedbar-save-cache)
14314 (add-to-list 'vhdl-updated-project-list key))
14315 (vhdl-speedbar-update-current-unit t t))))
14316 ((string-match "-" text) ; contract configuration
5eabfe72 14317 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14318 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14319 (let* ((key (vhdl-speedbar-line-key indent))
14320 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14321 (adelete 'unit-alist token)
14322 (if unit-alist
14323 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14324 (adelete 'vhdl-speedbar-shown-unit-alist key))
14325 (speedbar-delete-subblock indent)
14326 (when (memq 'display vhdl-speedbar-save-cache)
14327 (add-to-list 'vhdl-updated-project-list key))))
14328 (t (error "Nothing to display")))
14329 (when (equal (selected-frame) speedbar-frame)
14330 (speedbar-center-buffer-smartly)))
14331
14332(defun vhdl-speedbar-expand-package (text token indent)
14333 "Expand/contract the package under the cursor."
14334 (cond
14335 ((string-match "+" text) ; expand package
14336 (let* ((key (vhdl-speedbar-line-key indent))
14337 (pack-alist (aget vhdl-package-alist key t))
14338 (pack-entry (aget pack-alist token t))
14339 (comp-alist (nth 3 pack-entry))
14340 (func-alist (nth 4 pack-entry))
14341 (func-body-alist (nth 8 pack-entry))
14342 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14343 comp-entry func-entry func-body-entry)
14344 (if (not (or comp-alist func-alist subpack-alist))
14345 (speedbar-change-expand-button-char ??)
14346 (speedbar-change-expand-button-char ?-)
14347 ;; add package to `vhdl-speedbar-shown-unit-alist'
14348 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14349 (aput 'unit-alist token nil)
14350 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14351 (speedbar-with-writable
14352 (save-excursion
14353 (end-of-line) (forward-char 1)
14354 ;; insert components
14355 (when comp-alist
14356 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14357 (while comp-alist
14358 (setq comp-entry (car comp-alist))
14359 (speedbar-make-tag-line
14360 nil nil nil
14361 (cons token (nth 0 comp-entry))
14362 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14363 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14364 'vhdl-speedbar-entity-face (1+ indent))
14365 (setq comp-alist (cdr comp-alist)))
14366 ;; insert subprograms
14367 (when func-alist
14368 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14369 (while func-alist
14370 (setq func-entry (car func-alist)
14371 func-body-entry (aget func-body-alist (car func-entry) t))
14372 (when (nth 2 func-entry)
14373 (vhdl-speedbar-make-subprogram-line
14374 (nth 1 func-entry)
14375 (cons (nth 2 func-entry) (nth 3 func-entry))
14376 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14377 (1+ indent)))
14378 (setq func-alist (cdr func-alist)))
14379 ;; insert required packages
14380 (vhdl-speedbar-insert-subpackages
14381 subpack-alist (1+ indent) indent)))
14382 (when (memq 'display vhdl-speedbar-save-cache)
14383 (add-to-list 'vhdl-updated-project-list key))
14384 (vhdl-speedbar-update-current-unit t t))))
14385 ((string-match "-" text) ; contract package
14386 (speedbar-change-expand-button-char ?+)
14387 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14388 (let* ((key (vhdl-speedbar-line-key indent))
14389 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14390 (adelete 'unit-alist token)
14391 (if unit-alist
14392 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14393 (adelete 'vhdl-speedbar-shown-unit-alist key))
14394 (speedbar-delete-subblock indent)
14395 (when (memq 'display vhdl-speedbar-save-cache)
14396 (add-to-list 'vhdl-updated-project-list key))))
14397 (t (error "Nothing to display")))
14398 (when (equal (selected-frame) speedbar-frame)
14399 (speedbar-center-buffer-smartly)))
14400
14401(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14402 "Insert required packages."
14403 (let* ((pack-alist (aget vhdl-package-alist
14404 (vhdl-speedbar-line-key dir-indent) t))
14405 pack-key lib-name pack-entry)
14406 (when subpack-alist
14407 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14408 (while subpack-alist
14409 (setq pack-key (cdar subpack-alist)
14410 lib-name (caar subpack-alist))
14411 (setq pack-entry (aget pack-alist pack-key t))
14412 (vhdl-speedbar-make-subpack-line
14413 (or (nth 0 pack-entry) pack-key) lib-name
14414 (cons (nth 1 pack-entry) (nth 2 pack-entry)) indent)
14415 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14416
14417;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14418;; Display help functions
14419
3dcb36b7
JB
14420(defvar vhdl-speedbar-update-current-unit t
14421 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14422
14423(defun vhdl-speedbar-update-current-project ()
14424 "Highlight project that is currently active."
14425 (when (and vhdl-speedbar-show-projects
14426 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14427 (and (boundp 'speedbar-frame)
14428 (frame-live-p speedbar-frame)))
14429 (let ((last-frame (selected-frame))
14430 (project-alist vhdl-project-alist)
14431 pos)
14432 (select-frame speedbar-frame)
14433 (speedbar-with-writable
14434 (save-excursion
14435 (while project-alist
14436 (goto-char (point-min))
14437 (when (re-search-forward
14438 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14439 (put-text-property (match-beginning 1) (match-end 1) 'face
14440 (if (equal (caar project-alist) vhdl-project)
14441 'speedbar-selected-face
14442 'speedbar-directory-face))
14443 (when (equal (caar project-alist) vhdl-project)
14444 (setq pos (1- (match-beginning 1)))))
14445 (setq project-alist (cdr project-alist))))
14446 (when pos (goto-char pos)))
14447 (select-frame last-frame)
14448 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14449 t)
14450
14451(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14452 "Highlight all design units that are contained in the current file.
14453NO-POSITION non-nil means do not re-position cursor."
14454 (let ((last-frame (selected-frame))
3dcb36b7
JB
14455 (project-list vhdl-speedbar-shown-project-list)
14456 file-alist pos file-name)
5eabfe72 14457 ;; get current file name
3dcb36b7
JB
14458 (if (fboundp 'speedbar-select-attached-frame)
14459 (speedbar-select-attached-frame)
14460 (select-frame speedbar-attached-frame))
5eabfe72 14461 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14462 (when (and vhdl-speedbar-update-current-unit
14463 (or always (not (equal file-name speedbar-last-selected-file))))
14464 (if vhdl-speedbar-show-projects
14465 (while project-list
14466 (setq file-alist (append file-alist (aget vhdl-file-alist
14467 (car project-list) t)))
14468 (setq project-list (cdr project-list)))
14469 (setq file-alist (aget vhdl-file-alist
14470 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14471 (select-frame speedbar-frame)
14472 (set-buffer speedbar-buffer)
14473 (speedbar-with-writable
3dcb36b7 14474 (vhdl-prepare-search-1
5eabfe72
KH
14475 (save-excursion
14476 ;; unhighlight last units
3dcb36b7 14477 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14478 (vhdl-speedbar-update-units
3dcb36b7 14479 "\\[.\\] " (nth 0 file-entry)
5eabfe72
KH
14480 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14481 (vhdl-speedbar-update-units
3dcb36b7 14482 "{.} " (nth 1 file-entry)
5eabfe72
KH
14483 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14484 (vhdl-speedbar-update-units
3dcb36b7 14485 "\\[.\\] " (nth 3 file-entry)
5eabfe72
KH
14486 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14487 (vhdl-speedbar-update-units
3dcb36b7 14488 "[]>] " (nth 4 file-entry)
5eabfe72
KH
14489 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14490 (vhdl-speedbar-update-units
3dcb36b7
JB
14491 "\\[.\\].+(" '("body")
14492 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14493 (vhdl-speedbar-update-units
14494 "> " (nth 6 file-entry)
5eabfe72
KH
14495 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14496 ;; highlight current units
3dcb36b7
JB
14497 (let* ((file-entry (aget file-alist file-name t)))
14498 (setq
14499 pos (vhdl-speedbar-update-units
14500 "\\[.\\] " (nth 0 file-entry)
14501 file-name 'vhdl-speedbar-entity-selected-face pos)
14502 pos (vhdl-speedbar-update-units
14503 "{.} " (nth 1 file-entry)
14504 file-name 'vhdl-speedbar-architecture-selected-face pos)
14505 pos (vhdl-speedbar-update-units
14506 "\\[.\\] " (nth 3 file-entry)
14507 file-name 'vhdl-speedbar-configuration-selected-face pos)
14508 pos (vhdl-speedbar-update-units
14509 "[]>] " (nth 4 file-entry)
14510 file-name 'vhdl-speedbar-package-selected-face pos)
14511 pos (vhdl-speedbar-update-units
14512 "\\[.\\].+(" '("body")
14513 file-name 'vhdl-speedbar-package-selected-face pos)
14514 pos (vhdl-speedbar-update-units
14515 "> " (nth 6 file-entry)
14516 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14517 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14518 (when (and pos (not no-position))
14519 (goto-char pos)
14520 (speedbar-center-buffer-smartly)
5eabfe72
KH
14521 (speedbar-position-cursor-on-line))
14522 (setq speedbar-last-selected-file file-name))
14523 (select-frame last-frame)
14524 t))
14525
3dcb36b7
JB
14526(defun vhdl-speedbar-update-units (text unit-list file-name face
14527 &optional pos)
5eabfe72 14528 "Help function to highlight design units."
3dcb36b7
JB
14529 (while unit-list
14530 (goto-char (point-min))
14531 (while (re-search-forward
14532 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14533 (when (equal file-name (car (get-text-property
14534 (match-beginning 1) 'speedbar-token)))
14535 (setq pos (or pos (point-marker)))
14536 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14537 (setq unit-list (cdr unit-list)))
14538 pos)
5eabfe72
KH
14539
14540(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14541 ent-name ent-file-marker
14542 arch-name arch-file-marker
14543 conf-name conf-file-marker
14544 lib-name depth offset delimiter)
5eabfe72 14545 "Insert instantiation entry."
3dcb36b7
JB
14546 (let ((start (point))
14547 visible-start)
5eabfe72
KH
14548 (insert (int-to-string depth) ":")
14549 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14550 (setq visible-start (point))
14551 (insert-char ? (* depth speedbar-indentation-width))
14552 (while (> offset 0)
14553 (insert "|")
14554 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14555 (setq offset (1- offset)))
14556 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14557 (setq start (point))
3dcb36b7
JB
14558 (insert ">")
14559 (speedbar-make-button start (point) nil nil nil)
14560 (setq visible-start (point))
14561 (insert " ")
5eabfe72 14562 (setq start (point))
3dcb36b7
JB
14563 (if (not inst-name)
14564 (insert "(top)")
14565 (insert inst-name)
14566 (speedbar-make-button
14567 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14568 'vhdl-speedbar-find-file inst-file-marker))
14569 (insert delimiter)
14570 (when ent-name
5eabfe72 14571 (setq start (point))
3dcb36b7 14572 (insert ent-name)
5eabfe72 14573 (speedbar-make-button
3dcb36b7
JB
14574 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14575 'vhdl-speedbar-find-file ent-file-marker)
14576 (when arch-name
14577 (insert " (")
14578 (setq start (point))
14579 (insert arch-name)
14580 (speedbar-make-button
14581 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14582 'vhdl-speedbar-find-file arch-file-marker)
14583 (insert ")"))
14584 (when conf-name
14585 (insert " (")
14586 (setq start (point))
14587 (insert conf-name)
14588 (speedbar-make-button
14589 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14590 'vhdl-speedbar-find-file conf-file-marker)
14591 (insert ")")))
14592 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14593 (setq start (point))
3dcb36b7
JB
14594 (insert " (" lib-name ")")
14595 (put-text-property (+ 2 start) (1- (point)) 'face
14596 'vhdl-speedbar-library-face))
5eabfe72 14597 (insert-char ?\n 1)
3dcb36b7 14598 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14599
3dcb36b7
JB
14600(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14601 body-file-marker depth)
5eabfe72 14602 "Insert package entry."
3dcb36b7
JB
14603 (let ((start (point))
14604 visible-start)
5eabfe72
KH
14605 (insert (int-to-string depth) ":")
14606 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14607 (setq visible-start (point))
14608 (insert-char ? (* depth speedbar-indentation-width))
14609 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14610 (setq start (point))
3dcb36b7
JB
14611 (insert "[+]")
14612 (speedbar-make-button
14613 start (point) 'speedbar-button-face 'speedbar-highlight-face
14614 'vhdl-speedbar-expand-package pack-key)
14615 (setq visible-start (point))
14616 (insert-char ? 1 nil)
5eabfe72
KH
14617 (setq start (point))
14618 (insert pack-name)
14619 (speedbar-make-button
14620 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14621 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14622 (unless (car pack-file-marker)
14623 (insert "!"))
5eabfe72 14624 (when (car body-file-marker)
5eabfe72 14625 (insert " (")
5eabfe72
KH
14626 (setq start (point))
14627 (insert "body")
14628 (speedbar-make-button
14629 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14630 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14631 (insert ")"))
5eabfe72 14632 (insert-char ?\n 1)
3dcb36b7 14633 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14634
3dcb36b7
JB
14635(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14636 depth)
14637 "Insert used package entry."
14638 (let ((start (point))
14639 visible-start)
14640 (insert (int-to-string depth) ":")
14641 (put-text-property start (point) 'invisible t)
14642 (setq visible-start (point))
14643 (insert-char ? (* depth speedbar-indentation-width))
14644 (put-text-property visible-start (point) 'invisible nil)
14645 (setq start (point))
14646 (insert ">")
14647 (speedbar-make-button start (point) nil nil nil)
14648 (setq visible-start (point))
14649 (insert " ")
14650 (setq start (point))
14651 (insert pack-name)
14652 (speedbar-make-button
14653 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14654 'vhdl-speedbar-find-file pack-file-marker)
14655 (setq start (point))
14656 (insert " (" lib-name ")")
14657 (put-text-property (+ 2 start) (1- (point)) 'face
14658 'vhdl-speedbar-library-face)
14659 (insert-char ?\n 1)
14660 (put-text-property visible-start (point) 'invisible nil)))
14661
14662(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14663 func-body-file-marker
14664 depth)
14665 "Insert subprogram entry."
14666 (let ((start (point))
14667 visible-start)
5eabfe72
KH
14668 (insert (int-to-string depth) ":")
14669 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14670 (setq visible-start (point))
14671 (insert-char ? (* depth speedbar-indentation-width))
14672 (put-text-property visible-start (point) 'invisible nil)
14673 (setq start (point))
14674 (insert ">")
14675 (speedbar-make-button start (point) nil nil nil)
14676 (setq visible-start (point))
14677 (insert " ")
5eabfe72 14678 (setq start (point))
3dcb36b7
JB
14679 (insert func-name)
14680 (speedbar-make-button
14681 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14682 'vhdl-speedbar-find-file func-file-marker)
14683 (when (car func-body-file-marker)
14684 (insert " (")
14685 (setq start (point))
14686 (insert "body")
14687 (speedbar-make-button
14688 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14689 'vhdl-speedbar-find-file func-body-file-marker)
14690 (insert ")"))
14691 (insert-char ?\n 1)
14692 (put-text-property visible-start (point) 'invisible nil)))
14693
14694(defun vhdl-speedbar-make-title-line (text &optional depth)
14695 "Insert design unit title entry."
14696 (let ((start (point))
14697 visible-start)
14698 (when depth
14699 (insert (int-to-string depth) ":")
14700 (put-text-property start (point) 'invisible t))
14701 (setq visible-start (point))
14702 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14703 (setq start (point))
14704 (insert text)
14705 (speedbar-make-button start (point) nil nil nil nil)
14706 (insert-char ?\n 1)
3dcb36b7 14707 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14708
14709(defun vhdl-speedbar-insert-dirs (files level)
14710 "Insert subdirectories."
14711 (let ((dirs (car files)))
14712 (while dirs
14713 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14714 (car dirs) 'speedbar-dir-follow nil
14715 'speedbar-directory-face level)
14716 (setq dirs (cdr dirs)))))
14717
14718(defun vhdl-speedbar-dired (text token indent)
14719 "Speedbar click handler for directory expand button in hierarchy mode."
14720 (cond ((string-match "+" text) ; we have to expand this dir
14721 (setq speedbar-shown-directories
14722 (cons (expand-file-name
14723 (concat (speedbar-line-path indent) token "/"))
14724 speedbar-shown-directories))
14725 (speedbar-change-expand-button-char ?-)
14726 (speedbar-reset-scanners)
14727 (speedbar-with-writable
14728 (save-excursion
14729 (end-of-line) (forward-char 1)
14730 (vhdl-speedbar-insert-dirs
14731 (speedbar-file-lists
14732 (concat (speedbar-line-path indent) token "/"))
14733 (1+ indent))
14734 (speedbar-reset-scanners)
14735 (vhdl-speedbar-insert-dir-hierarchy
14736 (abbreviate-file-name
14737 (concat (speedbar-line-path indent) token "/"))
14738 (1+ indent) speedbar-power-click)))
3dcb36b7 14739 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
14740 ((string-match "-" text) ; we have to contract this node
14741 (speedbar-reset-scanners)
14742 (let ((oldl speedbar-shown-directories)
14743 (newl nil)
14744 (td (expand-file-name
14745 (concat (speedbar-line-path indent) token))))
14746 (while oldl
14747 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14748 (setq newl (cons (car oldl) newl)))
14749 (setq oldl (cdr oldl)))
14750 (setq speedbar-shown-directories (nreverse newl)))
14751 (speedbar-change-expand-button-char ?+)
14752 (speedbar-delete-subblock indent))
3dcb36b7
JB
14753 (t (error "Nothing to display")))
14754 (when (equal (selected-frame) speedbar-frame)
14755 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14756
14757(defun vhdl-speedbar-item-info ()
14758 "Derive and display information about this line item."
14759 (save-excursion
14760 (beginning-of-line)
14761 ;; skip invisible number info
3dcb36b7 14762 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 14763 (cond
3dcb36b7
JB
14764 ;; project/directory entry
14765 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14766 (if vhdl-speedbar-show-projects
14767 (message "Project \"%s\"" (match-string-no-properties 1))
14768 (speedbar-files-item-info)))
5eabfe72 14769 ;; design unit entry
3dcb36b7
JB
14770 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14771 (goto-char (match-end 1))
5eabfe72
KH
14772 (let ((face (get-text-property (point) 'face)))
14773 (message
14774 "%s \"%s\" in \"%s\""
14775 ;; design unit kind
14776 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14777 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 14778 (if (equal (match-string 2) ">") "Component" "Entity"))
5eabfe72
KH
14779 ((or (eq face 'vhdl-speedbar-architecture-face)
14780 (eq face 'vhdl-speedbar-architecture-selected-face))
14781 "Architecture")
14782 ((or (eq face 'vhdl-speedbar-configuration-face)
14783 (eq face 'vhdl-speedbar-configuration-selected-face))
14784 "Configuration")
14785 ((or (eq face 'vhdl-speedbar-package-face)
14786 (eq face 'vhdl-speedbar-package-selected-face))
14787 "Package")
14788 ((or (eq face 'vhdl-speedbar-instantiation-face)
14789 (eq face 'vhdl-speedbar-instantiation-selected-face))
14790 "Instantiation")
3dcb36b7
JB
14791 ((eq face 'vhdl-speedbar-subprogram-face)
14792 "Subprogram")
5eabfe72
KH
14793 (t ""))
14794 ;; design unit name
14795 (buffer-substring-no-properties
3dcb36b7
JB
14796 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14797 (match-end 1))
5eabfe72 14798 ;; file name
3dcb36b7
JB
14799 (file-relative-name
14800 (or (car (get-text-property (point) 'speedbar-token))
14801 "?")
14802 (vhdl-default-directory)))))
14803 (t (message "")))))
14804
14805(defun vhdl-speedbar-line-text ()
14806 "Calls `speedbar-line-text' and removes text properties."
14807 (let ((string (speedbar-line-text)))
14808 (set-text-properties 0 (length string) nil string)
14809 string))
5eabfe72
KH
14810
14811;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14812;; Help functions
d2ddb974 14813
3dcb36b7
JB
14814(defun vhdl-speedbar-line-key (&optional indent)
14815 "Get currently displayed directory of project name."
14816 (if vhdl-speedbar-show-projects
14817 (vhdl-speedbar-line-project)
14818 (abbreviate-file-name
14819 (file-name-as-directory (speedbar-line-path indent)))))
14820
14821(defun vhdl-speedbar-line-project (&optional indent)
14822 "Get currently displayed project name."
14823 (and vhdl-speedbar-show-projects
14824 (save-excursion
14825 (end-of-line)
14826 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
14827 (match-string-no-properties 1))))
14828
14829(defun vhdl-add-modified-file ()
14830 "Add file to `vhdl-modified-file-list'."
14831 (when vhdl-file-alist
14832 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
14833 nil)
5eabfe72
KH
14834
14835(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
14836 "Resolve path wildcards in PATH-LIST."
14837 (let (path-list-1 path-list-2 path-beg path-end dir)
14838 ;; eliminate non-existent directories
5eabfe72
KH
14839 (while path-list
14840 (setq dir (car path-list))
3dcb36b7
JB
14841 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
14842 (if (file-directory-p (match-string 2 dir))
14843 (setq path-list-1 (cons dir path-list-1))
14844 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 14845 (setq path-list (cdr path-list)))
3dcb36b7 14846 ;; resolve path wildcards
5eabfe72
KH
14847 (while path-list-1
14848 (setq dir (car path-list-1))
3dcb36b7 14849 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
14850 (progn
14851 (setq path-beg (match-string 1 dir)
14852 path-end (match-string 5 dir))
3dcb36b7 14853 (setq path-list-1
5eabfe72
KH
14854 (append
14855 (mapcar
14856 (function
14857 (lambda (var) (concat path-beg var path-end)))
14858 (let ((all-list (vhdl-directory-files
14859 (match-string 2 dir) t
14860 (concat "\\<" (wildcard-to-regexp
14861 (match-string 4 dir)))))
14862 dir-list)
14863 (while all-list
14864 (when (file-directory-p (car all-list))
14865 (setq dir-list (cons (car all-list) dir-list)))
14866 (setq all-list (cdr all-list)))
14867 dir-list))
3dcb36b7
JB
14868 (cdr path-list-1))))
14869 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 14870 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
14871 (setq path-list-2 (cons dir path-list-2)))
14872 (setq path-list-1 (cdr path-list-1))))
14873 (nreverse path-list-2)))
5eabfe72
KH
14874
14875(defun vhdl-speedbar-goto-this-unit (directory unit)
14876 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
14877 (let ((dest (point)))
3dcb36b7 14878 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
14879 (progn (goto-char (point-min)) t)
14880 (speedbar-goto-this-file directory))
14881 (re-search-forward (concat "[]}] " unit "\\>") nil t))
14882 (progn (speedbar-position-cursor-on-line)
14883 t)
14884 (goto-char dest)
14885 nil)))
14886
14887(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
14888 "When user clicks on TEXT, load file with name and position in TOKEN.
14889Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
14890is already shown in a buffer."
5eabfe72 14891 (if (not (car token))
3dcb36b7
JB
14892 (error "ERROR: File cannot be found")
14893 (let ((buffer (get-file-buffer (car token))))
14894 (speedbar-find-file-in-frame (car token))
14895 (when (or vhdl-speedbar-jump-to-unit buffer)
14896 (goto-line (cdr token))
14897 (recenter))
14898 (vhdl-speedbar-update-current-unit t t)
14899 (speedbar-set-timer speedbar-update-speed)
14900 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
14901
14902(defun vhdl-speedbar-port-copy ()
3dcb36b7 14903 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 14904 (interactive)
3dcb36b7
JB
14905 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
14906 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
14907 (error "ERROR: No entity/component or subprogram under cursor")
14908 (beginning-of-line)
14909 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
14910 (condition-case info
14911 (let ((token (get-text-property
14912 (match-beginning 3) 'speedbar-token)))
14913 (vhdl-visit-file (car token) t
14914 (progn (goto-line (cdr token))
14915 (end-of-line)
14916 (if is-entity
14917 (vhdl-port-copy)
14918 (vhdl-subprog-copy)))))
14919 (error (error "ERROR: %s not scanned successfully\n (%s)"
14920 (if is-entity "Port" "Interface") (cadr info))))
14921 (error "ERROR: No entity/component or subprogram on current line")))))
14922
14923(defun vhdl-speedbar-place-component ()
14924 "Place the entity/component under the cursor as component."
14925 (interactive)
14926 (if (not (vhdl-speedbar-check-unit 'entity))
14927 (error "ERROR: No entity/component under cursor.")
14928 (vhdl-speedbar-port-copy)
14929 (if (fboundp 'speedbar-select-attached-frame)
14930 (speedbar-select-attached-frame)
14931 (select-frame speedbar-attached-frame))
14932 (vhdl-compose-place-component)
14933 (select-frame speedbar-frame)))
14934
14935(defun vhdl-speedbar-make-design ()
14936 "Make (compile) design unit or directory/project under the cursor."
14937 (interactive)
14938 (if (not (save-excursion (beginning-of-line)
14939 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
14940 (error "ERROR: No primary design unit or directory/project under cursor")
14941 (let ((is-unit (match-string 2))
14942 (unit-name (vhdl-speedbar-line-text))
14943 (vhdl-project (vhdl-speedbar-line-project))
14944 (directory (file-name-as-directory
14945 (or (speedbar-line-file) (speedbar-line-path)))))
14946 (if (fboundp 'speedbar-select-attached-frame)
14947 (speedbar-select-attached-frame)
14948 (select-frame speedbar-attached-frame))
14949 (let ((default-directory directory))
14950 (vhdl-make (and is-unit unit-name))))))
14951
14952(defun vhdl-speedbar-generate-makefile ()
14953 "Generate Makefile for directory/project under the cursor."
14954 (interactive)
14955 (let ((vhdl-project (vhdl-speedbar-line-project))
14956 (default-directory (file-name-as-directory
14957 (or (speedbar-line-file) (speedbar-line-path)))))
14958 (vhdl-generate-makefile)))
14959
14960(defun vhdl-speedbar-check-unit (design-unit)
14961 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
14962expansion function)."
14963 (save-excursion
14964 (speedbar-position-cursor-on-line)
14965 (cond ((eq design-unit 'entity)
14966 (memq (get-text-property (match-end 0) 'face)
14967 '(vhdl-speedbar-entity-face
14968 vhdl-speedbar-entity-selected-face)))
14969 ((eq design-unit 'subprogram)
14970 (eq (get-text-property (match-end 0) 'face)
14971 'vhdl-speedbar-subprogram-face))
14972 (t nil))))
14973
14974(defun vhdl-speedbar-set-depth (depth)
14975 "Set hierarchy display depth to DEPTH and refresh speedbar."
14976 (setq vhdl-speedbar-hierarchy-depth depth)
14977 (speedbar-refresh))
5eabfe72
KH
14978
14979;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14980;; Fontification
14981
14982(defface vhdl-speedbar-entity-face
14983 '((((class color) (background light)) (:foreground "ForestGreen"))
14984 (((class color) (background dark)) (:foreground "PaleGreen")))
14985 "Face used for displaying entity names."
14986 :group 'speedbar-faces)
14987
14988(defface vhdl-speedbar-architecture-face
ea81d57e
DN
14989 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
14990 (((class color) (background light)) (:foreground "Blue"))
5eabfe72
KH
14991 (((class color) (background dark)) (:foreground "LightSkyBlue")))
14992 "Face used for displaying architecture names."
14993 :group 'speedbar-faces)
d2ddb974 14994
5eabfe72
KH
14995(defface vhdl-speedbar-configuration-face
14996 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
14997 (((class color) (background dark)) (:foreground "Salmon")))
14998 "Face used for displaying configuration names."
14999 :group 'speedbar-faces)
15000
15001(defface vhdl-speedbar-package-face
15002 '((((class color) (background light)) (:foreground "Grey50"))
15003 (((class color) (background dark)) (:foreground "Grey80")))
15004 "Face used for displaying package names."
15005 :group 'speedbar-faces)
15006
3dcb36b7
JB
15007(defface vhdl-speedbar-library-face
15008 '((((class color) (background light)) (:foreground "Purple"))
15009 (((class color) (background dark)) (:foreground "Orchid1")))
15010 "Face used for displaying library names."
15011 :group 'speedbar-faces)
15012
5eabfe72
KH
15013(defface vhdl-speedbar-instantiation-face
15014 '((((class color) (background light)) (:foreground "Brown"))
ea81d57e 15015 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
5eabfe72
KH
15016 (((class color) (background dark)) (:foreground "Yellow")))
15017 "Face used for displaying instantiation names."
15018 :group 'speedbar-faces)
15019
3dcb36b7
JB
15020(defface vhdl-speedbar-subprogram-face
15021 '((((class color) (background light)) (:foreground "Orchid4"))
15022 (((class color) (background dark)) (:foreground "BurlyWood2")))
15023 "Face used for displaying subprogram names."
15024 :group 'speedbar-faces)
15025
5eabfe72
KH
15026(defface vhdl-speedbar-entity-selected-face
15027 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15028 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15029 "Face used for displaying entity names."
15030 :group 'speedbar-faces)
15031
15032(defface vhdl-speedbar-architecture-selected-face
ea81d57e
DN
15033 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15034 (((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15035 (((class color) (background light)) (:foreground "Blue" :underline t))
5eabfe72
KH
15036 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15037 "Face used for displaying architecture names."
15038 :group 'speedbar-faces)
15039
15040(defface vhdl-speedbar-configuration-selected-face
15041 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15042 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15043 "Face used for displaying configuration names."
15044 :group 'speedbar-faces)
15045
15046(defface vhdl-speedbar-package-selected-face
15047 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15048 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15049 "Face used for displaying package names."
15050 :group 'speedbar-faces)
15051
15052(defface vhdl-speedbar-instantiation-selected-face
15053 '((((class color) (background light)) (:foreground "Brown" :underline t))
ea81d57e 15054 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1" :underline t))
5eabfe72
KH
15055 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15056 "Face used for displaying instantiation names."
15057 :group 'speedbar-faces)
15058
3dcb36b7
JB
15059;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15060;; Initialization
15061
15062;; add speedbar
15063(when (fboundp 'speedbar)
15064 (condition-case ()
15065 (when (and vhdl-speedbar-auto-open
15066 (not (and (boundp 'speedbar-frame)
15067 (frame-live-p speedbar-frame))))
15068 (speedbar-frame-mode 1)
15069 (if (fboundp 'speedbar-select-attached-frame)
15070 (speedbar-select-attached-frame)
15071 (select-frame speedbar-attached-frame)))
15072 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15073
15074;; initialize speedbar
15075(if (not (boundp 'speedbar-frame))
15076 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15077 (vhdl-speedbar-initialize)
15078 (when speedbar-frame (vhdl-speedbar-refresh)))
15079
15080
15081;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15082;;; Structural composition
15083;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15084
15085(defun vhdl-get-components-package-name ()
15086 "Return the name of the components package."
15087 (let ((project (vhdl-project-p)))
15088 (if project
15089 (vhdl-replace-string (car vhdl-components-package-name)
15090 (subst-char-in-string ? ?_ project))
15091 (cdr vhdl-components-package-name))))
15092
15093(defun vhdl-compose-new-component ()
15094 "Create entity and architecture for new component."
15095 (interactive)
15096 (let* ((case-fold-search t)
15097 (ent-name (read-from-minibuffer "entity name: "
15098 nil vhdl-minibuffer-local-map))
15099 (arch-name
15100 (if (equal (cdr vhdl-compose-architecture-name) "")
15101 (read-from-minibuffer "architecture name: "
15102 nil vhdl-minibuffer-local-map)
15103 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15104 ent-file-name arch-file-name ent-buffer arch-buffer project)
15105 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15106 ;; open entity file
15107 (unless (eq vhdl-compose-create-files 'none)
15108 (setq ent-file-name
15109 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15110 "." (file-name-extension (buffer-file-name))))
15111 (when (and (file-exists-p ent-file-name)
15112 (not (y-or-n-p (concat "File \"" ent-file-name
15113 "\" exists; overwrite? "))))
15114 (error "ERROR: Creating component...aborted"))
15115 (find-file ent-file-name)
15116 (erase-buffer)
15117 (set-buffer-modified-p nil))
15118 ;; insert header
15119 (if vhdl-compose-include-header
15120 (progn (vhdl-template-header)
15121 (goto-char (point-max)))
15122 (vhdl-comment-display-line) (insert "\n\n"))
15123 ;; insert library clause
15124 (vhdl-template-package-std-logic-1164)
15125 (when vhdl-use-components-package
15126 (insert "\n")
15127 (vhdl-template-standard-package (vhdl-work-library)
15128 (vhdl-get-components-package-name)))
15129 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15130 ;; insert entity declaration
15131 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15132 (vhdl-insert-keyword " IS\n")
15133 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15134 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15135 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15136 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15137 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15138 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15139 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15140 (vhdl-insert-keyword "END ")
15141 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15142 (insert ent-name ";\n\n")
15143 (vhdl-comment-display-line) (insert "\n")
15144 ;; open architecture file
15145 (if (not (eq vhdl-compose-create-files 'separate))
15146 (insert "\n")
15147 (setq ent-buffer (current-buffer))
15148 (setq arch-file-name
15149 (concat (vhdl-replace-string vhdl-architecture-file-name
15150 (concat ent-name " " arch-name))
15151 "." (file-name-extension (buffer-file-name))))
15152 (when (and (file-exists-p arch-file-name)
15153 (not (y-or-n-p (concat "File \"" arch-file-name
15154 "\" exists; overwrite? "))))
15155 (error "ERROR: Creating component...aborted"))
15156 (find-file arch-file-name)
15157 (erase-buffer)
15158 (set-buffer-modified-p nil)
15159 ;; insert header
15160 (if vhdl-compose-include-header
15161 (progn (vhdl-template-header)
15162 (goto-char (point-max)))
15163 (vhdl-comment-display-line) (insert "\n\n")))
15164 ;; insert architecture body
15165 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15166 (vhdl-insert-keyword " OF ") (insert ent-name)
15167 (vhdl-insert-keyword " IS\n\n")
15168 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15169 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15170 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15171 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15172 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15173 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15174 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15175 (vhdl-insert-keyword "BEGIN")
15176 (when vhdl-self-insert-comments
15177 (insert " -- ")
15178 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15179 (insert arch-name))
15180 (insert "\n\n")
15181 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15182 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15183 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15184 (vhdl-insert-keyword "END ")
15185 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15186 (insert arch-name ";\n\n")
15187 ;; insert footer
15188 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15189 (vhdl-template-footer)
15190 (vhdl-comment-display-line) (insert "\n"))
15191 (goto-char (point-min))
15192 (setq arch-buffer (current-buffer))
15193 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15194 (set-buffer arch-buffer) (save-buffer)
15195 (message
15196 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15197 (and ent-file-name
15198 (format "\n File created: \"%s\"" ent-file-name))
15199 (and arch-file-name
15200 (format "\n File created: \"%s\"" arch-file-name))))))
15201
15202(defun vhdl-compose-place-component ()
15203 "Place new component by pasting current port as component declaration and
15204component instantiation."
15205 (interactive)
15206 (if (not vhdl-port-list)
15207 (error "ERROR: No port has been read")
15208 (save-excursion
15209 (vhdl-prepare-search-2
15210 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15211 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15212 (error "ERROR: No architecture found"))
15213 (let* ((ent-name (match-string 1))
15214 (ent-file-name
15215 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15216 "." (file-name-extension (buffer-file-name))))
15217 (orig-buffer (current-buffer)))
15218 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15219 ;; place component declaration
15220 (unless (or vhdl-use-components-package
15221 (vhdl-use-direct-instantiation)
15222 (save-excursion
15223 (re-search-forward
15224 (concat "^\\s-*component\\s-+"
15225 (car vhdl-port-list) "\\>") nil t)))
15226 (re-search-forward "^begin\\>" nil)
15227 (beginning-of-line)
15228 (skip-chars-backward " \t\n")
15229 (insert "\n\n") (indent-to vhdl-basic-offset)
15230 (vhdl-port-paste-component t))
15231 ;; place component instantiation
15232 (re-search-forward "^end\\>" nil)
15233 (beginning-of-line)
15234 (skip-chars-backward " \t\n")
15235 (insert "\n\n") (indent-to vhdl-basic-offset)
15236 (vhdl-port-paste-instance nil t t)
15237 ;; place use clause for used packages
15238 (when (nth 3 vhdl-port-list)
15239 ;; open entity file
15240 (when (file-exists-p ent-file-name)
15241 (find-file ent-file-name))
15242 (goto-char (point-min))
15243 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15244 (error "ERROR: Entity not found: \"%s\"" ent-name))
15245 (goto-char (match-beginning 0))
15246 (if (and (save-excursion
15247 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15248 (match-string 1))
15249 (progn (goto-char (match-end 0))
15250 (beginning-of-line 2))
15251 (insert "\n")
15252 (backward-char))
15253 (vhdl-port-paste-context-clause)
15254 (switch-to-buffer orig-buffer))
15255 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15256
15257(defun vhdl-compose-wire-components ()
15258 "Connect components."
15259 (interactive)
15260 (save-excursion
15261 (vhdl-prepare-search-2
15262 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15263 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15264 (error "ERROR: No architecture found"))
15265 (let* ((ent-name (match-string 1))
15266 (ent-file-name
15267 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15268 "." (file-name-extension (buffer-file-name))))
15269 (arch-decl-pos (point-marker))
15270 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15271 (arch-end-pos (re-search-forward "^end\\>" nil))
15272 (pack-name (vhdl-get-components-package-name))
15273 (pack-file-name
15274 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15275 "." (file-name-extension (buffer-file-name))))
15276 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15277 port-alist generic-alist inst-alist
15278 signal-name signal-entry signal-alist local-list written-list
15279 single-in-list multi-in-list single-out-list multi-out-list
15280 constant-name constant-entry constant-alist single-list multi-list
15281 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15282 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15283 signal-beg-pos signal-pos
15284 constant-temp-pos port-temp-pos signal-temp-pos)
15285 (message "Wiring components...")
15286 ;; process all instances
15287 (goto-char arch-stat-pos)
15288 (while (re-search-forward
15289 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15290 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15291 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15292 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15293 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15294 (setq inst-name (match-string-no-properties 1)
15295 comp-name (match-string-no-properties 4)
15296 comp-ent-name (match-string-no-properties 12)
15297 has-generic (or (match-string 7) (match-string 17)))
15298 ;; get port ...
15299 (if comp-name
15300 ;; ... from component declaration
15301 (vhdl-visit-file
15302 (when vhdl-use-components-package pack-file-name) t
15303 (save-excursion
15304 (goto-char (point-min))
15305 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15306 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15307 (vhdl-port-copy)))
15308 ;; ... from entity declaration (direct instantiation)
15309 (setq comp-ent-file-name
15310 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name)
15311 "." (file-name-extension (buffer-file-name))))
15312 (vhdl-visit-file
15313 comp-ent-file-name t
15314 (save-excursion
15315 (goto-char (point-min))
15316 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15317 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15318 (vhdl-port-copy))))
15319 (vhdl-port-flatten t)
15320 (setq generic-alist (nth 1 vhdl-port-list)
15321 port-alist (nth 2 vhdl-port-list))
15322 (setq constant-alist nil
15323 signal-alist nil)
15324 (when has-generic
15325 ;; process all constants in generic map
15326 (vhdl-forward-syntactic-ws)
15327 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15328 (setq constant-name (match-string-no-properties 3))
15329 (setq constant-entry
15330 (cons constant-name
15331 (if (match-string 1)
15332 (or (aget generic-alist (match-string 2) t)
15333 (error (format "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15334 (cdar generic-alist))))
15335 (setq constant-alist (cons constant-entry constant-alist))
15336 (setq constant-name (downcase constant-name))
15337 (if (or (member constant-name single-list)
15338 (member constant-name multi-list))
15339 (progn (setq single-list (delete constant-name single-list))
15340 (add-to-list 'multi-list constant-name))
15341 (add-to-list 'single-list constant-name))
15342 (unless (match-string 1)
15343 (setq generic-alist (cdr generic-alist)))
15344 (vhdl-forward-syntactic-ws))
15345 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15346 ;; process all signals in port map
15347 (vhdl-forward-syntactic-ws)
15348 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15349 (setq signal-name (match-string-no-properties 3))
15350 (setq signal-entry (cons signal-name
15351 (if (match-string 1)
15352 (or (aget port-alist (match-string 2) t)
15353 (error (format "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15354 (cdar port-alist))))
15355 (setq signal-alist (cons signal-entry signal-alist))
15356 (setq signal-name (downcase signal-name))
15357 (if (equal (upcase (nth 2 signal-entry)) "IN")
15358 ;; input signal
15359 (cond
15360 ((member signal-name local-list)
15361 nil)
15362 ((or (member signal-name single-out-list)
15363 (member signal-name multi-out-list))
15364 (setq single-out-list (delete signal-name single-out-list))
15365 (setq multi-out-list (delete signal-name multi-out-list))
15366 (add-to-list 'local-list signal-name))
15367 ((member signal-name single-in-list)
15368 (setq single-in-list (delete signal-name single-in-list))
15369 (add-to-list 'multi-in-list signal-name))
15370 ((not (member signal-name multi-in-list))
15371 (add-to-list 'single-in-list signal-name)))
15372 ;; output signal
15373 (cond
15374 ((member signal-name local-list)
15375 nil)
15376 ((or (member signal-name single-in-list)
15377 (member signal-name multi-in-list))
15378 (setq single-in-list (delete signal-name single-in-list))
15379 (setq multi-in-list (delete signal-name multi-in-list))
15380 (add-to-list 'local-list signal-name))
15381 ((member signal-name single-out-list)
15382 (setq single-out-list (delete signal-name single-out-list))
15383 (add-to-list 'multi-out-list signal-name))
15384 ((not (member signal-name multi-out-list))
15385 (add-to-list 'single-out-list signal-name))))
15386 (unless (match-string 1)
15387 (setq port-alist (cdr port-alist)))
15388 (vhdl-forward-syntactic-ws))
15389 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15390 (nreverse signal-alist)) inst-alist)))
15391 ;; prepare signal insertion
15392 (vhdl-goto-marker arch-decl-pos)
15393 (forward-line 1)
15394 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15395 (setq signal-pos (point-marker))
15396 (while (progn (vhdl-forward-syntactic-ws)
15397 (looking-at "signal\\>"))
15398 (beginning-of-line 2)
15399 (delete-region signal-pos (point)))
15400 (setq signal-beg-pos signal-pos)
15401 ;; open entity file
15402 (when (file-exists-p ent-file-name)
15403 (find-file ent-file-name))
15404 (goto-char (point-min))
15405 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15406 (error "ERROR: Entity not found: \"%s\"" ent-name))
15407 ;; prepare generic clause insertion
15408 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15409 (match-string 1))
15410 (goto-char (match-beginning 0))
15411 (indent-to vhdl-basic-offset)
15412 (insert "generic ();\n\n")
15413 (backward-char 4))
15414 (backward-char)
15415 (setq generic-pos (point-marker))
15416 (forward-sexp) (end-of-line)
15417 (delete-region generic-pos (point)) (delete-char 1)
15418 (insert "(\n")
15419 (when multi-list
15420 (insert "\n")
15421 (indent-to (* 2 vhdl-basic-offset))
15422 (insert "-- global generics\n"))
15423 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15424 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15425 ;; prepare port clause insertion
15426 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15427 (match-string 1))
15428 (goto-char (match-beginning 0))
15429 (indent-to vhdl-basic-offset)
15430 (insert "port ();\n\n")
15431 (backward-char 4))
15432 (backward-char)
15433 (setq port-in-pos (point-marker))
15434 (forward-sexp) (end-of-line)
15435 (delete-region port-in-pos (point)) (delete-char 1)
15436 (insert "(\n")
15437 (when (or multi-in-list multi-out-list)
15438 (insert "\n")
15439 (indent-to (* 2 vhdl-basic-offset))
15440 (insert "-- global ports\n"))
15441 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15442 port-out-pos (point-marker) port-inst-pos (point-marker)
15443 port-end-pos (point-marker))
15444 ;; insert generics, ports and signals
15445 (setq inst-alist (nreverse inst-alist))
15446 (while inst-alist
15447 (setq inst-name (nth 0 (car inst-alist))
15448 constant-alist (nth 1 (car inst-alist))
15449 signal-alist (nth 2 (car inst-alist))
15450 constant-temp-pos generic-inst-pos
15451 port-temp-pos port-inst-pos
15452 signal-temp-pos signal-pos)
15453 ;; generics
15454 (while constant-alist
15455 (setq constant-name (downcase (caar constant-alist))
15456 constant-entry (car constant-alist))
15457 (cond ((member constant-name written-list)
15458 nil)
15459 ((member constant-name multi-list)
15460 (vhdl-goto-marker generic-pos)
15461 (setq generic-end-pos
15462 (vhdl-max-marker
15463 generic-end-pos
15464 (vhdl-compose-insert-generic constant-entry)))
15465 (setq generic-pos (point-marker))
15466 (add-to-list 'written-list constant-name))
15467 (t
15468 (vhdl-goto-marker
15469 (vhdl-max-marker generic-inst-pos generic-pos))
15470 (setq generic-end-pos
15471 (vhdl-compose-insert-generic constant-entry))
15472 (setq generic-inst-pos (point-marker))
15473 (add-to-list 'written-list constant-name)))
15474 (setq constant-alist (cdr constant-alist)))
15475 (when (/= constant-temp-pos generic-inst-pos)
15476 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15477 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15478 (insert "-- generics for \"" inst-name "\"\n")
15479 (vhdl-goto-marker generic-inst-pos))
15480 ;; ports and signals
15481 (while signal-alist
15482 (setq signal-name (downcase (caar signal-alist))
15483 signal-entry (car signal-alist))
15484 (cond ((member signal-name written-list)
15485 nil)
15486 ((member signal-name multi-in-list)
15487 (vhdl-goto-marker port-in-pos)
15488 (setq port-end-pos
15489 (vhdl-max-marker
15490 port-end-pos (vhdl-compose-insert-port signal-entry)))
15491 (setq port-in-pos (point-marker))
15492 (add-to-list 'written-list signal-name))
15493 ((member signal-name multi-out-list)
15494 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15495 (setq port-end-pos
15496 (vhdl-max-marker
15497 port-end-pos (vhdl-compose-insert-port signal-entry)))
15498 (setq port-out-pos (point-marker))
15499 (add-to-list 'written-list signal-name))
15500 ((or (member signal-name single-in-list)
15501 (member signal-name single-out-list))
15502 (vhdl-goto-marker
15503 (vhdl-max-marker
15504 port-inst-pos
15505 (vhdl-max-marker port-out-pos port-in-pos)))
15506 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15507 (setq port-inst-pos (point-marker))
15508 (add-to-list 'written-list signal-name))
15509 ((equal (upcase (nth 2 signal-entry)) "OUT")
15510 (vhdl-goto-marker signal-pos)
15511 (vhdl-compose-insert-signal signal-entry)
15512 (setq signal-pos (point-marker))
15513 (add-to-list 'written-list signal-name)))
15514 (setq signal-alist (cdr signal-alist)))
15515 (when (/= port-temp-pos port-inst-pos)
15516 (vhdl-goto-marker
15517 (vhdl-max-marker port-temp-pos
15518 (vhdl-max-marker port-in-pos port-out-pos)))
15519 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15520 (insert "-- ports to \"" inst-name "\"\n")
15521 (vhdl-goto-marker port-inst-pos))
15522 (when (/= signal-temp-pos signal-pos)
15523 (vhdl-goto-marker signal-temp-pos)
15524 (insert "\n") (indent-to vhdl-basic-offset)
15525 (insert "-- outputs of \"" inst-name "\"\n")
15526 (vhdl-goto-marker signal-pos))
15527 (setq inst-alist (cdr inst-alist)))
15528 ;; finalize generic/port clause
15529 (vhdl-goto-marker generic-end-pos) (backward-char)
15530 (when (= generic-beg-pos generic-end-pos)
15531 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15532 (insert ";") (backward-char))
15533 (insert ")")
15534 (vhdl-goto-marker port-end-pos) (backward-char)
15535 (when (= port-beg-pos port-end-pos)
15536 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15537 (insert ";") (backward-char))
15538 (insert ")")
15539 ;; align everything
15540 (when vhdl-auto-align
15541 (vhdl-goto-marker generic-beg-pos)
15542 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15543 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15544 (vhdl-goto-marker signal-beg-pos)
15545 (vhdl-align-region-groups signal-beg-pos signal-pos))
15546 (switch-to-buffer (marker-buffer signal-beg-pos))
15547 (message "Wiring components...done")))))
15548
15549(defun vhdl-compose-insert-generic (entry)
15550 "Insert ENTRY as generic declaration."
15551 (let (pos)
15552 (indent-to (* 2 vhdl-basic-offset))
15553 (insert (nth 0 entry) " : " (nth 1 entry))
15554 (when (nth 2 entry)
15555 (insert " := " (nth 2 entry)))
15556 (insert ";")
15557 (setq pos (point-marker))
15558 (when (and vhdl-include-port-comments (nth 3 entry))
15559 (vhdl-comment-insert-inline (nth 3 entry) t))
15560 (insert "\n")
15561 pos))
15562
15563(defun vhdl-compose-insert-port (entry)
15564 "Insert ENTRY as port declaration."
15565 (let (pos)
15566 (indent-to (* 2 vhdl-basic-offset))
15567 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15568 (setq pos (point-marker))
15569 (when (and vhdl-include-port-comments (nth 4 entry))
15570 (vhdl-comment-insert-inline (nth 4 entry) t))
15571 (insert "\n")
15572 pos))
15573
15574(defun vhdl-compose-insert-signal (entry)
15575 "Insert ENTRY as signal declaration."
15576 (indent-to vhdl-basic-offset)
15577 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15578 (when (and vhdl-include-port-comments (nth 4 entry))
15579 (vhdl-comment-insert-inline (nth 4 entry) t))
15580 (insert "\n"))
15581
15582(defun vhdl-compose-components-package ()
15583 "Generate a package containing component declarations for all entities in the
15584current project/directory."
15585 (interactive)
15586 (vhdl-require-hierarchy-info)
15587 (let* ((project (vhdl-project-p))
15588 (pack-name (vhdl-get-components-package-name))
15589 (pack-file-name
15590 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15591 "." (file-name-extension (buffer-file-name))))
15592 (ent-alist (aget vhdl-entity-alist
15593 (or project default-directory) t))
15594 (lazy-lock-minimum-size 0)
15595 clause-pos component-pos)
15596 (message "Generating components package \"%s\"..." pack-name)
15597 ;; open package file
15598 (when (and (file-exists-p pack-file-name)
15599 (not (y-or-n-p (concat "File \"" pack-file-name
15600 "\" exists; overwrite? "))))
15601 (error "ERROR: Generating components package...aborted"))
15602 (find-file pack-file-name)
15603 (erase-buffer)
15604 ;; insert header
15605 (if vhdl-compose-include-header
15606 (progn (vhdl-template-header
15607 (concat "Components package (generated by Emacs VHDL Mode "
15608 vhdl-version ")"))
15609 (goto-char (point-max)))
15610 (vhdl-comment-display-line) (insert "\n\n"))
15611 ;; insert std_logic_1164 package
15612 (vhdl-template-package-std-logic-1164)
15613 (insert "\n") (setq clause-pos (point-marker))
15614 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15615 ;; insert package declaration
15616 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15617 (vhdl-insert-keyword " IS\n\n")
15618 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15619 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15620 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15621 (indent-to vhdl-basic-offset)
15622 (setq component-pos (point-marker))
15623 (insert "\n\n") (vhdl-insert-keyword "END ")
15624 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15625 (insert pack-name ";\n\n")
15626 ;; insert footer
15627 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15628 (vhdl-template-footer)
15629 (vhdl-comment-display-line) (insert "\n"))
15630 ;; insert component declarations
15631 (while ent-alist
15632 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15633 (progn (goto-line (nth 3 (car ent-alist)))
15634 (end-of-line)
15635 (vhdl-port-copy)))
15636 (goto-char component-pos)
15637 (vhdl-port-paste-component t)
15638 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15639 (setq component-pos (point-marker))
15640 (goto-char clause-pos)
15641 (vhdl-port-paste-context-clause pack-name)
15642 (setq clause-pos (point-marker))
15643 (setq ent-alist (cdr ent-alist)))
15644 (goto-char (point-min))
15645 (save-buffer)
15646 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15647 pack-name pack-file-name)))
15648
15649
15650;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15651;;; Compilation / Makefile generation
15652;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15653;; (using `compile.el')
15654
15655(defun vhdl-makefile-name ()
15656 "Return the Makefile name of the current project or the current compiler if
15657no project is defined."
15658 (let ((project-alist (aget vhdl-project-alist vhdl-project))
15659 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
15660 (vhdl-replace-string
15661 (cons "\\(.*\\)\n\\(.*\\)"
15662 (or (nth 8 project-alist) (nth 8 compiler-alist)))
15663 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
15664
15665(defun vhdl-compile-directory ()
15666 "Return the directory where compilation/make should be run."
15667 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
15668 (compiler (aget vhdl-compiler-alist vhdl-compiler))
15669 (directory (vhdl-resolve-env-variable
15670 (if project
15671 (vhdl-replace-string
15672 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
15673 (nth 6 compiler)))))
15674 (file-name-as-directory
15675 (if (file-name-absolute-p directory)
15676 directory
15677 (expand-file-name directory (vhdl-default-directory))))))
15678
15679(defun vhdl-uniquify (in-list)
15680 "Remove duplicate elements from IN-LIST."
15681 (let (out-list)
15682 (while in-list
15683 (add-to-list 'out-list (car in-list))
15684 (setq in-list (cdr in-list)))
15685 out-list))
15686
15687(defun vhdl-set-compiler (name)
15688 "Set current compiler to NAME."
15689 (interactive
15690 (list (let ((completion-ignore-case t))
15691 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
15692 (if (assoc name vhdl-compiler-alist)
15693 (progn (setq vhdl-compiler name)
15694 (message "Current compiler: \"%s\"" vhdl-compiler))
15695 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
15696
15697;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15698;; Compilation
15699
15700(defun vhdl-compile-init ()
15701 "Initialize for compilation."
15702 (when (or (null compilation-error-regexp-alist)
15703 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
15704 compilation-error-regexp-alist)))
15705 ;; `compilation-error-regexp-alist'
15706 (let ((commands-alist vhdl-compiler-alist)
15707 regexp-alist sublist)
15708 (while commands-alist
15709 (setq sublist (nth 11 (car commands-alist)))
15710 (unless (or (equal "" (car sublist))
15711 (assoc (car sublist) regexp-alist))
15712 (setq regexp-alist (cons (list (nth 0 sublist)
15713 (if (= 0 (nth 1 sublist))
15714 (if vhdl-xemacs 9 nil)
15715 (nth 1 sublist))
15716 (nth 2 sublist) (nth 3 sublist))
15717 regexp-alist)))
15718 (setq commands-alist (cdr commands-alist)))
15719 (setq compilation-error-regexp-alist
15720 (append compilation-error-regexp-alist (nreverse regexp-alist))))
15721 ;; `compilation-file-regexp-alist'
15722 (let ((commands-alist vhdl-compiler-alist)
15723 regexp-alist sublist)
15724 ;; matches vhdl-mode file name output
15725 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
15726 (while commands-alist
15727 (setq sublist (nth 12 (car commands-alist)))
15728 (unless (or (equal "" (car sublist))
15729 (assoc (car sublist) regexp-alist))
15730 (setq regexp-alist (cons sublist regexp-alist)))
15731 (setq commands-alist (cdr commands-alist)))
15732 (setq compilation-file-regexp-alist
15733 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
15734
15735(defvar vhdl-compile-file-name nil
15736 "Name of file to be compiled.")
15737
15738(defun vhdl-compile-print-file-name ()
15739 "Function called within `compile' to print out file name for compilers that
15740do not print any file names."
15741 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
15742
15743(defun vhdl-get-compile-options (project compiler file-name
15744 &optional file-options-only)
15745 "Get compiler options. Returning nil means do not compile this file."
15746 (let* ((compiler-options (nth 1 compiler))
15747 (project-entry (aget (nth 4 project) vhdl-compiler))
15748 (project-options (nth 0 project-entry))
15749 (exception-list (and file-name (nth 2 project-entry)))
15750 (work-library (vhdl-work-library))
15751 (case-fold-search nil)
15752 file-options)
15753 (while (and exception-list
15754 (not (string-match (caar exception-list) file-name)))
15755 (setq exception-list (cdr exception-list)))
15756 (if (and exception-list (not (cdar exception-list)))
15757 nil
15758 (if (and file-options-only (not exception-list))
15759 'default
15760 (setq file-options (cdar exception-list))
15761 ;; insert library name in compiler-specific options
15762 (setq compiler-options
15763 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
15764 work-library))
15765 ;; insert compiler-specific options in project-specific options
15766 (when project-options
15767 (setq project-options
15768 (vhdl-replace-string
15769 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15770 (concat work-library "\n" compiler-options))))
15771 ;; insert project-specific options in file-specific options
15772 (when file-options
15773 (setq file-options
15774 (vhdl-replace-string
15775 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
15776 (concat work-library "\n" compiler-options "\n"
15777 project-options))))
15778 ;; return options
15779 (or file-options project-options compiler-options)))))
15780
15781(defun vhdl-get-make-options (project compiler)
15782 "Get make options."
15783 (let* ((compiler-options (nth 3 compiler))
15784 (project-entry (aget (nth 4 project) vhdl-compiler))
15785 (project-options (nth 1 project-entry))
15786 (makefile-name (vhdl-makefile-name)))
15787 ;; insert Makefile name in compiler-specific options
15788 (setq compiler-options
15789 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
15790 makefile-name))
15791 ;; insert compiler-specific options in project-specific options
15792 (when project-options
15793 (setq project-options
15794 (vhdl-replace-string
15795 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15796 (concat makefile-name "\n" compiler-options))))
15797 ;; return options
15798 (or project-options compiler-options)))
15799
15800(defun vhdl-compile ()
15801 "Compile current buffer using the VHDL compiler specified in
15802`vhdl-compiler'."
15803 (interactive)
15804 (vhdl-compile-init)
15805 (let* ((project (aget vhdl-project-alist vhdl-project))
15806 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
15807 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15808 (command (nth 0 compiler))
15809 (file-name (buffer-file-name))
15810 (options (vhdl-get-compile-options project compiler file-name))
15811 (default-directory (vhdl-compile-directory))
15812 compilation-process-setup-function)
15813 (unless (file-directory-p default-directory)
15814 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15815 ;; put file name into quotes if it contains spaces
15816 (when (string-match " " file-name)
15817 (setq file-name (concat "\"" file-name "\"")))
15818 ;; print out file name if compiler does not
15819 (setq vhdl-compile-file-name (buffer-file-name))
15820 (when (and (= 0 (nth 1 (nth 10 compiler)))
15821 (= 0 (nth 1 (nth 11 compiler))))
15822 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
15823 ;; run compilation
15824 (if options
15825 (when command
15826 (compile (concat command " " options " " file-name)))
15827 (vhdl-warning "Your project settings tell me not to compile this file"))))
15828
15829(defun vhdl-make (&optional target)
15830 "Call make command for compilation of all updated source files (requires
15831`Makefile'). Optional argument TARGET allows to compile the design
15832specified by a target."
15833 (interactive)
15834 (vhdl-compile-init)
15835 (let* ((project (aget vhdl-project-alist vhdl-project))
15836 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15837 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15838 (command (nth 2 compiler))
15839 (options (vhdl-get-make-options project compiler))
15840 (default-directory (vhdl-compile-directory)))
15841 (unless (file-directory-p default-directory)
15842 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15843 ;; run make
15844 (compile (concat (if (equal command "") "make" command)
15845 " " options " " target))))
15846
15847;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15848;; Makefile generation
15849
15850(defun vhdl-generate-makefile ()
15851 "Generate `Makefile'."
15852 (interactive)
15853 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15854 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15855 (command (nth 4 compiler)))
15856 ;; generate makefile
15857 (if command
15858 (let ((default-directory (vhdl-compile-directory)))
15859 (compile (vhdl-replace-string
15860 (cons "\\(.*\\) \\(.*\\)" command)
15861 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
15862 (vhdl-generate-makefile-1))))
15863
15864(defun vhdl-get-packages (lib-alist work-library)
15865 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
15866 (let (pack-list)
15867 (while lib-alist
15868 (when (equal (downcase (caar lib-alist)) (downcase work-library))
15869 (setq pack-list (cons (cdar lib-alist) pack-list)))
15870 (setq lib-alist (cdr lib-alist)))
15871 pack-list))
15872
15873(defun vhdl-generate-makefile-1 ()
15874 "Generate Makefile for current project or directory."
15875 ;; scan hierarchy if required
15876 (if (vhdl-project-p)
15877 (unless (or (assoc vhdl-project vhdl-file-alist)
15878 (vhdl-load-cache vhdl-project))
15879 (vhdl-scan-project-contents vhdl-project))
15880 (let ((directory (abbreviate-file-name default-directory)))
15881 (unless (or (assoc directory vhdl-file-alist)
15882 (vhdl-load-cache directory))
15883 (vhdl-scan-directory-contents directory))))
15884 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
15885 (project (vhdl-project-p))
15886 (ent-alist (aget vhdl-entity-alist (or project directory) t))
15887 (conf-alist (aget vhdl-config-alist (or project directory) t))
15888 (pack-alist (aget vhdl-package-alist (or project directory) t))
15889 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
15890 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
15891 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
15892 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
15893 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
15894 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
15895 (adjust-case (nth 5 regexp-list))
15896 (work-library (downcase (vhdl-work-library)))
15897 (compile-directory (expand-file-name (vhdl-compile-directory)
15898 default-directory))
15899 (makefile-name (vhdl-makefile-name))
15900 rule-alist arch-alist inst-alist
15901 target-list depend-list unit-list prim-list second-list subcomp-list
15902 lib-alist lib-body-alist pack-list all-pack-list
15903 ent-key ent-file-name arch-key arch-file-name ent-arch-key
15904 conf-key conf-file-name pack-key pack-file-name
15905 ent-entry arch-entry conf-entry pack-entry inst-entry
15906 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
15907 tmp-key tmp-list rule)
15908 ;; check prerequisites
15909 (unless (file-exists-p compile-directory)
15910 (make-directory compile-directory t))
15911 (unless regexp-list
15912 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
15913 vhdl-compiler))
15914 (message "Generating makefile \"%s\"..." makefile-name)
15915 ;; rules for all entities
15916 (setq tmp-list ent-alist)
15917 (while ent-alist
15918 (setq ent-entry (car ent-alist)
15919 ent-key (nth 0 ent-entry))
15920 (when (nth 2 ent-entry)
15921 (setq ent-file-name (file-relative-name
15922 (nth 2 ent-entry) compile-directory)
15923 arch-alist (nth 4 ent-entry)
15924 lib-alist (nth 5 ent-entry)
15925 rule (aget rule-alist ent-file-name)
15926 target-list (nth 0 rule)
15927 depend-list (nth 1 rule)
15928 second-list nil
15929 subcomp-list nil)
15930 (setq tmp-key (vhdl-replace-string
15931 ent-regexp (funcall adjust-case ent-key)))
15932 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
15933 ;; rule target for this entity
15934 (setq target-list (cons ent-key target-list))
15935 ;; rule dependencies for all used packages
15936 (setq pack-list (vhdl-get-packages lib-alist work-library))
15937 (setq depend-list (append depend-list pack-list))
15938 (setq all-pack-list pack-list)
15939 ;; add rule
15940 (aput 'rule-alist ent-file-name (list target-list depend-list))
15941 ;; rules for all corresponding architectures
15942 (while arch-alist
15943 (setq arch-entry (car arch-alist)
15944 arch-key (nth 0 arch-entry)
15945 ent-arch-key (concat ent-key "-" arch-key)
15946 arch-file-name (file-relative-name (nth 2 arch-entry)
15947 compile-directory)
15948 inst-alist (nth 4 arch-entry)
15949 lib-alist (nth 5 arch-entry)
15950 rule (aget rule-alist arch-file-name)
15951 target-list (nth 0 rule)
15952 depend-list (nth 1 rule))
15953 (setq tmp-key (vhdl-replace-string
15954 arch-regexp
15955 (funcall adjust-case (concat arch-key " " ent-key))))
15956 (setq unit-list
15957 (cons (cons ent-arch-key tmp-key) unit-list))
15958 (setq second-list (cons ent-arch-key second-list))
15959 ;; rule target for this architecture
15960 (setq target-list (cons ent-arch-key target-list))
15961 ;; rule dependency for corresponding entity
15962 (setq depend-list (cons ent-key depend-list))
15963 ;; rule dependencies for contained component instantiations
15964 (while inst-alist
15965 (setq inst-entry (car inst-alist))
15966 (when (or (null (nth 8 inst-entry))
15967 (equal (downcase (nth 8 inst-entry)) work-library))
15968 (setq inst-ent-key (or (nth 7 inst-entry)
15969 (nth 5 inst-entry)))
15970 (setq depend-list (cons inst-ent-key depend-list)
15971 subcomp-list (cons inst-ent-key subcomp-list)))
15972 (setq inst-alist (cdr inst-alist)))
15973 ;; rule dependencies for all used packages
15974 (setq pack-list (vhdl-get-packages lib-alist work-library))
15975 (setq depend-list (append depend-list pack-list))
15976 (setq all-pack-list (append all-pack-list pack-list))
15977 ;; add rule
15978 (aput 'rule-alist arch-file-name (list target-list depend-list))
15979 (setq arch-alist (cdr arch-alist)))
15980 (setq prim-list (cons (list ent-key second-list
15981 (append subcomp-list all-pack-list))
15982 prim-list)))
15983 (setq ent-alist (cdr ent-alist)))
15984 (setq ent-alist tmp-list)
15985 ;; rules for all configurations
15986 (setq tmp-list conf-alist)
15987 (while conf-alist
15988 (setq conf-entry (car conf-alist)
15989 conf-key (nth 0 conf-entry)
15990 conf-file-name (file-relative-name
15991 (nth 2 conf-entry) compile-directory)
15992 ent-key (nth 4 conf-entry)
15993 arch-key (nth 5 conf-entry)
15994 inst-alist (nth 6 conf-entry)
15995 lib-alist (nth 7 conf-entry)
15996 rule (aget rule-alist conf-file-name)
15997 target-list (nth 0 rule)
15998 depend-list (nth 1 rule)
15999 subcomp-list (list ent-key))
16000 (setq tmp-key (vhdl-replace-string
16001 conf-regexp (funcall adjust-case conf-key)))
16002 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
16003 ;; rule target for this configuration
16004 (setq target-list (cons conf-key target-list))
16005 ;; rule dependency for corresponding entity and architecture
16006 (setq depend-list
16007 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16008 ;; rule dependencies for used packages
16009 (setq pack-list (vhdl-get-packages lib-alist work-library))
16010 (setq depend-list (append depend-list pack-list))
16011 ;; rule dependencies for contained component configurations
16012 (while inst-alist
16013 (setq inst-entry (car inst-alist))
16014 (setq inst-ent-key (nth 2 inst-entry)
16015; comp-arch-key (nth 2 inst-entry))
16016 inst-conf-key (nth 4 inst-entry))
16017 (when (equal (downcase (nth 5 inst-entry)) work-library)
16018 (when inst-ent-key
16019 (setq depend-list (cons inst-ent-key depend-list)
16020 subcomp-list (cons inst-ent-key subcomp-list)))
16021; (when comp-arch-key
16022; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16023; depend-list)))
16024 (when inst-conf-key
16025 (setq depend-list (cons inst-conf-key depend-list)
16026 subcomp-list (cons inst-conf-key subcomp-list))))
16027 (setq inst-alist (cdr inst-alist)))
16028 ;; add rule
16029 (aput 'rule-alist conf-file-name (list target-list depend-list))
16030 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16031 prim-list))
16032 (setq conf-alist (cdr conf-alist)))
16033 (setq conf-alist tmp-list)
16034 ;; rules for all packages
16035 (setq tmp-list pack-alist)
16036 (while pack-alist
16037 (setq pack-entry (car pack-alist)
16038 pack-key (nth 0 pack-entry)
16039 pack-body-key nil)
16040 (when (nth 2 pack-entry)
16041 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16042 compile-directory)
16043 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16044 rule (aget rule-alist pack-file-name)
16045 target-list (nth 0 rule) depend-list (nth 1 rule))
16046 (setq tmp-key (vhdl-replace-string
16047 pack-regexp (funcall adjust-case pack-key)))
16048 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16049 ;; rule target for this package
16050 (setq target-list (cons pack-key target-list))
16051 ;; rule dependencies for all used packages
16052 (setq pack-list (vhdl-get-packages lib-alist work-library))
16053 (setq depend-list (append depend-list pack-list))
16054 (setq all-pack-list pack-list)
16055 ;; add rule
16056 (aput 'rule-alist pack-file-name (list target-list depend-list))
16057 ;; rules for this package's body
16058 (when (nth 7 pack-entry)
16059 (setq pack-body-key (concat pack-key "-body")
16060 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16061 compile-directory)
16062 rule (aget rule-alist pack-body-file-name)
16063 target-list (nth 0 rule)
16064 depend-list (nth 1 rule))
16065 (setq tmp-key (vhdl-replace-string
16066 pack-body-regexp (funcall adjust-case pack-key)))
16067 (setq unit-list
16068 (cons (cons pack-body-key tmp-key) unit-list))
16069 ;; rule target for this package's body
16070 (setq target-list (cons pack-body-key target-list))
16071 ;; rule dependency for corresponding package declaration
16072 (setq depend-list (cons pack-key depend-list))
16073 ;; rule dependencies for all used packages
16074 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16075 (setq depend-list (append depend-list pack-list))
16076 (setq all-pack-list (append all-pack-list pack-list))
16077 ;; add rule
16078 (aput 'rule-alist pack-body-file-name
16079 (list target-list depend-list)))
16080 (setq prim-list
16081 (cons (list pack-key (when pack-body-key (list pack-body-key))
16082 all-pack-list)
16083 prim-list)))
16084 (setq pack-alist (cdr pack-alist)))
16085 (setq pack-alist tmp-list)
16086 ;; generate Makefile
16087 (let* ((project (aget vhdl-project-alist project))
16088 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16089 (compiler-id (nth 9 compiler))
16090 (library-directory
16091 (vhdl-resolve-env-variable
16092 (vhdl-replace-string
16093 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16094 compiler-id)))
16095 (makefile-path-name (expand-file-name
16096 makefile-name compile-directory))
16097 (orig-buffer (current-buffer))
16098 cell second-list subcomp-list options unit-key unit-name)
16099 ;; sort lists
16100 (setq unit-list (vhdl-sort-alist unit-list))
16101 (setq prim-list (vhdl-sort-alist prim-list))
16102 (setq tmp-list rule-alist)
16103 (while tmp-list ; pre-sort rule targets
16104 (setq cell (cdar tmp-list))
16105 (setcar cell (sort (car cell) 'string<))
16106 (setq tmp-list (cdr tmp-list)))
16107 (setq rule-alist ; sort by first rule target
16108 (sort rule-alist
16109 (function (lambda (a b)
16110 (string< (car (cadr a)) (car (cadr b)))))))
16111 ;; open and clear Makefile
16112 (set-buffer (find-file-noselect makefile-path-name t t))
16113 (erase-buffer)
16114 (insert "# -*- Makefile -*-\n"
16115 "### " (file-name-nondirectory makefile-name)
16116 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16117 "\n")
16118 (if project
16119 (insert "\n# Project : " (nth 0 project))
16120 (insert "\n# Directory : \"" directory "\""))
16121 (insert "\n# Platform : " vhdl-compiler
16122 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16123 (user-login-name) "\n")
16124 ;; insert compile and option variable settings
16125 (insert "\n\n# Define compilation command and options\n"
16126 "\nCOMPILE = " (nth 0 compiler)
16127 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16128 "\n")
16129 ;; insert library paths
16130 (setq library-directory
16131 (directory-file-name
16132 (if (file-name-absolute-p library-directory)
16133 library-directory
16134 (file-relative-name
16135 (expand-file-name library-directory directory)
16136 compile-directory))))
16137 (insert "\n\n# Define library paths\n"
16138 "\nLIBRARY-" work-library " = " library-directory "\n")
16139 ;; insert variable definitions for all library unit files
16140 (insert "\n\n# Define library unit files\n")
16141 (setq tmp-list unit-list)
16142 (while unit-list
16143 (insert "\nUNIT-" work-library "-" (caar unit-list)
16144 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16145 (setq unit-list (cdr unit-list)))
16146 ;; insert variable definition for list of all library unit files
16147 (insert "\n\n\n# Define list of all library unit files\n"
16148 "\nALL_UNITS =")
16149 (setq unit-list tmp-list)
16150 (while unit-list
16151 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16152 (setq unit-list (cdr unit-list)))
16153 (insert "\n")
16154 (setq unit-list tmp-list)
16155 ;; insert `make all' rule
16156 (insert "\n\n\n# Rule for compiling entire design\n"
16157 "\nall :"
16158 " \\\n\t\tlibrary"
16159 " \\\n\t\t$(ALL_UNITS)\n")
16160 ;; insert `make clean' rule
16161 (insert "\n\n# Rule for cleaning entire design\n"
16162 "\nclean : "
16163 "\n\t-rm -f $(ALL_UNITS)\n")
16164 ;; insert `make library' rule
16165 (insert "\n\n# Rule for creating library directory\n"
16166 "\nlibrary :"
16167 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16168 "\n$(LIBRARY-" work-library ") :"
16169 "\n\t"
16170 (vhdl-replace-string
16171 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16172 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16173 "\n")
16174 ;; insert rule for each library unit
16175 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16176 (while prim-list
16177 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16178 (setq subcomp-list
16179 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16180 (setq unit-key (caar prim-list)
16181 unit-name (or (nth 0 (aget ent-alist unit-key t))
16182 (nth 0 (aget conf-alist unit-key t))
16183 (nth 0 (aget pack-alist unit-key t))))
16184 (insert "\n" unit-key)
16185 (unless (equal unit-key unit-name)
16186 (insert " \\\n" unit-name))
16187 (insert " :"
16188 " \\\n\t\tlibrary"
16189 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16190 (while second-list
16191 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16192 (setq second-list (cdr second-list)))
16193 (while subcomp-list
16194 (when (assoc (car subcomp-list) unit-list)
16195 (insert " \\\n\t\t" (car subcomp-list)))
16196 (setq subcomp-list (cdr subcomp-list)))
16197 (insert "\n")
16198 (setq prim-list (cdr prim-list)))
16199 ;; insert rule for each library unit file
16200 (insert "\n\n# Rules for compiling single library unit files\n")
16201 (while rule-alist
16202 (setq rule (car rule-alist))
16203 ;; get compiler options for this file
16204 (setq options
16205 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16206 ;; insert rule if file is supposed to be compiled
16207 (setq target-list (nth 1 rule)
16208 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16209 ;; insert targets
16210 (setq tmp-list target-list)
16211 (while target-list
16212 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16213 (if (cdr target-list) " \\" " :"))
16214 (setq target-list (cdr target-list)))
16215 (setq target-list tmp-list)
16216 ;; insert file name as first dependency
16217 (insert " \\\n\t\t" (nth 0 rule))
16218 ;; insert dependencies (except if also target or unit does not exist)
16219 (while depend-list
16220 (when (and (not (member (car depend-list) target-list))
16221 (assoc (car depend-list) unit-list))
16222 (insert " \\\n\t\t"
16223 "$(UNIT-" work-library "-" (car depend-list) ")"))
16224 (setq depend-list (cdr depend-list)))
16225 ;; insert compile command
16226 (if options
16227 (insert "\n\t$(COMPILE) "
16228 (if (eq options 'default) "$(OPTIONS)" options) " "
16229 (nth 0 rule) "\n")
16230 (setq tmp-list target-list)
16231 (while target-list
16232 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16233 (if (cdr target-list) " \\" "\n"))
16234 (setq target-list (cdr target-list)))
16235 (setq target-list tmp-list))
16236 (setq rule-alist (cdr rule-alist)))
16237 (insert "\n\n### " makefile-name " ends here\n")
16238 ;; run Makefile generation hook
16239 (run-hooks 'vhdl-makefile-generation-hook)
16240 (message "Generating makefile \"%s\"...done" makefile-name)
16241 ;; save and close file
16242 (if (file-writable-p makefile-path-name)
16243 (progn (save-buffer)
16244 (kill-buffer (current-buffer))
16245 (set-buffer orig-buffer)
16246 (setq file-name-history
16247 (cons makefile-path-name file-name-history)))
16248 (vhdl-warning-when-idle
16249 (format "File not writable: \"%s\""
16250 (abbreviate-file-name makefile-path-name)))
16251 (switch-to-buffer (current-buffer))))))
16252
5eabfe72
KH
16253
16254;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16255;;; Bug reports
16256;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16257;; (using `reporter.el')
16258
3dcb36b7
JB
16259(defconst vhdl-mode-help-address
16260 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16261 "Address for VHDL Mode bug reports.")
16262
3dcb36b7
JB
16263(defun vhdl-submit-bug-report ()
16264 "Submit via mail a bug report on VHDL Mode."
16265 (interactive)
16266 ;; load in reporter
16267 (and
16268 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16269 (let ((reporter-prompt-for-summary-p t))
16270 (reporter-submit-bug-report
16271 vhdl-mode-help-address
16272 (concat "VHDL Mode " vhdl-version)
16273 (list
16274 ;; report all important user options
16275 'vhdl-offsets-alist
16276 'vhdl-comment-only-line-offset
16277 'tab-width
16278 'vhdl-electric-mode
16279 'vhdl-stutter-mode
16280 'vhdl-indent-tabs-mode
16281 'vhdl-project-alist
16282 'vhdl-project
16283 'vhdl-project-file-name
16284 'vhdl-project-auto-load
16285 'vhdl-project-sort
16286 'vhdl-compiler-alist
16287 'vhdl-compiler
16288 'vhdl-compile-use-local-error-regexp
16289 'vhdl-makefile-generation-hook
16290 'vhdl-default-library
16291 'vhdl-standard
16292 'vhdl-basic-offset
16293 'vhdl-upper-case-keywords
16294 'vhdl-upper-case-types
16295 'vhdl-upper-case-attributes
16296 'vhdl-upper-case-enum-values
16297 'vhdl-upper-case-constants
16298 'vhdl-use-direct-instantiation
16299 'vhdl-entity-file-name
16300 'vhdl-architecture-file-name
16301 'vhdl-package-file-name
16302 'vhdl-file-name-case
16303 'vhdl-electric-keywords
16304 'vhdl-optional-labels
16305 'vhdl-insert-empty-lines
16306 'vhdl-argument-list-indent
16307 'vhdl-association-list-with-formals
16308 'vhdl-conditions-in-parenthesis
16309 'vhdl-zero-string
16310 'vhdl-one-string
16311 'vhdl-file-header
16312 'vhdl-file-footer
16313 'vhdl-company-name
16314 'vhdl-copyright-string
16315 'vhdl-platform-spec
16316 'vhdl-date-format
16317 'vhdl-modify-date-prefix-string
16318 'vhdl-modify-date-on-saving
16319 'vhdl-reset-kind
16320 'vhdl-reset-active-high
16321 'vhdl-clock-rising-edge
16322 'vhdl-clock-edge-condition
16323 'vhdl-clock-name
16324 'vhdl-reset-name
16325 'vhdl-model-alist
16326 'vhdl-include-port-comments
16327 'vhdl-include-direction-comments
16328 'vhdl-include-type-comments
16329 'vhdl-include-group-comments
16330 'vhdl-actual-port-name
16331 'vhdl-instance-name
16332 'vhdl-testbench-entity-name
16333 'vhdl-testbench-architecture-name
16334 'vhdl-testbench-configuration-name
16335 'vhdl-testbench-dut-name
16336 'vhdl-testbench-include-header
16337 'vhdl-testbench-declarations
16338 'vhdl-testbench-statements
16339 'vhdl-testbench-initialize-signals
16340 'vhdl-testbench-include-library
16341 'vhdl-testbench-include-configuration
16342 'vhdl-testbench-create-files
16343 'vhdl-compose-create-files
16344 'vhdl-compose-include-header
16345 'vhdl-compose-architecture-name
16346 'vhdl-components-package-name
16347 'vhdl-use-components-package
16348 'vhdl-self-insert-comments
16349 'vhdl-prompt-for-comments
16350 'vhdl-inline-comment-column
16351 'vhdl-end-comment-column
16352 'vhdl-auto-align
16353 'vhdl-align-groups
16354 'vhdl-align-group-separate
16355 'vhdl-align-same-indent
16356 'vhdl-highlight-keywords
16357 'vhdl-highlight-names
16358 'vhdl-highlight-special-words
16359 'vhdl-highlight-forbidden-words
16360 'vhdl-highlight-verilog-keywords
16361 'vhdl-highlight-translate-off
16362 'vhdl-highlight-case-sensitive
16363 'vhdl-special-syntax-alist
16364 'vhdl-forbidden-words
16365 'vhdl-forbidden-syntax
16366 'vhdl-directive-keywords
16367 'vhdl-speedbar-auto-open
16368 'vhdl-speedbar-display-mode
16369 'vhdl-speedbar-scan-limit
16370 'vhdl-speedbar-jump-to-unit
16371 'vhdl-speedbar-update-on-saving
16372 'vhdl-speedbar-save-cache
16373 'vhdl-speedbar-cache-file-name
16374 'vhdl-index-menu
16375 'vhdl-source-file-menu
16376 'vhdl-hideshow-menu
16377 'vhdl-hide-all-init
16378 'vhdl-print-two-column
16379 'vhdl-print-customize-faces
16380 'vhdl-intelligent-tab
16381 'vhdl-indent-syntax-based
16382 'vhdl-word-completion-case-sensitive
16383 'vhdl-word-completion-in-minibuffer
16384 'vhdl-underscore-is-part-of-word
16385 'vhdl-mode-hook)
16386 (function
16387 (lambda ()
16388 (insert
16389 (if vhdl-special-indent-hook
16390 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16391 "vhdl-special-indent-hook is set to '"
16392 (format "%s" vhdl-special-indent-hook)
16393 ".\nPerhaps this is your problem?\n"
16394 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16395 "\n"))))
16396 nil
16397 "Hi Reto,"))))
16398
16399
16400;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16401;;; Documentation
16402;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16403
16404(defconst vhdl-doc-release-notes nil
16405 "\
16406Release Notes for VHDL Mode 3.32
16407================================
16408
16409 - New Features
16410 - Enhanced Features
16411 - User Options
16412 - Remarks
16413
16414
16415New Features
16416------------
16417
16418STRUCTURAL COMPOSITION:
16419 - Enables simple structural composition similar to graphical editors.
16420 Simplifies the creation of higher design levels where subcomponents
16421 are simply sticked together:
16422 1. Create a skeleton for a new component
16423 2. Place subcomponents in it directly from the hierarchy browser
16424 3. Automatically connect all subcomponents and create the ports
16425 for the new component (based on names of actual ports)
16426 - Automatic generation of a components package (package containing
16427 component declarations for all entities).
16428 - Find more information in the online documentation (`C-c C-h').
16429
16430PORT TRANSLATION:
16431 - Reverse direction of ports (useful for testbenches).
16432
16433SUBPROGRAM TRANSLATION:
16434 - Copy/paste of subprogram interfaces (similar to port translation).
16435
16436CODE FILLING:
16437 - Condense code using code-sensitive block filling.
16438
16439CODE STATISTICS:
16440 - Calculate number of code lines and statements in a buffer.
16441
16442
16443Enhanced Features
16444-----------------
16445
16446TESTBENCH GENERATION:
16447 - Enhanced templates and user option default values.
16448
16449Emacs 21 compatibility/enhancements:
16450 - `lazy-lock-mode' is not used anymore (built-in `jit-lock-mode' is faster).
16451
16452And many other minor fixes and enhancements.
16453
16454
16455User Options
16456------------
16457
16458`vhdl-project-file-name': (enhanced)
16459 Include user name in project setup file name.
16460`vhdl-speedbar-cache-file-name': (enhanced, changed default)
16461 Include user name in cache file name.
16462`vhdl-default-library': (new)
16463 Default working library if no project is active.
16464`vhdl-architecture-file-name': (new)
16465 Specify how the architecture file name is obtained.
16466`vhdl-package-file-name': (new)
16467 Specify how the package file name is obtained.
16468`vhdl-file-name-case': (new)
16469 Allows to change case when deriving file names.
16470`vhdl-compose-create-files': (new)
16471 Specify whether new files should be created for a new component.
16472`vhdl-compose-include-header': (new)
16473 Specify whether a header is included in a new component's file.
16474`vhdl-compose-architecture-name': (new)
16475 Specify how a new component's architecture name is obtained.
16476`vhdl-components-package-name': (new)
16477 Specify how the name for the components package is obtained.
16478`vhdl-use-components-package': (new)
16479 Specify whether component declarations go in a components package.
16480`vhdl-use-direct-instantiation': (new)
16481 Specify whether to use VHDL'93 direct component instantiation.
16482`vhdl-instance-name': (changed default)
16483 Allows insertion of a running number to generate unique instance names.
16484`vhdl-testbench-entity-header', `vhdl-testbench-architecture-header':(obsolete)
16485 Headers are now automatically derived from the standard header.
16486`vhdl-testbench-include-header': (new)
16487 Specify whether a header is included in testbench files.
16488`vhdl-testbench-declaration', `vhdl-testbench-statements': (changed default)
16489 Non-empty default values for more complete testbench templates.
16490
16491
16492Remarks
16493-------
16494
16495- Changed key binding for `vhdl-comment-uncomment-region': `C-c c'
16496 (`C-c C-c ...' is now used for structural composition).
16497
16498- Automatic buffer highlighting (font-lock) is now controlled by option
16499 `global-font-lock-mode' in GNU Emacs (`font-lock-auto-fontify' in XEmacs).
16500 \(Important: You MUST customize this option in order to turn automatic
16501 buffer highlighting on.)
16502")
16503
16504
16505(defconst vhdl-doc-keywords nil
16506 "\
16507Reserved words in VHDL
16508----------------------
16509
16510VHDL'93 (IEEE Std 1076-1993):
16511 `vhdl-93-keywords' : keywords
16512 `vhdl-93-types' : standardized types
16513 `vhdl-93-attributes' : standardized attributes
16514 `vhdl-93-enum-values' : standardized enumeration values
16515 `vhdl-93-functions' : standardized functions
16516 `vhdl-93-packages' : standardized packages and libraries
16517
16518VHDL-AMS (IEEE Std 1076.1):
16519 `vhdl-ams-keywords' : keywords
16520 `vhdl-ams-types' : standardized types
16521 `vhdl-ams-attributes' : standardized attributes
16522 `vhdl-ams-enum-values' : standardized enumeration values
16523 `vhdl-ams-functions' : standardized functions
16524
16525Math Packages (IEEE Std 1076.2):
16526 `vhdl-math-types' : standardized types
16527 `vhdl-math-constants' : standardized constants
16528 `vhdl-math-functions' : standardized functions
16529 `vhdl-math-packages' : standardized packages
16530
16531Forbidden words:
16532 `vhdl-verilog-keywords' : Verilog reserved words
16533
16534NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16535
16536
16537(defconst vhdl-doc-coding-style nil
16538 "\
16539For VHDL coding style and naming convention guidelines, see the following
16540references:
16541
16542\[1] Ben Cohen.
16543 \"VHDL Coding Styles and Methodologies\".
16544 Kluwer Academic Publishers, 1999.
16545 http://members.aol.com/vhdlcohen/vhdl/
16546
16547\[2] Michael Keating and Pierre Bricaud.
16548 \"Reuse Methodology Manual, Second Edition\".
16549 Kluwer Academic Publishers, 1999.
16550 http://www.openmore.com/openmore/rmm2.html
16551
16552\[3] European Space Agency.
16553 \"VHDL Modelling Guidelines\".
16554 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16555
16556Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16557to visually support naming conventions.")
16558
16559
d2ddb974
KH
16560(defun vhdl-version ()
16561 "Echo the current version of VHDL Mode in the minibuffer."
16562 (interactive)
3dcb36b7 16563 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16564 (vhdl-keep-region-active))
16565
3dcb36b7
JB
16566(defun vhdl-doc-variable (variable)
16567 "Display VARIABLE's documentation in *Help* buffer."
16568 (interactive)
4bcb9c95
SM
16569 (unless vhdl-xemacs
16570 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16571 (with-output-to-temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7 16572 (princ (documentation-property variable 'variable-documentation))
4bcb9c95 16573 (with-current-buffer standard-output
3dcb36b7
JB
16574 (help-mode))
16575 (print-help-return-message)))
d2ddb974 16576
3dcb36b7
JB
16577(defun vhdl-doc-mode ()
16578 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 16579 (interactive)
4bcb9c95
SM
16580 (unless vhdl-xemacs
16581 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16582 (with-output-to-temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")
3dcb36b7
JB
16583 (princ mode-name)
16584 (princ " mode:\n")
16585 (princ (documentation 'vhdl-mode))
4bcb9c95 16586 (with-current-buffer standard-output
3dcb36b7
JB
16587 (help-mode))
16588 (print-help-return-message)))
d2ddb974
KH
16589
16590
5eabfe72 16591;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16592
16593(provide 'vhdl-mode)
16594
4bcb9c95 16595;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
d2ddb974 16596;;; vhdl-mode.el ends here