*** empty log message ***
[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))
130 "Non-nil if GNU Emacs 21 is used.")
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."
2042 (if vhdl-xemacs
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)
3dcb36b7 2682 (define-key vhdl-mode-map "\t" 'indent-according-to-mode))
5eabfe72
KH
2683 (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
2684 (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
2685 (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
2686 (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
2687 (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
2688 (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
2689 (define-key vhdl-mode-map "," 'vhdl-electric-comma)
2690 (define-key vhdl-mode-map "." 'vhdl-electric-period)
2691 (when (vhdl-standard-p 'ams)
2692 (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
2693
2694;; initialize mode map for VHDL Mode
2695(vhdl-mode-map-init)
d2ddb974
KH
2696
2697;; define special minibuffer keymap for enabling word completion in minibuffer
2698;; (useful in template generator prompts)
2699(defvar vhdl-minibuffer-local-map (copy-keymap minibuffer-local-map)
2700 "Keymap for minibuffer used in VHDL Mode.")
2701
5eabfe72
KH
2702(when vhdl-word-completion-in-minibuffer
2703 (define-key vhdl-minibuffer-local-map "\t" 'vhdl-minibuffer-tab))
2704
2705;; set up electric character functions to work with
2706;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2707(mapcar
2708 (function
2709 (lambda (sym)
2710 (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
2711 (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
2712 '(vhdl-electric-space
2713 vhdl-electric-tab
2714 vhdl-electric-return
2715 vhdl-electric-dash
2716 vhdl-electric-open-bracket
2717 vhdl-electric-close-bracket
2718 vhdl-electric-quote
2719 vhdl-electric-semicolon
2720 vhdl-electric-comma
2721 vhdl-electric-period
2722 vhdl-electric-equal))
2723
3dcb36b7
JB
2724;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2725;; Syntax table
2726
d2ddb974 2727(defvar vhdl-mode-syntax-table nil
5eabfe72 2728 "Syntax table used in `vhdl-mode' buffers.")
d2ddb974 2729
3dcb36b7
JB
2730(defvar vhdl-mode-ext-syntax-table nil
2731 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2732
5eabfe72
KH
2733(defun vhdl-mode-syntax-table-init ()
2734 "Initialize `vhdl-mode-syntax-table'."
d2ddb974 2735 (setq vhdl-mode-syntax-table (make-syntax-table))
5eabfe72
KH
2736 ;; define punctuation
2737 (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
2738 (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
2739 (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
2740 (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
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 ;; define string
2754 (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
2755 ;; define underscore
2756 (when vhdl-underscore-is-part-of-word
3dcb36b7 2757 (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
5eabfe72
KH
2758 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2759 (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
2760 ;; and \n and \^M end a comment
2761 (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
2762 (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
2763 ;; define parentheses to match
2764 (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
2765 (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
2766 (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
2767 (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
2768 (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
3dcb36b7
JB
2769 (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
2770 ;; extended syntax table including '_' (for simpler search regexps)
2771 (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
2772 (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
5eabfe72
KH
2773
2774;; initialize syntax table for VHDL Mode
2775(vhdl-mode-syntax-table-init)
2776
d2ddb974
KH
2777(defvar vhdl-syntactic-context nil
2778 "Buffer local variable containing syntactic analysis list.")
2779(make-variable-buffer-local 'vhdl-syntactic-context)
2780
5eabfe72 2781;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 2782;; Abbrev ook bindings
d2ddb974
KH
2783
2784(defvar vhdl-mode-abbrev-table nil
5eabfe72
KH
2785 "Abbrev table to use in `vhdl-mode' buffers.")
2786
2787(defun vhdl-mode-abbrev-table-init ()
2788 "Initialize `vhdl-mode-abbrev-table'."
2789 (when vhdl-mode-abbrev-table (clear-abbrev-table vhdl-mode-abbrev-table))
2790 (define-abbrev-table 'vhdl-mode-abbrev-table
2791 (append
2792 (when (memq 'vhdl vhdl-electric-keywords)
2793 ;; VHDL'93 keywords
2794 '(
3dcb36b7
JB
2795 ("--" "" vhdl-template-display-comment-hook 0)
2796 ("abs" "" vhdl-template-default-hook 0)
2797 ("access" "" vhdl-template-default-hook 0)
2798 ("after" "" vhdl-template-default-hook 0)
2799 ("alias" "" vhdl-template-alias-hook 0)
2800 ("all" "" vhdl-template-default-hook 0)
2801 ("and" "" vhdl-template-default-hook 0)
2802 ("arch" "" vhdl-template-architecture-hook 0)
2803 ("architecture" "" vhdl-template-architecture-hook 0)
2804 ("array" "" vhdl-template-default-hook 0)
2805 ("assert" "" vhdl-template-assert-hook 0)
2806 ("attr" "" vhdl-template-attribute-hook 0)
2807 ("attribute" "" vhdl-template-attribute-hook 0)
2808 ("begin" "" vhdl-template-default-indent-hook 0)
2809 ("block" "" vhdl-template-block-hook 0)
2810 ("body" "" vhdl-template-default-hook 0)
2811 ("buffer" "" vhdl-template-default-hook 0)
2812 ("bus" "" vhdl-template-default-hook 0)
2813 ("case" "" vhdl-template-case-hook 0)
2814 ("comp" "" vhdl-template-component-hook 0)
2815 ("component" "" vhdl-template-component-hook 0)
2816 ("cond" "" vhdl-template-conditional-signal-asst-hook 0)
2817 ("conditional" "" vhdl-template-conditional-signal-asst-hook 0)
2818 ("conf" "" vhdl-template-configuration-hook 0)
2819 ("configuration" "" vhdl-template-configuration-hook 0)
2820 ("cons" "" vhdl-template-constant-hook 0)
2821 ("constant" "" vhdl-template-constant-hook 0)
2822 ("disconnect" "" vhdl-template-disconnect-hook 0)
2823 ("downto" "" vhdl-template-default-hook 0)
2824 ("else" "" vhdl-template-else-hook 0)
2825 ("elseif" "" vhdl-template-elsif-hook 0)
2826 ("elsif" "" vhdl-template-elsif-hook 0)
2827 ("end" "" vhdl-template-default-indent-hook 0)
2828 ("entity" "" vhdl-template-entity-hook 0)
2829 ("exit" "" vhdl-template-exit-hook 0)
2830 ("file" "" vhdl-template-file-hook 0)
2831 ("for" "" vhdl-template-for-hook 0)
2832 ("func" "" vhdl-template-function-hook 0)
2833 ("function" "" vhdl-template-function-hook 0)
2834 ("generic" "" vhdl-template-generic-hook 0)
2835 ("group" "" vhdl-template-group-hook 0)
2836 ("guarded" "" vhdl-template-default-hook 0)
2837 ("if" "" vhdl-template-if-hook 0)
2838 ("impure" "" vhdl-template-default-hook 0)
2839 ("in" "" vhdl-template-default-hook 0)
2840 ("inertial" "" vhdl-template-default-hook 0)
2841 ("inout" "" vhdl-template-default-hook 0)
2842 ("inst" "" vhdl-template-instance-hook 0)
2843 ("instance" "" vhdl-template-instance-hook 0)
2844 ("is" "" vhdl-template-default-hook 0)
2845 ("label" "" vhdl-template-default-hook 0)
2846 ("library" "" vhdl-template-library-hook 0)
2847 ("linkage" "" vhdl-template-default-hook 0)
2848 ("literal" "" vhdl-template-default-hook 0)
2849 ("loop" "" vhdl-template-bare-loop-hook 0)
2850 ("map" "" vhdl-template-map-hook 0)
2851 ("mod" "" vhdl-template-default-hook 0)
2852 ("nand" "" vhdl-template-default-hook 0)
2853 ("new" "" vhdl-template-default-hook 0)
2854 ("next" "" vhdl-template-next-hook 0)
2855 ("nor" "" vhdl-template-default-hook 0)
2856 ("not" "" vhdl-template-default-hook 0)
2857 ("null" "" vhdl-template-default-hook 0)
2858 ("of" "" vhdl-template-default-hook 0)
2859 ("on" "" vhdl-template-default-hook 0)
2860 ("open" "" vhdl-template-default-hook 0)
2861 ("or" "" vhdl-template-default-hook 0)
2862 ("others" "" vhdl-template-others-hook 0)
2863 ("out" "" vhdl-template-default-hook 0)
2864 ("pack" "" vhdl-template-package-hook 0)
2865 ("package" "" vhdl-template-package-hook 0)
2866 ("port" "" vhdl-template-port-hook 0)
2867 ("postponed" "" vhdl-template-default-hook 0)
2868 ("procedure" "" vhdl-template-procedure-hook 0)
2869 ("process" "" vhdl-template-process-hook 0)
2870 ("pure" "" vhdl-template-default-hook 0)
2871 ("range" "" vhdl-template-default-hook 0)
2872 ("record" "" vhdl-template-default-hook 0)
2873 ("register" "" vhdl-template-default-hook 0)
2874 ("reject" "" vhdl-template-default-hook 0)
2875 ("rem" "" vhdl-template-default-hook 0)
2876 ("report" "" vhdl-template-report-hook 0)
2877 ("return" "" vhdl-template-return-hook 0)
2878 ("rol" "" vhdl-template-default-hook 0)
2879 ("ror" "" vhdl-template-default-hook 0)
2880 ("select" "" vhdl-template-selected-signal-asst-hook 0)
2881 ("severity" "" vhdl-template-default-hook 0)
2882 ("shared" "" vhdl-template-default-hook 0)
2883 ("sig" "" vhdl-template-signal-hook 0)
2884 ("signal" "" vhdl-template-signal-hook 0)
2885 ("sla" "" vhdl-template-default-hook 0)
2886 ("sll" "" vhdl-template-default-hook 0)
2887 ("sra" "" vhdl-template-default-hook 0)
2888 ("srl" "" vhdl-template-default-hook 0)
2889 ("subtype" "" vhdl-template-subtype-hook 0)
2890 ("then" "" vhdl-template-default-hook 0)
2891 ("to" "" vhdl-template-default-hook 0)
2892 ("transport" "" vhdl-template-default-hook 0)
2893 ("type" "" vhdl-template-type-hook 0)
2894 ("unaffected" "" vhdl-template-default-hook 0)
2895 ("units" "" vhdl-template-default-hook 0)
2896 ("until" "" vhdl-template-default-hook 0)
2897 ("use" "" vhdl-template-use-hook 0)
2898 ("var" "" vhdl-template-variable-hook 0)
2899 ("variable" "" vhdl-template-variable-hook 0)
2900 ("wait" "" vhdl-template-wait-hook 0)
2901 ("when" "" vhdl-template-when-hook 0)
2902 ("while" "" vhdl-template-while-loop-hook 0)
2903 ("with" "" vhdl-template-with-hook 0)
2904 ("xnor" "" vhdl-template-default-hook 0)
2905 ("xor" "" vhdl-template-default-hook 0)
5eabfe72
KH
2906 ))
2907 ;; VHDL-AMS keywords
2908 (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
2909 '(
3dcb36b7
JB
2910 ("across" "" vhdl-template-default-hook 0)
2911 ("break" "" vhdl-template-break-hook 0)
2912 ("limit" "" vhdl-template-limit-hook 0)
2913 ("nature" "" vhdl-template-nature-hook 0)
2914 ("noise" "" vhdl-template-default-hook 0)
2915 ("procedural" "" vhdl-template-procedural-hook 0)
2916 ("quantity" "" vhdl-template-quantity-hook 0)
2917 ("reference" "" vhdl-template-default-hook 0)
2918 ("spectrum" "" vhdl-template-default-hook 0)
2919 ("subnature" "" vhdl-template-subnature-hook 0)
2920 ("terminal" "" vhdl-template-terminal-hook 0)
2921 ("through" "" vhdl-template-default-hook 0)
2922 ("tolerance" "" vhdl-template-default-hook 0)
5eabfe72
KH
2923 ))
2924 ;; user model keywords
2925 (when (memq 'user vhdl-electric-keywords)
2926 (let ((alist vhdl-model-alist)
2927 abbrev-list keyword)
2928 (while alist
2929 (setq keyword (nth 3 (car alist)))
2930 (unless (equal keyword "")
2931 (setq abbrev-list
2932 (cons (list keyword ""
2933 (vhdl-function-name
2934 "vhdl-model" (nth 0 (car alist)) "hook") 0)
2935 abbrev-list)))
2936 (setq alist (cdr alist)))
2937 abbrev-list)))))
2938
2939;; initialize abbrev table for VHDL Mode
2940(vhdl-mode-abbrev-table-init)
2941
2942;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2943;; Template completion lists
2944
2945(defvar vhdl-template-construct-alist nil
2946 "List of built-in construct templates.")
2947
2948(defun vhdl-template-construct-alist-init ()
2949 "Initialize `vhdl-template-construct-alist'."
2950 (setq
2951 vhdl-template-construct-alist
2952 (append
2953 '(
2954 ("alias declaration" vhdl-template-alias)
2955 ("architecture body" vhdl-template-architecture)
2956 ("assertion" vhdl-template-assert)
2957 ("attribute declaration" vhdl-template-attribute-decl)
2958 ("attribute specification" vhdl-template-attribute-spec)
2959 ("block configuration" vhdl-template-block-configuration)
2960 ("block statement" vhdl-template-block)
2961 ("case statement" vhdl-template-case-is)
2962 ("component configuration" vhdl-template-component-conf)
2963 ("component declaration" vhdl-template-component-decl)
2964 ("component instantiation statement" vhdl-template-component-inst)
2965 ("conditional signal assignment" vhdl-template-conditional-signal-asst)
2966 ("configuration declaration" vhdl-template-configuration-decl)
2967 ("configuration specification" vhdl-template-configuration-spec)
2968 ("constant declaration" vhdl-template-constant)
2969 ("disconnection specification" vhdl-template-disconnect)
2970 ("entity declaration" vhdl-template-entity)
2971 ("exit statement" vhdl-template-exit)
2972 ("file declaration" vhdl-template-file)
2973 ("generate statement" vhdl-template-generate)
2974 ("generic clause" vhdl-template-generic)
2975 ("group declaration" vhdl-template-group-decl)
2976 ("group template declaration" vhdl-template-group-template)
2977 ("if statement" vhdl-template-if-then)
2978 ("library clause" vhdl-template-library)
2979 ("loop statement" vhdl-template-loop)
2980 ("next statement" vhdl-template-next)
2981 ("package declaration" vhdl-template-package-decl)
2982 ("package body" vhdl-template-package-body)
2983 ("port clause" vhdl-template-port)
2984 ("process statement" vhdl-template-process)
2985 ("report statement" vhdl-template-report)
2986 ("return statement" vhdl-template-return)
2987 ("selected signal assignment" vhdl-template-selected-signal-asst)
2988 ("signal declaration" vhdl-template-signal)
2989 ("subprogram declaration" vhdl-template-subprogram-decl)
2990 ("subprogram body" vhdl-template-subprogram-body)
2991 ("subtype declaration" vhdl-template-subtype)
2992 ("type declaration" vhdl-template-type)
2993 ("use clause" vhdl-template-use)
2994 ("variable declaration" vhdl-template-variable)
2995 ("wait statement" vhdl-template-wait)
2996 )
2997 (when (vhdl-standard-p 'ams)
2998 '(
2999 ("break statement" vhdl-template-break)
3000 ("nature declaration" vhdl-template-nature)
3001 ("quantity declaration" vhdl-template-quantity)
3002 ("simultaneous case statement" vhdl-template-case-use)
3003 ("simultaneous if statement" vhdl-template-if-use)
3004 ("simultaneous procedural statement" vhdl-template-procedural)
3005 ("step limit specification" vhdl-template-limit)
3006 ("subnature declaration" vhdl-template-subnature)
3007 ("terminal declaration" vhdl-template-terminal)
3008 )))))
d2ddb974 3009
5eabfe72
KH
3010;; initialize for VHDL Mode
3011(vhdl-template-construct-alist-init)
3012
3013(defvar vhdl-template-package-alist nil
3014 "List of built-in package templates.")
3015
3016(defun vhdl-template-package-alist-init ()
3017 "Initialize `vhdl-template-package-alist'."
3018 (setq
3019 vhdl-template-package-alist
3020 (append
3021 '(
3022 ("numeric_bit" vhdl-template-package-numeric-bit)
3023 ("numeric_std" vhdl-template-package-numeric-std)
3024 ("std_logic_1164" vhdl-template-package-std-logic-1164)
3025 ("std_logic_arith" vhdl-template-package-std-logic-arith)
3026 ("std_logic_misc" vhdl-template-package-std-logic-misc)
3027 ("std_logic_signed" vhdl-template-package-std-logic-signed)
3028 ("std_logic_textio" vhdl-template-package-std-logic-textio)
3029 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
3030 ("textio" vhdl-template-package-textio)
3031 )
3032 (when (vhdl-standard-p 'math)
3033 '(
3034 ("math_complex" vhdl-template-package-math-complex)
3035 ("math_real" vhdl-template-package-math-real)
3036 )))))
d2ddb974 3037
5eabfe72
KH
3038;; initialize for VHDL Mode
3039(vhdl-template-package-alist-init)
d2ddb974 3040
5eabfe72 3041(defvar vhdl-template-directive-alist
3dcb36b7
JB
3042 '(
3043 ("translate_on" vhdl-template-directive-translate-on)
3044 ("translate_off" vhdl-template-directive-translate-off)
3045 ("synthesis_on" vhdl-template-directive-synthesis-on)
3046 ("synthesis_off" vhdl-template-directive-synthesis-off)
3047 )
5eabfe72 3048 "List of built-in directive templates.")
d2ddb974 3049
5eabfe72
KH
3050
3051;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3052;;; Menues
3053;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3054
3055;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
3056;; VHDL menu (using `easy-menu.el')
3057
5eabfe72
KH
3058(defun vhdl-customize ()
3059 "Call the customize function with `vhdl' as argument."
3060 (interactive)
3061 (customize-browse 'vhdl))
3062
5eabfe72
KH
3063(defun vhdl-create-mode-menu ()
3064 "Create VHDL Mode menu."
3dcb36b7
JB
3065 `("VHDL"
3066 ,(append
3067 '("Project"
3068 ["None" (vhdl-set-project "")
3069 :style radio :selected (null vhdl-project)]
3070 "--")
3071 ;; add menu entries for defined projects
3072 (let ((project-alist vhdl-project-alist) menu-list name)
3073 (while project-alist
3074 (setq name (caar project-alist))
3075 (setq menu-list
3076 (cons `[,name (vhdl-set-project ,name)
3077 :style radio :selected (equal ,name vhdl-project)]
3078 menu-list))
3079 (setq project-alist (cdr project-alist)))
3080 (setq menu-list
3081 (if vhdl-project-sort
3082 (sort menu-list
3083 (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
3084 (nreverse menu-list)))
3085 (vhdl-menu-split menu-list "Project"))
3086 '("--" "--"
3087 ["Select Project..." vhdl-set-project t]
3088 "--"
3089 ["Duplicate Project" vhdl-duplicate-project vhdl-project]
3090 ["Import Project..." vhdl-import-project
3091 :keys "C-c C-p C-m" :active t]
3092 ["Export Project" vhdl-export-project vhdl-project]
3093 "--"
3094 ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
d2ddb974 3095 "--"
3dcb36b7
JB
3096 ("Compile"
3097 ["Compile Buffer" vhdl-compile t]
3098 ["Stop Compilation" kill-compilation t]
3099 "--"
3100 ["Make" vhdl-make t]
3101 ["Generate Makefile" vhdl-generate-makefile t]
3102 "--"
3103 ["Next Error" next-error t]
3104 ["Previous Error" previous-error t]
3105 ["First Error" first-error t]
3106 "--"
3107 ,(append
3108 '("Compiler")
3109 ;; add menu entries for defined compilers
3110 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3111 (while comp-alist
3112 (setq name (caar comp-alist))
3113 (setq menu-list
3114 (cons `[,name (setq vhdl-compiler ,name)
3115 :style radio :selected (equal ,name vhdl-compiler)]
3116 menu-list))
3117 (setq comp-alist (cdr comp-alist)))
3118 (setq menu-list (nreverse menu-list))
3119 (vhdl-menu-split menu-list "Compiler"))
3120 '("--" "--"
3121 ["Select Compiler..." vhdl-set-compiler t]
3122 "--"
3123 ["Customize Compiler..."
3124 (customize-option 'vhdl-compiler-alist) t])))
5eabfe72 3125 "--"
3dcb36b7
JB
3126 ,(append
3127 '("Template"
3128 ("VHDL Construct 1"
3129 ["Alias" vhdl-template-alias t]
3130 ["Architecture" vhdl-template-architecture t]
3131 ["Assert" vhdl-template-assert t]
3132 ["Attribute (Decl)" vhdl-template-attribute-decl t]
3133 ["Attribute (Spec)" vhdl-template-attribute-spec t]
3134 ["Block" vhdl-template-block t]
3135 ["Case" vhdl-template-case-is t]
3136 ["Component (Decl)" vhdl-template-component-decl t]
3137 ["(Component) Instance" vhdl-template-component-inst t]
3138 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
3139 ["Configuration (Block)" vhdl-template-block-configuration t]
3140 ["Configuration (Comp)" vhdl-template-component-conf t]
3141 ["Configuration (Decl)" vhdl-template-configuration-decl t]
3142 ["Configuration (Spec)" vhdl-template-configuration-spec t]
3143 ["Constant" vhdl-template-constant t]
3144 ["Disconnect" vhdl-template-disconnect t]
3145 ["Else" vhdl-template-else t]
3146 ["Elsif" vhdl-template-elsif t]
3147 ["Entity" vhdl-template-entity t]
3148 ["Exit" vhdl-template-exit t]
3149 ["File" vhdl-template-file t]
3150 ["For (Generate)" vhdl-template-for-generate t]
3151 ["For (Loop)" vhdl-template-for-loop t]
3152 ["Function (Body)" vhdl-template-function-body t]
3153 ["Function (Decl)" vhdl-template-function-decl t]
3154 ["Generic" vhdl-template-generic t]
3155 ["Group (Decl)" vhdl-template-group-decl t]
3156 ["Group (Template)" vhdl-template-group-template t])
3157 ("VHDL Construct 2"
3158 ["If (Generate)" vhdl-template-if-generate t]
3159 ["If (Then)" vhdl-template-if-then t]
3160 ["Library" vhdl-template-library t]
3161 ["Loop" vhdl-template-bare-loop t]
3162 ["Map" vhdl-template-map t]
3163 ["Next" vhdl-template-next t]
3164 ["Others (Aggregate)" vhdl-template-others t]
3165 ["Package (Decl)" vhdl-template-package-decl t]
3166 ["Package (Body)" vhdl-template-package-body t]
3167 ["Port" vhdl-template-port t]
3168 ["Procedure (Body)" vhdl-template-procedure-body t]
3169 ["Procedure (Decl)" vhdl-template-procedure-decl t]
3170 ["Process (Comb)" vhdl-template-process-comb t]
3171 ["Process (Seq)" vhdl-template-process-seq t]
3172 ["Report" vhdl-template-report t]
3173 ["Return" vhdl-template-return t]
3174 ["Select" vhdl-template-selected-signal-asst t]
3175 ["Signal" vhdl-template-signal t]
3176 ["Subtype" vhdl-template-subtype t]
3177 ["Type" vhdl-template-type t]
3178 ["Use" vhdl-template-use t]
3179 ["Variable" vhdl-template-variable t]
3180 ["Wait" vhdl-template-wait t]
3181 ["(Clocked Wait)" vhdl-template-clocked-wait t]
3182 ["When" vhdl-template-when t]
3183 ["While (Loop)" vhdl-template-while-loop t]
3184 ["With" vhdl-template-with t]))
3185 (when (vhdl-standard-p 'ams)
3186 '(("VHDL-AMS Construct"
3187 ["Break" vhdl-template-break t]
3188 ["Case (Use)" vhdl-template-case-use t]
3189 ["If (Use)" vhdl-template-if-use t]
3190 ["Limit" vhdl-template-limit t]
3191 ["Nature" vhdl-template-nature t]
3192 ["Procedural" vhdl-template-procedural t]
3193 ["Quantity (Free)" vhdl-template-quantity-free t]
3194 ["Quantity (Branch)" vhdl-template-quantity-branch t]
3195 ["Quantity (Source)" vhdl-template-quantity-source t]
3196 ["Subnature" vhdl-template-subnature t]
3197 ["Terminal" vhdl-template-terminal t])))
3198 '(["Insert Construct..." vhdl-template-insert-construct
3199 :keys "C-c C-i C-t"]
3200 "--")
3201 (list
3202 (append
3203 '("Package")
3204 (when (vhdl-standard-p 'math)
3205 '(["math_complex" vhdl-template-package-math-complex t]
3206 ["math_real" vhdl-template-package-math-real t]))
3207 '(["numeric_bit" vhdl-template-package-numeric-bit t]
3208 ["numeric_std" vhdl-template-package-numeric-std t]
3209 ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
3210 ["textio" vhdl-template-package-textio t]
3211 "--"
3212 ["std_logic_arith" vhdl-template-package-std-logic-arith t]
3213 ["std_logic_signed" vhdl-template-package-std-logic-signed t]
3214 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
3215 ["std_logic_misc" vhdl-template-package-std-logic-misc t]
3216 ["std_logic_textio" vhdl-template-package-std-logic-textio t]
3217 "--"
3218 ["Insert Package..." vhdl-template-insert-package
3219 :keys "C-c C-i C-p"])))
3220 '(("Directive"
3221 ["translate_on" vhdl-template-directive-translate-on t]
3222 ["translate_off" vhdl-template-directive-translate-off t]
3223 ["synthesis_on" vhdl-template-directive-synthesis-on t]
3224 ["synthesis_off" vhdl-template-directive-synthesis-off t]
3225 "--"
3226 ["Insert Directive..." vhdl-template-insert-directive
3227 :keys "C-c C-i C-d"])
5eabfe72 3228 "--"
3dcb36b7
JB
3229 ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
3230 ["Insert Footer" vhdl-template-footer t]
3231 ["Insert Date" vhdl-template-insert-date t]
3232 ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
5eabfe72 3233 "--"
3dcb36b7
JB
3234 ["Query Next Prompt" vhdl-template-search-prompt t]))
3235 ,(append
3236 '("Model")
3237 ;; add menu entries for defined models
3238 (let ((model-alist vhdl-model-alist) menu-list model)
3239 (while model-alist
3240 (setq model (car model-alist))
3241 (setq menu-list
3242 (cons
3243 (vector
3244 (nth 0 model)
3245 (vhdl-function-name "vhdl-model" (nth 0 model))
3246 :keys (concat "C-c C-m " (key-description (nth 2 model))))
3247 menu-list))
3248 (setq model-alist (cdr model-alist)))
3249 (setq menu-list (nreverse menu-list))
3250 (vhdl-menu-split menu-list "Model"))
3251 '("--" "--"
3252 ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
3253 ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
3254 ("Port"
5eabfe72 3255 ["Copy" vhdl-port-copy t]
d2ddb974 3256 "--"
5eabfe72
KH
3257 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
3258 ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
3259 ["Paste As Instance" vhdl-port-paste-instance
3260 :keys "C-c C-p C-i" :active vhdl-port-list]
3261 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
3262 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
3263 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
3dcb36b7 3264 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
d2ddb974 3265 "--"
3dcb36b7
JB
3266 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
3267 "--"
3268 ["Flatten" vhdl-port-flatten
3269 :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
3270 ["Reverse Direction" vhdl-port-reverse-direction
3271 :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
3272 ("Compose"
3273 ["New Component" vhdl-compose-new-component t]
3274 ["Place Component" vhdl-compose-place-component vhdl-port-list]
3275 ["Wire Components" vhdl-compose-wire-components t]
3276 "--"
3277 ["Generate Components Package" vhdl-compose-components-package t])
3278 ("Subprogram"
3279 ["Copy" vhdl-subprog-copy t]
3280 "--"
3281 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
3282 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
3283 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
3284 "--"
3285 ["Flatten" vhdl-subprog-flatten
3286 :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
3287 "--"
3288 ("Comment"
5eabfe72
KH
3289 ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
3290 "--"
3291 ["Insert Inline Comment" vhdl-comment-append-inline t]
3292 ["Insert Horizontal Line" vhdl-comment-display-line t]
3293 ["Insert Display Comment" vhdl-comment-display t]
3294 "--"
3295 ["Fill Comment" fill-paragraph t]
3296 ["Fill Comment Region" fill-region (mark)]
3297 ["Kill Comment Region" vhdl-comment-kill-region (mark)]
3dcb36b7
JB
3298 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
3299 ("Line"
5eabfe72
KH
3300 ["Kill" vhdl-line-kill t]
3301 ["Copy" vhdl-line-copy t]
3302 ["Yank" vhdl-line-yank t]
3303 ["Expand" vhdl-line-expand t]
3304 "--"
3305 ["Transpose Next" vhdl-line-transpose-next t]
3306 ["Transpose Prev" vhdl-line-transpose-previous t]
3307 ["Open" vhdl-line-open t]
3dcb36b7 3308 ["Join" vhdl-delete-indentation t]
5eabfe72
KH
3309 "--"
3310 ["Goto" goto-line t]
3dcb36b7
JB
3311 ["(Un)Comment Out" vhdl-comment-uncomment-line t])
3312 ("Move"
5eabfe72
KH
3313 ["Forward Statement" vhdl-end-of-statement t]
3314 ["Backward Statement" vhdl-beginning-of-statement t]
3315 ["Forward Expression" vhdl-forward-sexp t]
3316 ["Backward Expression" vhdl-backward-sexp t]
3dcb36b7
JB
3317 ["Forward Same Indent" vhdl-forward-same-indent t]
3318 ["Backward Same Indent" vhdl-backward-same-indent t]
5eabfe72
KH
3319 ["Forward Function" vhdl-end-of-defun t]
3320 ["Backward Function" vhdl-beginning-of-defun t]
3dcb36b7
JB
3321 ["Mark Function" vhdl-mark-defun t])
3322 "--"
3323 ("Indent"
3324 ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
3325 ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
5eabfe72 3326 ["Region" vhdl-indent-region (mark)]
3dcb36b7
JB
3327 ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
3328 ("Align"
5eabfe72 3329 ["Group" vhdl-align-group t]
3dcb36b7
JB
3330 ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
3331 ["List" vhdl-align-list t]
3332 ["Declarations" vhdl-align-declarations t]
3333 ["Region" vhdl-align-region (mark)]
3334 ["Buffer" vhdl-align-buffer t]
5eabfe72
KH
3335 "--"
3336 ["Inline Comment Group" vhdl-align-inline-comment-group t]
3337 ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
3dcb36b7
JB
3338 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
3339 ("Fill"
3340 ["List" vhdl-fill-list t]
3341 ["Group" vhdl-fill-group t]
3342 ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
3343 ["Region" vhdl-fill-region (mark)])
3344 ("Beautify"
3345 ["Region" vhdl-beautify-region (mark)]
3346 ["Buffer" vhdl-beautify-buffer t])
3347 ("Fix"
3348 ["Generic/Port Clause" vhdl-fix-clause t]
5eabfe72 3349 "--"
3dcb36b7
JB
3350 ["Case Region" vhdl-fix-case-region (mark)]
3351 ["Case Buffer" vhdl-fix-case-buffer t]
3352 "--"
3353 ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
3354 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
3355 "--"
3356 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
3357 ("Update"
3358 ["Sensitivity List" vhdl-update-sensitivity-list-process t]
3359 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
3360 "--"
3361 ["Fontify Buffer" vhdl-fontify-buffer t]
3362 ["Statistics Buffer" vhdl-statistics-buffer t]
3363 ["Show Messages" vhdl-show-messages t]
3364 ["Syntactic Info" vhdl-show-syntactic-information t]
3365 "--"
3366 ["Speedbar" vhdl-speedbar t]
3367 ["Hide/Show" vhdl-hs-minor-mode t]
3368 "--"
3369 ("Documentation"
5eabfe72 3370 ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
3dcb36b7 3371 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
5eabfe72 3372 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
3dcb36b7
JB
3373 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
3374 ["Version" vhdl-version t]
3375 ["Bug Report..." vhdl-submit-bug-report t]
3376 "--"
3377 ("Options"
3378 ("Mode"
3379 ["Electric Mode"
3380 (progn (customize-set-variable 'vhdl-electric-mode
3381 (not vhdl-electric-mode))
3382 (vhdl-mode-line-update))
3383 :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
3384 ["Stutter Mode"
3385 (progn (customize-set-variable 'vhdl-stutter-mode
3386 (not vhdl-stutter-mode))
3387 (vhdl-mode-line-update))
3388 :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
3389 ["Indent Tabs Mode"
3390 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3391 (not vhdl-indent-tabs-mode))
3392 (setq indent-tabs-mode vhdl-indent-tabs-mode))
3393 :style toggle :selected vhdl-indent-tabs-mode]
3394 "--"
3395 ["Customize Group..." (customize-group 'vhdl-mode) t])
3396 ("Project"
3397 ["Project Setup..." (customize-option 'vhdl-project-alist) t]
3398 ,(append
3399 '("Selected Project at Startup"
3400 ["None" (progn (customize-set-variable 'vhdl-project nil)
3401 (vhdl-set-project ""))
3402 :style radio :selected (null vhdl-project)]
3403 "--")
3404 ;; add menu entries for defined projects
3405 (let ((project-alist vhdl-project-alist) menu-list name)
3406 (while project-alist
3407 (setq name (caar project-alist))
3408 (setq menu-list
3409 (cons `[,name (progn (customize-set-variable
3410 'vhdl-project ,name)
3411 (vhdl-set-project ,name))
3412 :style radio :selected (equal ,name vhdl-project)]
3413 menu-list))
3414 (setq project-alist (cdr project-alist)))
3415 (setq menu-list (nreverse menu-list))
3416 (vhdl-menu-split menu-list "Project")))
3417 ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
3418 ("Auto Load Setup File"
3419 ["At Startup"
3420 (customize-set-variable 'vhdl-project-auto-load
3421 (if (memq 'startup vhdl-project-auto-load)
3422 (delq 'startup vhdl-project-auto-load)
3423 (cons 'startup vhdl-project-auto-load)))
3424 :style toggle :selected (memq 'startup vhdl-project-auto-load)])
3425 ["Sort Projects"
3426 (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
3427 :style toggle :selected vhdl-project-sort]
3428 "--"
3429 ["Customize Group..." (customize-group 'vhdl-project) t])
3430 ("Compiler"
3431 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
3432 ,(append
3433 '("Selected Compiler at Startup")
3434 ;; add menu entries for defined compilers
3435 (let ((comp-alist vhdl-compiler-alist) menu-list name)
3436 (while comp-alist
3437 (setq name (caar comp-alist))
3438 (setq menu-list
3439 (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
3440 :style radio :selected (equal ,name vhdl-compiler)]
3441 menu-list))
3442 (setq comp-alist (cdr comp-alist)))
3443 (setq menu-list (nreverse menu-list))
3444 (vhdl-menu-split menu-list "Compler")))
3445 ["Use Local Error Regexp"
3446 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3447 (not vhdl-compile-use-local-error-regexp))
3448 :style toggle :selected vhdl-compile-use-local-error-regexp]
3449 ["Makefile Generation Hook..."
3450 (customize-option 'vhdl-makefile-generation-hook) t]
3451 ["Default Library Name" (customize-option 'vhdl-default-library) t]
3452 "--"
3453 ["Customize Group..." (customize-group 'vhdl-compiler) t])
3454 ("Style"
3455 ("VHDL Standard"
3456 ["VHDL'87"
3457 (progn (customize-set-variable 'vhdl-standard
3458 (list '87 (cadr vhdl-standard)))
3459 (vhdl-activate-customizations))
3460 :style radio :selected (eq '87 (car vhdl-standard))]
3461 ["VHDL'93"
3462 (progn (customize-set-variable 'vhdl-standard
3463 (list '93 (cadr vhdl-standard)))
3464 (vhdl-activate-customizations))
3465 :style radio :selected (eq '93 (car vhdl-standard))]
3466 "--"
3467 ["VHDL-AMS"
3468 (progn (customize-set-variable
3469 'vhdl-standard (list (car vhdl-standard)
3470 (if (memq 'ams (cadr vhdl-standard))
3471 (delq 'ams (cadr vhdl-standard))
3472 (cons 'ams (cadr vhdl-standard)))))
3473 (vhdl-activate-customizations))
3474 :style toggle :selected (memq 'ams (cadr vhdl-standard))]
3475 ["Math Packages"
3476 (progn (customize-set-variable
3477 'vhdl-standard (list (car vhdl-standard)
3478 (if (memq 'math (cadr vhdl-standard))
3479 (delq 'math (cadr vhdl-standard))
3480 (cons 'math (cadr vhdl-standard)))))
3481 (vhdl-activate-customizations))
3482 :style toggle :selected (memq 'math (cadr vhdl-standard))])
3483 ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
3484 ["Upper Case Keywords"
3485 (customize-set-variable 'vhdl-upper-case-keywords
3486 (not vhdl-upper-case-keywords))
3487 :style toggle :selected vhdl-upper-case-keywords]
3488 ["Upper Case Types"
3489 (customize-set-variable 'vhdl-upper-case-types
3490 (not vhdl-upper-case-types))
3491 :style toggle :selected vhdl-upper-case-types]
3492 ["Upper Case Attributes"
3493 (customize-set-variable 'vhdl-upper-case-attributes
3494 (not vhdl-upper-case-attributes))
3495 :style toggle :selected vhdl-upper-case-attributes]
3496 ["Upper Case Enumeration Values"
3497 (customize-set-variable 'vhdl-upper-case-enum-values
3498 (not vhdl-upper-case-enum-values))
3499 :style toggle :selected vhdl-upper-case-enum-values]
3500 ["Upper Case Constants"
3501 (customize-set-variable 'vhdl-upper-case-constants
3502 (not vhdl-upper-case-constants))
3503 :style toggle :selected vhdl-upper-case-constants]
3504 ("Use Direct Instantiation"
3505 ["Never"
3506 (customize-set-variable 'vhdl-use-direct-instantiation 'never)
3507 :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
3508 ["Standard"
3509 (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
3510 :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
3511 ["Always"
3512 (customize-set-variable 'vhdl-use-direct-instantiation 'always)
3513 :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
3514 "--"
3515 ["Customize Group..." (customize-group 'vhdl-style) t])
3516 ("Naming"
3517 ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
3518 ["Architecture File Name..."
3519 (customize-option 'vhdl-architecture-file-name) t]
3520 ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
3521 ("File Name Case"
3522 ["As Is"
3523 (customize-set-variable 'vhdl-file-name-case 'identity)
3524 :style radio :selected (eq 'identity vhdl-file-name-case)]
3525 ["Lower Case"
3526 (customize-set-variable 'vhdl-file-name-case 'downcase)
3527 :style radio :selected (eq 'downcase vhdl-file-name-case)]
3528 ["Upper Case"
3529 (customize-set-variable 'vhdl-file-name-case 'upcase)
3530 :style radio :selected (eq 'upcase vhdl-file-name-case)]
3531 ["Capitalize"
3532 (customize-set-variable 'vhdl-file-name-case 'capitalize)
3533 :style radio :selected (eq 'capitalize vhdl-file-name-case)])
3534 "--"
3535 ["Customize Group..." (customize-group 'vhdl-naming) t])
3536 ("Template"
3537 ("Electric Keywords"
3538 ["VHDL Keywords"
3539 (customize-set-variable 'vhdl-electric-keywords
3540 (if (memq 'vhdl vhdl-electric-keywords)
3541 (delq 'vhdl vhdl-electric-keywords)
3542 (cons 'vhdl vhdl-electric-keywords)))
3543 :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
3544 ["User Model Keywords"
3545 (customize-set-variable 'vhdl-electric-keywords
3546 (if (memq 'user vhdl-electric-keywords)
3547 (delq 'user vhdl-electric-keywords)
3548 (cons 'user vhdl-electric-keywords)))
3549 :style toggle :selected (memq 'user vhdl-electric-keywords)])
3550 ("Insert Optional Labels"
3551 ["None"
3552 (customize-set-variable 'vhdl-optional-labels 'none)
3553 :style radio :selected (eq 'none vhdl-optional-labels)]
3554 ["Processes Only"
3555 (customize-set-variable 'vhdl-optional-labels 'process)
3556 :style radio :selected (eq 'process vhdl-optional-labels)]
3557 ["All Constructs"
3558 (customize-set-variable 'vhdl-optional-labels 'all)
3559 :style radio :selected (eq 'all vhdl-optional-labels)])
3560 ("Insert Empty Lines"
3561 ["None"
3562 (customize-set-variable 'vhdl-insert-empty-lines 'none)
3563 :style radio :selected (eq 'none vhdl-insert-empty-lines)]
3564 ["Design Units Only"
3565 (customize-set-variable 'vhdl-insert-empty-lines 'unit)
3566 :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
3567 ["All Constructs"
3568 (customize-set-variable 'vhdl-insert-empty-lines 'all)
3569 :style radio :selected (eq 'all vhdl-insert-empty-lines)])
3570 ["Argument List Indent"
3571 (customize-set-variable 'vhdl-argument-list-indent
3572 (not vhdl-argument-list-indent))
3573 :style toggle :selected vhdl-argument-list-indent]
3574 ["Association List with Formals"
3575 (customize-set-variable 'vhdl-association-list-with-formals
3576 (not vhdl-association-list-with-formals))
3577 :style toggle :selected vhdl-association-list-with-formals]
3578 ["Conditions in Parenthesis"
3579 (customize-set-variable 'vhdl-conditions-in-parenthesis
3580 (not vhdl-conditions-in-parenthesis))
3581 :style toggle :selected vhdl-conditions-in-parenthesis]
3582 ["Zero String..." (customize-option 'vhdl-zero-string) t]
3583 ["One String..." (customize-option 'vhdl-one-string) t]
3584 ("File Header"
3585 ["Header String..." (customize-option 'vhdl-file-header) t]
3586 ["Footer String..." (customize-option 'vhdl-file-footer) t]
3587 ["Company Name..." (customize-option 'vhdl-company-name) t]
3588 ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
3589 ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
3590 ["Date Format..." (customize-option 'vhdl-date-format) t]
3591 ["Modify Date Prefix String..."
3592 (customize-option 'vhdl-modify-date-prefix-string) t]
3593 ["Modify Date on Saving"
3594 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3595 (not vhdl-modify-date-on-saving))
3596 (vhdl-activate-customizations))
3597 :style toggle :selected vhdl-modify-date-on-saving])
3598 ("Sequential Process"
3599 ("Kind of Reset"
3600 ["None"
3601 (customize-set-variable 'vhdl-reset-kind 'none)
3602 :style radio :selected (eq 'none vhdl-reset-kind)]
3603 ["Synchronous"
3604 (customize-set-variable 'vhdl-reset-kind 'sync)
3605 :style radio :selected (eq 'sync vhdl-reset-kind)]
3606 ["Asynchronous"
3607 (customize-set-variable 'vhdl-reset-kind 'async)
3608 :style radio :selected (eq 'async vhdl-reset-kind)])
3609 ["Reset is Active High"
3610 (customize-set-variable 'vhdl-reset-active-high
3611 (not vhdl-reset-active-high))
3612 :style toggle :selected vhdl-reset-active-high]
3613 ["Use Rising Clock Edge"
3614 (customize-set-variable 'vhdl-clock-rising-edge
3615 (not vhdl-clock-rising-edge))
3616 :style toggle :selected vhdl-clock-rising-edge]
3617 ("Clock Edge Condition"
3618 ["Standard"
3619 (customize-set-variable 'vhdl-clock-edge-condition 'standard)
3620 :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
3621 ["Function \"rising_edge\""
3622 (customize-set-variable 'vhdl-clock-edge-condition 'function)
3623 :style radio :selected (eq 'function vhdl-clock-edge-condition)])
3624 ["Clock Name..." (customize-option 'vhdl-clock-name) t]
3625 ["Reset Name..." (customize-option 'vhdl-reset-name) t])
3626 "--"
3627 ["Customize Group..." (customize-group 'vhdl-template) t])
3628 ("Model"
3629 ["Model Definition..." (customize-option 'vhdl-model-alist) t])
3630 ("Port"
3631 ["Include Port Comments"
3632 (customize-set-variable 'vhdl-include-port-comments
3633 (not vhdl-include-port-comments))
3634 :style toggle :selected vhdl-include-port-comments]
3635 ["Include Direction Comments"
3636 (customize-set-variable 'vhdl-include-direction-comments
3637 (not vhdl-include-direction-comments))
3638 :style toggle :selected vhdl-include-direction-comments]
3639 ["Include Type Comments"
3640 (customize-set-variable 'vhdl-include-type-comments
3641 (not vhdl-include-type-comments))
3642 :style toggle :selected vhdl-include-type-comments]
3643 ("Include Group Comments"
3644 ["Never"
3645 (customize-set-variable 'vhdl-include-group-comments 'never)
3646 :style radio :selected (eq 'never vhdl-include-group-comments)]
3647 ["Declarations"
3648 (customize-set-variable 'vhdl-include-group-comments 'decl)
3649 :style radio :selected (eq 'decl vhdl-include-group-comments)]
3650 ["Always"
3651 (customize-set-variable 'vhdl-include-group-comments 'always)
3652 :style radio :selected (eq 'always vhdl-include-group-comments)])
3653 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
3654 ["Instance Name..." (customize-option 'vhdl-instance-name) t]
3655 ("Testbench"
3656 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
3657 ["Architecture Name..."
3658 (customize-option 'vhdl-testbench-architecture-name) t]
3659 ["Configuration Name..."
3660 (customize-option 'vhdl-testbench-configuration-name) t]
3661 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
3662 ["Include Header"
3663 (customize-set-variable 'vhdl-testbench-include-header
3664 (not vhdl-testbench-include-header))
3665 :style toggle :selected vhdl-testbench-include-header]
3666 ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
3667 ["Statements..." (customize-option 'vhdl-testbench-statements) t]
3668 ["Initialize Signals"
3669 (customize-set-variable 'vhdl-testbench-initialize-signals
3670 (not vhdl-testbench-initialize-signals))
3671 :style toggle :selected vhdl-testbench-initialize-signals]
3672 ["Include Library Clause"
3673 (customize-set-variable 'vhdl-testbench-include-library
3674 (not vhdl-testbench-include-library))
3675 :style toggle :selected vhdl-testbench-include-library]
3676 ["Include Configuration"
3677 (customize-set-variable 'vhdl-testbench-include-configuration
3678 (not vhdl-testbench-include-configuration))
3679 :style toggle :selected vhdl-testbench-include-configuration]
3680 ("Create Files"
3681 ["None"
3682 (customize-set-variable 'vhdl-testbench-create-files 'none)
3683 :style radio :selected (eq 'none vhdl-testbench-create-files)]
3684 ["Single"
3685 (customize-set-variable 'vhdl-testbench-create-files 'single)
3686 :style radio :selected (eq 'single vhdl-testbench-create-files)]
3687 ["Separate"
3688 (customize-set-variable 'vhdl-testbench-create-files 'separate)
3689 :style radio :selected (eq 'separate vhdl-testbench-create-files)]))
3690 "--"
3691 ["Customize Group..." (customize-group 'vhdl-port) t])
3692 ("Compose"
3693 ("Create Files"
3694 ["None"
3695 (customize-set-variable 'vhdl-compose-create-files 'none)
3696 :style radio :selected (eq 'none vhdl-compose-create-files)]
3697 ["Single"
3698 (customize-set-variable 'vhdl-compose-create-files 'single)
3699 :style radio :selected (eq 'single vhdl-compose-create-files)]
3700 ["Separate"
3701 (customize-set-variable 'vhdl-compose-create-files 'separate)
3702 :style radio :selected (eq 'separate vhdl-compose-create-files)])
3703 ["Include Header"
3704 (customize-set-variable 'vhdl-compose-include-header
3705 (not vhdl-compose-include-header))
3706 :style toggle :selected vhdl-compose-include-header]
3707 ["Architecture Name..."
3708 (customize-option 'vhdl-compose-architecture-name) t]
3709 ["Components Package Name..."
3710 (customize-option 'vhdl-components-package-name) t]
3711 ["Use Components Package"
3712 (customize-set-variable 'vhdl-use-components-package
3713 (not vhdl-use-components-package))
3714 :style toggle :selected vhdl-use-components-package]
3715 "--"
3716 ["Customize Group..." (customize-group 'vhdl-compose) t])
3717 ("Comment"
3718 ["Self Insert Comments"
3719 (customize-set-variable 'vhdl-self-insert-comments
3720 (not vhdl-self-insert-comments))
3721 :style toggle :selected vhdl-self-insert-comments]
3722 ["Prompt for Comments"
3723 (customize-set-variable 'vhdl-prompt-for-comments
3724 (not vhdl-prompt-for-comments))
3725 :style toggle :selected vhdl-prompt-for-comments]
3726 ["Inline Comment Column..."
3727 (customize-option 'vhdl-inline-comment-column) t]
3728 ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
3729 "--"
3730 ["Customize Group..." (customize-group 'vhdl-comment) t])
3731 ("Align"
3732 ["Auto Align Templates"
3733 (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
3734 :style toggle :selected vhdl-auto-align]
3735 ["Align Line Groups"
3736 (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
3737 :style toggle :selected vhdl-align-groups]
3738 ["Group Separation String..."
3739 (customize-set-variable 'vhdl-align-group-separate) t]
3740 ["Align Lines with Same Indent"
3741 (customize-set-variable 'vhdl-align-same-indent
3742 (not vhdl-align-same-indent))
3743 :style toggle :selected vhdl-align-same-indent]
3744 "--"
3745 ["Customize Group..." (customize-group 'vhdl-align) t])
3746 ("Highlight"
3747 ["Highlighting On/Off..."
3748 (customize-option
3749 (if vhdl-xemacs 'font-lock-auto-fontify 'global-font-lock-mode)) t]
3750 ["Highlight Keywords"
3751 (progn (customize-set-variable 'vhdl-highlight-keywords
3752 (not vhdl-highlight-keywords))
3753 (vhdl-fontify-buffer))
3754 :style toggle :selected vhdl-highlight-keywords]
3755 ["Highlight Names"
3756 (progn (customize-set-variable 'vhdl-highlight-names
3757 (not vhdl-highlight-names))
3758 (vhdl-fontify-buffer))
3759 :style toggle :selected vhdl-highlight-names]
3760 ["Highlight Special Words"
3761 (progn (customize-set-variable 'vhdl-highlight-special-words
3762 (not vhdl-highlight-special-words))
3763 (vhdl-fontify-buffer))
3764 :style toggle :selected vhdl-highlight-special-words]
3765 ["Highlight Forbidden Words"
3766 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
3767 (not vhdl-highlight-forbidden-words))
3768 (vhdl-fontify-buffer))
3769 :style toggle :selected vhdl-highlight-forbidden-words]
3770 ["Highlight Verilog Keywords"
3771 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
3772 (not vhdl-highlight-verilog-keywords))
3773 (vhdl-fontify-buffer))
3774 :style toggle :selected vhdl-highlight-verilog-keywords]
3775 ["Highlight \"translate_off\""
3776 (progn (customize-set-variable 'vhdl-highlight-translate-off
3777 (not vhdl-highlight-translate-off))
3778 (vhdl-fontify-buffer))
3779 :style toggle :selected vhdl-highlight-translate-off]
3780 ["Case Sensitive Highlighting"
3781 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
3782 (not vhdl-highlight-case-sensitive))
3783 (vhdl-fontify-buffer))
3784 :style toggle :selected vhdl-highlight-case-sensitive]
3785 ["Special Syntax Definition..."
3786 (customize-option 'vhdl-special-syntax-alist) t]
3787 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
3788 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
3789 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
3790 ["Colors..." (customize-group 'vhdl-highlight-faces) t]
3791 "--"
3792 ["Customize Group..." (customize-group 'vhdl-highlight) t])
3793 ("Speedbar"
3794 ["Auto Open at Startup"
3795 (customize-set-variable 'vhdl-speedbar-auto-open
3796 (not vhdl-speedbar-auto-open))
3797 :style toggle :selected vhdl-speedbar-auto-open]
3798 ("Default Displaying Mode"
3799 ["Files"
3800 (customize-set-variable 'vhdl-speedbar-display-mode 'files)
3801 :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
3802 ["Directory Hierarchy"
3803 (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
3804 :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
3805 ["Project Hierarchy"
3806 (customize-set-variable 'vhdl-speedbar-display-mode 'project)
3807 :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
3808 ["Indentation Offset..."
3809 (customize-option 'speedbar-indentation-width) t]
3810 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
3811 ["Jump to Unit when Opening"
3812 (customize-set-variable 'vhdl-speedbar-jump-to-unit
3813 (not vhdl-speedbar-jump-to-unit))
3814 :style toggle :selected vhdl-speedbar-jump-to-unit]
3815 ["Update Hierarchy on File Saving"
3816 (customize-set-variable 'vhdl-speedbar-update-on-saving
3817 (not vhdl-speedbar-update-on-saving))
3818 :style toggle :selected vhdl-speedbar-update-on-saving]
3819 ("Save in Cache File"
3820 ["Hierarchy Information"
3821 (customize-set-variable 'vhdl-speedbar-save-cache
3822 (if (memq 'hierarchy vhdl-speedbar-save-cache)
3823 (delq 'hierarchy vhdl-speedbar-save-cache)
3824 (cons 'hierarchy vhdl-speedbar-save-cache)))
3825 :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
3826 ["Displaying Status"
3827 (customize-set-variable 'vhdl-speedbar-save-cache
3828 (if (memq 'display vhdl-speedbar-save-cache)
3829 (delq 'display vhdl-speedbar-save-cache)
3830 (cons 'display vhdl-speedbar-save-cache)))
3831 :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
3832 ["Cache File Name..."
3833 (customize-option 'vhdl-speedbar-cache-file-name) t]
3834 "--"
3835 ["Customize Group..." (customize-group 'vhdl-speedbar) t])
3836 ("Menu"
3837 ["Add Index Menu when Loading File"
3838 (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
3839 (vhdl-index-menu-init))
3840 :style toggle :selected vhdl-index-menu]
3841 ["Add Source File Menu when Loading File"
3842 (progn (customize-set-variable 'vhdl-source-file-menu
3843 (not vhdl-source-file-menu))
3844 (vhdl-add-source-files-menu))
3845 :style toggle :selected vhdl-source-file-menu]
3846 ["Add Hideshow Menu at Startup"
3847 (progn (customize-set-variable 'vhdl-hideshow-menu
3848 (not vhdl-hideshow-menu))
3849 (vhdl-activate-customizations))
3850 :style toggle :selected vhdl-hideshow-menu]
3851 ["Hide Everything Initially"
3852 (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
3853 :style toggle :selected vhdl-hide-all-init]
3854 "--"
3855 ["Customize Group..." (customize-group 'vhdl-menu) t])
3856 ("Print"
3857 ["In Two Column Format"
3858 (progn (customize-set-variable 'vhdl-print-two-column
3859 (not vhdl-print-two-column))
3860 (message "Activate new setting by saving options and restarting Emacs"))
3861 :style toggle :selected vhdl-print-two-column]
3862 ["Use Customized Faces"
3863 (progn (customize-set-variable 'vhdl-print-customize-faces
3864 (not vhdl-print-customize-faces))
3865 (message "Activate new setting by saving options and restarting Emacs"))
3866 :style toggle :selected vhdl-print-customize-faces]
3867 "--"
3868 ["Customize Group..." (customize-group 'vhdl-print) t])
3869 ("Miscellaneous"
3870 ["Use Intelligent Tab"
3871 (progn (customize-set-variable 'vhdl-intelligent-tab
3872 (not vhdl-intelligent-tab))
3873 (vhdl-activate-customizations))
3874 :style toggle :selected vhdl-intelligent-tab]
3875 ["Indent Syntax-Based"
3876 (customize-set-variable 'vhdl-indent-syntax-based
3877 (not vhdl-indent-syntax-based))
3878 :style toggle :selected vhdl-indent-syntax-based]
3879 ["Word Completion is Case Sensitive"
3880 (customize-set-variable 'vhdl-word-completion-case-sensitive
3881 (not vhdl-word-completion-case-sensitive))
3882 :style toggle :selected vhdl-word-completion-case-sensitive]
3883 ["Word Completion in Minibuffer"
3884 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
3885 (not vhdl-word-completion-in-minibuffer))
3886 (message "Activate new setting by saving options and restarting Emacs"))
3887 :style toggle :selected vhdl-word-completion-in-minibuffer]
3888 ["Underscore is Part of Word"
3889 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
3890 (not vhdl-underscore-is-part-of-word))
3891 (vhdl-activate-customizations))
3892 :style toggle :selected vhdl-underscore-is-part-of-word]
3893 "--"
3894 ["Customize Group..." (customize-group 'vhdl-misc) t])
3895 ["Related..." (customize-browse 'vhdl-related) t]
d2ddb974 3896 "--"
3dcb36b7
JB
3897 ["Save Options" customize-save-customized t]
3898 ["Activate Options" vhdl-activate-customizations t]
3899 ["Browse Options..." vhdl-customize t])))
5eabfe72
KH
3900
3901(defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
3902 "VHDL Mode menu.")
3903
3904(defun vhdl-update-mode-menu ()
3dcb36b7 3905 "Update VHDL Mode menu."
5eabfe72
KH
3906 (interactive)
3907 (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
3908 (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
3909 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
3910 (easy-menu-define vhdl-mode-menu vhdl-mode-map
3911 "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
d2ddb974 3912
5eabfe72
KH
3913;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3914;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
d2ddb974 3915
3dcb36b7 3916(defconst vhdl-imenu-generic-expression
d2ddb974 3917 '(
5eabfe72
KH
3918 ("Subprogram"
3919 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
3920 4)
3921 ("Instance"
3922 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
3923 1)
3924 ("Component"
3925 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 3926 2)
5eabfe72
KH
3927 ("Procedural"
3928 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
3929 1)
3930 ("Process"
3931 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
3932 1)
3933 ("Block"
3934 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
3935 1)
3936 ("Package"
3937 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
3938 3)
d2ddb974
KH
3939 ("Configuration"
3940 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
3941 2)
5eabfe72
KH
3942 ("Architecture"
3943 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
d2ddb974 3944 2)
5eabfe72
KH
3945 ("Entity"
3946 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
d2ddb974 3947 2)
d2ddb974
KH
3948 )
3949 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
3950
5eabfe72
KH
3951(defun vhdl-index-menu-init ()
3952 "Initialize index menu."
3953 (set (make-local-variable 'imenu-case-fold-search) t)
3954 (set (make-local-variable 'imenu-generic-expression)
3955 vhdl-imenu-generic-expression)
3dcb36b7 3956 (when (and vhdl-index-menu (fboundp 'imenu))
5eabfe72
KH
3957 (if (or (not (boundp 'font-lock-maximum-size))
3958 (> font-lock-maximum-size (buffer-size)))
3959 (imenu-add-to-menubar "Index")
3960 (message "Scanning buffer for index...buffer too big"))))
d2ddb974 3961
3dcb36b7 3962;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
3963;; Source file menu (using `easy-menu.el')
3964
5eabfe72
KH
3965(defvar vhdl-sources-menu nil)
3966
3967(defun vhdl-directory-files (directory &optional full match)
3968 "Call `directory-files' if DIRECTORY exists, otherwise generate error
3969message."
3dcb36b7
JB
3970 (if (not (file-directory-p directory))
3971 (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
3972 (let ((dir (directory-files directory full match)))
3973 (setq dir (delete "." dir))
3974 (setq dir (delete ".." dir))
3975 dir)))
5eabfe72
KH
3976
3977(defun vhdl-get-source-files (&optional full directory)
3978 "Get list of VHDL source files in DIRECTORY or current directory."
3979 (let ((mode-alist auto-mode-alist)
3980 filename-regexp)
3981 ;; create regular expressions for matching file names
3dcb36b7 3982 (setq filename-regexp "\\`[^.].*\\(")
5eabfe72 3983 (while mode-alist
3dcb36b7 3984 (when (eq (cdar mode-alist) 'vhdl-mode)
5eabfe72 3985 (setq filename-regexp
3dcb36b7 3986 (concat filename-regexp (caar mode-alist) "\\|")))
5eabfe72
KH
3987 (setq mode-alist (cdr mode-alist)))
3988 (setq filename-regexp
3989 (concat (substring filename-regexp 0
3990 (string-match "\\\\|$" filename-regexp)) "\\)"))
3991 ;; find files
3dcb36b7
JB
3992 (vhdl-directory-files
3993 (or directory default-directory) full filename-regexp)))
d2ddb974
KH
3994
3995(defun vhdl-add-source-files-menu ()
5eabfe72
KH
3996 "Scan directory for all VHDL source files and generate menu.
3997The directory of the current source file is scanned."
d2ddb974
KH
3998 (interactive)
3999 (message "Scanning directory for source files ...")
5eabfe72 4000 (let ((newmap (current-local-map))
5eabfe72
KH
4001 (file-list (vhdl-get-source-files))
4002 menu-list found)
4003 ;; Create list for menu
4004 (setq found nil)
4005 (while file-list
4006 (setq found t)
4007 (setq menu-list (cons (vector (car file-list)
4008 (list 'find-file (car file-list)) t)
4009 menu-list))
4010 (setq file-list (cdr file-list)))
3dcb36b7 4011 (setq menu-list (vhdl-menu-split menu-list "Sources"))
5eabfe72
KH
4012 (when found (setq menu-list (cons "--" menu-list)))
4013 (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
4014 (setq menu-list (cons "Sources" menu-list))
d2ddb974 4015 ;; Create menu
5eabfe72
KH
4016 (easy-menu-add menu-list)
4017 (easy-menu-define vhdl-sources-menu newmap
4018 "VHDL source files menu" menu-list))
d2ddb974
KH
4019 (message ""))
4020
d2ddb974 4021
5eabfe72 4022;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4023;;; Mode definition
5eabfe72
KH
4024;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4025;; performs all buffer local initializations
4026
1c36bac6 4027;;;###autoload
d2ddb974
KH
4028(defun vhdl-mode ()
4029 "Major mode for editing VHDL code.
4030
4031Usage:
4032------
4033
3dcb36b7
JB
4034 TEMPLATE INSERTION (electrification):
4035 After typing a VHDL keyword and entering `SPC', you are prompted for
4036 arguments while a template is generated for that VHDL construct. Typing
4037 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4038 template generation. Optional arguments are indicated by square
4039 brackets and removed if the queried string is left empty. Prompts for
4040 mandatory arguments remain in the code if the queried string is left
4041 empty. They can be queried again by `C-c C-t C-q'. Enabled
4042 electrification is indicated by `/e' in the modeline.
4043
4044 Typing `M-SPC' after a keyword inserts a space without calling the
4045 template generator. Automatic template generation (i.e.
4046 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4047 setting option `vhdl-electric-mode' (see OPTIONS).
4048
4049 Template generators can be invoked from the VHDL menu, by key
4050 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4051 the keyword (i.e. first word of menu entry not in parenthesis) and
4052 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4053 conf, comp, cons, func, inst, pack, sig, var.
4054
4055 Template styles can be customized in customization group
4056 `vhdl-template' \(see OPTIONS).
4057
4058
4059 HEADER INSERTION:
4060 A file header can be inserted by `C-c C-t C-h'. A file footer
4061 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4062 See customization group `vhdl-header'.
4063
4064
4065 STUTTERING:
4066 Double striking of some keys inserts cumbersome VHDL syntax elements.
4067 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4068 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4069 the modeline. The stuttering keys and their effects are:
4070
4071 ;; --> \" : \" [ --> ( -- --> comment
4072 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4073 .. --> \" => \" ] --> ) --- --> horizontal line
4074 ,, --> \" <= \" ]] --> ] ---- --> display comment
4075 == --> \" == \" '' --> \\\"
4076
4077
4078 WORD COMPLETION:
4079 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4080 word in the buffer that starts alike, inserts it and adjusts case.
4081 Re-typing `TAB' toggles through alternative word completions. This also
4082 works in the minibuffer (i.e. in template generator prompts).
4083
4084 Typing `TAB' after `(' looks for and inserts complete parenthesized
4085 expressions (e.g. for array index ranges). All keywords as well as
4086 standard types and subprograms of VHDL have predefined abbreviations
4087 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4088 beginning with \"std\").
4089
4090 Typing `TAB' after a non-word character indents the line if at the
4091 beginning of a line (i.e. no preceding non-blank characters), and
4092 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4093 stop.
4094
4095
4096 COMMENTS:
4097 `--' puts a single comment.
4098 `---' draws a horizontal line for separating code segments.
4099 `----' inserts a display comment, i.e. two horizontal lines
4100 with a comment in between.
4101 `--CR' comments out code on that line. Re-hitting CR comments
4102 out following lines.
4103 `C-c c' comments out a region if not commented out,
4104 uncomments a region if already commented out.
4105
4106 You are prompted for comments after object definitions (i.e. signals,
4107 variables, constants, ports) and after subprogram and process
4108 specifications if option `vhdl-prompt-for-comments' is non-nil.
4109 Comments are automatically inserted as additional labels (e.g. after
4110 begin statements) and as help comments if `vhdl-self-insert-comments' is
4111 non-nil.
4112
4113 Inline comments (i.e. comments after a piece of code on the same line)
4114 are indented at least to `vhdl-inline-comment-column'. Comments go at
4115 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4116 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4117 in a comment automatically opens a new comment line. `M-q' re-fills
4118 multi-line comments.
4119
4120
4121 INDENTATION:
4122 `TAB' indents a line if at the beginning of the line. The amount of
4123 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4124 always indents the current line (is bound to `TAB' if option
4125 `vhdl-intelligent-tab' is nil).
4126
4127 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4128 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4129 indented normally (nil) or relative to the opening parenthesis (non-nil)
4130 according to option `vhdl-argument-list-indent'.
4131
4132 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4133 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4134 and vice versa.
4135
4136 Syntax-based indentation can be very slow in large files. Option
4137 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4138
4139
4140 ALIGNMENT:
4141 The alignment functions align operators, keywords, and inline comments
4142 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4143 separated by blank lines, `C-c C-a C-i' a block of lines with same
4144 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4145 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4146 C-a C-d' all lines within the declarative part of a design unit. `C-c
4147 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4148 for a group of lines, and `C-c C-a M-c' for a region.
4149
4150 If option `vhdl-align-groups' is non-nil, groups of code lines
4151 separated by special lines (see option `vhdl-align-group-separate') are
4152 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4153 blocks of lines with same indent are aligned separately. Some templates
4154 are automatically aligned after generation if option `vhdl-auto-align'
4155 is non-nil.
4156
4157 Alignment tries to align inline comments at
4158 `vhdl-inline-comment-column' and tries inline comment not to exceed
4159 `vhdl-end-comment-column'.
4160
4161 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4162 symbols are surrounded by one space, and multiple spaces are eliminated.
4163
4164
4165| CODE FILLING:
4166| Code filling allows to condens code (e.g. sensitivity lists or port
4167| maps) by removing comments and newlines and re-wrapping so that all
4168| lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4169| enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4170| blank lines, `C-c C-f C-i' a block of lines with same indent, and
4171| `C-c C-f M-f' an entire region.
4172
4173
4174 CODE BEAUTIFICATION:
4175 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4176 buffer respectively. This inludes indentation, alignment, and case
4177 fixing. Code beautification can also be run non-interactively using the
4178 command:
4179
4180 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4181
4182
4183 PORT TRANSLATION:
4184 Generic and port clauses from entity or component declarations can be
4185 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4186 as component instantiations and corresponding internal constants and
4187 signals, as a generic map with constants as actual generics, and as
4188 internal signal initializations (menu).
4189
4190 To include formals in component instantiations, see option
4191 `vhdl-association-list-with-formals'. To include comments in pasting,
4192 see options `vhdl-include-...-comments'.
4193
4194 A clause with several generic/port names on the same line can be
4195 flattened (`C-c C-p C-f') so that only one name per line exists. The
4196| direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4197| outputs and vice versa, which can be useful in testbenches. (This
4198| reversion is done on the internal data structure and is only reflected
4199| in subsequent paste operations.)
4200
4201 Names for actual ports, instances, testbenches, and
4202 design-under-test instances can be derived from existing names according
4203 to options `vhdl-...-name'. See customization group `vhdl-port'.
4204
4205
4206| SUBPROGRAM TRANSLATION:
4207| Similar functionality exists for copying/pasting the interface of
4208| subprograms (function/procedure). A subprogram interface can be copied
4209| and then pasted as a subprogram declaration, body or call (uses
4210| association list with formals).
4211
4212
4213 TESTBENCH GENERATION:
4214 A copied port can also be pasted as a testbench. The generated
4215 testbench includes an entity, an architecture, and an optional
4216 configuration. The architecture contains the component declaration and
4217 instantiation of the DUT as well as internal constant and signal
4218 declarations. Additional user-defined templates can be inserted. The
4219 names used for entity/architecture/configuration/DUT as well as the file
4220 structure to be generated can be customized. See customization group
4221 `vhdl-testbench'.
4222
4223
4224 KEY BINDINGS:
4225 Key bindings (`C-c ...') exist for most commands (see in menu).
4226
4227
4228 VHDL MENU:
4229 All commands can be found in the VHDL menu including their key bindings.
4230
4231
4232 FILE BROWSER:
4233 The speedbar allows browsing of directories and file contents. It can
4234 be accessed from the VHDL menu and is automatically opened if option
4235 `vhdl-speedbar-auto-open' is non-nil.
4236
4237 In speedbar, open files and directories with `mouse-2' on the name and
4238 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4239
4240
4241 DESIGN HIERARCHY BROWSER:
4242 The speedbar can also be used for browsing the hierarchy of design units
4243 contained in the source files of the current directory or the specified
4244 projects (see option `vhdl-project-alist').
4245
4246 The speedbar can be switched between file, directory hierarchy and
4247 project hierarchy browsing mode in the speedbar menu or by typing `f',
4248 `h' or `H' in speedbar.
4249
4250 In speedbar, open design units with `mouse-2' on the name and browse
4251 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4252 from entities and components (in packages). Individual design units and
4253 complete designs can directly be compiled (\"Make\" menu entry).
4254
4255 The hierarchy is automatically updated upon saving a modified source
4256 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4257 hierarchy is only updated for projects that have been opened once in the
4258 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4259 options in group `vhdl-speedbar').
4260
4261 Simple design consistency checks are done during scanning, such as
4262 multiple declarations of the same unit or missing primary units that are
4263 required by secondary units.
4264
4265
4266| STRUCTURAL COMPOSITION:
4267| Enables simple structural composition. `C-c C-c C-n' creates a skeleton
4268| for a new component. Subcomponents (i.e. component declaration and
4269| instantiation) can be automatically placed from a previously read port
4270| \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
4271| all subcomponents can be automatically connected using internal signals
4272| and ports (`C-c C-c C-w') following these rules:
4273| - subcomponent actual ports with same name are considered to be
4274| connected by a signal (internal signal or port)
4275| - signals that are only inputs to subcomponents are considered as
4276| inputs to this component -> input port created
4277| - signals that are only outputs from subcomponents are considered as
4278| outputs from this component -> output port created
4279| - signals that are inputs to AND outputs from subcomponents are
4280| considered as internal connections -> internal signal created
4281|
4282| Component declarations can be placed in a components package (option
4283| `vhdl-use-components-package') which can be automatically generated for
4284| an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
4285| component instantiation is also supported (option
4286| `vhdl-use-direct-instantiation').
4287|
4288| Purpose: With appropriate naming conventions it is possible to
4289| create higher design levels with only a few mouse clicks or key
4290| strokes. A new design level can be created by simply generating a new
4291| component, placing the required subcomponents from the hierarchy
4292| browser, and wiring everything automatically.
4293|
4294| Note: Automatic wiring only works reliably on templates of new
4295| components and component instantiations that were created by VHDL mode.
4296|
4297| See the options group `vhdl-compose' for all relevant user options.
4298
4299
4300 SOURCE FILE COMPILATION:
4301 The syntax of the current buffer can be analyzed by calling a VHDL
4302 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4303 option `vhdl-compiler'. The available compilers are listed in option
4304 `vhdl-compiler-alist' including all required compilation command,
4305 command options, compilation directory, and error message syntax
4306 information. New compilers can be added.
4307
4308 All the source files of an entire design can be compiled by the `make'
4309 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4310
4311
4312 MAKEFILE GENERATION:
4313 Makefiles can be generated automatically by an internal generation
4314 routine (`C-c M-k'). The library unit dependency information is
4315 obtained from the hierarchy browser. Makefile generation can be
4316 customized for each compiler in option `vhdl-compiler-alist'.
4317
4318 Makefile generation can also be run non-interactively using the
4319 command:
4320
4321 emacs -batch -l ~/.emacs -l vhdl-mode
4322 [-compiler compilername] [-project projectname]
4323 -f vhdl-generate-makefile
4324
4325 The Makefile's default target \"all\" compiles the entire design, the
4326 target \"clean\" removes it and the target \"library\" creates the
4327 library directory if not existent. The Makefile also includes a target
4328 for each primary library unit which allows selective compilation of this
4329 unit, its secondary units and its subhierarchy (example: compilation of
4330 a design specified by a configuration). User specific parts can be
4331 inserted into a Makefile with option `vhdl-makefile-generation-hook'.
4332
4333 Limitations:
4334 - Only library units and dependencies within the current library are
4335 considered. Makefiles for designs that span multiple libraries are
4336 not (yet) supported.
4337 - Only one-level configurations are supported (also hierarchical),
4338 but configurations that go down several levels are not.
4339 - The \"others\" keyword in configurations is not supported.
4340
4341
4342 PROJECTS:
4343 Projects can be defined in option `vhdl-project-alist' and a current
4344 project be selected using option `vhdl-project' (permanently) or from
4345 the menu or speedbar (temporarily). For each project, title and
4346 description strings (for the file headers), source files/directories
4347 (for the hierarchy browser and Makefile generation), library name, and
4348 compiler-dependent options, exceptions and compilation directory can be
4349 specified. Compilation settings overwrite the settings of option
4350 `vhdl-compiler-alist'.
4351
4352 Project setups can be exported (i.e. written to a file) and imported.
4353 Imported setups are not automatically saved in `vhdl-project-alist' but
4354 can be saved afterwards in its customization buffer. When starting
4355 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4356 vhdl-mode\") in a directory with an existing project setup file, it is
4357 automatically loaded and its project activated if option
4358 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4359 files can be specified in option `vhdl-project-file-name'. Multiple
4360 project setups can be automatically loaded from global directories.
4361 This is an alternative to specifying project setups with option
4362 `vhdl-project-alist'.
4363
4364
4365 SPECIAL MENUES:
4366 As an alternative to the speedbar, an index menu can be added (set
4367 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4368 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4369 file) for browsing the file contents (is not populated if buffer is
4370 larger than `font-lock-maximum-size'). Also, a source file menu can be
4371 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4372 current directory for VHDL source files.
4373
4374
4375 VHDL STANDARDS:
4376 The VHDL standards to be used are specified in option `vhdl-standard'.
4377 Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
4378
4379
4380 KEYWORD CASE:
4381 Lower and upper case for keywords and standardized types, attributes,
4382 and enumeration values is supported. If the option
4383 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4384 lower case and are converted into upper case automatically (not for
4385 types, attributes, and enumeration values). The case of keywords,
4386 types, attributes,and enumeration values can be fixed for an entire
4387 region (menu) or buffer (`C-c C-x C-c') according to the options
4388 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4389
4390
4391 HIGHLIGHTING (fontification):
4392 Keywords and standardized types, attributes, enumeration values, and
4393 function names (controlled by option `vhdl-highlight-keywords'), as well
4394 as comments, strings, and template prompts are highlighted using
4395 different colors. Unit, subprogram, signal, variable, constant,
4396 parameter and generic/port names in declarations as well as labels are
4397 highlighted if option `vhdl-highlight-names' is non-nil.
4398
4399 Additional reserved words or words with a forbidden syntax (e.g. words
4400 that should be avoided) can be specified in option
4401 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4402 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4403 keywords are highlighted as forbidden words if option
4404 `vhdl-highlight-verilog-keywords' is non-nil.
4405
4406 Words with special syntax can be highlighted by specifying their
4407 syntax and color in option `vhdl-special-syntax-alist' and by setting
4408 option `vhdl-highlight-special-words' to non-nil. This allows to
4409 establish some naming conventions (e.g. to distinguish different kinds
4410 of signals or other objects by using name suffices) and to support them
4411 visually.
4412
4413 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4414 to support case-sensitive highlighting. However, keywords are then only
4415 highlighted if written in lower case.
4416
4417 Code between \"translate_off\" and \"translate_on\" pragmas is
4418 highlighted using a different background color if option
4419 `vhdl-highlight-translate-off' is non-nil.
4420
4421 For documentation and customization of the used colors see
4422 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4423 highlighting of matching parenthesis, see customization group
4424 `paren-showing'. Automatic buffer highlighting is turned on/off by
4425 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4426
4427
4428 USER MODELS:
4429 VHDL models (templates) can be specified by the user and made accessible
4430 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4431 electrification. See option `vhdl-model-alist'.
4432
4433
4434 HIDE/SHOW:
4435 The code of blocks, processes, subprograms, component declarations and
4436 instantiations, generic/port clauses, and configuration declarations can
4437 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4438 the code (see customization group `vhdl-menu'). XEmacs: limited
4439 functionality due to old `hideshow.el' package.
4440
4441
4442 CODE UPDATING:
4443 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4444 current process, `C-c C-u M-s' of all processes in the current buffer.
4445 Limitations:
4446 - Only declared local signals (ports, signals declared in
4447 architecture and blocks) are automatically inserted.
4448 - Global signals declared in packages are not automatically inserted.
4449 Insert them once manually (will be kept afterwards).
4450 - Out parameters of procedures are considered to be read.
4451 Use option `vhdl-entity-file-name' to specify the entity file name
4452 \(used to obtain the port names).
4453
4454
4455 CODE FIXING:
4456 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4457 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4458
4459
4460 PRINTING:
4461 Postscript printing with different faces (an optimized set of faces is
4462 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4463 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4464 postscript printing commands. Option `vhdl-print-two-column' defines
4465 appropriate default settings for nice landscape two-column printing.
4466 The paper format can be set by option `ps-paper-type'. Do not forget to
4467 switch `ps-print-color-p' to nil for printing on black-and-white
4468 printers.
4469
4470
4471 OPTIONS:
4472 User options allow customization of VHDL Mode. All options are
4473 accessible from the \"Options\" menu entry. Simple options (switches
4474 and choices) can directly be changed, while for complex options a
4475 customization buffer is opened. Changed options can be saved for future
4476 sessions using the \"Save Options\" menu entry.
4477
4478 Options and their detailed descriptions can also be accessed by using
4479 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4480 customize-group' for groups). Some customizations only take effect
4481 after some action (read the NOTE in the option documentation).
4482 Customization can also be done globally (i.e. site-wide, read the
4483 INSTALL file).
4484
4485 Not all options are described in this documentation, so go and see
4486 what other useful user options there are (`M-x vhdl-customize' or menu)!
4487
4488
4489 FILE EXTENSIONS:
4490 As default, files with extensions \".vhd\" and \".vhdl\" are
4491 automatically recognized as VHDL source files. To add an extension
4492 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4493
4494 \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
4495
4496
4497 HINTS:
4498 - To start Emacs with open VHDL hierarchy browser without having to load
4499 a VHDL file first, use the command:
4500
4501 emacs -l vhdl-mode -f speedbar-frame-mode
4502
4503 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4504
4505 - Some features only work on properly indented code.
4506
4507
4508 RELEASE NOTES:
4509 See also the release notes (menu) for added features in new releases.
d2ddb974
KH
4510
4511
4512Maintenance:
4513------------
4514
3dcb36b7 4515To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
d2ddb974
KH
4516Add a description of the problem and include a reproducible test case.
4517
3dcb36b7 4518Questions and enhancement requests can be sent to <reto@gnu.org>.
d2ddb974
KH
4519
4520The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
3dcb36b7
JB
4521The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4522releases. You are kindly invited to participate in beta testing. Subscribe
4523to above mailing lists by sending an email to <reto@gnu.org>.
d2ddb974 4524
3dcb36b7
JB
4525VHDL Mode is officially distributed at
4526http://opensource.ethz.ch/emacs/vhdl-mode.html
4527where the latest version can be found.
d2ddb974
KH
4528
4529
3dcb36b7
JB
4530Known problems:
4531---------------
d2ddb974 4532
5eabfe72 4533- Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
3dcb36b7
JB
4534- XEmacs: Incorrect start-up when automatically opening speedbar.
4535- XEmacs: Indentation in XEmacs 21.4 (and higher).
d2ddb974
KH
4536
4537
3dcb36b7
JB
4538 The VHDL Mode Authors
4539 Reto Zimmermann and Rod Whitby
5eabfe72 4540
d2ddb974
KH
4541Key bindings:
4542-------------
4543
4544\\{vhdl-mode-map}"
4545 (interactive)
4546 (kill-all-local-variables)
d2ddb974
KH
4547 (setq major-mode 'vhdl-mode)
4548 (setq mode-name "VHDL")
5eabfe72
KH
4549
4550 ;; set maps and tables
d2ddb974 4551 (use-local-map vhdl-mode-map)
5eabfe72
KH
4552 (set-syntax-table vhdl-mode-syntax-table)
4553 (setq local-abbrev-table vhdl-mode-abbrev-table)
4554
3dcb36b7 4555 ;; set local variables
5eabfe72
KH
4556 (set (make-local-variable 'paragraph-start)
4557 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
d2ddb974
KH
4558 (set (make-local-variable 'paragraph-separate) paragraph-start)
4559 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
cf98062a
RS
4560 (set (make-local-variable 'require-final-newline)
4561 mode-require-final-newline)
d2ddb974
KH
4562 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4563 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4564 (set (make-local-variable 'comment-start) "--")
4565 (set (make-local-variable 'comment-end) "")
3dcb36b7
JB
4566 (when vhdl-emacs-21
4567 (set (make-local-variable 'comment-padding) ""))
5eabfe72 4568 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
d2ddb974
KH
4569 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4570 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
5eabfe72 4571 (set (make-local-variable 'comment-multi-line) nil)
d2ddb974 4572 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
5eabfe72 4573 (set (make-local-variable 'hippie-expand-verbose) nil)
d2ddb974
KH
4574
4575 ;; setup the comment indent variable in a Emacs version portable way
4576 ;; ignore any byte compiler warnings you might get here
5eabfe72
KH
4577 (when (boundp 'comment-indent-function)
4578 (make-local-variable 'comment-indent-function)
4579 (setq comment-indent-function 'vhdl-comment-indent))
d2ddb974
KH
4580
4581 ;; initialize font locking
5eabfe72
KH
4582 (set (make-local-variable 'font-lock-defaults)
4583 (list
3dcb36b7 4584 '(nil vhdl-font-lock-keywords) nil
5eabfe72
KH
4585 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4586 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
3dcb36b7
JB
4587 (unless vhdl-emacs-21
4588 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4589 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4590 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4591; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4592 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4593; (turn-on-font-lock)
d2ddb974
KH
4594
4595 ;; variables for source file compilation
3dcb36b7
JB
4596 (when vhdl-compile-use-local-error-regexp
4597 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4598 (set (make-local-variable 'compilation-file-regexp-alist) nil))
5eabfe72
KH
4599
4600 ;; add index menu
4601 (vhdl-index-menu-init)
4602 ;; add source file menu
d2ddb974 4603 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
5eabfe72
KH
4604 ;; add VHDL menu
4605 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4606 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4607 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4608 ;; initialize hideshow and add menu
5eabfe72 4609 (vhdl-hideshow-init)
d2ddb974
KH
4610 (run-hooks 'menu-bar-update-hook)
4611
5eabfe72
KH
4612 ;; miscellaneous
4613 (vhdl-ps-print-init)
3dcb36b7 4614 (vhdl-write-file-hooks-init)
5eabfe72 4615 (vhdl-mode-line-update)
3dcb36b7
JB
4616 (message "VHDL Mode %s.%s" vhdl-version
4617 (if noninteractive "" " See menu for documentation and release notes."))
5eabfe72
KH
4618
4619 ;; run hooks
4620 (run-hooks 'vhdl-mode-hook))
4621
4622(defun vhdl-activate-customizations ()
4623 "Activate all customizations on local variables."
4624 (interactive)
4625 (vhdl-mode-map-init)
4626 (use-local-map vhdl-mode-map)
4627 (set-syntax-table vhdl-mode-syntax-table)
4628 (setq comment-column vhdl-inline-comment-column)
4629 (setq end-comment-column vhdl-end-comment-column)
3dcb36b7 4630 (vhdl-write-file-hooks-init)
5eabfe72
KH
4631 (vhdl-update-mode-menu)
4632 (vhdl-hideshow-init)
4633 (run-hooks 'menu-bar-update-hook)
4634 (vhdl-mode-line-update))
4635
3dcb36b7
JB
4636(defun vhdl-write-file-hooks-init ()
4637 "Add/remove hooks when buffer is saved."
5eabfe72
KH
4638 (if vhdl-modify-date-on-saving
4639 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
3dcb36b7
JB
4640 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4641 (make-local-variable 'after-save-hook)
4642 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4643
4644(defun vhdl-process-command-line-option (option)
4645 "Process command line options for VHDL Mode."
4646 (cond
4647 ;; set compiler
4648 ((equal option "-compiler")
4649 (vhdl-set-compiler (car command-line-args-left))
4650 (setq command-line-args-left (cdr command-line-args-left)))
4651 ;; set project
4652 ((equal option "-project")
4653 (vhdl-set-project (car command-line-args-left))
4654 (setq command-line-args-left (cdr command-line-args-left)))))
4655
4656;; make Emacs process VHDL Mode options
4657(setq command-switch-alist
4658 (append command-switch-alist
4659 '(("-compiler" . vhdl-process-command-line-option)
4660 ("-project" . vhdl-process-command-line-option))))
5eabfe72
KH
4661
4662
4663;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4664;;; Keywords and standardized words
5eabfe72
KH
4665;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4666
3dcb36b7
JB
4667(defconst vhdl-93-keywords
4668 '(
4669 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4670 "assert" "attribute"
4671 "begin" "block" "body" "buffer" "bus"
4672 "case" "component" "configuration" "constant"
4673 "disconnect" "downto"
4674 "else" "elsif" "end" "entity" "exit"
4675 "file" "for" "function"
4676 "generate" "generic" "group" "guarded"
4677 "if" "impure" "in" "inertial" "inout" "is"
4678 "label" "library" "linkage" "literal" "loop"
4679 "map" "mod"
4680 "nand" "new" "next" "nor" "not" "null"
4681 "of" "on" "open" "or" "others" "out"
4682 "package" "port" "postponed" "procedure" "process" "pure"
4683 "range" "record" "register" "reject" "rem" "report" "return"
4684 "rol" "ror"
4685 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4686 "then" "to" "transport" "type"
4687 "unaffected" "units" "until" "use"
4688 "variable"
4689 "wait" "when" "while" "with"
4690 "xnor" "xor"
4691 )
4692 "List of VHDL'93 keywords.")
d2ddb974 4693
5eabfe72
KH
4694(defconst vhdl-ams-keywords
4695 '(
4696 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4697 "reference" "spectrum" "subnature" "terminal" "through"
4698 "tolerance"
4699 )
4700 "List of VHDL-AMS keywords.")
d2ddb974 4701
5eabfe72
KH
4702(defconst vhdl-verilog-keywords
4703 '(
4704 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4705 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4706 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4707 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4708 "endprimitive" "endspecify" "endtable" "endtask" "event"
4709 "for" "force" "forever" "fork" "function"
4710 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4711 "macromodule" "makefile" "medium" "module"
4712 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4713 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4714 "pullup"
4715 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4716 "rtranif0" "rtranif1"
4717 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4718 "strong1" "supply" "supply0" "supply1"
4719 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4720 "triand" "trior" "trireg"
4721 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4722 )
4723 "List of Verilog keywords as candidate for additional reserved words.")
d2ddb974 4724
5eabfe72
KH
4725(defconst vhdl-93-types
4726 '(
4727 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4728 "real" "time" "natural" "positive" "string" "line" "text" "side"
4729 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4730 "std_logic" "std_logic_vector"
4731 "std_ulogic" "std_ulogic_vector"
4732 )
4733 "List of VHDL'93 standardized types.")
d2ddb974 4734
5eabfe72
KH
4735(defconst vhdl-ams-types
4736 '(
4737 "domain_type" "real_vector"
3dcb36b7
JB
4738 ;; from `nature_pkg' package
4739 "voltage" "current" "electrical" "position" "velocity" "force"
4740 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4741 "pressure" "flowrate" "fluid"
4742 )
5eabfe72 4743 "List of VHDL-AMS standardized types.")
d2ddb974 4744
5eabfe72
KH
4745(defconst vhdl-math-types
4746 '(
4747 "complex" "complex_polar"
4748 )
4749 "List of Math Packages standardized types.")
d2ddb974 4750
5eabfe72
KH
4751(defconst vhdl-93-attributes
4752 '(
4753 "base" "left" "right" "high" "low" "pos" "val" "succ"
4754 "pred" "leftof" "rightof" "range" "reverse_range"
4755 "length" "delayed" "stable" "quiet" "transaction"
4756 "event" "active" "last_event" "last_active" "last_value"
4757 "driving" "driving_value" "ascending" "value" "image"
4758 "simple_name" "instance_name" "path_name"
4759 "foreign"
4760 )
4761 "List of VHDL'93 standardized attributes.")
d2ddb974 4762
5eabfe72
KH
4763(defconst vhdl-ams-attributes
4764 '(
4765 "across" "through"
4766 "reference" "contribution" "tolerance"
4767 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4768 "ramp" "slew"
4769 )
4770 "List of VHDL-AMS standardized attributes.")
d2ddb974 4771
5eabfe72
KH
4772(defconst vhdl-93-enum-values
4773 '(
4774 "true" "false"
4775 "note" "warning" "error" "failure"
4776 "read_mode" "write_mode" "append_mode"
4777 "open_ok" "status_error" "name_error" "mode_error"
4778 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4779 "right" "left"
4780 )
4781 "List of VHDL'93 standardized enumeration values.")
d2ddb974 4782
5eabfe72
KH
4783(defconst vhdl-ams-enum-values
4784 '(
4785 "quiescent_domain" "time_domain" "frequency_domain"
3dcb36b7
JB
4786 ;; from `nature_pkg' package
4787 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5eabfe72
KH
4788 )
4789 "List of VHDL-AMS standardized enumeration values.")
4790
4791(defconst vhdl-math-constants
4792 '(
4793 "math_e" "math_1_over_e"
4794 "math_pi" "math_two_pi" "math_1_over_pi"
4795 "math_half_pi" "math_q_pi" "math_3_half_pi"
4796 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4797 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4798 "math_deg_to_rad" "math_rad_to_deg"
4799 "cbase_1" "cbase_j" "czero"
4800 )
4801 "List of Math Packages standardized constants.")
4802
4803(defconst vhdl-93-functions
4804 '(
4805 "now" "resolved" "rising_edge" "falling_edge"
4806 "read" "readline" "write" "writeline" "endfile"
4807 "resize" "is_X" "std_match"
4808 "shift_left" "shift_right" "rotate_left" "rotate_right"
4809 "to_unsigned" "to_signed" "to_integer"
4810 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4811 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4812 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4813 "shl" "shr" "ext" "sxt"
3dcb36b7 4814 "deallocate"
5eabfe72
KH
4815 )
4816 "List of VHDL'93 standardized functions.")
4817
4818(defconst vhdl-ams-functions
4819 '(
4820 "frequency"
4821 )
4822 "List of VHDL-AMS standardized functions.")
4823
4824(defconst vhdl-math-functions
4825 '(
4826 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4827 "sqrt" "cbrt" "exp" "log"
4828 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4829 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4830 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4831 )
4832 "List of Math Packages standardized functions.")
4833
4834(defconst vhdl-93-packages
4835 '(
4836 "std_logic_1164" "numeric_std" "numeric_bit"
4837 "standard" "textio"
4838 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4839 "std_logic_misc" "std_logic_textio"
4840 "ieee" "std" "work"
4841 )
4842 "List of VHDL'93 standardized packages and libraries.")
4843
3dcb36b7
JB
4844(defconst vhdl-ams-packages
4845 '(
4846 ;; from `nature_pkg' package
4847 "nature_pkg"
4848 )
4849 "List of VHDL-AMS standardized packages and libraries.")
4850
5eabfe72
KH
4851(defconst vhdl-math-packages
4852 '(
4853 "math_real" "math_complex"
4854 )
4855 "List of Math Packages standardized packages and libraries.")
4856
4857(defvar vhdl-keywords nil
4858 "List of VHDL keywords.")
4859
4860(defvar vhdl-types nil
4861 "List of VHDL standardized types.")
4862
4863(defvar vhdl-attributes nil
4864 "List of VHDL standardized attributes.")
4865
4866(defvar vhdl-enum-values nil
4867 "List of VHDL standardized enumeration values.")
4868
4869(defvar vhdl-constants nil
4870 "List of VHDL standardized constants.")
4871
4872(defvar vhdl-functions nil
4873 "List of VHDL standardized functions.")
4874
4875(defvar vhdl-packages nil
4876 "List of VHDL standardized packages and libraries.")
4877
4878(defvar vhdl-reserved-words nil
4879 "List of additional reserved words.")
4880
4881(defvar vhdl-keywords-regexp nil
4882 "Regexp for VHDL keywords.")
4883
4884(defvar vhdl-types-regexp nil
4885 "Regexp for VHDL standardized types.")
4886
4887(defvar vhdl-attributes-regexp nil
4888 "Regexp for VHDL standardized attributes.")
4889
4890(defvar vhdl-enum-values-regexp nil
4891 "Regexp for VHDL standardized enumeration values.")
4892
4893(defvar vhdl-functions-regexp nil
4894 "Regexp for VHDL standardized functions.")
4895
4896(defvar vhdl-packages-regexp nil
4897 "Regexp for VHDL standardized packages and libraries.")
4898
4899(defvar vhdl-reserved-words-regexp nil
4900 "Regexp for additional reserved words.")
4901
3dcb36b7
JB
4902(defvar vhdl-directive-keywords-regexp nil
4903 "Regexp for compiler directive keywords.")
4904
5eabfe72
KH
4905(defun vhdl-words-init ()
4906 "Initialize reserved words."
4907 (setq vhdl-keywords
4908 (append vhdl-93-keywords
4909 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
4910 (setq vhdl-types
4911 (append vhdl-93-types
4912 (when (vhdl-standard-p 'ams) vhdl-ams-types)
4913 (when (vhdl-standard-p 'math) vhdl-math-types)))
4914 (setq vhdl-attributes
4915 (append vhdl-93-attributes
4916 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
4917 (setq vhdl-enum-values
4918 (append vhdl-93-enum-values
4919 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
4920 (setq vhdl-constants
4921 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
4922 (setq vhdl-functions
4923 (append vhdl-93-functions
4924 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
4925 (when (vhdl-standard-p 'math) vhdl-math-functions)))
4926 (setq vhdl-packages
4927 (append vhdl-93-packages
3dcb36b7 4928 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5eabfe72
KH
4929 (when (vhdl-standard-p 'math) vhdl-math-packages)))
4930 (setq vhdl-reserved-words
4931 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
4932 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
4933 '("")))
4934 (setq vhdl-keywords-regexp
4935 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
4936 (setq vhdl-types-regexp
4937 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
4938 (setq vhdl-attributes-regexp
4939 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
4940 (setq vhdl-enum-values-regexp
4941 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
4942 (setq vhdl-functions-regexp
4943 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
4944 (setq vhdl-packages-regexp
4945 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
4946 (setq vhdl-reserved-words-regexp
4947 (concat "\\<\\("
4948 (unless (equal vhdl-forbidden-syntax "")
4949 (concat vhdl-forbidden-syntax "\\|"))
4950 (regexp-opt vhdl-reserved-words)
4951 "\\)\\>"))
3dcb36b7
JB
4952 (setq vhdl-directive-keywords-regexp
4953 (concat "\\<\\(" (mapconcat 'regexp-quote
4954 vhdl-directive-keywords "\\|") "\\)\\>"))
5eabfe72
KH
4955 (vhdl-abbrev-list-init))
4956
4957;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4958;; Words to expand
4959
4960(defvar vhdl-abbrev-list nil
4961 "Predefined abbreviations for VHDL.")
4962
4963(defun vhdl-abbrev-list-init ()
4964 (setq vhdl-abbrev-list
4965 (append
4966 (list vhdl-upper-case-keywords) vhdl-keywords
4967 (list vhdl-upper-case-types) vhdl-types
4968 (list vhdl-upper-case-attributes) vhdl-attributes
4969 (list vhdl-upper-case-enum-values) vhdl-enum-values
4970 (list vhdl-upper-case-constants) vhdl-constants
4971 (list nil) vhdl-functions
4972 (list nil) vhdl-packages)))
4973
4974;; initialize reserved words for VHDL Mode
4975(vhdl-words-init)
4976
4977
4978;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4979;;; Indentation
5eabfe72
KH
4980;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4981
4982;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
4983;; Syntax analysis
4984
4985;; constant regular expressions for looking at various constructs
4986
4987(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
4988 "Regexp describing a VHDL symbol.
4989We cannot use just `word' syntax class since `_' cannot be in word
4990class. Putting underscore in word class breaks forward word movement
4991behavior that users are familiar with.")
4992
4993(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
4994 "Regexp describing a case statement header key.")
4995
4996(defconst vhdl-label-key
4997 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
4998 "Regexp describing a VHDL label.")
4999
5000;; Macro definitions:
5001
5002(defmacro vhdl-point (position)
5eabfe72
KH
5003 "Return the value of point at certain commonly referenced POSITIONs.
5004POSITION can be one of the following symbols:
5005
5006bol -- beginning of line
5007eol -- end of line
5008bod -- beginning of defun
5009boi -- back to indentation
5010eoi -- last whitespace on line
5011ionl -- indentation of next line
5012iopl -- indentation of previous line
5013bonl -- beginning of next line
5014bopl -- beginning of previous line
5015
5016This function does not modify point or mark."
d2ddb974 5017 (or (and (eq 'quote (car-safe position))
3dcb36b7
JB
5018 (null (cddr position)))
5019 (error "ERROR: Bad buffer position requested: %s" position))
d2ddb974 5020 (setq position (nth 1 position))
d4a5b644
GM
5021 `(let ((here (point)))
5022 ,@(cond
5023 ((eq position 'bol) '((beginning-of-line)))
5024 ((eq position 'eol) '((end-of-line)))
5025 ((eq position 'bod) '((save-match-data
5026 (vhdl-beginning-of-defun))))
5027 ((eq position 'boi) '((back-to-indentation)))
3dcb36b7 5028 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
d4a5b644
GM
5029 ((eq position 'bonl) '((forward-line 1)))
5030 ((eq position 'bopl) '((forward-line -1)))
5031 ((eq position 'iopl)
5032 '((forward-line -1)
5033 (back-to-indentation)))
5034 ((eq position 'ionl)
5035 '((forward-line 1)
5036 (back-to-indentation)))
3dcb36b7 5037 (t (error "ERROR: Unknown buffer position requested: %s" position))
d4a5b644
GM
5038 )
5039 (prog1
5040 (point)
5041 (goto-char here))
5042 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5043 ;; doesn't hurt for v19
5044 ,@nil
5045 ))
d2ddb974
KH
5046
5047(defmacro vhdl-safe (&rest body)
5eabfe72 5048 "Safely execute BODY, return nil if an error occurred."
d4a5b644
GM
5049 `(condition-case nil
5050 (progn ,@body)
5051 (error nil)))
d2ddb974
KH
5052
5053(defmacro vhdl-add-syntax (symbol &optional relpos)
5eabfe72
KH
5054 "A simple macro to append the syntax in SYMBOL to the syntax list.
5055Try to increase performance by using this macro."
d4a5b644
GM
5056 `(setq vhdl-syntactic-context
5057 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
d2ddb974
KH
5058
5059(defmacro vhdl-has-syntax (symbol)
5eabfe72
KH
5060 "A simple macro to return check the syntax list.
5061Try to increase performance by using this macro."
d4a5b644 5062 `(assoc ,symbol vhdl-syntactic-context))
d2ddb974
KH
5063
5064;; Syntactic element offset manipulation:
5065
5066(defun vhdl-read-offset (langelem)
5eabfe72 5067 "Read new offset value for LANGELEM from minibuffer.
2e8b9c7d 5068Return a valid value only."
d2ddb974
KH
5069 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5070 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5071 (prompt "Offset: ")
5072 offset input interned)
5073 (while (not offset)
5074 (setq input (read-string prompt oldoff)
5075 offset (cond ((string-equal "+" input) '+)
5076 ((string-equal "-" input) '-)
5077 ((string-equal "++" input) '++)
5078 ((string-equal "--" input) '--)
5079 ((string-match "^-?[0-9]+$" input)
5080 (string-to-int input))
5081 ((fboundp (setq interned (intern input)))
5082 interned)
5083 ((boundp interned) interned)
5084 ;; error, but don't signal one, keep trying
5085 ;; to read an input value
5086 (t (ding)
5087 (setq prompt errmsg)
5088 nil))))
5089 offset))
5090
5091(defun vhdl-set-offset (symbol offset &optional add-p)
5092 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5093SYMBOL is the syntactic element symbol to change and OFFSET is the new
5094offset for that syntactic element. Optional ADD says to add SYMBOL to
5095`vhdl-offsets-alist' if it doesn't already appear there."
5096 (interactive
5097 (let* ((langelem
5098 (intern (completing-read
5099 (concat "Syntactic symbol to change"
5100 (if current-prefix-arg " or add" "")
5101 ": ")
5102 (mapcar
5103 (function
5104 (lambda (langelem)
5105 (cons (format "%s" (car langelem)) nil)))
5106 vhdl-offsets-alist)
5107 nil (not current-prefix-arg)
5108 ;; initial contents tries to be the last element
5109 ;; on the syntactic analysis list for the current
5110 ;; line
5111 (let* ((syntax (vhdl-get-syntactic-context))
5112 (len (length syntax))
5113 (ic (format "%s" (car (nth (1- len) syntax)))))
5eabfe72 5114 ic)
d2ddb974
KH
5115 )))
5116 (offset (vhdl-read-offset langelem)))
5117 (list langelem offset current-prefix-arg)))
5118 ;; sanity check offset
5119 (or (eq offset '+)
5120 (eq offset '-)
5121 (eq offset '++)
5122 (eq offset '--)
5123 (integerp offset)
5124 (fboundp offset)
5125 (boundp offset)
3dcb36b7 5126 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
d2ddb974
KH
5127 offset))
5128 (let ((entry (assq symbol vhdl-offsets-alist)))
5129 (if entry
5130 (setcdr entry offset)
5131 (if add-p
5eabfe72
KH
5132 (setq vhdl-offsets-alist
5133 (cons (cons symbol offset) vhdl-offsets-alist))
3dcb36b7 5134 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
d2ddb974
KH
5135 (vhdl-keep-region-active))
5136
5137(defun vhdl-set-style (style &optional local)
5eabfe72 5138 "Set `vhdl-mode' variables to use one of several different indentation styles.
d2ddb974
KH
5139STYLE is a string representing the desired style and optional LOCAL is
5140a flag which, if non-nil, means to make the style variables being
5141changed buffer local, instead of the default, which is to set the
5142global variables. Interactively, the flag comes from the prefix
5143argument. The styles are chosen from the `vhdl-style-alist' variable."
5144 (interactive (list (completing-read "Use which VHDL indentation style? "
5eabfe72 5145 vhdl-style-alist nil t)
d2ddb974
KH
5146 current-prefix-arg))
5147 (let ((vars (cdr (assoc style vhdl-style-alist))))
5148 (or vars
3dcb36b7 5149 (error "ERROR: Invalid VHDL indentation style `%s'" style))
d2ddb974
KH
5150 ;; set all the variables
5151 (mapcar
5152 (function
5153 (lambda (varentry)
5154 (let ((var (car varentry))
5155 (val (cdr varentry)))
5156 (and local
5157 (make-local-variable var))
5158 ;; special case for vhdl-offsets-alist
5159 (if (not (eq var 'vhdl-offsets-alist))
5160 (set var val)
5161 ;; reset vhdl-offsets-alist to the default value first
5162 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5163 ;; now set the langelems that are different
5164 (mapcar
5165 (function
5166 (lambda (langentry)
5167 (let ((langelem (car langentry))
5168 (offset (cdr langentry)))
5169 (vhdl-set-offset langelem offset)
5170 )))
5171 val))
5172 )))
5173 vars))
5174 (vhdl-keep-region-active))
5175
5176(defun vhdl-get-offset (langelem)
5eabfe72
KH
5177 "Get offset from LANGELEM which is a cons cell of the form:
5178\(SYMBOL . RELPOS). The symbol is matched against
5179vhdl-offsets-alist and the offset found there is either returned,
5180or added to the indentation at RELPOS. If RELPOS is nil, then
5181the offset is simply returned."
d2ddb974
KH
5182 (let* ((symbol (car langelem))
5183 (relpos (cdr langelem))
5184 (match (assq symbol vhdl-offsets-alist))
5185 (offset (cdr-safe match)))
5186 ;; offset can be a number, a function, a variable, or one of the
5187 ;; symbols + or -
5188 (cond
5189 ((not match)
5190 (if vhdl-strict-syntax-p
3dcb36b7 5191 (error "ERROR: Don't know how to indent a %s" symbol)
d2ddb974
KH
5192 (setq offset 0
5193 relpos 0)))
5194 ((eq offset '+) (setq offset vhdl-basic-offset))
5195 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5196 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5197 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5198 ((and (not (numberp offset))
5199 (fboundp offset))
5200 (setq offset (funcall offset langelem)))
5201 ((not (numberp offset))
5202 (setq offset (eval offset)))
5203 )
5204 (+ (if (and relpos
5205 (< relpos (vhdl-point 'bol)))
5206 (save-excursion
5207 (goto-char relpos)
5208 (current-column))
5209 0)
5210 offset)))
5211
5212;; Syntactic support functions:
5213
3dcb36b7
JB
5214(defun vhdl-in-comment-p ()
5215 "Check if point is in a comment."
5216 (eq (vhdl-in-literal) 'comment))
5217
5218(defun vhdl-in-string-p ()
5219 "Check if point is in a string."
5220 (eq (vhdl-in-literal) 'string))
d2ddb974 5221
3dcb36b7 5222(defun vhdl-in-literal ()
5eabfe72 5223 "Determine if point is in a VHDL literal."
d2ddb974 5224 (save-excursion
5eabfe72 5225 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
d2ddb974
KH
5226 (cond
5227 ((nth 3 state) 'string)
5228 ((nth 4 state) 'comment)
5eabfe72 5229 (t nil)))))
d2ddb974 5230
3dcb36b7
JB
5231(defun vhdl-forward-comment (&optional direction)
5232 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5233negative, skip forward otherwise."
5234 (interactive "p")
5235 (if (and direction (< direction 0))
5236 ;; skip backwards
5237 (progn
5238 (skip-chars-backward " \t\n")
5239 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5240 (goto-char (match-beginning 3))
5241 (skip-chars-backward " \t\n")))
5242 ;; skip forwards
5243 (skip-chars-forward " \t\n")
5244 (while (looking-at "--.*")
5245 (goto-char (match-end 0))
5246 (skip-chars-forward " \t\n"))))
5247
5248;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5249(unless (and vhdl-xemacs (string< "21.2" emacs-version))
5250 (defalias 'vhdl-forward-comment 'forward-comment))
5251
d2ddb974
KH
5252;; This is the best we can do in Win-Emacs.
5253(defun vhdl-win-il (&optional lim)
5eabfe72 5254 "Determine if point is in a VHDL literal."
d2ddb974
KH
5255 (save-excursion
5256 (let* ((here (point))
5257 (state nil)
5258 (match nil)
5259 (lim (or lim (vhdl-point 'bod))))
5260 (goto-char lim )
5261 (while (< (point) here)
5262 (setq match
5263 (and (re-search-forward "--\\|[\"']"
5264 here 'move)
5265 (buffer-substring (match-beginning 0) (match-end 0))))
5266 (setq state
5267 (cond
5268 ;; no match
5269 ((null match) nil)
5270 ;; looking at the opening of a VHDL style comment
5271 ((string= "--" match)
5272 (if (<= here (progn (end-of-line) (point))) 'comment))
5273 ;; looking at the opening of a double quote string
5274 ((string= "\"" match)
5275 (if (not (save-restriction
5276 ;; this seems to be necessary since the
5277 ;; re-search-forward will not work without it
5278 (narrow-to-region (point) here)
5279 (re-search-forward
5280 ;; this regexp matches a double quote
5281 ;; which is preceded by an even number
5282 ;; of backslashes, including zero
5283 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5284 'string))
5285 ;; looking at the opening of a single quote string
5286 ((string= "'" match)
5287 (if (not (save-restriction
5288 ;; see comments from above
5289 (narrow-to-region (point) here)
5290 (re-search-forward
5291 ;; this matches a single quote which is
5292 ;; preceded by zero or two backslashes.
5293 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5294 here 'move)))
5295 'string))
5296 (t nil)))
5297 ) ; end-while
5298 state)))
5299
5eabfe72 5300(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5301 (fset 'vhdl-in-literal 'vhdl-win-il))
5302
5303;; Skipping of "syntactic whitespace". Syntactic whitespace is
5304;; defined as lexical whitespace or comments. Search no farther back
5305;; or forward than optional LIM. If LIM is omitted, (point-min) is
5306;; used for backward skipping, (point-max) is used for forward
5307;; skipping.
5308
5309(defun vhdl-forward-syntactic-ws (&optional lim)
5eabfe72 5310 "Forward skip of syntactic whitespace."
d2ddb974
KH
5311 (save-restriction
5312 (let* ((lim (or lim (point-max)))
5313 (here lim)
5314 (hugenum (point-max)))
5315 (narrow-to-region lim (point))
5316 (while (/= here (point))
5317 (setq here (point))
3dcb36b7 5318 (vhdl-forward-comment hugenum)))))
d2ddb974
KH
5319
5320;; This is the best we can do in Win-Emacs.
5321(defun vhdl-win-fsws (&optional lim)
5eabfe72 5322 "Forward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5323 (let ((lim (or lim (point-max)))
5324 stop)
5325 (while (not stop)
5326 (skip-chars-forward " \t\n\r\f" lim)
5327 (cond
5328 ;; vhdl comment
5329 ((looking-at "--") (end-of-line))
5330 ;; none of the above
3dcb36b7 5331 (t (setq stop t))))))
d2ddb974 5332
5eabfe72 5333(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5334 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5335
5336(defun vhdl-backward-syntactic-ws (&optional lim)
5eabfe72 5337 "Backward skip over syntactic whitespace."
d2ddb974
KH
5338 (save-restriction
5339 (let* ((lim (or lim (point-min)))
5340 (here lim)
5341 (hugenum (- (point-max))))
5342 (if (< lim (point))
5343 (progn
5344 (narrow-to-region lim (point))
5345 (while (/= here (point))
5346 (setq here (point))
3dcb36b7 5347 (vhdl-forward-comment hugenum)))))))
d2ddb974
KH
5348
5349;; This is the best we can do in Win-Emacs.
5350(defun vhdl-win-bsws (&optional lim)
5eabfe72 5351 "Backward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5352 (let ((lim (or lim (vhdl-point 'bod)))
5353 stop)
5354 (while (not stop)
5355 (skip-chars-backward " \t\n\r\f" lim)
5356 (cond
5357 ;; vhdl comment
3dcb36b7 5358 ((eq (vhdl-in-literal) 'comment)
d2ddb974
KH
5359 (skip-chars-backward "^-" lim)
5360 (skip-chars-backward "-" lim)
5361 (while (not (or (and (= (following-char) ?-)
5362 (= (char-after (1+ (point))) ?-))
5363 (<= (point) lim)))
5364 (skip-chars-backward "^-" lim)
5365 (skip-chars-backward "-" lim)))
5366 ;; none of the above
3dcb36b7 5367 (t (setq stop t))))))
d2ddb974 5368
5eabfe72 5369(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5370 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5371
5372;; Functions to help finding the correct indentation column:
5373
5374(defun vhdl-first-word (point)
5375 "If the keyword at POINT is at boi, then return (current-column) at
5376that point, else nil."
5377 (save-excursion
5378 (and (goto-char point)
5379 (eq (point) (vhdl-point 'boi))
5380 (current-column))))
5381
5382(defun vhdl-last-word (point)
5383 "If the keyword at POINT is at eoi, then return (current-column) at
5384that point, else nil."
5385 (save-excursion
5386 (and (goto-char point)
5387 (save-excursion (or (eq (progn (forward-sexp) (point))
5388 (vhdl-point 'eoi))
5389 (looking-at "\\s-*\\(--\\)?")))
5390 (current-column))))
5391
5392;; Core syntactic evaluation functions:
5393
5394(defconst vhdl-libunit-re
5395 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5396
5397(defun vhdl-libunit-p ()
5398 (and
5399 (save-excursion
5400 (forward-sexp)
5401 (skip-chars-forward " \t\n")
5402 (not (looking-at "is\\b[^_]")))
5403 (save-excursion
5404 (backward-sexp)
5405 (and (not (looking-at "use\\b[^_]"))
5406 (progn
5407 (forward-sexp)
5408 (vhdl-forward-syntactic-ws)
5409 (/= (following-char) ?:))))
5410 ))
5411
5412(defconst vhdl-defun-re
5eabfe72 5413 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
d2ddb974
KH
5414
5415(defun vhdl-defun-p ()
5416 (save-excursion
5eabfe72
KH
5417 (if (looking-at "block\\|process\\|procedural")
5418 ;; "block", "process", "procedural":
d2ddb974
KH
5419 (save-excursion
5420 (backward-sexp)
5421 (not (looking-at "end\\s-+\\w")))
5422 ;; "architecture", "configuration", "entity",
5423 ;; "package", "procedure", "function":
5424 t)))
5425
5426(defun vhdl-corresponding-defun ()
5427 "If the word at the current position corresponds to a \"defun\"
5428keyword, then return a string that can be used to find the
5429corresponding \"begin\" keyword, else return nil."
5430 (save-excursion
5431 (and (looking-at vhdl-defun-re)
5432 (vhdl-defun-p)
5eabfe72
KH
5433 (if (looking-at "block\\|process\\|procedural")
5434 ;; "block", "process". "procedural:
d2ddb974
KH
5435 (buffer-substring (match-beginning 0) (match-end 0))
5436 ;; "architecture", "configuration", "entity", "package",
5437 ;; "procedure", "function":
5438 "is"))))
5439
5440(defconst vhdl-begin-fwd-re
5eabfe72 5441 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
d2ddb974
KH
5442 "A regular expression for searching forward that matches all known
5443\"begin\" keywords.")
5444
5445(defconst vhdl-begin-bwd-re
5eabfe72 5446 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
d2ddb974
KH
5447 "A regular expression for searching backward that matches all known
5448\"begin\" keywords.")
5449
5450(defun vhdl-begin-p (&optional lim)
5451 "Return t if we are looking at a real \"begin\" keyword.
5452Assumes that the caller will make sure that we are looking at
5453vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5454the middle of an identifier that just happens to contain a \"begin\"
5455keyword."
5456 (cond
5457 ;; "[architecture|case|configuration|entity|package|
5458 ;; procedure|function] ... is":
5459 ((and (looking-at "i")
5460 (save-excursion
5461 ;; Skip backward over first sexp (needed to skip over a
5462 ;; procedure interface list, and is harmless in other
5463 ;; situations). Note that we need "return" in the
5464 ;; following search list so that we don't run into
5465 ;; semicolons in the function interface list.
5466 (backward-sexp)
5467 (let (foundp)
5468 (while (and (not foundp)
5469 (re-search-backward
5eabfe72 5470 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
d2ddb974
KH
5471 lim 'move))
5472 (if (or (= (preceding-char) ?_)
3dcb36b7 5473 (vhdl-in-literal))
d2ddb974
KH
5474 (backward-char)
5475 (setq foundp t))))
5476 (and (/= (following-char) ?\;)
5eabfe72 5477 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
d2ddb974
KH
5478 t)
5479 ;; "begin", "then":
5480 ((looking-at "be\\|t")
5481 t)
5482 ;; "else":
5483 ((and (looking-at "e")
5484 ;; make sure that the "else" isn't inside a
5485 ;; conditional signal assignment.
5486 (save-excursion
5487 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5488 (or (eq (following-char) ?\;)
5489 (eq (point) lim))))
5490 t)
5eabfe72 5491 ;; "block", "generate", "loop", "process", "procedural",
d2ddb974
KH
5492 ;; "units", "record":
5493 ((and (looking-at "bl\\|[glpur]")
5494 (save-excursion
5495 (backward-sexp)
5496 (not (looking-at "end\\s-+\\w"))))
5497 t)
5498 ;; "component":
5499 ((and (looking-at "c")
5500 (save-excursion
5501 (backward-sexp)
5502 (not (looking-at "end\\s-+\\w")))
5503 ;; look out for the dreaded entity class in an attribute
5504 (save-excursion
5505 (vhdl-backward-syntactic-ws lim)
5506 (/= (preceding-char) ?:)))
5507 t)
5508 ;; "for" (inside configuration declaration):
5509 ((and (looking-at "f")
5510 (save-excursion
5511 (backward-sexp)
5512 (not (looking-at "end\\s-+\\w")))
5513 (vhdl-has-syntax 'configuration))
5514 t)
5515 ))
5516
5517(defun vhdl-corresponding-mid (&optional lim)
5518 (cond
5eabfe72 5519 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
d2ddb974
KH
5520 "begin")
5521 ((looking-at "then")
5522 "<else>")
5523 (t
5524 "end")))
5525
5526(defun vhdl-corresponding-end (&optional lim)
5527 "If the word at the current position corresponds to a \"begin\"
5528keyword, then return a vector containing enough information to find
5529the corresponding \"end\" keyword, else return nil. The keyword to
5530search forward for is aref 0. The column in which the keyword must
5531appear is aref 1 or nil if any column is suitable.
5532Assumes that the caller will make sure that we are not in the middle
5533of an identifier that just happens to contain a \"begin\" keyword."
5534 (save-excursion
5535 (and (looking-at vhdl-begin-fwd-re)
5536 (/= (preceding-char) ?_)
3dcb36b7 5537 (not (vhdl-in-literal))
d2ddb974
KH
5538 (vhdl-begin-p lim)
5539 (cond
5540 ;; "is", "generate", "loop":
5541 ((looking-at "[igl]")
5542 (vector "end"
5543 (and (vhdl-last-word (point))
5544 (or (vhdl-first-word (point))
5545 (save-excursion
5546 (vhdl-beginning-of-statement-1 lim)
5547 (vhdl-backward-skip-label lim)
5548 (vhdl-first-word (point)))))))
5549 ;; "begin", "else", "for":
5550 ((looking-at "be\\|[ef]")
5551 (vector "end"
5552 (and (vhdl-last-word (point))
5553 (or (vhdl-first-word (point))
5554 (save-excursion
5555 (vhdl-beginning-of-statement-1 lim)
5556 (vhdl-backward-skip-label lim)
5557 (vhdl-first-word (point)))))))
5558 ;; "component", "units", "record":
5559 ((looking-at "[cur]")
5560 ;; The first end found will close the block
5561 (vector "end" nil))
5eabfe72 5562 ;; "block", "process", "procedural":
d2ddb974
KH
5563 ((looking-at "bl\\|p")
5564 (vector "end"
5565 (or (vhdl-first-word (point))
5566 (save-excursion
5567 (vhdl-beginning-of-statement-1 lim)
5568 (vhdl-backward-skip-label lim)
5569 (vhdl-first-word (point))))))
5570 ;; "then":
5571 ((looking-at "t")
5572 (vector "elsif\\|else\\|end\\s-+if"
5573 (and (vhdl-last-word (point))
5574 (or (vhdl-first-word (point))
5575 (save-excursion
5576 (vhdl-beginning-of-statement-1 lim)
5577 (vhdl-backward-skip-label lim)
5578 (vhdl-first-word (point)))))))
5579 ))))
5580
5581(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5582
5583(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5584
5585(defun vhdl-end-p (&optional lim)
5586 "Return t if we are looking at a real \"end\" keyword.
5587Assumes that the caller will make sure that we are looking at
5588vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5589the middle of an identifier that just happens to contain an \"end\"
5590keyword."
5591 (or (not (looking-at "else"))
5592 ;; make sure that the "else" isn't inside a conditional signal
5593 ;; assignment.
5594 (save-excursion
5595 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5596 (or (eq (following-char) ?\;)
5597 (eq (point) lim)))))
5598
5599(defun vhdl-corresponding-begin (&optional lim)
5600 "If the word at the current position corresponds to an \"end\"
5601keyword, then return a vector containing enough information to find
5602the corresponding \"begin\" keyword, else return nil. The keyword to
3dcb36b7 5603search backward for is aref 0. The column in which the keyword must
d2ddb974
KH
5604appear is aref 1 or nil if any column is suitable. The supplementary
5605keyword to search forward for is aref 2 or nil if this is not
5606required. If aref 3 is t, then the \"begin\" keyword may be found in
5607the middle of a statement.
5608Assumes that the caller will make sure that we are not in the middle
5609of an identifier that just happens to contain an \"end\" keyword."
5610 (save-excursion
5611 (let (pos)
5612 (if (and (looking-at vhdl-end-fwd-re)
3dcb36b7 5613 (not (vhdl-in-literal))
d2ddb974
KH
5614 (vhdl-end-p lim))
5615 (if (looking-at "el")
5616 ;; "else", "elsif":
5617 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5618 ;; "end ...":
5619 (setq pos (point))
5620 (forward-sexp)
5621 (skip-chars-forward " \t\n")
5622 (cond
5623 ;; "end if":
5624 ((looking-at "if\\b[^_]")
5625 (vector "else\\|elsif\\|if"
5626 (vhdl-first-word pos)
5627 "else\\|then" nil))
5628 ;; "end component":
5629 ((looking-at "component\\b[^_]")
5630 (vector (buffer-substring (match-beginning 1)
5631 (match-end 1))
5632 (vhdl-first-word pos)
5633 nil nil))
5634 ;; "end units", "end record":
5635 ((looking-at "\\(units\\|record\\)\\b[^_]")
5636 (vector (buffer-substring (match-beginning 1)
5637 (match-end 1))
5638 (vhdl-first-word pos)
5639 nil t))
5eabfe72
KH
5640 ;; "end block", "end process", "end procedural":
5641 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
d2ddb974
KH
5642 (vector "begin" (vhdl-first-word pos) nil nil))
5643 ;; "end case":
5644 ((looking-at "case\\b[^_]")
5645 (vector "case" (vhdl-first-word pos) "is" nil))
5646 ;; "end generate":
5647 ((looking-at "generate\\b[^_]")
5648 (vector "generate\\|for\\|if"
5649 (vhdl-first-word pos)
5650 "generate" nil))
5651 ;; "end loop":
5652 ((looking-at "loop\\b[^_]")
5653 (vector "loop\\|while\\|for"
5654 (vhdl-first-word pos)
5655 "loop" nil))
5656 ;; "end for" (inside configuration declaration):
5657 ((looking-at "for\\b[^_]")
5658 (vector "for" (vhdl-first-word pos) nil nil))
5659 ;; "end [id]":
5660 (t
5661 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5662 (vhdl-first-word pos)
5663 ;; return an alist of (statement . keyword) mappings
5664 '(
5665 ;; "begin ... end [id]":
5666 ("begin" . nil)
5667 ;; "architecture ... is ... begin ... end [id]":
5668 ("architecture" . "is")
5669 ;; "configuration ... is ... end [id]":
5670 ("configuration" . "is")
5671 ;; "entity ... is ... end [id]":
5672 ("entity" . "is")
5673 ;; "package ... is ... end [id]":
5674 ("package" . "is")
5675 ;; "procedure ... is ... begin ... end [id]":
5676 ("procedure" . "is")
5677 ;; "function ... is ... begin ... end [id]":
5678 ("function" . "is")
5679 )
5680 nil))
5681 ))) ; "end ..."
5682 )))
5683
5684(defconst vhdl-leader-re
5eabfe72 5685 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
d2ddb974
KH
5686
5687(defun vhdl-end-of-leader ()
5688 (save-excursion
5eabfe72 5689 (cond ((looking-at "block\\|process\\|procedural")
d2ddb974
KH
5690 (if (save-excursion
5691 (forward-sexp)
5692 (skip-chars-forward " \t\n")
5693 (= (following-char) ?\())
5694 (forward-sexp 2)
5695 (forward-sexp))
3dcb36b7
JB
5696 (when (looking-at "[ \t\n]*is")
5697 (goto-char (match-end 0)))
d2ddb974
KH
5698 (point))
5699 ((looking-at "component")
5700 (forward-sexp 2)
3dcb36b7
JB
5701 (when (looking-at "[ \t\n]*is")
5702 (goto-char (match-end 0)))
d2ddb974
KH
5703 (point))
5704 ((looking-at "for")
5705 (forward-sexp 2)
5706 (skip-chars-forward " \t\n")
5707 (while (looking-at "[,:(]")
5708 (forward-sexp)
5709 (skip-chars-forward " \t\n"))
5710 (point))
5711 (t nil)
5712 )))
5713
5714(defconst vhdl-trailer-re
5715 "\\b\\(is\\|then\\|generate\\|loop\\)\\b[^_]")
5716
5717(defconst vhdl-statement-fwd-re
5718 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5719 "A regular expression for searching forward that matches all known
5720\"statement\" keywords.")
5721
5722(defconst vhdl-statement-bwd-re
5723 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5724 "A regular expression for searching backward that matches all known
5725\"statement\" keywords.")
5726
5727(defun vhdl-statement-p (&optional lim)
5728 "Return t if we are looking at a real \"statement\" keyword.
5729Assumes that the caller will make sure that we are looking at
5eabfe72
KH
5730vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5731in the middle of an identifier that just happens to contain a
5732\"statement\" keyword."
d2ddb974
KH
5733 (cond
5734 ;; "for" ... "generate":
5735 ((and (looking-at "f")
5736 ;; Make sure it's the start of a parameter specification.
5737 (save-excursion
5738 (forward-sexp 2)
5739 (skip-chars-forward " \t\n")
5740 (looking-at "in\\b[^_]"))
5741 ;; Make sure it's not an "end for".
5742 (save-excursion
5743 (backward-sexp)
5744 (not (looking-at "end\\s-+\\w"))))
5745 t)
5746 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5747 ((and (looking-at "i")
5748 ;; Make sure it's not an "end if".
5749 (save-excursion
5750 (backward-sexp)
5751 (not (looking-at "end\\s-+\\w"))))
5752 t)
5753 ;; "while" ... "loop":
5754 ((looking-at "w")
5755 t)
5756 ))
5757
5758(defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5759 "Regexp describing a case statement alternative key.")
5760
5761(defun vhdl-case-alternative-p (&optional lim)
5762 "Return t if we are looking at a real case alternative.
5763Assumes that the caller will make sure that we are looking at
5764vhdl-case-alternative-re, and are not inside a literal, and that
5765we are not in the middle of an identifier that just happens to
5766contain a \"when\" keyword."
5767 (save-excursion
5768 (let (foundp)
5769 (while (and (not foundp)
5770 (re-search-backward ";\\|<=" lim 'move))
5771 (if (or (= (preceding-char) ?_)
3dcb36b7 5772 (vhdl-in-literal))
d2ddb974
KH
5773 (backward-char)
5774 (setq foundp t)))
5775 (or (eq (following-char) ?\;)
5776 (eq (point) lim)))
5777 ))
5778
5779;; Core syntactic movement functions:
5780
5781(defconst vhdl-b-t-b-re
5782 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5783
5784(defun vhdl-backward-to-block (&optional lim)
5785 "Move backward to the previous \"begin\" or \"end\" keyword."
5786 (let (foundp)
5787 (while (and (not foundp)
5788 (re-search-backward vhdl-b-t-b-re lim 'move))
5789 (if (or (= (preceding-char) ?_)
3dcb36b7 5790 (vhdl-in-literal))
d2ddb974
KH
5791 (backward-char)
5792 (cond
5793 ;; "begin" keyword:
5794 ((and (looking-at vhdl-begin-fwd-re)
5795 (/= (preceding-char) ?_)
5796 (vhdl-begin-p lim))
5797 (setq foundp 'begin))
5798 ;; "end" keyword:
5799 ((and (looking-at vhdl-end-fwd-re)
5800 (/= (preceding-char) ?_)
5801 (vhdl-end-p lim))
5802 (setq foundp 'end))
5803 ))
5804 )
5805 foundp
5806 ))
5807
5808(defun vhdl-forward-sexp (&optional count lim)
5809 "Move forward across one balanced expression (sexp).
5810With COUNT, do it that many times."
5811 (interactive "p")
5812 (let ((count (or count 1))
5813 (case-fold-search t)
5814 end-vec target)
5815 (save-excursion
5816 (while (> count 0)
5817 ;; skip whitespace
5818 (skip-chars-forward " \t\n")
5819 ;; Check for an unbalanced "end" keyword
5820 (if (and (looking-at vhdl-end-fwd-re)
5821 (/= (preceding-char) ?_)
3dcb36b7 5822 (not (vhdl-in-literal))
d2ddb974
KH
5823 (vhdl-end-p lim)
5824 (not (looking-at "else")))
5825 (error
3dcb36b7 5826 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
d2ddb974
KH
5827 ;; If the current keyword is a "begin" keyword, then find the
5828 ;; corresponding "end" keyword.
5829 (if (setq end-vec (vhdl-corresponding-end lim))
5830 (let (
5831 ;; end-re is the statement keyword to search for
5832 (end-re
5833 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5834 ;; column is either the statement keyword target column
5835 ;; or nil
5836 (column (aref end-vec 1))
5837 (eol (vhdl-point 'eol))
5838 foundp literal placeholder)
5839 ;; Look for the statement keyword.
5840 (while (and (not foundp)
5841 (re-search-forward end-re nil t)
5842 (setq placeholder (match-end 1))
5843 (goto-char (match-beginning 0)))
5844 ;; If we are in a literal, or not in the right target
5845 ;; column and not on the same line as the begin, then
5846 ;; try again.
5847 (if (or (and column
5848 (/= (current-indentation) column)
5849 (> (point) eol))
5850 (= (preceding-char) ?_)
3dcb36b7 5851 (setq literal (vhdl-in-literal)))
d2ddb974
KH
5852 (if (eq literal 'comment)
5853 (end-of-line)
5854 (forward-char))
5855 ;; An "else" keyword corresponds to both the opening brace
5856 ;; of the following sexp and the closing brace of the
5857 ;; previous sexp.
5858 (if (not (looking-at "else"))
5859 (goto-char placeholder))
5860 (setq foundp t))
5861 )
5862 (if (not foundp)
3dcb36b7 5863 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
d2ddb974
KH
5864 )
5865 ;; If the current keyword is not a "begin" keyword, then just
5866 ;; perform the normal forward-sexp.
5867 (forward-sexp)
5868 )
5869 (setq count (1- count))
5870 )
5871 (setq target (point)))
5872 (goto-char target)
5873 nil))
5874
5875(defun vhdl-backward-sexp (&optional count lim)
5876 "Move backward across one balanced expression (sexp).
5877With COUNT, do it that many times. LIM bounds any required backward
5878searches."
5879 (interactive "p")
5880 (let ((count (or count 1))
5881 (case-fold-search t)
5882 begin-vec target)
5883 (save-excursion
5884 (while (> count 0)
5885 ;; Perform the normal backward-sexp, unless we are looking at
5886 ;; "else" - an "else" keyword corresponds to both the opening brace
5887 ;; of the following sexp and the closing brace of the previous sexp.
5888 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
5889 (/= (preceding-char) ?_)
3dcb36b7 5890 (not (vhdl-in-literal)))
d2ddb974
KH
5891 nil
5892 (backward-sexp)
5893 (if (and (looking-at vhdl-begin-fwd-re)
5894 (/= (preceding-char) ?_)
3dcb36b7 5895 (not (vhdl-in-literal))
d2ddb974 5896 (vhdl-begin-p lim))
3dcb36b7 5897 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
d2ddb974
KH
5898 ;; If the current keyword is an "end" keyword, then find the
5899 ;; corresponding "begin" keyword.
5900 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
5901 (/= (preceding-char) ?_))
5902 (let (
5903 ;; begin-re is the statement keyword to search for
5904 (begin-re
5905 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
5906 ;; column is either the statement keyword target column
5907 ;; or nil
5908 (column (aref begin-vec 1))
5909 ;; internal-p controls where the statement keyword can
5910 ;; be found.
5911 (internal-p (aref begin-vec 3))
5912 (last-backward (point)) last-forward
5913 foundp literal keyword)
5914 ;; Look for the statement keyword.
5915 (while (and (not foundp)
5916 (re-search-backward begin-re lim t)
5917 (setq keyword
5918 (buffer-substring (match-beginning 1)
5919 (match-end 1))))
5920 ;; If we are in a literal or in the wrong column,
5921 ;; then try again.
5922 (if (or (and column
5923 (and (/= (current-indentation) column)
5924 ;; possibly accept current-column as
5925 ;; well as current-indentation.
5926 (or (not internal-p)
5927 (/= (current-column) column))))
5928 (= (preceding-char) ?_)
3dcb36b7 5929 (vhdl-in-literal))
d2ddb974
KH
5930 (backward-char)
5931 ;; If there is a supplementary keyword, then
5932 ;; search forward for it.
5933 (if (and (setq begin-re (aref begin-vec 2))
5934 (or (not (listp begin-re))
5935 ;; If begin-re is an alist, then find the
5936 ;; element corresponding to the actual
5937 ;; keyword that we found.
5938 (progn
5939 (setq begin-re
5940 (assoc keyword begin-re))
5941 (and begin-re
5942 (setq begin-re (cdr begin-re))))))
5943 (and
5944 (setq begin-re
5945 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
5946 (save-excursion
5947 (setq last-forward (point))
5948 ;; Look for the supplementary keyword
5949 ;; (bounded by the backward search start
5950 ;; point).
5951 (while (and (not foundp)
5952 (re-search-forward begin-re
5953 last-backward t)
5954 (goto-char (match-beginning 1)))
5955 ;; If we are in a literal, then try again.
5956 (if (or (= (preceding-char) ?_)
5957 (setq literal
3dcb36b7 5958 (vhdl-in-literal)))
d2ddb974
KH
5959 (if (eq literal 'comment)
5960 (goto-char
5961 (min (vhdl-point 'eol) last-backward))
5962 (forward-char))
5963 ;; We have found the supplementary keyword.
5964 ;; Save the position of the keyword in foundp.
5965 (setq foundp (point)))
5966 )
5967 foundp)
5968 ;; If the supplementary keyword was found, then
5969 ;; move point to the supplementary keyword.
5970 (goto-char foundp))
5971 ;; If there was no supplementary keyword, then
5972 ;; point is already at the statement keyword.
5973 (setq foundp t)))
5974 ) ; end of the search for the statement keyword
5975 (if (not foundp)
3dcb36b7 5976 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
d2ddb974
KH
5977 ))
5978 (setq count (1- count))
5979 )
5980 (setq target (point)))
5981 (goto-char target)
5982 nil))
5983
5984(defun vhdl-backward-up-list (&optional count limit)
5985 "Move backward out of one level of blocks.
5986With argument, do this that many times."
5987 (interactive "p")
5988 (let ((count (or count 1))
5989 target)
5990 (save-excursion
5991 (while (> count 0)
5992 (if (looking-at vhdl-defun-re)
3dcb36b7 5993 (error "ERROR: Unbalanced blocks"))
d2ddb974
KH
5994 (vhdl-backward-to-block limit)
5995 (setq count (1- count)))
5996 (setq target (point)))
5997 (goto-char target)))
5998
5999(defun vhdl-end-of-defun (&optional count)
6000 "Move forward to the end of a VHDL defun."
6001 (interactive)
6002 (let ((case-fold-search t))
6003 (vhdl-beginning-of-defun)
5eabfe72 6004 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6005 (re-search-forward "\\bis\\b"))
6006 (vhdl-forward-sexp)))
6007
6008(defun vhdl-mark-defun ()
6009 "Put mark at end of this \"defun\", point at beginning."
6010 (interactive)
6011 (let ((case-fold-search t))
6012 (push-mark)
6013 (vhdl-beginning-of-defun)
6014 (push-mark)
5eabfe72 6015 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6016 (re-search-forward "\\bis\\b"))
6017 (vhdl-forward-sexp)
6018 (exchange-point-and-mark)))
6019
6020(defun vhdl-beginning-of-libunit ()
6021 "Move backward to the beginning of a VHDL library unit.
6022Returns the location of the corresponding begin keyword, unless search
5eabfe72
KH
6023stops due to beginning or end of buffer.
6024Note that if point is between the \"libunit\" keyword and the
6025corresponding \"begin\" keyword, then that libunit will not be
6026recognised, and the search will continue backwards. If point is
6027at the \"begin\" keyword, then the defun will be recognised. The
6028returned point is at the first character of the \"libunit\" keyword."
d2ddb974
KH
6029 (let ((last-forward (point))
6030 (last-backward
6031 ;; Just in case we are actually sitting on the "begin"
6032 ;; keyword, allow for the keyword and an extra character,
6033 ;; as this will be used when looking forward for the
6034 ;; "begin" keyword.
6035 (save-excursion (forward-word 1) (1+ (point))))
6036 foundp literal placeholder)
6037 ;; Find the "libunit" keyword.
6038 (while (and (not foundp)
6039 (re-search-backward vhdl-libunit-re nil 'move))
6040 ;; If we are in a literal, or not at a real libunit, then try again.
6041 (if (or (= (preceding-char) ?_)
3dcb36b7 6042 (vhdl-in-literal)
d2ddb974
KH
6043 (not (vhdl-libunit-p)))
6044 (backward-char)
6045 ;; Find the corresponding "begin" keyword.
6046 (setq last-forward (point))
6047 (while (and (not foundp)
6048 (re-search-forward "\\bis\\b[^_]" last-backward t)
6049 (setq placeholder (match-beginning 0)))
6050 (if (or (= (preceding-char) ?_)
3dcb36b7 6051 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6052 ;; It wasn't a real keyword, so keep searching.
6053 (if (eq literal 'comment)
6054 (goto-char
6055 (min (vhdl-point 'eol) last-backward))
6056 (forward-char))
6057 ;; We have found the begin keyword, loop will exit.
6058 (setq foundp placeholder)))
6059 ;; Go back to the libunit keyword
6060 (goto-char last-forward)))
6061 foundp))
6062
6063(defun vhdl-beginning-of-defun (&optional count)
6064 "Move backward to the beginning of a VHDL defun.
6065With argument, do it that many times.
6066Returns the location of the corresponding begin keyword, unless search
6067stops due to beginning or end of buffer."
6068 ;; Note that if point is between the "defun" keyword and the
6069 ;; corresponding "begin" keyword, then that defun will not be
6070 ;; recognised, and the search will continue backwards. If point is
6071 ;; at the "begin" keyword, then the defun will be recognised. The
6072 ;; returned point is at the first character of the "defun" keyword.
6073 (interactive "p")
6074 (let ((count (or count 1))
6075 (case-fold-search t)
6076 (last-forward (point))
6077 foundp)
6078 (while (> count 0)
6079 (setq foundp nil)
6080 (goto-char last-forward)
6081 (let ((last-backward
6082 ;; Just in case we are actually sitting on the "begin"
6083 ;; keyword, allow for the keyword and an extra character,
6084 ;; as this will be used when looking forward for the
6085 ;; "begin" keyword.
6086 (save-excursion (forward-word 1) (1+ (point))))
6087 begin-string literal)
6088 (while (and (not foundp)
6089 (re-search-backward vhdl-defun-re nil 'move))
6090 ;; If we are in a literal, then try again.
6091 (if (or (= (preceding-char) ?_)
3dcb36b7 6092 (vhdl-in-literal))
d2ddb974
KH
6093 (backward-char)
6094 (if (setq begin-string (vhdl-corresponding-defun))
6095 ;; This is a real defun keyword.
6096 ;; Find the corresponding "begin" keyword.
6097 ;; Look for the begin keyword.
6098 (progn
6099 ;; Save the search start point.
6100 (setq last-forward (point))
6101 (while (and (not foundp)
6102 (search-forward begin-string last-backward t))
6103 (if (or (= (preceding-char) ?_)
6104 (save-match-data
3dcb36b7 6105 (setq literal (vhdl-in-literal))))
d2ddb974
KH
6106 ;; It wasn't a real keyword, so keep searching.
6107 (if (eq literal 'comment)
6108 (goto-char
6109 (min (vhdl-point 'eol) last-backward))
6110 (forward-char))
6111 ;; We have found the begin keyword, loop will exit.
6112 (setq foundp (match-beginning 0)))
6113 )
6114 ;; Go back to the defun keyword
6115 (goto-char last-forward)) ; end search for begin keyword
6116 ))
6117 ) ; end of the search for the defun keyword
6118 )
6119 (setq count (1- count))
6120 )
6121 (vhdl-keep-region-active)
6122 foundp))
6123
8d422bd5 6124(defun vhdl-beginning-of-statement (&optional count lim interactive)
d2ddb974
KH
6125 "Go to the beginning of the innermost VHDL statement.
6126With prefix arg, go back N - 1 statements. If already at the
6127beginning of a statement then go to the beginning of the preceding
6128one. If within a string or comment, or next to a comment (only
6129whitespace between), move by sentences instead of statements.
6130
8d422bd5 6131When called from a program, this function takes 3 optional args: the
d2ddb974 6132prefix arg, and a buffer position limit which is the farthest back to
8d422bd5
RS
6133search, and something whose meaning I don't understand."
6134 (interactive "p\np")
d2ddb974
KH
6135 (let ((count (or count 1))
6136 (case-fold-search t)
6137 (lim (or lim (point-min)))
6138 (here (point))
6139 state)
6140 (save-excursion
6141 (goto-char lim)
6142 (setq state (parse-partial-sexp (point) here nil nil)))
8d422bd5 6143 (if (and interactive
d2ddb974
KH
6144 (or (nth 3 state)
6145 (nth 4 state)
6146 (looking-at (concat "[ \t]*" comment-start-skip))))
6147 (forward-sentence (- count))
6148 (while (> count 0)
6149 (vhdl-beginning-of-statement-1 lim)
6150 (setq count (1- count))))
6151 ;; its possible we've been left up-buf of lim
6152 (goto-char (max (point) lim))
6153 )
6154 (vhdl-keep-region-active))
6155
6156(defconst vhdl-e-o-s-re
6157 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6158
6159(defun vhdl-end-of-statement ()
6160 "Very simple implementation."
6161 (interactive)
6162 (re-search-forward vhdl-e-o-s-re))
6163
6164(defconst vhdl-b-o-s-re
6165 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6166 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6167
6168(defun vhdl-beginning-of-statement-1 (&optional lim)
5eabfe72
KH
6169 "Move to the start of the current statement, or the previous
6170statement if already at the beginning of one."
d2ddb974
KH
6171 (let ((lim (or lim (point-min)))
6172 (here (point))
6173 (pos (point))
6174 donep)
6175 ;; go backwards one balanced expression, but be careful of
6176 ;; unbalanced paren being reached
6177 (if (not (vhdl-safe (progn (backward-sexp) t)))
6178 (progn
6179 (backward-up-list 1)
6180 (forward-char)
6181 (vhdl-forward-syntactic-ws here)
6182 (setq donep t)))
6183 (while (and (not donep)
6184 (not (bobp))
6185 ;; look backwards for a statement boundary
6186 (re-search-backward vhdl-b-o-s-re lim 'move))
6187 (if (or (= (preceding-char) ?_)
3dcb36b7 6188 (vhdl-in-literal))
d2ddb974
KH
6189 (backward-char)
6190 (cond
6191 ;; If we are looking at an open paren, then stop after it
6192 ((eq (following-char) ?\()
6193 (forward-char)
6194 (vhdl-forward-syntactic-ws here)
6195 (setq donep t))
6196 ;; If we are looking at a close paren, then skip it
6197 ((eq (following-char) ?\))
6198 (forward-char)
6199 (setq pos (point))
6200 (backward-sexp)
6201 (if (< (point) lim)
6202 (progn (goto-char pos)
6203 (vhdl-forward-syntactic-ws here)
6204 (setq donep t))))
6205 ;; If we are looking at a semicolon, then stop
6206 ((eq (following-char) ?\;)
6207 (progn
6208 (forward-char)
6209 (vhdl-forward-syntactic-ws here)
6210 (setq donep t)))
6211 ;; If we are looking at a "begin", then stop
6212 ((and (looking-at vhdl-begin-fwd-re)
6213 (/= (preceding-char) ?_)
6214 (vhdl-begin-p nil))
6215 ;; If it's a leader "begin", then find the
6216 ;; right place
6217 (if (looking-at vhdl-leader-re)
6218 (save-excursion
6219 ;; set a default stop point at the begin
6220 (setq pos (point))
6221 ;; is the start point inside the leader area ?
6222 (goto-char (vhdl-end-of-leader))
6223 (vhdl-forward-syntactic-ws here)
6224 (if (< (point) here)
6225 ;; start point was not inside leader area
6226 ;; set stop point at word after leader
6227 (setq pos (point))))
6228 (forward-word 1)
6229 (vhdl-forward-syntactic-ws here)
6230 (setq pos (point)))
6231 (goto-char pos)
6232 (setq donep t))
6233 ;; If we are looking at a "statement", then stop
6234 ((and (looking-at vhdl-statement-fwd-re)
6235 (/= (preceding-char) ?_)
6236 (vhdl-statement-p nil))
6237 (setq donep t))
6238 ;; If we are looking at a case alternative key, then stop
5eabfe72
KH
6239 ((and (looking-at vhdl-case-alternative-re)
6240 (vhdl-case-alternative-p lim))
d2ddb974
KH
6241 (save-excursion
6242 ;; set a default stop point at the when
6243 (setq pos (point))
6244 ;; is the start point inside the case alternative key ?
6245 (looking-at vhdl-case-alternative-re)
6246 (goto-char (match-end 0))
6247 (vhdl-forward-syntactic-ws here)
6248 (if (< (point) here)
6249 ;; start point was not inside the case alternative key
6250 ;; set stop point at word after case alternative keyleader
6251 (setq pos (point))))
6252 (goto-char pos)
6253 (setq donep t))
6254 ;; Bogus find, continue
6255 (t
6256 (backward-char)))))
6257 ))
6258
6259;; Defuns for calculating the current syntactic state:
6260
6261(defun vhdl-get-library-unit (bod placeholder)
5eabfe72
KH
6262 "If there is an enclosing library unit at bod, with it's \"begin\"
6263keyword at placeholder, then return the library unit type."
d2ddb974
KH
6264 (let ((here (vhdl-point 'bol)))
6265 (if (save-excursion
6266 (goto-char placeholder)
6267 (vhdl-safe (vhdl-forward-sexp 1 bod))
6268 (<= here (point)))
6269 (save-excursion
6270 (goto-char bod)
6271 (cond
6272 ((looking-at "e") 'entity)
6273 ((looking-at "a") 'architecture)
6274 ((looking-at "c") 'configuration)
6275 ((looking-at "p")
6276 (save-excursion
6277 (goto-char bod)
6278 (forward-sexp)
6279 (vhdl-forward-syntactic-ws here)
6280 (if (looking-at "body\\b[^_]")
6281 'package-body 'package))))))
6282 ))
6283
6284(defun vhdl-get-block-state (&optional lim)
5eabfe72
KH
6285 "Finds and records all the closest opens.
6286lim is the furthest back we need to search (it should be the
6287previous libunit keyword)."
d2ddb974
KH
6288 (let ((here (point))
6289 (lim (or lim (point-min)))
6290 keyword sexp-start sexp-mid sexp-end
6291 preceding-sexp containing-sexp
6292 containing-begin containing-mid containing-paren)
6293 (save-excursion
6294 ;; Find the containing-paren, and use that as the limit
6295 (if (setq containing-paren
6296 (save-restriction
6297 (narrow-to-region lim (point))
6298 (vhdl-safe (scan-lists (point) -1 1))))
6299 (setq lim containing-paren))
6300 ;; Look backwards for "begin" and "end" keywords.
6301 (while (and (> (point) lim)
6302 (not containing-sexp))
6303 (setq keyword (vhdl-backward-to-block lim))
6304 (cond
6305 ((eq keyword 'begin)
6306 ;; Found a "begin" keyword
6307 (setq sexp-start (point))
6308 (setq sexp-mid (vhdl-corresponding-mid lim))
6309 (setq sexp-end (vhdl-safe
6310 (save-excursion
6311 (vhdl-forward-sexp 1 lim) (point))))
6312 (if (and sexp-end (<= sexp-end here))
6313 ;; we want to record this sexp, but we only want to
6314 ;; record the last-most of any of them before here
6315 (or preceding-sexp
6316 (setq preceding-sexp sexp-start))
6317 ;; we're contained in this sexp so put sexp-start on
6318 ;; front of list
6319 (setq containing-sexp sexp-start)
6320 (setq containing-mid sexp-mid)
6321 (setq containing-begin t)))
6322 ((eq keyword 'end)
6323 ;; Found an "end" keyword
6324 (forward-sexp)
6325 (setq sexp-end (point))
6326 (setq sexp-mid nil)
6327 (setq sexp-start
6328 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6329 (progn (backward-sexp) (point))))
6330 ;; we want to record this sexp, but we only want to
6331 ;; record the last-most of any of them before here
6332 (or preceding-sexp
6333 (setq preceding-sexp sexp-start)))
6334 )))
6335 ;; Check if the containing-paren should be the containing-sexp
6336 (if (and containing-paren
6337 (or (null containing-sexp)
6338 (< containing-sexp containing-paren)))
6339 (setq containing-sexp containing-paren
6340 preceding-sexp nil
6341 containing-begin nil
6342 containing-mid nil))
6343 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6344 ))
6345
6346
6347(defconst vhdl-s-c-a-re
6348 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6349
6350(defun vhdl-skip-case-alternative (&optional lim)
5eabfe72
KH
6351 "Skip forward over case/when bodies, with optional maximal
6352limit. If no next case alternative is found, nil is returned and point
6353is not moved."
d2ddb974
KH
6354 (let ((lim (or lim (point-max)))
6355 (here (point))
6356 donep foundp)
6357 (while (and (< (point) lim)
6358 (not donep))
6359 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6360 (save-match-data
6361 (not (vhdl-in-literal)))
6362 (/= (match-beginning 0) here))
6363 (progn
6364 (goto-char (match-beginning 0))
6365 (cond
6366 ((and (looking-at "case")
6367 (re-search-forward "\\bis[^_]" lim t))
6368 (backward-sexp)
6369 (vhdl-forward-sexp))
6370 (t
6371 (setq donep t
6372 foundp t))))))
6373 (if (not foundp)
6374 (goto-char here))
6375 foundp))
6376
6377(defun vhdl-backward-skip-label (&optional lim)
5eabfe72
KH
6378 "Skip backward over a label, with optional maximal
6379limit. If label is not found, nil is returned and point
6380is not moved."
d2ddb974
KH
6381 (let ((lim (or lim (point-min)))
6382 placeholder)
6383 (if (save-excursion
6384 (vhdl-backward-syntactic-ws lim)
6385 (and (eq (preceding-char) ?:)
6386 (progn
6387 (backward-sexp)
6388 (setq placeholder (point))
6389 (looking-at vhdl-label-key))))
6390 (goto-char placeholder))
6391 ))
6392
6393(defun vhdl-forward-skip-label (&optional lim)
5eabfe72
KH
6394 "Skip forward over a label, with optional maximal
6395limit. If label is not found, nil is returned and point
6396is not moved."
d2ddb974
KH
6397 (let ((lim (or lim (point-max))))
6398 (if (looking-at vhdl-label-key)
6399 (progn
6400 (goto-char (match-end 0))
6401 (vhdl-forward-syntactic-ws lim)))
6402 ))
6403
6404(defun vhdl-get-syntactic-context ()
5eabfe72 6405 "Guess the syntactic description of the current line of VHDL code."
d2ddb974
KH
6406 (save-excursion
6407 (save-restriction
6408 (beginning-of-line)
6409 (let* ((indent-point (point))
6410 (case-fold-search t)
6411 vec literal containing-sexp preceding-sexp
6412 containing-begin containing-mid containing-leader
6413 char-before-ip char-after-ip begin-after-ip end-after-ip
6414 placeholder lim library-unit
6415 )
6416
6417 ;; Reset the syntactic context
6418 (setq vhdl-syntactic-context nil)
6419
6420 (save-excursion
6421 ;; Move to the start of the previous library unit, and
6422 ;; record the position of the "begin" keyword.
6423 (setq placeholder (vhdl-beginning-of-libunit))
6424 ;; The position of the "libunit" keyword gives us a gross
6425 ;; limit point.
6426 (setq lim (point))
6427 )
6428
6429 ;; If there is a previous library unit, and we are enclosed by
6430 ;; it, then set the syntax accordingly.
6431 (and placeholder
6432 (setq library-unit (vhdl-get-library-unit lim placeholder))
6433 (vhdl-add-syntax library-unit lim))
6434
6435 ;; Find the surrounding state.
6436 (if (setq vec (vhdl-get-block-state lim))
6437 (progn
6438 (setq containing-sexp (aref vec 0))
6439 (setq preceding-sexp (aref vec 1))
6440 (setq containing-begin (aref vec 2))
6441 (setq containing-mid (aref vec 3))
6442 ))
6443
6444 ;; set the limit on the farthest back we need to search
6445 (setq lim (if containing-sexp
6446 (save-excursion
6447 (goto-char containing-sexp)
6448 ;; set containing-leader if required
6449 (if (looking-at vhdl-leader-re)
6450 (setq containing-leader (vhdl-end-of-leader)))
6451 (vhdl-point 'bol))
6452 (point-min)))
6453
6454 ;; cache char before and after indent point, and move point to
6455 ;; the most likely position to perform the majority of tests
6456 (goto-char indent-point)
6457 (skip-chars-forward " \t")
3dcb36b7 6458 (setq literal (vhdl-in-literal))
d2ddb974
KH
6459 (setq char-after-ip (following-char))
6460 (setq begin-after-ip (and
6461 (not literal)
6462 (looking-at vhdl-begin-fwd-re)
6463 (vhdl-begin-p)))
6464 (setq end-after-ip (and
6465 (not literal)
6466 (looking-at vhdl-end-fwd-re)
6467 (vhdl-end-p)))
6468 (vhdl-backward-syntactic-ws lim)
6469 (setq char-before-ip (preceding-char))
6470 (goto-char indent-point)
6471 (skip-chars-forward " \t")
6472
6473 ;; now figure out syntactic qualities of the current line
6474 (cond
6475 ;; CASE 1: in a string or comment.
6476 ((memq literal '(string comment))
6477 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6478 ;; CASE 2: Line is at top level.
6479 ((null containing-sexp)
6480 ;; Find the point to which indentation will be relative
6481 (save-excursion
6482 (if (null preceding-sexp)
6483 ;; CASE 2X.1
6484 ;; no preceding-sexp -> use the preceding statement
6485 (vhdl-beginning-of-statement-1 lim)
6486 ;; CASE 2X.2
6487 ;; if there is a preceding-sexp then indent relative to it
6488 (goto-char preceding-sexp)
6489 ;; if not at boi, then the block-opening keyword is
6490 ;; probably following a label, so we need a different
6491 ;; relpos
6492 (if (/= (point) (vhdl-point 'boi))
6493 ;; CASE 2X.3
6494 (vhdl-beginning-of-statement-1 lim)))
6495 ;; v-b-o-s could have left us at point-min
6496 (and (bobp)
6497 ;; CASE 2X.4
6498 (vhdl-forward-syntactic-ws indent-point))
6499 (setq placeholder (point)))
6500 (cond
6501 ;; CASE 2A : we are looking at a block-open
6502 (begin-after-ip
6503 (vhdl-add-syntax 'block-open placeholder))
6504 ;; CASE 2B: we are looking at a block-close
6505 (end-after-ip
6506 (vhdl-add-syntax 'block-close placeholder))
6507 ;; CASE 2C: we are looking at a top-level statement
6508 ((progn
6509 (vhdl-backward-syntactic-ws lim)
6510 (or (bobp)
6511 (= (preceding-char) ?\;)))
6512 (vhdl-add-syntax 'statement placeholder))
6513 ;; CASE 2D: we are looking at a top-level statement-cont
6514 (t
6515 (vhdl-beginning-of-statement-1 lim)
6516 ;; v-b-o-s could have left us at point-min
6517 (and (bobp)
6518 ;; CASE 2D.1
6519 (vhdl-forward-syntactic-ws indent-point))
6520 (vhdl-add-syntax 'statement-cont (point)))
6521 )) ; end CASE 2
6522 ;; CASE 3: line is inside parentheses. Most likely we are
6523 ;; either in a subprogram argument (interface) list, or a
6524 ;; continued expression containing parentheses.
6525 ((null containing-begin)
6526 (vhdl-backward-syntactic-ws containing-sexp)
6527 (cond
6528 ;; CASE 3A: we are looking at the arglist closing paren
6529 ((eq char-after-ip ?\))
6530 (goto-char containing-sexp)
6531 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6532 ;; CASE 3B: we are looking at the first argument in an empty
6533 ;; argument list.
6534 ((eq char-before-ip ?\()
6535 (goto-char containing-sexp)
6536 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6537 ;; CASE 3C: we are looking at an arglist continuation line,
6538 ;; but the preceding argument is on the same line as the
6539 ;; opening paren. This case includes multi-line
6540 ;; expression paren groupings.
6541 ((and (save-excursion
6542 (goto-char (1+ containing-sexp))
6543 (skip-chars-forward " \t")
6544 (not (eolp))
6545 (not (looking-at "--")))
6546 (save-excursion
6547 (vhdl-beginning-of-statement-1 containing-sexp)
6548 (skip-chars-backward " \t(")
6549 (<= (point) containing-sexp)))
6550 (goto-char containing-sexp)
6551 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6552 ;; CASE 3D: we are looking at just a normal arglist
6553 ;; continuation line
6554 (t (vhdl-beginning-of-statement-1 containing-sexp)
6555 (vhdl-forward-syntactic-ws indent-point)
6556 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6557 ))
6558 ;; CASE 4: A block mid open
6559 ((and begin-after-ip
6560 (looking-at containing-mid))
6561 (goto-char containing-sexp)
6562 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6563 (if (looking-at vhdl-trailer-re)
6564 ;; CASE 4.1
6565 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6566 (vhdl-backward-skip-label (vhdl-point 'boi))
6567 (vhdl-add-syntax 'block-open (point)))
6568 ;; CASE 5: block close brace
6569 (end-after-ip
6570 (goto-char containing-sexp)
6571 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6572 (if (looking-at vhdl-trailer-re)
6573 ;; CASE 5.1
6574 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6575 (vhdl-backward-skip-label (vhdl-point 'boi))
6576 (vhdl-add-syntax 'block-close (point)))
6577 ;; CASE 6: A continued statement
6578 ((and (/= char-before-ip ?\;)
6579 ;; check it's not a trailer begin keyword, or a begin
6580 ;; keyword immediately following a label.
6581 (not (and begin-after-ip
6582 (or (looking-at vhdl-trailer-re)
6583 (save-excursion
6584 (vhdl-backward-skip-label containing-sexp)))))
6585 ;; check it's not a statement keyword
6586 (not (and (looking-at vhdl-statement-fwd-re)
6587 (vhdl-statement-p)))
6588 ;; see if the b-o-s is before the indent point
6589 (> indent-point
6590 (save-excursion
6591 (vhdl-beginning-of-statement-1 containing-sexp)
6592 ;; If we ended up after a leader, then this will
6593 ;; move us forward to the start of the first
6594 ;; statement. Note that a containing sexp here is
6595 ;; always a keyword, not a paren, so this will
6596 ;; have no effect if we hit the containing-sexp.
6597 (vhdl-forward-syntactic-ws indent-point)
6598 (setq placeholder (point))))
6599 ;; check it's not a block-intro
6600 (/= placeholder containing-sexp)
6601 ;; check it's not a case block-intro
6602 (save-excursion
6603 (goto-char placeholder)
6604 (or (not (looking-at vhdl-case-alternative-re))
6605 (> (match-end 0) indent-point))))
6606 ;; Make placeholder skip a label, but only if it puts us
6607 ;; before the indent point at the start of a line.
6608 (let ((new placeholder))
6609 (if (and (> indent-point
6610 (save-excursion
6611 (goto-char placeholder)
6612 (vhdl-forward-skip-label indent-point)
6613 (setq new (point))))
6614 (save-excursion
6615 (goto-char new)
6616 (eq new (progn (back-to-indentation) (point)))))
6617 (setq placeholder new)))
6618 (vhdl-add-syntax 'statement-cont placeholder)
6619 (if begin-after-ip
6620 (vhdl-add-syntax 'block-open)))
6621 ;; Statement. But what kind?
6622 ;; CASE 7: A case alternative key
6623 ((and (looking-at vhdl-case-alternative-re)
6624 (vhdl-case-alternative-p containing-sexp))
6625 ;; for a case alternative key, we set relpos to the first
6626 ;; non-whitespace char on the line containing the "case"
6627 ;; keyword.
6628 (goto-char containing-sexp)
6629 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6630 (if (looking-at vhdl-trailer-re)
6631 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6632 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6633 ;; CASE 8: statement catchall
6634 (t
6635 ;; we know its a statement, but we need to find out if it is
6636 ;; the first statement in a block
6637 (if containing-leader
6638 (goto-char containing-leader)
6639 (goto-char containing-sexp)
6640 ;; Note that a containing sexp here is always a keyword,
6641 ;; not a paren, so skip over the keyword.
6642 (forward-sexp))
6643 ;; move to the start of the first statement
6644 (vhdl-forward-syntactic-ws indent-point)
6645 (setq placeholder (point))
6646 ;; we want to ignore case alternatives keys when skipping forward
6647 (let (incase-p)
6648 (while (looking-at vhdl-case-alternative-re)
6649 (setq incase-p (point))
6650 ;; we also want to skip over the body of the
6651 ;; case/when statement if that doesn't put us at
6652 ;; after the indent-point
6653 (while (vhdl-skip-case-alternative indent-point))
6654 ;; set up the match end
6655 (looking-at vhdl-case-alternative-re)
6656 (goto-char (match-end 0))
6657 ;; move to the start of the first case alternative statement
6658 (vhdl-forward-syntactic-ws indent-point)
6659 (setq placeholder (point)))
6660 (cond
6661 ;; CASE 8A: we saw a case/when statement so we must be
6662 ;; in a switch statement. find out if we are at the
6663 ;; statement just after a case alternative key
6664 ((and incase-p
6665 (= (point) indent-point))
6666 ;; relpos is the "when" keyword
6667 (vhdl-add-syntax 'statement-case-intro incase-p))
6668 ;; CASE 8B: any old statement
6669 ((< (point) indent-point)
6670 ;; relpos is the first statement of the block
6671 (vhdl-add-syntax 'statement placeholder)
6672 (if begin-after-ip
6673 (vhdl-add-syntax 'block-open)))
6674 ;; CASE 8C: first statement in a block
6675 (t
6676 (goto-char containing-sexp)
6677 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6678 (if (looking-at vhdl-trailer-re)
6679 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6680 (vhdl-backward-skip-label (vhdl-point 'boi))
6681 (vhdl-add-syntax 'statement-block-intro (point))
6682 (if begin-after-ip
6683 (vhdl-add-syntax 'block-open)))
6684 )))
6685 )
6686
6687 ;; now we need to look at any modifiers
6688 (goto-char indent-point)
6689 (skip-chars-forward " \t")
6690 (if (looking-at "--")
6691 (vhdl-add-syntax 'comment))
6692 ;; return the syntax
6693 vhdl-syntactic-context))))
6694
6695;; Standard indentation line-ups:
6696
6697(defun vhdl-lineup-arglist (langelem)
5eabfe72
KH
6698 "Lineup the current arglist line with the arglist appearing just
6699after the containing paren which starts the arglist."
d2ddb974
KH
6700 (save-excursion
6701 (let* ((containing-sexp
6702 (save-excursion
6703 ;; arglist-cont-nonempty gives relpos ==
6704 ;; to boi of containing-sexp paren. This
6705 ;; is good when offset is +, but bad
6706 ;; when it is vhdl-lineup-arglist, so we
6707 ;; have to special case a kludge here.
6708 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6709 (progn
6710 (beginning-of-line)
6711 (backward-up-list 1)
6712 (skip-chars-forward " \t" (vhdl-point 'eol)))
6713 (goto-char (cdr langelem)))
6714 (point)))
6715 (cs-curcol (save-excursion
6716 (goto-char (cdr langelem))
6717 (current-column))))
6718 (if (save-excursion
6719 (beginning-of-line)
6720 (looking-at "[ \t]*)"))
6721 (progn (goto-char (match-end 0))
6722 (backward-sexp)
6723 (forward-char)
6724 (vhdl-forward-syntactic-ws)
6725 (- (current-column) cs-curcol))
6726 (goto-char containing-sexp)
6727 (or (eolp)
6728 (let ((eol (vhdl-point 'eol))
6729 (here (progn
6730 (forward-char)
6731 (skip-chars-forward " \t")
6732 (point))))
6733 (vhdl-forward-syntactic-ws)
6734 (if (< (point) eol)
6735 (goto-char here))))
6736 (- (current-column) cs-curcol)
6737 ))))
6738
6739(defun vhdl-lineup-arglist-intro (langelem)
5eabfe72 6740 "Lineup an arglist-intro line to just after the open paren."
d2ddb974
KH
6741 (save-excursion
6742 (let ((cs-curcol (save-excursion
6743 (goto-char (cdr langelem))
6744 (current-column)))
6745 (ce-curcol (save-excursion
6746 (beginning-of-line)
6747 (backward-up-list 1)
6748 (skip-chars-forward " \t" (vhdl-point 'eol))
6749 (current-column))))
6750 (- ce-curcol cs-curcol -1))))
6751
6752(defun vhdl-lineup-comment (langelem)
5eabfe72
KH
6753 "Support old behavior for comment indentation. We look at
6754vhdl-comment-only-line-offset to decide how to indent comment
6755only-lines."
d2ddb974
KH
6756 (save-excursion
6757 (back-to-indentation)
6758 ;; at or to the right of comment-column
6759 (if (>= (current-column) comment-column)
6760 (vhdl-comment-indent)
6761 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6762 (if (not (bolp))
6763 (or (car-safe vhdl-comment-only-line-offset)
6764 vhdl-comment-only-line-offset)
6765 (or (cdr-safe vhdl-comment-only-line-offset)
6766 (car-safe vhdl-comment-only-line-offset)
5eabfe72 6767 -1000 ;jam it against the left side
d2ddb974
KH
6768 )))))
6769
6770(defun vhdl-lineup-statement-cont (langelem)
5eabfe72 6771 "Line up statement-cont after the assignment operator."
d2ddb974
KH
6772 (save-excursion
6773 (let* ((relpos (cdr langelem))
6774 (assignp (save-excursion
6775 (goto-char (vhdl-point 'boi))
6776 (and (re-search-forward "\\(<\\|:\\)="
6777 (vhdl-point 'eol) t)
6778 (- (point) (vhdl-point 'boi)))))
6779 (curcol (progn
6780 (goto-char relpos)
6781 (current-column)))
6782 foundp)
6783 (while (and (not foundp)
6784 (< (point) (vhdl-point 'eol)))
6785 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
3dcb36b7 6786 (if (vhdl-in-literal)
d2ddb974
KH
6787 (forward-char)
6788 (if (= (preceding-char) ?\()
6789 ;; skip over any parenthesized expressions
6790 (goto-char (min (vhdl-point 'eol)
6791 (scan-lists (point) 1 1)))
6792 ;; found an assignment operator (not at eol)
6793 (setq foundp (not (looking-at "\\s-*$"))))))
6794 (if (not foundp)
6795 ;; there's no assignment operator on the line
6796 vhdl-basic-offset
6797 ;; calculate indentation column after assign and ws, unless
6798 ;; our line contains an assignment operator
6799 (if (not assignp)
6800 (progn
6801 (forward-char)
6802 (skip-chars-forward " \t")
6803 (setq assignp 0)))
6804 (- (current-column) assignp curcol))
6805 )))
6806
5eabfe72 6807;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 6808;; Progress reporting
d2ddb974 6809
3dcb36b7
JB
6810(defvar vhdl-progress-info nil
6811 "Array variable for progress information: 0 begin, 1 end, 2 time.")
5eabfe72 6812
3dcb36b7
JB
6813(defun vhdl-update-progress-info (string pos)
6814 "Update progress information."
6815 (when (and vhdl-progress-info (not noninteractive)
6816 (< vhdl-progress-interval
6817 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6818 (message (concat string "... (%2d%s)")
6819 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6820 (- (aref vhdl-progress-info 1)
6821 (aref vhdl-progress-info 0))) "%")
6822 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
5eabfe72 6823
3dcb36b7
JB
6824;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6825;; Indentation commands
5eabfe72
KH
6826
6827(defun vhdl-electric-tab (&optional prefix-arg)
6828 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7
JB
6829else if right of non whitespace on line then insert tab,
6830else if last command was a tab or return then dedent one step or if a comment
6831toggle between normal indent and inline comment indent,
d2ddb974
KH
6832else indent `correctly'."
6833 (interactive "*P")
3dcb36b7
JB
6834 (vhdl-prepare-search-2
6835 (cond
6836 ;; expand word
6837 ((= (char-syntax (preceding-char)) ?w)
6838 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6839 (case-replace nil)
6840 (hippie-expand-only-buffers
6841 (or (and (boundp 'hippie-expand-only-buffers)
6842 hippie-expand-only-buffers)
6843 '(vhdl-mode))))
6844 (vhdl-expand-abbrev prefix-arg)))
6845 ;; expand parenthesis
6846 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6847 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6848 (case-replace nil))
6849 (vhdl-expand-paren prefix-arg)))
6850 ;; insert tab
6851 ((> (current-column) (current-indentation))
6852 (insert-tab))
6853 ;; toggle comment indent
6854 ((and (looking-at "--")
6855 (or (eq last-command 'vhdl-electric-tab)
6856 (eq last-command 'vhdl-electric-return)))
6857 (cond ((= (current-indentation) 0) ; no indent
6858 (indent-to 1)
6859 (indent-according-to-mode))
6860 ((< (current-indentation) comment-column) ; normal indent
6861 (indent-to comment-column)
6862 (indent-according-to-mode))
6863 (t ; inline comment indent
6864 (kill-line -0))))
6865 ;; dedent
6866 ((and (>= (current-indentation) vhdl-basic-offset)
6867 (or (eq last-command 'vhdl-electric-tab)
6868 (eq last-command 'vhdl-electric-return)))
6869 (backward-delete-char-untabify vhdl-basic-offset nil))
6870 ;; indent line
6871 (t (indent-according-to-mode)))
5eabfe72
KH
6872 (setq this-command 'vhdl-electric-tab)))
6873
6874(defun vhdl-electric-return ()
d2ddb974
KH
6875 "newline-and-indent or indent-new-comment-line if in comment and preceding
6876character is a space."
6877 (interactive)
6878 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
6879 (indent-new-comment-line)
3dcb36b7
JB
6880 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
6881 (vhdl-fix-case-word -1))
5eabfe72
KH
6882 (newline-and-indent)))
6883
d2ddb974 6884(defun vhdl-indent-line ()
5eabfe72 6885 "Indent the current line as VHDL code. Returns the amount of
d2ddb974
KH
6886indentation change."
6887 (interactive)
3dcb36b7 6888 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
d2ddb974 6889 (pos (- (point-max) (point)))
3dcb36b7
JB
6890 (indent
6891 (if syntax
6892 ;; indent syntax-based
6893 (if (and (eq (caar syntax) 'comment)
6894 (>= (vhdl-get-offset (car syntax)) comment-column))
6895 ;; special case: comments at or right of comment-column
6896 (vhdl-get-offset (car syntax))
6897 (apply '+ (mapcar 'vhdl-get-offset syntax)))
6898 ;; indent like previous nonblank line
6899 (save-excursion (beginning-of-line)
6900 (re-search-backward "^[^\n]" nil t)
6901 (current-indentation))))
5eabfe72 6902 (shift-amt (- indent (current-indentation))))
d2ddb974
KH
6903 (and vhdl-echo-syntactic-information-p
6904 (message "syntax: %s, indent= %d" syntax indent))
5eabfe72 6905 (unless (zerop shift-amt)
d2ddb974
KH
6906 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
6907 (beginning-of-line)
6908 (indent-to indent))
6909 (if (< (point) (vhdl-point 'boi))
6910 (back-to-indentation)
6911 ;; If initial point was within line's indentation, position after
6912 ;; the indentation. Else stay at same point in text.
5eabfe72
KH
6913 (when (> (- (point-max) pos) (point))
6914 (goto-char (- (point-max) pos))))
d2ddb974 6915 (run-hooks 'vhdl-special-indent-hook)
3dcb36b7 6916 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
d2ddb974
KH
6917 shift-amt))
6918
3dcb36b7 6919(defun vhdl-indent-region (beg end column)
5eabfe72
KH
6920 "Indent region as VHDL code.
6921Adds progress reporting to `indent-region'."
6922 (interactive "r\nP")
3dcb36b7
JB
6923 (when vhdl-progress-interval
6924 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
6925 (count-lines (point-min) end) 0)))
6926 (indent-region beg end column)
5eabfe72
KH
6927 (when vhdl-progress-interval (message "Indenting...done"))
6928 (setq vhdl-progress-info nil))
d2ddb974 6929
3dcb36b7
JB
6930(defun vhdl-indent-buffer ()
6931 "Indent whole buffer as VHDL code.
6932Calls `indent-region' for whole buffer and adds progress reporting."
6933 (interactive)
6934 (vhdl-indent-region (point-min) (point-max) nil))
6935
6936(defun vhdl-indent-group ()
6937 "Indent group of lines between empty lines."
6938 (interactive)
6939 (let ((beg (save-excursion
6940 (if (re-search-backward vhdl-align-group-separate nil t)
6941 (point-marker)
6942 (point-min-marker))))
6943 (end (save-excursion
6944 (if (re-search-forward vhdl-align-group-separate nil t)
6945 (point-marker)
6946 (point-max-marker)))))
6947 (vhdl-indent-region beg end nil)))
6948
d2ddb974
KH
6949(defun vhdl-indent-sexp (&optional endpos)
6950 "Indent each line of the list starting just after point.
6951If optional arg ENDPOS is given, indent each line, stopping when
6952ENDPOS is encountered."
6953 (interactive)
6954 (save-excursion
6955 (let ((beg (point))
5eabfe72 6956 (end (progn (vhdl-forward-sexp nil endpos) (point))))
d2ddb974
KH
6957 (indent-region beg end nil))))
6958
5eabfe72 6959;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
6960;; Miscellaneous commands
6961
6962(defun vhdl-show-syntactic-information ()
6963 "Show syntactic information for current line."
6964 (interactive)
3dcb36b7 6965 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
d2ddb974
KH
6966 (vhdl-keep-region-active))
6967
6968;; Verification and regression functions:
6969
6970(defun vhdl-regress-line (&optional arg)
6971 "Check syntactic information for current line."
6972 (interactive "P")
6973 (let ((expected (save-excursion
6974 (end-of-line)
5eabfe72
KH
6975 (when (search-backward " -- ((" (vhdl-point 'bol) t)
6976 (forward-char 4)
6977 (read (current-buffer)))))
d2ddb974
KH
6978 (actual (vhdl-get-syntactic-context))
6979 (expurgated))
6980 ;; remove the library unit symbols
6981 (mapcar
6982 (function
6983 (lambda (elt)
6984 (if (memq (car elt) '(entity configuration package
6985 package-body architecture))
6986 nil
6987 (setq expurgated (append expurgated (list elt))))))
6988 actual)
6989 (if (and (not arg) expected (listp expected))
6990 (if (not (equal expected expurgated))
3dcb36b7 6991 (error "ERROR: Should be: %s, is: %s" expected expurgated))
d2ddb974
KH
6992 (save-excursion
6993 (beginning-of-line)
5eabfe72
KH
6994 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
6995 (end-of-line)
6996 (if (search-backward " -- ((" (vhdl-point 'bol) t)
6997 (kill-line))
6998 (insert " -- ")
6999 (insert (format "%s" expurgated))))))
d2ddb974
KH
7000 (vhdl-keep-region-active))
7001
7002
5eabfe72
KH
7003;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7004;;; Alignment, whitespace fixup, beautifying
7005;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7006
3dcb36b7 7007(defconst vhdl-align-alist
d2ddb974
KH
7008 '(
7009 ;; after some keywords
3dcb36b7
JB
7010 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7011 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
d2ddb974 7012 ;; before ':'
5eabfe72 7013 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
d2ddb974 7014 ;; after direction specifications
5eabfe72
KH
7015 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7016 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7017 ;; before "==", ":=", "=>", and "<="
3dcb36b7 7018 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
5eabfe72 7019 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
3dcb36b7 7020 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
d2ddb974
KH
7021 ;; before some keywords
7022 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
d2ddb974
KH
7023 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7024 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
3dcb36b7
JB
7025 ;; before "=>" since "when/else ... =>" can occur
7026 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
d2ddb974 7027 )
5eabfe72 7028 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
d2ddb974
KH
7029It is searched in order. If REGEXP is found anywhere in the first
7030line of a region to be aligned, ALIGN-PATTERN will be used for that
7031region. ALIGN-PATTERN must include the whitespace to be expanded or
5eabfe72
KH
7032contracted. It may also provide regexps for the text surrounding the
7033whitespace. SUBEXP specifies which sub-expression of
d2ddb974
KH
7034ALIGN-PATTERN matches the white space to be expanded/contracted.")
7035
3dcb36b7
JB
7036;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7037;; Align code
7038
d2ddb974
KH
7039(defvar vhdl-align-try-all-clauses t
7040 "If REGEXP is not found on the first line of the region that clause
5eabfe72 7041is ignored. If this variable is non-nil, then the clause is tried anyway.")
d2ddb974 7042
3dcb36b7
JB
7043(defun vhdl-do-group (function &optional spacing)
7044 "Apply FUNCTION on group of lines between empty lines."
7045 (let
7046 ;; search for group beginning
7047 ((beg (save-excursion
7048 (if (re-search-backward vhdl-align-group-separate nil t)
7049 (progn (beginning-of-line 2) (back-to-indentation) (point))
7050 (point-min))))
7051 ;; search for group end
7052 (end (save-excursion
7053 (if (re-search-forward vhdl-align-group-separate nil t)
7054 (progn (beginning-of-line) (point))
7055 (point-max)))))
7056 ;; run FUNCTION
7057 (funcall function beg end spacing)))
7058
7059(defun vhdl-do-list (function &optional spacing)
7060 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7061parentheses."
7062 (let (beg end)
7063 (save-excursion
7064 ;; search for beginning of balanced group of parentheses
7065 (setq beg (vhdl-re-search-backward "[()]" nil t))
7066 (while (looking-at ")")
7067 (forward-char) (backward-sexp)
7068 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7069 ;; search for end of balanced group of parentheses
7070 (when beg
7071 (forward-list)
7072 (setq end (point))
7073 (goto-char (1+ beg))
7074 (skip-chars-forward " \t\n")
7075 (setq beg (point))))
7076 ;; run FUNCTION
7077 (if beg
7078 (funcall function beg end spacing)
7079 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7080
7081(defun vhdl-do-same-indent (function &optional spacing)
7082 "Apply FUNCTION to block of lines with same indent."
7083 (let ((indent (current-indentation))
7084 beg end)
7085 ;; search for first line with same indent
7086 (save-excursion
7087 (while (and (not (bobp))
7088 (or (looking-at "^\\s-*\\(--.*\\)?$")
7089 (= (current-indentation) indent)))
7090 (unless (looking-at "^\\s-*$")
7091 (back-to-indentation) (setq beg (point)))
7092 (beginning-of-line -0)))
7093 ;; search for last line with same indent
7094 (save-excursion
7095 (while (and (not (eobp))
7096 (or (looking-at "^\\s-*\\(--.*\\)?$")
7097 (= (current-indentation) indent)))
7098 (if (looking-at "^\\s-*$")
7099 (beginning-of-line 2)
7100 (beginning-of-line 2)
7101 (setq end (point)))))
7102 ;; run FUNCTION
7103 (funcall function beg end spacing)))
7104
7105(defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
d2ddb974 7106 "Attempt to align a range of lines based on the content of the
5eabfe72
KH
7107lines. The definition of `alignment-list' determines the matching
7108order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7109is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
d2ddb974
KH
7110indentation is done before aligning."
7111 (interactive "r\np")
5eabfe72
KH
7112 (setq alignment-list (or alignment-list vhdl-align-alist))
7113 (setq spacing (or spacing 1))
d2ddb974
KH
7114 (save-excursion
7115 (let (bol indent)
7116 (goto-char end)
7117 (setq end (point-marker))
7118 (goto-char begin)
5eabfe72 7119 (setq bol (setq begin (progn (beginning-of-line) (point))))
3dcb36b7 7120; (untabify bol end)
5eabfe72
KH
7121 (when indent
7122 (indent-region bol end nil))))
3dcb36b7
JB
7123 (let ((copy (copy-alist alignment-list)))
7124 (vhdl-prepare-search-2
5eabfe72
KH
7125 (while copy
7126 (save-excursion
7127 (goto-char begin)
7128 (let (element
7129 (eol (save-excursion (progn (end-of-line) (point)))))
7130 (setq element (nth 0 copy))
7131 (when (and (or (and (listp (car element))
7132 (memq major-mode (car element)))
7133 (eq major-mode (car element)))
7134 (or vhdl-align-try-all-clauses
7135 (re-search-forward (car (cdr element)) eol t)))
3dcb36b7 7136 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
5eabfe72
KH
7137 (car (cdr (cdr (cdr element)))) spacing))
7138 (setq copy (cdr copy))))))))
7139
3dcb36b7 7140(defun vhdl-align-region-2 (begin end match &optional substr spacing)
d2ddb974
KH
7141 "Align a range of lines from BEGIN to END. The regular expression
7142MATCH must match exactly one fields: the whitespace to be
7143contracted/expanded. The alignment column will equal the
7144rightmost column of the widest whitespace block. SPACING is
7145the amount of extra spaces to add to the calculated maximum required.
7146SPACING defaults to 1 so that at least one space is inserted after
7147the token in MATCH."
5eabfe72
KH
7148 (setq spacing (or spacing 1))
7149 (setq substr (or substr 1))
d2ddb974
KH
7150 (save-excursion
7151 (let (distance (max 0) (lines 0) bol eol width)
7152 ;; Determine the greatest whitespace distance to the alignment
7153 ;; character
7154 (goto-char begin)
7155 (setq eol (progn (end-of-line) (point))
5eabfe72 7156 bol (setq begin (progn (beginning-of-line) (point))))
d2ddb974 7157 (while (< bol end)
5eabfe72
KH
7158 (save-excursion
7159 (when (and (re-search-forward match eol t)
3dcb36b7 7160 (not (vhdl-in-literal)))
5eabfe72
KH
7161 (setq distance (- (match-beginning substr) bol))
7162 (when (> distance max)
7163 (setq max distance))))
7164 (forward-line)
7165 (setq bol (point)
7166 eol (save-excursion (end-of-line) (point)))
7167 (setq lines (1+ lines)))
d2ddb974
KH
7168 ;; Now insert enough maxs to push each assignment operator to
7169 ;; the same column. We need to use 'lines' as a counter, since
7170 ;; the location of the mark may change
7171 (goto-char (setq bol begin))
5eabfe72 7172 (setq eol (save-excursion (end-of-line) (point)))
d2ddb974 7173 (while (> lines 0)
5eabfe72 7174 (when (and (re-search-forward match eol t)
3dcb36b7 7175 (not (vhdl-in-literal)))
5eabfe72
KH
7176 (setq width (- (match-end substr) (match-beginning substr)))
7177 (setq distance (- (match-beginning substr) bol))
7178 (goto-char (match-beginning substr))
7179 (delete-char width)
7180 (insert-char ? (+ (- max distance) spacing)))
7181 (beginning-of-line)
7182 (forward-line)
7183 (setq bol (point)
7184 eol (save-excursion (end-of-line) (point)))
7185 (setq lines (1- lines))))))
7186
3dcb36b7
JB
7187(defun vhdl-align-region-groups (beg end &optional spacing
7188 no-message no-comments)
7189 "Align region, treat groups of lines separately."
d2ddb974 7190 (interactive "r\nP")
5eabfe72 7191 (save-excursion
3dcb36b7 7192 (let (orig pos)
5eabfe72
KH
7193 (goto-char beg)
7194 (beginning-of-line)
3dcb36b7 7195 (setq orig (point-marker))
5eabfe72
KH
7196 (setq beg (point))
7197 (goto-char end)
7198 (setq end (point-marker))
7199 (untabify beg end)
3dcb36b7
JB
7200 (unless no-message
7201 (when vhdl-progress-interval
7202 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7203 (count-lines (point-min) end) 0))))
5eabfe72
KH
7204 (vhdl-fixup-whitespace-region beg end t)
7205 (goto-char beg)
7206 (if (not vhdl-align-groups)
7207 ;; align entire region
3dcb36b7
JB
7208 (progn (vhdl-align-region-1 beg end spacing)
7209 (unless no-comments
7210 (vhdl-align-inline-comment-region-1 beg end)))
5eabfe72
KH
7211 ;; align groups
7212 (while (and (< beg end)
3dcb36b7 7213 (re-search-forward vhdl-align-group-separate end t))
5eabfe72 7214 (setq pos (point-marker))
3dcb36b7
JB
7215 (vhdl-align-region-1 beg pos spacing)
7216 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7217 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
5eabfe72
KH
7218 (setq beg (1+ pos))
7219 (goto-char beg))
7220 ;; align last group
7221 (when (< beg end)
3dcb36b7
JB
7222 (vhdl-align-region-1 beg end spacing)
7223 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7224 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7225 (when vhdl-indent-tabs-mode
7226 (tabify orig end))
7227 (unless no-message
7228 (when vhdl-progress-interval (message "Aligning...done"))
7229 (setq vhdl-progress-info nil)))))
7230
7231(defun vhdl-align-region (beg end &optional spacing)
7232 "Align region, treat blocks with same indent and argument lists separately."
7233 (interactive "r\nP")
7234 (if (not vhdl-align-same-indent)
7235 ;; align entire region
7236 (vhdl-align-region-groups beg end spacing)
7237 ;; align blocks with same indent and argument lists
7238 (save-excursion
7239 (let ((cur-beg beg)
7240 indent cur-end)
7241 (when vhdl-progress-interval
7242 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7243 (count-lines (point-min) end) 0)))
7244 (goto-char end)
7245 (setq end (point-marker))
7246 (goto-char cur-beg)
7247 (while (< (point) end)
7248 ;; is argument list opening?
7249 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7250 (point) (vhdl-point 'eol)))))
7251 ;; determine region for argument list
7252 (progn (goto-char cur-beg)
7253 (forward-sexp)
7254 (setq cur-end (point))
7255 (beginning-of-line 2))
7256 ;; determine region with same indent
7257 (setq indent (current-indentation))
7258 (setq cur-beg (point))
7259 (setq cur-end (vhdl-point 'bonl))
7260 (beginning-of-line 2)
7261 (while (and (< (point) end)
7262 (or (looking-at "^\\s-*\\(--.*\\)?$")
7263 (= (current-indentation) indent))
7264 (<= (save-excursion
7265 (nth 0 (parse-partial-sexp
7266 (point) (vhdl-point 'eol)))) 0))
7267 (unless (looking-at "^\\s-*$")
7268 (setq cur-end (vhdl-point 'bonl)))
7269 (beginning-of-line 2)))
7270 ;; align region
7271 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7272 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7273 (when vhdl-progress-interval (message "Aligning...done"))
7274 (setq vhdl-progress-info nil)))))
5eabfe72
KH
7275
7276(defun vhdl-align-group (&optional spacing)
7277 "Align group of lines between empty lines."
7278 (interactive)
3dcb36b7 7279 (vhdl-do-group 'vhdl-align-region spacing))
5eabfe72 7280
3dcb36b7
JB
7281(defun vhdl-align-list (&optional spacing)
7282 "Align the lines of a list surrounded by a balanced group of parentheses."
5eabfe72 7283 (interactive)
3dcb36b7
JB
7284 (vhdl-do-list 'vhdl-align-region-groups spacing))
7285
7286(defun vhdl-align-same-indent (&optional spacing)
7287 "Align block of lines with same indent."
7288 (interactive)
7289 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7290
7291(defun vhdl-align-declarations (&optional spacing)
7292 "Align the lines within the declarative part of a design unit."
7293 (interactive)
7294 (let (beg end)
7295 (vhdl-prepare-search-2
7296 (save-excursion
7297 ;; search for declarative part
7298 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7299 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7300 (setq beg (point))
7301 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7302 (setq end (point)))))
7303 (if beg
7304 (vhdl-align-region-groups beg end spacing)
7305 (error "ERROR: Not within the declarative part of a design unit"))))
7306
7307(defun vhdl-align-buffer ()
7308 "Align buffer."
7309 (interactive)
7310 (vhdl-align-region (point-min) (point-max)))
7311
7312;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7313;; Align inline comments
7314
7315(defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7316 "Align inline comments in region."
7317 (save-excursion
7318 (let ((start-max comment-column)
7319 (length-max 0)
7320 comment-list start-list tmp-list start length
7321 cur-start prev-start no-code)
7322 (setq spacing (or spacing 2))
7323 (vhdl-prepare-search-2
7324 (goto-char beg)
7325 ;; search for comment start positions and lengths
7326 (while (< (point) end)
7327 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7328 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7329 (not (save-excursion (goto-char (match-beginning 2))
7330 (vhdl-in-literal))))
7331 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7332 (setq length (- (match-end 2) (match-beginning 2)))
7333 (setq start-max (max start start-max))
7334 (setq length-max (max length length-max))
7335 (setq comment-list (cons (cons start length) comment-list)))
7336 (beginning-of-line 2))
7337 (setq comment-list
7338 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7339 ;; reduce start positions
7340 (setq start-list (list (caar comment-list)))
7341 (setq comment-list (cdr comment-list))
7342 (while comment-list
7343 (unless (or (= (caar comment-list) (car start-list))
7344 (<= (+ (car start-list) (cdar comment-list))
7345 end-comment-column))
7346 (setq start-list (cons (caar comment-list) start-list)))
7347 (setq comment-list (cdr comment-list)))
7348 ;; align lines as nicely as possible
7349 (goto-char beg)
7350 (while (< (point) end)
7351 (setq cur-start nil)
7352 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7353 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7354 (not (save-excursion
7355 (goto-char (match-beginning 3))
7356 (vhdl-in-literal))))
7357 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7358 (>= (- (match-end 2) (match-beginning 2))
7359 comment-column))))
7360 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7361 (setq length (- (match-end 3) (match-beginning 3)))
7362 (setq no-code (= (match-beginning 1) (match-end 1)))
7363 ;; insert minimum whitespace
7364 (goto-char (match-end 2))
7365 (delete-region (match-beginning 2) (match-end 2))
7366 (insert-char ?\ spacing)
7367 (setq tmp-list start-list)
7368 ;; insert additional whitespace to align
7369 (setq cur-start
7370 (cond
7371 ;; align comment-only line to inline comment of previous line
7372 ((and no-code prev-start
7373 (<= length (- end-comment-column prev-start)))
7374 prev-start)
7375 ;; align all comments at `start-max' if this is possible
7376 ((<= (+ start-max length-max) end-comment-column)
7377 start-max)
7378 ;; align at `comment-column' if possible
7379 ((and (<= start comment-column)
7380 (<= length (- end-comment-column comment-column)))
7381 comment-column)
7382 ;; align at left-most possible start position otherwise
7383 (t
7384 (while (and tmp-list (< (car tmp-list) start))
7385 (setq tmp-list (cdr tmp-list)))
7386 (car tmp-list))))
7387 (indent-to cur-start))
7388 (setq prev-start cur-start)
7389 (beginning-of-line 2))))))
d2ddb974 7390
5eabfe72
KH
7391(defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7392 "Align inline comments within a region. Groups of code lines separated by
7393empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
d2ddb974 7394 (interactive "r\nP")
5eabfe72 7395 (save-excursion
3dcb36b7 7396 (let (orig pos)
5eabfe72
KH
7397 (goto-char beg)
7398 (beginning-of-line)
3dcb36b7 7399 (setq orig (point-marker))
5eabfe72
KH
7400 (setq beg (point))
7401 (goto-char end)
7402 (setq end (point-marker))
7403 (untabify beg end)
7404 (unless no-message (message "Aligning inline comments..."))
7405 (goto-char beg)
7406 (if (not vhdl-align-groups)
7407 ;; align entire region
7408 (vhdl-align-inline-comment-region-1 beg end spacing)
7409 ;; align groups
3dcb36b7
JB
7410 (while (and (< beg end)
7411 (re-search-forward vhdl-align-group-separate end t))
5eabfe72
KH
7412 (setq pos (point-marker))
7413 (vhdl-align-inline-comment-region-1 beg pos spacing)
7414 (setq beg (1+ pos))
7415 (goto-char beg))
7416 ;; align last group
7417 (when (< beg end)
3dcb36b7
JB
7418 (vhdl-align-inline-comment-region-1 beg end spacing)))
7419 (when vhdl-indent-tabs-mode
7420 (tabify orig end))
7421 (unless no-message (message "Aligning inline comments...done")))))
5eabfe72
KH
7422
7423(defun vhdl-align-inline-comment-group (&optional spacing)
7424 "Align inline comments within a group of lines between empty lines."
7425 (interactive)
7426 (save-excursion
7427 (let ((start (point))
7428 beg end)
3dcb36b7 7429 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
5eabfe72
KH
7430 (point-marker) (point-max)))
7431 (goto-char start)
3dcb36b7
JB
7432 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7433 (point) (point-min)))
5eabfe72
KH
7434 (untabify beg end)
7435 (message "Aligning inline comments...")
7436 (vhdl-align-inline-comment-region-1 beg end)
3dcb36b7
JB
7437 (when vhdl-indent-tabs-mode
7438 (tabify beg end))
5eabfe72
KH
7439 (message "Aligning inline comments...done"))))
7440
7441(defun vhdl-align-inline-comment-buffer ()
7442 "Align inline comments within buffer. Groups of code lines separated by
7443empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7444 (interactive)
7445 (vhdl-align-inline-comment-region (point-min) (point-max)))
7446
3dcb36b7
JB
7447;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7448;; Fixup whitespace
7449
5eabfe72
KH
7450(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7451 "Fixup whitespace in region. Surround operator symbols by one space,
7452eliminate multiple spaces (except at beginning of line), eliminate spaces at
3dcb36b7 7453end of line, do nothing in comments and strings."
5eabfe72
KH
7454 (interactive "r")
7455 (unless no-message (message "Fixing up whitespace..."))
7456 (save-excursion
7457 (goto-char end)
7458 (setq end (point-marker))
5eabfe72
KH
7459 ;; have no space before and one space after `,' and ';'
7460 (goto-char beg)
3dcb36b7
JB
7461 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7462 (if (match-string 1)
7463 (goto-char (match-end 1))
7464 (replace-match "\\3 " nil nil nil 3)))
7465 ;; have no space after `('
7466 (goto-char beg)
7467 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\((\\)\\s-+" end t)
7468 (if (match-string 1)
7469 (goto-char (match-end 1))
7470 (replace-match "\\2")))
7471 ;; have no space before `)'
7472 (goto-char beg)
7473 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7474 (if (match-string 1)
7475 (goto-char (match-end 1))
7476 (replace-match "\\2")))
7477 ;; surround operator symbols by one space
7478 (goto-char beg)
7479 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7480 (if (match-string 1)
7481 (goto-char (match-end 1))
7482 (replace-match "\\3 \\4 \\5")
7483 (goto-char (match-end 4))))
5eabfe72
KH
7484 ;; eliminate multiple spaces and spaces at end of line
7485 (goto-char beg)
7486 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
3dcb36b7 7487 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
5eabfe72
KH
7488 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7489 (progn (replace-match "" nil nil) t))
7490 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7491 (progn (replace-match ";" nil nil) t))
7492 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7493 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
3dcb36b7 7494 (progn (replace-match " " nil nil) t))
5eabfe72 7495 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
3dcb36b7
JB
7496 (progn (replace-match " " nil nil) t))
7497 (re-search-forward "[^ \t-]+" end t))))
5eabfe72
KH
7498 (unless no-message (message "Fixing up whitespace...done")))
7499
7500(defun vhdl-fixup-whitespace-buffer ()
7501 "Fixup whitespace in buffer. Surround operator symbols by one space,
7502eliminate multiple spaces (except at beginning of line), eliminate spaces at
7503end of line, do nothing in comments."
7504 (interactive)
7505 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7506
3dcb36b7
JB
7507;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7508;; Beautify
7509
5eabfe72
KH
7510(defun vhdl-beautify-region (beg end)
7511 "Beautify region by applying indentation, whitespace fixup, alignment, and
3dcb36b7
JB
7512case fixing to a region. Calls functions `vhdl-indent-buffer',
7513`vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
5eabfe72
KH
7514`vhdl-fix-case-buffer'."
7515 (interactive "r")
3dcb36b7 7516 (setq end (save-excursion (goto-char end) (point-marker)))
5eabfe72
KH
7517 (vhdl-indent-region beg end nil)
7518 (let ((vhdl-align-groups t))
3dcb36b7 7519 (vhdl-align-region beg end))
5eabfe72
KH
7520 (vhdl-fix-case-region beg end))
7521
7522(defun vhdl-beautify-buffer ()
7523 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7524case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7525buffer."
7526 (interactive)
3dcb36b7
JB
7527 (vhdl-beautify-region (point-min) (point-max))
7528 (when noninteractive (save-buffer)))
7529
7530;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7531;; Code filling
7532
7533(defun vhdl-fill-region (beg end &optional arg)
7534 "Fill lines for a region of code."
8d422bd5 7535 (interactive "r\np")
3dcb36b7
JB
7536 (save-excursion
7537 (goto-char beg)
8d422bd5 7538 (let ((margin (if interactive (current-indentation) (current-column))))
3dcb36b7
JB
7539 (goto-char end)
7540 (setq end (point-marker))
7541 ;; remove inline comments, newlines and whitespace
7542 (vhdl-comment-kill-region beg end)
7543 (vhdl-comment-kill-inline-region beg end)
7544 (subst-char-in-region beg (1- end) ?\n ?\ )
7545 (vhdl-fixup-whitespace-region beg end)
7546 ;; wrap and end-comment-column
7547 (goto-char beg)
7548 (while (re-search-forward "\\s-" end t)
7549 (when(> (current-column) vhdl-end-comment-column)
7550 (backward-char)
7551 (when (re-search-backward "\\s-" beg t)
7552 (replace-match "\n")
7553 (indent-to margin)))))))
7554
7555(defun vhdl-fill-group ()
7556 "Fill group of lines between empty lines."
7557 (interactive)
7558 (vhdl-do-group 'vhdl-fill-region))
7559
7560(defun vhdl-fill-list ()
7561 "Fill the lines of a list surrounded by a balanced group of parentheses."
7562 (interactive)
7563 (vhdl-do-list 'vhdl-fill-region))
7564
7565(defun vhdl-fill-same-indent ()
7566 "Fill the lines of block of lines with same indent."
7567 (interactive)
7568 (vhdl-do-same-indent 'vhdl-fill-region))
7569
7570
7571;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7572;;; Code updating/fixing
7573;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7574
7575;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7576;; Sensitivity list update
7577
7578;; Strategy:
7579;; - no sensitivity list is generated for processes with wait statements
7580;; - otherwise, do the following:
7581;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7582;; 2. scan for all signals already in the sensitivity list (in order to catch
7583;; manually entered global signals)
7584;; 3. signals from 1. and 2. form the list of visible signals
7585;; 4. search for if/elsif conditions containing an event (sequential code)
7586;; 5. scan for strings that are within syntactical regions where signals are
7587;; read but not within sequential code, and that correspond to visible
7588;; signals
7589;; 6. replace sensitivity list by list of signals from 5.
7590
7591(defun vhdl-update-sensitivity-list-process ()
7592 "Update sensitivity list of current process."
7593 (interactive)
7594 (save-excursion
7595 (vhdl-prepare-search-2
7596 (end-of-line)
7597 ;; look whether in process
7598 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7599 (equal (upcase (match-string 2)) "PROCESS")
7600 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7601 (error "ERROR: Not within a process")
7602 (message "Updating sensitivity list...")
7603 (vhdl-update-sensitivity-list)
7604 (message "Updating sensitivity list...done")))))
7605
7606(defun vhdl-update-sensitivity-list-buffer ()
7607 "Update sensitivity list of all processes in current buffer."
7608 (interactive)
7609 (save-excursion
7610 (vhdl-prepare-search-2
7611 (goto-char (point-min))
7612 (message "Updating sensitivity lists...")
7613 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7614 (goto-char (match-beginning 0))
7615 (condition-case nil (vhdl-update-sensitivity-list) (error)))
7616 (message "Updating sensitivity lists...done"))))
7617
7618(defun vhdl-update-sensitivity-list ()
7619 "Update sensitivity list."
7620 (let ((proc-beg (point))
7621 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7622 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7623 seq-region-list)
7624 (cond
7625 ;; search for wait statement (no sensitivity list allowed)
7626 ((progn (goto-char proc-mid)
7627 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7628 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7629 ;; combinational process (update sensitivity list)
7630 (t
7631 (let
7632 ;; scan for visible signals
7633 ((visible-list (vhdl-get-visible-signals))
7634 ;; define syntactic regions where signals are read
7635 (scan-regions-list
7636 '(;; right-hand side of signal/variable assignment
7637 ;; (special case: "<=" is relational operator in a condition)
7638 ((re-search-forward "[<:]=" proc-end t)
7639 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7640 ;; if condition
7641 ((re-search-forward "^\\s-*if\\>" proc-end t)
7642 (re-search-forward "\\<then\\>" proc-end t))
7643 ;; elsif condition
7644 ((re-search-forward "\\<elsif\\>" proc-end t)
7645 (re-search-forward "\\<then\\>" proc-end t))
7646 ;; while loop condition
7647 ((re-search-forward "^\\s-*while\\>" proc-end t)
7648 (re-search-forward "\\<loop\\>" proc-end t))
7649 ;; exit/next condition
7650 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7651 (re-search-forward ";" proc-end t))
7652 ;; assert condition
7653 ((re-search-forward "\\<assert\\>" proc-end t)
7654 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7655 ;; case expression
7656 ((re-search-forward "^\\s-*case\\>" proc-end t)
7657 (re-search-forward "\\<is\\>" proc-end t))
7658 ;; parameter list of procedure call
7659 ((re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7660 (progn (backward-char) (forward-sexp) (point)))))
7661 name read-list sens-list signal-list
7662 sens-beg sens-end beg end margin)
7663 ;; scan for signals in old sensitivity list
7664 (goto-char proc-beg)
7665 (re-search-forward "\\<process\\>" proc-mid t)
7666 (if (not (looking-at "[ \t\n]*("))
7667 (setq sens-beg (point))
7668 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7669 (goto-char (match-end 1))
7670 (forward-sexp)
7671 (setq sens-end (1- (point)))
7672 (goto-char sens-beg)
7673 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7674 (setq sens-list
7675 (cons (downcase (match-string 0)) sens-list))
7676 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7677 (setq signal-list (append visible-list sens-list))
7678 ;; search for sequential parts
7679 (goto-char proc-mid)
7680 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7681 (setq end (re-search-forward "\\<then\\>" proc-end t))
7682 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7683 (goto-char end)
7684 (backward-word 1)
7685 (vhdl-forward-sexp)
7686 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7687 (beginning-of-line)))
7688 ;; scan for signals read in process
7689 (while scan-regions-list
7690 (goto-char proc-mid)
7691 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7692 (setq end (eval (nth 1 (car scan-regions-list)))))
7693 (goto-char beg)
7694 (unless (or (vhdl-in-literal)
7695 (and seq-region-list
7696 (let ((tmp-list seq-region-list))
7697 (while (and tmp-list
7698 (< (point) (caar tmp-list)))
7699 (setq tmp-list (cdr tmp-list)))
7700 (and tmp-list (< (point) (cdar tmp-list))))))
7701 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>" end t)
7702 (setq name (match-string 1))
7703 (when (member (downcase name) signal-list)
7704 (add-to-list 'read-list name)))))
7705 (setq scan-regions-list (cdr scan-regions-list)))
7706 ;; update sensitivity list
7707 (goto-char sens-beg)
7708 (if sens-end
7709 (delete-region sens-beg sens-end)
7710 (when read-list
7711 (insert " ()") (backward-char)))
7712 (setq read-list (sort read-list 'string<))
7713 (when read-list
7714 (setq margin (current-column))
7715 (insert (car read-list))
7716 (setq read-list (cdr read-list))
7717 (while read-list
7718 (insert ",")
7719 (if (<= (+ (current-column) (length (car read-list)) 2)
7720 end-comment-column)
7721 (insert " ")
7722 (insert "\n") (indent-to margin))
7723 (insert (car read-list))
7724 (setq read-list (cdr read-list)))))))))
7725
7726(defun vhdl-get-visible-signals ()
7727 "Get all signals visible in the current block."
7728 (save-excursion
7729 (let (beg end signal-list entity-name file-name)
7730 ;; search for signals declared in surrounding block declarative parts
7731 (save-excursion
7732 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7733 (match-string 2))
7734 (goto-char (match-end 2))
7735 (vhdl-backward-sexp)
7736 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7737 beg)
7738 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7739 ;; scan for all declared signal names
7740 (goto-char beg)
7741 (while (re-search-forward "^\\s-*signal\\>" end t)
7742 (while (and (not (looking-at "[ \t\n]*:"))
7743 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7744 (setq signal-list
7745 (cons (downcase (match-string 1)) signal-list))))
7746 (goto-char beg)))
7747 ;; search for signals declared in architecture declarative part
7748 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7749 (not (equal "END" (upcase (match-string 1))))
7750 (setq entity-name (match-string 2))
7751 (setq end (re-search-forward "^begin\\>" nil t))))
7752 (error "ERROR: No architecture declarative part found")
7753 ;; scan for all declared signal names
7754 (goto-char beg)
7755 (while (re-search-forward "^\\s-*signal\\>" end t)
7756 (while (and (not (looking-at "[ \t\n]*:"))
7757 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7758 (setq signal-list
7759 (cons (downcase (match-string 1)) signal-list)))))
7760 ;; search for signals declared in entity port clause
7761 (goto-char (point-min))
7762 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7763 (setq file-name
7764 (concat (vhdl-replace-string vhdl-entity-file-name entity-name)
7765 "." (file-name-extension (buffer-file-name)))))
7766 (vhdl-visit-file
7767 file-name t
7768 (vhdl-prepare-search-2
7769 (goto-char (point-min))
7770 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7771 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7772 (when (setq beg (re-search-forward
7773 "^\\s-*port[ \t\n]*("
7774 (save-excursion
7775 (re-search-forward "^end\\>" nil t)) t))
7776 (setq end (save-excursion
7777 (backward-char) (forward-sexp) (point)))
7778 (vhdl-forward-syntactic-ws)
7779 (while (< (point) end)
7780 (while (and (not (looking-at "[ \t\n]*:"))
7781 (re-search-forward "[ \t\n,]*\\(\\w+\\)" end t))
7782 (setq signal-list
7783 (cons (downcase (match-string 1)) signal-list)))
7784 (re-search-forward ";" end 1)
7785 (vhdl-forward-syntactic-ws))))))
7786 signal-list)))
7787
7788;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7789;; Generic/port clause fixing
7790
7791(defun vhdl-fix-clause ()
7792 "Fix closing parenthesis within generic/port clause."
7793 (interactive)
7794 (save-excursion
7795 (vhdl-prepare-search-2
7796 (let ((pos (point))
7797 beg end)
7798 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7799 (error "ERROR: Not within a generic/port clause")
7800 ;; search for end of clause
7801 (goto-char (match-end 0))
7802 (setq beg (1- (point)))
7803 (vhdl-forward-syntactic-ws)
7804 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7805 (goto-char (1- (match-end 0)))
7806 (setq end (point-marker))
7807 (forward-char)
7808 (vhdl-forward-syntactic-ws))
7809 (goto-char end)
7810 (when (> pos (save-excursion (end-of-line) (point)))
7811 (error "ERROR: Not within a generic/port clause"))
7812 ;; delete closing parenthesis on separate line (not supported style)
7813 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7814 (vhdl-line-kill)
7815 (vhdl-backward-syntactic-ws)
7816 (setq end (point-marker))
7817 (insert ";"))
7818 ;; delete superfluous parentheses
7819 (while (progn (goto-char beg)
7820 (condition-case () (forward-sexp)
7821 (error (goto-char (point-max))))
7822 (< (point) end))
7823 (delete-backward-char 1))
7824 ;; add closing parenthesis
7825 (when (> (point) end)
7826 (goto-char end)
7827 (insert ")")))))))
7828
7829;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7830;; Miscellaneous
7831
7832(defun vhdl-remove-trailing-spaces ()
7833 "Remove trailing spaces in the whole buffer."
7834 (interactive)
7835 (save-match-data
7836 (save-excursion
7837 (goto-char (point-min))
7838 (while (re-search-forward "[ \t]+$" (point-max) t)
7839 (unless (vhdl-in-literal)
7840 (replace-match "" nil nil))))))
d2ddb974
KH
7841
7842
5eabfe72
KH
7843;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7844;;; Electrification
7845;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7846
5eabfe72
KH
7847(defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
7848 "Syntax of prompt inserted by template generators.")
7849
7850(defvar vhdl-template-invoked-by-hook nil
7851 "Indicates whether a template has been invoked by a hook or by key or menu.
7852Used for undoing after template abortion.")
7853
7854;; correct different behavior of function `unread-command-events' in XEmacs
3dcb36b7 7855(defun vhdl-character-to-event (arg))
5eabfe72 7856(defalias 'vhdl-character-to-event
3dcb36b7
JB
7857 (if vhdl-xemacs 'character-to-event 'identity))
7858
7859(defun vhdl-work-library ()
7860 "Return the working library name of the current project or \"work\" if no
7861project is defined."
7862 (vhdl-resolve-env-variable
7863 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
5eabfe72
KH
7864
7865;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7866;; Enabling/disabling
7867
7868(defun vhdl-mode-line-update ()
7869 "Update the modeline string for VHDL major mode."
7870 (setq mode-name (concat "VHDL"
7871 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
7872 (and vhdl-electric-mode "e")
7873 (and vhdl-stutter-mode "s")))
3dcb36b7 7874 (force-mode-line-update t))
5eabfe72
KH
7875
7876(defun vhdl-electric-mode (arg)
7877 "Toggle VHDL electric mode.
7878Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7879 (interactive "P")
7880 (setq vhdl-electric-mode
7881 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
7882 ((> arg 0) t) (t nil)))
7883 (vhdl-mode-line-update))
7884
7885(defun vhdl-stutter-mode (arg)
7886 "Toggle VHDL stuttering mode.
7887Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7888 (interactive "P")
7889 (setq vhdl-stutter-mode
7890 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
7891 ((> arg 0) t) (t nil)))
7892 (vhdl-mode-line-update))
7893
7894;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7895;; Stuttering
d2ddb974 7896
5eabfe72
KH
7897(defun vhdl-electric-dash (count)
7898 "-- starts a comment, --- draws a horizontal line,
7899---- starts a display comment"
d2ddb974 7900 (interactive "p")
3dcb36b7 7901 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
5eabfe72
KH
7902 (cond
7903 ((and abbrev-start-location (= abbrev-start-location (point)))
7904 (setq abbrev-start-location nil)
7905 (goto-char last-abbrev-location)
7906 (beginning-of-line nil)
7907 (vhdl-comment-display))
7908 ((/= (preceding-char) ?-) ; standard dash (minus)
d2ddb974 7909 (self-insert-command count))
5eabfe72
KH
7910 (t (self-insert-command count)
7911 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
7912 (let ((next-input (read-char)))
7913 (if (= next-input ?-) ; triple dash
7914 (progn
7915 (vhdl-comment-display-line)
7916 (message
7917 "Enter '-' for display comment, else continue coding")
7918 (let ((next-input (read-char)))
7919 (if (= next-input ?-) ; four dashes
7920 (vhdl-comment-display t)
7921 (setq unread-command-events ; pushback the char
7922 (list (vhdl-character-to-event next-input))))))
7923 (setq unread-command-events ; pushback the char
7924 (list (vhdl-character-to-event next-input)))
7925 (vhdl-comment-insert)))))
7926 (self-insert-command count)))
7927
7928(defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
d2ddb974 7929 (interactive "p")
3dcb36b7 7930 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7931 (if (= (preceding-char) ?\()
7932 (progn (delete-char -1) (insert-char ?\[ 1))
7933 (insert-char ?\( 1))
7934 (self-insert-command count)))
d2ddb974 7935
5eabfe72 7936(defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
d2ddb974 7937 (interactive "p")
3dcb36b7 7938 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974 7939 (progn
5eabfe72
KH
7940 (if (= (preceding-char) ?\))
7941 (progn (delete-char -1) (insert-char ?\] 1))
7942 (insert-char ?\) 1))
7943 (blink-matching-open))
7944 (self-insert-command count)))
d2ddb974 7945
5eabfe72 7946(defun vhdl-electric-quote (count) "'' --> \""
d2ddb974 7947 (interactive "p")
3dcb36b7 7948 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7949 (if (= (preceding-char) last-input-char)
7950 (progn (delete-backward-char 1) (insert-char ?\" 1))
7951 (insert-char ?\' 1))
7952 (self-insert-command count)))
d2ddb974 7953
5eabfe72 7954(defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
d2ddb974 7955 (interactive "p")
3dcb36b7 7956 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7957 (cond ((= (preceding-char) last-input-char)
7958 (progn (delete-char -1)
3dcb36b7 7959 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
7960 (insert ": ")
7961 (setq this-command 'vhdl-electric-colon)))
7962 ((and
7963 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
7964 (progn (delete-char -1) (insert "= ")))
7965 (t (insert-char ?\; 1)))
7966 (self-insert-command count)))
7967
7968(defun vhdl-electric-comma (count) "',,' --> ' <= '"
d2ddb974 7969 (interactive "p")
3dcb36b7 7970 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
7971 (cond ((= (preceding-char) last-input-char)
7972 (progn (delete-char -1)
3dcb36b7 7973 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 7974 (insert "<= ")))
5eabfe72
KH
7975 (t (insert-char ?\, 1)))
7976 (self-insert-command count)))
d2ddb974 7977
5eabfe72 7978(defun vhdl-electric-period (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-equal (count) "'==' --> ' == '"
d2ddb974 7989 (interactive "p")
3dcb36b7 7990 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7991 (cond ((= (preceding-char) last-input-char)
7992 (progn (delete-char -1)
3dcb36b7 7993 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
7994 (insert "== ")))
7995 (t (insert-char ?\= 1)))
7996 (self-insert-command count)))
d2ddb974 7997
5eabfe72 7998;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
7999;; VHDL templates
8000
5eabfe72
KH
8001(defun vhdl-template-paired-parens ()
8002 "Insert a pair of round parentheses, placing point between them."
d2ddb974 8003 (interactive)
5eabfe72
KH
8004 (insert "()")
8005 (backward-char))
d2ddb974 8006
5eabfe72
KH
8007(defun vhdl-template-alias ()
8008 "Insert alias declaration."
d2ddb974 8009 (interactive)
5eabfe72
KH
8010 (let ((start (point)))
8011 (vhdl-insert-keyword "ALIAS ")
8012 (when (vhdl-template-field "name" nil t start (point))
8013 (insert " : ")
8014 (unless (vhdl-template-field
8015 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8016 nil t)
3dcb36b7 8017 (delete-backward-char 3))
5eabfe72
KH
8018 (vhdl-insert-keyword " IS ")
8019 (vhdl-template-field "name" ";")
8020 (vhdl-comment-insert-inline))))
8021
8022(defun vhdl-template-architecture ()
8023 "Insert architecture."
8024 (interactive)
8025 (let ((margin (current-indentation))
8026 (start (point))
3dcb36b7 8027 arch-name)
d2ddb974 8028 (vhdl-insert-keyword "ARCHITECTURE ")
5eabfe72
KH
8029 (when (setq arch-name
8030 (vhdl-template-field "name" nil t start (point)))
d2ddb974 8031 (vhdl-insert-keyword " OF ")
3dcb36b7
JB
8032 (if (save-excursion
8033 (vhdl-prepare-search-1
8034 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8035 (insert (match-string 1))
5eabfe72 8036 (vhdl-template-field "entity name"))
3dcb36b7 8037 (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8038 (vhdl-template-begin-end
8039 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8040 (memq vhdl-insert-empty-lines '(unit all))))))
d2ddb974 8041
5eabfe72 8042(defun vhdl-template-array (kind &optional secondary)
d2ddb974
KH
8043 "Insert array type definition."
8044 (interactive)
5eabfe72
KH
8045 (let ((start (point)))
8046 (vhdl-insert-keyword "ARRAY (")
8047 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8048 secondary)
8049 (vhdl-insert-keyword ") OF ")
8050 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8051 (vhdl-insert-keyword ";"))))
8052
8053(defun vhdl-template-assert ()
8054 "Insert an assertion statement."
8055 (interactive)
8056 (let ((start (point)))
8057 (vhdl-insert-keyword "ASSERT ")
8058 (when vhdl-conditions-in-parenthesis (insert "("))
8059 (when (vhdl-template-field "condition (negated)" nil t start (point))
8060 (when vhdl-conditions-in-parenthesis (insert ")"))
8061 (setq start (point))
8062 (vhdl-insert-keyword " REPORT ")
8063 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8064 (delete-region start (point)))
8065 (setq start (point))
8066 (vhdl-insert-keyword " SEVERITY ")
8067 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8068 (delete-region start (point)))
8069 (insert ";"))))
8070
8071(defun vhdl-template-attribute ()
8072 "Insert an attribute declaration or specification."
8073 (interactive)
8074 (if (eq (vhdl-decision-query
8075 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8076 (vhdl-template-attribute-spec)
8077 (vhdl-template-attribute-decl)))
d2ddb974 8078
5eabfe72
KH
8079(defun vhdl-template-attribute-decl ()
8080 "Insert an attribute declaration."
d2ddb974 8081 (interactive)
5eabfe72
KH
8082 (let ((start (point)))
8083 (vhdl-insert-keyword "ATTRIBUTE ")
8084 (when (vhdl-template-field "name" " : " t start (point))
8085 (vhdl-template-field "type" ";")
8086 (vhdl-comment-insert-inline))))
8087
8088(defun vhdl-template-attribute-spec ()
8089 "Insert an attribute specification."
8090 (interactive)
8091 (let ((start (point)))
8092 (vhdl-insert-keyword "ATTRIBUTE ")
8093 (when (vhdl-template-field "name" nil t start (point))
8094 (vhdl-insert-keyword " OF ")
8095 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8096 (vhdl-template-field "entity class")
8097 (vhdl-insert-keyword " IS ")
8098 (vhdl-template-field "expression" ";"))))
d2ddb974 8099
5eabfe72
KH
8100(defun vhdl-template-block ()
8101 "Insert a block."
d2ddb974 8102 (interactive)
5eabfe72
KH
8103 (let ((margin (current-indentation))
8104 (start (point))
8105 label)
8106 (vhdl-insert-keyword ": BLOCK ")
8107 (goto-char start)
8108 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8109 (forward-word 1)
8110 (forward-char 1)
d2ddb974 8111 (insert "(")
5eabfe72
KH
8112 (if (vhdl-template-field "[guard expression]" nil t)
8113 (insert ")")
8114 (delete-char -2))
8115 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 8116 (insert "\n")
5eabfe72
KH
8117 (vhdl-template-begin-end "BLOCK" label margin)
8118 (vhdl-comment-block))))
d2ddb974 8119
5eabfe72 8120(defun vhdl-template-block-configuration ()
d2ddb974
KH
8121 "Insert a block configuration statement."
8122 (interactive)
5eabfe72
KH
8123 (let ((margin (current-indentation))
8124 (start (point)))
d2ddb974 8125 (vhdl-insert-keyword "FOR ")
5eabfe72 8126 (when (vhdl-template-field "block name" nil t start (point))
d2ddb974
KH
8127 (vhdl-insert-keyword "\n\n")
8128 (indent-to margin)
8129 (vhdl-insert-keyword "END FOR;")
8130 (end-of-line 0)
5eabfe72 8131 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8132
5eabfe72
KH
8133(defun vhdl-template-break ()
8134 "Insert a break statement."
d2ddb974 8135 (interactive)
5eabfe72
KH
8136 (let (position)
8137 (vhdl-insert-keyword "BREAK")
8138 (setq position (point))
8139 (insert " ")
8140 (while (or
8141 (progn (vhdl-insert-keyword "FOR ")
8142 (if (vhdl-template-field "[quantity name]" " USE " t)
8143 (progn (vhdl-template-field "quantity name" " => ") t)
8144 (kill-word -1) nil))
8145 (vhdl-template-field "[quantity name]" " => " t))
8146 (vhdl-template-field "expression")
8147 (setq position (point))
8148 (insert ", "))
8149 (delete-region position (point))
8150 (unless (vhdl-sequential-statement-p)
8151 (vhdl-insert-keyword " ON ")
8152 (if (vhdl-template-field "[sensitivity list]" nil t)
8153 (setq position (point))
8154 (delete-region position (point))))
8155 (vhdl-insert-keyword " WHEN ")
8156 (when vhdl-conditions-in-parenthesis (insert "("))
8157 (if (vhdl-template-field "[condition]" nil t)
8158 (when vhdl-conditions-in-parenthesis (insert ")"))
8159 (delete-region position (point)))
8160 (insert ";")))
8161
8162(defun vhdl-template-case (&optional kind)
8163 "Insert a case statement."
8164 (interactive)
8165 (let ((margin (current-indentation))
8166 (start (point))
8167 label)
8168 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8169 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8170 (vhdl-insert-keyword "CASE ")
8171 (vhdl-insert-keyword ": CASE ")
8172 (goto-char start)
8173 (setq label (vhdl-template-field "[label]" nil t))
8174 (unless label (delete-char 2))
8175 (forward-word 1)
8176 (forward-char 1))
8177 (when (vhdl-template-field "expression" nil t start (point))
8178 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
d2ddb974 8179 (indent-to margin)
5eabfe72
KH
8180 (vhdl-insert-keyword "END CASE")
8181 (when label (insert " " label))
8182 (insert ";")
d2ddb974
KH
8183 (forward-line -1)
8184 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8185 (vhdl-insert-keyword "WHEN ")
8186 (let ((position (point)))
8187 (insert " => ;\n")
8188 (indent-to (+ margin vhdl-basic-offset))
8189 (vhdl-insert-keyword "WHEN OTHERS => null;")
8190 (goto-char position)))))
d2ddb974 8191
5eabfe72
KH
8192(defun vhdl-template-case-is ()
8193 "Insert a sequential case statement."
d2ddb974 8194 (interactive)
5eabfe72
KH
8195 (vhdl-template-case 'is))
8196
8197(defun vhdl-template-case-use ()
8198 "Insert a simultaneous case statement."
8199 (interactive)
8200 (vhdl-template-case 'use))
8201
8202(defun vhdl-template-component ()
8203 "Insert a component declaration."
8204 (interactive)
8205 (vhdl-template-component-decl))
8206
8207(defun vhdl-template-component-conf ()
8208 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8209since these are almost equivalent)."
8210 (interactive)
8211 (let ((margin (current-indentation))
8212 (result (vhdl-template-configuration-spec t)))
8213 (when result
8214 (insert "\n")
8215 (indent-to margin)
8216 (vhdl-insert-keyword "END FOR;")
8217 (when (eq result 'no-use)
8218 (end-of-line -0)))))
8219
8220(defun vhdl-template-component-decl ()
8221 "Insert a component declaration."
8222 (interactive)
8223 (let ((margin (current-indentation))
8224 (start (point))
8225 name end-column)
d2ddb974 8226 (vhdl-insert-keyword "COMPONENT ")
5eabfe72 8227 (when (setq name (vhdl-template-field "name" nil t start (point)))
3dcb36b7 8228 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
d2ddb974
KH
8229 (insert "\n\n")
8230 (indent-to margin)
5eabfe72
KH
8231 (vhdl-insert-keyword "END COMPONENT")
8232 (unless (vhdl-standard-p '87) (insert " " name))
8233 (insert ";")
8234 (setq end-column (current-column))
d2ddb974
KH
8235 (end-of-line -0)
8236 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 8237 (vhdl-template-generic-list t t)
d2ddb974
KH
8238 (insert "\n")
8239 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8240 (vhdl-template-port-list t)
8241 (beginning-of-line 2)
8242 (forward-char end-column))))
d2ddb974 8243
5eabfe72
KH
8244(defun vhdl-template-component-inst ()
8245 "Insert a component instantiation statement."
d2ddb974 8246 (interactive)
5eabfe72
KH
8247 (let ((margin (current-indentation))
8248 (start (point))
8249 unit position)
8250 (when (vhdl-template-field "instance label" nil t start (point))
8251 (insert ": ")
3dcb36b7 8252 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
8253 (vhdl-template-field "component name")
8254 ;; direct instantiation
8255 (setq unit (vhdl-template-field
8256 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8257 (setq unit (upcase (or unit "")))
8258 (cond ((equal unit "ENTITY")
3dcb36b7
JB
8259 (vhdl-template-field "library name" "." nil nil nil nil
8260 (vhdl-work-library))
5eabfe72
KH
8261 (vhdl-template-field "entity name" "(")
8262 (if (vhdl-template-field "[architecture name]" nil t)
8263 (insert ")")
8264 (delete-char -1)))
8265 ((equal unit "CONFIGURATION")
3dcb36b7
JB
8266 (vhdl-template-field "library name" "." nil nil nil nil
8267 (vhdl-work-library))
5eabfe72
KH
8268 (vhdl-template-field "configuration name"))
8269 (t (vhdl-template-field "component name"))))
8270 (insert "\n")
d2ddb974 8271 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8272 (setq position (point))
8273 (vhdl-insert-keyword "GENERIC ")
8274 (when (vhdl-template-map position t t)
8275 (insert "\n")
8276 (indent-to (+ margin vhdl-basic-offset)))
8277 (setq position (point))
8278 (vhdl-insert-keyword "PORT ")
8279 (unless (vhdl-template-map position t t)
8280 (kill-line -0)
8281 (delete-char -1))
8282 (insert ";"))))
d2ddb974 8283
5eabfe72
KH
8284(defun vhdl-template-conditional-signal-asst ()
8285 "Insert a conditional signal assignment."
d2ddb974 8286 (interactive)
5eabfe72 8287 (when (vhdl-template-field "target signal")
d2ddb974 8288 (insert " <= ")
5eabfe72
KH
8289; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8290; (insert " "))
d2ddb974 8291 (let ((margin (current-column))
5eabfe72
KH
8292 (start (point))
8293 position)
8294 (vhdl-template-field "waveform")
8295 (setq position (point))
d2ddb974 8296 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8297 (when vhdl-conditions-in-parenthesis (insert "("))
8298 (while (and (vhdl-template-field "[condition]" nil t)
8299 (progn
8300 (when vhdl-conditions-in-parenthesis (insert ")"))
8301 (setq position (point))
8302 (vhdl-insert-keyword " ELSE")
8303 (insert "\n")
8304 (indent-to margin)
8305 (vhdl-template-field "[waveform]" nil t)))
8306 (setq position (point))
d2ddb974 8307 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8308 (when vhdl-conditions-in-parenthesis (insert "(")))
8309 (delete-region position (point))
d2ddb974 8310 (insert ";")
3dcb36b7 8311 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 8312
5eabfe72
KH
8313(defun vhdl-template-configuration ()
8314 "Insert a configuration specification if within an architecture,
d2ddb974
KH
8315a block or component configuration if within a configuration declaration,
8316a configuration declaration if not within a design unit."
8317 (interactive)
3dcb36b7
JB
8318 (vhdl-prepare-search-1
8319 (cond
8320 ((and (save-excursion ; architecture body
8321 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8322 (equal "ARCHITECTURE" (upcase (match-string 1))))
8323 (vhdl-template-configuration-spec))
8324 ((and (save-excursion ; configuration declaration
8325 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8326 (equal "CONFIGURATION" (upcase (match-string 1))))
8327 (if (eq (vhdl-decision-query
8328 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8329 (vhdl-template-component-conf)
8330 (vhdl-template-block-configuration)))
8331 (t (vhdl-template-configuration-decl))))) ; otherwise
5eabfe72
KH
8332
8333(defun vhdl-template-configuration-spec (&optional optional-use)
8334 "Insert a configuration specification."
d2ddb974 8335 (interactive)
5eabfe72
KH
8336 (let ((margin (current-indentation))
8337 (start (point))
8338 aspect position)
d2ddb974 8339 (vhdl-insert-keyword "FOR ")
3dcb36b7 8340 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
5eabfe72 8341 t start (point))
3dcb36b7 8342 (vhdl-template-field "component name" "\n")
d2ddb974 8343 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8344 (setq start (point))
8345 (vhdl-insert-keyword "USE ")
8346 (if (and optional-use
8347 (not (setq aspect (vhdl-template-field
8348 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8349 (progn (delete-region start (point)) 'no-use)
8350 (unless optional-use
8351 (setq aspect (vhdl-template-field
8352 "ENTITY | CONFIGURATION | OPEN" " ")))
8353 (setq aspect (upcase (or aspect "")))
8354 (cond ((equal aspect "ENTITY")
3dcb36b7
JB
8355 (vhdl-template-field "library name" "." nil nil nil nil
8356 (vhdl-work-library))
5eabfe72
KH
8357 (vhdl-template-field "entity name" "(")
8358 (if (vhdl-template-field "[architecture name]" nil t)
8359 (insert ")")
d2ddb974 8360 (delete-char -1))
5eabfe72
KH
8361 (insert "\n")
8362 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8363 (setq position (point))
8364 (vhdl-insert-keyword "GENERIC ")
8365 (when (vhdl-template-map position t t)
8366 (insert "\n")
8367 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8368 (setq position (point))
8369 (vhdl-insert-keyword "PORT ")
8370 (unless (vhdl-template-map position t t)
8371 (kill-line -0)
8372 (delete-char -1))
8373 (insert ";")
8374 t)
8375 ((equal aspect "CONFIGURATION")
3dcb36b7
JB
8376 (vhdl-template-field "library name" "." nil nil nil nil
8377 (vhdl-work-library))
5eabfe72 8378 (vhdl-template-field "configuration name" ";"))
3dcb36b7 8379 (t (delete-backward-char 1) (insert ";") t))))))
5eabfe72 8380
d2ddb974 8381
5eabfe72
KH
8382(defun vhdl-template-configuration-decl ()
8383 "Insert a configuration declaration."
d2ddb974 8384 (interactive)
5eabfe72
KH
8385 (let ((margin (current-indentation))
8386 (start (point))
5eabfe72 8387 entity-exists string name position)
d2ddb974 8388 (vhdl-insert-keyword "CONFIGURATION ")
5eabfe72 8389 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974 8390 (vhdl-insert-keyword " OF ")
5eabfe72 8391 (save-excursion
3dcb36b7
JB
8392 (vhdl-prepare-search-1
8393 (setq entity-exists (vhdl-re-search-backward
5eabfe72
KH
8394 "\\<entity \\(\\w*\\) is\\>" nil t))
8395 (setq string (match-string 1))))
d2ddb974 8396 (if (and entity-exists (not (equal string "")))
5eabfe72
KH
8397 (insert string)
8398 (vhdl-template-field "entity name"))
8399 (vhdl-insert-keyword " IS\n")
8400 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8401 (indent-to (+ margin vhdl-basic-offset))
8402 (setq position (point))
8403 (insert "\n")
8404 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
d2ddb974
KH
8405 (indent-to margin)
8406 (vhdl-insert-keyword "END ")
5eabfe72
KH
8407 (unless (vhdl-standard-p '87)
8408 (vhdl-insert-keyword "CONFIGURATION "))
d2ddb974 8409 (insert name ";")
5eabfe72 8410 (goto-char position))))
d2ddb974 8411
5eabfe72
KH
8412(defun vhdl-template-constant ()
8413 "Insert a constant declaration."
8414 (interactive)
8415 (let ((start (point))
8416 (in-arglist (vhdl-in-argument-list-p)))
8417 (vhdl-insert-keyword "CONSTANT ")
8418 (when (vhdl-template-field "name" nil t start (point))
d2ddb974 8419 (insert " : ")
5eabfe72
KH
8420 (when in-arglist (vhdl-insert-keyword "IN "))
8421 (vhdl-template-field "type")
d2ddb974 8422 (if in-arglist
5eabfe72
KH
8423 (progn (insert ";")
8424 (vhdl-comment-insert-inline))
d2ddb974
KH
8425 (let ((position (point)))
8426 (insert " := ")
5eabfe72
KH
8427 (unless (vhdl-template-field "[initialization]" nil t)
8428 (delete-region position (point)))
8429 (insert ";")
8430 (vhdl-comment-insert-inline))))))
d2ddb974 8431
5eabfe72 8432(defun vhdl-template-default ()
d2ddb974
KH
8433 "Insert nothing."
8434 (interactive)
8435 (insert " ")
8436 (unexpand-abbrev)
8437 (backward-word 1)
8438 (vhdl-case-word 1)
5eabfe72 8439 (forward-char 1))
d2ddb974 8440
5eabfe72 8441(defun vhdl-template-default-indent ()
d2ddb974
KH
8442 "Insert nothing and indent."
8443 (interactive)
8444 (insert " ")
8445 (unexpand-abbrev)
8446 (backward-word 1)
8447 (vhdl-case-word 1)
8448 (forward-char 1)
3dcb36b7 8449 (indent-according-to-mode))
d2ddb974 8450
5eabfe72 8451(defun vhdl-template-disconnect ()
d2ddb974
KH
8452 "Insert a disconnect statement."
8453 (interactive)
5eabfe72
KH
8454 (let ((start (point)))
8455 (vhdl-insert-keyword "DISCONNECT ")
8456 (when (vhdl-template-field "signal names | OTHERS | ALL"
8457 " : " t start (point))
8458 (vhdl-template-field "type")
8459 (vhdl-insert-keyword " AFTER ")
8460 (vhdl-template-field "time expression" ";"))))
8461
8462(defun vhdl-template-else ()
d2ddb974
KH
8463 "Insert an else statement."
8464 (interactive)
3dcb36b7
JB
8465 (let (margin)
8466 (vhdl-prepare-search-1
5eabfe72 8467 (vhdl-insert-keyword "ELSE")
3dcb36b7
JB
8468 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8469 (equal "WHEN" (upcase (match-string 1))))
5eabfe72 8470 (insert " ")
3dcb36b7 8471 (indent-according-to-mode)
5eabfe72
KH
8472 (setq margin (current-indentation))
8473 (insert "\n")
8474 (indent-to (+ margin vhdl-basic-offset))))))
8475
8476(defun vhdl-template-elsif ()
d2ddb974
KH
8477 "Insert an elsif statement."
8478 (interactive)
5eabfe72
KH
8479 (let ((start (point))
8480 margin)
d2ddb974 8481 (vhdl-insert-keyword "ELSIF ")
3dcb36b7
JB
8482 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8483 (when vhdl-conditions-in-parenthesis (insert "("))
8484 (when (vhdl-template-field "condition" nil t start (point))
8485 (when vhdl-conditions-in-parenthesis (insert ")"))
8486 (indent-according-to-mode)
8487 (setq margin (current-indentation))
8488 (vhdl-insert-keyword
8489 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8490 (indent-to (+ margin vhdl-basic-offset))))))
d2ddb974 8491
5eabfe72
KH
8492(defun vhdl-template-entity ()
8493 "Insert an entity."
d2ddb974 8494 (interactive)
5eabfe72
KH
8495 (let ((margin (current-indentation))
8496 (start (point))
8497 name end-column)
d2ddb974 8498 (vhdl-insert-keyword "ENTITY ")
5eabfe72 8499 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974
KH
8500 (vhdl-insert-keyword " IS\n\n")
8501 (indent-to margin)
8502 (vhdl-insert-keyword "END ")
5eabfe72
KH
8503 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8504 (insert name ";")
8505 (setq end-column (current-column))
d2ddb974
KH
8506 (end-of-line -0)
8507 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8508 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8509 (indent-to (+ margin vhdl-basic-offset))
8510 (when (vhdl-template-generic-list t)
8511 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8512 (insert "\n")
8513 (indent-to (+ margin vhdl-basic-offset))
8514 (when (vhdl-template-port-list t)
8515 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8516 (beginning-of-line 2)
8517 (forward-char end-column))))
d2ddb974 8518
5eabfe72 8519(defun vhdl-template-exit ()
d2ddb974
KH
8520 "Insert an exit statement."
8521 (interactive)
5eabfe72
KH
8522 (let ((start (point)))
8523 (vhdl-insert-keyword "EXIT ")
3dcb36b7
JB
8524 (if (vhdl-template-field "[loop label]" nil t start (point))
8525 (let ((position (point)))
8526 (vhdl-insert-keyword " WHEN ")
8527 (when vhdl-conditions-in-parenthesis (insert "("))
8528 (if (vhdl-template-field "[condition]" nil t)
8529 (when vhdl-conditions-in-parenthesis (insert ")"))
8530 (delete-region position (point))))
d2ddb974 8531 (delete-char -1))
5eabfe72
KH
8532 (insert ";")))
8533
8534(defun vhdl-template-file ()
8535 "Insert a file declaration."
8536 (interactive)
8537 (let ((start (point)))
8538 (vhdl-insert-keyword "FILE ")
8539 (when (vhdl-template-field "name" nil t start (point))
8540 (insert " : ")
8541 (vhdl-template-field "type")
8542 (unless (vhdl-standard-p '87)
8543 (vhdl-insert-keyword " OPEN ")
8544 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8545 nil t)
3dcb36b7 8546 (delete-backward-char 6)))
5eabfe72
KH
8547 (vhdl-insert-keyword " IS ")
8548 (when (vhdl-standard-p '87)
8549 (vhdl-template-field "[IN | OUT]" " " t))
8550 (vhdl-template-field "filename-string" nil nil nil nil t)
8551 (insert ";")
8552 (vhdl-comment-insert-inline))))
d2ddb974 8553
5eabfe72
KH
8554(defun vhdl-template-for ()
8555 "Insert a block or component configuration if within a configuration
8556declaration, a configuration specification if within an architecture
3dcb36b7
JB
8557declarative part (and not within a subprogram), a for-loop if within a
8558sequential statement part (subprogram or process), and a for-generate
8559otherwise."
5eabfe72 8560 (interactive)
3dcb36b7
JB
8561 (vhdl-prepare-search-1
8562 (cond
8563 ((vhdl-sequential-statement-p) ; sequential statement
8564 (vhdl-template-for-loop))
8565 ((and (save-excursion ; configuration declaration
8566 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8567 (equal "CONFIGURATION" (upcase (match-string 1))))
8568 (if (eq (vhdl-decision-query
8569 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8570 (vhdl-template-component-conf)
8571 (vhdl-template-block-configuration)))
8572 ((and (save-excursion
8573 (re-search-backward ; architecture declarative part
8574 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8575 (equal "ARCHITECTURE" (upcase (match-string 1))))
8576 (vhdl-template-configuration-spec))
8577 (t (vhdl-template-for-generate))))) ; concurrent statement
5eabfe72
KH
8578
8579(defun vhdl-template-for-generate ()
8580 "Insert a for-generate."
d2ddb974 8581 (interactive)
5eabfe72
KH
8582 (let ((margin (current-indentation))
8583 (start (point))
3dcb36b7 8584 label position)
5eabfe72
KH
8585 (vhdl-insert-keyword ": FOR ")
8586 (setq position (point-marker))
8587 (goto-char start)
8588 (when (setq label (vhdl-template-field "label" nil t start position))
8589 (goto-char position)
8590 (vhdl-template-field "loop variable")
8591 (vhdl-insert-keyword " IN ")
8592 (vhdl-template-field "range")
8593 (vhdl-template-generate-body margin label))))
d2ddb974 8594
5eabfe72
KH
8595(defun vhdl-template-for-loop ()
8596 "Insert a for loop."
d2ddb974 8597 (interactive)
5eabfe72
KH
8598 (let ((margin (current-indentation))
8599 (start (point))
8600 label index)
8601 (if (not (eq vhdl-optional-labels 'all))
8602 (vhdl-insert-keyword "FOR ")
8603 (vhdl-insert-keyword ": FOR ")
8604 (goto-char start)
8605 (setq label (vhdl-template-field "[label]" nil t))
8606 (unless label (delete-char 2))
8607 (forward-word 1)
8608 (forward-char 1))
8609 (when (setq index (vhdl-template-field "loop variable"
8610 nil t start (point)))
d2ddb974 8611 (vhdl-insert-keyword " IN ")
5eabfe72 8612 (vhdl-template-field "range")
d2ddb974
KH
8613 (vhdl-insert-keyword " LOOP\n\n")
8614 (indent-to margin)
8615 (vhdl-insert-keyword "END LOOP")
5eabfe72
KH
8616 (if label
8617 (insert " " label ";")
d2ddb974 8618 (insert ";")
5eabfe72 8619 (when vhdl-self-insert-comments (insert " -- " index)))
d2ddb974 8620 (forward-line -1)
5eabfe72 8621 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8622
5eabfe72
KH
8623(defun vhdl-template-function (&optional kind)
8624 "Insert a function declaration or body."
d2ddb974 8625 (interactive)
5eabfe72
KH
8626 (let ((margin (current-indentation))
8627 (start (point))
8628 name)
8629 (vhdl-insert-keyword "FUNCTION ")
8630 (when (setq name (vhdl-template-field "name" nil t start (point)))
8631 (vhdl-template-argument-list t)
3dcb36b7 8632 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
d2ddb974 8633 (end-of-line)
5eabfe72 8634 (insert "\n")
d2ddb974 8635 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8636 (vhdl-insert-keyword "RETURN ")
8637 (vhdl-template-field "type")
8638 (if (if kind (eq kind 'body)
8639 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
3dcb36b7 8640 (progn (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8641 (vhdl-template-begin-end
8642 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8643 (vhdl-comment-block))
8644 (insert ";")))))
8645
8646(defun vhdl-template-function-decl ()
8647 "Insert a function declaration."
8648 (interactive)
8649 (vhdl-template-function 'decl))
d2ddb974 8650
5eabfe72
KH
8651(defun vhdl-template-function-body ()
8652 "Insert a function declaration."
d2ddb974 8653 (interactive)
5eabfe72
KH
8654 (vhdl-template-function 'body))
8655
8656(defun vhdl-template-generate ()
8657 "Insert a generation scheme."
8658 (interactive)
8659 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8660 (vhdl-template-if-generate)
8661 (vhdl-template-for-generate)))
d2ddb974 8662
5eabfe72
KH
8663(defun vhdl-template-generic ()
8664 "Insert generic declaration, or generic map in instantiation statements."
8665 (interactive)
3dcb36b7
JB
8666 (let ((start (point)))
8667 (vhdl-prepare-search-1
5eabfe72
KH
8668 (cond
8669 ((and (save-excursion ; entity declaration
8670 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8671 (equal "ENTITY" (upcase (match-string 1))))
8672 (vhdl-template-generic-list nil))
8673 ((or (save-excursion
8674 (or (beginning-of-line)
8675 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 8676 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
8677 (vhdl-insert-keyword "GENERIC ")
8678 (vhdl-template-map start))
8679 (t (vhdl-template-generic-list nil t))))))
8680
8681(defun vhdl-template-group ()
8682 "Insert group or group template declaration."
8683 (interactive)
8684 (let ((start (point)))
8685 (if (eq (vhdl-decision-query
8686 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8687 (vhdl-template-group-template)
8688 (vhdl-template-group-decl))))
8689
8690(defun vhdl-template-group-decl ()
8691 "Insert group declaration."
8692 (interactive)
8693 (let ((start (point)))
8694 (vhdl-insert-keyword "GROUP ")
8695 (when (vhdl-template-field "name" " : " t start (point))
8696 (vhdl-template-field "template name" " (")
8697 (vhdl-template-field "constituent list" ");")
8698 (vhdl-comment-insert-inline))))
8699
8700(defun vhdl-template-group-template ()
8701 "Insert group template declaration."
8702 (interactive)
8703 (let ((start (point)))
8704 (vhdl-insert-keyword "GROUP ")
8705 (when (vhdl-template-field "template name" nil t start (point))
8706 (vhdl-insert-keyword " IS (")
8707 (vhdl-template-field "entity class list" ");")
8708 (vhdl-comment-insert-inline))))
8709
5eabfe72
KH
8710(defun vhdl-template-if ()
8711 "Insert a sequential if statement or an if-generate statement."
8712 (interactive)
8713 (if (vhdl-sequential-statement-p)
8714 (vhdl-template-if-then)
8715 (if (and (vhdl-standard-p 'ams)
8716 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8717 (vhdl-template-if-use)
8718 (vhdl-template-if-generate))))
8719
8720(defun vhdl-template-if-generate ()
8721 "Insert an if-generate."
8722 (interactive)
8723 (let ((margin (current-indentation))
8724 (start (point))
3dcb36b7 8725 label position)
5eabfe72
KH
8726 (vhdl-insert-keyword ": IF ")
8727 (setq position (point-marker))
8728 (goto-char start)
8729 (when (setq label (vhdl-template-field "label" nil t start position))
8730 (goto-char position)
8731 (when vhdl-conditions-in-parenthesis (insert "("))
8732 (vhdl-template-field "condition")
8733 (when vhdl-conditions-in-parenthesis (insert ")"))
8734 (vhdl-template-generate-body margin label))))
d2ddb974 8735
5eabfe72
KH
8736(defun vhdl-template-if-then-use (kind)
8737 "Insert a sequential if statement."
8738 (interactive)
8739 (let ((margin (current-indentation))
8740 (start (point))
8741 label)
8742 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8743 (vhdl-insert-keyword "IF ")
8744 (vhdl-insert-keyword ": IF ")
8745 (goto-char start)
8746 (setq label (vhdl-template-field "[label]" nil t))
8747 (unless label (delete-char 2))
8748 (forward-word 1)
8749 (forward-char 1))
8750 (when vhdl-conditions-in-parenthesis (insert "("))
8751 (when (vhdl-template-field "condition" nil t start (point))
8752 (when vhdl-conditions-in-parenthesis (insert ")"))
8753 (vhdl-insert-keyword
8754 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
d2ddb974 8755 (indent-to margin)
5eabfe72
KH
8756 (vhdl-insert-keyword "END IF")
8757 (when label (insert " " label))
8758 (insert ";")
d2ddb974 8759 (forward-line -1)
5eabfe72
KH
8760 (indent-to (+ margin vhdl-basic-offset)))))
8761
8762(defun vhdl-template-if-then ()
8763 "Insert a sequential if statement."
8764 (interactive)
8765 (vhdl-template-if-then-use 'then))
8766
8767(defun vhdl-template-if-use ()
8768 "Insert a simultaneous if statement."
8769 (interactive)
8770 (vhdl-template-if-then-use 'use))
8771
8772(defun vhdl-template-instance ()
8773 "Insert a component instantiation statement."
8774 (interactive)
8775 (vhdl-template-component-inst))
d2ddb974 8776
5eabfe72 8777(defun vhdl-template-library ()
d2ddb974
KH
8778 "Insert a library specification."
8779 (interactive)
5eabfe72
KH
8780 (let ((margin (current-indentation))
8781 (start (point))
8782 name end-pos)
d2ddb974 8783 (vhdl-insert-keyword "LIBRARY ")
5eabfe72
KH
8784 (when (setq name (vhdl-template-field "names" nil t start (point)))
8785 (insert ";")
8786 (unless (string-match "," name)
8787 (setq end-pos (point))
8788 (insert "\n")
8789 (indent-to margin)
8790 (vhdl-insert-keyword "USE ")
8791 (insert name)
8792 (vhdl-insert-keyword "..ALL;")
8793 (backward-char 5)
8794 (if (vhdl-template-field "package name")
8795 (forward-char 5)
8796 (delete-region end-pos (+ (point) 5)))))))
8797
8798(defun vhdl-template-limit ()
8799 "Insert a limit."
d2ddb974 8800 (interactive)
5eabfe72
KH
8801 (let ((start (point)))
8802 (vhdl-insert-keyword "LIMIT ")
8803 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8804 t start (point))
8805 (vhdl-template-field "type")
8806 (vhdl-insert-keyword " WITH ")
8807 (vhdl-template-field "real expression" ";"))))
8808
8809(defun vhdl-template-loop ()
8810 "Insert a loop."
8811 (interactive)
8812 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8813 (cond ((eq char ?w)
8814 (vhdl-template-while-loop))
8815 ((eq char ?f)
8816 (vhdl-template-for-loop))
8817 (t (vhdl-template-bare-loop)))))
8818
8819(defun vhdl-template-bare-loop ()
8820 "Insert a loop."
8821 (interactive)
8822 (let ((margin (current-indentation))
8823 (start (point))
8824 label)
8825 (if (not (eq vhdl-optional-labels 'all))
8826 (vhdl-insert-keyword "LOOP ")
8827 (vhdl-insert-keyword ": LOOP ")
8828 (goto-char start)
8829 (setq label (vhdl-template-field "[label]" nil t))
8830 (unless label (delete-char 2))
8831 (forward-word 1)
8832 (delete-char 1))
d2ddb974
KH
8833 (insert "\n\n")
8834 (indent-to margin)
8835 (vhdl-insert-keyword "END LOOP")
5eabfe72 8836 (insert (if label (concat " " label ";") ";"))
d2ddb974 8837 (forward-line -1)
5eabfe72 8838 (indent-to (+ margin vhdl-basic-offset))))
d2ddb974 8839
5eabfe72
KH
8840(defun vhdl-template-map (&optional start optional secondary)
8841 "Insert a map specification with association list."
d2ddb974 8842 (interactive)
5eabfe72
KH
8843 (let ((start (or start (point)))
8844 margin end-pos)
8845 (vhdl-insert-keyword "MAP (")
8846 (if (not vhdl-association-list-with-formals)
8847 (if (vhdl-template-field
8848 (concat (and optional "[") "association list" (and optional "]"))
8849 ")" (or (not secondary) optional)
8850 (and (not secondary) start) (point))
8851 t
8852 (if (and optional secondary) (delete-region start (point)))
8853 nil)
8854 (if vhdl-argument-list-indent
8855 (setq margin (current-column))
8856 (setq margin (+ (current-indentation) vhdl-basic-offset))
8857 (insert "\n")
8858 (indent-to margin))
8859 (if (vhdl-template-field
8860 (concat (and optional "[") "formal" (and optional "]"))
8861 " => " (or (not secondary) optional)
8862 (and (not secondary) start) (point))
8863 (progn
8864 (vhdl-template-field "actual" ",")
8865 (setq end-pos (point))
8866 (insert "\n")
8867 (indent-to margin)
8868 (while (vhdl-template-field "[formal]" " => " t)
8869 (vhdl-template-field "actual" ",")
8870 (setq end-pos (point))
8871 (insert "\n")
8872 (indent-to margin))
8873 (delete-region end-pos (point))
3dcb36b7 8874 (delete-backward-char 1)
5eabfe72 8875 (insert ")")
3dcb36b7 8876 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
8877 t)
8878 (when (and optional secondary) (delete-region start (point)))
8879 nil))))
d2ddb974 8880
5eabfe72 8881(defun vhdl-template-modify (&optional noerror)
d2ddb974
KH
8882 "Actualize modification date."
8883 (interactive)
3dcb36b7
JB
8884 (vhdl-prepare-search-2
8885 (save-excursion
8886 (goto-char (point-min))
8887 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
8888 (progn (delete-region (point) (progn (end-of-line) (point)))
8889 (vhdl-template-insert-date))
8890 (unless noerror
8891 (error (concat "ERROR: Modification date prefix string \""
8892 vhdl-modify-date-prefix-string "\" not found")))))))
5eabfe72
KH
8893
8894(defun vhdl-template-modify-noerror ()
8895 "Call `vhdl-template-modify' with NOERROR non-nil."
8896 (vhdl-template-modify t))
8897
8898(defun vhdl-template-nature ()
8899 "Insert a nature declaration."
8900 (interactive)
8901 (let ((start (point))
8902 name mid-pos end-pos)
8903 (vhdl-insert-keyword "NATURE ")
8904 (when (setq name (vhdl-template-field "name" nil t start (point)))
8905 (vhdl-insert-keyword " IS ")
8906 (let ((definition
8907 (upcase
8908 (or (vhdl-template-field
8909 "across type | ARRAY | RECORD")
8910 ""))))
8911 (cond ((equal definition "")
8912 (insert ";"))
8913 ((equal definition "ARRAY")
8914 (kill-word -1)
8915 (vhdl-template-array 'nature t))
8916 ((equal definition "RECORD")
8917 (setq mid-pos (point-marker))
8918 (kill-word -1)
8919 (vhdl-template-record 'nature name t))
8920 (t
8921 (vhdl-insert-keyword " ACROSS ")
8922 (vhdl-template-field "through type")
8923 (vhdl-insert-keyword " THROUGH ")
8924 (vhdl-template-field "reference name")
8925 (vhdl-insert-keyword " REFERENCE;")))
8926 (when mid-pos
8927 (setq end-pos (point-marker))
8928 (goto-char mid-pos)
8929 (end-of-line))
8930 (vhdl-comment-insert-inline)
8931 (when end-pos (goto-char end-pos))))))
8932
8933(defun vhdl-template-next ()
8934 "Insert a next statement."
d2ddb974 8935 (interactive)
3dcb36b7
JB
8936 (let ((start (point)))
8937 (vhdl-insert-keyword "NEXT ")
8938 (if (vhdl-template-field "[loop label]" nil t start (point))
8939 (let ((position (point)))
8940 (vhdl-insert-keyword " WHEN ")
8941 (when vhdl-conditions-in-parenthesis (insert "("))
8942 (if (vhdl-template-field "[condition]" nil t)
8943 (when vhdl-conditions-in-parenthesis (insert ")"))
8944 (delete-region position (point))))
8945 (delete-char -1))
5eabfe72
KH
8946 (insert ";")))
8947
8948(defun vhdl-template-others ()
8949 "Insert an others aggregate."
8950 (interactive)
3dcb36b7
JB
8951 (let ((start (point)))
8952 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
8953 (progn (unless vhdl-template-invoked-by-hook (insert "("))
8954 (vhdl-insert-keyword "OTHERS => '")
8955 (when (vhdl-template-field "value" nil t start (point))
8956 (insert "')")))
8957 (vhdl-insert-keyword "OTHERS "))))
d2ddb974 8958
5eabfe72 8959(defun vhdl-template-package (&optional kind)
d2ddb974
KH
8960 "Insert a package specification or body."
8961 (interactive)
5eabfe72
KH
8962 (let ((margin (current-indentation))
8963 (start (point))
8964 name body position)
d2ddb974 8965 (vhdl-insert-keyword "PACKAGE ")
5eabfe72
KH
8966 (setq body (if kind (eq kind 'body)
8967 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
3dcb36b7
JB
8968 (when body
8969 (vhdl-insert-keyword "BODY ")
8970 (when (save-excursion
8971 (vhdl-prepare-search-1
8972 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
8973 (insert (setq name (match-string 1)))))
8974 (when (or name
8975 (setq name (vhdl-template-field "name" nil t start (point))))
5eabfe72
KH
8976 (vhdl-insert-keyword " IS\n")
8977 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8978 (indent-to (+ margin vhdl-basic-offset))
8979 (setq position (point))
8980 (insert "\n")
8981 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8982 (indent-to margin)
8983 (vhdl-insert-keyword "END ")
8984 (unless (vhdl-standard-p '87)
8985 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
8986 (insert (or name "") ";")
8987 (goto-char position))))
d2ddb974 8988
5eabfe72
KH
8989(defun vhdl-template-package-decl ()
8990 "Insert a package specification."
d2ddb974 8991 (interactive)
5eabfe72 8992 (vhdl-template-package 'decl))
d2ddb974 8993
5eabfe72
KH
8994(defun vhdl-template-package-body ()
8995 "Insert a package body."
d2ddb974 8996 (interactive)
5eabfe72 8997 (vhdl-template-package 'body))
d2ddb974 8998
5eabfe72
KH
8999(defun vhdl-template-port ()
9000 "Insert a port declaration, or port map in instantiation statements."
d2ddb974 9001 (interactive)
3dcb36b7
JB
9002 (let ((start (point)))
9003 (vhdl-prepare-search-1
5eabfe72
KH
9004 (cond
9005 ((and (save-excursion ; entity declaration
9006 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9007 (equal "ENTITY" (upcase (match-string 1))))
9008 (vhdl-template-port-list nil))
9009 ((or (save-excursion
9010 (or (beginning-of-line)
9011 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 9012 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
9013 (vhdl-insert-keyword "PORT ")
9014 (vhdl-template-map start))
9015 (t (vhdl-template-port-list nil))))))
9016
9017(defun vhdl-template-procedural ()
9018 "Insert a procedural."
9019 (interactive)
9020 (let ((margin (current-indentation))
9021 (start (point))
9022 (case-fold-search t)
9023 label)
9024 (vhdl-insert-keyword "PROCEDURAL ")
9025 (when (memq vhdl-optional-labels '(process all))
9026 (goto-char start)
9027 (insert ": ")
9028 (goto-char start)
9029 (setq label (vhdl-template-field "[label]" nil t))
9030 (unless label (delete-char 2))
9031 (forward-word 1)
9032 (forward-char 1))
9033 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
3dcb36b7 9034 (insert "\n")
5eabfe72
KH
9035 (vhdl-template-begin-end "PROCEDURAL" label margin)
9036 (vhdl-comment-block)))
9037
9038(defun vhdl-template-procedure (&optional kind)
9039 "Insert a procedure declaration or body."
9040 (interactive)
9041 (let ((margin (current-indentation))
9042 (start (point))
9043 name)
9044 (vhdl-insert-keyword "PROCEDURE ")
9045 (when (setq name (vhdl-template-field "name" nil t start (point)))
9046 (vhdl-template-argument-list)
9047 (if (if kind (eq kind 'body)
9048 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9049 (progn (vhdl-insert-keyword " IS")
9050 (when vhdl-auto-align
3dcb36b7
JB
9051 (vhdl-align-region-groups start (point) 1))
9052 (end-of-line) (insert "\n")
5eabfe72
KH
9053 (vhdl-template-begin-end
9054 (unless (vhdl-standard-p '87) "PROCEDURE")
9055 name margin)
9056 (vhdl-comment-block))
9057 (insert ";")
3dcb36b7 9058 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9059 (end-of-line)))))
9060
9061(defun vhdl-template-procedure-decl ()
9062 "Insert a procedure declaration."
9063 (interactive)
9064 (vhdl-template-procedure 'decl))
d2ddb974 9065
5eabfe72
KH
9066(defun vhdl-template-procedure-body ()
9067 "Insert a procedure body."
9068 (interactive)
9069 (vhdl-template-procedure 'body))
9070
9071(defun vhdl-template-process (&optional kind)
9072 "Insert a process."
9073 (interactive)
9074 (let ((margin (current-indentation))
9075 (start (point))
5eabfe72
KH
9076 label seq input-signals clock reset final-pos)
9077 (setq seq (if kind (eq kind 'seq)
9078 (eq (vhdl-decision-query
9079 "process" "(c)ombinational or (s)equential?" t) ?s)))
9080 (vhdl-insert-keyword "PROCESS ")
9081 (when (memq vhdl-optional-labels '(process all))
9082 (goto-char start)
9083 (insert ": ")
9084 (goto-char start)
9085 (setq label (vhdl-template-field "[label]" nil t))
9086 (unless label (delete-char 2))
9087 (forward-word 1)
9088 (forward-char 1))
9089 (insert "(")
9090 (if (not seq)
9091 (unless (setq input-signals
9092 (vhdl-template-field "[sensitivity list]" ")" t))
9093 (setq input-signals "")
9094 (delete-char -2))
9095 (setq clock (or (and (not (equal "" vhdl-clock-name))
9096 (progn (insert vhdl-clock-name) vhdl-clock-name))
9097 (vhdl-template-field "clock name") "<clock>"))
9098 (when (eq vhdl-reset-kind 'async)
9099 (insert ", ")
9100 (setq reset (or (and (not (equal "" vhdl-reset-name))
9101 (progn (insert vhdl-reset-name) vhdl-reset-name))
9102 (vhdl-template-field "reset name") "<reset>")))
9103 (insert ")"))
9104 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 9105 (insert "\n")
5eabfe72
KH
9106 (vhdl-template-begin-end "PROCESS" label margin)
9107 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9108 (when vhdl-prompt-for-comments
9109 (setq final-pos (point-marker))
3dcb36b7
JB
9110 (vhdl-prepare-search-2
9111 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9112 (vhdl-re-search-backward "\\<process\\>" nil t))
5eabfe72
KH
9113 (end-of-line -0)
9114 (if (bobp)
9115 (progn (insert "\n") (forward-line -1))
9116 (insert "\n"))
9117 (indent-to margin)
9118 (insert "-- purpose: ")
9119 (if (not (vhdl-template-field "[description]" nil t))
9120 (vhdl-line-kill-entire)
9121 (insert "\n")
9122 (indent-to margin)
9123 (insert "-- type : ")
9124 (insert (if seq "sequential" "combinational") "\n")
9125 (indent-to margin)
9126 (insert "-- inputs : ")
9127 (if (not seq)
9128 (insert input-signals)
9129 (insert clock ", ")
9130 (when reset (insert reset ", "))
9131 (unless (vhdl-template-field "[signal names]" nil t)
9132 (delete-char -2)))
9133 (insert "\n")
9134 (indent-to margin)
9135 (insert "-- outputs: ")
9136 (vhdl-template-field "[signal names]" nil t))))
9137 (goto-char final-pos))))
9138
9139(defun vhdl-template-process-comb ()
9140 "Insert a combinational process."
9141 (interactive)
9142 (vhdl-template-process 'comb))
9143
9144(defun vhdl-template-process-seq ()
9145 "Insert a sequential process."
9146 (interactive)
9147 (vhdl-template-process 'seq))
9148
9149(defun vhdl-template-quantity ()
9150 "Insert a quantity declaration."
9151 (interactive)
9152 (if (vhdl-in-argument-list-p)
9153 (let ((start (point)))
9154 (vhdl-insert-keyword "QUANTITY ")
9155 (when (vhdl-template-field "names" nil t start (point))
9156 (insert " : ")
9157 (vhdl-template-field "[IN | OUT]" " " t)
9158 (vhdl-template-field "type")
9159 (insert ";")
9160 (vhdl-comment-insert-inline)))
9161 (let ((char (vhdl-decision-query
9162 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9163 (cond ((eq char ?f) (vhdl-template-quantity-free))
9164 ((eq char ?b) (vhdl-template-quantity-branch))
9165 ((eq char ?s) (vhdl-template-quantity-source))
9166 (t (vhdl-template-undo (point) (point)))))))
9167
9168(defun vhdl-template-quantity-free ()
9169 "Insert a free quantity declaration."
9170 (interactive)
9171 (vhdl-insert-keyword "QUANTITY ")
9172 (vhdl-template-field "names")
9173 (insert " : ")
9174 (vhdl-template-field "type")
9175 (let ((position (point)))
9176 (insert " := ")
9177 (unless (vhdl-template-field "[initialization]" nil t)
9178 (delete-region position (point)))
9179 (insert ";")
9180 (vhdl-comment-insert-inline)))
9181
9182(defun vhdl-template-quantity-branch ()
9183 "Insert a branch quantity declaration."
9184 (interactive)
9185 (let (position)
9186 (vhdl-insert-keyword "QUANTITY ")
9187 (when (vhdl-template-field "[across names]" " " t)
9188 (vhdl-insert-keyword "ACROSS "))
9189 (when (vhdl-template-field "[through names]" " " t)
9190 (vhdl-insert-keyword "THROUGH "))
9191 (vhdl-template-field "plus terminal name")
9192 (setq position (point))
9193 (vhdl-insert-keyword " TO ")
9194 (unless (vhdl-template-field "[minus terminal name]" nil t)
9195 (delete-region position (point)))
9196 (insert ";")
9197 (vhdl-comment-insert-inline)))
9198
9199(defun vhdl-template-quantity-source ()
9200 "Insert a source quantity declaration."
9201 (interactive)
9202 (vhdl-insert-keyword "QUANTITY ")
9203 (vhdl-template-field "names")
9204 (insert " : ")
9205 (vhdl-template-field "type" " ")
9206 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9207 (progn (vhdl-insert-keyword "NOISE ")
9208 (vhdl-template-field "power expression"))
9209 (vhdl-insert-keyword "SPECTRUM ")
9210 (vhdl-template-field "magnitude expression" ", ")
9211 (vhdl-template-field "phase expression"))
9212 (insert ";")
9213 (vhdl-comment-insert-inline))
9214
9215(defun vhdl-template-record (kind &optional name secondary)
d2ddb974
KH
9216 "Insert a record type declaration."
9217 (interactive)
9218 (let ((margin (current-column))
9219 (start (point))
9220 (first t))
9221 (vhdl-insert-keyword "RECORD\n")
9222 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9223 (when (or (vhdl-template-field "element names"
9224 nil (not secondary) start (point))
9225 secondary)
9226 (while (or first (vhdl-template-field "[element names]" nil t))
9227 (insert " : ")
9228 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9229 (vhdl-comment-insert-inline)
9230 (insert "\n")
d2ddb974 9231 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 9232 (setq first nil))
d2ddb974
KH
9233 (kill-line -0)
9234 (indent-to margin)
5eabfe72
KH
9235 (vhdl-insert-keyword "END RECORD")
9236 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9237 (insert ";")
3dcb36b7 9238 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9239
5eabfe72
KH
9240(defun vhdl-template-report ()
9241 "Insert a report statement."
9242 (interactive)
9243 (let ((start (point)))
9244 (vhdl-insert-keyword "REPORT ")
9245 (if (equal "\"\"" (vhdl-template-field
9246 "string expression" nil t start (point) t))
3dcb36b7 9247 (delete-backward-char 2)
5eabfe72
KH
9248 (setq start (point))
9249 (vhdl-insert-keyword " SEVERITY ")
9250 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9251 (delete-region start (point)))
9252 (insert ";"))))
9253
9254(defun vhdl-template-return ()
d2ddb974
KH
9255 "Insert a return statement."
9256 (interactive)
3dcb36b7
JB
9257 (let ((start (point)))
9258 (vhdl-insert-keyword "RETURN ")
9259 (unless (vhdl-template-field "[expression]" nil t start (point))
9260 (delete-char -1))
9261 (insert ";")))
d2ddb974 9262
5eabfe72 9263(defun vhdl-template-selected-signal-asst ()
d2ddb974
KH
9264 "Insert a selected signal assignment."
9265 (interactive)
5eabfe72
KH
9266 (let ((margin (current-indentation))
9267 (start (point))
9268 (choices t))
d2ddb974 9269 (let ((position (point)))
5eabfe72 9270 (vhdl-insert-keyword " SELECT ")
d2ddb974
KH
9271 (goto-char position))
9272 (vhdl-insert-keyword "WITH ")
5eabfe72
KH
9273 (when (vhdl-template-field "selector expression"
9274 nil t start (+ (point) 7))
9275 (forward-word 1)
9276 (delete-char 1)
d2ddb974
KH
9277 (insert "\n")
9278 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9279 (vhdl-template-field "target signal" " <= ")
9280; (vhdl-template-field "[GUARDED] [TRANSPORT]")
d2ddb974
KH
9281 (insert "\n")
9282 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9283 (vhdl-template-field "waveform")
9284 (vhdl-insert-keyword " WHEN ")
9285 (vhdl-template-field "choices" ",")
9286 (insert "\n")
9287 (indent-to (+ margin vhdl-basic-offset))
9288 (while (and choices (vhdl-template-field "[waveform]" nil t))
d2ddb974 9289 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
9290 (if (setq choices (vhdl-template-field "[choices]" "," t))
9291 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9292 (vhdl-insert-keyword "OTHERS")))
9293 (when choices
d2ddb974
KH
9294 (fixup-whitespace)
9295 (delete-char -2))
9296 (insert ";")
3dcb36b7 9297 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9298
5eabfe72 9299(defun vhdl-template-signal ()
d2ddb974
KH
9300 "Insert a signal declaration."
9301 (interactive)
5eabfe72
KH
9302 (let ((start (point))
9303 (in-arglist (vhdl-in-argument-list-p)))
9304 (vhdl-insert-keyword "SIGNAL ")
9305 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9306 (insert " : ")
5eabfe72
KH
9307 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9308 (vhdl-template-field "type")
d2ddb974 9309 (if in-arglist
5eabfe72
KH
9310 (progn (insert ";")
9311 (vhdl-comment-insert-inline))
d2ddb974
KH
9312 (let ((position (point)))
9313 (insert " := ")
5eabfe72
KH
9314 (unless (vhdl-template-field "[initialization]" nil t)
9315 (delete-region position (point)))
9316 (insert ";")
9317 (vhdl-comment-insert-inline))))))
9318
9319(defun vhdl-template-subnature ()
9320 "Insert a subnature declaration."
9321 (interactive)
9322 (let ((start (point))
9323 position)
9324 (vhdl-insert-keyword "SUBNATURE ")
9325 (when (vhdl-template-field "name" nil t start (point))
9326 (vhdl-insert-keyword " IS ")
9327 (vhdl-template-field "nature" " (")
9328 (if (vhdl-template-field "[index range]" nil t)
9329 (insert ")")
9330 (delete-char -2))
9331 (setq position (point))
9332 (vhdl-insert-keyword " TOLERANCE ")
9333 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9334 nil t nil nil t))
9335 (delete-region position (point))
9336 (vhdl-insert-keyword " ACROSS ")
9337 (vhdl-template-field "string expression" nil nil nil nil t)
9338 (vhdl-insert-keyword " THROUGH"))
9339 (insert ";")
9340 (vhdl-comment-insert-inline))))
9341
9342(defun vhdl-template-subprogram-body ()
9343 "Insert a subprogram body."
9344 (interactive)
9345 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9346 (vhdl-template-function-body)
9347 (vhdl-template-procedure-body)))
d2ddb974 9348
5eabfe72
KH
9349(defun vhdl-template-subprogram-decl ()
9350 "Insert a subprogram declaration."
9351 (interactive)
9352 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9353 (vhdl-template-function-decl)
9354 (vhdl-template-procedure-decl)))
9355
9356(defun vhdl-template-subtype ()
d2ddb974
KH
9357 "Insert a subtype declaration."
9358 (interactive)
5eabfe72
KH
9359 (let ((start (point)))
9360 (vhdl-insert-keyword "SUBTYPE ")
9361 (when (vhdl-template-field "name" nil t start (point))
9362 (vhdl-insert-keyword " IS ")
9363 (vhdl-template-field "type" " ")
9364 (unless
9365 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
d2ddb974 9366 (delete-char -1))
5eabfe72
KH
9367 (insert ";")
9368 (vhdl-comment-insert-inline))))
d2ddb974 9369
5eabfe72
KH
9370(defun vhdl-template-terminal ()
9371 "Insert a terminal declaration."
d2ddb974 9372 (interactive)
5eabfe72
KH
9373 (let ((start (point)))
9374 (vhdl-insert-keyword "TERMINAL ")
9375 (when (vhdl-template-field "names" nil t start (point))
9376 (insert " : ")
9377 (vhdl-template-field "nature")
9378 (insert ";")
9379 (vhdl-comment-insert-inline))))
d2ddb974 9380
5eabfe72
KH
9381(defun vhdl-template-type ()
9382 "Insert a type declaration."
9383 (interactive)
9384 (let ((start (point))
9385 name mid-pos end-pos)
9386 (vhdl-insert-keyword "TYPE ")
9387 (when (setq name (vhdl-template-field "name" nil t start (point)))
9388 (vhdl-insert-keyword " IS ")
9389 (let ((definition
9390 (upcase
9391 (or (vhdl-template-field
9392 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9393 ""))))
9394 (cond ((equal definition "")
3dcb36b7 9395 (delete-backward-char 4)
5eabfe72
KH
9396 (insert ";"))
9397 ((equal definition "ARRAY")
9398 (kill-word -1)
9399 (vhdl-template-array 'type t))
9400 ((equal definition "RECORD")
9401 (setq mid-pos (point-marker))
9402 (kill-word -1)
9403 (vhdl-template-record 'type name t))
9404 ((equal definition "ACCESS")
9405 (insert " ")
9406 (vhdl-template-field "type" ";"))
9407 ((equal definition "FILE")
9408 (vhdl-insert-keyword " OF ")
9409 (vhdl-template-field "type" ";"))
9410 (t (insert ";")))
9411 (when mid-pos
9412 (setq end-pos (point-marker))
9413 (goto-char mid-pos)
9414 (end-of-line))
9415 (vhdl-comment-insert-inline)
9416 (when end-pos (goto-char end-pos))))))
9417
9418(defun vhdl-template-use ()
d2ddb974
KH
9419 "Insert a use clause."
9420 (interactive)
3dcb36b7
JB
9421 (let ((start (point)))
9422 (vhdl-prepare-search-1
5eabfe72
KH
9423 (vhdl-insert-keyword "USE ")
9424 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9425 (vhdl-insert-keyword "..ALL;")
9426 (backward-char 6)
9427 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9428 (forward-char 1)
9429 (vhdl-template-field "package name")
9430 (forward-char 5))))))
9431
9432(defun vhdl-template-variable ()
d2ddb974
KH
9433 "Insert a variable declaration."
9434 (interactive)
5eabfe72 9435 (let ((start (point))
5eabfe72 9436 (in-arglist (vhdl-in-argument-list-p)))
3dcb36b7 9437 (vhdl-prepare-search-2
5eabfe72 9438 (if (or (save-excursion
3dcb36b7 9439 (and (vhdl-re-search-backward
5eabfe72
KH
9440 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9441 nil t)
9442 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9443 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9444 (vhdl-insert-keyword "VARIABLE ")
9445 (vhdl-insert-keyword "SHARED VARIABLE ")))
9446 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9447 (insert " : ")
5eabfe72
KH
9448 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9449 (vhdl-template-field "type")
d2ddb974 9450 (if in-arglist
5eabfe72
KH
9451 (progn (insert ";")
9452 (vhdl-comment-insert-inline))
d2ddb974
KH
9453 (let ((position (point)))
9454 (insert " := ")
5eabfe72
KH
9455 (unless (vhdl-template-field "[initialization]" nil t)
9456 (delete-region position (point)))
9457 (insert ";")
9458 (vhdl-comment-insert-inline))))))
d2ddb974 9459
5eabfe72 9460(defun vhdl-template-wait ()
d2ddb974
KH
9461 "Insert a wait statement."
9462 (interactive)
9463 (vhdl-insert-keyword "WAIT ")
5eabfe72
KH
9464 (unless (vhdl-template-field
9465 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9466 nil t)
9467 (delete-char -1))
9468 (insert ";"))
d2ddb974 9469
5eabfe72 9470(defun vhdl-template-when ()
d2ddb974
KH
9471 "Indent correctly if within a case statement."
9472 (interactive)
9473 (let ((position (point))
5eabfe72 9474 margin)
3dcb36b7 9475 (vhdl-prepare-search-2
5eabfe72 9476 (if (and (= (current-column) (current-indentation))
3dcb36b7 9477 (vhdl-re-search-forward "\\<end\\>" nil t)
5eabfe72
KH
9478 (looking-at "\\s-*\\<case\\>"))
9479 (progn
9480 (setq margin (current-indentation))
9481 (goto-char position)
9482 (delete-horizontal-space)
9483 (indent-to (+ margin vhdl-basic-offset)))
9484 (goto-char position)))
9485 (vhdl-insert-keyword "WHEN ")))
9486
9487(defun vhdl-template-while-loop ()
9488 "Insert a while loop."
d2ddb974 9489 (interactive)
5eabfe72
KH
9490 (let* ((margin (current-indentation))
9491 (start (point))
9492 label)
9493 (if (not (eq vhdl-optional-labels 'all))
9494 (vhdl-insert-keyword "WHILE ")
9495 (vhdl-insert-keyword ": WHILE ")
9496 (goto-char start)
9497 (setq label (vhdl-template-field "[label]" nil t))
9498 (unless label (delete-char 2))
9499 (forward-word 1)
9500 (forward-char 1))
9501 (when vhdl-conditions-in-parenthesis (insert "("))
9502 (when (vhdl-template-field "condition" nil t start (point))
9503 (when vhdl-conditions-in-parenthesis (insert ")"))
d2ddb974
KH
9504 (vhdl-insert-keyword " LOOP\n\n")
9505 (indent-to margin)
9506 (vhdl-insert-keyword "END LOOP")
5eabfe72 9507 (insert (if label (concat " " label ";") ";"))
d2ddb974 9508 (forward-line -1)
5eabfe72 9509 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 9510
5eabfe72 9511(defun vhdl-template-with ()
d2ddb974
KH
9512 "Insert a with statement (i.e. selected signal assignment)."
9513 (interactive)
3dcb36b7
JB
9514 (vhdl-prepare-search-1
9515 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9516 (equal ";" (match-string 1)))
9517 (vhdl-template-selected-signal-asst)
9518 (vhdl-insert-keyword "WITH "))))
5eabfe72
KH
9519
9520;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9521;; Special templates
9522
9523(defun vhdl-template-clocked-wait ()
9524 "Insert a wait statement for rising/falling clock edge."
9525 (interactive)
9526 (let ((start (point))
9527 clock)
9528 (vhdl-insert-keyword "WAIT UNTIL ")
9529 (when (setq clock
9530 (or (and (not (equal "" vhdl-clock-name))
9531 (progn (insert vhdl-clock-name) vhdl-clock-name))
9532 (vhdl-template-field "clock name" nil t start (point))))
9533 (insert "'event")
9534 (vhdl-insert-keyword " AND ")
9535 (insert clock)
9536 (insert
9537 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9538 (vhdl-comment-insert-inline
9539 (concat (if vhdl-clock-rising-edge "rising" "falling")
9540 " clock edge")))))
9541
9542(defun vhdl-template-seq-process (clock reset)
9543 "Insert a template for the body of a sequential process."
9544 (let ((margin (current-indentation))
9545 position)
d2ddb974 9546 (vhdl-insert-keyword "IF ")
5eabfe72
KH
9547 (when (eq vhdl-reset-kind 'async)
9548 (insert reset " = "
9549 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9550 (vhdl-insert-keyword " THEN")
9551 (vhdl-comment-insert-inline
9552 (concat "asynchronous reset (active "
9553 (if vhdl-reset-active-high "high" "low") ")"))
9554 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9555 (setq position (point))
9556 (insert "\n") (indent-to margin)
9557 (vhdl-insert-keyword "ELSIF "))
9558 (if (eq vhdl-clock-edge-condition 'function)
9559 (insert (if vhdl-clock-rising-edge "rising" "falling")
9560 "_edge(" clock ")")
9561 (insert clock "'event")
9562 (vhdl-insert-keyword " AND ")
9563 (insert clock " = "
9564 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9565 (vhdl-insert-keyword " THEN")
9566 (vhdl-comment-insert-inline
9567 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9568 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9569 (when (eq vhdl-reset-kind 'sync)
9570 (vhdl-insert-keyword "IF ")
9571 (setq reset (or (and (not (equal "" vhdl-reset-name))
9572 (progn (insert vhdl-reset-name) vhdl-reset-name))
9573 (vhdl-template-field "reset name") "<reset>"))
9574 (insert " = "
9575 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9576 (vhdl-insert-keyword " THEN")
9577 (vhdl-comment-insert-inline
9578 (concat "synchronous reset (active "
9579 (if vhdl-reset-active-high "high" "low") ")"))
9580 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9581 (setq position (point))
9582 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9583 (vhdl-insert-keyword "ELSE")
9584 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9585 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9586 (vhdl-insert-keyword "END IF;"))
9587 (when (eq vhdl-reset-kind 'none)
9588 (setq position (point)))
9589 (insert "\n") (indent-to margin)
d2ddb974 9590 (vhdl-insert-keyword "END IF;")
5eabfe72
KH
9591 (goto-char position)
9592 reset))
d2ddb974 9593
5eabfe72
KH
9594(defun vhdl-template-standard-package (library package)
9595 "Insert specification of a standard package. Include a library
9596specification, if not already there."
3dcb36b7
JB
9597 (let ((margin (current-indentation)))
9598 (unless (equal library "std")
9599 (unless (or (save-excursion
9600 (vhdl-prepare-search-1
9601 (and (not (bobp))
9602 (re-search-backward
9603 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9604 library "\\|end\\)\\>") nil t)
9605 (match-string 2))))
9606 (equal (downcase library) "work"))
9607 (vhdl-insert-keyword "LIBRARY ")
9608 (insert library ";\n")
9609 (indent-to margin))
9610 (vhdl-insert-keyword "USE ")
9611 (insert library "." package)
9612 (vhdl-insert-keyword ".ALL;"))))
d2ddb974 9613
5eabfe72
KH
9614(defun vhdl-template-package-math-complex ()
9615 "Insert specification of `math_complex' package."
d2ddb974 9616 (interactive)
5eabfe72 9617 (vhdl-template-standard-package "ieee" "math_complex"))
d2ddb974 9618
5eabfe72
KH
9619(defun vhdl-template-package-math-real ()
9620 "Insert specification of `math_real' package."
d2ddb974 9621 (interactive)
5eabfe72 9622 (vhdl-template-standard-package "ieee" "math_real"))
d2ddb974 9623
5eabfe72
KH
9624(defun vhdl-template-package-numeric-bit ()
9625 "Insert specification of `numeric_bit' package."
d2ddb974 9626 (interactive)
5eabfe72 9627 (vhdl-template-standard-package "ieee" "numeric_bit"))
d2ddb974 9628
5eabfe72
KH
9629(defun vhdl-template-package-numeric-std ()
9630 "Insert specification of `numeric_std' package."
d2ddb974 9631 (interactive)
5eabfe72 9632 (vhdl-template-standard-package "ieee" "numeric_std"))
d2ddb974 9633
5eabfe72
KH
9634(defun vhdl-template-package-std-logic-1164 ()
9635 "Insert specification of `std_logic_1164' package."
9636 (interactive)
9637 (vhdl-template-standard-package "ieee" "std_logic_1164"))
d2ddb974 9638
5eabfe72
KH
9639(defun vhdl-template-package-std-logic-arith ()
9640 "Insert specification of `std_logic_arith' package."
9641 (interactive)
9642 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9643
9644(defun vhdl-template-package-std-logic-misc ()
9645 "Insert specification of `std_logic_misc' package."
9646 (interactive)
9647 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9648
9649(defun vhdl-template-package-std-logic-signed ()
9650 "Insert specification of `std_logic_signed' package."
9651 (interactive)
9652 (vhdl-template-standard-package "ieee" "std_logic_signed"))
d2ddb974 9653
5eabfe72
KH
9654(defun vhdl-template-package-std-logic-textio ()
9655 "Insert specification of `std_logic_textio' package."
9656 (interactive)
9657 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9658
9659(defun vhdl-template-package-std-logic-unsigned ()
9660 "Insert specification of `std_logic_unsigned' package."
9661 (interactive)
9662 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9663
9664(defun vhdl-template-package-textio ()
9665 "Insert specification of `textio' package."
9666 (interactive)
9667 (vhdl-template-standard-package "std" "textio"))
9668
9669(defun vhdl-template-directive (directive)
9670 "Insert directive."
9671 (unless (= (current-indentation) (current-column))
9672 (delete-horizontal-space)
9673 (insert " "))
9674 (insert "-- pragma " directive))
9675
9676(defun vhdl-template-directive-translate-on ()
9677 "Insert directive 'translate_on'."
9678 (interactive)
9679 (vhdl-template-directive "translate_on"))
9680
9681(defun vhdl-template-directive-translate-off ()
9682 "Insert directive 'translate_off'."
9683 (interactive)
9684 (vhdl-template-directive "translate_off"))
9685
9686(defun vhdl-template-directive-synthesis-on ()
9687 "Insert directive 'synthesis_on'."
9688 (interactive)
9689 (vhdl-template-directive "synthesis_on"))
9690
9691(defun vhdl-template-directive-synthesis-off ()
9692 "Insert directive 'synthesis_off'."
9693 (interactive)
9694 (vhdl-template-directive "synthesis_off"))
9695
3dcb36b7
JB
9696;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9697;; Header and footer templates
9698
9699(defun vhdl-template-header (&optional file-title)
9700 "Insert a VHDL file header."
9701 (interactive)
9702 (unless (equal vhdl-file-header "")
9703 (let (pos)
9704 (save-excursion
9705 (goto-char (point-min))
9706 (vhdl-insert-string-or-file vhdl-file-header)
9707 (setq pos (point-marker)))
9708 (vhdl-template-replace-header-keywords
9709 (point-min-marker) pos file-title))))
9710
9711(defun vhdl-template-footer ()
9712 "Insert a VHDL file footer."
9713 (interactive)
9714 (unless (equal vhdl-file-footer "")
9715 (let (pos)
9716 (save-excursion
9717 (goto-char (point-max))
9718 (setq pos (point-marker))
9719 (vhdl-insert-string-or-file vhdl-file-footer)
9720 (unless (= (preceding-char) ?\n)
9721 (insert "\n")))
9722 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9723
9724(defun vhdl-template-replace-header-keywords (beg end &optional file-title
9725 is-model)
9726 "Replace keywords in header and footer."
9727 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9728 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9729 pos)
9730 (vhdl-prepare-search-2
9731 (save-excursion
9732 (goto-char beg)
9733 (while (search-forward "<projectdesc>" end t)
9734 (replace-match project-desc t t))
9735 (goto-char beg)
9736 (while (search-forward "<filename>" end t)
9737 (replace-match (buffer-name) t t))
9738 (goto-char beg)
9739 (while (search-forward "<copyright>" end t)
9740 (replace-match vhdl-copyright-string t t))
9741 (goto-char beg)
9742 (while (search-forward "<author>" end t)
9743 (replace-match "" t t)
9744 (insert (user-full-name))
9745 (when user-mail-address (insert " <" user-mail-address ">")))
9746 (goto-char beg)
9747 (while (search-forward "<login>" end t)
9748 (replace-match (user-login-name) t t))
9749 (goto-char beg)
9750 (while (search-forward "<project>" end t)
9751 (replace-match project-title t t))
9752 (goto-char beg)
9753 (while (search-forward "<company>" end t)
9754 (replace-match vhdl-company-name t t))
9755 (goto-char beg)
9756 (while (search-forward "<platform>" end t)
9757 (replace-match vhdl-platform-spec t t))
9758 (goto-char beg)
9759 (while (search-forward "<standard>" end t)
9760 (replace-match
9761 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9762 ((vhdl-standard-p '93) "'93"))
9763 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9764 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9765 (goto-char beg)
9766 ;; Replace <RCS> with $, so that RCS for the source is
9767 ;; not over-enthusiastic with replacements
9768 (while (search-forward "<RCS>" end t)
9769 (replace-match "$" nil t))
9770 (goto-char beg)
9771 (while (search-forward "<date>" end t)
9772 (replace-match "" t t)
9773 (vhdl-template-insert-date))
9774 (goto-char beg)
9775 (while (search-forward "<year>" end t)
9776 (replace-match (format-time-string "%Y" nil) t t))
9777 (goto-char beg)
9778 (when file-title
9779 (while (search-forward "<title string>" end t)
9780 (replace-match file-title t t))
9781 (goto-char beg))
9782 (let (string)
9783 (while
9784 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9785 (setq string (read-string (concat (match-string 1) ": ")))
9786 (replace-match string t t)))
9787 (goto-char beg)
9788 (when (and (not is-model) (search-forward "<cursor>" end t))
9789 (replace-match "" t t)
9790 (setq pos (point))))
9791 (when pos (goto-char pos))
9792 (unless is-model
9793 (when (or (not project-title) (equal project-title ""))
9794 (message "You can specify a project title in user option `vhdl-project-alist'"))
9795 (when (or (not project-desc) (equal project-desc ""))
9796 (message "You can specify a project description in user option `vhdl-project-alist'"))
9797 (when (equal vhdl-platform-spec "")
9798 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9799 (when (equal vhdl-company-name "")
9800 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9801
5eabfe72
KH
9802;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9803;; Comment templates and functions
9804
9805(defun vhdl-comment-indent ()
9806 "Indent comments."
9807 (let* ((position (point))
9808 (col
9809 (progn
9810 (forward-line -1)
9811 (if (re-search-forward "--" position t)
9812 (- (current-column) 2) ; existing comment at bol stays there
9813 (goto-char position)
9814 (skip-chars-backward " \t")
9815 (max comment-column ; else indent to comment column
9816 (1+ (current-column))))))) ; except leave at least one space
9817 (goto-char position)
9818 col))
9819
9820(defun vhdl-comment-insert ()
d2ddb974 9821 "Start a comment at the end of the line.
5eabfe72
KH
9822If on line with code, indent at least `comment-column'.
9823If starting after end-comment-column, start a new line."
d2ddb974 9824 (interactive)
5eabfe72
KH
9825 (when (> (current-column) end-comment-column) (newline-and-indent))
9826 (if (or (looking-at "\\s-*$") ; end of line
d2ddb974
KH
9827 (and (not unread-command-events) ; called with key binding or menu
9828 (not (end-of-line))))
5eabfe72
KH
9829 (let (margin)
9830 (while (= (preceding-char) ?-) (delete-char -1))
d2ddb974 9831 (setq margin (current-column))
5eabfe72
KH
9832 (delete-horizontal-space)
9833 (if (bolp)
9834 (progn (indent-to margin) (insert "--"))
d2ddb974 9835 (insert " ")
5eabfe72
KH
9836 (indent-to comment-column)
9837 (insert "--"))
d2ddb974 9838 (if (not unread-command-events) (insert " ")))
5eabfe72 9839 ;; else code following current point implies commenting out code
d2ddb974
KH
9840 (let (next-input code)
9841 (while (= (preceding-char) ?-) (delete-char -2))
9842 (while (= (setq next-input (read-char)) 13) ; CR
5eabfe72 9843 (insert "--") ; or have a space after it?
d2ddb974
KH
9844 (forward-char -2)
9845 (forward-line 1)
9846 (message "Enter CR if commenting out a line of code.")
5eabfe72 9847 (setq code t))
3dcb36b7 9848 (unless code
5eabfe72 9849 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
d2ddb974 9850 (setq unread-command-events
5eabfe72 9851 (list (vhdl-character-to-event next-input)))))) ; pushback the char
d2ddb974 9852
5eabfe72 9853(defun vhdl-comment-display (&optional line-exists)
d2ddb974
KH
9854 "Add 2 comment lines at the current indent, making a display comment."
9855 (interactive)
5eabfe72 9856 (let ((margin (current-indentation)))
3dcb36b7 9857 (unless line-exists (vhdl-comment-display-line))
5eabfe72
KH
9858 (insert "\n") (indent-to margin)
9859 (insert "\n") (indent-to margin)
9860 (vhdl-comment-display-line)
9861 (end-of-line -0)
9862 (insert "-- ")))
9863
9864(defun vhdl-comment-display-line ()
d2ddb974
KH
9865 "Displays one line of dashes."
9866 (interactive)
9867 (while (= (preceding-char) ?-) (delete-char -2))
9868 (let* ((col (current-column))
9869 (len (- end-comment-column col)))
5eabfe72 9870 (insert-char ?- len)))
d2ddb974 9871
5eabfe72
KH
9872(defun vhdl-comment-append-inline ()
9873 "Append empty inline comment to current line."
9874 (interactive)
9875 (end-of-line)
9876 (delete-horizontal-space)
9877 (insert " ")
9878 (indent-to comment-column)
9879 (insert "-- "))
9880
9881(defun vhdl-comment-insert-inline (&optional string always-insert)
9882 "Insert inline comment."
9883 (when (or (and string (or vhdl-self-insert-comments always-insert))
9884 (and (not string) vhdl-prompt-for-comments))
9885 (let ((position (point)))
9886 (insert " ")
9887 (indent-to comment-column)
9888 (insert "-- ")
3dcb36b7
JB
9889 (if (not (or (and string (progn (insert string) t))
9890 (vhdl-template-field "[comment]" nil t)))
9891 (delete-region position (point))
9892 (while (= (preceding-char) ? ) (delete-backward-char 1))
9893; (when (> (current-column) end-comment-column)
9894; (setq position (point-marker))
9895; (re-search-backward "-- ")
9896; (insert "\n")
9897; (indent-to comment-column)
9898; (goto-char position))
9899 ))))
5eabfe72
KH
9900
9901(defun vhdl-comment-block ()
9902 "Insert comment for code block."
9903 (when vhdl-prompt-for-comments
3dcb36b7
JB
9904 (let ((final-pos (point-marker)))
9905 (vhdl-prepare-search-2
5eabfe72 9906 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
3dcb36b7 9907 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
5eabfe72
KH
9908 (let (margin)
9909 (back-to-indentation)
9910 (setq margin (current-column))
9911 (end-of-line -0)
9912 (if (bobp)
9913 (progn (insert "\n") (forward-line -1))
9914 (insert "\n"))
9915 (indent-to margin)
9916 (insert "-- purpose: ")
9917 (unless (vhdl-template-field "[description]" nil t)
9918 (vhdl-line-kill-entire)))))
9919 (goto-char final-pos))))
d2ddb974
KH
9920
9921(defun vhdl-comment-uncomment-region (beg end &optional arg)
5eabfe72 9922 "Comment out region if not commented out, uncomment otherwise."
d2ddb974 9923 (interactive "r\nP")
5eabfe72
KH
9924 (save-excursion
9925 (goto-char (1- end))
9926 (end-of-line)
9927 (setq end (point-marker))
9928 (goto-char beg)
9929 (beginning-of-line)
9930 (setq beg (point))
9931 (if (looking-at comment-start)
3dcb36b7 9932 (comment-region beg end '(4))
5eabfe72
KH
9933 (comment-region beg end))))
9934
9935(defun vhdl-comment-uncomment-line (&optional arg)
9936 "Comment out line if not commented out, uncomment otherwise."
d2ddb974 9937 (interactive "p")
5eabfe72
KH
9938 (save-excursion
9939 (beginning-of-line)
9940 (let ((position (point)))
9941 (forward-line (or arg 1))
9942 (vhdl-comment-uncomment-region position (point)))))
d2ddb974 9943
5eabfe72
KH
9944(defun vhdl-comment-kill-region (beg end)
9945 "Kill comments in region."
9946 (interactive "r")
9947 (save-excursion
9948 (goto-char end)
9949 (setq end (point-marker))
9950 (goto-char beg)
9951 (beginning-of-line)
9952 (while (< (point) end)
9953 (if (looking-at "^\\(\\s-*--.*\n\\)")
9954 (progn (delete-region (match-beginning 1) (match-end 1)))
9955 (beginning-of-line 2)))))
9956
9957(defun vhdl-comment-kill-inline-region (beg end)
9958 "Kill inline comments in region."
9959 (interactive "r")
9960 (save-excursion
9961 (goto-char end)
9962 (setq end (point-marker))
9963 (goto-char beg)
9964 (beginning-of-line)
9965 (while (< (point) end)
9966 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
9967 (delete-region (match-beginning 1) (match-end 1)))
9968 (beginning-of-line 2))))
9969
9970;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9971;; Subtemplates
9972
9973(defun vhdl-template-begin-end (construct name margin &optional empty-lines)
d2ddb974
KH
9974 "Insert a begin ... end pair with optional name after the end.
9975Point is left between them."
5eabfe72 9976 (let (position)
5eabfe72 9977 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
9978 (indent-to margin)
9979 (vhdl-insert-keyword "BEGIN")
5eabfe72
KH
9980 (when (and (or construct name) vhdl-self-insert-comments)
9981 (insert " --")
9982 (when construct (insert " ") (vhdl-insert-keyword construct))
9983 (when name (insert " " name)))
d2ddb974 9984 (insert "\n")
5eabfe72 9985 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974 9986 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9987 (setq position (point))
9988 (insert "\n")
9989 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
9990 (indent-to margin)
9991 (vhdl-insert-keyword "END")
5eabfe72
KH
9992 (when construct (insert " ") (vhdl-insert-keyword construct))
9993 (insert (if name (concat " " name) "") ";")
9994 (goto-char position)))
d2ddb974 9995
5eabfe72 9996(defun vhdl-template-argument-list (&optional is-function)
d2ddb974
KH
9997 "Read from user a procedure or function argument list."
9998 (insert " (")
d2ddb974 9999 (let ((margin (current-column))
5eabfe72
KH
10000 (start (point))
10001 (end-pos (point))
10002 not-empty interface semicolon-pos)
3dcb36b7 10003 (unless vhdl-argument-list-indent
5eabfe72
KH
10004 (setq margin (+ (current-indentation) vhdl-basic-offset))
10005 (insert "\n")
10006 (indent-to margin))
10007 (setq interface (vhdl-template-field
10008 (concat "[CONSTANT | SIGNAL"
10009 (unless is-function " | VARIABLE") "]") " " t))
10010 (while (vhdl-template-field "[names]" nil t)
10011 (setq not-empty t)
10012 (insert " : ")
3dcb36b7 10013 (unless is-function
5eabfe72
KH
10014 (if (and interface (equal (upcase interface) "CONSTANT"))
10015 (vhdl-insert-keyword "IN ")
10016 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10017 (vhdl-template-field "type")
10018 (setq semicolon-pos (point))
10019 (insert ";")
10020 (vhdl-comment-insert-inline)
10021 (setq end-pos (point))
10022 (insert "\n")
10023 (indent-to margin)
10024 (setq interface (vhdl-template-field
10025 (concat "[CONSTANT | SIGNAL"
10026 (unless is-function " | VARIABLE") "]") " " t)))
10027 (delete-region end-pos (point))
10028 (when semicolon-pos (goto-char semicolon-pos))
10029 (if not-empty
10030 (progn (delete-char 1) (insert ")"))
3dcb36b7 10031 (delete-backward-char 2))))
5eabfe72
KH
10032
10033(defun vhdl-template-generic-list (optional &optional no-value)
d2ddb974 10034 "Read from user a generic spec argument list."
5eabfe72 10035 (let (margin
d2ddb974 10036 (start (point)))
5eabfe72
KH
10037 (vhdl-insert-keyword "GENERIC (")
10038 (setq margin (current-column))
3dcb36b7 10039 (unless vhdl-argument-list-indent
5eabfe72
KH
10040 (let ((position (point)))
10041 (back-to-indentation)
10042 (setq margin (+ (current-column) vhdl-basic-offset))
10043 (goto-char position)
10044 (insert "\n")
10045 (indent-to margin)))
10046 (let ((vhdl-generics (vhdl-template-field
10047 (concat (and optional "[") "name"
10048 (and no-value "s") (and optional "]"))
10049 nil optional)))
10050 (if (not vhdl-generics)
d2ddb974 10051 (if optional
5eabfe72 10052 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10053 (unless vhdl-argument-list-indent
5eabfe72
KH
10054 (vhdl-line-kill-entire) (end-of-line -0)))
10055 (vhdl-template-undo start (point))
d2ddb974
KH
10056 nil )
10057 (insert " : ")
5eabfe72
KH
10058 (let (semicolon-pos end-pos)
10059 (while vhdl-generics
10060 (vhdl-template-field "type")
10061 (if no-value
10062 (progn (setq semicolon-pos (point))
10063 (insert ";"))
10064 (insert " := ")
10065 (unless (vhdl-template-field "[value]" nil t)
10066 (delete-char -4))
10067 (setq semicolon-pos (point))
10068 (insert ";"))
10069 (vhdl-comment-insert-inline)
10070 (setq end-pos (point))
10071 (insert "\n")
10072 (indent-to margin)
10073 (setq vhdl-generics (vhdl-template-field
10074 (concat "[name" (and no-value "s") "]")
10075 " : " t)))
10076 (delete-region end-pos (point))
10077 (goto-char semicolon-pos)
10078 (insert ")")
10079 (end-of-line)
3dcb36b7 10080 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
10081 t)))))
10082
10083(defun vhdl-template-port-list (optional)
10084 "Read from user a port spec argument list."
10085 (let ((start (point))
10086 margin vhdl-ports object)
10087 (vhdl-insert-keyword "PORT (")
10088 (setq margin (current-column))
3dcb36b7 10089 (unless vhdl-argument-list-indent
5eabfe72
KH
10090 (let ((position (point)))
10091 (back-to-indentation)
10092 (setq margin (+ (current-column) vhdl-basic-offset))
10093 (goto-char position)
10094 (insert "\n")
10095 (indent-to margin)))
10096 (when (vhdl-standard-p 'ams)
10097 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10098 " " t)))
10099 (setq vhdl-ports (vhdl-template-field
10100 (concat (and optional "[") "names" (and optional "]"))
10101 nil optional))
10102 (if (not vhdl-ports)
10103 (if optional
10104 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10105 (unless vhdl-argument-list-indent
5eabfe72
KH
10106 (vhdl-line-kill-entire) (end-of-line -0)))
10107 (vhdl-template-undo start (point))
10108 nil)
10109 (insert " : ")
10110 (let (semicolon-pos end-pos)
10111 (while vhdl-ports
10112 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10113 (vhdl-template-field "IN | OUT | INOUT" " "))
10114 ((equal "QUANTITY" (upcase object))
10115 (vhdl-template-field "[IN | OUT]" " " t)))
10116 (vhdl-template-field
10117 (if (and object (equal "TERMINAL" (upcase object)))
10118 "nature" "type"))
10119 (setq semicolon-pos (point))
10120 (insert ";")
10121 (vhdl-comment-insert-inline)
10122 (setq end-pos (point))
10123 (insert "\n")
10124 (indent-to margin)
10125 (when (vhdl-standard-p 'ams)
10126 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10127 " " t)))
10128 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10129 (delete-region end-pos (point))
10130 (goto-char semicolon-pos)
10131 (insert ")")
10132 (end-of-line)
3dcb36b7 10133 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
5eabfe72
KH
10134 t))))
10135
10136(defun vhdl-template-generate-body (margin label)
10137 "Insert body for generate template."
10138 (vhdl-insert-keyword " GENERATE")
3dcb36b7
JB
10139; (if (not (vhdl-standard-p '87))
10140; (vhdl-template-begin-end "GENERATE" label margin)
10141 (insert "\n\n")
10142 (indent-to margin)
10143 (vhdl-insert-keyword "END GENERATE ")
10144 (insert label ";")
10145 (end-of-line 0)
10146 (indent-to (+ margin vhdl-basic-offset)))
5eabfe72
KH
10147
10148(defun vhdl-template-insert-date ()
d2ddb974
KH
10149 "Insert date in appropriate format."
10150 (interactive)
5eabfe72
KH
10151 (insert
10152 (cond
3dcb36b7 10153 ;; 'american, 'european, 'scientific kept for backward compatibility
5eabfe72
KH
10154 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10155 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10156 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10157 (t (format-time-string vhdl-date-format nil)))))
10158
10159;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10160;; Help functions
10161
10162(defun vhdl-electric-space (count)
10163 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10164if in comment and past end-comment-column."
10165 (interactive "p")
10166 (cond ((vhdl-in-comment-p)
10167 (self-insert-command count)
10168 (cond ((>= (current-column) (+ 2 end-comment-column))
3dcb36b7
JB
10169 (backward-char 1)
10170 (skip-chars-backward "^ \t\n")
5eabfe72 10171 (indent-new-comment-line)
3dcb36b7 10172 (skip-chars-forward "^ \t\n")
5eabfe72
KH
10173 (forward-char 1))
10174 ((>= (current-column) end-comment-column)
10175 (indent-new-comment-line))
10176 (t nil)))
10177 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10178 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
3dcb36b7
JB
10179 (vhdl-prepare-search-1
10180 (or (expand-abbrev) (vhdl-fix-case-word -1)))
5eabfe72
KH
10181 (self-insert-command count))
10182 (t (self-insert-command count))))
10183
10184(defun vhdl-template-field (prompt &optional follow-string optional
10185 begin end is-string default)
10186 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10187If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10188an empty string is inserted, return nil and call `vhdl-template-undo' for
10189the region between BEGIN and END. IS-STRING indicates whether a string
10190with double-quotes is to be inserted. DEFAULT specifies a default string."
10191 (let ((position (point))
10192 string)
10193 (insert "<" prompt ">")
10194 (setq string
10195 (condition-case ()
10196 (read-from-minibuffer (concat prompt ": ")
10197 (or (and is-string '("\"\"" . 2)) default)
10198 vhdl-minibuffer-local-map)
10199 (quit (if (and optional begin end)
10200 (progn (beep) "")
10201 (keyboard-quit)))))
10202 (when (or (not (equal string "")) optional)
10203 (delete-region position (point)))
10204 (when (and (equal string "") optional begin end)
10205 (vhdl-template-undo begin end)
10206 (message "Template aborted"))
3dcb36b7 10207 (unless (equal string "")
5eabfe72
KH
10208 (insert string)
10209 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
3dcb36b7
JB
10210 vhdl-keywords-regexp)
10211 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10212 vhdl-types-regexp)
10213 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10214 (concat "'" vhdl-attributes-regexp))
10215 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10216 vhdl-enum-values-regexp))
5eabfe72
KH
10217 (when (or (not (equal string "")) (not optional))
10218 (insert (or follow-string "")))
10219 (if (equal string "") nil string)))
10220
10221(defun vhdl-decision-query (string prompt &optional optional)
10222 "Query a decision from the user."
10223 (let ((start (point)))
10224 (when string (vhdl-insert-keyword (concat string " ")))
10225 (message prompt)
10226 (let ((char (read-char)))
10227 (delete-region start (point))
10228 (if (and optional (eq char ?\r))
10229 (progn (insert " ")
10230 (unexpand-abbrev)
3dcb36b7 10231 (throw 'abort "ERROR: Template aborted"))
5eabfe72 10232 char))))
d2ddb974
KH
10233
10234(defun vhdl-insert-keyword (keyword)
5eabfe72
KH
10235 "Insert KEYWORD and adjust case."
10236 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
d2ddb974
KH
10237
10238(defun vhdl-case-keyword (keyword)
5eabfe72
KH
10239 "Adjust case of KEYWORD."
10240 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
d2ddb974
KH
10241
10242(defun vhdl-case-word (num)
5eabfe72
KH
10243 "Adjust case or following NUM words."
10244 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10245
10246(defun vhdl-minibuffer-tab (&optional prefix-arg)
10247 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7 10248else insert tab (used for word completion in VHDL minibuffer)."
5eabfe72 10249 (interactive "P")
3dcb36b7
JB
10250 (cond
10251 ;; expand word
10252 ((= (char-syntax (preceding-char)) ?w)
10253 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10254 (case-replace nil)
10255 (hippie-expand-only-buffers
10256 (or (and (boundp 'hippie-expand-only-buffers)
10257 hippie-expand-only-buffers)
10258 '(vhdl-mode))))
10259 (vhdl-expand-abbrev prefix-arg)))
10260 ;; expand parenthesis
10261 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10262 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10263 (case-replace nil))
10264 (vhdl-expand-paren prefix-arg)))
10265 ;; insert tab
10266 (t (insert-tab))))
5eabfe72
KH
10267
10268(defun vhdl-template-search-prompt ()
10269 "Search for left out template prompts and query again."
10270 (interactive)
3dcb36b7
JB
10271 (vhdl-prepare-search-2
10272 (when (or (re-search-forward
10273 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10274 (re-search-backward
10275 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10276 (let ((string (match-string 1)))
10277 (replace-match "")
10278 (vhdl-template-field string)))))
5eabfe72
KH
10279
10280(defun vhdl-template-undo (begin end)
10281 "Undo aborted template by deleting region and unexpanding the keyword."
10282 (cond (vhdl-template-invoked-by-hook
10283 (goto-char end)
10284 (insert " ")
10285 (delete-region begin end)
10286 (unexpand-abbrev))
10287 (t (delete-region begin end))))
10288
10289(defun vhdl-insert-string-or-file (string)
10290 "Insert STRING or file contents if STRING is an existing file name."
10291 (unless (equal string "")
3dcb36b7
JB
10292 (let ((file-name
10293 (progn (string-match "^\\([^\n]+\\)" string)
10294 (vhdl-resolve-env-variable (match-string 1 string)))))
10295 (if (file-exists-p file-name)
10296 (forward-char (cadr (insert-file-contents file-name)))
10297 (insert string)))))
10298
10299(defun vhdl-beginning-of-block ()
10300 "Move cursor to the beginning of the enclosing block."
10301 (let (pos)
10302 (save-excursion
10303 (beginning-of-line)
10304 ;; search backward for block beginning or end
10305 (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))
10306 ;; not consider subprogram declarations
10307 (or (and (match-string 5)
10308 (save-match-data
10309 (save-excursion
10310 (goto-char (match-end 5))
10311 (forward-word 1) (forward-sexp)
10312 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10313 (match-string 1)))
10314 ;; not consider configuration specifications
10315 (and (match-string 6)
10316 (save-match-data
10317 (save-excursion
10318 (vhdl-end-of-block)
10319 (beginning-of-line)
10320 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10321 (match-string 2))
10322 ;; skip subblock if block end found
10323 (vhdl-beginning-of-block)))
10324 (when pos (goto-char pos))))
10325
10326(defun vhdl-end-of-block ()
10327 "Move cursor to the end of the enclosing block."
10328 (let (pos)
10329 (save-excursion
10330 (end-of-line)
10331 ;; search forward for block beginning or end
10332 (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))
10333 ;; not consider subprogram declarations
10334 (or (and (match-string 5)
10335 (save-match-data
10336 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10337 (match-string 1)))
10338 ;; not consider configuration specifications
10339 (and (match-string 6)
10340 (save-match-data
10341 (save-excursion
10342 (vhdl-end-of-block)
10343 (beginning-of-line)
10344 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10345 (not (match-string 2)))
10346 ;; skip subblock if block beginning found
10347 (vhdl-end-of-block)))
10348 (when pos (goto-char pos))))
5eabfe72
KH
10349
10350(defun vhdl-sequential-statement-p ()
10351 "Check if point is within sequential statement part."
3dcb36b7
JB
10352 (let ((start (point)))
10353 (save-excursion
10354 (vhdl-prepare-search-2
10355 ;; is sequential statement if ...
10356 (and (re-search-backward "^\\s-*begin\\>" nil t)
10357 ;; ... point is between "begin" and "end" of ...
10358 (progn (vhdl-end-of-block)
10359 (< start (point)))
10360 ;; ... a sequential block
10361 (progn (vhdl-beginning-of-block)
10362 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
5eabfe72
KH
10363
10364(defun vhdl-in-argument-list-p ()
10365 "Check if within an argument list."
10366 (save-excursion
3dcb36b7
JB
10367 (vhdl-prepare-search-2
10368 (or (string-match "arglist"
10369 (format "%s" (caar (vhdl-get-syntactic-context))))
10370 (progn (beginning-of-line)
10371 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
5eabfe72
KH
10372
10373;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10374;; Abbrev hooks
10375
10376(defun vhdl-hooked-abbrev (func)
10377 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10378but not if inside a comment or quote)."
3dcb36b7 10379 (if (or (vhdl-in-literal)
5eabfe72
KH
10380 (save-excursion
10381 (forward-word -1)
10382 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10383 (progn
10384 (insert " ")
10385 (unexpand-abbrev)
10386 (delete-char -1))
10387 (if (not vhdl-electric-mode)
10388 (progn
10389 (insert " ")
10390 (unexpand-abbrev)
10391 (backward-word 1)
10392 (vhdl-case-word 1)
10393 (delete-char 1))
10394 (let ((invoke-char last-command-char)
10395 (abbrev-mode -1)
10396 (vhdl-template-invoked-by-hook t))
10397 (let ((caught (catch 'abort
10398 (funcall func))))
10399 (when (stringp caught) (message caught)))
10400 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10401 ;; delete CR which is still in event queue
3dcb36b7 10402 (if vhdl-xemacs
5eabfe72
KH
10403 (enqueue-eval-event 'delete-char -1)
10404 (setq unread-command-events ; push back a delete char
10405 (list (vhdl-character-to-event ?\177))))))))
10406
10407(defun vhdl-template-alias-hook ()
10408 (vhdl-hooked-abbrev 'vhdl-template-alias))
10409(defun vhdl-template-architecture-hook ()
10410 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10411(defun vhdl-template-assert-hook ()
10412 (vhdl-hooked-abbrev 'vhdl-template-assert))
10413(defun vhdl-template-attribute-hook ()
10414 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10415(defun vhdl-template-block-hook ()
10416 (vhdl-hooked-abbrev 'vhdl-template-block))
10417(defun vhdl-template-break-hook ()
10418 (vhdl-hooked-abbrev 'vhdl-template-break))
10419(defun vhdl-template-case-hook ()
10420 (vhdl-hooked-abbrev 'vhdl-template-case))
10421(defun vhdl-template-component-hook ()
10422 (vhdl-hooked-abbrev 'vhdl-template-component))
10423(defun vhdl-template-instance-hook ()
10424 (vhdl-hooked-abbrev 'vhdl-template-instance))
10425(defun vhdl-template-conditional-signal-asst-hook ()
10426 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10427(defun vhdl-template-configuration-hook ()
10428 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10429(defun vhdl-template-constant-hook ()
10430 (vhdl-hooked-abbrev 'vhdl-template-constant))
10431(defun vhdl-template-disconnect-hook ()
10432 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10433(defun vhdl-template-display-comment-hook ()
10434 (vhdl-hooked-abbrev 'vhdl-comment-display))
10435(defun vhdl-template-else-hook ()
10436 (vhdl-hooked-abbrev 'vhdl-template-else))
10437(defun vhdl-template-elsif-hook ()
10438 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10439(defun vhdl-template-entity-hook ()
10440 (vhdl-hooked-abbrev 'vhdl-template-entity))
10441(defun vhdl-template-exit-hook ()
10442 (vhdl-hooked-abbrev 'vhdl-template-exit))
10443(defun vhdl-template-file-hook ()
10444 (vhdl-hooked-abbrev 'vhdl-template-file))
10445(defun vhdl-template-for-hook ()
10446 (vhdl-hooked-abbrev 'vhdl-template-for))
10447(defun vhdl-template-function-hook ()
10448 (vhdl-hooked-abbrev 'vhdl-template-function))
10449(defun vhdl-template-generic-hook ()
10450 (vhdl-hooked-abbrev 'vhdl-template-generic))
10451(defun vhdl-template-group-hook ()
10452 (vhdl-hooked-abbrev 'vhdl-template-group))
10453(defun vhdl-template-library-hook ()
10454 (vhdl-hooked-abbrev 'vhdl-template-library))
10455(defun vhdl-template-limit-hook ()
10456 (vhdl-hooked-abbrev 'vhdl-template-limit))
10457(defun vhdl-template-if-hook ()
10458 (vhdl-hooked-abbrev 'vhdl-template-if))
10459(defun vhdl-template-bare-loop-hook ()
10460 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10461(defun vhdl-template-map-hook ()
10462 (vhdl-hooked-abbrev 'vhdl-template-map))
10463(defun vhdl-template-nature-hook ()
10464 (vhdl-hooked-abbrev 'vhdl-template-nature))
10465(defun vhdl-template-next-hook ()
10466 (vhdl-hooked-abbrev 'vhdl-template-next))
3dcb36b7
JB
10467(defun vhdl-template-others-hook ()
10468 (vhdl-hooked-abbrev 'vhdl-template-others))
5eabfe72
KH
10469(defun vhdl-template-package-hook ()
10470 (vhdl-hooked-abbrev 'vhdl-template-package))
10471(defun vhdl-template-port-hook ()
10472 (vhdl-hooked-abbrev 'vhdl-template-port))
10473(defun vhdl-template-procedural-hook ()
10474 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10475(defun vhdl-template-procedure-hook ()
10476 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10477(defun vhdl-template-process-hook ()
10478 (vhdl-hooked-abbrev 'vhdl-template-process))
10479(defun vhdl-template-quantity-hook ()
10480 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10481(defun vhdl-template-report-hook ()
10482 (vhdl-hooked-abbrev 'vhdl-template-report))
10483(defun vhdl-template-return-hook ()
10484 (vhdl-hooked-abbrev 'vhdl-template-return))
10485(defun vhdl-template-selected-signal-asst-hook ()
10486 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10487(defun vhdl-template-signal-hook ()
10488 (vhdl-hooked-abbrev 'vhdl-template-signal))
10489(defun vhdl-template-subnature-hook ()
10490 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10491(defun vhdl-template-subtype-hook ()
10492 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10493(defun vhdl-template-terminal-hook ()
10494 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10495(defun vhdl-template-type-hook ()
10496 (vhdl-hooked-abbrev 'vhdl-template-type))
10497(defun vhdl-template-use-hook ()
10498 (vhdl-hooked-abbrev 'vhdl-template-use))
10499(defun vhdl-template-variable-hook ()
10500 (vhdl-hooked-abbrev 'vhdl-template-variable))
10501(defun vhdl-template-wait-hook ()
10502 (vhdl-hooked-abbrev 'vhdl-template-wait))
10503(defun vhdl-template-when-hook ()
10504 (vhdl-hooked-abbrev 'vhdl-template-when))
10505(defun vhdl-template-while-loop-hook ()
10506 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10507(defun vhdl-template-with-hook ()
10508 (vhdl-hooked-abbrev 'vhdl-template-with))
10509(defun vhdl-template-and-hook ()
10510 (vhdl-hooked-abbrev 'vhdl-template-and))
10511(defun vhdl-template-or-hook ()
10512 (vhdl-hooked-abbrev 'vhdl-template-or))
10513(defun vhdl-template-nand-hook ()
10514 (vhdl-hooked-abbrev 'vhdl-template-nand))
10515(defun vhdl-template-nor-hook ()
10516 (vhdl-hooked-abbrev 'vhdl-template-nor))
10517(defun vhdl-template-xor-hook ()
10518 (vhdl-hooked-abbrev 'vhdl-template-xor))
10519(defun vhdl-template-xnor-hook ()
10520 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10521(defun vhdl-template-not-hook ()
10522 (vhdl-hooked-abbrev 'vhdl-template-not))
10523
10524(defun vhdl-template-default-hook ()
10525 (vhdl-hooked-abbrev 'vhdl-template-default))
10526(defun vhdl-template-default-indent-hook ()
10527 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10528
10529;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10530;; Template insertion from completion list
10531
10532(defun vhdl-template-insert-construct (name)
10533 "Insert the built-in construct template with NAME."
10534 (interactive
10535 (list (let ((completion-ignore-case t))
10536 (completing-read "Construct name: "
10537 vhdl-template-construct-alist nil t))))
10538 (vhdl-template-insert-fun
3dcb36b7 10539 (cadr (assoc name vhdl-template-construct-alist))))
5eabfe72
KH
10540
10541(defun vhdl-template-insert-package (name)
10542 "Insert the built-in package template with NAME."
10543 (interactive
10544 (list (let ((completion-ignore-case t))
10545 (completing-read "Package name: "
10546 vhdl-template-package-alist nil t))))
10547 (vhdl-template-insert-fun
3dcb36b7 10548 (cadr (assoc name vhdl-template-package-alist))))
5eabfe72
KH
10549
10550(defun vhdl-template-insert-directive (name)
10551 "Insert the built-in directive template with NAME."
10552 (interactive
10553 (list (let ((completion-ignore-case t))
10554 (completing-read "Directive name: "
10555 vhdl-template-directive-alist nil t))))
10556 (vhdl-template-insert-fun
3dcb36b7 10557 (cadr (assoc name vhdl-template-directive-alist))))
5eabfe72
KH
10558
10559(defun vhdl-template-insert-fun (fun)
10560 "Call FUN to insert a built-in template."
10561 (let ((caught (catch 'abort (when fun (funcall fun)))))
10562 (when (stringp caught) (message caught))))
10563
10564
10565;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10566;;; Models
10567;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10568
10569(defun vhdl-model-insert (model-name)
10570 "Insert the user model with name MODEL-NAME."
10571 (interactive
10572 (let ((completion-ignore-case t))
10573 (list (completing-read "Model name: " vhdl-model-alist))))
3dcb36b7 10574 (indent-according-to-mode)
5eabfe72
KH
10575 (let ((start (point-marker))
10576 (margin (current-indentation))
5eabfe72 10577 model position prompt string end)
3dcb36b7 10578 (vhdl-prepare-search-2
5eabfe72
KH
10579 (when (setq model (assoc model-name vhdl-model-alist))
10580 ;; insert model
10581 (beginning-of-line)
10582 (delete-horizontal-space)
10583 (goto-char start)
10584 (vhdl-insert-string-or-file (nth 1 model))
10585 (setq end (point-marker))
10586 ;; indent code
10587 (goto-char start)
10588 (beginning-of-line)
10589 (while (< (point) end)
10590 (unless (looking-at "^$")
10591 (insert-char ? margin))
10592 (beginning-of-line 2))
10593 (goto-char start)
10594 ;; insert clock
10595 (unless (equal "" vhdl-clock-name)
10596 (while (re-search-forward "<clock>" end t)
10597 (replace-match vhdl-clock-name)))
10598 (goto-char start)
10599 ;; insert reset
10600 (unless (equal "" vhdl-reset-name)
10601 (while (re-search-forward "<reset>" end t)
10602 (replace-match vhdl-reset-name)))
3dcb36b7
JB
10603 ;; replace header prompts
10604 (vhdl-template-replace-header-keywords start end nil t)
5eabfe72 10605 (goto-char start)
3dcb36b7 10606 ;; query other prompts
5eabfe72
KH
10607 (while (re-search-forward
10608 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10609 (unless (equal "cursor" (match-string 1))
10610 (setq position (match-beginning 1))
10611 (setq prompt (match-string 1))
10612 (replace-match "")
10613 (setq string (vhdl-template-field prompt nil t))
a5a08b1f 10614 ;; replace occurrences of same prompt
5eabfe72
KH
10615 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10616 (replace-match (or string "")))
10617 (goto-char position)))
10618 (goto-char start)
10619 ;; goto final position
10620 (if (re-search-forward "<cursor>" end t)
10621 (replace-match "")
10622 (goto-char end))))))
10623
10624(defun vhdl-model-defun ()
10625 "Define help and hook functions for user models."
10626 (let ((model-alist vhdl-model-alist)
10627 model-name model-keyword)
10628 (while model-alist
10629 ;; define functions for user models that can be invoked from menu and key
10630 ;; bindings and which themselves call `vhdl-model-insert' with the model
10631 ;; name as argument
10632 (setq model-name (nth 0 (car model-alist)))
d4a5b644
GM
10633 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10634 ,(concat "Insert model for \"" model-name "\".")
10635 (interactive)
10636 (vhdl-model-insert ,model-name)))
5eabfe72
KH
10637 ;; define hooks for user models that are invoked from keyword abbrevs
10638 (setq model-keyword (nth 3 (car model-alist)))
10639 (unless (equal model-keyword "")
d4a5b644
GM
10640 (eval `(defun
10641 ,(vhdl-function-name
10642 "vhdl-model" model-name "hook") ()
10643 (vhdl-hooked-abbrev
10644 ',(vhdl-function-name "vhdl-model" model-name)))))
5eabfe72
KH
10645 (setq model-alist (cdr model-alist)))))
10646
10647(vhdl-model-defun)
10648
10649
10650;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10651;;; Port translation
10652;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10653
10654(defvar vhdl-port-list nil
3dcb36b7 10655 "Variable to hold last port map parsed.")
5eabfe72 10656;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
10657;; (ent-name
10658;; ((generic-names) generic-type generic-init generic-comment group-comment)
10659;; ((port-names) port-object port-direct port-type port-comment group-comment)
10660;; (lib-name pack-key))
5eabfe72
KH
10661
10662(defun vhdl-parse-string (string &optional optional)
3dcb36b7 10663 "Check that the text following point matches the regexp in STRING."
5eabfe72 10664 (if (looking-at string)
3dcb36b7 10665 (goto-char (match-end 0))
5eabfe72 10666 (unless optional
3dcb36b7
JB
10667 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10668 (vhdl-current-line) string)))
5eabfe72
KH
10669 nil))
10670
10671(defun vhdl-replace-string (regexp-cons string)
10672 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
3dcb36b7 10673 (vhdl-prepare-search-1
5eabfe72 10674 (if (string-match (car regexp-cons) string)
3dcb36b7
JB
10675 (funcall vhdl-file-name-case
10676 (replace-match (cdr regexp-cons) t nil string))
5eabfe72
KH
10677 string)))
10678
3dcb36b7
JB
10679(defun vhdl-parse-group-comment ()
10680 "Parse comment and empty lines between groups of lines."
10681 (let ((start (point))
10682 string)
10683 (vhdl-forward-comment (point-max))
10684 (setq string (buffer-substring-no-properties start (point)))
10685 ;; strip off leading blanks and first newline
10686 (while (string-match "^\\(\\s-+\\)" string)
10687 (setq string (concat (substring string 0 (match-beginning 1))
10688 (substring string (match-end 1)))))
10689 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10690 (substring string 1)
10691 string)))
10692
10693(defun vhdl-paste-group-comment (string indent)
10694 "Paste comment and empty lines from STRING between groups of lines
10695with INDENT."
10696 (let ((pos (point-marker)))
10697 (when (> indent 0)
10698 (while (string-match "^\\(--\\)" string)
10699 (setq string (concat (substring string 0 (match-beginning 1))
10700 (make-string indent ? )
10701 (substring string (match-beginning 1))))))
10702 (beginning-of-line)
10703 (insert string)
10704 (goto-char pos)))
10705
10706(defvar vhdl-port-flattened nil
10707 "Indicates whether a port has been flattened.")
10708
10709(defun vhdl-port-flatten (&optional as-alist)
5eabfe72
KH
10710 "Flatten port list so that only one generic/port exists per line."
10711 (interactive)
10712 (if (not vhdl-port-list)
3dcb36b7 10713 (error "ERROR: No port has been read")
5eabfe72
KH
10714 (message "Flattening port...")
10715 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10716 (old-vhdl-port-list (cdr vhdl-port-list))
10717 old-port-list new-port-list old-port new-port names)
10718 ;; traverse port list and flatten entries
3dcb36b7 10719 (while (cdr old-vhdl-port-list)
5eabfe72
KH
10720 (setq old-port-list (car old-vhdl-port-list))
10721 (setq new-port-list nil)
10722 (while old-port-list
10723 (setq old-port (car old-port-list))
10724 (setq names (car old-port))
10725 (while names
3dcb36b7
JB
10726 (setq new-port (cons (if as-alist (car names) (list (car names)))
10727 (cdr old-port)))
5eabfe72
KH
10728 (setq new-port-list (append new-port-list (list new-port)))
10729 (setq names (cdr names)))
10730 (setq old-port-list (cdr old-port-list)))
10731 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10732 (setq new-vhdl-port-list (append new-vhdl-port-list
10733 (list new-port-list))))
3dcb36b7
JB
10734 (setq vhdl-port-list
10735 (append new-vhdl-port-list (list old-vhdl-port-list))
10736 vhdl-port-flattened t)
5eabfe72
KH
10737 (message "Flattening port...done"))))
10738
3dcb36b7
JB
10739(defvar vhdl-port-reversed-direction nil
10740 "Indicates whether port directions are reversed.")
10741
10742(defun vhdl-port-reverse-direction ()
10743 "Reverse direction for all ports (useful in testbenches)."
10744 (interactive)
10745 (if (not vhdl-port-list)
10746 (error "ERROR: No port has been read")
10747 (message "Reversing port directions...")
10748 (let ((port-list (nth 2 vhdl-port-list))
10749 port-dir-car port-dir)
10750 ;; traverse port list and reverse directions
10751 (while port-list
10752 (setq port-dir-car (cddr (car port-list))
10753 port-dir (car port-dir-car))
10754 (setcar port-dir-car
10755 (cond ((equal port-dir "in") "out")
10756 ((equal port-dir "out") "in")
10757 (t port-dir)))
10758 (setq port-list (cdr port-list)))
10759 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10760 (message "Reversing port directions...done"))))
10761
5eabfe72
KH
10762(defun vhdl-port-copy ()
10763 "Get generic and port information from an entity or component declaration."
10764 (interactive)
5eabfe72 10765 (save-excursion
3dcb36b7
JB
10766 (let (parse-error end-of-list
10767 decl-type name generic-list port-list context-clause
10768 object names direct type init comment group-comment)
10769 (vhdl-prepare-search-2
5eabfe72
KH
10770 (setq
10771 parse-error
10772 (catch 'parse
10773 ;; check if within entity or component declaration
3dcb36b7 10774 (end-of-line)
5eabfe72
KH
10775 (when (or (not (re-search-backward
10776 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
3dcb36b7
JB
10777 (equal "END" (upcase (match-string 1))))
10778 (throw 'parse "ERROR: Not within an entity or component declaration"))
10779 (setq decl-type (downcase (match-string-no-properties 1)))
5eabfe72 10780 (forward-word 1)
3dcb36b7
JB
10781 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10782 (setq name (match-string-no-properties 1))
10783 (message "Reading port of %s \"%s\"..." decl-type name)
5eabfe72
KH
10784 (vhdl-forward-syntactic-ws)
10785 ;; parse generic clause
10786 (when (vhdl-parse-string "generic[ \t\n]*(" t)
3dcb36b7
JB
10787 ;; parse group comment and spacing
10788 (setq group-comment (vhdl-parse-group-comment))
10789 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
10790 (while (not end-of-list)
10791 ;; parse names
10792 (vhdl-parse-string "\\(\\w+\\)[ \t\n]*")
3dcb36b7 10793 (setq names (list (match-string-no-properties 1)))
5eabfe72 10794 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
3dcb36b7
JB
10795 (setq names
10796 (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10797 ;; parse type
10798 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
3dcb36b7 10799 (setq type (match-string-no-properties 1))
5eabfe72
KH
10800 (setq comment nil)
10801 (while (looking-at "(")
10802 (setq type
10803 (concat type
3dcb36b7 10804 (buffer-substring-no-properties
5eabfe72
KH
10805 (point) (progn (forward-sexp) (point)))
10806 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
3dcb36b7 10807 (match-string-no-properties 1)))))
5eabfe72
KH
10808 ;; special case: closing parenthesis is on separate line
10809 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10810 (setq comment (substring type (match-beginning 2)))
10811 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10812 ;; strip of trailing group-comment
5eabfe72
KH
10813 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10814 (setq type (substring type 0 (match-end 1)))
10815 ;; parse initialization expression
10816 (setq init nil)
10817 (when (vhdl-parse-string ":=[ \t\n]*" t)
10818 (vhdl-parse-string "\\([^();\n]*\\)")
3dcb36b7 10819 (setq init (match-string-no-properties 1))
5eabfe72
KH
10820 (while (looking-at "(")
10821 (setq init
10822 (concat init
3dcb36b7 10823 (buffer-substring-no-properties
5eabfe72
KH
10824 (point) (progn (forward-sexp) (point)))
10825 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 10826 (match-string-no-properties 1))))))
5eabfe72
KH
10827 ;; special case: closing parenthesis is on separate line
10828 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10829 (setq comment (substring init (match-beginning 2)))
10830 (setq init (substring init 0 (match-beginning 1)))
10831 (vhdl-forward-syntactic-ws))
10832 (skip-chars-forward " \t")
10833 ;; parse inline comment, special case: as above, no initial.
10834 (unless comment
10835 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10836 (match-string-no-properties 1))))
5eabfe72
KH
10837 (vhdl-forward-syntactic-ws)
10838 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 10839 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
10840 ;; parse inline comment
10841 (unless comment
10842 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10843 (match-string-no-properties 1))))
5eabfe72 10844 ;; save everything in list
3dcb36b7
JB
10845 (setq generic-list (append generic-list
10846 (list (list names type init
10847 comment group-comment))))
10848 ;; parse group comment and spacing
10849 (setq group-comment (vhdl-parse-group-comment))))
5eabfe72
KH
10850 ;; parse port clause
10851 (when (vhdl-parse-string "port[ \t\n]*(" t)
3dcb36b7
JB
10852 ;; parse group comment and spacing
10853 (setq group-comment (vhdl-parse-group-comment))
10854 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
10855 (while (not end-of-list)
10856 ;; parse object
10857 (setq object
3dcb36b7
JB
10858 (and (vhdl-parse-string "\\(signal\\|quantity\\|terminal\\)[ \t\n]*" t)
10859 (match-string-no-properties 1)))
10860 ;; parse names (accept extended identifiers)
10861 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10862 (setq names (list (match-string-no-properties 1)))
10863 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
10864 (setq names (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10865 ;; parse direction
10866 (vhdl-parse-string ":[ \t\n]*")
10867 (setq direct
3dcb36b7
JB
10868 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
10869 (match-string-no-properties 1)))
5eabfe72
KH
10870 ;; parse type
10871 (vhdl-parse-string "\\([^();\n]+\\)")
3dcb36b7 10872 (setq type (match-string-no-properties 1))
5eabfe72
KH
10873 (setq comment nil)
10874 (while (looking-at "(")
10875 (setq type (concat type
3dcb36b7 10876 (buffer-substring-no-properties
5eabfe72
KH
10877 (point) (progn (forward-sexp) (point)))
10878 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 10879 (match-string-no-properties 1)))))
5eabfe72 10880 ;; special case: closing parenthesis is on separate line
3dcb36b7 10881 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
5eabfe72
KH
10882 (setq comment (substring type (match-beginning 2)))
10883 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10884 ;; strip of trailing group-comment
5eabfe72
KH
10885 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10886 (setq type (substring type 0 (match-end 1)))
10887 (vhdl-forward-syntactic-ws)
10888 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 10889 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
10890 ;; parse inline comment
10891 (unless comment
10892 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10893 (match-string-no-properties 1))))
5eabfe72 10894 ;; save everything in list
3dcb36b7
JB
10895 (setq port-list (append port-list
10896 (list (list names object direct type
10897 comment group-comment))))
10898 ;; parse group comment and spacing
10899 (setq group-comment (vhdl-parse-group-comment))))
10900; (vhdl-parse-string "end\\>")
10901 ;; parse context clause
10902 (setq context-clause (vhdl-scan-context-clause))
10903; ;; add surrounding package to context clause
10904; (when (and (equal decl-type "component")
10905; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
10906; (setq context-clause
10907; (append context-clause
10908; (list (cons (vhdl-work-library)
10909; (match-string-no-properties 1))))))
10910 (message "Reading port of %s \"%s\"...done" decl-type name)
5eabfe72
KH
10911 nil)))
10912 ;; finish parsing
10913 (if parse-error
10914 (error parse-error)
3dcb36b7
JB
10915 (setq vhdl-port-list (list name generic-list port-list context-clause)
10916 vhdl-port-reversed-direction nil
10917 vhdl-port-flattened nil)))))
10918
10919(defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
10920 "Paste a context clause."
10921 (let ((margin (current-indentation))
10922 (clause-list (nth 3 vhdl-port-list))
10923 clause)
10924 (while clause-list
10925 (setq clause (car clause-list))
10926 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
10927 (downcase exclude-pack-name)))
10928 (save-excursion
10929 (re-search-backward
10930 (concat "^\\s-*use\\s-+" (car clause)
10931 "\." (cdr clause) "\\>") nil t)))
10932 (vhdl-template-standard-package (car clause) (cdr clause))
10933 (insert "\n"))
10934 (setq clause-list (cdr clause-list)))))
5eabfe72
KH
10935
10936(defun vhdl-port-paste-generic (&optional no-init)
10937 "Paste a generic clause."
10938 (let ((margin (current-indentation))
3dcb36b7
JB
10939 (generic-list (nth 1 vhdl-port-list))
10940 list-margin start names generic)
5eabfe72 10941 ;; paste generic clause
3dcb36b7 10942 (when generic-list
5eabfe72
KH
10943 (setq start (point))
10944 (vhdl-insert-keyword "GENERIC (")
10945 (unless vhdl-argument-list-indent
10946 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10947 (setq list-margin (current-column))
3dcb36b7
JB
10948 (while generic-list
10949 (setq generic (car generic-list))
10950 ;; paste group comment and spacing
10951 (when (memq vhdl-include-group-comments '(decl always))
10952 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72 10953 ;; paste names
5eabfe72
KH
10954 (setq names (nth 0 generic))
10955 (while names
10956 (insert (car names))
10957 (setq names (cdr names))
10958 (when names (insert ", ")))
10959 ;; paste type
10960 (insert " : " (nth 1 generic))
10961 ;; paste initialization
10962 (when (and (not no-init) (nth 2 generic))
10963 (insert " := " (nth 2 generic)))
3dcb36b7 10964 (unless (cdr generic-list) (insert ")"))
5eabfe72
KH
10965 (insert ";")
10966 ;; paste comment
10967 (when (and vhdl-include-port-comments (nth 3 generic))
10968 (vhdl-comment-insert-inline (nth 3 generic) t))
3dcb36b7
JB
10969 (setq generic-list (cdr generic-list))
10970 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72 10971 ;; align generic clause
3dcb36b7 10972 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
5eabfe72
KH
10973
10974(defun vhdl-port-paste-port ()
10975 "Paste a port clause."
10976 (let ((margin (current-indentation))
3dcb36b7
JB
10977 (port-list (nth 2 vhdl-port-list))
10978 list-margin start names port)
5eabfe72 10979 ;; paste port clause
3dcb36b7 10980 (when port-list
5eabfe72
KH
10981 (setq start (point))
10982 (vhdl-insert-keyword "PORT (")
10983 (unless vhdl-argument-list-indent
10984 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10985 (setq list-margin (current-column))
3dcb36b7
JB
10986 (while port-list
10987 (setq port (car port-list))
10988 ;; paste group comment and spacing
10989 (when (memq vhdl-include-group-comments '(decl always))
10990 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
10991 ;; paste object
10992 (when (nth 1 port) (insert (nth 1 port) " "))
10993 ;; paste names
10994 (setq names (nth 0 port))
10995 (while names
10996 (insert (car names))
10997 (setq names (cdr names))
10998 (when names (insert ", ")))
10999 ;; paste direction
11000 (insert " : ")
11001 (when (nth 2 port) (insert (nth 2 port) " "))
11002 ;; paste type
11003 (insert (nth 3 port))
3dcb36b7 11004 (unless (cdr port-list) (insert ")"))
5eabfe72
KH
11005 (insert ";")
11006 ;; paste comment
11007 (when (and vhdl-include-port-comments (nth 4 port))
11008 (vhdl-comment-insert-inline (nth 4 port) t))
3dcb36b7
JB
11009 (setq port-list (cdr port-list))
11010 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72 11011 ;; align port clause
3dcb36b7 11012 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
5eabfe72 11013
3dcb36b7 11014(defun vhdl-port-paste-declaration (kind &optional no-indent)
5eabfe72 11015 "Paste as an entity or component declaration."
3dcb36b7 11016 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11017 (let ((margin (current-indentation))
11018 (name (nth 0 vhdl-port-list)))
11019 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11020 (insert name)
3dcb36b7
JB
11021 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11022 (vhdl-insert-keyword " IS"))
11023 ;; paste generic and port clause
5eabfe72
KH
11024 (when (nth 1 vhdl-port-list)
11025 (insert "\n")
11026 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11027 (insert "\n"))
11028 (indent-to (+ margin vhdl-basic-offset))
11029 (vhdl-port-paste-generic (eq kind 'component)))
11030 (when (nth 2 vhdl-port-list)
11031 (insert "\n")
11032 (when (and (memq vhdl-insert-empty-lines '(unit all))
11033 (eq kind 'entity))
11034 (insert "\n"))
11035 (indent-to (+ margin vhdl-basic-offset)))
11036 (vhdl-port-paste-port)
11037 (insert "\n")
11038 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11039 (insert "\n"))
11040 (indent-to margin)
11041 (vhdl-insert-keyword "END")
11042 (if (eq kind 'entity)
11043 (progn
11044 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11045 (insert " " name))
11046 (vhdl-insert-keyword " COMPONENT")
11047 (unless (vhdl-standard-p '87) (insert " " name)))
11048 (insert ";")))
11049
3dcb36b7 11050(defun vhdl-port-paste-entity (&optional no-indent)
5eabfe72
KH
11051 "Paste as an entity declaration."
11052 (interactive)
11053 (if (not vhdl-port-list)
3dcb36b7
JB
11054 (error "ERROR: No port read")
11055 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11056 (vhdl-port-paste-declaration 'entity no-indent)
11057 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
5eabfe72 11058
3dcb36b7 11059(defun vhdl-port-paste-component (&optional no-indent)
5eabfe72
KH
11060 "Paste as a component declaration."
11061 (interactive)
11062 (if (not vhdl-port-list)
3dcb36b7
JB
11063 (error "ERROR: No port read")
11064 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11065 (vhdl-port-paste-declaration 'component no-indent)
11066 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
5eabfe72
KH
11067
11068(defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11069 "Paste as a generic map."
11070 (interactive)
3dcb36b7 11071 (unless secondary (indent-according-to-mode))
5eabfe72
KH
11072 (let ((margin (current-indentation))
11073 list-margin start generic
3dcb36b7
JB
11074 (generic-list (nth 1 vhdl-port-list)))
11075 (when generic-list
5eabfe72
KH
11076 (setq start (point))
11077 (vhdl-insert-keyword "GENERIC MAP (")
11078 (if (not vhdl-association-list-with-formals)
11079 ;; paste list of actual generics
3dcb36b7
JB
11080 (while generic-list
11081 (insert (if no-constants
11082 (car (nth 0 (car generic-list)))
11083 (or (nth 2 (car generic-list)) " ")))
11084 (setq generic-list (cdr generic-list))
11085 (insert (if generic-list ", " ")")))
5eabfe72 11086 (unless vhdl-argument-list-indent
3dcb36b7 11087 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11088 (setq list-margin (current-column))
3dcb36b7
JB
11089 (while generic-list
11090 (setq generic (car generic-list))
11091 ;; paste group comment and spacing
11092 (when (eq vhdl-include-group-comments 'always)
11093 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72
KH
11094 ;; paste formal and actual generic
11095 (insert (car (nth 0 generic)) " => "
11096 (if no-constants
11097 (car (nth 0 generic))
11098 (or (nth 2 generic) "")))
3dcb36b7
JB
11099 (setq generic-list (cdr generic-list))
11100 (insert (if generic-list "," ")"))
5eabfe72 11101 ;; paste comment
3dcb36b7
JB
11102 (when (or vhdl-include-type-comments
11103 (and vhdl-include-port-comments (nth 3 generic)))
11104 (vhdl-comment-insert-inline
11105 (concat
11106 (when vhdl-include-type-comments
11107 (concat "[" (nth 1 generic) "] "))
11108 (when vhdl-include-port-comments (nth 3 generic))) t))
11109 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11110 ;; align generic map
11111 (when vhdl-auto-align
3dcb36b7 11112 (vhdl-align-region-groups start (point) 1 t))))))
5eabfe72
KH
11113
11114(defun vhdl-port-paste-port-map ()
11115 "Paste as a port map."
11116 (let ((margin (current-indentation))
11117 list-margin start port
3dcb36b7
JB
11118 (port-list (nth 2 vhdl-port-list)))
11119 (when port-list
5eabfe72
KH
11120 (setq start (point))
11121 (vhdl-insert-keyword "PORT MAP (")
11122 (if (not vhdl-association-list-with-formals)
11123 ;; paste list of actual ports
3dcb36b7 11124 (while port-list
5eabfe72 11125 (insert (vhdl-replace-string vhdl-actual-port-name
3dcb36b7
JB
11126 (car (nth 0 (car port-list)))))
11127 (setq port-list (cdr port-list))
11128 (insert (if port-list ", " ");")))
5eabfe72 11129 (unless vhdl-argument-list-indent
3dcb36b7 11130 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11131 (setq list-margin (current-column))
3dcb36b7
JB
11132 (while port-list
11133 (setq port (car port-list))
11134 ;; paste group comment and spacing
11135 (when (eq vhdl-include-group-comments 'always)
11136 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11137 ;; paste formal and actual port
11138 (insert (car (nth 0 port)) " => ")
11139 (insert (vhdl-replace-string vhdl-actual-port-name
11140 (car (nth 0 port))))
3dcb36b7
JB
11141 (setq port-list (cdr port-list))
11142 (insert (if port-list "," ");"))
5eabfe72
KH
11143 ;; paste comment
11144 (when (or vhdl-include-direction-comments
3dcb36b7 11145 vhdl-include-type-comments
5eabfe72
KH
11146 (and vhdl-include-port-comments (nth 4 port)))
11147 (vhdl-comment-insert-inline
11148 (concat
3dcb36b7
JB
11149 (cond ((and vhdl-include-direction-comments
11150 vhdl-include-type-comments)
11151 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11152 (nth 3 port) "] "))
11153 ((and vhdl-include-direction-comments (nth 2 port))
11154 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11155 (vhdl-include-direction-comments " ")
11156 (vhdl-include-type-comments
11157 (concat "[" (nth 3 port) "] ")))
11158 (when vhdl-include-port-comments (nth 4 port))) t))
11159 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11160 ;; align port clause
11161 (when vhdl-auto-align
3dcb36b7 11162 (vhdl-align-region-groups start (point) 1))))))
5eabfe72 11163
3dcb36b7 11164(defun vhdl-port-paste-instance (&optional name no-indent title)
5eabfe72
KH
11165 "Paste as an instantiation."
11166 (interactive)
11167 (if (not vhdl-port-list)
3dcb36b7 11168 (error "ERROR: No port read")
5eabfe72
KH
11169 (let ((orig-vhdl-port-list vhdl-port-list))
11170 ;; flatten local copy of port list (must be flat for port mapping)
11171 (vhdl-port-flatten)
3dcb36b7
JB
11172 (unless no-indent (indent-according-to-mode))
11173 (let ((margin (current-indentation)))
5eabfe72 11174 ;; paste instantiation
3dcb36b7
JB
11175 (cond (name
11176 (insert name))
11177 ((equal (cdr vhdl-instance-name) "")
11178 (setq name (vhdl-template-field "instance name")))
11179 ((string-match "\%d" (cdr vhdl-instance-name))
11180 (let ((n 1))
11181 (while (save-excursion
11182 (setq name (format (vhdl-replace-string
11183 vhdl-instance-name
11184 (nth 0 vhdl-port-list)) n))
11185 (goto-char (point-min))
11186 (vhdl-re-search-forward name nil t))
11187 (setq n (1+ n)))
11188 (insert name)))
11189 (t (insert (vhdl-replace-string vhdl-instance-name
11190 (nth 0 vhdl-port-list)))))
11191 (message "Pasting port as instantiation \"%s\"..." name)
11192 (insert ": ")
11193 (when title
11194 (save-excursion
11195 (beginning-of-line)
11196 (indent-to vhdl-basic-offset)
11197 (insert "-- instance \"" name "\"\n")))
11198 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
11199 (insert (nth 0 vhdl-port-list))
11200 (vhdl-insert-keyword "ENTITY ")
3dcb36b7 11201 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
5eabfe72
KH
11202 (when (nth 1 vhdl-port-list)
11203 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11204 (vhdl-port-paste-generic-map t t))
11205 (when (nth 2 vhdl-port-list)
11206 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11207 (vhdl-port-paste-port-map))
3dcb36b7
JB
11208 (message "Pasting port as instantiation \"%s\"...done" name))
11209 (setq vhdl-port-list orig-vhdl-port-list))))
11210
11211(defun vhdl-port-paste-constants (&optional no-indent)
11212 "Paste generics as constants."
11213 (interactive)
11214 (if (not vhdl-port-list)
11215 (error "ERROR: No port read")
11216 (let ((orig-vhdl-port-list vhdl-port-list))
11217 (message "Pasting port as constants...")
11218 ;; flatten local copy of port list (must be flat for constant initial.)
11219 (vhdl-port-flatten)
11220 (unless no-indent (indent-according-to-mode))
11221 (let ((margin (current-indentation))
11222 start generic name
11223 (generic-list (nth 1 vhdl-port-list)))
11224 (when generic-list
11225 (setq start (point))
11226 (while generic-list
11227 (setq generic (car generic-list))
11228 ;; paste group comment and spacing
11229 (when (memq vhdl-include-group-comments '(decl always))
11230 (vhdl-paste-group-comment (nth 4 generic) margin))
11231 (vhdl-insert-keyword "CONSTANT ")
11232 ;; paste generic constants
11233 (setq name (nth 0 generic))
11234 (when name
11235 (insert (car name))
11236 ;; paste type
11237 (insert " : " (nth 1 generic))
11238 ;; paste initialization
11239 (when (nth 2 generic)
11240 (insert " := " (nth 2 generic)))
11241 (insert ";")
11242 ;; paste comment
11243 (when (and vhdl-include-port-comments (nth 3 generic))
11244 (vhdl-comment-insert-inline (nth 3 generic) t))
11245 (setq generic-list (cdr generic-list))
11246 (when generic-list (insert "\n") (indent-to margin))))
11247 ;; align signal list
11248 (when vhdl-auto-align
11249 (vhdl-align-region-groups start (point) 1))))
11250 (message "Pasting port as constants...done")
5eabfe72
KH
11251 (setq vhdl-port-list orig-vhdl-port-list))))
11252
3dcb36b7 11253(defun vhdl-port-paste-signals (&optional initialize no-indent)
5eabfe72
KH
11254 "Paste ports as internal signals."
11255 (interactive)
11256 (if (not vhdl-port-list)
3dcb36b7 11257 (error "ERROR: No port read")
5eabfe72 11258 (message "Pasting port as signals...")
3dcb36b7 11259 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11260 (let ((margin (current-indentation))
11261 start port names
3dcb36b7
JB
11262 (port-list (nth 2 vhdl-port-list)))
11263 (when port-list
5eabfe72 11264 (setq start (point))
3dcb36b7
JB
11265 (while port-list
11266 (setq port (car port-list))
11267 ;; paste group comment and spacing
11268 (when (memq vhdl-include-group-comments '(decl always))
11269 (vhdl-paste-group-comment (nth 5 port) margin))
5eabfe72
KH
11270 ;; paste object
11271 (if (nth 1 port)
11272 (insert (nth 1 port) " ")
11273 (vhdl-insert-keyword "SIGNAL "))
11274 ;; paste actual port signals
11275 (setq names (nth 0 port))
11276 (while names
11277 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11278 (setq names (cdr names))
11279 (when names (insert ", ")))
11280 ;; paste type
11281 (insert " : " (nth 3 port))
11282 ;; paste initialization (inputs only)
3dcb36b7
JB
11283 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11284 (insert " := " (if (string-match "(.+)" (nth 3 port))
11285 "(others => '0')" "'0'")))
5eabfe72
KH
11286 (insert ";")
11287 ;; paste comment
3dcb36b7
JB
11288 (when (or vhdl-include-direction-comments
11289 (and vhdl-include-port-comments (nth 4 port)))
11290 (vhdl-comment-insert-inline
11291 (concat
11292 (cond ((and vhdl-include-direction-comments (nth 2 port))
11293 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11294 (vhdl-include-direction-comments " "))
11295 (when vhdl-include-port-comments (nth 4 port))) t))
11296 (setq port-list (cdr port-list))
11297 (when port-list (insert "\n") (indent-to margin)))
5eabfe72 11298 ;; align signal list
3dcb36b7 11299 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
5eabfe72
KH
11300 (message "Pasting port as signals...done")))
11301
3dcb36b7
JB
11302(defun vhdl-port-paste-initializations (&optional no-indent)
11303 "Paste ports as signal initializations."
5eabfe72
KH
11304 (interactive)
11305 (if (not vhdl-port-list)
3dcb36b7 11306 (error "ERROR: No port read")
5eabfe72 11307 (let ((orig-vhdl-port-list vhdl-port-list))
3dcb36b7
JB
11308 (message "Pasting port as initializations...")
11309 ;; flatten local copy of port list (must be flat for signal initial.)
5eabfe72 11310 (vhdl-port-flatten)
3dcb36b7 11311 (unless no-indent (indent-according-to-mode))
5eabfe72 11312 (let ((margin (current-indentation))
3dcb36b7
JB
11313 start port name
11314 (port-list (nth 2 vhdl-port-list)))
11315 (when port-list
5eabfe72 11316 (setq start (point))
3dcb36b7
JB
11317 (while port-list
11318 (setq port (car port-list))
11319 ;; paste actual port signal (inputs only)
11320 (when (equal "IN" (upcase (nth 2 port)))
11321 (setq name (car (nth 0 port)))
11322 (insert (vhdl-replace-string vhdl-actual-port-name name))
5eabfe72 11323 ;; paste initialization
3dcb36b7
JB
11324 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11325 "(others => '0')" "'0'") ";"))
11326 (setq port-list (cdr port-list))
11327 (when (and port-list
11328 (equal "IN" (upcase (nth 2 (car port-list)))))
11329 (insert "\n") (indent-to margin)))
11330 ;; align signal list
11331 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11332 (message "Pasting port as initializations...done")
5eabfe72
KH
11333 (setq vhdl-port-list orig-vhdl-port-list))))
11334
11335(defun vhdl-port-paste-testbench ()
3dcb36b7 11336 "Paste as a bare-bones testbench."
5eabfe72
KH
11337 (interactive)
11338 (if (not vhdl-port-list)
3dcb36b7 11339 (error "ERROR: No port read")
5eabfe72
KH
11340 (let ((case-fold-search t)
11341 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11342 (nth 0 vhdl-port-list)))
11343 (source-buffer (current-buffer))
3dcb36b7
JB
11344 arch-name config-name ent-file-name arch-file-name
11345 ent-buffer arch-buffer position)
5eabfe72 11346 ;; open entity file
3dcb36b7 11347 (unless (eq vhdl-testbench-create-files 'none)
5eabfe72 11348 (setq ent-file-name
3dcb36b7
JB
11349 (concat ent-name "." (file-name-extension (buffer-file-name))))
11350 (if (file-exists-p ent-file-name)
5eabfe72 11351 (if (y-or-n-p
3dcb36b7
JB
11352 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11353 (progn (find-file ent-file-name)
11354 (erase-buffer)
11355 (set-buffer-modified-p nil))
11356 (if (eq vhdl-testbench-create-files 'separate)
11357 (setq ent-file-name nil)
11358 (error "ERROR: Pasting port as testbench...aborted")))
11359 (find-file ent-file-name)))
11360 (unless (and (eq vhdl-testbench-create-files 'separate)
11361 (null ent-file-name))
11362 ;; paste entity header
11363 (if vhdl-testbench-include-header
11364 (progn (vhdl-template-header
11365 (concat "Testbench for design \""
11366 (nth 0 vhdl-port-list) "\""))
11367 (goto-char (point-max)))
11368 (vhdl-comment-display-line) (insert "\n\n"))
11369 ;; paste std_logic_1164 package
11370 (when vhdl-testbench-include-library
11371 (vhdl-template-package-std-logic-1164)
11372 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11373 ;; paste entity declaration
11374 (vhdl-insert-keyword "ENTITY ")
5eabfe72
KH
11375 (insert ent-name)
11376 (vhdl-insert-keyword " IS")
3dcb36b7 11377 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
5eabfe72 11378 (insert "\n")
3dcb36b7
JB
11379 (vhdl-insert-keyword "END ")
11380 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11381 (insert ent-name ";")
11382 (insert "\n\n")
11383 (vhdl-comment-display-line) (insert "\n"))
11384 ;; get architecture name
11385 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11386 (read-from-minibuffer "architecture name: "
11387 nil vhdl-minibuffer-local-map)
11388 (vhdl-replace-string vhdl-testbench-architecture-name
11389 (nth 0 vhdl-port-list))))
11390 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11391 ;; open architecture file
11392 (if (not (eq vhdl-testbench-create-files 'separate))
5eabfe72 11393 (insert "\n")
3dcb36b7
JB
11394 (setq ent-buffer (current-buffer))
11395 (setq arch-file-name
11396 (concat ent-name "_" arch-name "."
11397 (file-name-extension (buffer-file-name))))
11398 (when (and (file-exists-p arch-file-name)
11399 (not (y-or-n-p (concat "File \"" arch-file-name
11400 "\" exists; overwrite? "))))
11401 (error "ERROR: Pasting port as testbench...aborted"))
11402 (find-file arch-file-name)
11403 (erase-buffer)
11404 (set-buffer-modified-p nil)
11405 ;; paste architecture header
11406 (if vhdl-testbench-include-header
11407 (progn (vhdl-template-header
11408 (concat "Testbench architecture for design \""
11409 (nth 0 vhdl-port-list) "\""))
11410 (goto-char (point-max)))
11411 (vhdl-comment-display-line) (insert "\n\n")))
11412 ;; paste architecture body
11413 (vhdl-insert-keyword "ARCHITECTURE ")
11414 (insert arch-name)
11415 (vhdl-insert-keyword " OF ")
11416 (insert ent-name)
11417 (vhdl-insert-keyword " IS")
11418 (insert "\n\n") (indent-to vhdl-basic-offset)
11419 ;; paste component declaration
11420 (unless (vhdl-use-direct-instantiation)
11421 (vhdl-port-paste-component t)
11422 (insert "\n\n") (indent-to vhdl-basic-offset))
11423 ;; paste constants
11424 (when (nth 1 vhdl-port-list)
11425 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11426 (vhdl-port-paste-constants t)
11427 (insert "\n\n") (indent-to vhdl-basic-offset))
11428 ;; paste internal signals
11429 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11430 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11431 (insert "\n")
11432 ;; paste custom declarations
11433 (unless (equal "" vhdl-testbench-declarations)
5eabfe72 11434 (insert "\n")
3dcb36b7
JB
11435 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11436 (setq position (point))
11437 (insert "\n\n")
11438 (vhdl-comment-display-line) (insert "\n")
11439 (when vhdl-testbench-include-configuration
11440 (setq config-name (vhdl-replace-string
11441 vhdl-testbench-configuration-name
11442 (concat ent-name " " arch-name)))
11443 (insert "\n")
11444 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11445 (vhdl-insert-keyword " OF ") (insert ent-name)
11446 (vhdl-insert-keyword " IS\n")
11447 (indent-to vhdl-basic-offset)
11448 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11449 (indent-to vhdl-basic-offset)
11450 (vhdl-insert-keyword "END FOR;\n")
11451 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11452 (vhdl-comment-display-line) (insert "\n"))
11453 (goto-char position)
11454 (vhdl-template-begin-end
11455 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11456 ;; paste instantiation
11457 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11458 (vhdl-port-paste-instance
11459 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11460 (insert "\n")
11461 ;; paste custom statements
11462 (unless (equal "" vhdl-testbench-statements)
11463 (insert "\n")
11464 (vhdl-insert-string-or-file vhdl-testbench-statements))
11465 (insert "\n")
11466 (indent-to vhdl-basic-offset)
11467 (unless (eq vhdl-testbench-create-files 'none)
11468 (setq arch-buffer (current-buffer))
11469 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11470 (set-buffer arch-buffer) (save-buffer))
11471 (message
11472 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11473 ent-name arch-name)
11474 (and ent-file-name
11475 (format "\n File created: \"%s\"" ent-file-name))
11476 (and arch-file-name
11477 (format "\n File created: \"%s\"" arch-file-name)))))))
5eabfe72
KH
11478
11479
11480;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11481;;; Subprogram interface translation
5eabfe72
KH
11482;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11483
3dcb36b7
JB
11484(defvar vhdl-subprog-list nil
11485 "Variable to hold last subprogram interface parsed.")
11486;; structure: (parenthesised expression means list of such entries)
11487;; (subprog-name kind
11488;; ((names) object direct type init comment group-comment)
11489;; return-type return-comment group-comment)
5eabfe72 11490
3dcb36b7
JB
11491(defvar vhdl-subprog-flattened nil
11492 "Indicates whether an subprogram interface has been flattened.")
5eabfe72 11493
3dcb36b7
JB
11494(defun vhdl-subprog-flatten ()
11495 "Flatten interface list so that only one parameter exists per line."
11496 (interactive)
11497 (if (not vhdl-subprog-list)
11498 (error "ERROR: No subprogram interface has been read")
11499 (message "Flattening subprogram interface...")
11500 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11501 new-subprog-list old-subprog new-subprog names)
11502 ;; traverse parameter list and flatten entries
11503 (while old-subprog-list
11504 (setq old-subprog (car old-subprog-list))
11505 (setq names (car old-subprog))
11506 (while names
11507 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11508 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11509 (setq names (cdr names)))
11510 (setq old-subprog-list (cdr old-subprog-list)))
11511 (setq vhdl-subprog-list
11512 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11513 new-subprog-list (nth 3 vhdl-subprog-list)
11514 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11515 vhdl-subprog-flattened t)
11516 (message "Flattening subprogram interface...done"))))
11517
11518(defun vhdl-subprog-copy ()
11519 "Get interface information from a subprogram specification."
11520 (interactive)
11521 (save-excursion
11522 (let (parse-error pos end-of-list
11523 name kind param-list object names direct type init
11524 comment group-comment
11525 return-type return-comment return-group-comment)
11526 (vhdl-prepare-search-2
11527 (setq
11528 parse-error
11529 (catch 'parse
11530 ;; check if within function declaration
11531 (setq pos (point))
11532 (end-of-line)
11533 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11534 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11535 (goto-char (match-end 0))
11536 (save-excursion (backward-char)
11537 (forward-sexp)
11538 (<= pos (point))))
11539 (throw 'parse "ERROR: Not within a subprogram specification"))
11540 (setq name (match-string-no-properties 5))
11541 (setq kind (if (match-string 2) 'procedure 'function))
11542 (setq end-of-list (not (match-string 7)))
11543 (message "Reading interface of subprogram \"%s\"..." name)
11544 ;; parse parameter list
11545 (setq group-comment (vhdl-parse-group-comment))
11546 (setq end-of-list (or end-of-list
11547 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11548 (while (not end-of-list)
11549 ;; parse object
11550 (setq object
11551 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11552 (match-string-no-properties 1)))
11553 ;; parse names (accept extended identifiers)
11554 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11555 (setq names (list (match-string-no-properties 1)))
11556 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11557 (setq names (append names (list (match-string-no-properties 1)))))
11558 ;; parse direction
11559 (vhdl-parse-string ":[ \t\n]*")
11560 (setq direct
11561 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11562 (match-string-no-properties 1)))
11563 ;; parse type
11564 (vhdl-parse-string "\\([^():;\n]+\\)")
11565 (setq type (match-string-no-properties 1))
11566 (setq comment nil)
11567 (while (looking-at "(")
11568 (setq type
11569 (concat type
11570 (buffer-substring-no-properties
11571 (point) (progn (forward-sexp) (point)))
11572 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11573 (match-string-no-properties 1)))))
11574 ;; special case: closing parenthesis is on separate line
11575 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11576 (setq comment (substring type (match-beginning 2)))
11577 (setq type (substring type 0 (match-beginning 1))))
11578 ;; strip off trailing group-comment
11579 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11580 (setq type (substring type 0 (match-end 1)))
11581 ;; parse initialization expression
11582 (setq init nil)
11583 (when (vhdl-parse-string ":=[ \t\n]*" t)
11584 (vhdl-parse-string "\\([^();\n]*\\)")
11585 (setq init (match-string-no-properties 1))
11586 (while (looking-at "(")
11587 (setq init
11588 (concat init
11589 (buffer-substring-no-properties
11590 (point) (progn (forward-sexp) (point)))
11591 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11592 (match-string-no-properties 1))))))
11593 ;; special case: closing parenthesis is on separate line
11594 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11595 (setq comment (substring init (match-beginning 2)))
11596 (setq init (substring init 0 (match-beginning 1)))
11597 (vhdl-forward-syntactic-ws))
11598 (skip-chars-forward " \t")
11599 ;; parse inline comment, special case: as above, no initial.
11600 (unless comment
11601 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11602 (match-string-no-properties 1))))
11603 (vhdl-forward-syntactic-ws)
11604 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11605 ;; parse inline comment
11606 (unless comment
11607 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11608 (match-string-no-properties 1))))
11609 (setq return-group-comment (vhdl-parse-group-comment))
11610 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11611 ;; parse return type
11612 (when (match-string 3)
11613 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11614 (setq return-type (match-string-no-properties 1))
11615 (when (and return-type
11616 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11617 (setq return-comment (substring return-type (match-beginning 2)))
11618 (setq return-type (substring return-type 0 (match-beginning 1))))
11619 ;; strip of trailing group-comment
11620 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11621 (setq return-type (substring return-type 0 (match-end 1)))
11622 ;; parse return comment
11623 (unless return-comment
11624 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11625 (match-string-no-properties 1)))))
11626 ;; parse inline comment
11627 (unless comment
11628 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11629 (match-string-no-properties 1))))
11630 ;; save everything in list
11631 (setq param-list (append param-list
11632 (list (list names object direct type init
11633 comment group-comment))))
11634 ;; parse group comment and spacing
11635 (setq group-comment (vhdl-parse-group-comment)))
11636 (message "Reading interface of subprogram \"%s\"...done" name)
11637 nil)))
11638 ;; finish parsing
11639 (if parse-error
11640 (error parse-error)
11641 (setq vhdl-subprog-list
11642 (list name kind param-list return-type return-comment
11643 return-group-comment)
11644 vhdl-subprog-flattened nil)))))
11645
11646(defun vhdl-subprog-paste-specification (kind)
11647 "Paste as a subprogram specification."
11648 (indent-according-to-mode)
11649 (let ((margin (current-column))
11650 (param-list (nth 2 vhdl-subprog-list))
11651 list-margin start names param)
11652 ;; paste keyword and name
11653 (vhdl-insert-keyword
11654 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11655 (insert (nth 0 vhdl-subprog-list))
11656 (if (not param-list)
11657 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11658 (setq start (point))
11659 ;; paste parameter list
11660 (insert " (")
11661 (unless vhdl-argument-list-indent
11662 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11663 (setq list-margin (current-column))
11664 (while param-list
11665 (setq param (car param-list))
11666 ;; paste group comment and spacing
11667 (when (memq vhdl-include-group-comments (list kind 'always))
11668 (vhdl-paste-group-comment (nth 6 param) list-margin))
11669 ;; paste object
11670 (when (nth 1 param) (insert (nth 1 param) " "))
11671 ;; paste names
11672 (setq names (nth 0 param))
11673 (while names
11674 (insert (car names))
11675 (setq names (cdr names))
11676 (when names (insert ", ")))
11677 ;; paste direction
11678 (insert " : ")
11679 (when (nth 2 param) (insert (nth 2 param) " "))
11680 ;; paste type
11681 (insert (nth 3 param))
11682 ;; paste initialization
11683 (when (nth 4 param) (insert " := " (nth 4 param)))
11684 ;; terminate line
11685 (if (cdr param-list)
11686 (insert ";")
11687 (insert ")")
11688 (when (null (nth 3 vhdl-subprog-list))
11689 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11690 ;; paste comment
11691 (when (and vhdl-include-port-comments (nth 5 param))
11692 (vhdl-comment-insert-inline (nth 5 param) t))
11693 (setq param-list (cdr param-list))
11694 (when param-list (insert "\n") (indent-to list-margin)))
11695 (when (nth 3 vhdl-subprog-list)
11696 (insert "\n") (indent-to list-margin)
11697 ;; paste group comment and spacing
11698 (when (memq vhdl-include-group-comments (list kind 'always))
11699 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11700 ;; paste return type
11701 (insert "return " (nth 3 vhdl-subprog-list))
11702 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11703 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11704 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11705 ;; align parameter list
11706 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11707 ;; paste body
11708 (when (eq kind 'body)
11709 (insert "\n")
11710 (vhdl-template-begin-end
11711 (unless (vhdl-standard-p '87)
11712 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11713 (nth 0 vhdl-subprog-list) margin))))
11714
11715(defun vhdl-subprog-paste-declaration ()
11716 "Paste as a subprogram declaration."
11717 (interactive)
11718 (if (not vhdl-subprog-list)
11719 (error "ERROR: No subprogram interface read")
11720 (message "Pasting interface as subprogram declaration \"%s\"..."
11721 (car vhdl-subprog-list))
11722 ;; paste specification
11723 (vhdl-subprog-paste-specification 'decl)
11724 (message "Pasting interface as subprogram declaration \"%s\"...done"
11725 (car vhdl-subprog-list))))
11726
11727(defun vhdl-subprog-paste-body ()
11728 "Paste as a subprogram body."
11729 (interactive)
11730 (if (not vhdl-subprog-list)
11731 (error "ERROR: No subprogram interface read")
11732 (message "Pasting interface as subprogram body \"%s\"..."
11733 (car vhdl-subprog-list))
11734 ;; paste specification and body
11735 (vhdl-subprog-paste-specification 'body)
11736 (message "Pasting interface as subprogram body \"%s\"...done"
11737 (car vhdl-subprog-list))))
11738
11739(defun vhdl-subprog-paste-call ()
11740 "Paste as a subprogram call."
11741 (interactive)
11742 (if (not vhdl-subprog-list)
11743 (error "ERROR: No subprogram interface read")
11744 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11745 param-list margin list-margin param start)
11746 ;; flatten local copy of interface list (must be flat for parameter mapping)
11747 (vhdl-subprog-flatten)
11748 (setq param-list (nth 2 vhdl-subprog-list))
11749 (indent-according-to-mode)
11750 (setq margin (current-indentation))
11751 (message "Pasting interface as subprogram call \"%s\"..."
11752 (car vhdl-subprog-list))
11753 ;; paste name
11754 (insert (nth 0 vhdl-subprog-list))
11755 (if (not param-list)
11756 (insert ";")
11757 (setq start (point))
11758 ;; paste parameter list
11759 (insert " (")
11760 (unless vhdl-argument-list-indent
11761 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11762 (setq list-margin (current-column))
11763 (while param-list
11764 (setq param (car param-list))
11765 ;; paste group comment and spacing
11766 (when (eq vhdl-include-group-comments 'always)
11767 (vhdl-paste-group-comment (nth 6 param) list-margin))
11768 ;; paste formal port
11769 (insert (car (nth 0 param)) " => ")
11770 (setq param-list (cdr param-list))
11771 (insert (if param-list "," ");"))
11772 ;; paste comment
11773 (when (and vhdl-include-port-comments (nth 5 param))
11774 (vhdl-comment-insert-inline (nth 5 param)))
11775 (when param-list (insert "\n") (indent-to list-margin)))
11776 ;; align parameter list
11777 (when vhdl-auto-align
11778 (vhdl-align-region-groups start (point) 1)))
11779 (message "Pasting interface as subprogram call \"%s\"...done"
11780 (car vhdl-subprog-list))
11781 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11782
11783
11784;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11785;;; Miscellaneous
11786;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11787
11788;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11789;; Hippie expand customization
11790
11791(defvar vhdl-expand-upper-case nil)
11792
11793(defun vhdl-try-expand-abbrev (old)
11794 "Try expanding abbreviations from `vhdl-abbrev-list'."
11795 (unless old
11796 (he-init-string (he-dabbrev-beg) (point))
5eabfe72
KH
11797 (setq he-expand-list
11798 (let ((abbrev-list vhdl-abbrev-list)
11799 (sel-abbrev-list '()))
11800 (while abbrev-list
11801 (when (or (not (stringp (car abbrev-list)))
11802 (string-match
11803 (concat "^" he-search-string) (car abbrev-list)))
11804 (setq sel-abbrev-list
11805 (cons (car abbrev-list) sel-abbrev-list)))
11806 (setq abbrev-list (cdr abbrev-list)))
11807 (nreverse sel-abbrev-list))))
11808 (while (and he-expand-list
11809 (or (not (stringp (car he-expand-list)))
11810 (he-string-member (car he-expand-list) he-tried-table t)))
11811; (equal (car he-expand-list) he-search-string)))
11812 (unless (stringp (car he-expand-list))
11813 (setq vhdl-expand-upper-case (car he-expand-list)))
11814 (setq he-expand-list (cdr he-expand-list)))
11815 (if (null he-expand-list)
11816 (progn (when old (he-reset-string))
11817 nil)
11818 (he-substitute-string
11819 (if vhdl-expand-upper-case
11820 (upcase (car he-expand-list))
11821 (car he-expand-list))
11822 t)
11823 (setq he-expand-list (cdr he-expand-list))
11824 t))
11825
11826(defun vhdl-he-list-beg ()
11827 "Also looks at the word before `(' in order to better match parenthesized
11828expressions (e.g. for index ranges of types and signals)."
11829 (save-excursion
11830 (condition-case ()
11831 (progn (backward-up-list 1)
11832 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
11833 (error ()))
11834 (point)))
11835
11836;; override `he-list-beg' from `hippie-exp'
11837(unless (and (boundp 'viper-mode) viper-mode)
5eabfe72
KH
11838 (defalias 'he-list-beg 'vhdl-he-list-beg))
11839
11840;; function for expanding abbrevs and dabbrevs
3dcb36b7 11841(defun vhdl-expand-abbrev (arg))
5eabfe72
KH
11842(fset 'vhdl-expand-abbrev (make-hippie-expand-function
11843 '(try-expand-dabbrev
11844 try-expand-dabbrev-all-buffers
11845 vhdl-try-expand-abbrev)))
11846
11847;; function for expanding parenthesis
3dcb36b7 11848(defun vhdl-expand-paren (arg))
5eabfe72
KH
11849(fset 'vhdl-expand-paren (make-hippie-expand-function
11850 '(try-expand-list
11851 try-expand-list-all-buffers)))
11852
11853;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11854;; Case fixing
d2ddb974
KH
11855
11856(defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
11857 "Convert all words matching word-regexp in region to lower or upper case,
11858depending on parameter upper-case."
3dcb36b7 11859 (let ((case-replace nil)
5eabfe72 11860 (last-update 0))
3dcb36b7 11861 (vhdl-prepare-search-2
5eabfe72
KH
11862 (save-excursion
11863 (goto-char end)
11864 (setq end (point-marker))
11865 (goto-char beg)
11866 (while (re-search-forward word-regexp end t)
3dcb36b7 11867 (or (vhdl-in-literal)
5eabfe72
KH
11868 (if upper-case
11869 (upcase-word -1)
11870 (downcase-word -1)))
3dcb36b7 11871 (when (and count vhdl-progress-interval (not noninteractive)
5eabfe72
KH
11872 (< vhdl-progress-interval
11873 (- (nth 1 (current-time)) last-update)))
11874 (message "Fixing case... (%2d%s)"
11875 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
11876 "%")
11877 (setq last-update (nth 1 (current-time)))))
3dcb36b7 11878 (goto-char end)))))
d2ddb974
KH
11879
11880(defun vhdl-fix-case-region (beg end &optional arg)
11881 "Convert all VHDL words in region to lower or upper case, depending on
3dcb36b7 11882options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974
KH
11883 (interactive "r\nP")
11884 (vhdl-fix-case-region-1
5eabfe72 11885 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
d2ddb974 11886 (vhdl-fix-case-region-1
5eabfe72 11887 beg end vhdl-upper-case-types vhdl-types-regexp 1)
d2ddb974 11888 (vhdl-fix-case-region-1
5eabfe72
KH
11889 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
11890 (vhdl-fix-case-region-1
3dcb36b7
JB
11891 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
11892 (when vhdl-progress-interval (message "Fixing case...done")))
d2ddb974 11893
5eabfe72
KH
11894(defun vhdl-fix-case-buffer ()
11895 "Convert all VHDL words in buffer to lower or upper case, depending on
3dcb36b7 11896options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974 11897 (interactive)
5eabfe72
KH
11898 (vhdl-fix-case-region (point-min) (point-max)))
11899
3dcb36b7
JB
11900(defun vhdl-fix-case-word (&optional arg)
11901 "Convert word after cursor to upper case if necessary."
11902 (interactive "p")
11903 (save-excursion
11904 (when arg (backward-word 1))
11905 (vhdl-prepare-search-1
11906 (when (and vhdl-upper-case-keywords
11907 (looking-at vhdl-keywords-regexp))
11908 (upcase-word 1))
11909 (when (and vhdl-upper-case-types
11910 (looking-at vhdl-types-regexp))
11911 (upcase-word 1))
11912 (when (and vhdl-upper-case-attributes
11913 (looking-at vhdl-attributes-regexp))
11914 (upcase-word 1))
11915 (when (and vhdl-upper-case-enum-values
11916 (looking-at vhdl-enum-values-regexp))
11917 (upcase-word 1)))))
11918
5eabfe72
KH
11919;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11920;; Line handling functions
d2ddb974
KH
11921
11922(defun vhdl-current-line ()
11923 "Return the line number of the line containing point."
11924 (save-restriction
11925 (widen)
11926 (save-excursion
11927 (beginning-of-line)
5eabfe72 11928 (1+ (count-lines 1 (point))))))
d2ddb974 11929
5eabfe72 11930(defun vhdl-line-kill-entire (&optional arg)
d2ddb974 11931 "Delete entire line."
5eabfe72
KH
11932 (interactive "p")
11933 (beginning-of-line)
11934 (kill-line (or arg 1)))
11935
11936(defun vhdl-line-kill (&optional arg)
11937 "Kill current line."
11938 (interactive "p")
11939 (vhdl-line-kill-entire arg))
11940
11941(defun vhdl-line-copy (&optional arg)
11942 "Copy current line."
11943 (interactive "p")
11944 (save-excursion
11945 (beginning-of-line)
11946 (let ((position (point)))
11947 (forward-line (or arg 1))
11948 (copy-region-as-kill position (point)))))
11949
11950(defun vhdl-line-yank ()
11951 "Yank entire line."
d2ddb974 11952 (interactive)
5eabfe72
KH
11953 (beginning-of-line)
11954 (yank))
d2ddb974 11955
5eabfe72
KH
11956(defun vhdl-line-expand (&optional prefix-arg)
11957 "Hippie-expand current line."
11958 (interactive "P")
11959 (let ((case-fold-search t) (case-replace nil)
11960 (hippie-expand-try-functions-list
11961 '(try-expand-line try-expand-line-all-buffers)))
11962 (hippie-expand prefix-arg)))
11963
11964(defun vhdl-line-transpose-next (&optional arg)
11965 "Interchange this line with next line."
11966 (interactive "p")
11967 (forward-line 1)
11968 (transpose-lines (or arg 1))
11969 (forward-line -1))
11970
11971(defun vhdl-line-transpose-previous (&optional arg)
11972 "Interchange this line with previous line."
11973 (interactive "p")
11974 (forward-line 1)
11975 (transpose-lines (- 0 (or arg 0)))
11976 (forward-line -1))
11977
11978(defun vhdl-line-open ()
d2ddb974
KH
11979 "Open a new line and indent."
11980 (interactive)
5eabfe72
KH
11981 (end-of-line -0)
11982 (newline-and-indent))
d2ddb974 11983
3dcb36b7
JB
11984(defun vhdl-delete-indentation ()
11985 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
11986it works within comments too."
11987 (interactive)
11988 (let ((fill-prefix "-- "))
11989 (delete-indentation)))
d2ddb974 11990
5eabfe72 11991;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11992;; Move functions
d2ddb974 11993
3dcb36b7
JB
11994(defun vhdl-forward-same-indent ()
11995 "Move forward to next line with same indent."
11996 (interactive)
11997 (let ((pos (point))
11998 (indent (current-indentation)))
11999 (beginning-of-line 2)
12000 (while (and (not (eobp))
12001 (or (looking-at "^\\s-*\\(--.*\\)?$")
12002 (> (current-indentation) indent)))
12003 (beginning-of-line 2))
12004 (if (= (current-indentation) indent)
12005 (back-to-indentation)
12006 (message "No following line with same indent found in this block")
12007 (goto-char pos)
12008 nil)))
5eabfe72 12009
3dcb36b7
JB
12010(defun vhdl-backward-same-indent ()
12011 "Move backward to previous line with same indent."
12012 (interactive)
12013 (let ((pos (point))
12014 (indent (current-indentation)))
12015 (beginning-of-line -0)
12016 (while (and (not (bobp))
12017 (or (looking-at "^\\s-*\\(--.*\\)?$")
12018 (> (current-indentation) indent)))
12019 (beginning-of-line -0))
12020 (if (= (current-indentation) indent)
12021 (back-to-indentation)
12022 (message "No preceding line with same indent found in this block")
12023 (goto-char pos)
12024 nil)))
5eabfe72
KH
12025
12026;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
12027;; Statistics
12028
12029(defun vhdl-statistics-buffer ()
12030 "Get some file statistics."
12031 (interactive)
12032 (let ((no-stats 0)
12033 (no-code-lines 0)
12034 (no-lines (count-lines (point-min) (point-max))))
12035 (save-excursion
12036 ;; count statements
12037 (goto-char (point-min))
12038 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12039 (if (match-string 1)
12040 (goto-char (match-end 1))
12041 (setq no-stats (1+ no-stats))))
12042 ;; count code lines
12043 (goto-char (point-min))
12044 (while (not (eobp))
12045 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12046 (setq no-code-lines (1+ no-code-lines)))
12047 (beginning-of-line 2)))
12048 ;; print results
12049 (message "\n\
12050File statistics: \"%s\"\n\
12051---------------------\n\
12052# statements : %5d\n\
12053# code lines : %5d\n\
12054# total lines : %5d\n\ "
12055 (buffer-file-name) no-stats no-code-lines no-lines)
12056 (unless vhdl-emacs-21 (vhdl-show-messages))))
12057
5eabfe72 12058;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12059;; Help functions
d2ddb974 12060
3dcb36b7
JB
12061(defun vhdl-re-search-forward (regexp &optional bound noerror count)
12062 "Like `re-search-forward', but does not match within literals."
12063 (let (pos)
12064 (save-excursion
12065 (while (and (setq pos (re-search-forward regexp bound noerror count))
12066 (vhdl-in-literal))))
12067 (when pos (goto-char pos))
12068 pos))
12069
12070(defun vhdl-re-search-backward (regexp &optional bound noerror count)
12071 "Like `re-search-backward', but does not match within literals."
12072 (let (pos)
12073 (save-excursion
12074 (while (and (setq pos (re-search-backward regexp bound noerror count))
12075 (vhdl-in-literal))))
12076 (when pos (goto-char pos))
12077 pos))
5eabfe72 12078
d2ddb974 12079
3dcb36b7
JB
12080;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12081;;; Project
12082;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12083
12084(defun vhdl-set-project (name)
12085 "Set current project to NAME."
12086 (interactive
12087 (list (let ((completion-ignore-case t))
12088 (completing-read "Project name: " vhdl-project-alist nil t))))
12089 (cond ((equal name "")
12090 (setq vhdl-project nil)
12091 (message "Current VHDL project: None"))
12092 ((assoc name vhdl-project-alist)
12093 (setq vhdl-project name)
12094 (message "Current VHDL project: \"%s\"" name))
12095 (t
12096 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12097 (vhdl-speedbar-update-current-project))
12098
12099(defun vhdl-toggle-project (name token indent)
12100 "Set current project to NAME or unset if NAME is current project."
12101 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12102
12103(defun vhdl-export-project (file-name)
12104 "Write project setup for current project."
12105 (interactive
12106 (let ((name (vhdl-resolve-env-variable
12107 (vhdl-replace-string
12108 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12109 (concat (subst-char-in-string
12110 ? ?_ (or (vhdl-project-p)
12111 (error "ERROR: No current project")))
12112 " " (user-login-name))))))
12113 (list (read-file-name
12114 "Write project file: "
12115 (when (file-name-absolute-p name) "") nil nil name))))
12116 (setq file-name (abbreviate-file-name file-name))
12117 (let ((orig-buffer (current-buffer)))
12118 (unless (file-exists-p (file-name-directory file-name))
12119 (make-directory (file-name-directory file-name) t))
12120 (if (not (file-writable-p file-name))
12121 (error "ERROR: File not writable: \"%s\"" file-name)
12122 (set-buffer (find-file-noselect file-name t t))
12123 (erase-buffer)
12124 (insert ";; -*- Emacs-Lisp -*-\n\n"
12125 ";;; " (file-name-nondirectory file-name)
12126 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12127 ";; Project : " vhdl-project "\n"
12128 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12129 (user-login-name) "\n\n\n"
12130 ";; project name\n"
12131 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12132 ";; project setup\n"
12133 "(aput 'vhdl-project-alist vhdl-project\n'")
12134 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12135 (insert ")\n")
12136 (save-buffer)
12137 (kill-buffer (current-buffer))
12138 (set-buffer orig-buffer))))
12139
12140(defun vhdl-import-project (file-name &optional auto not-make-current)
12141 "Read project setup and set current project."
12142 (interactive
12143 (let ((name (vhdl-resolve-env-variable
12144 (vhdl-replace-string
12145 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12146 (concat "" " " (user-login-name))))))
12147 (list (read-file-name
12148 "Read project file: " (when (file-name-absolute-p name) "") nil t
12149 (file-name-directory name)))))
12150 (when (file-exists-p file-name)
12151 (condition-case ()
12152 (let ((current-project vhdl-project))
12153 (load-file file-name)
12154 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12155 (adelete 'vhdl-project-alist vhdl-project)
12156 (error))
12157 (when not-make-current
12158 (setq vhdl-project current-project))
12159 (vhdl-update-mode-menu)
12160 (vhdl-speedbar-refresh)
12161 (unless not-make-current
12162 (message "Current VHDL project: \"%s\"%s"
12163 vhdl-project (if auto " (auto-loaded)" ""))))
12164 (error (vhdl-warning
12165 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12166
12167(defun vhdl-duplicate-project ()
12168 "Duplicate setup of current project."
5eabfe72 12169 (interactive)
3dcb36b7
JB
12170 (let ((new-name (read-from-minibuffer "New project name: "))
12171 (project-entry (aget vhdl-project-alist vhdl-project t)))
12172 (setq vhdl-project-alist
12173 (append vhdl-project-alist
12174 (list (cons new-name project-entry))))
12175 (vhdl-update-mode-menu)))
12176
12177(defun vhdl-auto-load-project ()
12178 "Automatically load project setup at startup."
12179 (let ((file-name-list vhdl-project-file-name)
12180 file-list list-length)
12181 (while file-name-list
12182 (setq file-list
12183 (append file-list
12184 (file-expand-wildcards
12185 (vhdl-resolve-env-variable
12186 (vhdl-replace-string
12187 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12188 (concat "\*" " " (user-login-name)))))))
12189 (setq list-length (or list-length (length file-list)))
12190 (setq file-name-list (cdr file-name-list)))
12191 (while file-list
12192 (vhdl-import-project (expand-file-name (car file-list)) t
12193 (not (> list-length 0)))
12194 (setq list-length (1- list-length))
12195 (setq file-list (cdr file-list)))))
12196
12197;; automatically load project setup when idle after startup
12198(when (memq 'startup vhdl-project-auto-load)
12199 (if noninteractive
12200 (vhdl-auto-load-project)
12201 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
5eabfe72
KH
12202
12203
12204;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12205;;; Hideshow
12206;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12207;; (using `hideshow.el')
d2ddb974 12208
3dcb36b7
JB
12209(defconst vhdl-hs-start-regexp
12210 (concat
12211 "\\(^\\)\\s-*\\("
12212 ;; generic/port clause
12213 "\\(generic\\|port\\)[ \t\n]*(\\|"
12214 ;; component
12215 "component\\>\\|"
12216 ;; component instantiation
12217 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12218 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12219 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12220 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12221 ;; subprogram
12222 "\\(function\\|procedure\\)\\>\\|"
12223 ;; process, block
12224 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12225 ;; configuration declaration
12226 "configuration\\>"
12227 "\\)")
12228 "Regexp to match start of construct to hide.")
12229
12230(defun vhdl-hs-forward-sexp-func (count)
12231 "Find end of construct to hide (for hideshow). Only searches forward."
12232 (let ((pos (point)))
12233 (vhdl-prepare-search-2
12234 (beginning-of-line)
12235 (cond
12236 ;; generic/port clause
12237 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12238 (goto-char (match-end 0))
12239 (backward-char)
12240 (forward-sexp))
12241 ;; component declaration
12242 ((looking-at "^\\s-*component\\>")
12243 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12244 ;; component instantiation
12245 ((looking-at
12246 (concat
12247 "^\\s-*\\w+\\s-*:[ \t\n]*"
12248 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12249 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12250 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12251 (goto-char (match-end 0))
12252 (backward-char)
12253 (forward-sexp)
12254 (setq pos (point))
12255 (vhdl-forward-syntactic-ws)
12256 (when (looking-at "port\\s-+map[ \t\n]*(")
12257 (goto-char (match-end 0))
12258 (backward-char)
12259 (forward-sexp)
12260 (setq pos (point)))
12261 (goto-char pos))
12262 ;; subprogram declaration/body
12263 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12264 (goto-char (match-end 0))
12265 (vhdl-forward-syntactic-ws)
12266 (when (looking-at "(")
12267 (forward-sexp))
12268 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12269 (vhdl-in-literal)))
12270 ;; subprogram body
12271 (when (match-string 2)
12272 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12273 (backward-word 1)
12274 (vhdl-forward-sexp)))
12275 ;; block (recursive)
12276 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12277 (goto-char (match-end 0))
12278 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12279 (match-beginning 2))
12280 (vhdl-hs-forward-sexp-func count)))
12281 ;; process
12282 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12283 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12284 ;; configuration declaration
12285 ((looking-at "^\\s-*configuration\\>")
12286 (forward-word 4)
12287 (vhdl-forward-sexp))
12288 (t (goto-char pos))))))
5eabfe72
KH
12289
12290(defun vhdl-hideshow-init ()
12291 "Initialize `hideshow'."
3dcb36b7
JB
12292 (when vhdl-hideshow-menu
12293 (vhdl-hs-minor-mode 1)))
12294
12295(defun vhdl-hs-minor-mode (&optional arg)
12296 "Toggle hideshow minor mode and update menu bar."
12297 (interactive "P")
12298 (require 'hideshow)
12299 ;; check for hideshow version 5.x
12300 (if (not (boundp 'hs-block-start-mdata-select))
12301 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12302 ;; initialize hideshow
12303 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12304 (setq hs-special-modes-alist
12305 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12306 'vhdl-hs-forward-sexp-func nil)
12307 hs-special-modes-alist)))
12308 (make-local-variable 'hs-minor-mode-hook)
12309 (if vhdl-hide-all-init
12310 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12311 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12312 (hs-minor-mode arg)
12313 (vhdl-mode-line-update))) ; hack to update menu bar
5eabfe72
KH
12314
12315
12316;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12317;;; Font locking
12318;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12319;; (using `font-lock.el')
12320
5eabfe72 12321;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12322;; Help functions
5eabfe72
KH
12323
12324(defun vhdl-within-translate-off ()
12325 "Return point if within translate-off region, else nil."
12326 (and (save-excursion
12327 (re-search-backward
12328 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12329 (equal "off" (match-string 1))
12330 (point)))
12331
12332(defun vhdl-start-translate-off (limit)
12333 "Return point before translate-off pragma if before LIMIT, else nil."
12334 (when (re-search-forward
12335 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12336 (match-beginning 0)))
12337
12338(defun vhdl-end-translate-off (limit)
12339 "Return point after translate-on pragma if before LIMIT, else nil."
12340 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12341
12342(defun vhdl-match-translate-off (limit)
12343 "Match a translate-off block, setting match-data and returning t, else nil."
12344 (when (< (point) limit)
12345 (let ((start (or (vhdl-within-translate-off)
12346 (vhdl-start-translate-off limit)))
12347 (case-fold-search t))
12348 (when start
12349 (let ((end (or (vhdl-end-translate-off limit) limit)))
12350 (set-match-data (list start end))
12351 (goto-char end))))))
12352
12353(defun vhdl-font-lock-match-item (limit)
12354 "Match, and move over, any declaration item after point. Adapted from
12355`font-lock-match-c-style-declaration-item-and-skip-to-next'."
12356 (condition-case nil
12357 (save-restriction
12358 (narrow-to-region (point-min) limit)
12359 ;; match item
3dcb36b7 12360 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5eabfe72
KH
12361 (save-match-data
12362 (goto-char (match-end 1))
12363 ;; move to next item
12364 (if (looking-at "\\(\\s-*,\\)")
12365 (goto-char (match-end 1))
12366 (end-of-line) t))))
12367 (error t)))
12368
12369;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12370;; Syntax definitions
12371
5eabfe72
KH
12372(defconst vhdl-font-lock-syntactic-keywords
12373 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12374 "Mark single quotes as having string quote syntax in 'c' instances.")
12375
d2ddb974
KH
12376(defvar vhdl-font-lock-keywords nil
12377 "Regular expressions to highlight in VHDL Mode.")
12378
3dcb36b7
JB
12379(defvar vhdl-font-lock-keywords-0
12380 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12381 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12382This does highlighting of template prompts and directives (pragmas).")
d2ddb974 12383
5eabfe72 12384(defvar vhdl-font-lock-keywords-1 nil
3dcb36b7 12385 ;; set in `vhdl-font-lock-init' because dependent on user options
5eabfe72
KH
12386 "For consideration as a value of `vhdl-font-lock-keywords'.
12387This does highlighting of keywords and standard identifiers.")
12388
12389(defconst vhdl-font-lock-keywords-2
d2ddb974
KH
12390 (list
12391 ;; highlight names of units, subprograms, and components when declared
12392 (list
12393 (concat
12394 "^\\s-*\\("
3dcb36b7
JB
12395 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12396 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
d2ddb974 12397 "\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12398 5 'font-lock-function-name-face)
12399
12400 ;; highlight entity names of architectures and configurations
12401 (list
12402 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12403 2 'font-lock-function-name-face)
d2ddb974
KH
12404
12405 ;; highlight labels of common constructs
12406 (list
12407 (concat
3dcb36b7
JB
12408 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12409 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12410 "postponed\\|process\\|"
5eabfe72
KH
12411 (when (vhdl-standard-p 'ams) "procedural\\|")
12412 "with\\|while"
3dcb36b7 12413 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\)*\\s-*<=\\)")
d2ddb974
KH
12414 1 'font-lock-function-name-face)
12415
5eabfe72 12416 ;; highlight label and component name of component instantiations
d2ddb974 12417 (list
5eabfe72 12418 (concat
3dcb36b7
JB
12419 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12420 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12421 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12422
12423 ;; highlight label and instantiated unit of component instantiations
12424 (list
12425 (concat
12426 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12427 "\\(component\\|configuration\\|entity\\)\\s-+"
12428 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12429 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12430 '(5 font-lock-function-name-face nil t)
12431 '(7 font-lock-function-name-face nil t))
d2ddb974
KH
12432
12433 ;; highlight names and labels at end of constructs
12434 (list
12435 (concat
5eabfe72
KH
12436 "^\\s-*end\\s-+\\(\\("
12437 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
3dcb36b7
JB
12438 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12439 "procedure\\|\\(postponed\\s-+\\)?process\\|"
5eabfe72
KH
12440 (when (vhdl-standard-p 'ams) "procedural\\|")
12441 "units"
3dcb36b7 12442 "\\)\\s-+\\)?\\(\\w*\\)")
5eabfe72
KH
12443 5 'font-lock-function-name-face)
12444
12445 ;; highlight labels in exit and next statements
12446 (list
12447 (concat
12448 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12449 3 'font-lock-function-name-face)
12450
12451 ;; highlight entity name in attribute specifications
12452 (list
12453 (concat
12454 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12455 1 'font-lock-function-name-face)
12456
3dcb36b7
JB
12457 ;; highlight labels in block and component specifications
12458 (list
12459 (concat
12460 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12461 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12462 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12463
12464 ;; highlight names in library clauses
12465 (list "^\\s-*library\\>"
12466 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12467
12468 ;; highlight names in use clauses
5eabfe72
KH
12469 (list
12470 (concat
3dcb36b7
JB
12471 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12472 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12473 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12474 '(7 font-lock-function-name-face nil t))
5eabfe72
KH
12475
12476 ;; highlight attribute name in attribute declarations/specifications
12477 (list
12478 (concat
12479 "^\\s-*attribute\\s-+\\(\\w+\\)")
12480 1 'vhdl-font-lock-attribute-face)
12481
12482 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12483 (list
12484 (concat
3dcb36b7 12485 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12486 3 'font-lock-type-face)
12487
12488 ;; highlight signal/variable/constant declaration names
12489 (list "\\(:[^=]\\)"
12490 '(vhdl-font-lock-match-item
12491 (progn (goto-char (match-beginning 1))
12492 (skip-syntax-backward " ")
12493 (skip-syntax-backward "w_")
12494 (skip-syntax-backward " ")
12495 (while (= (preceding-char) ?,)
12496 (backward-char 1)
12497 (skip-syntax-backward " ")
12498 (skip-syntax-backward "w_")
12499 (skip-syntax-backward " ")))
12500; (skip-chars-backward "^-(\n\";")
12501 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12502
3dcb36b7
JB
12503 ;; highlight formal parameters in component instantiations and subprogram
12504 ;; calls
12505 (list "\\(=>\\)"
12506 '(vhdl-font-lock-match-item
12507 (progn (goto-char (match-beginning 1))
12508 (skip-syntax-backward " ")
12509 (while (= (preceding-char) ?\)) (backward-sexp))
12510 (skip-syntax-backward "w_")
12511 (skip-syntax-backward " ")
12512 (when (memq (preceding-char) '(?n ?N))
12513 (goto-char (point-max))))
12514 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12515
12516 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12517 ;; variables
12518 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
5eabfe72
KH
12519 '(vhdl-font-lock-match-item
12520 (progn (goto-char (match-end 1)) (match-beginning 2))
12521 nil (1 font-lock-variable-name-face)))
d2ddb974 12522 )
5eabfe72
KH
12523 "For consideration as a value of `vhdl-font-lock-keywords'.
12524This does context sensitive highlighting of names and labels.")
d2ddb974 12525
5eabfe72 12526(defvar vhdl-font-lock-keywords-3 nil
3dcb36b7 12527 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12528 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72
KH
12529This does highlighting of words with special syntax.")
12530
12531(defvar vhdl-font-lock-keywords-4 nil
3dcb36b7 12532 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12533 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12534This does highlighting of additional reserved words.")
d2ddb974 12535
5eabfe72
KH
12536(defconst vhdl-font-lock-keywords-5
12537 ;; background highlight translate-off regions
12538 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12539 "For consideration as a value of `vhdl-font-lock-keywords'.
12540This does background highlighting of translate-off regions.")
12541
12542;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12543;; Font and color definitions
12544
5eabfe72 12545(defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
d2ddb974
KH
12546 "Face name to use for prompts.")
12547
5eabfe72
KH
12548(defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12549 "Face name to use for standardized attributes.")
12550
12551(defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12552 "Face name to use for standardized enumeration values.")
d2ddb974 12553
5eabfe72
KH
12554(defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12555 "Face name to use for standardized functions and packages.")
d2ddb974 12556
5eabfe72
KH
12557(defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12558 "Face name to use for directives.")
d2ddb974 12559
5eabfe72
KH
12560(defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12561 "Face name to use for additional reserved words.")
d2ddb974 12562
5eabfe72
KH
12563(defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12564 "Face name to use for translate-off regions.")
d2ddb974 12565
5eabfe72
KH
12566;; face names to use for words with special syntax.
12567(let ((syntax-alist vhdl-special-syntax-alist)
12568 name)
12569 (while syntax-alist
12570 (setq name (vhdl-function-name
12571 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
d4a5b644
GM
12572 (eval `(defvar ,name ',name
12573 ,(concat "Face name to use for "
12574 (nth 0 (car syntax-alist)) ".")))
5eabfe72
KH
12575 (setq syntax-alist (cdr syntax-alist))))
12576
3dcb36b7 12577(defgroup vhdl-highlight-faces nil
5eabfe72
KH
12578 "Faces for highlighting."
12579 :group 'vhdl-highlight)
d2ddb974 12580
3dcb36b7
JB
12581;; add faces used from `font-lock'
12582(custom-add-to-group
12583 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12584(custom-add-to-group
12585 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12586(custom-add-to-group
12587 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12588(custom-add-to-group
12589 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12590(custom-add-to-group
12591 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12592(custom-add-to-group
12593 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12594
d2ddb974 12595(defface vhdl-font-lock-prompt-face
ea81d57e
DN
12596 '((((min-colors 88) (class color) (background light))
12597 (:foreground "Red1" :bold t))
12598 (((class color) (background light)) (:foreground "Red" :bold t))
3dcb36b7 12599 (((class color) (background dark)) (:foreground "Pink" :bold t))
d2ddb974 12600 (t (:inverse-video t)))
5eabfe72
KH
12601 "Font lock mode face used to highlight prompts."
12602 :group 'vhdl-highlight-faces
d2ddb974
KH
12603 :group 'font-lock-highlighting-faces)
12604
12605(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12606 '((((class color) (background light)) (:foreground "Orchid"))
12607 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12608 (t (:italic t :bold t)))
5eabfe72
KH
12609 "Font lock mode face used to highlight standardized attributes."
12610 :group 'vhdl-highlight-faces
d2ddb974
KH
12611 :group 'font-lock-highlighting-faces)
12612
5eabfe72 12613(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12614 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12615 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12616 (t (:italic t :bold t)))
5eabfe72
KH
12617 "Font lock mode face used to highlight standardized enumeration values."
12618 :group 'vhdl-highlight-faces
d2ddb974
KH
12619 :group 'font-lock-highlighting-faces)
12620
5eabfe72 12621(defface vhdl-font-lock-function-face
3dcb36b7 12622 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12623 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12624 (t (:italic t :bold t)))
5eabfe72
KH
12625 "Font lock mode face used to highlight standardized functions and packages."
12626 :group 'vhdl-highlight-faces
d2ddb974
KH
12627 :group 'font-lock-highlighting-faces)
12628
5eabfe72
KH
12629(defface vhdl-font-lock-directive-face
12630 '((((class color) (background light)) (:foreground "CadetBlue"))
12631 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12632 (t (:italic t :bold t)))
5eabfe72
KH
12633 "Font lock mode face used to highlight directives."
12634 :group 'vhdl-highlight-faces
d2ddb974
KH
12635 :group 'font-lock-highlighting-faces)
12636
5eabfe72 12637(defface vhdl-font-lock-reserved-words-face
3dcb36b7 12638 '((((class color) (background light)) (:foreground "Orange" :bold t))
ea81d57e
DN
12639 (((min-colors 88) (class color) (background dark))
12640 (:foreground "Yellow1" :bold t))
3dcb36b7 12641 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12642 (t ()))
5eabfe72
KH
12643 "Font lock mode face used to highlight additional reserved words."
12644 :group 'vhdl-highlight-faces
d2ddb974
KH
12645 :group 'font-lock-highlighting-faces)
12646
5eabfe72
KH
12647(defface vhdl-font-lock-translate-off-face
12648 '((((class color) (background light)) (:background "LightGray"))
12649 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12650 (t ()))
5eabfe72
KH
12651 "Font lock mode face used to background highlight translate-off regions."
12652 :group 'vhdl-highlight-faces
d2ddb974
KH
12653 :group 'font-lock-highlighting-faces)
12654
5eabfe72
KH
12655;; font lock mode faces used to highlight words with special syntax.
12656(let ((syntax-alist vhdl-special-syntax-alist))
12657 (while syntax-alist
d4a5b644 12658 (eval `(defface ,(vhdl-function-name
3dcb36b7 12659 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12660 '((((class color) (background light))
12661 (:foreground ,(nth 2 (car syntax-alist))))
12662 (((class color) (background dark))
12663 (:foreground ,(nth 3 (car syntax-alist))))
12664 (t ()))
12665 ,(concat "Font lock mode face used to highlight "
12666 (nth 0 (car syntax-alist)) ".")
12667 :group 'vhdl-highlight-faces
12668 :group 'font-lock-highlighting-faces))
5eabfe72
KH
12669 (setq syntax-alist (cdr syntax-alist))))
12670
12671;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12672;; Font lock initialization
12673
12674(defun vhdl-font-lock-init ()
5eabfe72 12675 "Initialize fontification."
3dcb36b7
JB
12676 ;; highlight template prompts and directives
12677 (setq vhdl-font-lock-keywords-0
12678 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12679 vhdl-template-prompt-syntax ">\\)")
12680 2 'vhdl-font-lock-prompt-face t)
12681 (list (concat "--\\s-*"
12682 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12683 2 'vhdl-font-lock-directive-face t)))
5eabfe72
KH
12684 ;; highlight keywords and standardized types, attributes, enumeration
12685 ;; values, and subprograms
12686 (setq vhdl-font-lock-keywords-1
12687 (list
12688 (list (concat "'" vhdl-attributes-regexp)
12689 1 'vhdl-font-lock-attribute-face)
12690 (list vhdl-types-regexp 1 'font-lock-type-face)
12691 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12692 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12693 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12694 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12695 ;; highlight words with special syntax.
12696 (setq vhdl-font-lock-keywords-3
12697 (let ((syntax-alist vhdl-special-syntax-alist)
12698 keywords)
12699 (while syntax-alist
12700 (setq keywords
12701 (cons
12702 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12703 (vhdl-function-name
12704 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12705 keywords))
12706 (setq syntax-alist (cdr syntax-alist)))
12707 keywords))
12708 ;; highlight additional reserved words
12709 (setq vhdl-font-lock-keywords-4
12710 (list (list vhdl-reserved-words-regexp 1
12711 'vhdl-font-lock-reserved-words-face)))
12712 ;; highlight everything together
d2ddb974 12713 (setq vhdl-font-lock-keywords
5eabfe72
KH
12714 (append
12715 vhdl-font-lock-keywords-0
12716 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12717 (when (or vhdl-highlight-forbidden-words
12718 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12719 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12720 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12721 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12722
12723;; initialize fontification for VHDL Mode
12724(vhdl-font-lock-init)
12725
12726(defun vhdl-fontify-buffer ()
12727 "Re-initialize fontification and fontify buffer."
12728 (interactive)
12729 (setq font-lock-defaults
12730 (list
12731 'vhdl-font-lock-keywords nil
12732 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12733 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12734 (when (fboundp 'font-lock-unset-defaults)
12735 (font-lock-unset-defaults)) ; not implemented in XEmacs
12736 (font-lock-set-defaults)
3dcb36b7
JB
12737 (font-lock-mode nil)
12738 (font-lock-mode t))
5eabfe72
KH
12739
12740;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12741;; Initialization for postscript printing
12742
12743(defun vhdl-ps-print-settings ()
12744 "Initialize custom face and page settings for postscript printing."
12745 ;; define custom face settings
12746 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12747 ps-print-color-p)
12748 (set (make-local-variable 'ps-bold-faces)
12749 '(font-lock-keyword-face
12750 font-lock-type-face
12751 vhdl-font-lock-attribute-face
5eabfe72
KH
12752 vhdl-font-lock-enumvalue-face
12753 vhdl-font-lock-directive-face))
d2ddb974
KH
12754 (set (make-local-variable 'ps-italic-faces)
12755 '(font-lock-comment-face
12756 font-lock-function-name-face
12757 font-lock-type-face
d2ddb974 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-underlined-faces)
12762 '(font-lock-string-face))
5eabfe72 12763 (setq ps-always-build-face-reference t))
d2ddb974
KH
12764 ;; define page settings, so that a line containing 79 characters (default)
12765 ;; fits into one column
5eabfe72
KH
12766 (when vhdl-print-two-column
12767 (set (make-local-variable 'ps-landscape-mode) t)
12768 (set (make-local-variable 'ps-number-of-columns) 2)
12769 (set (make-local-variable 'ps-font-size) 7.0)
12770 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12771 (set (make-local-variable 'ps-header-font-size) 9.0)
12772 (set (make-local-variable 'ps-header-offset) 12.0)
12773 (when (eq ps-paper-type 'letter)
12774 (set (make-local-variable 'ps-inter-column) 40.0)
12775 (set (make-local-variable 'ps-left-margin) 40.0)
12776 (set (make-local-variable 'ps-right-margin) 40.0))))
12777
12778(defun vhdl-ps-print-init ()
12779 "Initialize postscript printing."
3dcb36b7
JB
12780 (if vhdl-xemacs
12781 (when (boundp 'ps-print-color-p)
12782 (vhdl-ps-print-settings))
5eabfe72
KH
12783 (make-local-variable 'ps-print-hook)
12784 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12785
12786
12787;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12788;;; Hierarchy browser (using `speedbar.el')
12789;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12790;; Allows displaying the hierarchy of all VHDL design units contained in a
12791;; directory by using the speedbar.
12792
12793;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12794;; Variables
12795
12796(defvar vhdl-entity-alist nil
3dcb36b7
JB
12797 "Cache with entities and corresponding architectures for each
12798project/directory.")
5eabfe72 12799;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12800;; (cache-key
12801;; (ent-key ent-name ent-file ent-line
12802;; (arch-key arch-name arch-file arch-line
12803;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12804;; inst-arch-key inst-conf-key inst-lib-key)
12805;; (lib-name pack-key))
12806;; (lib-name pack-key))
12807
12808(defvar vhdl-config-alist nil
12809 "Cache with configurations for each project/directory.")
12810;; structure: (parenthesised expression means list of such entries)
12811;; (cache-key
12812;; (conf-key conf-name conf-file conf-line ent-key arch-key
12813;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12814;; inst-conf-key inst-lib-key)
12815;; (lib-name pack-key)))
5eabfe72
KH
12816
12817(defvar vhdl-package-alist nil
3dcb36b7 12818 "Cache with packages for each project/directory.")
5eabfe72 12819;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12820;; (cache-key
12821;; (pack-key pack-name pack-file pack-line
12822;; (comp-key comp-name comp-file comp-line)
12823;; (func-key func-name func-file func-line)
12824;; (lib-name pack-key)
12825;; pack-body-file pack-body-line
12826;; (func-key func-name func-body-file func-body-line)
12827;; (lib-name pack-key)))
5eabfe72
KH
12828
12829(defvar vhdl-ent-inst-alist nil
3dcb36b7 12830 "Cache with instantiated entities for each project/directory.")
5eabfe72 12831;; structure: (parenthesised expression means list of such entries)
3dcb36b7 12832;; (cache-key (inst-ent-key))
5eabfe72 12833
3dcb36b7
JB
12834(defvar vhdl-file-alist nil
12835 "Cache with design units in each file for each project/directory.")
12836;; structure: (parenthesised expression means list of such entries)
12837;; (cache-key
12838;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
12839;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 12840
3dcb36b7
JB
12841(defvar vhdl-directory-alist nil
12842 "Cache with source directories for each project.")
12843;; structure: (parenthesised expression means list of such entries)
12844;; (cache-key (directory))
5eabfe72 12845
3dcb36b7 12846(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
12847 "Alist of design units simultaneously open in the current speedbar for each
12848directory and project.")
12849
3dcb36b7
JB
12850(defvar vhdl-speedbar-shown-project-list nil
12851 "List of projects simultaneously open in the current speedbar.")
5eabfe72 12852
3dcb36b7
JB
12853(defvar vhdl-updated-project-list nil
12854 "List of projects and directories with updated files.")
12855
12856(defvar vhdl-modified-file-list nil
12857 "List of modified files to be rescanned for hierarchy updating.")
12858
12859(defvar vhdl-speedbar-hierarchy-depth 0
12860 "Depth of instantiation hierarchy to display.")
12861
12862(defvar vhdl-speedbar-show-projects nil
12863 "Non-nil means project hierarchy is displayed in speedbar, directory
12864hierarchy otherwise.")
12865
12866(defun vhdl-get-end-of-unit ()
12867 "Return position of end of current unit."
12868 (let ((pos (point)))
12869 (save-excursion
12870 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
12871 (save-excursion
12872 (goto-char (match-beginning 0))
12873 (vhdl-backward-syntactic-ws)
12874 (and (/= (preceding-char) ?\;) (not (bobp))))))
12875 (re-search-backward "^[ \t]*end\\>" pos 1)
12876 (point))))
12877
12878(defun vhdl-match-string-downcase (num &optional string)
12879 "Like `match-string-no-properties' with down-casing."
12880 (let ((match (match-string-no-properties num string)))
12881 (and match (downcase match))))
5eabfe72 12882
5eabfe72
KH
12883
12884;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12885;; Scan functions
12886
3dcb36b7
JB
12887(defun vhdl-scan-context-clause ()
12888 "Scan the context clause that preceeds a design unit."
12889 (let (lib-alist)
12890 (save-excursion
12891 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
12892 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
12893 (equal "USE" (upcase (match-string 1))))
12894 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
12895 (setq lib-alist (cons (cons (match-string-no-properties 1)
12896 (vhdl-match-string-downcase 2))
12897 lib-alist))))))
12898 lib-alist))
12899
12900(defun vhdl-scan-directory-contents (name &optional project update num-string
12901 non-final)
12902 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
12903 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
12904; (unless (file-directory-p (match-string 1 name))
12905; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
12906 (let* ((dir-name (match-string 1 name))
12907 (file-pattern (match-string 2 name))
12908 (is-directory (= 0 (length file-pattern)))
5eabfe72 12909 (file-list
3dcb36b7
JB
12910 (if update
12911 (list name)
12912 (if is-directory
12913 (vhdl-get-source-files t dir-name)
12914 (vhdl-directory-files
12915 dir-name t (wildcard-to-regexp file-pattern)))))
12916 (key (or project dir-name))
12917 (file-exclude-regexp
12918 (or (nth 3 (aget vhdl-project-alist project)) ""))
12919 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
12920 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
12921 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
12922 ent-alist conf-alist pack-alist ent-inst-list file-alist
12923 tmp-list tmp-entry no-files files-exist big-files)
12924 (when (or project update)
12925 (setq ent-alist (aget vhdl-entity-alist key t)
12926 conf-alist (aget vhdl-config-alist key t)
12927 pack-alist (aget vhdl-package-alist key t)
12928 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
12929 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
12930 (when (and (not is-directory) (null file-list))
12931 (message "No such file: \"%s\"" name))
3dcb36b7
JB
12932 (setq files-exist file-list)
12933 (when file-list
12934 (setq no-files (length file-list))
12935 (message "Scanning %s %s\"%s\"..."
12936 (if is-directory "directory" "files") (or num-string "") name)
12937 ;; exclude files
12938 (unless (equal file-exclude-regexp "")
12939 (let ((case-fold-search nil)
12940 file-tmp-list)
12941 (while file-list
12942 (unless (string-match file-exclude-regexp (car file-list))
12943 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
12944 (setq file-list (cdr file-list)))
12945 (setq file-list (nreverse file-tmp-list))))
12946 ;; do for all files
12947 (while file-list
12948 (unless noninteractive
5eabfe72
KH
12949 (message "Scanning %s %s\"%s\"... (%2d%s)"
12950 (if is-directory "directory" "files")
12951 (or num-string "") name
3dcb36b7
JB
12952 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
12953 (let ((file-name (abbreviate-file-name (car file-list)))
12954 ent-list arch-list arch-ent-list conf-list
12955 pack-list pack-body-list inst-list inst-ent-list)
12956 ;; scan file
12957 (vhdl-visit-file
12958 file-name nil
12959 (vhdl-prepare-search-2
12960 (save-excursion
12961 ;; scan for design units
12962 (if (and limit-design-file-size
12963 (< limit-design-file-size (buffer-size)))
12964 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
12965 (setq big-files t))
12966 ;; scan for entities
12967 (goto-char (point-min))
12968 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12969 (let* ((ent-name (match-string-no-properties 1))
12970 (ent-key (downcase ent-name))
12971 (ent-entry (aget ent-alist ent-key t))
12972 (arch-alist (nth 3 ent-entry))
12973 (lib-alist (vhdl-scan-context-clause)))
12974 (if (nth 1 ent-entry)
12975 (vhdl-warning-when-idle
12976 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12977 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
12978 file-name (vhdl-current-line))
12979 (setq ent-list (cons ent-key ent-list))
12980 (aput 'ent-alist ent-key
12981 (list ent-name file-name (vhdl-current-line)
12982 arch-alist lib-alist)))))
12983 ;; scan for architectures
12984 (goto-char (point-min))
12985 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12986 (let* ((arch-name (match-string-no-properties 1))
12987 (arch-key (downcase arch-name))
12988 (ent-name (match-string-no-properties 2))
12989 (ent-key (downcase ent-name))
12990 (ent-entry (aget ent-alist ent-key t))
12991 (arch-alist (nth 3 ent-entry))
12992 (arch-entry (aget arch-alist arch-key t))
12993 (lib-arch-alist (vhdl-scan-context-clause)))
12994 (if arch-entry
12995 (vhdl-warning-when-idle
12996 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12997 arch-name ent-name (nth 1 arch-entry)
12998 (nth 2 arch-entry) file-name (vhdl-current-line))
12999 (setq arch-list (cons arch-key arch-list)
13000 arch-ent-list (cons ent-key arch-ent-list))
13001 (aput 'arch-alist arch-key
13002 (list arch-name file-name (vhdl-current-line) nil
13003 lib-arch-alist))
13004 (aput 'ent-alist ent-key
13005 (list (or (nth 0 ent-entry) ent-name)
13006 (nth 1 ent-entry) (nth 2 ent-entry)
13007 (vhdl-sort-alist arch-alist)
13008 (nth 4 ent-entry))))))
13009 ;; scan for configurations
13010 (goto-char (point-min))
13011 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13012 (let* ((conf-name (match-string-no-properties 1))
13013 (conf-key (downcase conf-name))
13014 (conf-entry (aget conf-alist conf-key t))
13015 (ent-name (match-string-no-properties 2))
13016 (ent-key (downcase ent-name))
13017 (lib-alist (vhdl-scan-context-clause))
13018 (conf-line (vhdl-current-line))
13019 (end-of-unit (vhdl-get-end-of-unit))
13020 arch-key comp-conf-list inst-key-list
13021 inst-comp-key inst-ent-key inst-arch-key
13022 inst-conf-key inst-lib-key)
13023 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13024 (setq arch-key (vhdl-match-string-downcase 1)))
13025 (if conf-entry
13026 (vhdl-warning-when-idle
13027 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13028 conf-name ent-name (nth 1 conf-entry)
13029 (nth 2 conf-entry) file-name conf-line)
13030 (setq conf-list (cons conf-key conf-list))
13031 ;; scan for subconfigurations and subentities
13032 (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)
13033 (setq inst-comp-key (vhdl-match-string-downcase 3)
13034 inst-key-list (split-string
13035 (vhdl-match-string-downcase 1)
13036 "[ \t\n]*,[ \t\n]*"))
13037 (vhdl-forward-syntactic-ws)
13038 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13039 (setq
13040 inst-lib-key (vhdl-match-string-downcase 3)
13041 inst-ent-key (and (match-string 2)
13042 (vhdl-match-string-downcase 4))
13043 inst-arch-key (and (match-string 2)
13044 (vhdl-match-string-downcase 6))
13045 inst-conf-key (and (not (match-string 2))
13046 (vhdl-match-string-downcase 4)))
13047 (while inst-key-list
13048 (setq comp-conf-list
13049 (cons (list (car inst-key-list)
13050 inst-comp-key inst-ent-key
13051 inst-arch-key inst-conf-key
13052 inst-lib-key)
13053 comp-conf-list))
13054 (setq inst-key-list (cdr inst-key-list)))))
13055 (aput 'conf-alist conf-key
13056 (list conf-name file-name conf-line ent-key
13057 arch-key comp-conf-list lib-alist)))))
13058 ;; scan for packages
13059 (goto-char (point-min))
13060 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13061 (let* ((pack-name (match-string-no-properties 2))
13062 (pack-key (downcase pack-name))
13063 (is-body (match-string-no-properties 1))
13064 (pack-entry (aget pack-alist pack-key t))
13065 (pack-line (vhdl-current-line))
13066 (end-of-unit (vhdl-get-end-of-unit))
13067 comp-name func-name comp-alist func-alist lib-alist)
13068 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13069 (vhdl-warning-when-idle
13070 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13071 (if is-body " body" "") pack-name
13072 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13073 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13074 file-name (vhdl-current-line))
13075 ;; scan for context clauses
13076 (setq lib-alist (vhdl-scan-context-clause))
13077 ;; scan for component and subprogram declarations/bodies
13078 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13079 (if (equal (upcase (match-string 1)) "COMPONENT")
13080 (setq comp-name (match-string-no-properties 2)
13081 comp-alist
13082 (cons (list (downcase comp-name) comp-name
13083 file-name (vhdl-current-line))
13084 comp-alist))
13085 (setq func-name (match-string-no-properties 2)
13086 func-alist
13087 (cons (list (downcase func-name) func-name
13088 file-name (vhdl-current-line))
13089 func-alist))))
13090 (setq func-alist (nreverse func-alist))
13091 (setq comp-alist (nreverse comp-alist))
13092 (if is-body
13093 (setq pack-body-list (cons pack-key pack-body-list))
13094 (setq pack-list (cons pack-key pack-list)))
13095 (aput
13096 'pack-alist pack-key
13097 (if is-body
13098 (list (or (nth 0 pack-entry) pack-name)
13099 (nth 1 pack-entry) (nth 2 pack-entry)
13100 (nth 3 pack-entry) (nth 4 pack-entry)
13101 (nth 5 pack-entry)
13102 file-name pack-line func-alist lib-alist)
13103 (list pack-name file-name pack-line
13104 comp-alist func-alist lib-alist
13105 (nth 6 pack-entry) (nth 7 pack-entry)
13106 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13107 ;; scan for hierarchy
13108 (if (and limit-hier-file-size
13109 (< limit-hier-file-size (buffer-size)))
13110 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13111 (setq big-files t))
13112 ;; scan for architectures
13113 (goto-char (point-min))
13114 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13115 (let* ((ent-name (match-string-no-properties 2))
13116 (ent-key (downcase ent-name))
13117 (arch-name (match-string-no-properties 1))
13118 (arch-key (downcase arch-name))
13119 (ent-entry (aget ent-alist ent-key t))
13120 (arch-alist (nth 3 ent-entry))
13121 (arch-entry (aget arch-alist arch-key t))
13122 (beg-of-unit (point))
13123 (end-of-unit (vhdl-get-end-of-unit))
13124 (inst-no 0)
13125 inst-alist)
13126 ;; scan for contained instantiations
13127 (while (and (re-search-forward
13128 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13129 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13130 "component[ \t\n]+\\(\\w+\\)\\|"
13131 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\)") end-of-unit t)
13132 (or (not limit-hier-inst-no)
13133 (<= (setq inst-no (1+ inst-no))
13134 limit-hier-inst-no)))
13135 (let* ((inst-name (match-string-no-properties 1))
13136 (inst-key (downcase inst-name))
13137 (inst-comp-name
13138 (or (match-string-no-properties 3)
13139 (match-string-no-properties 6)))
13140 (inst-ent-key
13141 (or (and (match-string 8)
13142 (vhdl-match-string-downcase 11))
13143 (and inst-comp-name
13144 (downcase inst-comp-name))))
13145 (inst-arch-key (vhdl-match-string-downcase 13))
13146 (inst-conf-key
13147 (and (not (match-string 8))
13148 (vhdl-match-string-downcase 11)))
13149 (inst-lib-key (vhdl-match-string-downcase 10)))
13150 (goto-char (match-end 1))
13151 (setq inst-list (cons inst-key inst-list)
13152 inst-ent-list (cons inst-ent-key inst-ent-list))
13153 (setq inst-alist
13154 (append
13155 inst-alist
13156 (list (list inst-key inst-name file-name
13157 (vhdl-current-line) inst-comp-name
13158 inst-ent-key inst-arch-key
13159 inst-conf-key inst-lib-key))))))
13160 ;; scan for contained configuration specifications
13161 (goto-char beg-of-unit)
13162 (while (re-search-forward
13163 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13164 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13165 (let* ((inst-comp-name (match-string-no-properties 3))
13166 (inst-ent-key
13167 (and (match-string 6)
13168 (vhdl-match-string-downcase 9)))
13169 (inst-arch-key (vhdl-match-string-downcase 11))
13170 (inst-conf-key
13171 (and (not (match-string 6))
13172 (vhdl-match-string-downcase 9)))
13173 (inst-lib-key (vhdl-match-string-downcase 8))
13174 (inst-key-list
13175 (split-string (vhdl-match-string-downcase 1)
13176 "[ \t\n]*,[ \t\n]*"))
13177 (tmp-inst-alist inst-alist)
13178 inst-entry)
13179 (while tmp-inst-alist
13180 (when (and (or (equal "all" (car inst-key-list))
13181 (member (nth 0 (car tmp-inst-alist))
13182 inst-key-list))
13183 (equal
13184 (downcase
13185 (or (nth 4 (car tmp-inst-alist)) ""))
13186 (downcase inst-comp-name)))
13187 (setq inst-entry (car tmp-inst-alist))
13188 (setq inst-ent-list
13189 (cons (or inst-ent-key (nth 5 inst-entry))
13190 (vhdl-delete
13191 (nth 5 inst-entry) inst-ent-list)))
13192 (setq inst-entry
13193 (list (nth 0 inst-entry) (nth 1 inst-entry)
13194 (nth 2 inst-entry) (nth 3 inst-entry)
13195 (nth 4 inst-entry)
13196 (or inst-ent-key (nth 5 inst-entry))
13197 (or inst-arch-key (nth 6 inst-entry))
13198 inst-conf-key inst-lib-key))
13199 (setcar tmp-inst-alist inst-entry))
13200 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13201 ;; save in cache
13202 (aput 'arch-alist arch-key
13203 (list (nth 0 arch-entry) (nth 1 arch-entry)
13204 (nth 2 arch-entry) inst-alist
13205 (nth 4 arch-entry)))
13206 (aput 'ent-alist ent-key
13207 (list (nth 0 ent-entry) (nth 1 ent-entry)
13208 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13209 (nth 4 ent-entry)))
13210 (when (and limit-hier-inst-no
13211 (> inst-no limit-hier-inst-no))
13212 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13213 (setq big-files t))
13214 (goto-char end-of-unit))))
13215 ;; remember design units for this file
13216 (aput 'file-alist file-name
13217 (list ent-list arch-list arch-ent-list conf-list
13218 pack-list pack-body-list inst-list inst-ent-list))
13219 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13220 (setq file-list (cdr file-list))))
13221 (when (or (and (not project) files-exist)
13222 (and project (not non-final)))
13223 ;; consistency checks:
13224 ;; check whether each architecture has a corresponding entity
13225 (setq tmp-list ent-alist)
13226 (while tmp-list
13227 (when (null (nth 2 (car tmp-list)))
13228 (setq tmp-entry (car (nth 4 (car tmp-list))))
13229 (vhdl-warning-when-idle
13230 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13231 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13232 (nth 3 tmp-entry)))
13233 (setq tmp-list (cdr tmp-list)))
13234 ;; check whether configuration has a corresponding entity/architecture
13235 (setq tmp-list conf-alist)
13236 (while tmp-list
13237 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13238 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13239 (setq tmp-entry (car tmp-list))
13240 (vhdl-warning-when-idle
13241 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13242 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13243 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13244 (setq tmp-entry (car tmp-list))
13245 (vhdl-warning-when-idle
13246 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13247 (nth 1 tmp-entry) (nth 4 tmp-entry)
13248 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13249 (setq tmp-list (cdr tmp-list)))
13250 ;; check whether each package body has a package declaration
13251 (setq tmp-list pack-alist)
13252 (while tmp-list
13253 (when (null (nth 2 (car tmp-list)))
13254 (setq tmp-entry (car tmp-list))
13255 (vhdl-warning-when-idle
13256 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13257 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13258 (setq tmp-list (cdr tmp-list)))
13259 ;; sort lists
13260 (setq ent-alist (vhdl-sort-alist ent-alist))
13261 (setq conf-alist (vhdl-sort-alist conf-alist))
13262 (setq pack-alist (vhdl-sort-alist pack-alist))
13263 ;; remember updated directory/project
13264 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13265 ;; clear directory alists
13266 (unless project
13267 (adelete 'vhdl-entity-alist key)
13268 (adelete 'vhdl-config-alist key)
13269 (adelete 'vhdl-package-alist key)
13270 (adelete 'vhdl-ent-inst-alist key)
13271 (adelete 'vhdl-file-alist key))
13272 ;; put directory contents into cache
13273 (aput 'vhdl-entity-alist key ent-alist)
13274 (aput 'vhdl-config-alist key conf-alist)
13275 (aput 'vhdl-package-alist key pack-alist)
13276 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13277 (aput 'vhdl-file-alist key file-alist)
13278 ;; final messages
13279 (message "Scanning %s %s\"%s\"...done"
13280 (if is-directory "directory" "files") (or num-string "") name)
13281 (unless project (message "Scanning directory...done"))
13282 (when big-files
13283 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13284 ;; save cache when scanned non-interactively
13285 (when (or (not project) (not non-final))
13286 (when (and noninteractive vhdl-speedbar-save-cache)
13287 (vhdl-save-cache key)))
13288 t))
5eabfe72 13289
3dcb36b7 13290(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13291 "Scan the contents of all VHDL files found in the directories and files
13292of PROJECT."
3dcb36b7
JB
13293 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13294 (default-dir (vhdl-resolve-env-variable
13295 (nth 1 (aget vhdl-project-alist project))))
13296 (file-exclude-regexp
13297 (or (nth 3 (aget vhdl-project-alist project)) ""))
13298 dir-list-tmp dir dir-name num-dir act-dir recursive)
13299 ;; clear project alists
13300 (adelete 'vhdl-entity-alist project)
13301 (adelete 'vhdl-config-alist project)
13302 (adelete 'vhdl-package-alist project)
13303 (adelete 'vhdl-ent-inst-alist project)
13304 (adelete 'vhdl-file-alist project)
13305 ;; expand directory names by default-directory
13306 (message "Collecting source files...")
13307 (while dir-list
13308 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13309 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13310 (setq recursive (match-string 1 dir)
13311 dir-name (match-string 3 dir))
13312 (setq dir-list-tmp
13313 (cons (concat recursive
13314 (if (file-name-absolute-p dir-name) "" default-dir)
13315 dir-name)
13316 dir-list-tmp))
13317 (setq dir-list (cdr dir-list)))
13318 ;; resolve path wildcards
5eabfe72
KH
13319 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13320 ;; expand directories
13321 (while dir-list-tmp
13322 (setq dir (car dir-list-tmp))
13323 ;; get subdirectories
3dcb36b7 13324 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13325 (setq dir-list (append dir-list (vhdl-get-subdirs
13326 (match-string 1 dir))))
13327 (setq dir-list (append dir-list (list dir))))
13328 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13329 ;; exclude files
13330 (unless (equal file-exclude-regexp "")
13331 (let ((case-fold-search nil))
13332 (while dir-list
13333 (unless (string-match file-exclude-regexp (car dir-list))
13334 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13335 (setq dir-list (cdr dir-list)))
13336 (setq dir-list (nreverse dir-list-tmp))))
13337 (message "Collecting source files...done")
13338 ;; scan for design units for each directory in DIR-LIST
13339 (setq dir-list-tmp nil
13340 num-dir (length dir-list)
5eabfe72
KH
13341 act-dir 1)
13342 (while dir-list
3dcb36b7
JB
13343 (setq dir-name (abbreviate-file-name
13344 (expand-file-name (car dir-list))))
13345 (vhdl-scan-directory-contents dir-name project nil
13346 (format "(%s/%s) " act-dir num-dir)
13347 (cdr dir-list))
13348 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13349 (setq dir-list (cdr dir-list)
13350 act-dir (1+ act-dir)))
3dcb36b7
JB
13351 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13352 (message "Scanning project \"%s\"...done" project)))
13353
13354(defun vhdl-update-file-contents (file-name)
13355 "Update hierarchy information by contents of current buffer."
13356 (setq file-name (abbreviate-file-name file-name))
13357 (let* ((dir-name (file-name-directory file-name))
13358 (directory-alist vhdl-directory-alist)
13359 updated)
13360 (while directory-alist
13361 (when (member dir-name (nth 1 (car directory-alist)))
13362 (let* ((vhdl-project (nth 0 (car directory-alist)))
13363 (project (vhdl-project-p))
13364 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13365 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13366 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13367 (ent-inst-list (car (aget vhdl-ent-inst-alist
13368 (or project dir-name) t)))
13369 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13370 (file-entry (aget file-alist file-name t))
13371 (ent-list (nth 0 file-entry))
13372 (arch-list (nth 1 file-entry))
13373 (arch-ent-list (nth 2 file-entry))
13374 (conf-list (nth 3 file-entry))
13375 (pack-list (nth 4 file-entry))
13376 (pack-body-list (nth 5 file-entry))
13377 (inst-ent-list (nth 7 file-entry))
13378 (cache-key (or project dir-name))
13379 arch-alist key ent-key entry)
13380 ;; delete design units previously contained in this file:
13381 ;; entities
13382 (while ent-list
13383 (setq key (car ent-list)
13384 entry (aget ent-alist key t))
13385 (when (equal file-name (nth 1 entry))
13386 (if (nth 3 entry)
13387 (aput 'ent-alist key
13388 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13389 (adelete 'ent-alist key)))
13390 (setq ent-list (cdr ent-list)))
13391 ;; architectures
13392 (while arch-list
13393 (setq key (car arch-list)
13394 ent-key (car arch-ent-list)
13395 entry (aget ent-alist ent-key t)
13396 arch-alist (nth 3 entry))
13397 (when (equal file-name (nth 1 (aget arch-alist key t)))
13398 (adelete 'arch-alist key)
13399 (if (or (nth 1 entry) arch-alist)
13400 (aput 'ent-alist ent-key
13401 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13402 arch-alist (nth 4 entry)))
13403 (adelete 'ent-alist ent-key)))
13404 (setq arch-list (cdr arch-list)
13405 arch-ent-list (cdr arch-ent-list)))
13406 ;; configurations
13407 (while conf-list
13408 (setq key (car conf-list))
13409 (when (equal file-name (nth 1 (aget conf-alist key t)))
13410 (adelete 'conf-alist key))
13411 (setq conf-list (cdr conf-list)))
13412 ;; package declarations
13413 (while pack-list
13414 (setq key (car pack-list)
13415 entry (aget pack-alist key t))
13416 (when (equal file-name (nth 1 entry))
13417 (if (nth 6 entry)
13418 (aput 'pack-alist key
13419 (list (nth 0 entry) nil nil nil nil nil
13420 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13421 (nth 9 entry)))
13422 (adelete 'pack-alist key)))
13423 (setq pack-list (cdr pack-list)))
13424 ;; package bodies
13425 (while pack-body-list
13426 (setq key (car pack-body-list)
13427 entry (aget pack-alist key t))
13428 (when (equal file-name (nth 6 entry))
13429 (if (nth 1 entry)
13430 (aput 'pack-alist key
13431 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13432 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13433 nil nil nil nil))
13434 (adelete 'pack-alist key)))
13435 (setq pack-body-list (cdr pack-body-list)))
13436 ;; instantiated entities
13437 (while inst-ent-list
13438 (setq ent-inst-list
13439 (vhdl-delete (car inst-ent-list) ent-inst-list))
13440 (setq inst-ent-list (cdr inst-ent-list)))
13441 ;; update caches
13442 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13443 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13444 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13445 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13446 ;; scan file
13447 (vhdl-scan-directory-contents file-name project t)
13448 (when (or (and vhdl-speedbar-show-projects project)
13449 (and (not vhdl-speedbar-show-projects) (not project)))
13450 (vhdl-speedbar-refresh project))
13451 (setq updated t)))
13452 (setq directory-alist (cdr directory-alist)))
13453 updated))
13454
13455(defun vhdl-update-hierarchy ()
13456 "Update directory and hierarchy information in speedbar."
13457 (let ((file-list (reverse vhdl-modified-file-list))
13458 updated)
13459 (when (and vhdl-speedbar-update-on-saving file-list)
13460 (while file-list
13461 (setq updated
13462 (or (vhdl-update-file-contents (car file-list))
13463 updated))
13464 (setq file-list (cdr file-list)))
13465 (setq vhdl-modified-file-list nil)
13466 (when updated (message "Updating hierarchy...done")))))
13467
13468;; structure (parenthesised expression means list of such entries)
13469;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13470;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13471;; comp-lib-name level)
13472(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13473 conf-inst-alist level indent
13474 &optional include-top ent-hier)
13475 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13476entity ENT-KEY."
13477 (let* ((ent-entry (aget ent-alist ent-key t))
13478 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13479 (cdar (last (nth 3 ent-entry)))))
13480 (inst-alist (nth 3 arch-entry))
13481 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13482 hier-list subcomp-list tmp-list inst-key inst-comp-name
13483 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13484 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13485 (when include-top
13486 (setq level (1+ level)))
13487 (when (member ent-key ent-hier)
13488 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13489 ;; check configured architecture (already checked during scanning)
13490; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13491; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13492 ;; process all instances
13493 (while inst-alist
13494 (setq inst-entry (car inst-alist)
13495 inst-key (nth 0 inst-entry)
13496 inst-comp-name (nth 4 inst-entry)
13497 inst-conf-key (nth 7 inst-entry))
13498 ;; search entry in configuration's instantiations list
13499 (setq tmp-list conf-inst-alist)
13500 (while (and tmp-list
13501 (not (and (member (nth 0 (car tmp-list))
13502 (list "all" inst-key))
13503 (equal (nth 1 (car tmp-list))
13504 (downcase (or inst-comp-name ""))))))
13505 (setq tmp-list (cdr tmp-list)))
13506 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13507 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13508 (when (and inst-conf-key (not inst-conf-entry))
13509 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13510 ;; determine entity
13511 (setq inst-ent-key
13512 (or (nth 2 (car tmp-list)) ; from configuration
13513 (nth 3 inst-conf-entry) ; from subconfiguration
13514 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13515 ; from configuration spec.
13516 (nth 5 inst-entry))) ; from direct instantiation
13517 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13518 ;; determine architecture
13519 (setq inst-arch-key
13520 (or (nth 3 (car tmp-list)) ; from configuration
13521 (nth 4 inst-conf-entry) ; from subconfiguration
13522 (nth 6 inst-entry) ; from direct instantiation
13523 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13524 ; from configuration spec.
13525 (caar (nth 3 inst-ent-entry)))) ; random (simplified MRA)
13526 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13527 ;; set library
13528 (setq inst-lib-key
13529 (or (nth 5 (car tmp-list)) ; from configuration
13530 (nth 8 inst-entry))) ; from direct instantiation
13531 ;; gather information for this instance
13532 (setq comp-entry
13533 (list (nth 1 inst-entry)
13534 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13535 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13536 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13537 (or (nth 0 inst-arch-entry) inst-arch-key)
13538 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13539 (or (nth 0 inst-conf-entry) inst-conf-key)
13540 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13541 inst-lib-key level))
13542 ;; get subcomponent hierarchy
13543 (setq subcomp-list (vhdl-get-hierarchy
13544 ent-alist conf-alist
13545 inst-ent-key inst-arch-key inst-conf-key
13546 (nth 5 inst-conf-entry)
13547 (1+ level) indent nil (cons ent-key ent-hier)))
13548 ;; add to list
13549 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13550 (setq inst-alist (cdr inst-alist)))
13551 (when include-top
5eabfe72 13552 (setq hier-list
3dcb36b7
JB
13553 (cons (list nil nil (nth 0 ent-entry)
13554 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13555 (nth 0 arch-entry)
13556 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13557 nil nil
13558 nil (1- level))
13559 hier-list)))
13560 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13561 hier-list))
13562
3dcb36b7
JB
13563(defun vhdl-get-instantiations (ent-key indent)
13564 "Get all instantiations of entity ENT-KEY."
13565 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13566 arch-alist inst-alist ent-inst-list
13567 ent-entry arch-entry inst-entry)
13568 (while ent-alist
13569 (setq ent-entry (car ent-alist))
3dcb36b7 13570 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13571 (while arch-alist
13572 (setq arch-entry (car arch-alist))
3dcb36b7 13573 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13574 (while inst-alist
13575 (setq inst-entry (car inst-alist))
3dcb36b7 13576 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13577 (setq ent-inst-list
3dcb36b7
JB
13578 (cons (list (nth 1 inst-entry)
13579 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13580 (nth 1 ent-entry)
13581 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13582 (nth 1 arch-entry)
13583 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13584 ent-inst-list)))
5eabfe72
KH
13585 (setq inst-alist (cdr inst-alist)))
13586 (setq arch-alist (cdr arch-alist)))
13587 (setq ent-alist (cdr ent-alist)))
13588 (nreverse ent-inst-list)))
13589
13590;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13591;; Caching in file
13592
13593(defun vhdl-save-caches ()
13594 "Save all updated hierarchy caches to file."
13595 (interactive)
13596 (condition-case nil
13597 (when vhdl-speedbar-save-cache
13598 ;; update hierarchy
13599 (vhdl-update-hierarchy)
13600 (let ((project-list vhdl-updated-project-list))
13601 (message "Saving hierarchy caches...")
13602 ;; write updated project caches
13603 (while project-list
13604 (vhdl-save-cache (car project-list))
13605 (setq project-list (cdr project-list)))
13606 (message "Saving hierarchy caches...done")))
13607 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13608 (sit-for 2)))))
13609
13610(defun vhdl-save-cache (key)
13611 "Save current hierarchy cache to file."
13612 (let* ((orig-buffer (current-buffer))
13613 (vhdl-project key)
13614 (project (vhdl-project-p))
13615 (default-directory key)
13616 (directory (abbreviate-file-name (vhdl-default-directory)))
13617 (file-name (vhdl-resolve-env-variable
13618 (vhdl-replace-string
13619 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13620 (concat
13621 (subst-char-in-string ? ?_ (or project "dir"))
13622 " " (user-login-name)))))
13623 (file-dir-name (expand-file-name file-name directory))
13624 (cache-key (or project directory))
13625 (key (if project "project" "directory")))
13626 (unless (file-exists-p (file-name-directory file-dir-name))
13627 (make-directory (file-name-directory file-dir-name) t))
13628 (if (not (file-writable-p file-dir-name))
13629 (progn (vhdl-warning (format "File not writable: \"%s\""
13630 (abbreviate-file-name file-dir-name)))
13631 (sit-for 2))
13632 (message "Saving cache: \"%s\"" file-dir-name)
13633 (set-buffer (find-file-noselect file-dir-name t t))
13634 (erase-buffer)
13635 (insert ";; -*- Emacs-Lisp -*-\n\n"
13636 ";;; " (file-name-nondirectory file-name)
13637 " - design hierarchy cache file for Emacs VHDL Mode "
13638 vhdl-version "\n")
13639 (insert "\n;; " (if project "Project " "Directory") " : ")
13640 (if project (insert project) (prin1 directory (current-buffer)))
13641 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13642 (user-login-name) "\n\n"
13643 "\n;; version number\n"
13644 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13645 "\n;; " (if project "project" "directory") " name"
13646 "\n(setq " key " ")
13647 (prin1 (or project directory) (current-buffer))
13648 (insert ")\n")
13649 (when (member 'hierarchy vhdl-speedbar-save-cache)
13650 (insert "\n;; entity and architecture cache\n"
13651 "(aput 'vhdl-entity-alist " key " '")
13652 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13653 (insert ")\n\n;; configuration cache\n"
13654 "(aput 'vhdl-config-alist " key " '")
13655 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13656 (insert ")\n\n;; package cache\n"
13657 "(aput 'vhdl-package-alist " key " '")
13658 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13659 (insert ")\n\n;; instantiated entities cache\n"
13660 "(aput 'vhdl-ent-inst-alist " key " '")
13661 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13662 (insert ")\n\n;; design units per file cache\n"
13663 "(aput 'vhdl-file-alist " key " '")
13664 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13665 (when project
13666 (insert ")\n\n;; source directories in project cache\n"
13667 "(aput 'vhdl-directory-alist " key " '")
13668 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13669 (insert ")\n"))
13670 (when (member 'display vhdl-speedbar-save-cache)
13671 (insert "\n;; shown design units cache\n"
13672 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13673 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13674 (current-buffer))
13675 (insert ")\n"))
13676 (setq vhdl-updated-project-list
13677 (delete cache-key vhdl-updated-project-list))
13678 (save-buffer)
13679 (kill-buffer (current-buffer))
13680 (set-buffer orig-buffer))))
13681
13682(defun vhdl-load-cache (key)
13683 "Load hierarchy cache information from file."
13684 (let* ((vhdl-project key)
13685 (default-directory key)
13686 (directory (vhdl-default-directory))
13687 (file-name (vhdl-resolve-env-variable
13688 (vhdl-replace-string
13689 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13690 (concat
13691 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13692 " " (user-login-name)))))
13693 (file-dir-name (expand-file-name file-name directory))
13694 vhdl-cache-version)
13695 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13696 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13697 (when (file-exists-p file-dir-name)
13698 (condition-case ()
13699 (progn (load-file file-dir-name)
13700 (string< (mapconcat
13701 (lambda (a) (format "%3d" (string-to-int a)))
13702 (split-string "3.31.14" "\\.") "")
13703 (mapconcat
13704 (lambda (a) (format "%3d" (string-to-int a)))
13705 (split-string vhdl-cache-version "\\.") "")))
13706 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13707 nil))))))
13708
13709(defun vhdl-require-hierarchy-info ()
13710 "Make sure that hierarchy information is available. Load cache or scan files
13711if required."
13712 (if (vhdl-project-p)
13713 (unless (or (assoc vhdl-project vhdl-file-alist)
13714 (vhdl-load-cache vhdl-project))
13715 (vhdl-scan-project-contents vhdl-project))
13716 (let ((directory (abbreviate-file-name default-directory)))
13717 (unless (or (assoc directory vhdl-file-alist)
13718 (vhdl-load-cache directory))
13719 (vhdl-scan-directory-contents directory)))))
13720
13721;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13722;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13723
13724(defvar vhdl-speedbar-key-map nil
13725 "Keymap used when in the VHDL hierarchy browser mode.")
13726
3dcb36b7 13727(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13728 "Additional menu-items to add to speedbar frame.")
13729
13730(defun vhdl-speedbar-initialize ()
13731 "Initialize speedbar."
13732 ;; general settings
13733; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13734 ;; VHDL file extensions (extracted from `auto-mode-alist')
13735 (let ((mode-alist auto-mode-alist))
13736 (while mode-alist
3dcb36b7
JB
13737 (when (eq (cdar mode-alist) 'vhdl-mode)
13738 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13739 (setq mode-alist (cdr mode-alist))))
13740 ;; hierarchy browser settings
13741 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13742 ;; special functions
5eabfe72 13743 (speedbar-add-mode-functions-list
3dcb36b7 13744 '("vhdl directory"
5eabfe72
KH
13745 (speedbar-item-info . vhdl-speedbar-item-info)
13746 (speedbar-line-path . speedbar-files-line-path)))
3dcb36b7
JB
13747 (speedbar-add-mode-functions-list
13748 '("vhdl project"
13749 (speedbar-item-info . vhdl-speedbar-item-info)
13750 (speedbar-line-path . vhdl-speedbar-line-project)))
13751 ;; keymap
5eabfe72
KH
13752 (unless vhdl-speedbar-key-map
13753 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13754 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13755 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13756 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
13757 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13758 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13759 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13760 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13761 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13762 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13763 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13764 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13765 (let ((key 0))
13766 (while (<= key 9)
13767 (define-key vhdl-speedbar-key-map (int-to-string key)
13768 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13769 (setq key (1+ key)))))
5eabfe72
KH
13770 (define-key speedbar-key-map "h"
13771 (lambda () (interactive)
3dcb36b7
JB
13772 (speedbar-change-initial-expansion-list "vhdl directory")))
13773 (define-key speedbar-key-map "H"
13774 (lambda () (interactive)
13775 (speedbar-change-initial-expansion-list "vhdl project")))
13776 ;; menu
13777 (unless vhdl-speedbar-menu-items
13778 (setq
13779 vhdl-speedbar-menu-items
13780 `(["Edit" speedbar-edit-line t]
13781 ["Expand" speedbar-expand-line
13782 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13783 ["Contract" vhdl-speedbar-contract-level t]
13784 ["Expand All" vhdl-speedbar-expand-all t]
13785 ["Contract All" vhdl-speedbar-contract-all t]
13786 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13787 (while (<= key 9)
13788 (setq menu-list
13789 (cons `[,(if (= key 0) "All" (int-to-string key))
13790 (vhdl-speedbar-set-depth ,key)
13791 :style radio
13792 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13793 :keys ,(int-to-string key)]
13794 menu-list))
13795 (setq key (1+ key)))
13796 (nreverse menu-list))
13797 "--"
13798 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13799 (or (vhdl-speedbar-check-unit 'entity)
13800 (vhdl-speedbar-check-unit 'subprogram))]
13801 ["Place Component" vhdl-speedbar-place-component
13802 (vhdl-speedbar-check-unit 'entity)]
13803 ["Make" vhdl-speedbar-make-design
13804 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13805 ["Generate Makefile" vhdl-speedbar-generate-makefile
13806 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
13807 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
13808 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13809 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
13810 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
13811 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13812 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
13813 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
13814 ;; hook-ups
13815 (speedbar-add-expansion-list
13816 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13817 vhdl-speedbar-display-directory))
13818 (speedbar-add-expansion-list
13819 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13820 vhdl-speedbar-display-projects))
5eabfe72 13821 (setq speedbar-stealthy-function-list
3dcb36b7
JB
13822 (append
13823 '(("vhdl directory" vhdl-speedbar-update-current-unit)
13824 ("vhdl project" vhdl-speedbar-update-current-project
13825 vhdl-speedbar-update-current-unit)
13826; ("files" (lambda () (setq speedbar-ignored-path-regexp
13827; (speedbar-extension-list-to-regex
13828; speedbar-ignored-path-expressions))))
13829 )
13830 speedbar-stealthy-function-list))
13831 (when (eq vhdl-speedbar-display-mode 'directory)
13832 (setq speedbar-initial-expansion-list-name "vhdl directory"))
13833 (when (eq vhdl-speedbar-display-mode 'project)
13834 (setq speedbar-initial-expansion-list-name "vhdl project"))
13835 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
13836
13837(defun vhdl-speedbar (&optional arg)
13838 "Open/close speedbar."
d2ddb974 13839 (interactive)
5eabfe72 13840 (if (not (fboundp 'speedbar))
3dcb36b7
JB
13841 (error "WARNING: Speedbar is not available or not installed")
13842 (condition-case ()
5eabfe72 13843 (speedbar-frame-mode arg)
3dcb36b7 13844 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
13845
13846;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13847;; Display functions
13848
3dcb36b7
JB
13849(defvar vhdl-speedbar-last-selected-project nil
13850 "Name of last selected project.")
13851
5eabfe72
KH
13852;; macros must be defined in the file they are used (copied from `speedbar.el')
13853(defmacro speedbar-with-writable (&rest forms)
13854 "Allow the buffer to be writable and evaluate FORMS."
13855 (list 'let '((inhibit-read-only t))
13856 (cons 'progn forms)))
13857(put 'speedbar-with-writable 'lisp-indent-function 0)
13858
3dcb36b7 13859(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 13860 "Display directory and hierarchy information in speedbar."
3dcb36b7
JB
13861 (setq vhdl-speedbar-show-projects nil)
13862 (setq speedbar-ignored-path-regexp
13863 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
5eabfe72
KH
13864 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
13865 (setq speedbar-last-selected-file nil)
13866 (speedbar-with-writable
3dcb36b7
JB
13867 (condition-case nil
13868 (progn
13869 ;; insert directory path
13870 (speedbar-directory-buttons directory depth)
13871 ;; insert subdirectories
13872 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
13873 ;; scan and insert hierarchy of current directory
13874 (vhdl-speedbar-insert-dir-hierarchy directory depth
13875 speedbar-power-click)
13876 ;; expand subdirectories
13877 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
13878 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
13879
13880(defun vhdl-speedbar-display-projects (project depth &optional rescan)
13881 "Display projects and hierarchy information in speedbar."
13882 (setq vhdl-speedbar-show-projects t)
13883 (setq speedbar-ignored-path-regexp ".")
13884 (setq speedbar-last-selected-file nil)
13885 (setq vhdl-speedbar-last-selected-project nil)
13886 (speedbar-with-writable
13887 (condition-case nil
13888 ;; insert projects
13889 (vhdl-speedbar-insert-projects)
13890 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
13891 (setq speedbar-full-text-cache nil)) ; prevent caching
13892
13893(defun vhdl-speedbar-insert-projects ()
13894 "Insert all projects in speedbar."
13895 (vhdl-speedbar-make-title-line "Projects:")
13896 (let ((project-alist (if vhdl-project-sort
13897 (vhdl-sort-alist (copy-alist vhdl-project-alist))
13898 vhdl-project-alist))
13899 (vhdl-speedbar-update-current-unit nil))
13900 ;; insert projects
13901 (while project-alist
13902 (speedbar-make-tag-line
13903 'angle ?+ 'vhdl-speedbar-expand-project
13904 (caar project-alist) (caar project-alist)
13905 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
13906 (setq project-alist (cdr project-alist)))
13907 (setq project-alist vhdl-project-alist)
13908 ;; expand projects
13909 (while project-alist
13910 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
13911 (goto-char (point-min))
13912 (when (re-search-forward
13913 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
13914 (goto-char (match-end 1))
13915 (speedbar-do-function-pointer)))
13916 (setq project-alist (cdr project-alist))))
13917; (vhdl-speedbar-update-current-project)
13918; (vhdl-speedbar-update-current-unit nil t)
13919 )
13920
13921(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
13922 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
13923otherwise use cached data."
13924 (when (or rescan (and (not (assoc project vhdl-file-alist))
13925 (not (vhdl-load-cache project))))
13926 (vhdl-scan-project-contents project))
13927 ;; insert design hierarchy
13928 (vhdl-speedbar-insert-hierarchy
13929 (aget vhdl-entity-alist project t)
13930 (aget vhdl-config-alist project t)
13931 (aget vhdl-package-alist project t)
13932 (car (aget vhdl-ent-inst-alist project t)) indent)
13933 (insert (int-to-string indent) ":\n")
13934 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
13935 (put-text-property (1- (point)) (point) 'invisible nil)
13936 ;; expand design units
13937 (vhdl-speedbar-expand-units project))
13938
13939(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
13940 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
13941otherwise use cached data."
13942 (when (or rescan (and (not (assoc directory vhdl-file-alist))
13943 (not (vhdl-load-cache directory))))
13944 (vhdl-scan-directory-contents directory))
13945 ;; insert design hierarchy
13946 (vhdl-speedbar-insert-hierarchy
13947 (aget vhdl-entity-alist directory t)
13948 (aget vhdl-config-alist directory t)
13949 (aget vhdl-package-alist directory t)
13950 (car (aget vhdl-ent-inst-alist directory t)) depth)
13951 ;; expand design units
13952 (vhdl-speedbar-expand-units directory)
13953 (aput 'vhdl-directory-alist directory (list (list directory))))
13954
13955(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 13956 ent-inst-list depth)
3dcb36b7
JB
13957 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
13958 (if (not (or ent-alist conf-alist pack-alist))
13959 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
13960 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
13961 ;; insert entities
13962 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
13963 (while ent-alist
13964 (setq ent-entry (car ent-alist))
13965 (speedbar-make-tag-line
13966 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
13967 (nth 1 ent-entry) 'vhdl-speedbar-find-file
13968 (cons (nth 2 ent-entry) (nth 3 ent-entry))
5eabfe72 13969 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
13970 (unless (nth 2 ent-entry)
13971 (end-of-line 0) (insert "!") (forward-char 1))
13972 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
13973 (end-of-line 0) (insert " (top)") (forward-char 1))
13974 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
13975 ;; insert configurations
13976 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
13977 (while conf-alist
13978 (setq conf-entry (car conf-alist))
13979 (speedbar-make-tag-line
13980 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
13981 (nth 1 conf-entry) 'vhdl-speedbar-find-file
13982 (cons (nth 2 conf-entry) (nth 3 conf-entry))
13983 'vhdl-speedbar-configuration-face depth)
13984 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
13985 ;; insert packages
13986 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
13987 (while pack-alist
13988 (setq pack-entry (car pack-alist))
13989 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
13990 (nth 0 pack-entry) (nth 1 pack-entry)
13991 (cons (nth 2 pack-entry) (nth 3 pack-entry))
13992 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
13993 depth)
13994 (setq pack-alist (cdr pack-alist))))))
13995
5eabfe72 13996(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 13997 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 13998 (interactive)
3dcb36b7
JB
13999 (let (key path)
14000 (cond
14001 ;; current project
14002 (vhdl-speedbar-show-projects
14003 (setq key (vhdl-speedbar-line-project))
14004 (vhdl-scan-project-contents key))
14005 ;; top-level directory
14006 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14007 (re-search-forward "[0-9]+:" nil t)
14008 (vhdl-scan-directory-contents
14009 (abbreviate-file-name (speedbar-line-path))))
14010 ;; current directory
14011 (t (setq path (speedbar-line-path))
14012 (string-match "^\\(.+[/\\]\\)" path)
14013 (vhdl-scan-directory-contents
14014 (abbreviate-file-name (match-string 1 path)))))
14015 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14016
14017(defun vhdl-speedbar-expand-dirs (directory)
14018 "Expand subdirectories in DIRECTORY according to
14019 `speedbar-shown-directories'."
14020 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14021 (let ((sf (cdr (reverse speedbar-shown-directories)))
14022 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14023 (setq speedbar-shown-directories
14024 (list (expand-file-name default-directory)))
14025 (while sf
14026 (when (speedbar-goto-this-file (car sf))
14027 (beginning-of-line)
14028 (when (looking-at "[0-9]+:\\s-*<")
14029 (goto-char (match-end 0))
3dcb36b7
JB
14030 (speedbar-do-function-pointer)))
14031 (setq sf (cdr sf))))
14032 (vhdl-speedbar-update-current-unit nil t))
14033
14034(defun vhdl-speedbar-expand-units (key)
14035 "Expand design units in directory/project KEY according to
14036`vhdl-speedbar-shown-unit-alist'."
14037 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14038 (vhdl-speedbar-update-current-unit nil)
14039 vhdl-updated-project-list)
14040 (adelete 'vhdl-speedbar-shown-unit-alist key)
14041 (vhdl-prepare-search-1
14042 (while unit-alist ; expand units
14043 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14044 (beginning-of-line)
14045 (let ((arch-alist (nth 1 (car unit-alist)))
14046 position)
14047 (when (looking-at "^[0-9]+:\\s-*\\[")
14048 (goto-char (match-end 0))
14049 (setq position (point))
14050 (speedbar-do-function-pointer)
14051 (select-frame speedbar-frame)
14052 (while arch-alist ; expand architectures
14053 (goto-char position)
14054 (when (re-search-forward
14055 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14056 (car arch-alist) "\\>\\)") nil t)
14057 (beginning-of-line)
14058 (when (looking-at "^[0-9]+:\\s-*{")
14059 (goto-char (match-end 0))
14060 (speedbar-do-function-pointer)
14061 (select-frame speedbar-frame)))
14062 (setq arch-alist (cdr arch-alist))))
14063 (setq unit-alist (cdr unit-alist))))))
14064 (vhdl-speedbar-update-current-unit nil t))
14065
14066(defun vhdl-speedbar-contract-level ()
14067 "Contract current level in current directory/project."
14068 (interactive)
14069 (when (or (save-excursion
14070 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14071 (and (save-excursion
14072 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14073 (re-search-backward
14074 (format "^[0-%d]:\\s-*[[{<]-"
14075 (max (1- (string-to-int (match-string 1))) 0)) nil t)))
14076 (goto-char (match-end 0))
14077 (speedbar-do-function-pointer)
14078 (speedbar-center-buffer-smartly)))
14079
14080(defun vhdl-speedbar-contract-all ()
14081 "Contract all expanded design units in current directory/project."
14082 (interactive)
14083 (if (and vhdl-speedbar-show-projects
14084 (save-excursion (beginning-of-line) (looking-at "^0:")))
14085 (progn (setq vhdl-speedbar-shown-project-list nil)
14086 (vhdl-speedbar-refresh))
14087 (let ((key (vhdl-speedbar-line-key)))
14088 (adelete 'vhdl-speedbar-shown-unit-alist key)
14089 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14090 (when (memq 'display vhdl-speedbar-save-cache)
14091 (add-to-list 'vhdl-updated-project-list key)))))
14092
14093(defun vhdl-speedbar-expand-all ()
14094 "Expand all design units in current directory/project."
14095 (interactive)
14096 (let* ((key (vhdl-speedbar-line-key))
14097 (ent-alist (aget vhdl-entity-alist key t))
14098 (conf-alist (aget vhdl-config-alist key t))
14099 (pack-alist (aget vhdl-package-alist key t))
14100 arch-alist unit-alist subunit-alist)
14101 (add-to-list 'vhdl-speedbar-shown-project-list key)
14102 (while ent-alist
14103 (setq arch-alist (nth 4 (car ent-alist)))
14104 (setq subunit-alist nil)
14105 (while arch-alist
14106 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14107 (setq arch-alist (cdr arch-alist)))
14108 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14109 (setq ent-alist (cdr ent-alist)))
14110 (while conf-alist
14111 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14112 (setq conf-alist (cdr conf-alist)))
14113 (while pack-alist
14114 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14115 (setq pack-alist (cdr pack-alist)))
14116 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14117 (vhdl-speedbar-refresh)
14118 (when (memq 'display vhdl-speedbar-save-cache)
14119 (add-to-list 'vhdl-updated-project-list key))))
14120
14121(defun vhdl-speedbar-expand-project (text token indent)
14122 "Expand/contract the project under the cursor."
14123 (cond
14124 ((string-match "+" text) ; expand project
14125 (speedbar-change-expand-button-char ?-)
14126 (unless (member token vhdl-speedbar-shown-project-list)
14127 (setq vhdl-speedbar-shown-project-list
14128 (cons token vhdl-speedbar-shown-project-list)))
14129 (speedbar-with-writable
14130 (save-excursion
14131 (end-of-line) (forward-char 1)
14132 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14133 speedbar-power-click))))
14134 ((string-match "-" text) ; contract project
14135 (speedbar-change-expand-button-char ?+)
14136 (setq vhdl-speedbar-shown-project-list
14137 (delete token vhdl-speedbar-shown-project-list))
14138 (speedbar-delete-subblock indent))
14139 (t (error "Nothing to display")))
14140 (when (equal (selected-frame) speedbar-frame)
14141 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14142
14143(defun vhdl-speedbar-expand-entity (text token indent)
14144 "Expand/contract the entity under the cursor."
14145 (cond
14146 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14147 (let* ((key (vhdl-speedbar-line-key indent))
14148 (ent-alist (aget vhdl-entity-alist key t))
14149 (ent-entry (aget ent-alist token t))
14150 (arch-alist (nth 3 ent-entry))
5eabfe72 14151 (inst-alist (vhdl-get-instantiations token indent))
3dcb36b7
JB
14152 (subpack-alist (nth 4 ent-entry))
14153 arch-entry inst-entry)
14154 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14155 (speedbar-change-expand-button-char ??)
14156 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14157 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14158 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14159 (aput 'unit-alist token nil)
14160 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14161 (speedbar-with-writable
3dcb36b7
JB
14162 (save-excursion
14163 (end-of-line) (forward-char 1)
14164 ;; insert architectures
14165 (when arch-alist
14166 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14167 (while arch-alist
14168 (setq arch-entry (car arch-alist))
14169 (speedbar-make-tag-line
14170 'curly ?+ 'vhdl-speedbar-expand-architecture
14171 (cons token (nth 0 arch-entry))
14172 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14173 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14174 'vhdl-speedbar-architecture-face (1+ indent))
14175 (setq arch-alist (cdr arch-alist)))
14176 ;; insert instantiations
14177 (when inst-alist
14178 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14179 (while inst-alist
14180 (setq inst-entry (car inst-alist))
14181 (vhdl-speedbar-make-inst-line
14182 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14183 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14184 nil nil nil (1+ indent) 0 " in ")
14185 (setq inst-alist (cdr inst-alist)))
14186 ;; insert required packages
14187 (vhdl-speedbar-insert-subpackages
14188 subpack-alist (1+ indent) indent)))
14189 (when (memq 'display vhdl-speedbar-save-cache)
14190 (add-to-list 'vhdl-updated-project-list key))
14191 (vhdl-speedbar-update-current-unit t t))))
5eabfe72
KH
14192 ((string-match "-" text) ; contract entity
14193 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14194 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14195 (let* ((key (vhdl-speedbar-line-key indent))
14196 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14197 (adelete 'unit-alist token)
14198 (if unit-alist
14199 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14200 (adelete 'vhdl-speedbar-shown-unit-alist key))
14201 (speedbar-delete-subblock indent)
14202 (when (memq 'display vhdl-speedbar-save-cache)
14203 (add-to-list 'vhdl-updated-project-list key))))
14204 (t (error "Nothing to display")))
14205 (when (equal (selected-frame) speedbar-frame)
14206 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14207
14208(defun vhdl-speedbar-expand-architecture (text token indent)
14209 "Expand/contract the architecture under the cursor."
14210 (cond
14211 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14212 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14213 (ent-alist (aget vhdl-entity-alist key t))
14214 (conf-alist (aget vhdl-config-alist key t))
14215 (hier-alist (vhdl-get-hierarchy
14216 ent-alist conf-alist (car token) (cdr token) nil nil
14217 0 (1- indent)))
14218 (ent-entry (aget ent-alist (car token) t))
14219 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14220 (subpack-alist (nth 4 arch-entry))
14221 entry)
14222 (if (not (or hier-alist subpack-alist))
14223 (speedbar-change-expand-button-char ??)
14224 (speedbar-change-expand-button-char ?-)
14225 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14226 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14227 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14228 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14229 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14230 (speedbar-with-writable
14231 (save-excursion
14232 (end-of-line) (forward-char 1)
14233 ;; insert instance hierarchy
14234 (when hier-alist
14235 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14236 (1+ indent)))
14237 (while hier-alist
14238 (setq entry (car hier-alist))
14239 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14240 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14241 (vhdl-speedbar-make-inst-line
14242 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14243 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14244 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14245 (setq hier-alist (cdr hier-alist)))
14246 ;; insert required packages
14247 (vhdl-speedbar-insert-subpackages
14248 subpack-alist (1+ indent) (1- indent))))
14249 (when (memq 'display vhdl-speedbar-save-cache)
14250 (add-to-list 'vhdl-updated-project-list key))
14251 (vhdl-speedbar-update-current-unit t t))))
14252 ((string-match "-" text) ; contract architecture
14253 (speedbar-change-expand-button-char ?+)
14254 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14255 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14256 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14257 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14258 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14259 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14260 (speedbar-delete-subblock indent)
14261 (when (memq 'display vhdl-speedbar-save-cache)
14262 (add-to-list 'vhdl-updated-project-list key))))
14263 (t (error "Nothing to display")))
14264 (when (equal (selected-frame) speedbar-frame)
14265 (speedbar-center-buffer-smartly)))
14266
14267(defun vhdl-speedbar-expand-config (text token indent)
14268 "Expand/contract the configuration under the cursor."
14269 (cond
14270 ((string-match "+" text) ; expand configuration
14271 (let* ((key (vhdl-speedbar-line-key indent))
14272 (conf-alist (aget vhdl-config-alist key t))
14273 (conf-entry (aget conf-alist token))
14274 (ent-alist (aget vhdl-entity-alist key t))
14275 (hier-alist (vhdl-get-hierarchy
14276 ent-alist conf-alist (nth 3 conf-entry)
14277 (nth 4 conf-entry) token (nth 5 conf-entry)
14278 0 indent t))
14279 (subpack-alist (nth 6 conf-entry))
14280 entry)
14281 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14282 (speedbar-change-expand-button-char ??)
14283 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14284 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14285 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14286 (aput 'unit-alist token nil)
14287 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14288 (speedbar-with-writable
14289 (save-excursion
14290 (end-of-line) (forward-char 1)
14291 ;; insert instance hierarchy
14292 (when hier-alist
3dcb36b7 14293 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14294 (while hier-alist
3dcb36b7
JB
14295 (setq entry (car hier-alist))
14296 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14297 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14298 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14299 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14300 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14301 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14302 (setq hier-alist (cdr hier-alist)))
14303 ;; insert required packages
14304 (vhdl-speedbar-insert-subpackages
14305 subpack-alist (1+ indent) indent)))
14306 (when (memq 'display vhdl-speedbar-save-cache)
14307 (add-to-list 'vhdl-updated-project-list key))
14308 (vhdl-speedbar-update-current-unit t t))))
14309 ((string-match "-" text) ; contract configuration
5eabfe72 14310 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14311 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14312 (let* ((key (vhdl-speedbar-line-key indent))
14313 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14314 (adelete 'unit-alist token)
14315 (if unit-alist
14316 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14317 (adelete 'vhdl-speedbar-shown-unit-alist key))
14318 (speedbar-delete-subblock indent)
14319 (when (memq 'display vhdl-speedbar-save-cache)
14320 (add-to-list 'vhdl-updated-project-list key))))
14321 (t (error "Nothing to display")))
14322 (when (equal (selected-frame) speedbar-frame)
14323 (speedbar-center-buffer-smartly)))
14324
14325(defun vhdl-speedbar-expand-package (text token indent)
14326 "Expand/contract the package under the cursor."
14327 (cond
14328 ((string-match "+" text) ; expand package
14329 (let* ((key (vhdl-speedbar-line-key indent))
14330 (pack-alist (aget vhdl-package-alist key t))
14331 (pack-entry (aget pack-alist token t))
14332 (comp-alist (nth 3 pack-entry))
14333 (func-alist (nth 4 pack-entry))
14334 (func-body-alist (nth 8 pack-entry))
14335 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14336 comp-entry func-entry func-body-entry)
14337 (if (not (or comp-alist func-alist subpack-alist))
14338 (speedbar-change-expand-button-char ??)
14339 (speedbar-change-expand-button-char ?-)
14340 ;; add package to `vhdl-speedbar-shown-unit-alist'
14341 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14342 (aput 'unit-alist token nil)
14343 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14344 (speedbar-with-writable
14345 (save-excursion
14346 (end-of-line) (forward-char 1)
14347 ;; insert components
14348 (when comp-alist
14349 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14350 (while comp-alist
14351 (setq comp-entry (car comp-alist))
14352 (speedbar-make-tag-line
14353 nil nil nil
14354 (cons token (nth 0 comp-entry))
14355 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14356 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14357 'vhdl-speedbar-entity-face (1+ indent))
14358 (setq comp-alist (cdr comp-alist)))
14359 ;; insert subprograms
14360 (when func-alist
14361 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14362 (while func-alist
14363 (setq func-entry (car func-alist)
14364 func-body-entry (aget func-body-alist (car func-entry) t))
14365 (when (nth 2 func-entry)
14366 (vhdl-speedbar-make-subprogram-line
14367 (nth 1 func-entry)
14368 (cons (nth 2 func-entry) (nth 3 func-entry))
14369 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14370 (1+ indent)))
14371 (setq func-alist (cdr func-alist)))
14372 ;; insert required packages
14373 (vhdl-speedbar-insert-subpackages
14374 subpack-alist (1+ indent) indent)))
14375 (when (memq 'display vhdl-speedbar-save-cache)
14376 (add-to-list 'vhdl-updated-project-list key))
14377 (vhdl-speedbar-update-current-unit t t))))
14378 ((string-match "-" text) ; contract package
14379 (speedbar-change-expand-button-char ?+)
14380 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14381 (let* ((key (vhdl-speedbar-line-key indent))
14382 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14383 (adelete 'unit-alist token)
14384 (if unit-alist
14385 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14386 (adelete 'vhdl-speedbar-shown-unit-alist key))
14387 (speedbar-delete-subblock indent)
14388 (when (memq 'display vhdl-speedbar-save-cache)
14389 (add-to-list 'vhdl-updated-project-list key))))
14390 (t (error "Nothing to display")))
14391 (when (equal (selected-frame) speedbar-frame)
14392 (speedbar-center-buffer-smartly)))
14393
14394(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14395 "Insert required packages."
14396 (let* ((pack-alist (aget vhdl-package-alist
14397 (vhdl-speedbar-line-key dir-indent) t))
14398 pack-key lib-name pack-entry)
14399 (when subpack-alist
14400 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14401 (while subpack-alist
14402 (setq pack-key (cdar subpack-alist)
14403 lib-name (caar subpack-alist))
14404 (setq pack-entry (aget pack-alist pack-key t))
14405 (vhdl-speedbar-make-subpack-line
14406 (or (nth 0 pack-entry) pack-key) lib-name
14407 (cons (nth 1 pack-entry) (nth 2 pack-entry)) indent)
14408 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14409
14410;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14411;; Display help functions
14412
3dcb36b7
JB
14413(defvar vhdl-speedbar-update-current-unit t
14414 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14415
14416(defun vhdl-speedbar-update-current-project ()
14417 "Highlight project that is currently active."
14418 (when (and vhdl-speedbar-show-projects
14419 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14420 (and (boundp 'speedbar-frame)
14421 (frame-live-p speedbar-frame)))
14422 (let ((last-frame (selected-frame))
14423 (project-alist vhdl-project-alist)
14424 pos)
14425 (select-frame speedbar-frame)
14426 (speedbar-with-writable
14427 (save-excursion
14428 (while project-alist
14429 (goto-char (point-min))
14430 (when (re-search-forward
14431 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14432 (put-text-property (match-beginning 1) (match-end 1) 'face
14433 (if (equal (caar project-alist) vhdl-project)
14434 'speedbar-selected-face
14435 'speedbar-directory-face))
14436 (when (equal (caar project-alist) vhdl-project)
14437 (setq pos (1- (match-beginning 1)))))
14438 (setq project-alist (cdr project-alist))))
14439 (when pos (goto-char pos)))
14440 (select-frame last-frame)
14441 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14442 t)
14443
14444(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14445 "Highlight all design units that are contained in the current file.
14446NO-POSITION non-nil means do not re-position cursor."
14447 (let ((last-frame (selected-frame))
3dcb36b7
JB
14448 (project-list vhdl-speedbar-shown-project-list)
14449 file-alist pos file-name)
5eabfe72 14450 ;; get current file name
3dcb36b7
JB
14451 (if (fboundp 'speedbar-select-attached-frame)
14452 (speedbar-select-attached-frame)
14453 (select-frame speedbar-attached-frame))
5eabfe72 14454 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14455 (when (and vhdl-speedbar-update-current-unit
14456 (or always (not (equal file-name speedbar-last-selected-file))))
14457 (if vhdl-speedbar-show-projects
14458 (while project-list
14459 (setq file-alist (append file-alist (aget vhdl-file-alist
14460 (car project-list) t)))
14461 (setq project-list (cdr project-list)))
14462 (setq file-alist (aget vhdl-file-alist
14463 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14464 (select-frame speedbar-frame)
14465 (set-buffer speedbar-buffer)
14466 (speedbar-with-writable
3dcb36b7 14467 (vhdl-prepare-search-1
5eabfe72
KH
14468 (save-excursion
14469 ;; unhighlight last units
3dcb36b7 14470 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14471 (vhdl-speedbar-update-units
3dcb36b7 14472 "\\[.\\] " (nth 0 file-entry)
5eabfe72
KH
14473 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14474 (vhdl-speedbar-update-units
3dcb36b7 14475 "{.} " (nth 1 file-entry)
5eabfe72
KH
14476 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14477 (vhdl-speedbar-update-units
3dcb36b7 14478 "\\[.\\] " (nth 3 file-entry)
5eabfe72
KH
14479 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14480 (vhdl-speedbar-update-units
3dcb36b7 14481 "[]>] " (nth 4 file-entry)
5eabfe72
KH
14482 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14483 (vhdl-speedbar-update-units
3dcb36b7
JB
14484 "\\[.\\].+(" '("body")
14485 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14486 (vhdl-speedbar-update-units
14487 "> " (nth 6 file-entry)
5eabfe72
KH
14488 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14489 ;; highlight current units
3dcb36b7
JB
14490 (let* ((file-entry (aget file-alist file-name t)))
14491 (setq
14492 pos (vhdl-speedbar-update-units
14493 "\\[.\\] " (nth 0 file-entry)
14494 file-name 'vhdl-speedbar-entity-selected-face pos)
14495 pos (vhdl-speedbar-update-units
14496 "{.} " (nth 1 file-entry)
14497 file-name 'vhdl-speedbar-architecture-selected-face pos)
14498 pos (vhdl-speedbar-update-units
14499 "\\[.\\] " (nth 3 file-entry)
14500 file-name 'vhdl-speedbar-configuration-selected-face pos)
14501 pos (vhdl-speedbar-update-units
14502 "[]>] " (nth 4 file-entry)
14503 file-name 'vhdl-speedbar-package-selected-face pos)
14504 pos (vhdl-speedbar-update-units
14505 "\\[.\\].+(" '("body")
14506 file-name 'vhdl-speedbar-package-selected-face pos)
14507 pos (vhdl-speedbar-update-units
14508 "> " (nth 6 file-entry)
14509 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14510 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14511 (when (and pos (not no-position))
14512 (goto-char pos)
14513 (speedbar-center-buffer-smartly)
5eabfe72
KH
14514 (speedbar-position-cursor-on-line))
14515 (setq speedbar-last-selected-file file-name))
14516 (select-frame last-frame)
14517 t))
14518
3dcb36b7
JB
14519(defun vhdl-speedbar-update-units (text unit-list file-name face
14520 &optional pos)
5eabfe72 14521 "Help function to highlight design units."
3dcb36b7
JB
14522 (while unit-list
14523 (goto-char (point-min))
14524 (while (re-search-forward
14525 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14526 (when (equal file-name (car (get-text-property
14527 (match-beginning 1) 'speedbar-token)))
14528 (setq pos (or pos (point-marker)))
14529 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14530 (setq unit-list (cdr unit-list)))
14531 pos)
5eabfe72
KH
14532
14533(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14534 ent-name ent-file-marker
14535 arch-name arch-file-marker
14536 conf-name conf-file-marker
14537 lib-name depth offset delimiter)
5eabfe72 14538 "Insert instantiation entry."
3dcb36b7
JB
14539 (let ((start (point))
14540 visible-start)
5eabfe72
KH
14541 (insert (int-to-string depth) ":")
14542 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14543 (setq visible-start (point))
14544 (insert-char ? (* depth speedbar-indentation-width))
14545 (while (> offset 0)
14546 (insert "|")
14547 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14548 (setq offset (1- offset)))
14549 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14550 (setq start (point))
3dcb36b7
JB
14551 (insert ">")
14552 (speedbar-make-button start (point) nil nil nil)
14553 (setq visible-start (point))
14554 (insert " ")
5eabfe72 14555 (setq start (point))
3dcb36b7
JB
14556 (if (not inst-name)
14557 (insert "(top)")
14558 (insert inst-name)
14559 (speedbar-make-button
14560 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14561 'vhdl-speedbar-find-file inst-file-marker))
14562 (insert delimiter)
14563 (when ent-name
5eabfe72 14564 (setq start (point))
3dcb36b7 14565 (insert ent-name)
5eabfe72 14566 (speedbar-make-button
3dcb36b7
JB
14567 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14568 'vhdl-speedbar-find-file ent-file-marker)
14569 (when arch-name
14570 (insert " (")
14571 (setq start (point))
14572 (insert arch-name)
14573 (speedbar-make-button
14574 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14575 'vhdl-speedbar-find-file arch-file-marker)
14576 (insert ")"))
14577 (when conf-name
14578 (insert " (")
14579 (setq start (point))
14580 (insert conf-name)
14581 (speedbar-make-button
14582 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14583 'vhdl-speedbar-find-file conf-file-marker)
14584 (insert ")")))
14585 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14586 (setq start (point))
3dcb36b7
JB
14587 (insert " (" lib-name ")")
14588 (put-text-property (+ 2 start) (1- (point)) 'face
14589 'vhdl-speedbar-library-face))
5eabfe72 14590 (insert-char ?\n 1)
3dcb36b7 14591 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14592
3dcb36b7
JB
14593(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14594 body-file-marker depth)
5eabfe72 14595 "Insert package entry."
3dcb36b7
JB
14596 (let ((start (point))
14597 visible-start)
5eabfe72
KH
14598 (insert (int-to-string depth) ":")
14599 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14600 (setq visible-start (point))
14601 (insert-char ? (* depth speedbar-indentation-width))
14602 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14603 (setq start (point))
3dcb36b7
JB
14604 (insert "[+]")
14605 (speedbar-make-button
14606 start (point) 'speedbar-button-face 'speedbar-highlight-face
14607 'vhdl-speedbar-expand-package pack-key)
14608 (setq visible-start (point))
14609 (insert-char ? 1 nil)
5eabfe72
KH
14610 (setq start (point))
14611 (insert pack-name)
14612 (speedbar-make-button
14613 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14614 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14615 (unless (car pack-file-marker)
14616 (insert "!"))
5eabfe72 14617 (when (car body-file-marker)
5eabfe72 14618 (insert " (")
5eabfe72
KH
14619 (setq start (point))
14620 (insert "body")
14621 (speedbar-make-button
14622 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14623 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14624 (insert ")"))
5eabfe72 14625 (insert-char ?\n 1)
3dcb36b7 14626 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14627
3dcb36b7
JB
14628(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14629 depth)
14630 "Insert used package entry."
14631 (let ((start (point))
14632 visible-start)
14633 (insert (int-to-string depth) ":")
14634 (put-text-property start (point) 'invisible t)
14635 (setq visible-start (point))
14636 (insert-char ? (* depth speedbar-indentation-width))
14637 (put-text-property visible-start (point) 'invisible nil)
14638 (setq start (point))
14639 (insert ">")
14640 (speedbar-make-button start (point) nil nil nil)
14641 (setq visible-start (point))
14642 (insert " ")
14643 (setq start (point))
14644 (insert pack-name)
14645 (speedbar-make-button
14646 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14647 'vhdl-speedbar-find-file pack-file-marker)
14648 (setq start (point))
14649 (insert " (" lib-name ")")
14650 (put-text-property (+ 2 start) (1- (point)) 'face
14651 'vhdl-speedbar-library-face)
14652 (insert-char ?\n 1)
14653 (put-text-property visible-start (point) 'invisible nil)))
14654
14655(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14656 func-body-file-marker
14657 depth)
14658 "Insert subprogram entry."
14659 (let ((start (point))
14660 visible-start)
5eabfe72
KH
14661 (insert (int-to-string depth) ":")
14662 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14663 (setq visible-start (point))
14664 (insert-char ? (* depth speedbar-indentation-width))
14665 (put-text-property visible-start (point) 'invisible nil)
14666 (setq start (point))
14667 (insert ">")
14668 (speedbar-make-button start (point) nil nil nil)
14669 (setq visible-start (point))
14670 (insert " ")
5eabfe72 14671 (setq start (point))
3dcb36b7
JB
14672 (insert func-name)
14673 (speedbar-make-button
14674 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14675 'vhdl-speedbar-find-file func-file-marker)
14676 (when (car func-body-file-marker)
14677 (insert " (")
14678 (setq start (point))
14679 (insert "body")
14680 (speedbar-make-button
14681 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14682 'vhdl-speedbar-find-file func-body-file-marker)
14683 (insert ")"))
14684 (insert-char ?\n 1)
14685 (put-text-property visible-start (point) 'invisible nil)))
14686
14687(defun vhdl-speedbar-make-title-line (text &optional depth)
14688 "Insert design unit title entry."
14689 (let ((start (point))
14690 visible-start)
14691 (when depth
14692 (insert (int-to-string depth) ":")
14693 (put-text-property start (point) 'invisible t))
14694 (setq visible-start (point))
14695 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14696 (setq start (point))
14697 (insert text)
14698 (speedbar-make-button start (point) nil nil nil nil)
14699 (insert-char ?\n 1)
3dcb36b7 14700 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14701
14702(defun vhdl-speedbar-insert-dirs (files level)
14703 "Insert subdirectories."
14704 (let ((dirs (car files)))
14705 (while dirs
14706 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14707 (car dirs) 'speedbar-dir-follow nil
14708 'speedbar-directory-face level)
14709 (setq dirs (cdr dirs)))))
14710
14711(defun vhdl-speedbar-dired (text token indent)
14712 "Speedbar click handler for directory expand button in hierarchy mode."
14713 (cond ((string-match "+" text) ; we have to expand this dir
14714 (setq speedbar-shown-directories
14715 (cons (expand-file-name
14716 (concat (speedbar-line-path indent) token "/"))
14717 speedbar-shown-directories))
14718 (speedbar-change-expand-button-char ?-)
14719 (speedbar-reset-scanners)
14720 (speedbar-with-writable
14721 (save-excursion
14722 (end-of-line) (forward-char 1)
14723 (vhdl-speedbar-insert-dirs
14724 (speedbar-file-lists
14725 (concat (speedbar-line-path indent) token "/"))
14726 (1+ indent))
14727 (speedbar-reset-scanners)
14728 (vhdl-speedbar-insert-dir-hierarchy
14729 (abbreviate-file-name
14730 (concat (speedbar-line-path indent) token "/"))
14731 (1+ indent) speedbar-power-click)))
3dcb36b7 14732 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
14733 ((string-match "-" text) ; we have to contract this node
14734 (speedbar-reset-scanners)
14735 (let ((oldl speedbar-shown-directories)
14736 (newl nil)
14737 (td (expand-file-name
14738 (concat (speedbar-line-path indent) token))))
14739 (while oldl
14740 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14741 (setq newl (cons (car oldl) newl)))
14742 (setq oldl (cdr oldl)))
14743 (setq speedbar-shown-directories (nreverse newl)))
14744 (speedbar-change-expand-button-char ?+)
14745 (speedbar-delete-subblock indent))
3dcb36b7
JB
14746 (t (error "Nothing to display")))
14747 (when (equal (selected-frame) speedbar-frame)
14748 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14749
14750(defun vhdl-speedbar-item-info ()
14751 "Derive and display information about this line item."
14752 (save-excursion
14753 (beginning-of-line)
14754 ;; skip invisible number info
3dcb36b7 14755 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 14756 (cond
3dcb36b7
JB
14757 ;; project/directory entry
14758 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14759 (if vhdl-speedbar-show-projects
14760 (message "Project \"%s\"" (match-string-no-properties 1))
14761 (speedbar-files-item-info)))
5eabfe72 14762 ;; design unit entry
3dcb36b7
JB
14763 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14764 (goto-char (match-end 1))
5eabfe72
KH
14765 (let ((face (get-text-property (point) 'face)))
14766 (message
14767 "%s \"%s\" in \"%s\""
14768 ;; design unit kind
14769 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14770 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 14771 (if (equal (match-string 2) ">") "Component" "Entity"))
5eabfe72
KH
14772 ((or (eq face 'vhdl-speedbar-architecture-face)
14773 (eq face 'vhdl-speedbar-architecture-selected-face))
14774 "Architecture")
14775 ((or (eq face 'vhdl-speedbar-configuration-face)
14776 (eq face 'vhdl-speedbar-configuration-selected-face))
14777 "Configuration")
14778 ((or (eq face 'vhdl-speedbar-package-face)
14779 (eq face 'vhdl-speedbar-package-selected-face))
14780 "Package")
14781 ((or (eq face 'vhdl-speedbar-instantiation-face)
14782 (eq face 'vhdl-speedbar-instantiation-selected-face))
14783 "Instantiation")
3dcb36b7
JB
14784 ((eq face 'vhdl-speedbar-subprogram-face)
14785 "Subprogram")
5eabfe72
KH
14786 (t ""))
14787 ;; design unit name
14788 (buffer-substring-no-properties
3dcb36b7
JB
14789 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14790 (match-end 1))
5eabfe72 14791 ;; file name
3dcb36b7
JB
14792 (file-relative-name
14793 (or (car (get-text-property (point) 'speedbar-token))
14794 "?")
14795 (vhdl-default-directory)))))
14796 (t (message "")))))
14797
14798(defun vhdl-speedbar-line-text ()
14799 "Calls `speedbar-line-text' and removes text properties."
14800 (let ((string (speedbar-line-text)))
14801 (set-text-properties 0 (length string) nil string)
14802 string))
5eabfe72
KH
14803
14804;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14805;; Help functions
d2ddb974 14806
3dcb36b7
JB
14807(defun vhdl-speedbar-line-key (&optional indent)
14808 "Get currently displayed directory of project name."
14809 (if vhdl-speedbar-show-projects
14810 (vhdl-speedbar-line-project)
14811 (abbreviate-file-name
14812 (file-name-as-directory (speedbar-line-path indent)))))
14813
14814(defun vhdl-speedbar-line-project (&optional indent)
14815 "Get currently displayed project name."
14816 (and vhdl-speedbar-show-projects
14817 (save-excursion
14818 (end-of-line)
14819 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
14820 (match-string-no-properties 1))))
14821
14822(defun vhdl-add-modified-file ()
14823 "Add file to `vhdl-modified-file-list'."
14824 (when vhdl-file-alist
14825 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
14826 nil)
5eabfe72
KH
14827
14828(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
14829 "Resolve path wildcards in PATH-LIST."
14830 (let (path-list-1 path-list-2 path-beg path-end dir)
14831 ;; eliminate non-existent directories
5eabfe72
KH
14832 (while path-list
14833 (setq dir (car path-list))
3dcb36b7
JB
14834 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
14835 (if (file-directory-p (match-string 2 dir))
14836 (setq path-list-1 (cons dir path-list-1))
14837 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 14838 (setq path-list (cdr path-list)))
3dcb36b7 14839 ;; resolve path wildcards
5eabfe72
KH
14840 (while path-list-1
14841 (setq dir (car path-list-1))
3dcb36b7 14842 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
14843 (progn
14844 (setq path-beg (match-string 1 dir)
14845 path-end (match-string 5 dir))
3dcb36b7 14846 (setq path-list-1
5eabfe72
KH
14847 (append
14848 (mapcar
14849 (function
14850 (lambda (var) (concat path-beg var path-end)))
14851 (let ((all-list (vhdl-directory-files
14852 (match-string 2 dir) t
14853 (concat "\\<" (wildcard-to-regexp
14854 (match-string 4 dir)))))
14855 dir-list)
14856 (while all-list
14857 (when (file-directory-p (car all-list))
14858 (setq dir-list (cons (car all-list) dir-list)))
14859 (setq all-list (cdr all-list)))
14860 dir-list))
3dcb36b7
JB
14861 (cdr path-list-1))))
14862 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 14863 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
14864 (setq path-list-2 (cons dir path-list-2)))
14865 (setq path-list-1 (cdr path-list-1))))
14866 (nreverse path-list-2)))
5eabfe72
KH
14867
14868(defun vhdl-speedbar-goto-this-unit (directory unit)
14869 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
14870 (let ((dest (point)))
3dcb36b7 14871 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
14872 (progn (goto-char (point-min)) t)
14873 (speedbar-goto-this-file directory))
14874 (re-search-forward (concat "[]}] " unit "\\>") nil t))
14875 (progn (speedbar-position-cursor-on-line)
14876 t)
14877 (goto-char dest)
14878 nil)))
14879
14880(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
14881 "When user clicks on TEXT, load file with name and position in TOKEN.
14882Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
14883is already shown in a buffer."
5eabfe72 14884 (if (not (car token))
3dcb36b7
JB
14885 (error "ERROR: File cannot be found")
14886 (let ((buffer (get-file-buffer (car token))))
14887 (speedbar-find-file-in-frame (car token))
14888 (when (or vhdl-speedbar-jump-to-unit buffer)
14889 (goto-line (cdr token))
14890 (recenter))
14891 (vhdl-speedbar-update-current-unit t t)
14892 (speedbar-set-timer speedbar-update-speed)
14893 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
14894
14895(defun vhdl-speedbar-port-copy ()
3dcb36b7 14896 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 14897 (interactive)
3dcb36b7
JB
14898 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
14899 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
14900 (error "ERROR: No entity/component or subprogram under cursor")
14901 (beginning-of-line)
14902 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
14903 (condition-case info
14904 (let ((token (get-text-property
14905 (match-beginning 3) 'speedbar-token)))
14906 (vhdl-visit-file (car token) t
14907 (progn (goto-line (cdr token))
14908 (end-of-line)
14909 (if is-entity
14910 (vhdl-port-copy)
14911 (vhdl-subprog-copy)))))
14912 (error (error "ERROR: %s not scanned successfully\n (%s)"
14913 (if is-entity "Port" "Interface") (cadr info))))
14914 (error "ERROR: No entity/component or subprogram on current line")))))
14915
14916(defun vhdl-speedbar-place-component ()
14917 "Place the entity/component under the cursor as component."
14918 (interactive)
14919 (if (not (vhdl-speedbar-check-unit 'entity))
14920 (error "ERROR: No entity/component under cursor.")
14921 (vhdl-speedbar-port-copy)
14922 (if (fboundp 'speedbar-select-attached-frame)
14923 (speedbar-select-attached-frame)
14924 (select-frame speedbar-attached-frame))
14925 (vhdl-compose-place-component)
14926 (select-frame speedbar-frame)))
14927
14928(defun vhdl-speedbar-make-design ()
14929 "Make (compile) design unit or directory/project under the cursor."
14930 (interactive)
14931 (if (not (save-excursion (beginning-of-line)
14932 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
14933 (error "ERROR: No primary design unit or directory/project under cursor")
14934 (let ((is-unit (match-string 2))
14935 (unit-name (vhdl-speedbar-line-text))
14936 (vhdl-project (vhdl-speedbar-line-project))
14937 (directory (file-name-as-directory
14938 (or (speedbar-line-file) (speedbar-line-path)))))
14939 (if (fboundp 'speedbar-select-attached-frame)
14940 (speedbar-select-attached-frame)
14941 (select-frame speedbar-attached-frame))
14942 (let ((default-directory directory))
14943 (vhdl-make (and is-unit unit-name))))))
14944
14945(defun vhdl-speedbar-generate-makefile ()
14946 "Generate Makefile for directory/project under the cursor."
14947 (interactive)
14948 (let ((vhdl-project (vhdl-speedbar-line-project))
14949 (default-directory (file-name-as-directory
14950 (or (speedbar-line-file) (speedbar-line-path)))))
14951 (vhdl-generate-makefile)))
14952
14953(defun vhdl-speedbar-check-unit (design-unit)
14954 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
14955expansion function)."
14956 (save-excursion
14957 (speedbar-position-cursor-on-line)
14958 (cond ((eq design-unit 'entity)
14959 (memq (get-text-property (match-end 0) 'face)
14960 '(vhdl-speedbar-entity-face
14961 vhdl-speedbar-entity-selected-face)))
14962 ((eq design-unit 'subprogram)
14963 (eq (get-text-property (match-end 0) 'face)
14964 'vhdl-speedbar-subprogram-face))
14965 (t nil))))
14966
14967(defun vhdl-speedbar-set-depth (depth)
14968 "Set hierarchy display depth to DEPTH and refresh speedbar."
14969 (setq vhdl-speedbar-hierarchy-depth depth)
14970 (speedbar-refresh))
5eabfe72
KH
14971
14972;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14973;; Fontification
14974
14975(defface vhdl-speedbar-entity-face
14976 '((((class color) (background light)) (:foreground "ForestGreen"))
14977 (((class color) (background dark)) (:foreground "PaleGreen")))
14978 "Face used for displaying entity names."
14979 :group 'speedbar-faces)
14980
14981(defface vhdl-speedbar-architecture-face
ea81d57e
DN
14982 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
14983 (((class color) (background light)) (:foreground "Blue"))
5eabfe72
KH
14984 (((class color) (background dark)) (:foreground "LightSkyBlue")))
14985 "Face used for displaying architecture names."
14986 :group 'speedbar-faces)
d2ddb974 14987
5eabfe72
KH
14988(defface vhdl-speedbar-configuration-face
14989 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
14990 (((class color) (background dark)) (:foreground "Salmon")))
14991 "Face used for displaying configuration names."
14992 :group 'speedbar-faces)
14993
14994(defface vhdl-speedbar-package-face
14995 '((((class color) (background light)) (:foreground "Grey50"))
14996 (((class color) (background dark)) (:foreground "Grey80")))
14997 "Face used for displaying package names."
14998 :group 'speedbar-faces)
14999
3dcb36b7
JB
15000(defface vhdl-speedbar-library-face
15001 '((((class color) (background light)) (:foreground "Purple"))
15002 (((class color) (background dark)) (:foreground "Orchid1")))
15003 "Face used for displaying library names."
15004 :group 'speedbar-faces)
15005
5eabfe72
KH
15006(defface vhdl-speedbar-instantiation-face
15007 '((((class color) (background light)) (:foreground "Brown"))
ea81d57e 15008 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
5eabfe72
KH
15009 (((class color) (background dark)) (:foreground "Yellow")))
15010 "Face used for displaying instantiation names."
15011 :group 'speedbar-faces)
15012
3dcb36b7
JB
15013(defface vhdl-speedbar-subprogram-face
15014 '((((class color) (background light)) (:foreground "Orchid4"))
15015 (((class color) (background dark)) (:foreground "BurlyWood2")))
15016 "Face used for displaying subprogram names."
15017 :group 'speedbar-faces)
15018
5eabfe72
KH
15019(defface vhdl-speedbar-entity-selected-face
15020 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15021 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15022 "Face used for displaying entity names."
15023 :group 'speedbar-faces)
15024
15025(defface vhdl-speedbar-architecture-selected-face
ea81d57e
DN
15026 '((((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15027 (((min-colors 88) (class color) (background light)) (:foreground "Blue1" :underline t))
15028 (((class color) (background light)) (:foreground "Blue" :underline t))
5eabfe72
KH
15029 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15030 "Face used for displaying architecture names."
15031 :group 'speedbar-faces)
15032
15033(defface vhdl-speedbar-configuration-selected-face
15034 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15035 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15036 "Face used for displaying configuration names."
15037 :group 'speedbar-faces)
15038
15039(defface vhdl-speedbar-package-selected-face
15040 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15041 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15042 "Face used for displaying package names."
15043 :group 'speedbar-faces)
15044
15045(defface vhdl-speedbar-instantiation-selected-face
15046 '((((class color) (background light)) (:foreground "Brown" :underline t))
ea81d57e 15047 (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1" :underline t))
5eabfe72
KH
15048 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15049 "Face used for displaying instantiation names."
15050 :group 'speedbar-faces)
15051
3dcb36b7
JB
15052;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15053;; Initialization
15054
15055;; add speedbar
15056(when (fboundp 'speedbar)
15057 (condition-case ()
15058 (when (and vhdl-speedbar-auto-open
15059 (not (and (boundp 'speedbar-frame)
15060 (frame-live-p speedbar-frame))))
15061 (speedbar-frame-mode 1)
15062 (if (fboundp 'speedbar-select-attached-frame)
15063 (speedbar-select-attached-frame)
15064 (select-frame speedbar-attached-frame)))
15065 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15066
15067;; initialize speedbar
15068(if (not (boundp 'speedbar-frame))
15069 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15070 (vhdl-speedbar-initialize)
15071 (when speedbar-frame (vhdl-speedbar-refresh)))
15072
15073
15074;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15075;;; Structural composition
15076;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15077
15078(defun vhdl-get-components-package-name ()
15079 "Return the name of the components package."
15080 (let ((project (vhdl-project-p)))
15081 (if project
15082 (vhdl-replace-string (car vhdl-components-package-name)
15083 (subst-char-in-string ? ?_ project))
15084 (cdr vhdl-components-package-name))))
15085
15086(defun vhdl-compose-new-component ()
15087 "Create entity and architecture for new component."
15088 (interactive)
15089 (let* ((case-fold-search t)
15090 (ent-name (read-from-minibuffer "entity name: "
15091 nil vhdl-minibuffer-local-map))
15092 (arch-name
15093 (if (equal (cdr vhdl-compose-architecture-name) "")
15094 (read-from-minibuffer "architecture name: "
15095 nil vhdl-minibuffer-local-map)
15096 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15097 ent-file-name arch-file-name ent-buffer arch-buffer project)
15098 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15099 ;; open entity file
15100 (unless (eq vhdl-compose-create-files 'none)
15101 (setq ent-file-name
15102 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15103 "." (file-name-extension (buffer-file-name))))
15104 (when (and (file-exists-p ent-file-name)
15105 (not (y-or-n-p (concat "File \"" ent-file-name
15106 "\" exists; overwrite? "))))
15107 (error "ERROR: Creating component...aborted"))
15108 (find-file ent-file-name)
15109 (erase-buffer)
15110 (set-buffer-modified-p nil))
15111 ;; insert header
15112 (if vhdl-compose-include-header
15113 (progn (vhdl-template-header)
15114 (goto-char (point-max)))
15115 (vhdl-comment-display-line) (insert "\n\n"))
15116 ;; insert library clause
15117 (vhdl-template-package-std-logic-1164)
15118 (when vhdl-use-components-package
15119 (insert "\n")
15120 (vhdl-template-standard-package (vhdl-work-library)
15121 (vhdl-get-components-package-name)))
15122 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15123 ;; insert entity declaration
15124 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15125 (vhdl-insert-keyword " IS\n")
15126 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15127 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15128 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15129 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15130 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15131 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15132 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15133 (vhdl-insert-keyword "END ")
15134 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15135 (insert ent-name ";\n\n")
15136 (vhdl-comment-display-line) (insert "\n")
15137 ;; open architecture file
15138 (if (not (eq vhdl-compose-create-files 'separate))
15139 (insert "\n")
15140 (setq ent-buffer (current-buffer))
15141 (setq arch-file-name
15142 (concat (vhdl-replace-string vhdl-architecture-file-name
15143 (concat ent-name " " arch-name))
15144 "." (file-name-extension (buffer-file-name))))
15145 (when (and (file-exists-p arch-file-name)
15146 (not (y-or-n-p (concat "File \"" arch-file-name
15147 "\" exists; overwrite? "))))
15148 (error "ERROR: Creating component...aborted"))
15149 (find-file arch-file-name)
15150 (erase-buffer)
15151 (set-buffer-modified-p nil)
15152 ;; insert header
15153 (if vhdl-compose-include-header
15154 (progn (vhdl-template-header)
15155 (goto-char (point-max)))
15156 (vhdl-comment-display-line) (insert "\n\n")))
15157 ;; insert architecture body
15158 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15159 (vhdl-insert-keyword " OF ") (insert ent-name)
15160 (vhdl-insert-keyword " IS\n\n")
15161 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15162 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15163 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15164 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15165 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15166 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15167 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15168 (vhdl-insert-keyword "BEGIN")
15169 (when vhdl-self-insert-comments
15170 (insert " -- ")
15171 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15172 (insert arch-name))
15173 (insert "\n\n")
15174 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15175 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15176 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15177 (vhdl-insert-keyword "END ")
15178 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15179 (insert arch-name ";\n\n")
15180 ;; insert footer
15181 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15182 (vhdl-template-footer)
15183 (vhdl-comment-display-line) (insert "\n"))
15184 (goto-char (point-min))
15185 (setq arch-buffer (current-buffer))
15186 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15187 (set-buffer arch-buffer) (save-buffer)
15188 (message
15189 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15190 (and ent-file-name
15191 (format "\n File created: \"%s\"" ent-file-name))
15192 (and arch-file-name
15193 (format "\n File created: \"%s\"" arch-file-name))))))
15194
15195(defun vhdl-compose-place-component ()
15196 "Place new component by pasting current port as component declaration and
15197component instantiation."
15198 (interactive)
15199 (if (not vhdl-port-list)
15200 (error "ERROR: No port has been read")
15201 (save-excursion
15202 (vhdl-prepare-search-2
15203 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15204 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15205 (error "ERROR: No architecture found"))
15206 (let* ((ent-name (match-string 1))
15207 (ent-file-name
15208 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15209 "." (file-name-extension (buffer-file-name))))
15210 (orig-buffer (current-buffer)))
15211 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15212 ;; place component declaration
15213 (unless (or vhdl-use-components-package
15214 (vhdl-use-direct-instantiation)
15215 (save-excursion
15216 (re-search-forward
15217 (concat "^\\s-*component\\s-+"
15218 (car vhdl-port-list) "\\>") nil t)))
15219 (re-search-forward "^begin\\>" nil)
15220 (beginning-of-line)
15221 (skip-chars-backward " \t\n")
15222 (insert "\n\n") (indent-to vhdl-basic-offset)
15223 (vhdl-port-paste-component t))
15224 ;; place component instantiation
15225 (re-search-forward "^end\\>" nil)
15226 (beginning-of-line)
15227 (skip-chars-backward " \t\n")
15228 (insert "\n\n") (indent-to vhdl-basic-offset)
15229 (vhdl-port-paste-instance nil t t)
15230 ;; place use clause for used packages
15231 (when (nth 3 vhdl-port-list)
15232 ;; open entity file
15233 (when (file-exists-p ent-file-name)
15234 (find-file ent-file-name))
15235 (goto-char (point-min))
15236 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15237 (error "ERROR: Entity not found: \"%s\"" ent-name))
15238 (goto-char (match-beginning 0))
15239 (if (and (save-excursion
15240 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15241 (match-string 1))
15242 (progn (goto-char (match-end 0))
15243 (beginning-of-line 2))
15244 (insert "\n")
15245 (backward-char))
15246 (vhdl-port-paste-context-clause)
15247 (switch-to-buffer orig-buffer))
15248 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15249
15250(defun vhdl-compose-wire-components ()
15251 "Connect components."
15252 (interactive)
15253 (save-excursion
15254 (vhdl-prepare-search-2
15255 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15256 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15257 (error "ERROR: No architecture found"))
15258 (let* ((ent-name (match-string 1))
15259 (ent-file-name
15260 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15261 "." (file-name-extension (buffer-file-name))))
15262 (arch-decl-pos (point-marker))
15263 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15264 (arch-end-pos (re-search-forward "^end\\>" nil))
15265 (pack-name (vhdl-get-components-package-name))
15266 (pack-file-name
15267 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15268 "." (file-name-extension (buffer-file-name))))
15269 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15270 port-alist generic-alist inst-alist
15271 signal-name signal-entry signal-alist local-list written-list
15272 single-in-list multi-in-list single-out-list multi-out-list
15273 constant-name constant-entry constant-alist single-list multi-list
15274 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15275 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15276 signal-beg-pos signal-pos
15277 constant-temp-pos port-temp-pos signal-temp-pos)
15278 (message "Wiring components...")
15279 ;; process all instances
15280 (goto-char arch-stat-pos)
15281 (while (re-search-forward
15282 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15283 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15284 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15285 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15286 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15287 (setq inst-name (match-string-no-properties 1)
15288 comp-name (match-string-no-properties 4)
15289 comp-ent-name (match-string-no-properties 12)
15290 has-generic (or (match-string 7) (match-string 17)))
15291 ;; get port ...
15292 (if comp-name
15293 ;; ... from component declaration
15294 (vhdl-visit-file
15295 (when vhdl-use-components-package pack-file-name) t
15296 (save-excursion
15297 (goto-char (point-min))
15298 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15299 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15300 (vhdl-port-copy)))
15301 ;; ... from entity declaration (direct instantiation)
15302 (setq comp-ent-file-name
15303 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name)
15304 "." (file-name-extension (buffer-file-name))))
15305 (vhdl-visit-file
15306 comp-ent-file-name t
15307 (save-excursion
15308 (goto-char (point-min))
15309 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15310 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15311 (vhdl-port-copy))))
15312 (vhdl-port-flatten t)
15313 (setq generic-alist (nth 1 vhdl-port-list)
15314 port-alist (nth 2 vhdl-port-list))
15315 (setq constant-alist nil
15316 signal-alist nil)
15317 (when has-generic
15318 ;; process all constants in generic map
15319 (vhdl-forward-syntactic-ws)
15320 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15321 (setq constant-name (match-string-no-properties 3))
15322 (setq constant-entry
15323 (cons constant-name
15324 (if (match-string 1)
15325 (or (aget generic-alist (match-string 2) t)
15326 (error (format "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15327 (cdar generic-alist))))
15328 (setq constant-alist (cons constant-entry constant-alist))
15329 (setq constant-name (downcase constant-name))
15330 (if (or (member constant-name single-list)
15331 (member constant-name multi-list))
15332 (progn (setq single-list (delete constant-name single-list))
15333 (add-to-list 'multi-list constant-name))
15334 (add-to-list 'single-list constant-name))
15335 (unless (match-string 1)
15336 (setq generic-alist (cdr generic-alist)))
15337 (vhdl-forward-syntactic-ws))
15338 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15339 ;; process all signals in port map
15340 (vhdl-forward-syntactic-ws)
15341 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15342 (setq signal-name (match-string-no-properties 3))
15343 (setq signal-entry (cons signal-name
15344 (if (match-string 1)
15345 (or (aget port-alist (match-string 2) t)
15346 (error (format "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15347 (cdar port-alist))))
15348 (setq signal-alist (cons signal-entry signal-alist))
15349 (setq signal-name (downcase signal-name))
15350 (if (equal (upcase (nth 2 signal-entry)) "IN")
15351 ;; input signal
15352 (cond
15353 ((member signal-name local-list)
15354 nil)
15355 ((or (member signal-name single-out-list)
15356 (member signal-name multi-out-list))
15357 (setq single-out-list (delete signal-name single-out-list))
15358 (setq multi-out-list (delete signal-name multi-out-list))
15359 (add-to-list 'local-list signal-name))
15360 ((member signal-name single-in-list)
15361 (setq single-in-list (delete signal-name single-in-list))
15362 (add-to-list 'multi-in-list signal-name))
15363 ((not (member signal-name multi-in-list))
15364 (add-to-list 'single-in-list signal-name)))
15365 ;; output signal
15366 (cond
15367 ((member signal-name local-list)
15368 nil)
15369 ((or (member signal-name single-in-list)
15370 (member signal-name multi-in-list))
15371 (setq single-in-list (delete signal-name single-in-list))
15372 (setq multi-in-list (delete signal-name multi-in-list))
15373 (add-to-list 'local-list signal-name))
15374 ((member signal-name single-out-list)
15375 (setq single-out-list (delete signal-name single-out-list))
15376 (add-to-list 'multi-out-list signal-name))
15377 ((not (member signal-name multi-out-list))
15378 (add-to-list 'single-out-list signal-name))))
15379 (unless (match-string 1)
15380 (setq port-alist (cdr port-alist)))
15381 (vhdl-forward-syntactic-ws))
15382 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15383 (nreverse signal-alist)) inst-alist)))
15384 ;; prepare signal insertion
15385 (vhdl-goto-marker arch-decl-pos)
15386 (forward-line 1)
15387 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15388 (setq signal-pos (point-marker))
15389 (while (progn (vhdl-forward-syntactic-ws)
15390 (looking-at "signal\\>"))
15391 (beginning-of-line 2)
15392 (delete-region signal-pos (point)))
15393 (setq signal-beg-pos signal-pos)
15394 ;; open entity file
15395 (when (file-exists-p ent-file-name)
15396 (find-file ent-file-name))
15397 (goto-char (point-min))
15398 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15399 (error "ERROR: Entity not found: \"%s\"" ent-name))
15400 ;; prepare generic clause insertion
15401 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15402 (match-string 1))
15403 (goto-char (match-beginning 0))
15404 (indent-to vhdl-basic-offset)
15405 (insert "generic ();\n\n")
15406 (backward-char 4))
15407 (backward-char)
15408 (setq generic-pos (point-marker))
15409 (forward-sexp) (end-of-line)
15410 (delete-region generic-pos (point)) (delete-char 1)
15411 (insert "(\n")
15412 (when multi-list
15413 (insert "\n")
15414 (indent-to (* 2 vhdl-basic-offset))
15415 (insert "-- global generics\n"))
15416 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15417 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15418 ;; prepare port clause insertion
15419 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15420 (match-string 1))
15421 (goto-char (match-beginning 0))
15422 (indent-to vhdl-basic-offset)
15423 (insert "port ();\n\n")
15424 (backward-char 4))
15425 (backward-char)
15426 (setq port-in-pos (point-marker))
15427 (forward-sexp) (end-of-line)
15428 (delete-region port-in-pos (point)) (delete-char 1)
15429 (insert "(\n")
15430 (when (or multi-in-list multi-out-list)
15431 (insert "\n")
15432 (indent-to (* 2 vhdl-basic-offset))
15433 (insert "-- global ports\n"))
15434 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15435 port-out-pos (point-marker) port-inst-pos (point-marker)
15436 port-end-pos (point-marker))
15437 ;; insert generics, ports and signals
15438 (setq inst-alist (nreverse inst-alist))
15439 (while inst-alist
15440 (setq inst-name (nth 0 (car inst-alist))
15441 constant-alist (nth 1 (car inst-alist))
15442 signal-alist (nth 2 (car inst-alist))
15443 constant-temp-pos generic-inst-pos
15444 port-temp-pos port-inst-pos
15445 signal-temp-pos signal-pos)
15446 ;; generics
15447 (while constant-alist
15448 (setq constant-name (downcase (caar constant-alist))
15449 constant-entry (car constant-alist))
15450 (cond ((member constant-name written-list)
15451 nil)
15452 ((member constant-name multi-list)
15453 (vhdl-goto-marker generic-pos)
15454 (setq generic-end-pos
15455 (vhdl-max-marker
15456 generic-end-pos
15457 (vhdl-compose-insert-generic constant-entry)))
15458 (setq generic-pos (point-marker))
15459 (add-to-list 'written-list constant-name))
15460 (t
15461 (vhdl-goto-marker
15462 (vhdl-max-marker generic-inst-pos generic-pos))
15463 (setq generic-end-pos
15464 (vhdl-compose-insert-generic constant-entry))
15465 (setq generic-inst-pos (point-marker))
15466 (add-to-list 'written-list constant-name)))
15467 (setq constant-alist (cdr constant-alist)))
15468 (when (/= constant-temp-pos generic-inst-pos)
15469 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15470 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15471 (insert "-- generics for \"" inst-name "\"\n")
15472 (vhdl-goto-marker generic-inst-pos))
15473 ;; ports and signals
15474 (while signal-alist
15475 (setq signal-name (downcase (caar signal-alist))
15476 signal-entry (car signal-alist))
15477 (cond ((member signal-name written-list)
15478 nil)
15479 ((member signal-name multi-in-list)
15480 (vhdl-goto-marker port-in-pos)
15481 (setq port-end-pos
15482 (vhdl-max-marker
15483 port-end-pos (vhdl-compose-insert-port signal-entry)))
15484 (setq port-in-pos (point-marker))
15485 (add-to-list 'written-list signal-name))
15486 ((member signal-name multi-out-list)
15487 (vhdl-goto-marker (vhdl-max-marker port-out-pos 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-out-pos (point-marker))
15492 (add-to-list 'written-list signal-name))
15493 ((or (member signal-name single-in-list)
15494 (member signal-name single-out-list))
15495 (vhdl-goto-marker
15496 (vhdl-max-marker
15497 port-inst-pos
15498 (vhdl-max-marker port-out-pos port-in-pos)))
15499 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15500 (setq port-inst-pos (point-marker))
15501 (add-to-list 'written-list signal-name))
15502 ((equal (upcase (nth 2 signal-entry)) "OUT")
15503 (vhdl-goto-marker signal-pos)
15504 (vhdl-compose-insert-signal signal-entry)
15505 (setq signal-pos (point-marker))
15506 (add-to-list 'written-list signal-name)))
15507 (setq signal-alist (cdr signal-alist)))
15508 (when (/= port-temp-pos port-inst-pos)
15509 (vhdl-goto-marker
15510 (vhdl-max-marker port-temp-pos
15511 (vhdl-max-marker port-in-pos port-out-pos)))
15512 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15513 (insert "-- ports to \"" inst-name "\"\n")
15514 (vhdl-goto-marker port-inst-pos))
15515 (when (/= signal-temp-pos signal-pos)
15516 (vhdl-goto-marker signal-temp-pos)
15517 (insert "\n") (indent-to vhdl-basic-offset)
15518 (insert "-- outputs of \"" inst-name "\"\n")
15519 (vhdl-goto-marker signal-pos))
15520 (setq inst-alist (cdr inst-alist)))
15521 ;; finalize generic/port clause
15522 (vhdl-goto-marker generic-end-pos) (backward-char)
15523 (when (= generic-beg-pos generic-end-pos)
15524 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15525 (insert ";") (backward-char))
15526 (insert ")")
15527 (vhdl-goto-marker port-end-pos) (backward-char)
15528 (when (= port-beg-pos port-end-pos)
15529 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15530 (insert ";") (backward-char))
15531 (insert ")")
15532 ;; align everything
15533 (when vhdl-auto-align
15534 (vhdl-goto-marker generic-beg-pos)
15535 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15536 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15537 (vhdl-goto-marker signal-beg-pos)
15538 (vhdl-align-region-groups signal-beg-pos signal-pos))
15539 (switch-to-buffer (marker-buffer signal-beg-pos))
15540 (message "Wiring components...done")))))
15541
15542(defun vhdl-compose-insert-generic (entry)
15543 "Insert ENTRY as generic declaration."
15544 (let (pos)
15545 (indent-to (* 2 vhdl-basic-offset))
15546 (insert (nth 0 entry) " : " (nth 1 entry))
15547 (when (nth 2 entry)
15548 (insert " := " (nth 2 entry)))
15549 (insert ";")
15550 (setq pos (point-marker))
15551 (when (and vhdl-include-port-comments (nth 3 entry))
15552 (vhdl-comment-insert-inline (nth 3 entry) t))
15553 (insert "\n")
15554 pos))
15555
15556(defun vhdl-compose-insert-port (entry)
15557 "Insert ENTRY as port declaration."
15558 (let (pos)
15559 (indent-to (* 2 vhdl-basic-offset))
15560 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15561 (setq pos (point-marker))
15562 (when (and vhdl-include-port-comments (nth 4 entry))
15563 (vhdl-comment-insert-inline (nth 4 entry) t))
15564 (insert "\n")
15565 pos))
15566
15567(defun vhdl-compose-insert-signal (entry)
15568 "Insert ENTRY as signal declaration."
15569 (indent-to vhdl-basic-offset)
15570 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15571 (when (and vhdl-include-port-comments (nth 4 entry))
15572 (vhdl-comment-insert-inline (nth 4 entry) t))
15573 (insert "\n"))
15574
15575(defun vhdl-compose-components-package ()
15576 "Generate a package containing component declarations for all entities in the
15577current project/directory."
15578 (interactive)
15579 (vhdl-require-hierarchy-info)
15580 (let* ((project (vhdl-project-p))
15581 (pack-name (vhdl-get-components-package-name))
15582 (pack-file-name
15583 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15584 "." (file-name-extension (buffer-file-name))))
15585 (ent-alist (aget vhdl-entity-alist
15586 (or project default-directory) t))
15587 (lazy-lock-minimum-size 0)
15588 clause-pos component-pos)
15589 (message "Generating components package \"%s\"..." pack-name)
15590 ;; open package file
15591 (when (and (file-exists-p pack-file-name)
15592 (not (y-or-n-p (concat "File \"" pack-file-name
15593 "\" exists; overwrite? "))))
15594 (error "ERROR: Generating components package...aborted"))
15595 (find-file pack-file-name)
15596 (erase-buffer)
15597 ;; insert header
15598 (if vhdl-compose-include-header
15599 (progn (vhdl-template-header
15600 (concat "Components package (generated by Emacs VHDL Mode "
15601 vhdl-version ")"))
15602 (goto-char (point-max)))
15603 (vhdl-comment-display-line) (insert "\n\n"))
15604 ;; insert std_logic_1164 package
15605 (vhdl-template-package-std-logic-1164)
15606 (insert "\n") (setq clause-pos (point-marker))
15607 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15608 ;; insert package declaration
15609 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15610 (vhdl-insert-keyword " IS\n\n")
15611 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15612 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15613 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15614 (indent-to vhdl-basic-offset)
15615 (setq component-pos (point-marker))
15616 (insert "\n\n") (vhdl-insert-keyword "END ")
15617 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15618 (insert pack-name ";\n\n")
15619 ;; insert footer
15620 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15621 (vhdl-template-footer)
15622 (vhdl-comment-display-line) (insert "\n"))
15623 ;; insert component declarations
15624 (while ent-alist
15625 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15626 (progn (goto-line (nth 3 (car ent-alist)))
15627 (end-of-line)
15628 (vhdl-port-copy)))
15629 (goto-char component-pos)
15630 (vhdl-port-paste-component t)
15631 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15632 (setq component-pos (point-marker))
15633 (goto-char clause-pos)
15634 (vhdl-port-paste-context-clause pack-name)
15635 (setq clause-pos (point-marker))
15636 (setq ent-alist (cdr ent-alist)))
15637 (goto-char (point-min))
15638 (save-buffer)
15639 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15640 pack-name pack-file-name)))
15641
15642
15643;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15644;;; Compilation / Makefile generation
15645;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15646;; (using `compile.el')
15647
15648(defun vhdl-makefile-name ()
15649 "Return the Makefile name of the current project or the current compiler if
15650no project is defined."
15651 (let ((project-alist (aget vhdl-project-alist vhdl-project))
15652 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
15653 (vhdl-replace-string
15654 (cons "\\(.*\\)\n\\(.*\\)"
15655 (or (nth 8 project-alist) (nth 8 compiler-alist)))
15656 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
15657
15658(defun vhdl-compile-directory ()
15659 "Return the directory where compilation/make should be run."
15660 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
15661 (compiler (aget vhdl-compiler-alist vhdl-compiler))
15662 (directory (vhdl-resolve-env-variable
15663 (if project
15664 (vhdl-replace-string
15665 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
15666 (nth 6 compiler)))))
15667 (file-name-as-directory
15668 (if (file-name-absolute-p directory)
15669 directory
15670 (expand-file-name directory (vhdl-default-directory))))))
15671
15672(defun vhdl-uniquify (in-list)
15673 "Remove duplicate elements from IN-LIST."
15674 (let (out-list)
15675 (while in-list
15676 (add-to-list 'out-list (car in-list))
15677 (setq in-list (cdr in-list)))
15678 out-list))
15679
15680(defun vhdl-set-compiler (name)
15681 "Set current compiler to NAME."
15682 (interactive
15683 (list (let ((completion-ignore-case t))
15684 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
15685 (if (assoc name vhdl-compiler-alist)
15686 (progn (setq vhdl-compiler name)
15687 (message "Current compiler: \"%s\"" vhdl-compiler))
15688 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
15689
15690;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15691;; Compilation
15692
15693(defun vhdl-compile-init ()
15694 "Initialize for compilation."
15695 (when (or (null compilation-error-regexp-alist)
15696 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
15697 compilation-error-regexp-alist)))
15698 ;; `compilation-error-regexp-alist'
15699 (let ((commands-alist vhdl-compiler-alist)
15700 regexp-alist sublist)
15701 (while commands-alist
15702 (setq sublist (nth 11 (car commands-alist)))
15703 (unless (or (equal "" (car sublist))
15704 (assoc (car sublist) regexp-alist))
15705 (setq regexp-alist (cons (list (nth 0 sublist)
15706 (if (= 0 (nth 1 sublist))
15707 (if vhdl-xemacs 9 nil)
15708 (nth 1 sublist))
15709 (nth 2 sublist) (nth 3 sublist))
15710 regexp-alist)))
15711 (setq commands-alist (cdr commands-alist)))
15712 (setq compilation-error-regexp-alist
15713 (append compilation-error-regexp-alist (nreverse regexp-alist))))
15714 ;; `compilation-file-regexp-alist'
15715 (let ((commands-alist vhdl-compiler-alist)
15716 regexp-alist sublist)
15717 ;; matches vhdl-mode file name output
15718 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
15719 (while commands-alist
15720 (setq sublist (nth 12 (car commands-alist)))
15721 (unless (or (equal "" (car sublist))
15722 (assoc (car sublist) regexp-alist))
15723 (setq regexp-alist (cons sublist regexp-alist)))
15724 (setq commands-alist (cdr commands-alist)))
15725 (setq compilation-file-regexp-alist
15726 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
15727
15728(defvar vhdl-compile-file-name nil
15729 "Name of file to be compiled.")
15730
15731(defun vhdl-compile-print-file-name ()
15732 "Function called within `compile' to print out file name for compilers that
15733do not print any file names."
15734 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
15735
15736(defun vhdl-get-compile-options (project compiler file-name
15737 &optional file-options-only)
15738 "Get compiler options. Returning nil means do not compile this file."
15739 (let* ((compiler-options (nth 1 compiler))
15740 (project-entry (aget (nth 4 project) vhdl-compiler))
15741 (project-options (nth 0 project-entry))
15742 (exception-list (and file-name (nth 2 project-entry)))
15743 (work-library (vhdl-work-library))
15744 (case-fold-search nil)
15745 file-options)
15746 (while (and exception-list
15747 (not (string-match (caar exception-list) file-name)))
15748 (setq exception-list (cdr exception-list)))
15749 (if (and exception-list (not (cdar exception-list)))
15750 nil
15751 (if (and file-options-only (not exception-list))
15752 'default
15753 (setq file-options (cdar exception-list))
15754 ;; insert library name in compiler-specific options
15755 (setq compiler-options
15756 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
15757 work-library))
15758 ;; insert compiler-specific options in project-specific options
15759 (when project-options
15760 (setq project-options
15761 (vhdl-replace-string
15762 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15763 (concat work-library "\n" compiler-options))))
15764 ;; insert project-specific options in file-specific options
15765 (when file-options
15766 (setq file-options
15767 (vhdl-replace-string
15768 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
15769 (concat work-library "\n" compiler-options "\n"
15770 project-options))))
15771 ;; return options
15772 (or file-options project-options compiler-options)))))
15773
15774(defun vhdl-get-make-options (project compiler)
15775 "Get make options."
15776 (let* ((compiler-options (nth 3 compiler))
15777 (project-entry (aget (nth 4 project) vhdl-compiler))
15778 (project-options (nth 1 project-entry))
15779 (makefile-name (vhdl-makefile-name)))
15780 ;; insert Makefile name in compiler-specific options
15781 (setq compiler-options
15782 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
15783 makefile-name))
15784 ;; insert compiler-specific options in project-specific options
15785 (when project-options
15786 (setq project-options
15787 (vhdl-replace-string
15788 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15789 (concat makefile-name "\n" compiler-options))))
15790 ;; return options
15791 (or project-options compiler-options)))
15792
15793(defun vhdl-compile ()
15794 "Compile current buffer using the VHDL compiler specified in
15795`vhdl-compiler'."
15796 (interactive)
15797 (vhdl-compile-init)
15798 (let* ((project (aget vhdl-project-alist vhdl-project))
15799 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
15800 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15801 (command (nth 0 compiler))
15802 (file-name (buffer-file-name))
15803 (options (vhdl-get-compile-options project compiler file-name))
15804 (default-directory (vhdl-compile-directory))
15805 compilation-process-setup-function)
15806 (unless (file-directory-p default-directory)
15807 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15808 ;; put file name into quotes if it contains spaces
15809 (when (string-match " " file-name)
15810 (setq file-name (concat "\"" file-name "\"")))
15811 ;; print out file name if compiler does not
15812 (setq vhdl-compile-file-name (buffer-file-name))
15813 (when (and (= 0 (nth 1 (nth 10 compiler)))
15814 (= 0 (nth 1 (nth 11 compiler))))
15815 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
15816 ;; run compilation
15817 (if options
15818 (when command
15819 (compile (concat command " " options " " file-name)))
15820 (vhdl-warning "Your project settings tell me not to compile this file"))))
15821
15822(defun vhdl-make (&optional target)
15823 "Call make command for compilation of all updated source files (requires
15824`Makefile'). Optional argument TARGET allows to compile the design
15825specified by a target."
15826 (interactive)
15827 (vhdl-compile-init)
15828 (let* ((project (aget vhdl-project-alist vhdl-project))
15829 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15830 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15831 (command (nth 2 compiler))
15832 (options (vhdl-get-make-options project compiler))
15833 (default-directory (vhdl-compile-directory)))
15834 (unless (file-directory-p default-directory)
15835 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15836 ;; run make
15837 (compile (concat (if (equal command "") "make" command)
15838 " " options " " target))))
15839
15840;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15841;; Makefile generation
15842
15843(defun vhdl-generate-makefile ()
15844 "Generate `Makefile'."
15845 (interactive)
15846 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15847 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15848 (command (nth 4 compiler)))
15849 ;; generate makefile
15850 (if command
15851 (let ((default-directory (vhdl-compile-directory)))
15852 (compile (vhdl-replace-string
15853 (cons "\\(.*\\) \\(.*\\)" command)
15854 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
15855 (vhdl-generate-makefile-1))))
15856
15857(defun vhdl-get-packages (lib-alist work-library)
15858 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
15859 (let (pack-list)
15860 (while lib-alist
15861 (when (equal (downcase (caar lib-alist)) (downcase work-library))
15862 (setq pack-list (cons (cdar lib-alist) pack-list)))
15863 (setq lib-alist (cdr lib-alist)))
15864 pack-list))
15865
15866(defun vhdl-generate-makefile-1 ()
15867 "Generate Makefile for current project or directory."
15868 ;; scan hierarchy if required
15869 (if (vhdl-project-p)
15870 (unless (or (assoc vhdl-project vhdl-file-alist)
15871 (vhdl-load-cache vhdl-project))
15872 (vhdl-scan-project-contents vhdl-project))
15873 (let ((directory (abbreviate-file-name default-directory)))
15874 (unless (or (assoc directory vhdl-file-alist)
15875 (vhdl-load-cache directory))
15876 (vhdl-scan-directory-contents directory))))
15877 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
15878 (project (vhdl-project-p))
15879 (ent-alist (aget vhdl-entity-alist (or project directory) t))
15880 (conf-alist (aget vhdl-config-alist (or project directory) t))
15881 (pack-alist (aget vhdl-package-alist (or project directory) t))
15882 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
15883 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
15884 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
15885 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
15886 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
15887 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
15888 (adjust-case (nth 5 regexp-list))
15889 (work-library (downcase (vhdl-work-library)))
15890 (compile-directory (expand-file-name (vhdl-compile-directory)
15891 default-directory))
15892 (makefile-name (vhdl-makefile-name))
15893 rule-alist arch-alist inst-alist
15894 target-list depend-list unit-list prim-list second-list subcomp-list
15895 lib-alist lib-body-alist pack-list all-pack-list
15896 ent-key ent-file-name arch-key arch-file-name ent-arch-key
15897 conf-key conf-file-name pack-key pack-file-name
15898 ent-entry arch-entry conf-entry pack-entry inst-entry
15899 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
15900 tmp-key tmp-list rule)
15901 ;; check prerequisites
15902 (unless (file-exists-p compile-directory)
15903 (make-directory compile-directory t))
15904 (unless regexp-list
15905 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
15906 vhdl-compiler))
15907 (message "Generating makefile \"%s\"..." makefile-name)
15908 ;; rules for all entities
15909 (setq tmp-list ent-alist)
15910 (while ent-alist
15911 (setq ent-entry (car ent-alist)
15912 ent-key (nth 0 ent-entry))
15913 (when (nth 2 ent-entry)
15914 (setq ent-file-name (file-relative-name
15915 (nth 2 ent-entry) compile-directory)
15916 arch-alist (nth 4 ent-entry)
15917 lib-alist (nth 5 ent-entry)
15918 rule (aget rule-alist ent-file-name)
15919 target-list (nth 0 rule)
15920 depend-list (nth 1 rule)
15921 second-list nil
15922 subcomp-list nil)
15923 (setq tmp-key (vhdl-replace-string
15924 ent-regexp (funcall adjust-case ent-key)))
15925 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
15926 ;; rule target for this entity
15927 (setq target-list (cons ent-key target-list))
15928 ;; rule dependencies for all used packages
15929 (setq pack-list (vhdl-get-packages lib-alist work-library))
15930 (setq depend-list (append depend-list pack-list))
15931 (setq all-pack-list pack-list)
15932 ;; add rule
15933 (aput 'rule-alist ent-file-name (list target-list depend-list))
15934 ;; rules for all corresponding architectures
15935 (while arch-alist
15936 (setq arch-entry (car arch-alist)
15937 arch-key (nth 0 arch-entry)
15938 ent-arch-key (concat ent-key "-" arch-key)
15939 arch-file-name (file-relative-name (nth 2 arch-entry)
15940 compile-directory)
15941 inst-alist (nth 4 arch-entry)
15942 lib-alist (nth 5 arch-entry)
15943 rule (aget rule-alist arch-file-name)
15944 target-list (nth 0 rule)
15945 depend-list (nth 1 rule))
15946 (setq tmp-key (vhdl-replace-string
15947 arch-regexp
15948 (funcall adjust-case (concat arch-key " " ent-key))))
15949 (setq unit-list
15950 (cons (cons ent-arch-key tmp-key) unit-list))
15951 (setq second-list (cons ent-arch-key second-list))
15952 ;; rule target for this architecture
15953 (setq target-list (cons ent-arch-key target-list))
15954 ;; rule dependency for corresponding entity
15955 (setq depend-list (cons ent-key depend-list))
15956 ;; rule dependencies for contained component instantiations
15957 (while inst-alist
15958 (setq inst-entry (car inst-alist))
15959 (when (or (null (nth 8 inst-entry))
15960 (equal (downcase (nth 8 inst-entry)) work-library))
15961 (setq inst-ent-key (or (nth 7 inst-entry)
15962 (nth 5 inst-entry)))
15963 (setq depend-list (cons inst-ent-key depend-list)
15964 subcomp-list (cons inst-ent-key subcomp-list)))
15965 (setq inst-alist (cdr inst-alist)))
15966 ;; rule dependencies for all used packages
15967 (setq pack-list (vhdl-get-packages lib-alist work-library))
15968 (setq depend-list (append depend-list pack-list))
15969 (setq all-pack-list (append all-pack-list pack-list))
15970 ;; add rule
15971 (aput 'rule-alist arch-file-name (list target-list depend-list))
15972 (setq arch-alist (cdr arch-alist)))
15973 (setq prim-list (cons (list ent-key second-list
15974 (append subcomp-list all-pack-list))
15975 prim-list)))
15976 (setq ent-alist (cdr ent-alist)))
15977 (setq ent-alist tmp-list)
15978 ;; rules for all configurations
15979 (setq tmp-list conf-alist)
15980 (while conf-alist
15981 (setq conf-entry (car conf-alist)
15982 conf-key (nth 0 conf-entry)
15983 conf-file-name (file-relative-name
15984 (nth 2 conf-entry) compile-directory)
15985 ent-key (nth 4 conf-entry)
15986 arch-key (nth 5 conf-entry)
15987 inst-alist (nth 6 conf-entry)
15988 lib-alist (nth 7 conf-entry)
15989 rule (aget rule-alist conf-file-name)
15990 target-list (nth 0 rule)
15991 depend-list (nth 1 rule)
15992 subcomp-list (list ent-key))
15993 (setq tmp-key (vhdl-replace-string
15994 conf-regexp (funcall adjust-case conf-key)))
15995 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
15996 ;; rule target for this configuration
15997 (setq target-list (cons conf-key target-list))
15998 ;; rule dependency for corresponding entity and architecture
15999 (setq depend-list
16000 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
16001 ;; rule dependencies for used packages
16002 (setq pack-list (vhdl-get-packages lib-alist work-library))
16003 (setq depend-list (append depend-list pack-list))
16004 ;; rule dependencies for contained component configurations
16005 (while inst-alist
16006 (setq inst-entry (car inst-alist))
16007 (setq inst-ent-key (nth 2 inst-entry)
16008; comp-arch-key (nth 2 inst-entry))
16009 inst-conf-key (nth 4 inst-entry))
16010 (when (equal (downcase (nth 5 inst-entry)) work-library)
16011 (when inst-ent-key
16012 (setq depend-list (cons inst-ent-key depend-list)
16013 subcomp-list (cons inst-ent-key subcomp-list)))
16014; (when comp-arch-key
16015; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16016; depend-list)))
16017 (when inst-conf-key
16018 (setq depend-list (cons inst-conf-key depend-list)
16019 subcomp-list (cons inst-conf-key subcomp-list))))
16020 (setq inst-alist (cdr inst-alist)))
16021 ;; add rule
16022 (aput 'rule-alist conf-file-name (list target-list depend-list))
16023 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16024 prim-list))
16025 (setq conf-alist (cdr conf-alist)))
16026 (setq conf-alist tmp-list)
16027 ;; rules for all packages
16028 (setq tmp-list pack-alist)
16029 (while pack-alist
16030 (setq pack-entry (car pack-alist)
16031 pack-key (nth 0 pack-entry)
16032 pack-body-key nil)
16033 (when (nth 2 pack-entry)
16034 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16035 compile-directory)
16036 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16037 rule (aget rule-alist pack-file-name)
16038 target-list (nth 0 rule) depend-list (nth 1 rule))
16039 (setq tmp-key (vhdl-replace-string
16040 pack-regexp (funcall adjust-case pack-key)))
16041 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16042 ;; rule target for this package
16043 (setq target-list (cons pack-key target-list))
16044 ;; rule dependencies for all used packages
16045 (setq pack-list (vhdl-get-packages lib-alist work-library))
16046 (setq depend-list (append depend-list pack-list))
16047 (setq all-pack-list pack-list)
16048 ;; add rule
16049 (aput 'rule-alist pack-file-name (list target-list depend-list))
16050 ;; rules for this package's body
16051 (when (nth 7 pack-entry)
16052 (setq pack-body-key (concat pack-key "-body")
16053 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16054 compile-directory)
16055 rule (aget rule-alist pack-body-file-name)
16056 target-list (nth 0 rule)
16057 depend-list (nth 1 rule))
16058 (setq tmp-key (vhdl-replace-string
16059 pack-body-regexp (funcall adjust-case pack-key)))
16060 (setq unit-list
16061 (cons (cons pack-body-key tmp-key) unit-list))
16062 ;; rule target for this package's body
16063 (setq target-list (cons pack-body-key target-list))
16064 ;; rule dependency for corresponding package declaration
16065 (setq depend-list (cons pack-key depend-list))
16066 ;; rule dependencies for all used packages
16067 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16068 (setq depend-list (append depend-list pack-list))
16069 (setq all-pack-list (append all-pack-list pack-list))
16070 ;; add rule
16071 (aput 'rule-alist pack-body-file-name
16072 (list target-list depend-list)))
16073 (setq prim-list
16074 (cons (list pack-key (when pack-body-key (list pack-body-key))
16075 all-pack-list)
16076 prim-list)))
16077 (setq pack-alist (cdr pack-alist)))
16078 (setq pack-alist tmp-list)
16079 ;; generate Makefile
16080 (let* ((project (aget vhdl-project-alist project))
16081 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16082 (compiler-id (nth 9 compiler))
16083 (library-directory
16084 (vhdl-resolve-env-variable
16085 (vhdl-replace-string
16086 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16087 compiler-id)))
16088 (makefile-path-name (expand-file-name
16089 makefile-name compile-directory))
16090 (orig-buffer (current-buffer))
16091 cell second-list subcomp-list options unit-key unit-name)
16092 ;; sort lists
16093 (setq unit-list (vhdl-sort-alist unit-list))
16094 (setq prim-list (vhdl-sort-alist prim-list))
16095 (setq tmp-list rule-alist)
16096 (while tmp-list ; pre-sort rule targets
16097 (setq cell (cdar tmp-list))
16098 (setcar cell (sort (car cell) 'string<))
16099 (setq tmp-list (cdr tmp-list)))
16100 (setq rule-alist ; sort by first rule target
16101 (sort rule-alist
16102 (function (lambda (a b)
16103 (string< (car (cadr a)) (car (cadr b)))))))
16104 ;; open and clear Makefile
16105 (set-buffer (find-file-noselect makefile-path-name t t))
16106 (erase-buffer)
16107 (insert "# -*- Makefile -*-\n"
16108 "### " (file-name-nondirectory makefile-name)
16109 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16110 "\n")
16111 (if project
16112 (insert "\n# Project : " (nth 0 project))
16113 (insert "\n# Directory : \"" directory "\""))
16114 (insert "\n# Platform : " vhdl-compiler
16115 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16116 (user-login-name) "\n")
16117 ;; insert compile and option variable settings
16118 (insert "\n\n# Define compilation command and options\n"
16119 "\nCOMPILE = " (nth 0 compiler)
16120 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16121 "\n")
16122 ;; insert library paths
16123 (setq library-directory
16124 (directory-file-name
16125 (if (file-name-absolute-p library-directory)
16126 library-directory
16127 (file-relative-name
16128 (expand-file-name library-directory directory)
16129 compile-directory))))
16130 (insert "\n\n# Define library paths\n"
16131 "\nLIBRARY-" work-library " = " library-directory "\n")
16132 ;; insert variable definitions for all library unit files
16133 (insert "\n\n# Define library unit files\n")
16134 (setq tmp-list unit-list)
16135 (while unit-list
16136 (insert "\nUNIT-" work-library "-" (caar unit-list)
16137 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16138 (setq unit-list (cdr unit-list)))
16139 ;; insert variable definition for list of all library unit files
16140 (insert "\n\n\n# Define list of all library unit files\n"
16141 "\nALL_UNITS =")
16142 (setq unit-list tmp-list)
16143 (while unit-list
16144 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16145 (setq unit-list (cdr unit-list)))
16146 (insert "\n")
16147 (setq unit-list tmp-list)
16148 ;; insert `make all' rule
16149 (insert "\n\n\n# Rule for compiling entire design\n"
16150 "\nall :"
16151 " \\\n\t\tlibrary"
16152 " \\\n\t\t$(ALL_UNITS)\n")
16153 ;; insert `make clean' rule
16154 (insert "\n\n# Rule for cleaning entire design\n"
16155 "\nclean : "
16156 "\n\t-rm -f $(ALL_UNITS)\n")
16157 ;; insert `make library' rule
16158 (insert "\n\n# Rule for creating library directory\n"
16159 "\nlibrary :"
16160 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16161 "\n$(LIBRARY-" work-library ") :"
16162 "\n\t"
16163 (vhdl-replace-string
16164 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16165 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16166 "\n")
16167 ;; insert rule for each library unit
16168 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16169 (while prim-list
16170 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16171 (setq subcomp-list
16172 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16173 (setq unit-key (caar prim-list)
16174 unit-name (or (nth 0 (aget ent-alist unit-key t))
16175 (nth 0 (aget conf-alist unit-key t))
16176 (nth 0 (aget pack-alist unit-key t))))
16177 (insert "\n" unit-key)
16178 (unless (equal unit-key unit-name)
16179 (insert " \\\n" unit-name))
16180 (insert " :"
16181 " \\\n\t\tlibrary"
16182 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16183 (while second-list
16184 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16185 (setq second-list (cdr second-list)))
16186 (while subcomp-list
16187 (when (assoc (car subcomp-list) unit-list)
16188 (insert " \\\n\t\t" (car subcomp-list)))
16189 (setq subcomp-list (cdr subcomp-list)))
16190 (insert "\n")
16191 (setq prim-list (cdr prim-list)))
16192 ;; insert rule for each library unit file
16193 (insert "\n\n# Rules for compiling single library unit files\n")
16194 (while rule-alist
16195 (setq rule (car rule-alist))
16196 ;; get compiler options for this file
16197 (setq options
16198 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16199 ;; insert rule if file is supposed to be compiled
16200 (setq target-list (nth 1 rule)
16201 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16202 ;; insert targets
16203 (setq tmp-list target-list)
16204 (while target-list
16205 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16206 (if (cdr target-list) " \\" " :"))
16207 (setq target-list (cdr target-list)))
16208 (setq target-list tmp-list)
16209 ;; insert file name as first dependency
16210 (insert " \\\n\t\t" (nth 0 rule))
16211 ;; insert dependencies (except if also target or unit does not exist)
16212 (while depend-list
16213 (when (and (not (member (car depend-list) target-list))
16214 (assoc (car depend-list) unit-list))
16215 (insert " \\\n\t\t"
16216 "$(UNIT-" work-library "-" (car depend-list) ")"))
16217 (setq depend-list (cdr depend-list)))
16218 ;; insert compile command
16219 (if options
16220 (insert "\n\t$(COMPILE) "
16221 (if (eq options 'default) "$(OPTIONS)" options) " "
16222 (nth 0 rule) "\n")
16223 (setq tmp-list target-list)
16224 (while target-list
16225 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16226 (if (cdr target-list) " \\" "\n"))
16227 (setq target-list (cdr target-list)))
16228 (setq target-list tmp-list))
16229 (setq rule-alist (cdr rule-alist)))
16230 (insert "\n\n### " makefile-name " ends here\n")
16231 ;; run Makefile generation hook
16232 (run-hooks 'vhdl-makefile-generation-hook)
16233 (message "Generating makefile \"%s\"...done" makefile-name)
16234 ;; save and close file
16235 (if (file-writable-p makefile-path-name)
16236 (progn (save-buffer)
16237 (kill-buffer (current-buffer))
16238 (set-buffer orig-buffer)
16239 (setq file-name-history
16240 (cons makefile-path-name file-name-history)))
16241 (vhdl-warning-when-idle
16242 (format "File not writable: \"%s\""
16243 (abbreviate-file-name makefile-path-name)))
16244 (switch-to-buffer (current-buffer))))))
16245
5eabfe72
KH
16246
16247;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16248;;; Bug reports
16249;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16250;; (using `reporter.el')
16251
3dcb36b7
JB
16252(defconst vhdl-mode-help-address
16253 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16254 "Address for VHDL Mode bug reports.")
16255
3dcb36b7
JB
16256(defun vhdl-submit-bug-report ()
16257 "Submit via mail a bug report on VHDL Mode."
16258 (interactive)
16259 ;; load in reporter
16260 (and
16261 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16262 (let ((reporter-prompt-for-summary-p t))
16263 (reporter-submit-bug-report
16264 vhdl-mode-help-address
16265 (concat "VHDL Mode " vhdl-version)
16266 (list
16267 ;; report all important user options
16268 'vhdl-offsets-alist
16269 'vhdl-comment-only-line-offset
16270 'tab-width
16271 'vhdl-electric-mode
16272 'vhdl-stutter-mode
16273 'vhdl-indent-tabs-mode
16274 'vhdl-project-alist
16275 'vhdl-project
16276 'vhdl-project-file-name
16277 'vhdl-project-auto-load
16278 'vhdl-project-sort
16279 'vhdl-compiler-alist
16280 'vhdl-compiler
16281 'vhdl-compile-use-local-error-regexp
16282 'vhdl-makefile-generation-hook
16283 'vhdl-default-library
16284 'vhdl-standard
16285 'vhdl-basic-offset
16286 'vhdl-upper-case-keywords
16287 'vhdl-upper-case-types
16288 'vhdl-upper-case-attributes
16289 'vhdl-upper-case-enum-values
16290 'vhdl-upper-case-constants
16291 'vhdl-use-direct-instantiation
16292 'vhdl-entity-file-name
16293 'vhdl-architecture-file-name
16294 'vhdl-package-file-name
16295 'vhdl-file-name-case
16296 'vhdl-electric-keywords
16297 'vhdl-optional-labels
16298 'vhdl-insert-empty-lines
16299 'vhdl-argument-list-indent
16300 'vhdl-association-list-with-formals
16301 'vhdl-conditions-in-parenthesis
16302 'vhdl-zero-string
16303 'vhdl-one-string
16304 'vhdl-file-header
16305 'vhdl-file-footer
16306 'vhdl-company-name
16307 'vhdl-copyright-string
16308 'vhdl-platform-spec
16309 'vhdl-date-format
16310 'vhdl-modify-date-prefix-string
16311 'vhdl-modify-date-on-saving
16312 'vhdl-reset-kind
16313 'vhdl-reset-active-high
16314 'vhdl-clock-rising-edge
16315 'vhdl-clock-edge-condition
16316 'vhdl-clock-name
16317 'vhdl-reset-name
16318 'vhdl-model-alist
16319 'vhdl-include-port-comments
16320 'vhdl-include-direction-comments
16321 'vhdl-include-type-comments
16322 'vhdl-include-group-comments
16323 'vhdl-actual-port-name
16324 'vhdl-instance-name
16325 'vhdl-testbench-entity-name
16326 'vhdl-testbench-architecture-name
16327 'vhdl-testbench-configuration-name
16328 'vhdl-testbench-dut-name
16329 'vhdl-testbench-include-header
16330 'vhdl-testbench-declarations
16331 'vhdl-testbench-statements
16332 'vhdl-testbench-initialize-signals
16333 'vhdl-testbench-include-library
16334 'vhdl-testbench-include-configuration
16335 'vhdl-testbench-create-files
16336 'vhdl-compose-create-files
16337 'vhdl-compose-include-header
16338 'vhdl-compose-architecture-name
16339 'vhdl-components-package-name
16340 'vhdl-use-components-package
16341 'vhdl-self-insert-comments
16342 'vhdl-prompt-for-comments
16343 'vhdl-inline-comment-column
16344 'vhdl-end-comment-column
16345 'vhdl-auto-align
16346 'vhdl-align-groups
16347 'vhdl-align-group-separate
16348 'vhdl-align-same-indent
16349 'vhdl-highlight-keywords
16350 'vhdl-highlight-names
16351 'vhdl-highlight-special-words
16352 'vhdl-highlight-forbidden-words
16353 'vhdl-highlight-verilog-keywords
16354 'vhdl-highlight-translate-off
16355 'vhdl-highlight-case-sensitive
16356 'vhdl-special-syntax-alist
16357 'vhdl-forbidden-words
16358 'vhdl-forbidden-syntax
16359 'vhdl-directive-keywords
16360 'vhdl-speedbar-auto-open
16361 'vhdl-speedbar-display-mode
16362 'vhdl-speedbar-scan-limit
16363 'vhdl-speedbar-jump-to-unit
16364 'vhdl-speedbar-update-on-saving
16365 'vhdl-speedbar-save-cache
16366 'vhdl-speedbar-cache-file-name
16367 'vhdl-index-menu
16368 'vhdl-source-file-menu
16369 'vhdl-hideshow-menu
16370 'vhdl-hide-all-init
16371 'vhdl-print-two-column
16372 'vhdl-print-customize-faces
16373 'vhdl-intelligent-tab
16374 'vhdl-indent-syntax-based
16375 'vhdl-word-completion-case-sensitive
16376 'vhdl-word-completion-in-minibuffer
16377 'vhdl-underscore-is-part-of-word
16378 'vhdl-mode-hook)
16379 (function
16380 (lambda ()
16381 (insert
16382 (if vhdl-special-indent-hook
16383 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16384 "vhdl-special-indent-hook is set to '"
16385 (format "%s" vhdl-special-indent-hook)
16386 ".\nPerhaps this is your problem?\n"
16387 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16388 "\n"))))
16389 nil
16390 "Hi Reto,"))))
16391
16392
16393;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16394;;; Documentation
16395;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16396
16397(defconst vhdl-doc-release-notes nil
16398 "\
16399Release Notes for VHDL Mode 3.32
16400================================
16401
16402 - New Features
16403 - Enhanced Features
16404 - User Options
16405 - Remarks
16406
16407
16408New Features
16409------------
16410
16411STRUCTURAL COMPOSITION:
16412 - Enables simple structural composition similar to graphical editors.
16413 Simplifies the creation of higher design levels where subcomponents
16414 are simply sticked together:
16415 1. Create a skeleton for a new component
16416 2. Place subcomponents in it directly from the hierarchy browser
16417 3. Automatically connect all subcomponents and create the ports
16418 for the new component (based on names of actual ports)
16419 - Automatic generation of a components package (package containing
16420 component declarations for all entities).
16421 - Find more information in the online documentation (`C-c C-h').
16422
16423PORT TRANSLATION:
16424 - Reverse direction of ports (useful for testbenches).
16425
16426SUBPROGRAM TRANSLATION:
16427 - Copy/paste of subprogram interfaces (similar to port translation).
16428
16429CODE FILLING:
16430 - Condense code using code-sensitive block filling.
16431
16432CODE STATISTICS:
16433 - Calculate number of code lines and statements in a buffer.
16434
16435
16436Enhanced Features
16437-----------------
16438
16439TESTBENCH GENERATION:
16440 - Enhanced templates and user option default values.
16441
16442Emacs 21 compatibility/enhancements:
16443 - `lazy-lock-mode' is not used anymore (built-in `jit-lock-mode' is faster).
16444
16445And many other minor fixes and enhancements.
16446
16447
16448User Options
16449------------
16450
16451`vhdl-project-file-name': (enhanced)
16452 Include user name in project setup file name.
16453`vhdl-speedbar-cache-file-name': (enhanced, changed default)
16454 Include user name in cache file name.
16455`vhdl-default-library': (new)
16456 Default working library if no project is active.
16457`vhdl-architecture-file-name': (new)
16458 Specify how the architecture file name is obtained.
16459`vhdl-package-file-name': (new)
16460 Specify how the package file name is obtained.
16461`vhdl-file-name-case': (new)
16462 Allows to change case when deriving file names.
16463`vhdl-compose-create-files': (new)
16464 Specify whether new files should be created for a new component.
16465`vhdl-compose-include-header': (new)
16466 Specify whether a header is included in a new component's file.
16467`vhdl-compose-architecture-name': (new)
16468 Specify how a new component's architecture name is obtained.
16469`vhdl-components-package-name': (new)
16470 Specify how the name for the components package is obtained.
16471`vhdl-use-components-package': (new)
16472 Specify whether component declarations go in a components package.
16473`vhdl-use-direct-instantiation': (new)
16474 Specify whether to use VHDL'93 direct component instantiation.
16475`vhdl-instance-name': (changed default)
16476 Allows insertion of a running number to generate unique instance names.
16477`vhdl-testbench-entity-header', `vhdl-testbench-architecture-header':(obsolete)
16478 Headers are now automatically derived from the standard header.
16479`vhdl-testbench-include-header': (new)
16480 Specify whether a header is included in testbench files.
16481`vhdl-testbench-declaration', `vhdl-testbench-statements': (changed default)
16482 Non-empty default values for more complete testbench templates.
16483
16484
16485Remarks
16486-------
16487
16488- Changed key binding for `vhdl-comment-uncomment-region': `C-c c'
16489 (`C-c C-c ...' is now used for structural composition).
16490
16491- Automatic buffer highlighting (font-lock) is now controlled by option
16492 `global-font-lock-mode' in GNU Emacs (`font-lock-auto-fontify' in XEmacs).
16493 \(Important: You MUST customize this option in order to turn automatic
16494 buffer highlighting on.)
16495")
16496
16497
16498(defconst vhdl-doc-keywords nil
16499 "\
16500Reserved words in VHDL
16501----------------------
16502
16503VHDL'93 (IEEE Std 1076-1993):
16504 `vhdl-93-keywords' : keywords
16505 `vhdl-93-types' : standardized types
16506 `vhdl-93-attributes' : standardized attributes
16507 `vhdl-93-enum-values' : standardized enumeration values
16508 `vhdl-93-functions' : standardized functions
16509 `vhdl-93-packages' : standardized packages and libraries
16510
16511VHDL-AMS (IEEE Std 1076.1):
16512 `vhdl-ams-keywords' : keywords
16513 `vhdl-ams-types' : standardized types
16514 `vhdl-ams-attributes' : standardized attributes
16515 `vhdl-ams-enum-values' : standardized enumeration values
16516 `vhdl-ams-functions' : standardized functions
16517
16518Math Packages (IEEE Std 1076.2):
16519 `vhdl-math-types' : standardized types
16520 `vhdl-math-constants' : standardized constants
16521 `vhdl-math-functions' : standardized functions
16522 `vhdl-math-packages' : standardized packages
16523
16524Forbidden words:
16525 `vhdl-verilog-keywords' : Verilog reserved words
16526
16527NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16528
16529
16530(defconst vhdl-doc-coding-style nil
16531 "\
16532For VHDL coding style and naming convention guidelines, see the following
16533references:
16534
16535\[1] Ben Cohen.
16536 \"VHDL Coding Styles and Methodologies\".
16537 Kluwer Academic Publishers, 1999.
16538 http://members.aol.com/vhdlcohen/vhdl/
16539
16540\[2] Michael Keating and Pierre Bricaud.
16541 \"Reuse Methodology Manual, Second Edition\".
16542 Kluwer Academic Publishers, 1999.
16543 http://www.openmore.com/openmore/rmm2.html
16544
16545\[3] European Space Agency.
16546 \"VHDL Modelling Guidelines\".
16547 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16548
16549Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16550to visually support naming conventions.")
16551
16552
d2ddb974
KH
16553(defun vhdl-version ()
16554 "Echo the current version of VHDL Mode in the minibuffer."
16555 (interactive)
3dcb36b7 16556 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16557 (vhdl-keep-region-active))
16558
3dcb36b7
JB
16559(defun vhdl-doc-variable (variable)
16560 "Display VARIABLE's documentation in *Help* buffer."
16561 (interactive)
16562 (with-output-to-temp-buffer "*Help*"
16563 (princ (documentation-property variable 'variable-documentation))
16564 (unless vhdl-xemacs
16565 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16566 (save-excursion
16567 (set-buffer standard-output)
16568 (help-mode))
16569 (print-help-return-message)))
d2ddb974 16570
3dcb36b7
JB
16571(defun vhdl-doc-mode ()
16572 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 16573 (interactive)
3dcb36b7
JB
16574 (with-output-to-temp-buffer "*Help*"
16575 (princ mode-name)
16576 (princ " mode:\n")
16577 (princ (documentation 'vhdl-mode))
16578 (unless vhdl-xemacs
16579 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16580 (save-excursion
16581 (set-buffer standard-output)
16582 (help-mode))
16583 (print-help-return-message)))
d2ddb974
KH
16584
16585
5eabfe72 16586;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16587
16588(provide 'vhdl-mode)
16589
ab5796a9 16590;;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
d2ddb974 16591;;; vhdl-mode.el ends here