Sync to HEAD
[bpt/emacs.git] / lisp / progmodes / vhdl-mode.el
CommitLineData
d2ddb974
KH
1;;; vhdl-mode.el --- major mode for editing VHDL code
2
3dcb36b7
JB
3;; Copyright (C) 1992-2003 Free Software Foundation, Inc.
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)
4560 (set (make-local-variable 'require-final-newline) t)
4561 (set (make-local-variable 'parse-sexp-ignore-comments) t)
4562 (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
4563 (set (make-local-variable 'comment-start) "--")
4564 (set (make-local-variable 'comment-end) "")
3dcb36b7
JB
4565 (when vhdl-emacs-21
4566 (set (make-local-variable 'comment-padding) ""))
5eabfe72 4567 (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
d2ddb974
KH
4568 (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
4569 (set (make-local-variable 'comment-start-skip) "--+\\s-*")
5eabfe72 4570 (set (make-local-variable 'comment-multi-line) nil)
d2ddb974 4571 (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
5eabfe72 4572 (set (make-local-variable 'hippie-expand-verbose) nil)
d2ddb974
KH
4573
4574 ;; setup the comment indent variable in a Emacs version portable way
4575 ;; ignore any byte compiler warnings you might get here
5eabfe72
KH
4576 (when (boundp 'comment-indent-function)
4577 (make-local-variable 'comment-indent-function)
4578 (setq comment-indent-function 'vhdl-comment-indent))
d2ddb974
KH
4579
4580 ;; initialize font locking
5eabfe72
KH
4581 (set (make-local-variable 'font-lock-defaults)
4582 (list
3dcb36b7 4583 '(nil vhdl-font-lock-keywords) nil
5eabfe72
KH
4584 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
4585 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
3dcb36b7
JB
4586 (unless vhdl-emacs-21
4587 (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
4588 (set (make-local-variable 'lazy-lock-defer-contextually) nil)
4589 (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
4590; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4591 (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
4592; (turn-on-font-lock)
d2ddb974
KH
4593
4594 ;; variables for source file compilation
3dcb36b7
JB
4595 (when vhdl-compile-use-local-error-regexp
4596 (set (make-local-variable 'compilation-error-regexp-alist) nil)
4597 (set (make-local-variable 'compilation-file-regexp-alist) nil))
5eabfe72
KH
4598
4599 ;; add index menu
4600 (vhdl-index-menu-init)
4601 ;; add source file menu
d2ddb974 4602 (if vhdl-source-file-menu (vhdl-add-source-files-menu))
5eabfe72
KH
4603 ;; add VHDL menu
4604 (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
4605 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4606 "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
4607 ;; initialize hideshow and add menu
5eabfe72 4608 (vhdl-hideshow-init)
d2ddb974
KH
4609 (run-hooks 'menu-bar-update-hook)
4610
5eabfe72
KH
4611 ;; miscellaneous
4612 (vhdl-ps-print-init)
3dcb36b7 4613 (vhdl-write-file-hooks-init)
5eabfe72 4614 (vhdl-mode-line-update)
3dcb36b7
JB
4615 (message "VHDL Mode %s.%s" vhdl-version
4616 (if noninteractive "" " See menu for documentation and release notes."))
5eabfe72
KH
4617
4618 ;; run hooks
4619 (run-hooks 'vhdl-mode-hook))
4620
4621(defun vhdl-activate-customizations ()
4622 "Activate all customizations on local variables."
4623 (interactive)
4624 (vhdl-mode-map-init)
4625 (use-local-map vhdl-mode-map)
4626 (set-syntax-table vhdl-mode-syntax-table)
4627 (setq comment-column vhdl-inline-comment-column)
4628 (setq end-comment-column vhdl-end-comment-column)
3dcb36b7 4629 (vhdl-write-file-hooks-init)
5eabfe72
KH
4630 (vhdl-update-mode-menu)
4631 (vhdl-hideshow-init)
4632 (run-hooks 'menu-bar-update-hook)
4633 (vhdl-mode-line-update))
4634
3dcb36b7
JB
4635(defun vhdl-write-file-hooks-init ()
4636 "Add/remove hooks when buffer is saved."
5eabfe72
KH
4637 (if vhdl-modify-date-on-saving
4638 (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror)
3dcb36b7
JB
4639 (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror))
4640 (make-local-variable 'after-save-hook)
4641 (add-hook 'after-save-hook 'vhdl-add-modified-file))
4642
4643(defun vhdl-process-command-line-option (option)
4644 "Process command line options for VHDL Mode."
4645 (cond
4646 ;; set compiler
4647 ((equal option "-compiler")
4648 (vhdl-set-compiler (car command-line-args-left))
4649 (setq command-line-args-left (cdr command-line-args-left)))
4650 ;; set project
4651 ((equal option "-project")
4652 (vhdl-set-project (car command-line-args-left))
4653 (setq command-line-args-left (cdr command-line-args-left)))))
4654
4655;; make Emacs process VHDL Mode options
4656(setq command-switch-alist
4657 (append command-switch-alist
4658 '(("-compiler" . vhdl-process-command-line-option)
4659 ("-project" . vhdl-process-command-line-option))))
5eabfe72
KH
4660
4661
4662;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4663;;; Keywords and standardized words
5eabfe72
KH
4664;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4665
3dcb36b7
JB
4666(defconst vhdl-93-keywords
4667 '(
4668 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4669 "assert" "attribute"
4670 "begin" "block" "body" "buffer" "bus"
4671 "case" "component" "configuration" "constant"
4672 "disconnect" "downto"
4673 "else" "elsif" "end" "entity" "exit"
4674 "file" "for" "function"
4675 "generate" "generic" "group" "guarded"
4676 "if" "impure" "in" "inertial" "inout" "is"
4677 "label" "library" "linkage" "literal" "loop"
4678 "map" "mod"
4679 "nand" "new" "next" "nor" "not" "null"
4680 "of" "on" "open" "or" "others" "out"
4681 "package" "port" "postponed" "procedure" "process" "pure"
4682 "range" "record" "register" "reject" "rem" "report" "return"
4683 "rol" "ror"
4684 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4685 "then" "to" "transport" "type"
4686 "unaffected" "units" "until" "use"
4687 "variable"
4688 "wait" "when" "while" "with"
4689 "xnor" "xor"
4690 )
4691 "List of VHDL'93 keywords.")
d2ddb974 4692
5eabfe72
KH
4693(defconst vhdl-ams-keywords
4694 '(
4695 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4696 "reference" "spectrum" "subnature" "terminal" "through"
4697 "tolerance"
4698 )
4699 "List of VHDL-AMS keywords.")
d2ddb974 4700
5eabfe72
KH
4701(defconst vhdl-verilog-keywords
4702 '(
4703 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4704 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4705 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4706 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4707 "endprimitive" "endspecify" "endtable" "endtask" "event"
4708 "for" "force" "forever" "fork" "function"
4709 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4710 "macromodule" "makefile" "medium" "module"
4711 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4712 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4713 "pullup"
4714 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4715 "rtranif0" "rtranif1"
4716 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4717 "strong1" "supply" "supply0" "supply1"
4718 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4719 "triand" "trior" "trireg"
4720 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4721 )
4722 "List of Verilog keywords as candidate for additional reserved words.")
d2ddb974 4723
5eabfe72
KH
4724(defconst vhdl-93-types
4725 '(
4726 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4727 "real" "time" "natural" "positive" "string" "line" "text" "side"
4728 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4729 "std_logic" "std_logic_vector"
4730 "std_ulogic" "std_ulogic_vector"
4731 )
4732 "List of VHDL'93 standardized types.")
d2ddb974 4733
5eabfe72
KH
4734(defconst vhdl-ams-types
4735 '(
4736 "domain_type" "real_vector"
3dcb36b7
JB
4737 ;; from `nature_pkg' package
4738 "voltage" "current" "electrical" "position" "velocity" "force"
4739 "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
4740 "pressure" "flowrate" "fluid"
4741 )
5eabfe72 4742 "List of VHDL-AMS standardized types.")
d2ddb974 4743
5eabfe72
KH
4744(defconst vhdl-math-types
4745 '(
4746 "complex" "complex_polar"
4747 )
4748 "List of Math Packages standardized types.")
d2ddb974 4749
5eabfe72
KH
4750(defconst vhdl-93-attributes
4751 '(
4752 "base" "left" "right" "high" "low" "pos" "val" "succ"
4753 "pred" "leftof" "rightof" "range" "reverse_range"
4754 "length" "delayed" "stable" "quiet" "transaction"
4755 "event" "active" "last_event" "last_active" "last_value"
4756 "driving" "driving_value" "ascending" "value" "image"
4757 "simple_name" "instance_name" "path_name"
4758 "foreign"
4759 )
4760 "List of VHDL'93 standardized attributes.")
d2ddb974 4761
5eabfe72
KH
4762(defconst vhdl-ams-attributes
4763 '(
4764 "across" "through"
4765 "reference" "contribution" "tolerance"
4766 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
4767 "ramp" "slew"
4768 )
4769 "List of VHDL-AMS standardized attributes.")
d2ddb974 4770
5eabfe72
KH
4771(defconst vhdl-93-enum-values
4772 '(
4773 "true" "false"
4774 "note" "warning" "error" "failure"
4775 "read_mode" "write_mode" "append_mode"
4776 "open_ok" "status_error" "name_error" "mode_error"
4777 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
4778 "right" "left"
4779 )
4780 "List of VHDL'93 standardized enumeration values.")
d2ddb974 4781
5eabfe72
KH
4782(defconst vhdl-ams-enum-values
4783 '(
4784 "quiescent_domain" "time_domain" "frequency_domain"
3dcb36b7
JB
4785 ;; from `nature_pkg' package
4786 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5eabfe72
KH
4787 )
4788 "List of VHDL-AMS standardized enumeration values.")
4789
4790(defconst vhdl-math-constants
4791 '(
4792 "math_e" "math_1_over_e"
4793 "math_pi" "math_two_pi" "math_1_over_pi"
4794 "math_half_pi" "math_q_pi" "math_3_half_pi"
4795 "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
4796 "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
4797 "math_deg_to_rad" "math_rad_to_deg"
4798 "cbase_1" "cbase_j" "czero"
4799 )
4800 "List of Math Packages standardized constants.")
4801
4802(defconst vhdl-93-functions
4803 '(
4804 "now" "resolved" "rising_edge" "falling_edge"
4805 "read" "readline" "write" "writeline" "endfile"
4806 "resize" "is_X" "std_match"
4807 "shift_left" "shift_right" "rotate_left" "rotate_right"
4808 "to_unsigned" "to_signed" "to_integer"
4809 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
4810 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
4811 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
4812 "shl" "shr" "ext" "sxt"
3dcb36b7 4813 "deallocate"
5eabfe72
KH
4814 )
4815 "List of VHDL'93 standardized functions.")
4816
4817(defconst vhdl-ams-functions
4818 '(
4819 "frequency"
4820 )
4821 "List of VHDL-AMS standardized functions.")
4822
4823(defconst vhdl-math-functions
4824 '(
4825 "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
4826 "sqrt" "cbrt" "exp" "log"
4827 "sin" "cos" "tan" "arcsin" "arccos" "arctan"
4828 "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
4829 "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
4830 )
4831 "List of Math Packages standardized functions.")
4832
4833(defconst vhdl-93-packages
4834 '(
4835 "std_logic_1164" "numeric_std" "numeric_bit"
4836 "standard" "textio"
4837 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
4838 "std_logic_misc" "std_logic_textio"
4839 "ieee" "std" "work"
4840 )
4841 "List of VHDL'93 standardized packages and libraries.")
4842
3dcb36b7
JB
4843(defconst vhdl-ams-packages
4844 '(
4845 ;; from `nature_pkg' package
4846 "nature_pkg"
4847 )
4848 "List of VHDL-AMS standardized packages and libraries.")
4849
5eabfe72
KH
4850(defconst vhdl-math-packages
4851 '(
4852 "math_real" "math_complex"
4853 )
4854 "List of Math Packages standardized packages and libraries.")
4855
4856(defvar vhdl-keywords nil
4857 "List of VHDL keywords.")
4858
4859(defvar vhdl-types nil
4860 "List of VHDL standardized types.")
4861
4862(defvar vhdl-attributes nil
4863 "List of VHDL standardized attributes.")
4864
4865(defvar vhdl-enum-values nil
4866 "List of VHDL standardized enumeration values.")
4867
4868(defvar vhdl-constants nil
4869 "List of VHDL standardized constants.")
4870
4871(defvar vhdl-functions nil
4872 "List of VHDL standardized functions.")
4873
4874(defvar vhdl-packages nil
4875 "List of VHDL standardized packages and libraries.")
4876
4877(defvar vhdl-reserved-words nil
4878 "List of additional reserved words.")
4879
4880(defvar vhdl-keywords-regexp nil
4881 "Regexp for VHDL keywords.")
4882
4883(defvar vhdl-types-regexp nil
4884 "Regexp for VHDL standardized types.")
4885
4886(defvar vhdl-attributes-regexp nil
4887 "Regexp for VHDL standardized attributes.")
4888
4889(defvar vhdl-enum-values-regexp nil
4890 "Regexp for VHDL standardized enumeration values.")
4891
4892(defvar vhdl-functions-regexp nil
4893 "Regexp for VHDL standardized functions.")
4894
4895(defvar vhdl-packages-regexp nil
4896 "Regexp for VHDL standardized packages and libraries.")
4897
4898(defvar vhdl-reserved-words-regexp nil
4899 "Regexp for additional reserved words.")
4900
3dcb36b7
JB
4901(defvar vhdl-directive-keywords-regexp nil
4902 "Regexp for compiler directive keywords.")
4903
5eabfe72
KH
4904(defun vhdl-words-init ()
4905 "Initialize reserved words."
4906 (setq vhdl-keywords
4907 (append vhdl-93-keywords
4908 (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
4909 (setq vhdl-types
4910 (append vhdl-93-types
4911 (when (vhdl-standard-p 'ams) vhdl-ams-types)
4912 (when (vhdl-standard-p 'math) vhdl-math-types)))
4913 (setq vhdl-attributes
4914 (append vhdl-93-attributes
4915 (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
4916 (setq vhdl-enum-values
4917 (append vhdl-93-enum-values
4918 (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
4919 (setq vhdl-constants
4920 (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
4921 (setq vhdl-functions
4922 (append vhdl-93-functions
4923 (when (vhdl-standard-p 'ams) vhdl-ams-functions)
4924 (when (vhdl-standard-p 'math) vhdl-math-functions)))
4925 (setq vhdl-packages
4926 (append vhdl-93-packages
3dcb36b7 4927 (when (vhdl-standard-p 'ams) vhdl-ams-packages)
5eabfe72
KH
4928 (when (vhdl-standard-p 'math) vhdl-math-packages)))
4929 (setq vhdl-reserved-words
4930 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
4931 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
4932 '("")))
4933 (setq vhdl-keywords-regexp
4934 (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
4935 (setq vhdl-types-regexp
4936 (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
4937 (setq vhdl-attributes-regexp
4938 (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
4939 (setq vhdl-enum-values-regexp
4940 (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
4941 (setq vhdl-functions-regexp
4942 (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
4943 (setq vhdl-packages-regexp
4944 (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
4945 (setq vhdl-reserved-words-regexp
4946 (concat "\\<\\("
4947 (unless (equal vhdl-forbidden-syntax "")
4948 (concat vhdl-forbidden-syntax "\\|"))
4949 (regexp-opt vhdl-reserved-words)
4950 "\\)\\>"))
3dcb36b7
JB
4951 (setq vhdl-directive-keywords-regexp
4952 (concat "\\<\\(" (mapconcat 'regexp-quote
4953 vhdl-directive-keywords "\\|") "\\)\\>"))
5eabfe72
KH
4954 (vhdl-abbrev-list-init))
4955
4956;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4957;; Words to expand
4958
4959(defvar vhdl-abbrev-list nil
4960 "Predefined abbreviations for VHDL.")
4961
4962(defun vhdl-abbrev-list-init ()
4963 (setq vhdl-abbrev-list
4964 (append
4965 (list vhdl-upper-case-keywords) vhdl-keywords
4966 (list vhdl-upper-case-types) vhdl-types
4967 (list vhdl-upper-case-attributes) vhdl-attributes
4968 (list vhdl-upper-case-enum-values) vhdl-enum-values
4969 (list vhdl-upper-case-constants) vhdl-constants
4970 (list nil) vhdl-functions
4971 (list nil) vhdl-packages)))
4972
4973;; initialize reserved words for VHDL Mode
4974(vhdl-words-init)
4975
4976
4977;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 4978;;; Indentation
5eabfe72
KH
4979;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4980
4981;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
4982;; Syntax analysis
4983
4984;; constant regular expressions for looking at various constructs
4985
4986(defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
4987 "Regexp describing a VHDL symbol.
4988We cannot use just `word' syntax class since `_' cannot be in word
4989class. Putting underscore in word class breaks forward word movement
4990behavior that users are familiar with.")
4991
4992(defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
4993 "Regexp describing a case statement header key.")
4994
4995(defconst vhdl-label-key
4996 (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
4997 "Regexp describing a VHDL label.")
4998
4999;; Macro definitions:
5000
5001(defmacro vhdl-point (position)
5eabfe72
KH
5002 "Return the value of point at certain commonly referenced POSITIONs.
5003POSITION can be one of the following symbols:
5004
5005bol -- beginning of line
5006eol -- end of line
5007bod -- beginning of defun
5008boi -- back to indentation
5009eoi -- last whitespace on line
5010ionl -- indentation of next line
5011iopl -- indentation of previous line
5012bonl -- beginning of next line
5013bopl -- beginning of previous line
5014
5015This function does not modify point or mark."
d2ddb974 5016 (or (and (eq 'quote (car-safe position))
3dcb36b7
JB
5017 (null (cddr position)))
5018 (error "ERROR: Bad buffer position requested: %s" position))
d2ddb974 5019 (setq position (nth 1 position))
d4a5b644
GM
5020 `(let ((here (point)))
5021 ,@(cond
5022 ((eq position 'bol) '((beginning-of-line)))
5023 ((eq position 'eol) '((end-of-line)))
5024 ((eq position 'bod) '((save-match-data
5025 (vhdl-beginning-of-defun))))
5026 ((eq position 'boi) '((back-to-indentation)))
3dcb36b7 5027 ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
d4a5b644
GM
5028 ((eq position 'bonl) '((forward-line 1)))
5029 ((eq position 'bopl) '((forward-line -1)))
5030 ((eq position 'iopl)
5031 '((forward-line -1)
5032 (back-to-indentation)))
5033 ((eq position 'ionl)
5034 '((forward-line 1)
5035 (back-to-indentation)))
3dcb36b7 5036 (t (error "ERROR: Unknown buffer position requested: %s" position))
d4a5b644
GM
5037 )
5038 (prog1
5039 (point)
5040 (goto-char here))
5041 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5042 ;; doesn't hurt for v19
5043 ,@nil
5044 ))
d2ddb974
KH
5045
5046(defmacro vhdl-safe (&rest body)
5eabfe72 5047 "Safely execute BODY, return nil if an error occurred."
d4a5b644
GM
5048 `(condition-case nil
5049 (progn ,@body)
5050 (error nil)))
d2ddb974
KH
5051
5052(defmacro vhdl-add-syntax (symbol &optional relpos)
5eabfe72
KH
5053 "A simple macro to append the syntax in SYMBOL to the syntax list.
5054Try to increase performance by using this macro."
d4a5b644
GM
5055 `(setq vhdl-syntactic-context
5056 (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
d2ddb974
KH
5057
5058(defmacro vhdl-has-syntax (symbol)
5eabfe72
KH
5059 "A simple macro to return check the syntax list.
5060Try to increase performance by using this macro."
d4a5b644 5061 `(assoc ,symbol vhdl-syntactic-context))
d2ddb974
KH
5062
5063;; Syntactic element offset manipulation:
5064
5065(defun vhdl-read-offset (langelem)
5eabfe72
KH
5066 "Read new offset value for LANGELEM from minibuffer.
5067Return a legal value only."
d2ddb974
KH
5068 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
5069 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5070 (prompt "Offset: ")
5071 offset input interned)
5072 (while (not offset)
5073 (setq input (read-string prompt oldoff)
5074 offset (cond ((string-equal "+" input) '+)
5075 ((string-equal "-" input) '-)
5076 ((string-equal "++" input) '++)
5077 ((string-equal "--" input) '--)
5078 ((string-match "^-?[0-9]+$" input)
5079 (string-to-int input))
5080 ((fboundp (setq interned (intern input)))
5081 interned)
5082 ((boundp interned) interned)
5083 ;; error, but don't signal one, keep trying
5084 ;; to read an input value
5085 (t (ding)
5086 (setq prompt errmsg)
5087 nil))))
5088 offset))
5089
5090(defun vhdl-set-offset (symbol offset &optional add-p)
5091 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5092SYMBOL is the syntactic element symbol to change and OFFSET is the new
5093offset for that syntactic element. Optional ADD says to add SYMBOL to
5094`vhdl-offsets-alist' if it doesn't already appear there."
5095 (interactive
5096 (let* ((langelem
5097 (intern (completing-read
5098 (concat "Syntactic symbol to change"
5099 (if current-prefix-arg " or add" "")
5100 ": ")
5101 (mapcar
5102 (function
5103 (lambda (langelem)
5104 (cons (format "%s" (car langelem)) nil)))
5105 vhdl-offsets-alist)
5106 nil (not current-prefix-arg)
5107 ;; initial contents tries to be the last element
5108 ;; on the syntactic analysis list for the current
5109 ;; line
5110 (let* ((syntax (vhdl-get-syntactic-context))
5111 (len (length syntax))
5112 (ic (format "%s" (car (nth (1- len) syntax)))))
5eabfe72 5113 ic)
d2ddb974
KH
5114 )))
5115 (offset (vhdl-read-offset langelem)))
5116 (list langelem offset current-prefix-arg)))
5117 ;; sanity check offset
5118 (or (eq offset '+)
5119 (eq offset '-)
5120 (eq offset '++)
5121 (eq offset '--)
5122 (integerp offset)
5123 (fboundp offset)
5124 (boundp offset)
3dcb36b7 5125 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
d2ddb974
KH
5126 offset))
5127 (let ((entry (assq symbol vhdl-offsets-alist)))
5128 (if entry
5129 (setcdr entry offset)
5130 (if add-p
5eabfe72
KH
5131 (setq vhdl-offsets-alist
5132 (cons (cons symbol offset) vhdl-offsets-alist))
3dcb36b7 5133 (error "ERROR: %s is not a valid syntactic symbol" symbol))))
d2ddb974
KH
5134 (vhdl-keep-region-active))
5135
5136(defun vhdl-set-style (style &optional local)
5eabfe72 5137 "Set `vhdl-mode' variables to use one of several different indentation styles.
d2ddb974
KH
5138STYLE is a string representing the desired style and optional LOCAL is
5139a flag which, if non-nil, means to make the style variables being
5140changed buffer local, instead of the default, which is to set the
5141global variables. Interactively, the flag comes from the prefix
5142argument. The styles are chosen from the `vhdl-style-alist' variable."
5143 (interactive (list (completing-read "Use which VHDL indentation style? "
5eabfe72 5144 vhdl-style-alist nil t)
d2ddb974
KH
5145 current-prefix-arg))
5146 (let ((vars (cdr (assoc style vhdl-style-alist))))
5147 (or vars
3dcb36b7 5148 (error "ERROR: Invalid VHDL indentation style `%s'" style))
d2ddb974
KH
5149 ;; set all the variables
5150 (mapcar
5151 (function
5152 (lambda (varentry)
5153 (let ((var (car varentry))
5154 (val (cdr varentry)))
5155 (and local
5156 (make-local-variable var))
5157 ;; special case for vhdl-offsets-alist
5158 (if (not (eq var 'vhdl-offsets-alist))
5159 (set var val)
5160 ;; reset vhdl-offsets-alist to the default value first
5161 (setq vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default))
5162 ;; now set the langelems that are different
5163 (mapcar
5164 (function
5165 (lambda (langentry)
5166 (let ((langelem (car langentry))
5167 (offset (cdr langentry)))
5168 (vhdl-set-offset langelem offset)
5169 )))
5170 val))
5171 )))
5172 vars))
5173 (vhdl-keep-region-active))
5174
5175(defun vhdl-get-offset (langelem)
5eabfe72
KH
5176 "Get offset from LANGELEM which is a cons cell of the form:
5177\(SYMBOL . RELPOS). The symbol is matched against
5178vhdl-offsets-alist and the offset found there is either returned,
5179or added to the indentation at RELPOS. If RELPOS is nil, then
5180the offset is simply returned."
d2ddb974
KH
5181 (let* ((symbol (car langelem))
5182 (relpos (cdr langelem))
5183 (match (assq symbol vhdl-offsets-alist))
5184 (offset (cdr-safe match)))
5185 ;; offset can be a number, a function, a variable, or one of the
5186 ;; symbols + or -
5187 (cond
5188 ((not match)
5189 (if vhdl-strict-syntax-p
3dcb36b7 5190 (error "ERROR: Don't know how to indent a %s" symbol)
d2ddb974
KH
5191 (setq offset 0
5192 relpos 0)))
5193 ((eq offset '+) (setq offset vhdl-basic-offset))
5194 ((eq offset '-) (setq offset (- vhdl-basic-offset)))
5195 ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
5196 ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
5197 ((and (not (numberp offset))
5198 (fboundp offset))
5199 (setq offset (funcall offset langelem)))
5200 ((not (numberp offset))
5201 (setq offset (eval offset)))
5202 )
5203 (+ (if (and relpos
5204 (< relpos (vhdl-point 'bol)))
5205 (save-excursion
5206 (goto-char relpos)
5207 (current-column))
5208 0)
5209 offset)))
5210
5211;; Syntactic support functions:
5212
3dcb36b7
JB
5213(defun vhdl-in-comment-p ()
5214 "Check if point is in a comment."
5215 (eq (vhdl-in-literal) 'comment))
5216
5217(defun vhdl-in-string-p ()
5218 "Check if point is in a string."
5219 (eq (vhdl-in-literal) 'string))
d2ddb974 5220
3dcb36b7 5221(defun vhdl-in-literal ()
5eabfe72 5222 "Determine if point is in a VHDL literal."
d2ddb974 5223 (save-excursion
5eabfe72 5224 (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
d2ddb974
KH
5225 (cond
5226 ((nth 3 state) 'string)
5227 ((nth 4 state) 'comment)
5eabfe72 5228 (t nil)))))
d2ddb974 5229
3dcb36b7
JB
5230(defun vhdl-forward-comment (&optional direction)
5231 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5232negative, skip forward otherwise."
5233 (interactive "p")
5234 (if (and direction (< direction 0))
5235 ;; skip backwards
5236 (progn
5237 (skip-chars-backward " \t\n")
5238 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
5239 (goto-char (match-beginning 3))
5240 (skip-chars-backward " \t\n")))
5241 ;; skip forwards
5242 (skip-chars-forward " \t\n")
5243 (while (looking-at "--.*")
5244 (goto-char (match-end 0))
5245 (skip-chars-forward " \t\n"))))
5246
5247;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5248(unless (and vhdl-xemacs (string< "21.2" emacs-version))
5249 (defalias 'vhdl-forward-comment 'forward-comment))
5250
d2ddb974
KH
5251;; This is the best we can do in Win-Emacs.
5252(defun vhdl-win-il (&optional lim)
5eabfe72 5253 "Determine if point is in a VHDL literal."
d2ddb974
KH
5254 (save-excursion
5255 (let* ((here (point))
5256 (state nil)
5257 (match nil)
5258 (lim (or lim (vhdl-point 'bod))))
5259 (goto-char lim )
5260 (while (< (point) here)
5261 (setq match
5262 (and (re-search-forward "--\\|[\"']"
5263 here 'move)
5264 (buffer-substring (match-beginning 0) (match-end 0))))
5265 (setq state
5266 (cond
5267 ;; no match
5268 ((null match) nil)
5269 ;; looking at the opening of a VHDL style comment
5270 ((string= "--" match)
5271 (if (<= here (progn (end-of-line) (point))) 'comment))
5272 ;; looking at the opening of a double quote string
5273 ((string= "\"" match)
5274 (if (not (save-restriction
5275 ;; this seems to be necessary since the
5276 ;; re-search-forward will not work without it
5277 (narrow-to-region (point) here)
5278 (re-search-forward
5279 ;; this regexp matches a double quote
5280 ;; which is preceded by an even number
5281 ;; of backslashes, including zero
5282 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
5283 'string))
5284 ;; looking at the opening of a single quote string
5285 ((string= "'" match)
5286 (if (not (save-restriction
5287 ;; see comments from above
5288 (narrow-to-region (point) here)
5289 (re-search-forward
5290 ;; this matches a single quote which is
5291 ;; preceded by zero or two backslashes.
5292 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5293 here 'move)))
5294 'string))
5295 (t nil)))
5296 ) ; end-while
5297 state)))
5298
5eabfe72 5299(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5300 (fset 'vhdl-in-literal 'vhdl-win-il))
5301
5302;; Skipping of "syntactic whitespace". Syntactic whitespace is
5303;; defined as lexical whitespace or comments. Search no farther back
5304;; or forward than optional LIM. If LIM is omitted, (point-min) is
5305;; used for backward skipping, (point-max) is used for forward
5306;; skipping.
5307
5308(defun vhdl-forward-syntactic-ws (&optional lim)
5eabfe72 5309 "Forward skip of syntactic whitespace."
d2ddb974
KH
5310 (save-restriction
5311 (let* ((lim (or lim (point-max)))
5312 (here lim)
5313 (hugenum (point-max)))
5314 (narrow-to-region lim (point))
5315 (while (/= here (point))
5316 (setq here (point))
3dcb36b7 5317 (vhdl-forward-comment hugenum)))))
d2ddb974
KH
5318
5319;; This is the best we can do in Win-Emacs.
5320(defun vhdl-win-fsws (&optional lim)
5eabfe72 5321 "Forward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5322 (let ((lim (or lim (point-max)))
5323 stop)
5324 (while (not stop)
5325 (skip-chars-forward " \t\n\r\f" lim)
5326 (cond
5327 ;; vhdl comment
5328 ((looking-at "--") (end-of-line))
5329 ;; none of the above
3dcb36b7 5330 (t (setq stop t))))))
d2ddb974 5331
5eabfe72 5332(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5333 (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
5334
5335(defun vhdl-backward-syntactic-ws (&optional lim)
5eabfe72 5336 "Backward skip over syntactic whitespace."
d2ddb974
KH
5337 (save-restriction
5338 (let* ((lim (or lim (point-min)))
5339 (here lim)
5340 (hugenum (- (point-max))))
5341 (if (< lim (point))
5342 (progn
5343 (narrow-to-region lim (point))
5344 (while (/= here (point))
5345 (setq here (point))
3dcb36b7 5346 (vhdl-forward-comment hugenum)))))))
d2ddb974
KH
5347
5348;; This is the best we can do in Win-Emacs.
5349(defun vhdl-win-bsws (&optional lim)
5eabfe72 5350 "Backward skip syntactic whitespace for Win-Emacs."
d2ddb974
KH
5351 (let ((lim (or lim (vhdl-point 'bod)))
5352 stop)
5353 (while (not stop)
5354 (skip-chars-backward " \t\n\r\f" lim)
5355 (cond
5356 ;; vhdl comment
3dcb36b7 5357 ((eq (vhdl-in-literal) 'comment)
d2ddb974
KH
5358 (skip-chars-backward "^-" lim)
5359 (skip-chars-backward "-" lim)
5360 (while (not (or (and (= (following-char) ?-)
5361 (= (char-after (1+ (point))) ?-))
5362 (<= (point) lim)))
5363 (skip-chars-backward "^-" lim)
5364 (skip-chars-backward "-" lim)))
5365 ;; none of the above
3dcb36b7 5366 (t (setq stop t))))))
d2ddb974 5367
5eabfe72 5368(and (string-match "Win-Emacs" emacs-version)
d2ddb974
KH
5369 (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
5370
5371;; Functions to help finding the correct indentation column:
5372
5373(defun vhdl-first-word (point)
5374 "If the keyword at POINT is at boi, then return (current-column) at
5375that point, else nil."
5376 (save-excursion
5377 (and (goto-char point)
5378 (eq (point) (vhdl-point 'boi))
5379 (current-column))))
5380
5381(defun vhdl-last-word (point)
5382 "If the keyword at POINT is at eoi, then return (current-column) at
5383that point, else nil."
5384 (save-excursion
5385 (and (goto-char point)
5386 (save-excursion (or (eq (progn (forward-sexp) (point))
5387 (vhdl-point 'eoi))
5388 (looking-at "\\s-*\\(--\\)?")))
5389 (current-column))))
5390
5391;; Core syntactic evaluation functions:
5392
5393(defconst vhdl-libunit-re
5394 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5395
5396(defun vhdl-libunit-p ()
5397 (and
5398 (save-excursion
5399 (forward-sexp)
5400 (skip-chars-forward " \t\n")
5401 (not (looking-at "is\\b[^_]")))
5402 (save-excursion
5403 (backward-sexp)
5404 (and (not (looking-at "use\\b[^_]"))
5405 (progn
5406 (forward-sexp)
5407 (vhdl-forward-syntactic-ws)
5408 (/= (following-char) ?:))))
5409 ))
5410
5411(defconst vhdl-defun-re
5eabfe72 5412 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
d2ddb974
KH
5413
5414(defun vhdl-defun-p ()
5415 (save-excursion
5eabfe72
KH
5416 (if (looking-at "block\\|process\\|procedural")
5417 ;; "block", "process", "procedural":
d2ddb974
KH
5418 (save-excursion
5419 (backward-sexp)
5420 (not (looking-at "end\\s-+\\w")))
5421 ;; "architecture", "configuration", "entity",
5422 ;; "package", "procedure", "function":
5423 t)))
5424
5425(defun vhdl-corresponding-defun ()
5426 "If the word at the current position corresponds to a \"defun\"
5427keyword, then return a string that can be used to find the
5428corresponding \"begin\" keyword, else return nil."
5429 (save-excursion
5430 (and (looking-at vhdl-defun-re)
5431 (vhdl-defun-p)
5eabfe72
KH
5432 (if (looking-at "block\\|process\\|procedural")
5433 ;; "block", "process". "procedural:
d2ddb974
KH
5434 (buffer-substring (match-beginning 0) (match-end 0))
5435 ;; "architecture", "configuration", "entity", "package",
5436 ;; "procedure", "function":
5437 "is"))))
5438
5439(defconst vhdl-begin-fwd-re
5eabfe72 5440 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
d2ddb974
KH
5441 "A regular expression for searching forward that matches all known
5442\"begin\" keywords.")
5443
5444(defconst vhdl-begin-bwd-re
5eabfe72 5445 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
d2ddb974
KH
5446 "A regular expression for searching backward that matches all known
5447\"begin\" keywords.")
5448
5449(defun vhdl-begin-p (&optional lim)
5450 "Return t if we are looking at a real \"begin\" keyword.
5451Assumes that the caller will make sure that we are looking at
5452vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5453the middle of an identifier that just happens to contain a \"begin\"
5454keyword."
5455 (cond
5456 ;; "[architecture|case|configuration|entity|package|
5457 ;; procedure|function] ... is":
5458 ((and (looking-at "i")
5459 (save-excursion
5460 ;; Skip backward over first sexp (needed to skip over a
5461 ;; procedure interface list, and is harmless in other
5462 ;; situations). Note that we need "return" in the
5463 ;; following search list so that we don't run into
5464 ;; semicolons in the function interface list.
5465 (backward-sexp)
5466 (let (foundp)
5467 (while (and (not foundp)
5468 (re-search-backward
5eabfe72 5469 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
d2ddb974
KH
5470 lim 'move))
5471 (if (or (= (preceding-char) ?_)
3dcb36b7 5472 (vhdl-in-literal))
d2ddb974
KH
5473 (backward-char)
5474 (setq foundp t))))
5475 (and (/= (following-char) ?\;)
5eabfe72 5476 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
d2ddb974
KH
5477 t)
5478 ;; "begin", "then":
5479 ((looking-at "be\\|t")
5480 t)
5481 ;; "else":
5482 ((and (looking-at "e")
5483 ;; make sure that the "else" isn't inside a
5484 ;; conditional signal assignment.
5485 (save-excursion
5486 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5487 (or (eq (following-char) ?\;)
5488 (eq (point) lim))))
5489 t)
5eabfe72 5490 ;; "block", "generate", "loop", "process", "procedural",
d2ddb974
KH
5491 ;; "units", "record":
5492 ((and (looking-at "bl\\|[glpur]")
5493 (save-excursion
5494 (backward-sexp)
5495 (not (looking-at "end\\s-+\\w"))))
5496 t)
5497 ;; "component":
5498 ((and (looking-at "c")
5499 (save-excursion
5500 (backward-sexp)
5501 (not (looking-at "end\\s-+\\w")))
5502 ;; look out for the dreaded entity class in an attribute
5503 (save-excursion
5504 (vhdl-backward-syntactic-ws lim)
5505 (/= (preceding-char) ?:)))
5506 t)
5507 ;; "for" (inside configuration declaration):
5508 ((and (looking-at "f")
5509 (save-excursion
5510 (backward-sexp)
5511 (not (looking-at "end\\s-+\\w")))
5512 (vhdl-has-syntax 'configuration))
5513 t)
5514 ))
5515
5516(defun vhdl-corresponding-mid (&optional lim)
5517 (cond
5eabfe72 5518 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
d2ddb974
KH
5519 "begin")
5520 ((looking-at "then")
5521 "<else>")
5522 (t
5523 "end")))
5524
5525(defun vhdl-corresponding-end (&optional lim)
5526 "If the word at the current position corresponds to a \"begin\"
5527keyword, then return a vector containing enough information to find
5528the corresponding \"end\" keyword, else return nil. The keyword to
5529search forward for is aref 0. The column in which the keyword must
5530appear is aref 1 or nil if any column is suitable.
5531Assumes that the caller will make sure that we are not in the middle
5532of an identifier that just happens to contain a \"begin\" keyword."
5533 (save-excursion
5534 (and (looking-at vhdl-begin-fwd-re)
5535 (/= (preceding-char) ?_)
3dcb36b7 5536 (not (vhdl-in-literal))
d2ddb974
KH
5537 (vhdl-begin-p lim)
5538 (cond
5539 ;; "is", "generate", "loop":
5540 ((looking-at "[igl]")
5541 (vector "end"
5542 (and (vhdl-last-word (point))
5543 (or (vhdl-first-word (point))
5544 (save-excursion
5545 (vhdl-beginning-of-statement-1 lim)
5546 (vhdl-backward-skip-label lim)
5547 (vhdl-first-word (point)))))))
5548 ;; "begin", "else", "for":
5549 ((looking-at "be\\|[ef]")
5550 (vector "end"
5551 (and (vhdl-last-word (point))
5552 (or (vhdl-first-word (point))
5553 (save-excursion
5554 (vhdl-beginning-of-statement-1 lim)
5555 (vhdl-backward-skip-label lim)
5556 (vhdl-first-word (point)))))))
5557 ;; "component", "units", "record":
5558 ((looking-at "[cur]")
5559 ;; The first end found will close the block
5560 (vector "end" nil))
5eabfe72 5561 ;; "block", "process", "procedural":
d2ddb974
KH
5562 ((looking-at "bl\\|p")
5563 (vector "end"
5564 (or (vhdl-first-word (point))
5565 (save-excursion
5566 (vhdl-beginning-of-statement-1 lim)
5567 (vhdl-backward-skip-label lim)
5568 (vhdl-first-word (point))))))
5569 ;; "then":
5570 ((looking-at "t")
5571 (vector "elsif\\|else\\|end\\s-+if"
5572 (and (vhdl-last-word (point))
5573 (or (vhdl-first-word (point))
5574 (save-excursion
5575 (vhdl-beginning-of-statement-1 lim)
5576 (vhdl-backward-skip-label lim)
5577 (vhdl-first-word (point)))))))
5578 ))))
5579
5580(defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5581
5582(defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5583
5584(defun vhdl-end-p (&optional lim)
5585 "Return t if we are looking at a real \"end\" keyword.
5586Assumes that the caller will make sure that we are looking at
5587vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5588the middle of an identifier that just happens to contain an \"end\"
5589keyword."
5590 (or (not (looking-at "else"))
5591 ;; make sure that the "else" isn't inside a conditional signal
5592 ;; assignment.
5593 (save-excursion
5594 (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
5595 (or (eq (following-char) ?\;)
5596 (eq (point) lim)))))
5597
5598(defun vhdl-corresponding-begin (&optional lim)
5599 "If the word at the current position corresponds to an \"end\"
5600keyword, then return a vector containing enough information to find
5601the corresponding \"begin\" keyword, else return nil. The keyword to
3dcb36b7 5602search backward for is aref 0. The column in which the keyword must
d2ddb974
KH
5603appear is aref 1 or nil if any column is suitable. The supplementary
5604keyword to search forward for is aref 2 or nil if this is not
5605required. If aref 3 is t, then the \"begin\" keyword may be found in
5606the middle of a statement.
5607Assumes that the caller will make sure that we are not in the middle
5608of an identifier that just happens to contain an \"end\" keyword."
5609 (save-excursion
5610 (let (pos)
5611 (if (and (looking-at vhdl-end-fwd-re)
3dcb36b7 5612 (not (vhdl-in-literal))
d2ddb974
KH
5613 (vhdl-end-p lim))
5614 (if (looking-at "el")
5615 ;; "else", "elsif":
5616 (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
5617 ;; "end ...":
5618 (setq pos (point))
5619 (forward-sexp)
5620 (skip-chars-forward " \t\n")
5621 (cond
5622 ;; "end if":
5623 ((looking-at "if\\b[^_]")
5624 (vector "else\\|elsif\\|if"
5625 (vhdl-first-word pos)
5626 "else\\|then" nil))
5627 ;; "end component":
5628 ((looking-at "component\\b[^_]")
5629 (vector (buffer-substring (match-beginning 1)
5630 (match-end 1))
5631 (vhdl-first-word pos)
5632 nil nil))
5633 ;; "end units", "end record":
5634 ((looking-at "\\(units\\|record\\)\\b[^_]")
5635 (vector (buffer-substring (match-beginning 1)
5636 (match-end 1))
5637 (vhdl-first-word pos)
5638 nil t))
5eabfe72
KH
5639 ;; "end block", "end process", "end procedural":
5640 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
d2ddb974
KH
5641 (vector "begin" (vhdl-first-word pos) nil nil))
5642 ;; "end case":
5643 ((looking-at "case\\b[^_]")
5644 (vector "case" (vhdl-first-word pos) "is" nil))
5645 ;; "end generate":
5646 ((looking-at "generate\\b[^_]")
5647 (vector "generate\\|for\\|if"
5648 (vhdl-first-word pos)
5649 "generate" nil))
5650 ;; "end loop":
5651 ((looking-at "loop\\b[^_]")
5652 (vector "loop\\|while\\|for"
5653 (vhdl-first-word pos)
5654 "loop" nil))
5655 ;; "end for" (inside configuration declaration):
5656 ((looking-at "for\\b[^_]")
5657 (vector "for" (vhdl-first-word pos) nil nil))
5658 ;; "end [id]":
5659 (t
5660 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
5661 (vhdl-first-word pos)
5662 ;; return an alist of (statement . keyword) mappings
5663 '(
5664 ;; "begin ... end [id]":
5665 ("begin" . nil)
5666 ;; "architecture ... is ... begin ... end [id]":
5667 ("architecture" . "is")
5668 ;; "configuration ... is ... end [id]":
5669 ("configuration" . "is")
5670 ;; "entity ... is ... end [id]":
5671 ("entity" . "is")
5672 ;; "package ... is ... end [id]":
5673 ("package" . "is")
5674 ;; "procedure ... is ... begin ... end [id]":
5675 ("procedure" . "is")
5676 ;; "function ... is ... begin ... end [id]":
5677 ("function" . "is")
5678 )
5679 nil))
5680 ))) ; "end ..."
5681 )))
5682
5683(defconst vhdl-leader-re
5eabfe72 5684 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
d2ddb974
KH
5685
5686(defun vhdl-end-of-leader ()
5687 (save-excursion
5eabfe72 5688 (cond ((looking-at "block\\|process\\|procedural")
d2ddb974
KH
5689 (if (save-excursion
5690 (forward-sexp)
5691 (skip-chars-forward " \t\n")
5692 (= (following-char) ?\())
5693 (forward-sexp 2)
5694 (forward-sexp))
3dcb36b7
JB
5695 (when (looking-at "[ \t\n]*is")
5696 (goto-char (match-end 0)))
d2ddb974
KH
5697 (point))
5698 ((looking-at "component")
5699 (forward-sexp 2)
3dcb36b7
JB
5700 (when (looking-at "[ \t\n]*is")
5701 (goto-char (match-end 0)))
d2ddb974
KH
5702 (point))
5703 ((looking-at "for")
5704 (forward-sexp 2)
5705 (skip-chars-forward " \t\n")
5706 (while (looking-at "[,:(]")
5707 (forward-sexp)
5708 (skip-chars-forward " \t\n"))
5709 (point))
5710 (t nil)
5711 )))
5712
5713(defconst vhdl-trailer-re
5714 "\\b\\(is\\|then\\|generate\\|loop\\)\\b[^_]")
5715
5716(defconst vhdl-statement-fwd-re
5717 "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
5718 "A regular expression for searching forward that matches all known
5719\"statement\" keywords.")
5720
5721(defconst vhdl-statement-bwd-re
5722 "\\b\\(if\\|for\\|while\\)\\b[^_]"
5723 "A regular expression for searching backward that matches all known
5724\"statement\" keywords.")
5725
5726(defun vhdl-statement-p (&optional lim)
5727 "Return t if we are looking at a real \"statement\" keyword.
5728Assumes that the caller will make sure that we are looking at
5eabfe72
KH
5729vhdl-statement-fwd-re, and are not inside a literal, and that we are not
5730in the middle of an identifier that just happens to contain a
5731\"statement\" keyword."
d2ddb974
KH
5732 (cond
5733 ;; "for" ... "generate":
5734 ((and (looking-at "f")
5735 ;; Make sure it's the start of a parameter specification.
5736 (save-excursion
5737 (forward-sexp 2)
5738 (skip-chars-forward " \t\n")
5739 (looking-at "in\\b[^_]"))
5740 ;; Make sure it's not an "end for".
5741 (save-excursion
5742 (backward-sexp)
5743 (not (looking-at "end\\s-+\\w"))))
5744 t)
5745 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
5746 ((and (looking-at "i")
5747 ;; Make sure it's not an "end if".
5748 (save-excursion
5749 (backward-sexp)
5750 (not (looking-at "end\\s-+\\w"))))
5751 t)
5752 ;; "while" ... "loop":
5753 ((looking-at "w")
5754 t)
5755 ))
5756
5757(defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
5758 "Regexp describing a case statement alternative key.")
5759
5760(defun vhdl-case-alternative-p (&optional lim)
5761 "Return t if we are looking at a real case alternative.
5762Assumes that the caller will make sure that we are looking at
5763vhdl-case-alternative-re, and are not inside a literal, and that
5764we are not in the middle of an identifier that just happens to
5765contain a \"when\" keyword."
5766 (save-excursion
5767 (let (foundp)
5768 (while (and (not foundp)
5769 (re-search-backward ";\\|<=" lim 'move))
5770 (if (or (= (preceding-char) ?_)
3dcb36b7 5771 (vhdl-in-literal))
d2ddb974
KH
5772 (backward-char)
5773 (setq foundp t)))
5774 (or (eq (following-char) ?\;)
5775 (eq (point) lim)))
5776 ))
5777
5778;; Core syntactic movement functions:
5779
5780(defconst vhdl-b-t-b-re
5781 (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
5782
5783(defun vhdl-backward-to-block (&optional lim)
5784 "Move backward to the previous \"begin\" or \"end\" keyword."
5785 (let (foundp)
5786 (while (and (not foundp)
5787 (re-search-backward vhdl-b-t-b-re lim 'move))
5788 (if (or (= (preceding-char) ?_)
3dcb36b7 5789 (vhdl-in-literal))
d2ddb974
KH
5790 (backward-char)
5791 (cond
5792 ;; "begin" keyword:
5793 ((and (looking-at vhdl-begin-fwd-re)
5794 (/= (preceding-char) ?_)
5795 (vhdl-begin-p lim))
5796 (setq foundp 'begin))
5797 ;; "end" keyword:
5798 ((and (looking-at vhdl-end-fwd-re)
5799 (/= (preceding-char) ?_)
5800 (vhdl-end-p lim))
5801 (setq foundp 'end))
5802 ))
5803 )
5804 foundp
5805 ))
5806
5807(defun vhdl-forward-sexp (&optional count lim)
5808 "Move forward across one balanced expression (sexp).
5809With COUNT, do it that many times."
5810 (interactive "p")
5811 (let ((count (or count 1))
5812 (case-fold-search t)
5813 end-vec target)
5814 (save-excursion
5815 (while (> count 0)
5816 ;; skip whitespace
5817 (skip-chars-forward " \t\n")
5818 ;; Check for an unbalanced "end" keyword
5819 (if (and (looking-at vhdl-end-fwd-re)
5820 (/= (preceding-char) ?_)
3dcb36b7 5821 (not (vhdl-in-literal))
d2ddb974
KH
5822 (vhdl-end-p lim)
5823 (not (looking-at "else")))
5824 (error
3dcb36b7 5825 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
d2ddb974
KH
5826 ;; If the current keyword is a "begin" keyword, then find the
5827 ;; corresponding "end" keyword.
5828 (if (setq end-vec (vhdl-corresponding-end lim))
5829 (let (
5830 ;; end-re is the statement keyword to search for
5831 (end-re
5832 (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
5833 ;; column is either the statement keyword target column
5834 ;; or nil
5835 (column (aref end-vec 1))
5836 (eol (vhdl-point 'eol))
5837 foundp literal placeholder)
5838 ;; Look for the statement keyword.
5839 (while (and (not foundp)
5840 (re-search-forward end-re nil t)
5841 (setq placeholder (match-end 1))
5842 (goto-char (match-beginning 0)))
5843 ;; If we are in a literal, or not in the right target
5844 ;; column and not on the same line as the begin, then
5845 ;; try again.
5846 (if (or (and column
5847 (/= (current-indentation) column)
5848 (> (point) eol))
5849 (= (preceding-char) ?_)
3dcb36b7 5850 (setq literal (vhdl-in-literal)))
d2ddb974
KH
5851 (if (eq literal 'comment)
5852 (end-of-line)
5853 (forward-char))
5854 ;; An "else" keyword corresponds to both the opening brace
5855 ;; of the following sexp and the closing brace of the
5856 ;; previous sexp.
5857 (if (not (looking-at "else"))
5858 (goto-char placeholder))
5859 (setq foundp t))
5860 )
5861 (if (not foundp)
3dcb36b7 5862 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
d2ddb974
KH
5863 )
5864 ;; If the current keyword is not a "begin" keyword, then just
5865 ;; perform the normal forward-sexp.
5866 (forward-sexp)
5867 )
5868 (setq count (1- count))
5869 )
5870 (setq target (point)))
5871 (goto-char target)
5872 nil))
5873
5874(defun vhdl-backward-sexp (&optional count lim)
5875 "Move backward across one balanced expression (sexp).
5876With COUNT, do it that many times. LIM bounds any required backward
5877searches."
5878 (interactive "p")
5879 (let ((count (or count 1))
5880 (case-fold-search t)
5881 begin-vec target)
5882 (save-excursion
5883 (while (> count 0)
5884 ;; Perform the normal backward-sexp, unless we are looking at
5885 ;; "else" - an "else" keyword corresponds to both the opening brace
5886 ;; of the following sexp and the closing brace of the previous sexp.
5887 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
5888 (/= (preceding-char) ?_)
3dcb36b7 5889 (not (vhdl-in-literal)))
d2ddb974
KH
5890 nil
5891 (backward-sexp)
5892 (if (and (looking-at vhdl-begin-fwd-re)
5893 (/= (preceding-char) ?_)
3dcb36b7 5894 (not (vhdl-in-literal))
d2ddb974 5895 (vhdl-begin-p lim))
3dcb36b7 5896 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
d2ddb974
KH
5897 ;; If the current keyword is an "end" keyword, then find the
5898 ;; corresponding "begin" keyword.
5899 (if (and (setq begin-vec (vhdl-corresponding-begin lim))
5900 (/= (preceding-char) ?_))
5901 (let (
5902 ;; begin-re is the statement keyword to search for
5903 (begin-re
5904 (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
5905 ;; column is either the statement keyword target column
5906 ;; or nil
5907 (column (aref begin-vec 1))
5908 ;; internal-p controls where the statement keyword can
5909 ;; be found.
5910 (internal-p (aref begin-vec 3))
5911 (last-backward (point)) last-forward
5912 foundp literal keyword)
5913 ;; Look for the statement keyword.
5914 (while (and (not foundp)
5915 (re-search-backward begin-re lim t)
5916 (setq keyword
5917 (buffer-substring (match-beginning 1)
5918 (match-end 1))))
5919 ;; If we are in a literal or in the wrong column,
5920 ;; then try again.
5921 (if (or (and column
5922 (and (/= (current-indentation) column)
5923 ;; possibly accept current-column as
5924 ;; well as current-indentation.
5925 (or (not internal-p)
5926 (/= (current-column) column))))
5927 (= (preceding-char) ?_)
3dcb36b7 5928 (vhdl-in-literal))
d2ddb974
KH
5929 (backward-char)
5930 ;; If there is a supplementary keyword, then
5931 ;; search forward for it.
5932 (if (and (setq begin-re (aref begin-vec 2))
5933 (or (not (listp begin-re))
5934 ;; If begin-re is an alist, then find the
5935 ;; element corresponding to the actual
5936 ;; keyword that we found.
5937 (progn
5938 (setq begin-re
5939 (assoc keyword begin-re))
5940 (and begin-re
5941 (setq begin-re (cdr begin-re))))))
5942 (and
5943 (setq begin-re
5944 (concat "\\b\\(" begin-re "\\)\\b[^_]"))
5945 (save-excursion
5946 (setq last-forward (point))
5947 ;; Look for the supplementary keyword
5948 ;; (bounded by the backward search start
5949 ;; point).
5950 (while (and (not foundp)
5951 (re-search-forward begin-re
5952 last-backward t)
5953 (goto-char (match-beginning 1)))
5954 ;; If we are in a literal, then try again.
5955 (if (or (= (preceding-char) ?_)
5956 (setq literal
3dcb36b7 5957 (vhdl-in-literal)))
d2ddb974
KH
5958 (if (eq literal 'comment)
5959 (goto-char
5960 (min (vhdl-point 'eol) last-backward))
5961 (forward-char))
5962 ;; We have found the supplementary keyword.
5963 ;; Save the position of the keyword in foundp.
5964 (setq foundp (point)))
5965 )
5966 foundp)
5967 ;; If the supplementary keyword was found, then
5968 ;; move point to the supplementary keyword.
5969 (goto-char foundp))
5970 ;; If there was no supplementary keyword, then
5971 ;; point is already at the statement keyword.
5972 (setq foundp t)))
5973 ) ; end of the search for the statement keyword
5974 (if (not foundp)
3dcb36b7 5975 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
d2ddb974
KH
5976 ))
5977 (setq count (1- count))
5978 )
5979 (setq target (point)))
5980 (goto-char target)
5981 nil))
5982
5983(defun vhdl-backward-up-list (&optional count limit)
5984 "Move backward out of one level of blocks.
5985With argument, do this that many times."
5986 (interactive "p")
5987 (let ((count (or count 1))
5988 target)
5989 (save-excursion
5990 (while (> count 0)
5991 (if (looking-at vhdl-defun-re)
3dcb36b7 5992 (error "ERROR: Unbalanced blocks"))
d2ddb974
KH
5993 (vhdl-backward-to-block limit)
5994 (setq count (1- count)))
5995 (setq target (point)))
5996 (goto-char target)))
5997
5998(defun vhdl-end-of-defun (&optional count)
5999 "Move forward to the end of a VHDL defun."
6000 (interactive)
6001 (let ((case-fold-search t))
6002 (vhdl-beginning-of-defun)
5eabfe72 6003 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6004 (re-search-forward "\\bis\\b"))
6005 (vhdl-forward-sexp)))
6006
6007(defun vhdl-mark-defun ()
6008 "Put mark at end of this \"defun\", point at beginning."
6009 (interactive)
6010 (let ((case-fold-search t))
6011 (push-mark)
6012 (vhdl-beginning-of-defun)
6013 (push-mark)
5eabfe72 6014 (if (not (looking-at "block\\|process\\|procedural"))
d2ddb974
KH
6015 (re-search-forward "\\bis\\b"))
6016 (vhdl-forward-sexp)
6017 (exchange-point-and-mark)))
6018
6019(defun vhdl-beginning-of-libunit ()
6020 "Move backward to the beginning of a VHDL library unit.
6021Returns the location of the corresponding begin keyword, unless search
5eabfe72
KH
6022stops due to beginning or end of buffer.
6023Note that if point is between the \"libunit\" keyword and the
6024corresponding \"begin\" keyword, then that libunit will not be
6025recognised, and the search will continue backwards. If point is
6026at the \"begin\" keyword, then the defun will be recognised. The
6027returned point is at the first character of the \"libunit\" keyword."
d2ddb974
KH
6028 (let ((last-forward (point))
6029 (last-backward
6030 ;; Just in case we are actually sitting on the "begin"
6031 ;; keyword, allow for the keyword and an extra character,
6032 ;; as this will be used when looking forward for the
6033 ;; "begin" keyword.
6034 (save-excursion (forward-word 1) (1+ (point))))
6035 foundp literal placeholder)
6036 ;; Find the "libunit" keyword.
6037 (while (and (not foundp)
6038 (re-search-backward vhdl-libunit-re nil 'move))
6039 ;; If we are in a literal, or not at a real libunit, then try again.
6040 (if (or (= (preceding-char) ?_)
3dcb36b7 6041 (vhdl-in-literal)
d2ddb974
KH
6042 (not (vhdl-libunit-p)))
6043 (backward-char)
6044 ;; Find the corresponding "begin" keyword.
6045 (setq last-forward (point))
6046 (while (and (not foundp)
6047 (re-search-forward "\\bis\\b[^_]" last-backward t)
6048 (setq placeholder (match-beginning 0)))
6049 (if (or (= (preceding-char) ?_)
3dcb36b7 6050 (setq literal (vhdl-in-literal)))
d2ddb974
KH
6051 ;; It wasn't a real keyword, so keep searching.
6052 (if (eq literal 'comment)
6053 (goto-char
6054 (min (vhdl-point 'eol) last-backward))
6055 (forward-char))
6056 ;; We have found the begin keyword, loop will exit.
6057 (setq foundp placeholder)))
6058 ;; Go back to the libunit keyword
6059 (goto-char last-forward)))
6060 foundp))
6061
6062(defun vhdl-beginning-of-defun (&optional count)
6063 "Move backward to the beginning of a VHDL defun.
6064With argument, do it that many times.
6065Returns the location of the corresponding begin keyword, unless search
6066stops due to beginning or end of buffer."
6067 ;; Note that if point is between the "defun" keyword and the
6068 ;; corresponding "begin" keyword, then that defun will not be
6069 ;; recognised, and the search will continue backwards. If point is
6070 ;; at the "begin" keyword, then the defun will be recognised. The
6071 ;; returned point is at the first character of the "defun" keyword.
6072 (interactive "p")
6073 (let ((count (or count 1))
6074 (case-fold-search t)
6075 (last-forward (point))
6076 foundp)
6077 (while (> count 0)
6078 (setq foundp nil)
6079 (goto-char last-forward)
6080 (let ((last-backward
6081 ;; Just in case we are actually sitting on the "begin"
6082 ;; keyword, allow for the keyword and an extra character,
6083 ;; as this will be used when looking forward for the
6084 ;; "begin" keyword.
6085 (save-excursion (forward-word 1) (1+ (point))))
6086 begin-string literal)
6087 (while (and (not foundp)
6088 (re-search-backward vhdl-defun-re nil 'move))
6089 ;; If we are in a literal, then try again.
6090 (if (or (= (preceding-char) ?_)
3dcb36b7 6091 (vhdl-in-literal))
d2ddb974
KH
6092 (backward-char)
6093 (if (setq begin-string (vhdl-corresponding-defun))
6094 ;; This is a real defun keyword.
6095 ;; Find the corresponding "begin" keyword.
6096 ;; Look for the begin keyword.
6097 (progn
6098 ;; Save the search start point.
6099 (setq last-forward (point))
6100 (while (and (not foundp)
6101 (search-forward begin-string last-backward t))
6102 (if (or (= (preceding-char) ?_)
6103 (save-match-data
3dcb36b7 6104 (setq literal (vhdl-in-literal))))
d2ddb974
KH
6105 ;; It wasn't a real keyword, so keep searching.
6106 (if (eq literal 'comment)
6107 (goto-char
6108 (min (vhdl-point 'eol) last-backward))
6109 (forward-char))
6110 ;; We have found the begin keyword, loop will exit.
6111 (setq foundp (match-beginning 0)))
6112 )
6113 ;; Go back to the defun keyword
6114 (goto-char last-forward)) ; end search for begin keyword
6115 ))
6116 ) ; end of the search for the defun keyword
6117 )
6118 (setq count (1- count))
6119 )
6120 (vhdl-keep-region-active)
6121 foundp))
6122
6123(defun vhdl-beginning-of-statement (&optional count lim)
6124 "Go to the beginning of the innermost VHDL statement.
6125With prefix arg, go back N - 1 statements. If already at the
6126beginning of a statement then go to the beginning of the preceding
6127one. If within a string or comment, or next to a comment (only
6128whitespace between), move by sentences instead of statements.
6129
6130When called from a program, this function takes 2 optional args: the
6131prefix arg, and a buffer position limit which is the farthest back to
6132search."
6133 (interactive "p")
6134 (let ((count (or count 1))
6135 (case-fold-search t)
6136 (lim (or lim (point-min)))
6137 (here (point))
6138 state)
6139 (save-excursion
6140 (goto-char lim)
6141 (setq state (parse-partial-sexp (point) here nil nil)))
6142 (if (and (interactive-p)
6143 (or (nth 3 state)
6144 (nth 4 state)
6145 (looking-at (concat "[ \t]*" comment-start-skip))))
6146 (forward-sentence (- count))
6147 (while (> count 0)
6148 (vhdl-beginning-of-statement-1 lim)
6149 (setq count (1- count))))
6150 ;; its possible we've been left up-buf of lim
6151 (goto-char (max (point) lim))
6152 )
6153 (vhdl-keep-region-active))
6154
6155(defconst vhdl-e-o-s-re
6156 (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
6157
6158(defun vhdl-end-of-statement ()
6159 "Very simple implementation."
6160 (interactive)
6161 (re-search-forward vhdl-e-o-s-re))
6162
6163(defconst vhdl-b-o-s-re
6164 (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
6165 vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
6166
6167(defun vhdl-beginning-of-statement-1 (&optional lim)
5eabfe72
KH
6168 "Move to the start of the current statement, or the previous
6169statement if already at the beginning of one."
d2ddb974
KH
6170 (let ((lim (or lim (point-min)))
6171 (here (point))
6172 (pos (point))
6173 donep)
6174 ;; go backwards one balanced expression, but be careful of
6175 ;; unbalanced paren being reached
6176 (if (not (vhdl-safe (progn (backward-sexp) t)))
6177 (progn
6178 (backward-up-list 1)
6179 (forward-char)
6180 (vhdl-forward-syntactic-ws here)
6181 (setq donep t)))
6182 (while (and (not donep)
6183 (not (bobp))
6184 ;; look backwards for a statement boundary
6185 (re-search-backward vhdl-b-o-s-re lim 'move))
6186 (if (or (= (preceding-char) ?_)
3dcb36b7 6187 (vhdl-in-literal))
d2ddb974
KH
6188 (backward-char)
6189 (cond
6190 ;; If we are looking at an open paren, then stop after it
6191 ((eq (following-char) ?\()
6192 (forward-char)
6193 (vhdl-forward-syntactic-ws here)
6194 (setq donep t))
6195 ;; If we are looking at a close paren, then skip it
6196 ((eq (following-char) ?\))
6197 (forward-char)
6198 (setq pos (point))
6199 (backward-sexp)
6200 (if (< (point) lim)
6201 (progn (goto-char pos)
6202 (vhdl-forward-syntactic-ws here)
6203 (setq donep t))))
6204 ;; If we are looking at a semicolon, then stop
6205 ((eq (following-char) ?\;)
6206 (progn
6207 (forward-char)
6208 (vhdl-forward-syntactic-ws here)
6209 (setq donep t)))
6210 ;; If we are looking at a "begin", then stop
6211 ((and (looking-at vhdl-begin-fwd-re)
6212 (/= (preceding-char) ?_)
6213 (vhdl-begin-p nil))
6214 ;; If it's a leader "begin", then find the
6215 ;; right place
6216 (if (looking-at vhdl-leader-re)
6217 (save-excursion
6218 ;; set a default stop point at the begin
6219 (setq pos (point))
6220 ;; is the start point inside the leader area ?
6221 (goto-char (vhdl-end-of-leader))
6222 (vhdl-forward-syntactic-ws here)
6223 (if (< (point) here)
6224 ;; start point was not inside leader area
6225 ;; set stop point at word after leader
6226 (setq pos (point))))
6227 (forward-word 1)
6228 (vhdl-forward-syntactic-ws here)
6229 (setq pos (point)))
6230 (goto-char pos)
6231 (setq donep t))
6232 ;; If we are looking at a "statement", then stop
6233 ((and (looking-at vhdl-statement-fwd-re)
6234 (/= (preceding-char) ?_)
6235 (vhdl-statement-p nil))
6236 (setq donep t))
6237 ;; If we are looking at a case alternative key, then stop
5eabfe72
KH
6238 ((and (looking-at vhdl-case-alternative-re)
6239 (vhdl-case-alternative-p lim))
d2ddb974
KH
6240 (save-excursion
6241 ;; set a default stop point at the when
6242 (setq pos (point))
6243 ;; is the start point inside the case alternative key ?
6244 (looking-at vhdl-case-alternative-re)
6245 (goto-char (match-end 0))
6246 (vhdl-forward-syntactic-ws here)
6247 (if (< (point) here)
6248 ;; start point was not inside the case alternative key
6249 ;; set stop point at word after case alternative keyleader
6250 (setq pos (point))))
6251 (goto-char pos)
6252 (setq donep t))
6253 ;; Bogus find, continue
6254 (t
6255 (backward-char)))))
6256 ))
6257
6258;; Defuns for calculating the current syntactic state:
6259
6260(defun vhdl-get-library-unit (bod placeholder)
5eabfe72
KH
6261 "If there is an enclosing library unit at bod, with it's \"begin\"
6262keyword at placeholder, then return the library unit type."
d2ddb974
KH
6263 (let ((here (vhdl-point 'bol)))
6264 (if (save-excursion
6265 (goto-char placeholder)
6266 (vhdl-safe (vhdl-forward-sexp 1 bod))
6267 (<= here (point)))
6268 (save-excursion
6269 (goto-char bod)
6270 (cond
6271 ((looking-at "e") 'entity)
6272 ((looking-at "a") 'architecture)
6273 ((looking-at "c") 'configuration)
6274 ((looking-at "p")
6275 (save-excursion
6276 (goto-char bod)
6277 (forward-sexp)
6278 (vhdl-forward-syntactic-ws here)
6279 (if (looking-at "body\\b[^_]")
6280 'package-body 'package))))))
6281 ))
6282
6283(defun vhdl-get-block-state (&optional lim)
5eabfe72
KH
6284 "Finds and records all the closest opens.
6285lim is the furthest back we need to search (it should be the
6286previous libunit keyword)."
d2ddb974
KH
6287 (let ((here (point))
6288 (lim (or lim (point-min)))
6289 keyword sexp-start sexp-mid sexp-end
6290 preceding-sexp containing-sexp
6291 containing-begin containing-mid containing-paren)
6292 (save-excursion
6293 ;; Find the containing-paren, and use that as the limit
6294 (if (setq containing-paren
6295 (save-restriction
6296 (narrow-to-region lim (point))
6297 (vhdl-safe (scan-lists (point) -1 1))))
6298 (setq lim containing-paren))
6299 ;; Look backwards for "begin" and "end" keywords.
6300 (while (and (> (point) lim)
6301 (not containing-sexp))
6302 (setq keyword (vhdl-backward-to-block lim))
6303 (cond
6304 ((eq keyword 'begin)
6305 ;; Found a "begin" keyword
6306 (setq sexp-start (point))
6307 (setq sexp-mid (vhdl-corresponding-mid lim))
6308 (setq sexp-end (vhdl-safe
6309 (save-excursion
6310 (vhdl-forward-sexp 1 lim) (point))))
6311 (if (and sexp-end (<= sexp-end here))
6312 ;; we want to record this sexp, but we only want to
6313 ;; record the last-most of any of them before here
6314 (or preceding-sexp
6315 (setq preceding-sexp sexp-start))
6316 ;; we're contained in this sexp so put sexp-start on
6317 ;; front of list
6318 (setq containing-sexp sexp-start)
6319 (setq containing-mid sexp-mid)
6320 (setq containing-begin t)))
6321 ((eq keyword 'end)
6322 ;; Found an "end" keyword
6323 (forward-sexp)
6324 (setq sexp-end (point))
6325 (setq sexp-mid nil)
6326 (setq sexp-start
6327 (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
6328 (progn (backward-sexp) (point))))
6329 ;; we want to record this sexp, but we only want to
6330 ;; record the last-most of any of them before here
6331 (or preceding-sexp
6332 (setq preceding-sexp sexp-start)))
6333 )))
6334 ;; Check if the containing-paren should be the containing-sexp
6335 (if (and containing-paren
6336 (or (null containing-sexp)
6337 (< containing-sexp containing-paren)))
6338 (setq containing-sexp containing-paren
6339 preceding-sexp nil
6340 containing-begin nil
6341 containing-mid nil))
6342 (vector containing-sexp preceding-sexp containing-begin containing-mid)
6343 ))
6344
6345
6346(defconst vhdl-s-c-a-re
6347 (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
6348
6349(defun vhdl-skip-case-alternative (&optional lim)
5eabfe72
KH
6350 "Skip forward over case/when bodies, with optional maximal
6351limit. If no next case alternative is found, nil is returned and point
6352is not moved."
d2ddb974
KH
6353 (let ((lim (or lim (point-max)))
6354 (here (point))
6355 donep foundp)
6356 (while (and (< (point) lim)
6357 (not donep))
6358 (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
6359 (save-match-data
6360 (not (vhdl-in-literal)))
6361 (/= (match-beginning 0) here))
6362 (progn
6363 (goto-char (match-beginning 0))
6364 (cond
6365 ((and (looking-at "case")
6366 (re-search-forward "\\bis[^_]" lim t))
6367 (backward-sexp)
6368 (vhdl-forward-sexp))
6369 (t
6370 (setq donep t
6371 foundp t))))))
6372 (if (not foundp)
6373 (goto-char here))
6374 foundp))
6375
6376(defun vhdl-backward-skip-label (&optional lim)
5eabfe72
KH
6377 "Skip backward over a label, with optional maximal
6378limit. If label is not found, nil is returned and point
6379is not moved."
d2ddb974
KH
6380 (let ((lim (or lim (point-min)))
6381 placeholder)
6382 (if (save-excursion
6383 (vhdl-backward-syntactic-ws lim)
6384 (and (eq (preceding-char) ?:)
6385 (progn
6386 (backward-sexp)
6387 (setq placeholder (point))
6388 (looking-at vhdl-label-key))))
6389 (goto-char placeholder))
6390 ))
6391
6392(defun vhdl-forward-skip-label (&optional lim)
5eabfe72
KH
6393 "Skip forward over a label, with optional maximal
6394limit. If label is not found, nil is returned and point
6395is not moved."
d2ddb974
KH
6396 (let ((lim (or lim (point-max))))
6397 (if (looking-at vhdl-label-key)
6398 (progn
6399 (goto-char (match-end 0))
6400 (vhdl-forward-syntactic-ws lim)))
6401 ))
6402
6403(defun vhdl-get-syntactic-context ()
5eabfe72 6404 "Guess the syntactic description of the current line of VHDL code."
d2ddb974
KH
6405 (save-excursion
6406 (save-restriction
6407 (beginning-of-line)
6408 (let* ((indent-point (point))
6409 (case-fold-search t)
6410 vec literal containing-sexp preceding-sexp
6411 containing-begin containing-mid containing-leader
6412 char-before-ip char-after-ip begin-after-ip end-after-ip
6413 placeholder lim library-unit
6414 )
6415
6416 ;; Reset the syntactic context
6417 (setq vhdl-syntactic-context nil)
6418
6419 (save-excursion
6420 ;; Move to the start of the previous library unit, and
6421 ;; record the position of the "begin" keyword.
6422 (setq placeholder (vhdl-beginning-of-libunit))
6423 ;; The position of the "libunit" keyword gives us a gross
6424 ;; limit point.
6425 (setq lim (point))
6426 )
6427
6428 ;; If there is a previous library unit, and we are enclosed by
6429 ;; it, then set the syntax accordingly.
6430 (and placeholder
6431 (setq library-unit (vhdl-get-library-unit lim placeholder))
6432 (vhdl-add-syntax library-unit lim))
6433
6434 ;; Find the surrounding state.
6435 (if (setq vec (vhdl-get-block-state lim))
6436 (progn
6437 (setq containing-sexp (aref vec 0))
6438 (setq preceding-sexp (aref vec 1))
6439 (setq containing-begin (aref vec 2))
6440 (setq containing-mid (aref vec 3))
6441 ))
6442
6443 ;; set the limit on the farthest back we need to search
6444 (setq lim (if containing-sexp
6445 (save-excursion
6446 (goto-char containing-sexp)
6447 ;; set containing-leader if required
6448 (if (looking-at vhdl-leader-re)
6449 (setq containing-leader (vhdl-end-of-leader)))
6450 (vhdl-point 'bol))
6451 (point-min)))
6452
6453 ;; cache char before and after indent point, and move point to
6454 ;; the most likely position to perform the majority of tests
6455 (goto-char indent-point)
6456 (skip-chars-forward " \t")
3dcb36b7 6457 (setq literal (vhdl-in-literal))
d2ddb974
KH
6458 (setq char-after-ip (following-char))
6459 (setq begin-after-ip (and
6460 (not literal)
6461 (looking-at vhdl-begin-fwd-re)
6462 (vhdl-begin-p)))
6463 (setq end-after-ip (and
6464 (not literal)
6465 (looking-at vhdl-end-fwd-re)
6466 (vhdl-end-p)))
6467 (vhdl-backward-syntactic-ws lim)
6468 (setq char-before-ip (preceding-char))
6469 (goto-char indent-point)
6470 (skip-chars-forward " \t")
6471
6472 ;; now figure out syntactic qualities of the current line
6473 (cond
6474 ;; CASE 1: in a string or comment.
6475 ((memq literal '(string comment))
6476 (vhdl-add-syntax literal (vhdl-point 'bopl)))
6477 ;; CASE 2: Line is at top level.
6478 ((null containing-sexp)
6479 ;; Find the point to which indentation will be relative
6480 (save-excursion
6481 (if (null preceding-sexp)
6482 ;; CASE 2X.1
6483 ;; no preceding-sexp -> use the preceding statement
6484 (vhdl-beginning-of-statement-1 lim)
6485 ;; CASE 2X.2
6486 ;; if there is a preceding-sexp then indent relative to it
6487 (goto-char preceding-sexp)
6488 ;; if not at boi, then the block-opening keyword is
6489 ;; probably following a label, so we need a different
6490 ;; relpos
6491 (if (/= (point) (vhdl-point 'boi))
6492 ;; CASE 2X.3
6493 (vhdl-beginning-of-statement-1 lim)))
6494 ;; v-b-o-s could have left us at point-min
6495 (and (bobp)
6496 ;; CASE 2X.4
6497 (vhdl-forward-syntactic-ws indent-point))
6498 (setq placeholder (point)))
6499 (cond
6500 ;; CASE 2A : we are looking at a block-open
6501 (begin-after-ip
6502 (vhdl-add-syntax 'block-open placeholder))
6503 ;; CASE 2B: we are looking at a block-close
6504 (end-after-ip
6505 (vhdl-add-syntax 'block-close placeholder))
6506 ;; CASE 2C: we are looking at a top-level statement
6507 ((progn
6508 (vhdl-backward-syntactic-ws lim)
6509 (or (bobp)
6510 (= (preceding-char) ?\;)))
6511 (vhdl-add-syntax 'statement placeholder))
6512 ;; CASE 2D: we are looking at a top-level statement-cont
6513 (t
6514 (vhdl-beginning-of-statement-1 lim)
6515 ;; v-b-o-s could have left us at point-min
6516 (and (bobp)
6517 ;; CASE 2D.1
6518 (vhdl-forward-syntactic-ws indent-point))
6519 (vhdl-add-syntax 'statement-cont (point)))
6520 )) ; end CASE 2
6521 ;; CASE 3: line is inside parentheses. Most likely we are
6522 ;; either in a subprogram argument (interface) list, or a
6523 ;; continued expression containing parentheses.
6524 ((null containing-begin)
6525 (vhdl-backward-syntactic-ws containing-sexp)
6526 (cond
6527 ;; CASE 3A: we are looking at the arglist closing paren
6528 ((eq char-after-ip ?\))
6529 (goto-char containing-sexp)
6530 (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
6531 ;; CASE 3B: we are looking at the first argument in an empty
6532 ;; argument list.
6533 ((eq char-before-ip ?\()
6534 (goto-char containing-sexp)
6535 (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
6536 ;; CASE 3C: we are looking at an arglist continuation line,
6537 ;; but the preceding argument is on the same line as the
6538 ;; opening paren. This case includes multi-line
6539 ;; expression paren groupings.
6540 ((and (save-excursion
6541 (goto-char (1+ containing-sexp))
6542 (skip-chars-forward " \t")
6543 (not (eolp))
6544 (not (looking-at "--")))
6545 (save-excursion
6546 (vhdl-beginning-of-statement-1 containing-sexp)
6547 (skip-chars-backward " \t(")
6548 (<= (point) containing-sexp)))
6549 (goto-char containing-sexp)
6550 (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
6551 ;; CASE 3D: we are looking at just a normal arglist
6552 ;; continuation line
6553 (t (vhdl-beginning-of-statement-1 containing-sexp)
6554 (vhdl-forward-syntactic-ws indent-point)
6555 (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
6556 ))
6557 ;; CASE 4: A block mid open
6558 ((and begin-after-ip
6559 (looking-at containing-mid))
6560 (goto-char containing-sexp)
6561 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6562 (if (looking-at vhdl-trailer-re)
6563 ;; CASE 4.1
6564 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6565 (vhdl-backward-skip-label (vhdl-point 'boi))
6566 (vhdl-add-syntax 'block-open (point)))
6567 ;; CASE 5: block close brace
6568 (end-after-ip
6569 (goto-char containing-sexp)
6570 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6571 (if (looking-at vhdl-trailer-re)
6572 ;; CASE 5.1
6573 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6574 (vhdl-backward-skip-label (vhdl-point 'boi))
6575 (vhdl-add-syntax 'block-close (point)))
6576 ;; CASE 6: A continued statement
6577 ((and (/= char-before-ip ?\;)
6578 ;; check it's not a trailer begin keyword, or a begin
6579 ;; keyword immediately following a label.
6580 (not (and begin-after-ip
6581 (or (looking-at vhdl-trailer-re)
6582 (save-excursion
6583 (vhdl-backward-skip-label containing-sexp)))))
6584 ;; check it's not a statement keyword
6585 (not (and (looking-at vhdl-statement-fwd-re)
6586 (vhdl-statement-p)))
6587 ;; see if the b-o-s is before the indent point
6588 (> indent-point
6589 (save-excursion
6590 (vhdl-beginning-of-statement-1 containing-sexp)
6591 ;; If we ended up after a leader, then this will
6592 ;; move us forward to the start of the first
6593 ;; statement. Note that a containing sexp here is
6594 ;; always a keyword, not a paren, so this will
6595 ;; have no effect if we hit the containing-sexp.
6596 (vhdl-forward-syntactic-ws indent-point)
6597 (setq placeholder (point))))
6598 ;; check it's not a block-intro
6599 (/= placeholder containing-sexp)
6600 ;; check it's not a case block-intro
6601 (save-excursion
6602 (goto-char placeholder)
6603 (or (not (looking-at vhdl-case-alternative-re))
6604 (> (match-end 0) indent-point))))
6605 ;; Make placeholder skip a label, but only if it puts us
6606 ;; before the indent point at the start of a line.
6607 (let ((new placeholder))
6608 (if (and (> indent-point
6609 (save-excursion
6610 (goto-char placeholder)
6611 (vhdl-forward-skip-label indent-point)
6612 (setq new (point))))
6613 (save-excursion
6614 (goto-char new)
6615 (eq new (progn (back-to-indentation) (point)))))
6616 (setq placeholder new)))
6617 (vhdl-add-syntax 'statement-cont placeholder)
6618 (if begin-after-ip
6619 (vhdl-add-syntax 'block-open)))
6620 ;; Statement. But what kind?
6621 ;; CASE 7: A case alternative key
6622 ((and (looking-at vhdl-case-alternative-re)
6623 (vhdl-case-alternative-p containing-sexp))
6624 ;; for a case alternative key, we set relpos to the first
6625 ;; non-whitespace char on the line containing the "case"
6626 ;; keyword.
6627 (goto-char containing-sexp)
6628 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6629 (if (looking-at vhdl-trailer-re)
6630 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6631 (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
6632 ;; CASE 8: statement catchall
6633 (t
6634 ;; we know its a statement, but we need to find out if it is
6635 ;; the first statement in a block
6636 (if containing-leader
6637 (goto-char containing-leader)
6638 (goto-char containing-sexp)
6639 ;; Note that a containing sexp here is always a keyword,
6640 ;; not a paren, so skip over the keyword.
6641 (forward-sexp))
6642 ;; move to the start of the first statement
6643 (vhdl-forward-syntactic-ws indent-point)
6644 (setq placeholder (point))
6645 ;; we want to ignore case alternatives keys when skipping forward
6646 (let (incase-p)
6647 (while (looking-at vhdl-case-alternative-re)
6648 (setq incase-p (point))
6649 ;; we also want to skip over the body of the
6650 ;; case/when statement if that doesn't put us at
6651 ;; after the indent-point
6652 (while (vhdl-skip-case-alternative indent-point))
6653 ;; set up the match end
6654 (looking-at vhdl-case-alternative-re)
6655 (goto-char (match-end 0))
6656 ;; move to the start of the first case alternative statement
6657 (vhdl-forward-syntactic-ws indent-point)
6658 (setq placeholder (point)))
6659 (cond
6660 ;; CASE 8A: we saw a case/when statement so we must be
6661 ;; in a switch statement. find out if we are at the
6662 ;; statement just after a case alternative key
6663 ((and incase-p
6664 (= (point) indent-point))
6665 ;; relpos is the "when" keyword
6666 (vhdl-add-syntax 'statement-case-intro incase-p))
6667 ;; CASE 8B: any old statement
6668 ((< (point) indent-point)
6669 ;; relpos is the first statement of the block
6670 (vhdl-add-syntax 'statement placeholder)
6671 (if begin-after-ip
6672 (vhdl-add-syntax 'block-open)))
6673 ;; CASE 8C: first statement in a block
6674 (t
6675 (goto-char containing-sexp)
6676 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6677 (if (looking-at vhdl-trailer-re)
6678 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
6679 (vhdl-backward-skip-label (vhdl-point 'boi))
6680 (vhdl-add-syntax 'statement-block-intro (point))
6681 (if begin-after-ip
6682 (vhdl-add-syntax 'block-open)))
6683 )))
6684 )
6685
6686 ;; now we need to look at any modifiers
6687 (goto-char indent-point)
6688 (skip-chars-forward " \t")
6689 (if (looking-at "--")
6690 (vhdl-add-syntax 'comment))
6691 ;; return the syntax
6692 vhdl-syntactic-context))))
6693
6694;; Standard indentation line-ups:
6695
6696(defun vhdl-lineup-arglist (langelem)
5eabfe72
KH
6697 "Lineup the current arglist line with the arglist appearing just
6698after the containing paren which starts the arglist."
d2ddb974
KH
6699 (save-excursion
6700 (let* ((containing-sexp
6701 (save-excursion
6702 ;; arglist-cont-nonempty gives relpos ==
6703 ;; to boi of containing-sexp paren. This
6704 ;; is good when offset is +, but bad
6705 ;; when it is vhdl-lineup-arglist, so we
6706 ;; have to special case a kludge here.
6707 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
6708 (progn
6709 (beginning-of-line)
6710 (backward-up-list 1)
6711 (skip-chars-forward " \t" (vhdl-point 'eol)))
6712 (goto-char (cdr langelem)))
6713 (point)))
6714 (cs-curcol (save-excursion
6715 (goto-char (cdr langelem))
6716 (current-column))))
6717 (if (save-excursion
6718 (beginning-of-line)
6719 (looking-at "[ \t]*)"))
6720 (progn (goto-char (match-end 0))
6721 (backward-sexp)
6722 (forward-char)
6723 (vhdl-forward-syntactic-ws)
6724 (- (current-column) cs-curcol))
6725 (goto-char containing-sexp)
6726 (or (eolp)
6727 (let ((eol (vhdl-point 'eol))
6728 (here (progn
6729 (forward-char)
6730 (skip-chars-forward " \t")
6731 (point))))
6732 (vhdl-forward-syntactic-ws)
6733 (if (< (point) eol)
6734 (goto-char here))))
6735 (- (current-column) cs-curcol)
6736 ))))
6737
6738(defun vhdl-lineup-arglist-intro (langelem)
5eabfe72 6739 "Lineup an arglist-intro line to just after the open paren."
d2ddb974
KH
6740 (save-excursion
6741 (let ((cs-curcol (save-excursion
6742 (goto-char (cdr langelem))
6743 (current-column)))
6744 (ce-curcol (save-excursion
6745 (beginning-of-line)
6746 (backward-up-list 1)
6747 (skip-chars-forward " \t" (vhdl-point 'eol))
6748 (current-column))))
6749 (- ce-curcol cs-curcol -1))))
6750
6751(defun vhdl-lineup-comment (langelem)
5eabfe72
KH
6752 "Support old behavior for comment indentation. We look at
6753vhdl-comment-only-line-offset to decide how to indent comment
6754only-lines."
d2ddb974
KH
6755 (save-excursion
6756 (back-to-indentation)
6757 ;; at or to the right of comment-column
6758 (if (>= (current-column) comment-column)
6759 (vhdl-comment-indent)
6760 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
6761 (if (not (bolp))
6762 (or (car-safe vhdl-comment-only-line-offset)
6763 vhdl-comment-only-line-offset)
6764 (or (cdr-safe vhdl-comment-only-line-offset)
6765 (car-safe vhdl-comment-only-line-offset)
5eabfe72 6766 -1000 ;jam it against the left side
d2ddb974
KH
6767 )))))
6768
6769(defun vhdl-lineup-statement-cont (langelem)
5eabfe72 6770 "Line up statement-cont after the assignment operator."
d2ddb974
KH
6771 (save-excursion
6772 (let* ((relpos (cdr langelem))
6773 (assignp (save-excursion
6774 (goto-char (vhdl-point 'boi))
6775 (and (re-search-forward "\\(<\\|:\\)="
6776 (vhdl-point 'eol) t)
6777 (- (point) (vhdl-point 'boi)))))
6778 (curcol (progn
6779 (goto-char relpos)
6780 (current-column)))
6781 foundp)
6782 (while (and (not foundp)
6783 (< (point) (vhdl-point 'eol)))
6784 (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
3dcb36b7 6785 (if (vhdl-in-literal)
d2ddb974
KH
6786 (forward-char)
6787 (if (= (preceding-char) ?\()
6788 ;; skip over any parenthesized expressions
6789 (goto-char (min (vhdl-point 'eol)
6790 (scan-lists (point) 1 1)))
6791 ;; found an assignment operator (not at eol)
6792 (setq foundp (not (looking-at "\\s-*$"))))))
6793 (if (not foundp)
6794 ;; there's no assignment operator on the line
6795 vhdl-basic-offset
6796 ;; calculate indentation column after assign and ws, unless
6797 ;; our line contains an assignment operator
6798 (if (not assignp)
6799 (progn
6800 (forward-char)
6801 (skip-chars-forward " \t")
6802 (setq assignp 0)))
6803 (- (current-column) assignp curcol))
6804 )))
6805
5eabfe72 6806;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 6807;; Progress reporting
d2ddb974 6808
3dcb36b7
JB
6809(defvar vhdl-progress-info nil
6810 "Array variable for progress information: 0 begin, 1 end, 2 time.")
5eabfe72 6811
3dcb36b7
JB
6812(defun vhdl-update-progress-info (string pos)
6813 "Update progress information."
6814 (when (and vhdl-progress-info (not noninteractive)
6815 (< vhdl-progress-interval
6816 (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
6817 (message (concat string "... (%2d%s)")
6818 (/ (* 100 (- pos (aref vhdl-progress-info 0)))
6819 (- (aref vhdl-progress-info 1)
6820 (aref vhdl-progress-info 0))) "%")
6821 (aset vhdl-progress-info 2 (nth 1 (current-time)))))
5eabfe72 6822
3dcb36b7
JB
6823;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6824;; Indentation commands
5eabfe72
KH
6825
6826(defun vhdl-electric-tab (&optional prefix-arg)
6827 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7
JB
6828else if right of non whitespace on line then insert tab,
6829else if last command was a tab or return then dedent one step or if a comment
6830toggle between normal indent and inline comment indent,
d2ddb974
KH
6831else indent `correctly'."
6832 (interactive "*P")
3dcb36b7
JB
6833 (vhdl-prepare-search-2
6834 (cond
6835 ;; expand word
6836 ((= (char-syntax (preceding-char)) ?w)
6837 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6838 (case-replace nil)
6839 (hippie-expand-only-buffers
6840 (or (and (boundp 'hippie-expand-only-buffers)
6841 hippie-expand-only-buffers)
6842 '(vhdl-mode))))
6843 (vhdl-expand-abbrev prefix-arg)))
6844 ;; expand parenthesis
6845 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
6846 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
6847 (case-replace nil))
6848 (vhdl-expand-paren prefix-arg)))
6849 ;; insert tab
6850 ((> (current-column) (current-indentation))
6851 (insert-tab))
6852 ;; toggle comment indent
6853 ((and (looking-at "--")
6854 (or (eq last-command 'vhdl-electric-tab)
6855 (eq last-command 'vhdl-electric-return)))
6856 (cond ((= (current-indentation) 0) ; no indent
6857 (indent-to 1)
6858 (indent-according-to-mode))
6859 ((< (current-indentation) comment-column) ; normal indent
6860 (indent-to comment-column)
6861 (indent-according-to-mode))
6862 (t ; inline comment indent
6863 (kill-line -0))))
6864 ;; dedent
6865 ((and (>= (current-indentation) vhdl-basic-offset)
6866 (or (eq last-command 'vhdl-electric-tab)
6867 (eq last-command 'vhdl-electric-return)))
6868 (backward-delete-char-untabify vhdl-basic-offset nil))
6869 ;; indent line
6870 (t (indent-according-to-mode)))
5eabfe72
KH
6871 (setq this-command 'vhdl-electric-tab)))
6872
6873(defun vhdl-electric-return ()
d2ddb974
KH
6874 "newline-and-indent or indent-new-comment-line if in comment and preceding
6875character is a space."
6876 (interactive)
6877 (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
6878 (indent-new-comment-line)
3dcb36b7
JB
6879 (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
6880 (vhdl-fix-case-word -1))
5eabfe72
KH
6881 (newline-and-indent)))
6882
d2ddb974 6883(defun vhdl-indent-line ()
5eabfe72 6884 "Indent the current line as VHDL code. Returns the amount of
d2ddb974
KH
6885indentation change."
6886 (interactive)
3dcb36b7 6887 (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
d2ddb974 6888 (pos (- (point-max) (point)))
3dcb36b7
JB
6889 (indent
6890 (if syntax
6891 ;; indent syntax-based
6892 (if (and (eq (caar syntax) 'comment)
6893 (>= (vhdl-get-offset (car syntax)) comment-column))
6894 ;; special case: comments at or right of comment-column
6895 (vhdl-get-offset (car syntax))
6896 (apply '+ (mapcar 'vhdl-get-offset syntax)))
6897 ;; indent like previous nonblank line
6898 (save-excursion (beginning-of-line)
6899 (re-search-backward "^[^\n]" nil t)
6900 (current-indentation))))
5eabfe72 6901 (shift-amt (- indent (current-indentation))))
d2ddb974
KH
6902 (and vhdl-echo-syntactic-information-p
6903 (message "syntax: %s, indent= %d" syntax indent))
5eabfe72 6904 (unless (zerop shift-amt)
d2ddb974
KH
6905 (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
6906 (beginning-of-line)
6907 (indent-to indent))
6908 (if (< (point) (vhdl-point 'boi))
6909 (back-to-indentation)
6910 ;; If initial point was within line's indentation, position after
6911 ;; the indentation. Else stay at same point in text.
5eabfe72
KH
6912 (when (> (- (point-max) pos) (point))
6913 (goto-char (- (point-max) pos))))
d2ddb974 6914 (run-hooks 'vhdl-special-indent-hook)
3dcb36b7 6915 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
d2ddb974
KH
6916 shift-amt))
6917
3dcb36b7 6918(defun vhdl-indent-region (beg end column)
5eabfe72
KH
6919 "Indent region as VHDL code.
6920Adds progress reporting to `indent-region'."
6921 (interactive "r\nP")
3dcb36b7
JB
6922 (when vhdl-progress-interval
6923 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
6924 (count-lines (point-min) end) 0)))
6925 (indent-region beg end column)
5eabfe72
KH
6926 (when vhdl-progress-interval (message "Indenting...done"))
6927 (setq vhdl-progress-info nil))
d2ddb974 6928
3dcb36b7
JB
6929(defun vhdl-indent-buffer ()
6930 "Indent whole buffer as VHDL code.
6931Calls `indent-region' for whole buffer and adds progress reporting."
6932 (interactive)
6933 (vhdl-indent-region (point-min) (point-max) nil))
6934
6935(defun vhdl-indent-group ()
6936 "Indent group of lines between empty lines."
6937 (interactive)
6938 (let ((beg (save-excursion
6939 (if (re-search-backward vhdl-align-group-separate nil t)
6940 (point-marker)
6941 (point-min-marker))))
6942 (end (save-excursion
6943 (if (re-search-forward vhdl-align-group-separate nil t)
6944 (point-marker)
6945 (point-max-marker)))))
6946 (vhdl-indent-region beg end nil)))
6947
d2ddb974
KH
6948(defun vhdl-indent-sexp (&optional endpos)
6949 "Indent each line of the list starting just after point.
6950If optional arg ENDPOS is given, indent each line, stopping when
6951ENDPOS is encountered."
6952 (interactive)
6953 (save-excursion
6954 (let ((beg (point))
5eabfe72 6955 (end (progn (vhdl-forward-sexp nil endpos) (point))))
d2ddb974
KH
6956 (indent-region beg end nil))))
6957
5eabfe72 6958;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
6959;; Miscellaneous commands
6960
6961(defun vhdl-show-syntactic-information ()
6962 "Show syntactic information for current line."
6963 (interactive)
3dcb36b7 6964 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
d2ddb974
KH
6965 (vhdl-keep-region-active))
6966
6967;; Verification and regression functions:
6968
6969(defun vhdl-regress-line (&optional arg)
6970 "Check syntactic information for current line."
6971 (interactive "P")
6972 (let ((expected (save-excursion
6973 (end-of-line)
5eabfe72
KH
6974 (when (search-backward " -- ((" (vhdl-point 'bol) t)
6975 (forward-char 4)
6976 (read (current-buffer)))))
d2ddb974
KH
6977 (actual (vhdl-get-syntactic-context))
6978 (expurgated))
6979 ;; remove the library unit symbols
6980 (mapcar
6981 (function
6982 (lambda (elt)
6983 (if (memq (car elt) '(entity configuration package
6984 package-body architecture))
6985 nil
6986 (setq expurgated (append expurgated (list elt))))))
6987 actual)
6988 (if (and (not arg) expected (listp expected))
6989 (if (not (equal expected expurgated))
3dcb36b7 6990 (error "ERROR: Should be: %s, is: %s" expected expurgated))
d2ddb974
KH
6991 (save-excursion
6992 (beginning-of-line)
5eabfe72
KH
6993 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
6994 (end-of-line)
6995 (if (search-backward " -- ((" (vhdl-point 'bol) t)
6996 (kill-line))
6997 (insert " -- ")
6998 (insert (format "%s" expurgated))))))
d2ddb974
KH
6999 (vhdl-keep-region-active))
7000
7001
5eabfe72
KH
7002;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7003;;; Alignment, whitespace fixup, beautifying
7004;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7005
3dcb36b7 7006(defconst vhdl-align-alist
d2ddb974
KH
7007 '(
7008 ;; after some keywords
3dcb36b7
JB
7009 (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
7010 "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
d2ddb974 7011 ;; before ':'
5eabfe72 7012 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
d2ddb974 7013 ;; after direction specifications
5eabfe72
KH
7014 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7015 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7016 ;; before "==", ":=", "=>", and "<="
3dcb36b7 7017 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
5eabfe72 7018 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
3dcb36b7 7019 (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
d2ddb974
KH
7020 ;; before some keywords
7021 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
d2ddb974
KH
7022 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7023 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
3dcb36b7
JB
7024 ;; before "=>" since "when/else ... =>" can occur
7025 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
d2ddb974 7026 )
5eabfe72 7027 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
d2ddb974
KH
7028It is searched in order. If REGEXP is found anywhere in the first
7029line of a region to be aligned, ALIGN-PATTERN will be used for that
7030region. ALIGN-PATTERN must include the whitespace to be expanded or
5eabfe72
KH
7031contracted. It may also provide regexps for the text surrounding the
7032whitespace. SUBEXP specifies which sub-expression of
d2ddb974
KH
7033ALIGN-PATTERN matches the white space to be expanded/contracted.")
7034
3dcb36b7
JB
7035;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7036;; Align code
7037
d2ddb974
KH
7038(defvar vhdl-align-try-all-clauses t
7039 "If REGEXP is not found on the first line of the region that clause
5eabfe72 7040is ignored. If this variable is non-nil, then the clause is tried anyway.")
d2ddb974 7041
3dcb36b7
JB
7042(defun vhdl-do-group (function &optional spacing)
7043 "Apply FUNCTION on group of lines between empty lines."
7044 (let
7045 ;; search for group beginning
7046 ((beg (save-excursion
7047 (if (re-search-backward vhdl-align-group-separate nil t)
7048 (progn (beginning-of-line 2) (back-to-indentation) (point))
7049 (point-min))))
7050 ;; search for group end
7051 (end (save-excursion
7052 (if (re-search-forward vhdl-align-group-separate nil t)
7053 (progn (beginning-of-line) (point))
7054 (point-max)))))
7055 ;; run FUNCTION
7056 (funcall function beg end spacing)))
7057
7058(defun vhdl-do-list (function &optional spacing)
7059 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7060parentheses."
7061 (let (beg end)
7062 (save-excursion
7063 ;; search for beginning of balanced group of parentheses
7064 (setq beg (vhdl-re-search-backward "[()]" nil t))
7065 (while (looking-at ")")
7066 (forward-char) (backward-sexp)
7067 (setq beg (vhdl-re-search-backward "[()]" nil t)))
7068 ;; search for end of balanced group of parentheses
7069 (when beg
7070 (forward-list)
7071 (setq end (point))
7072 (goto-char (1+ beg))
7073 (skip-chars-forward " \t\n")
7074 (setq beg (point))))
7075 ;; run FUNCTION
7076 (if beg
7077 (funcall function beg end spacing)
7078 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7079
7080(defun vhdl-do-same-indent (function &optional spacing)
7081 "Apply FUNCTION to block of lines with same indent."
7082 (let ((indent (current-indentation))
7083 beg end)
7084 ;; search for first line with same indent
7085 (save-excursion
7086 (while (and (not (bobp))
7087 (or (looking-at "^\\s-*\\(--.*\\)?$")
7088 (= (current-indentation) indent)))
7089 (unless (looking-at "^\\s-*$")
7090 (back-to-indentation) (setq beg (point)))
7091 (beginning-of-line -0)))
7092 ;; search for last line with same indent
7093 (save-excursion
7094 (while (and (not (eobp))
7095 (or (looking-at "^\\s-*\\(--.*\\)?$")
7096 (= (current-indentation) indent)))
7097 (if (looking-at "^\\s-*$")
7098 (beginning-of-line 2)
7099 (beginning-of-line 2)
7100 (setq end (point)))))
7101 ;; run FUNCTION
7102 (funcall function beg end spacing)))
7103
7104(defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
d2ddb974 7105 "Attempt to align a range of lines based on the content of the
5eabfe72
KH
7106lines. The definition of `alignment-list' determines the matching
7107order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7108is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
d2ddb974
KH
7109indentation is done before aligning."
7110 (interactive "r\np")
5eabfe72
KH
7111 (setq alignment-list (or alignment-list vhdl-align-alist))
7112 (setq spacing (or spacing 1))
d2ddb974
KH
7113 (save-excursion
7114 (let (bol indent)
7115 (goto-char end)
7116 (setq end (point-marker))
7117 (goto-char begin)
5eabfe72 7118 (setq bol (setq begin (progn (beginning-of-line) (point))))
3dcb36b7 7119; (untabify bol end)
5eabfe72
KH
7120 (when indent
7121 (indent-region bol end nil))))
3dcb36b7
JB
7122 (let ((copy (copy-alist alignment-list)))
7123 (vhdl-prepare-search-2
5eabfe72
KH
7124 (while copy
7125 (save-excursion
7126 (goto-char begin)
7127 (let (element
7128 (eol (save-excursion (progn (end-of-line) (point)))))
7129 (setq element (nth 0 copy))
7130 (when (and (or (and (listp (car element))
7131 (memq major-mode (car element)))
7132 (eq major-mode (car element)))
7133 (or vhdl-align-try-all-clauses
7134 (re-search-forward (car (cdr element)) eol t)))
3dcb36b7 7135 (vhdl-align-region-2 begin end (car (cdr (cdr element)))
5eabfe72
KH
7136 (car (cdr (cdr (cdr element)))) spacing))
7137 (setq copy (cdr copy))))))))
7138
3dcb36b7 7139(defun vhdl-align-region-2 (begin end match &optional substr spacing)
d2ddb974
KH
7140 "Align a range of lines from BEGIN to END. The regular expression
7141MATCH must match exactly one fields: the whitespace to be
7142contracted/expanded. The alignment column will equal the
7143rightmost column of the widest whitespace block. SPACING is
7144the amount of extra spaces to add to the calculated maximum required.
7145SPACING defaults to 1 so that at least one space is inserted after
7146the token in MATCH."
5eabfe72
KH
7147 (setq spacing (or spacing 1))
7148 (setq substr (or substr 1))
d2ddb974
KH
7149 (save-excursion
7150 (let (distance (max 0) (lines 0) bol eol width)
7151 ;; Determine the greatest whitespace distance to the alignment
7152 ;; character
7153 (goto-char begin)
7154 (setq eol (progn (end-of-line) (point))
5eabfe72 7155 bol (setq begin (progn (beginning-of-line) (point))))
d2ddb974 7156 (while (< bol end)
5eabfe72
KH
7157 (save-excursion
7158 (when (and (re-search-forward match eol t)
3dcb36b7 7159 (not (vhdl-in-literal)))
5eabfe72
KH
7160 (setq distance (- (match-beginning substr) bol))
7161 (when (> distance max)
7162 (setq max distance))))
7163 (forward-line)
7164 (setq bol (point)
7165 eol (save-excursion (end-of-line) (point)))
7166 (setq lines (1+ lines)))
d2ddb974
KH
7167 ;; Now insert enough maxs to push each assignment operator to
7168 ;; the same column. We need to use 'lines' as a counter, since
7169 ;; the location of the mark may change
7170 (goto-char (setq bol begin))
5eabfe72 7171 (setq eol (save-excursion (end-of-line) (point)))
d2ddb974 7172 (while (> lines 0)
5eabfe72 7173 (when (and (re-search-forward match eol t)
3dcb36b7 7174 (not (vhdl-in-literal)))
5eabfe72
KH
7175 (setq width (- (match-end substr) (match-beginning substr)))
7176 (setq distance (- (match-beginning substr) bol))
7177 (goto-char (match-beginning substr))
7178 (delete-char width)
7179 (insert-char ? (+ (- max distance) spacing)))
7180 (beginning-of-line)
7181 (forward-line)
7182 (setq bol (point)
7183 eol (save-excursion (end-of-line) (point)))
7184 (setq lines (1- lines))))))
7185
3dcb36b7
JB
7186(defun vhdl-align-region-groups (beg end &optional spacing
7187 no-message no-comments)
7188 "Align region, treat groups of lines separately."
d2ddb974 7189 (interactive "r\nP")
5eabfe72 7190 (save-excursion
3dcb36b7 7191 (let (orig pos)
5eabfe72
KH
7192 (goto-char beg)
7193 (beginning-of-line)
3dcb36b7 7194 (setq orig (point-marker))
5eabfe72
KH
7195 (setq beg (point))
7196 (goto-char end)
7197 (setq end (point-marker))
7198 (untabify beg end)
3dcb36b7
JB
7199 (unless no-message
7200 (when vhdl-progress-interval
7201 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7202 (count-lines (point-min) end) 0))))
5eabfe72
KH
7203 (vhdl-fixup-whitespace-region beg end t)
7204 (goto-char beg)
7205 (if (not vhdl-align-groups)
7206 ;; align entire region
3dcb36b7
JB
7207 (progn (vhdl-align-region-1 beg end spacing)
7208 (unless no-comments
7209 (vhdl-align-inline-comment-region-1 beg end)))
5eabfe72
KH
7210 ;; align groups
7211 (while (and (< beg end)
3dcb36b7 7212 (re-search-forward vhdl-align-group-separate end t))
5eabfe72 7213 (setq pos (point-marker))
3dcb36b7
JB
7214 (vhdl-align-region-1 beg pos spacing)
7215 (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
7216 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
5eabfe72
KH
7217 (setq beg (1+ pos))
7218 (goto-char beg))
7219 ;; align last group
7220 (when (< beg end)
3dcb36b7
JB
7221 (vhdl-align-region-1 beg end spacing)
7222 (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
7223 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7224 (when vhdl-indent-tabs-mode
7225 (tabify orig end))
7226 (unless no-message
7227 (when vhdl-progress-interval (message "Aligning...done"))
7228 (setq vhdl-progress-info nil)))))
7229
7230(defun vhdl-align-region (beg end &optional spacing)
7231 "Align region, treat blocks with same indent and argument lists separately."
7232 (interactive "r\nP")
7233 (if (not vhdl-align-same-indent)
7234 ;; align entire region
7235 (vhdl-align-region-groups beg end spacing)
7236 ;; align blocks with same indent and argument lists
7237 (save-excursion
7238 (let ((cur-beg beg)
7239 indent cur-end)
7240 (when vhdl-progress-interval
7241 (setq vhdl-progress-info (vector (count-lines (point-min) beg)
7242 (count-lines (point-min) end) 0)))
7243 (goto-char end)
7244 (setq end (point-marker))
7245 (goto-char cur-beg)
7246 (while (< (point) end)
7247 ;; is argument list opening?
7248 (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
7249 (point) (vhdl-point 'eol)))))
7250 ;; determine region for argument list
7251 (progn (goto-char cur-beg)
7252 (forward-sexp)
7253 (setq cur-end (point))
7254 (beginning-of-line 2))
7255 ;; determine region with same indent
7256 (setq indent (current-indentation))
7257 (setq cur-beg (point))
7258 (setq cur-end (vhdl-point 'bonl))
7259 (beginning-of-line 2)
7260 (while (and (< (point) end)
7261 (or (looking-at "^\\s-*\\(--.*\\)?$")
7262 (= (current-indentation) indent))
7263 (<= (save-excursion
7264 (nth 0 (parse-partial-sexp
7265 (point) (vhdl-point 'eol)))) 0))
7266 (unless (looking-at "^\\s-*$")
7267 (setq cur-end (vhdl-point 'bonl)))
7268 (beginning-of-line 2)))
7269 ;; align region
7270 (vhdl-align-region-groups cur-beg cur-end spacing t t))
7271 (vhdl-align-inline-comment-region beg end spacing noninteractive)
7272 (when vhdl-progress-interval (message "Aligning...done"))
7273 (setq vhdl-progress-info nil)))))
5eabfe72
KH
7274
7275(defun vhdl-align-group (&optional spacing)
7276 "Align group of lines between empty lines."
7277 (interactive)
3dcb36b7 7278 (vhdl-do-group 'vhdl-align-region spacing))
5eabfe72 7279
3dcb36b7
JB
7280(defun vhdl-align-list (&optional spacing)
7281 "Align the lines of a list surrounded by a balanced group of parentheses."
5eabfe72 7282 (interactive)
3dcb36b7
JB
7283 (vhdl-do-list 'vhdl-align-region-groups spacing))
7284
7285(defun vhdl-align-same-indent (&optional spacing)
7286 "Align block of lines with same indent."
7287 (interactive)
7288 (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
7289
7290(defun vhdl-align-declarations (&optional spacing)
7291 "Align the lines within the declarative part of a design unit."
7292 (interactive)
7293 (let (beg end)
7294 (vhdl-prepare-search-2
7295 (save-excursion
7296 ;; search for declarative part
7297 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
7298 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7299 (setq beg (point))
7300 (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
7301 (setq end (point)))))
7302 (if beg
7303 (vhdl-align-region-groups beg end spacing)
7304 (error "ERROR: Not within the declarative part of a design unit"))))
7305
7306(defun vhdl-align-buffer ()
7307 "Align buffer."
7308 (interactive)
7309 (vhdl-align-region (point-min) (point-max)))
7310
7311;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7312;; Align inline comments
7313
7314(defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
7315 "Align inline comments in region."
7316 (save-excursion
7317 (let ((start-max comment-column)
7318 (length-max 0)
7319 comment-list start-list tmp-list start length
7320 cur-start prev-start no-code)
7321 (setq spacing (or spacing 2))
7322 (vhdl-prepare-search-2
7323 (goto-char beg)
7324 ;; search for comment start positions and lengths
7325 (while (< (point) end)
7326 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7327 (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
7328 (not (save-excursion (goto-char (match-beginning 2))
7329 (vhdl-in-literal))))
7330 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7331 (setq length (- (match-end 2) (match-beginning 2)))
7332 (setq start-max (max start start-max))
7333 (setq length-max (max length length-max))
7334 (setq comment-list (cons (cons start length) comment-list)))
7335 (beginning-of-line 2))
7336 (setq comment-list
7337 (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
7338 ;; reduce start positions
7339 (setq start-list (list (caar comment-list)))
7340 (setq comment-list (cdr comment-list))
7341 (while comment-list
7342 (unless (or (= (caar comment-list) (car start-list))
7343 (<= (+ (car start-list) (cdar comment-list))
7344 end-comment-column))
7345 (setq start-list (cons (caar comment-list) start-list)))
7346 (setq comment-list (cdr comment-list)))
7347 ;; align lines as nicely as possible
7348 (goto-char beg)
7349 (while (< (point) end)
7350 (setq cur-start nil)
7351 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7352 (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7353 (not (save-excursion
7354 (goto-char (match-beginning 3))
7355 (vhdl-in-literal))))
7356 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7357 (>= (- (match-end 2) (match-beginning 2))
7358 comment-column))))
7359 (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
7360 (setq length (- (match-end 3) (match-beginning 3)))
7361 (setq no-code (= (match-beginning 1) (match-end 1)))
7362 ;; insert minimum whitespace
7363 (goto-char (match-end 2))
7364 (delete-region (match-beginning 2) (match-end 2))
7365 (insert-char ?\ spacing)
7366 (setq tmp-list start-list)
7367 ;; insert additional whitespace to align
7368 (setq cur-start
7369 (cond
7370 ;; align comment-only line to inline comment of previous line
7371 ((and no-code prev-start
7372 (<= length (- end-comment-column prev-start)))
7373 prev-start)
7374 ;; align all comments at `start-max' if this is possible
7375 ((<= (+ start-max length-max) end-comment-column)
7376 start-max)
7377 ;; align at `comment-column' if possible
7378 ((and (<= start comment-column)
7379 (<= length (- end-comment-column comment-column)))
7380 comment-column)
7381 ;; align at left-most possible start position otherwise
7382 (t
7383 (while (and tmp-list (< (car tmp-list) start))
7384 (setq tmp-list (cdr tmp-list)))
7385 (car tmp-list))))
7386 (indent-to cur-start))
7387 (setq prev-start cur-start)
7388 (beginning-of-line 2))))))
d2ddb974 7389
5eabfe72
KH
7390(defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
7391 "Align inline comments within a region. Groups of code lines separated by
7392empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
d2ddb974 7393 (interactive "r\nP")
5eabfe72 7394 (save-excursion
3dcb36b7 7395 (let (orig pos)
5eabfe72
KH
7396 (goto-char beg)
7397 (beginning-of-line)
3dcb36b7 7398 (setq orig (point-marker))
5eabfe72
KH
7399 (setq beg (point))
7400 (goto-char end)
7401 (setq end (point-marker))
7402 (untabify beg end)
7403 (unless no-message (message "Aligning inline comments..."))
7404 (goto-char beg)
7405 (if (not vhdl-align-groups)
7406 ;; align entire region
7407 (vhdl-align-inline-comment-region-1 beg end spacing)
7408 ;; align groups
3dcb36b7
JB
7409 (while (and (< beg end)
7410 (re-search-forward vhdl-align-group-separate end t))
5eabfe72
KH
7411 (setq pos (point-marker))
7412 (vhdl-align-inline-comment-region-1 beg pos spacing)
7413 (setq beg (1+ pos))
7414 (goto-char beg))
7415 ;; align last group
7416 (when (< beg end)
3dcb36b7
JB
7417 (vhdl-align-inline-comment-region-1 beg end spacing)))
7418 (when vhdl-indent-tabs-mode
7419 (tabify orig end))
7420 (unless no-message (message "Aligning inline comments...done")))))
5eabfe72
KH
7421
7422(defun vhdl-align-inline-comment-group (&optional spacing)
7423 "Align inline comments within a group of lines between empty lines."
7424 (interactive)
7425 (save-excursion
7426 (let ((start (point))
7427 beg end)
3dcb36b7 7428 (setq end (if (re-search-forward vhdl-align-group-separate nil t)
5eabfe72
KH
7429 (point-marker) (point-max)))
7430 (goto-char start)
3dcb36b7
JB
7431 (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
7432 (point) (point-min)))
5eabfe72
KH
7433 (untabify beg end)
7434 (message "Aligning inline comments...")
7435 (vhdl-align-inline-comment-region-1 beg end)
3dcb36b7
JB
7436 (when vhdl-indent-tabs-mode
7437 (tabify beg end))
5eabfe72
KH
7438 (message "Aligning inline comments...done"))))
7439
7440(defun vhdl-align-inline-comment-buffer ()
7441 "Align inline comments within buffer. Groups of code lines separated by
7442empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7443 (interactive)
7444 (vhdl-align-inline-comment-region (point-min) (point-max)))
7445
3dcb36b7
JB
7446;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7447;; Fixup whitespace
7448
5eabfe72
KH
7449(defun vhdl-fixup-whitespace-region (beg end &optional no-message)
7450 "Fixup whitespace in region. Surround operator symbols by one space,
7451eliminate multiple spaces (except at beginning of line), eliminate spaces at
3dcb36b7 7452end of line, do nothing in comments and strings."
5eabfe72
KH
7453 (interactive "r")
7454 (unless no-message (message "Fixing up whitespace..."))
7455 (save-excursion
7456 (goto-char end)
7457 (setq end (point-marker))
5eabfe72
KH
7458 ;; have no space before and one space after `,' and ';'
7459 (goto-char beg)
3dcb36b7
JB
7460 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
7461 (if (match-string 1)
7462 (goto-char (match-end 1))
7463 (replace-match "\\3 " nil nil nil 3)))
7464 ;; have no space after `('
7465 (goto-char beg)
7466 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\((\\)\\s-+" end t)
7467 (if (match-string 1)
7468 (goto-char (match-end 1))
7469 (replace-match "\\2")))
7470 ;; have no space before `)'
7471 (goto-char beg)
7472 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
7473 (if (match-string 1)
7474 (goto-char (match-end 1))
7475 (replace-match "\\2")))
7476 ;; surround operator symbols by one space
7477 (goto-char beg)
7478 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
7479 (if (match-string 1)
7480 (goto-char (match-end 1))
7481 (replace-match "\\3 \\4 \\5")
7482 (goto-char (match-end 4))))
5eabfe72
KH
7483 ;; eliminate multiple spaces and spaces at end of line
7484 (goto-char beg)
7485 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
3dcb36b7 7486 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
5eabfe72
KH
7487 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
7488 (progn (replace-match "" nil nil) t))
7489 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
7490 (progn (replace-match ";" nil nil) t))
7491 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
7492 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
3dcb36b7 7493 (progn (replace-match " " nil nil) t))
5eabfe72 7494 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
3dcb36b7
JB
7495 (progn (replace-match " " nil nil) t))
7496 (re-search-forward "[^ \t-]+" end t))))
5eabfe72
KH
7497 (unless no-message (message "Fixing up whitespace...done")))
7498
7499(defun vhdl-fixup-whitespace-buffer ()
7500 "Fixup whitespace in buffer. Surround operator symbols by one space,
7501eliminate multiple spaces (except at beginning of line), eliminate spaces at
7502end of line, do nothing in comments."
7503 (interactive)
7504 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7505
3dcb36b7
JB
7506;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7507;; Beautify
7508
5eabfe72
KH
7509(defun vhdl-beautify-region (beg end)
7510 "Beautify region by applying indentation, whitespace fixup, alignment, and
3dcb36b7
JB
7511case fixing to a region. Calls functions `vhdl-indent-buffer',
7512`vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
5eabfe72
KH
7513`vhdl-fix-case-buffer'."
7514 (interactive "r")
3dcb36b7 7515 (setq end (save-excursion (goto-char end) (point-marker)))
5eabfe72
KH
7516 (vhdl-indent-region beg end nil)
7517 (let ((vhdl-align-groups t))
3dcb36b7 7518 (vhdl-align-region beg end))
5eabfe72
KH
7519 (vhdl-fix-case-region beg end))
7520
7521(defun vhdl-beautify-buffer ()
7522 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
7523case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
7524buffer."
7525 (interactive)
3dcb36b7
JB
7526 (vhdl-beautify-region (point-min) (point-max))
7527 (when noninteractive (save-buffer)))
7528
7529;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7530;; Code filling
7531
7532(defun vhdl-fill-region (beg end &optional arg)
7533 "Fill lines for a region of code."
7534 (interactive "r")
7535 (save-excursion
7536 (goto-char beg)
7537 (let ((margin (if (interactive-p) (current-indentation) (current-column))))
7538 (goto-char end)
7539 (setq end (point-marker))
7540 ;; remove inline comments, newlines and whitespace
7541 (vhdl-comment-kill-region beg end)
7542 (vhdl-comment-kill-inline-region beg end)
7543 (subst-char-in-region beg (1- end) ?\n ?\ )
7544 (vhdl-fixup-whitespace-region beg end)
7545 ;; wrap and end-comment-column
7546 (goto-char beg)
7547 (while (re-search-forward "\\s-" end t)
7548 (when(> (current-column) vhdl-end-comment-column)
7549 (backward-char)
7550 (when (re-search-backward "\\s-" beg t)
7551 (replace-match "\n")
7552 (indent-to margin)))))))
7553
7554(defun vhdl-fill-group ()
7555 "Fill group of lines between empty lines."
7556 (interactive)
7557 (vhdl-do-group 'vhdl-fill-region))
7558
7559(defun vhdl-fill-list ()
7560 "Fill the lines of a list surrounded by a balanced group of parentheses."
7561 (interactive)
7562 (vhdl-do-list 'vhdl-fill-region))
7563
7564(defun vhdl-fill-same-indent ()
7565 "Fill the lines of block of lines with same indent."
7566 (interactive)
7567 (vhdl-do-same-indent 'vhdl-fill-region))
7568
7569
7570;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7571;;; Code updating/fixing
7572;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7573
7574;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7575;; Sensitivity list update
7576
7577;; Strategy:
7578;; - no sensitivity list is generated for processes with wait statements
7579;; - otherwise, do the following:
7580;; 1. scan for all local signals (ports, signals declared in arch./blocks)
7581;; 2. scan for all signals already in the sensitivity list (in order to catch
7582;; manually entered global signals)
7583;; 3. signals from 1. and 2. form the list of visible signals
7584;; 4. search for if/elsif conditions containing an event (sequential code)
7585;; 5. scan for strings that are within syntactical regions where signals are
7586;; read but not within sequential code, and that correspond to visible
7587;; signals
7588;; 6. replace sensitivity list by list of signals from 5.
7589
7590(defun vhdl-update-sensitivity-list-process ()
7591 "Update sensitivity list of current process."
7592 (interactive)
7593 (save-excursion
7594 (vhdl-prepare-search-2
7595 (end-of-line)
7596 ;; look whether in process
7597 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
7598 (equal (upcase (match-string 2)) "PROCESS")
7599 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
7600 (error "ERROR: Not within a process")
7601 (message "Updating sensitivity list...")
7602 (vhdl-update-sensitivity-list)
7603 (message "Updating sensitivity list...done")))))
7604
7605(defun vhdl-update-sensitivity-list-buffer ()
7606 "Update sensitivity list of all processes in current buffer."
7607 (interactive)
7608 (save-excursion
7609 (vhdl-prepare-search-2
7610 (goto-char (point-min))
7611 (message "Updating sensitivity lists...")
7612 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
7613 (goto-char (match-beginning 0))
7614 (condition-case nil (vhdl-update-sensitivity-list) (error)))
7615 (message "Updating sensitivity lists...done"))))
7616
7617(defun vhdl-update-sensitivity-list ()
7618 "Update sensitivity list."
7619 (let ((proc-beg (point))
7620 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
7621 (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
7622 seq-region-list)
7623 (cond
7624 ;; search for wait statement (no sensitivity list allowed)
7625 ((progn (goto-char proc-mid)
7626 (vhdl-re-search-forward "\\<wait\\>" proc-end t))
7627 (error "ERROR: Process with wait statement, sensitivity list not generated"))
7628 ;; combinational process (update sensitivity list)
7629 (t
7630 (let
7631 ;; scan for visible signals
7632 ((visible-list (vhdl-get-visible-signals))
7633 ;; define syntactic regions where signals are read
7634 (scan-regions-list
7635 '(;; right-hand side of signal/variable assignment
7636 ;; (special case: "<=" is relational operator in a condition)
7637 ((re-search-forward "[<:]=" proc-end t)
7638 (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
7639 ;; if condition
7640 ((re-search-forward "^\\s-*if\\>" proc-end t)
7641 (re-search-forward "\\<then\\>" proc-end t))
7642 ;; elsif condition
7643 ((re-search-forward "\\<elsif\\>" proc-end t)
7644 (re-search-forward "\\<then\\>" proc-end t))
7645 ;; while loop condition
7646 ((re-search-forward "^\\s-*while\\>" proc-end t)
7647 (re-search-forward "\\<loop\\>" proc-end t))
7648 ;; exit/next condition
7649 ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
7650 (re-search-forward ";" proc-end t))
7651 ;; assert condition
7652 ((re-search-forward "\\<assert\\>" proc-end t)
7653 (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
7654 ;; case expression
7655 ((re-search-forward "^\\s-*case\\>" proc-end t)
7656 (re-search-forward "\\<is\\>" proc-end t))
7657 ;; parameter list of procedure call
7658 ((re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
7659 (progn (backward-char) (forward-sexp) (point)))))
7660 name read-list sens-list signal-list
7661 sens-beg sens-end beg end margin)
7662 ;; scan for signals in old sensitivity list
7663 (goto-char proc-beg)
7664 (re-search-forward "\\<process\\>" proc-mid t)
7665 (if (not (looking-at "[ \t\n]*("))
7666 (setq sens-beg (point))
7667 (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
7668 (goto-char (match-end 1))
7669 (forward-sexp)
7670 (setq sens-end (1- (point)))
7671 (goto-char sens-beg)
7672 (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
7673 (setq sens-list
7674 (cons (downcase (match-string 0)) sens-list))
7675 (re-search-forward "\\s-*,\\s-*" sens-end t))))
7676 (setq signal-list (append visible-list sens-list))
7677 ;; search for sequential parts
7678 (goto-char proc-mid)
7679 (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
7680 (setq end (re-search-forward "\\<then\\>" proc-end t))
7681 (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
7682 (goto-char end)
7683 (backward-word 1)
7684 (vhdl-forward-sexp)
7685 (setq seq-region-list (cons (cons end (point)) seq-region-list))
7686 (beginning-of-line)))
7687 ;; scan for signals read in process
7688 (while scan-regions-list
7689 (goto-char proc-mid)
7690 (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
7691 (setq end (eval (nth 1 (car scan-regions-list)))))
7692 (goto-char beg)
7693 (unless (or (vhdl-in-literal)
7694 (and seq-region-list
7695 (let ((tmp-list seq-region-list))
7696 (while (and tmp-list
7697 (< (point) (caar tmp-list)))
7698 (setq tmp-list (cdr tmp-list)))
7699 (and tmp-list (< (point) (cdar tmp-list))))))
7700 (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>" end t)
7701 (setq name (match-string 1))
7702 (when (member (downcase name) signal-list)
7703 (add-to-list 'read-list name)))))
7704 (setq scan-regions-list (cdr scan-regions-list)))
7705 ;; update sensitivity list
7706 (goto-char sens-beg)
7707 (if sens-end
7708 (delete-region sens-beg sens-end)
7709 (when read-list
7710 (insert " ()") (backward-char)))
7711 (setq read-list (sort read-list 'string<))
7712 (when read-list
7713 (setq margin (current-column))
7714 (insert (car read-list))
7715 (setq read-list (cdr read-list))
7716 (while read-list
7717 (insert ",")
7718 (if (<= (+ (current-column) (length (car read-list)) 2)
7719 end-comment-column)
7720 (insert " ")
7721 (insert "\n") (indent-to margin))
7722 (insert (car read-list))
7723 (setq read-list (cdr read-list)))))))))
7724
7725(defun vhdl-get-visible-signals ()
7726 "Get all signals visible in the current block."
7727 (save-excursion
7728 (let (beg end signal-list entity-name file-name)
7729 ;; search for signals declared in surrounding block declarative parts
7730 (save-excursion
7731 (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
7732 (match-string 2))
7733 (goto-char (match-end 2))
7734 (vhdl-backward-sexp)
7735 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
7736 beg)
7737 (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
7738 ;; scan for all declared signal names
7739 (goto-char beg)
7740 (while (re-search-forward "^\\s-*signal\\>" end t)
7741 (while (and (not (looking-at "[ \t\n]*:"))
7742 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7743 (setq signal-list
7744 (cons (downcase (match-string 1)) signal-list))))
7745 (goto-char beg)))
7746 ;; search for signals declared in architecture declarative part
7747 (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
7748 (not (equal "END" (upcase (match-string 1))))
7749 (setq entity-name (match-string 2))
7750 (setq end (re-search-forward "^begin\\>" nil t))))
7751 (error "ERROR: No architecture declarative part found")
7752 ;; scan for all declared signal names
7753 (goto-char beg)
7754 (while (re-search-forward "^\\s-*signal\\>" end t)
7755 (while (and (not (looking-at "[ \t\n]*:"))
7756 (re-search-forward "[ \t\n,]+\\(\\w+\\)" end t))
7757 (setq signal-list
7758 (cons (downcase (match-string 1)) signal-list)))))
7759 ;; search for signals declared in entity port clause
7760 (goto-char (point-min))
7761 (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
7762 (setq file-name
7763 (concat (vhdl-replace-string vhdl-entity-file-name entity-name)
7764 "." (file-name-extension (buffer-file-name)))))
7765 (vhdl-visit-file
7766 file-name t
7767 (vhdl-prepare-search-2
7768 (goto-char (point-min))
7769 (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
7770 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
7771 (when (setq beg (re-search-forward
7772 "^\\s-*port[ \t\n]*("
7773 (save-excursion
7774 (re-search-forward "^end\\>" nil t)) t))
7775 (setq end (save-excursion
7776 (backward-char) (forward-sexp) (point)))
7777 (vhdl-forward-syntactic-ws)
7778 (while (< (point) end)
7779 (while (and (not (looking-at "[ \t\n]*:"))
7780 (re-search-forward "[ \t\n,]*\\(\\w+\\)" end t))
7781 (setq signal-list
7782 (cons (downcase (match-string 1)) signal-list)))
7783 (re-search-forward ";" end 1)
7784 (vhdl-forward-syntactic-ws))))))
7785 signal-list)))
7786
7787;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7788;; Generic/port clause fixing
7789
7790(defun vhdl-fix-clause ()
7791 "Fix closing parenthesis within generic/port clause."
7792 (interactive)
7793 (save-excursion
7794 (vhdl-prepare-search-2
7795 (let ((pos (point))
7796 beg end)
7797 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
7798 (error "ERROR: Not within a generic/port clause")
7799 ;; search for end of clause
7800 (goto-char (match-end 0))
7801 (setq beg (1- (point)))
7802 (vhdl-forward-syntactic-ws)
7803 (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
7804 (goto-char (1- (match-end 0)))
7805 (setq end (point-marker))
7806 (forward-char)
7807 (vhdl-forward-syntactic-ws))
7808 (goto-char end)
7809 (when (> pos (save-excursion (end-of-line) (point)))
7810 (error "ERROR: Not within a generic/port clause"))
7811 ;; delete closing parenthesis on separate line (not supported style)
7812 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
7813 (vhdl-line-kill)
7814 (vhdl-backward-syntactic-ws)
7815 (setq end (point-marker))
7816 (insert ";"))
7817 ;; delete superfluous parentheses
7818 (while (progn (goto-char beg)
7819 (condition-case () (forward-sexp)
7820 (error (goto-char (point-max))))
7821 (< (point) end))
7822 (delete-backward-char 1))
7823 ;; add closing parenthesis
7824 (when (> (point) end)
7825 (goto-char end)
7826 (insert ")")))))))
7827
7828;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7829;; Miscellaneous
7830
7831(defun vhdl-remove-trailing-spaces ()
7832 "Remove trailing spaces in the whole buffer."
7833 (interactive)
7834 (save-match-data
7835 (save-excursion
7836 (goto-char (point-min))
7837 (while (re-search-forward "[ \t]+$" (point-max) t)
7838 (unless (vhdl-in-literal)
7839 (replace-match "" nil nil))))))
d2ddb974
KH
7840
7841
5eabfe72
KH
7842;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7843;;; Electrification
7844;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974 7845
5eabfe72
KH
7846(defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
7847 "Syntax of prompt inserted by template generators.")
7848
7849(defvar vhdl-template-invoked-by-hook nil
7850 "Indicates whether a template has been invoked by a hook or by key or menu.
7851Used for undoing after template abortion.")
7852
7853;; correct different behavior of function `unread-command-events' in XEmacs
3dcb36b7 7854(defun vhdl-character-to-event (arg))
5eabfe72 7855(defalias 'vhdl-character-to-event
3dcb36b7
JB
7856 (if vhdl-xemacs 'character-to-event 'identity))
7857
7858(defun vhdl-work-library ()
7859 "Return the working library name of the current project or \"work\" if no
7860project is defined."
7861 (vhdl-resolve-env-variable
7862 (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
5eabfe72
KH
7863
7864;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7865;; Enabling/disabling
7866
7867(defun vhdl-mode-line-update ()
7868 "Update the modeline string for VHDL major mode."
7869 (setq mode-name (concat "VHDL"
7870 (and (or vhdl-electric-mode vhdl-stutter-mode) "/")
7871 (and vhdl-electric-mode "e")
7872 (and vhdl-stutter-mode "s")))
3dcb36b7 7873 (force-mode-line-update t))
5eabfe72
KH
7874
7875(defun vhdl-electric-mode (arg)
7876 "Toggle VHDL electric mode.
7877Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7878 (interactive "P")
7879 (setq vhdl-electric-mode
7880 (cond ((or (not arg) (zerop arg)) (not vhdl-electric-mode))
7881 ((> arg 0) t) (t nil)))
7882 (vhdl-mode-line-update))
7883
7884(defun vhdl-stutter-mode (arg)
7885 "Toggle VHDL stuttering mode.
7886Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
7887 (interactive "P")
7888 (setq vhdl-stutter-mode
7889 (cond ((or (not arg) (zerop arg)) (not vhdl-stutter-mode))
7890 ((> arg 0) t) (t nil)))
7891 (vhdl-mode-line-update))
7892
7893;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7894;; Stuttering
d2ddb974 7895
5eabfe72
KH
7896(defun vhdl-electric-dash (count)
7897 "-- starts a comment, --- draws a horizontal line,
7898---- starts a display comment"
d2ddb974 7899 (interactive "p")
3dcb36b7 7900 (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
5eabfe72
KH
7901 (cond
7902 ((and abbrev-start-location (= abbrev-start-location (point)))
7903 (setq abbrev-start-location nil)
7904 (goto-char last-abbrev-location)
7905 (beginning-of-line nil)
7906 (vhdl-comment-display))
7907 ((/= (preceding-char) ?-) ; standard dash (minus)
d2ddb974 7908 (self-insert-command count))
5eabfe72
KH
7909 (t (self-insert-command count)
7910 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
7911 (let ((next-input (read-char)))
7912 (if (= next-input ?-) ; triple dash
7913 (progn
7914 (vhdl-comment-display-line)
7915 (message
7916 "Enter '-' for display comment, else continue coding")
7917 (let ((next-input (read-char)))
7918 (if (= next-input ?-) ; four dashes
7919 (vhdl-comment-display t)
7920 (setq unread-command-events ; pushback the char
7921 (list (vhdl-character-to-event next-input))))))
7922 (setq unread-command-events ; pushback the char
7923 (list (vhdl-character-to-event next-input)))
7924 (vhdl-comment-insert)))))
7925 (self-insert-command count)))
7926
7927(defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
d2ddb974 7928 (interactive "p")
3dcb36b7 7929 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7930 (if (= (preceding-char) ?\()
7931 (progn (delete-char -1) (insert-char ?\[ 1))
7932 (insert-char ?\( 1))
7933 (self-insert-command count)))
d2ddb974 7934
5eabfe72 7935(defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
d2ddb974 7936 (interactive "p")
3dcb36b7 7937 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974 7938 (progn
5eabfe72
KH
7939 (if (= (preceding-char) ?\))
7940 (progn (delete-char -1) (insert-char ?\] 1))
7941 (insert-char ?\) 1))
7942 (blink-matching-open))
7943 (self-insert-command count)))
d2ddb974 7944
5eabfe72 7945(defun vhdl-electric-quote (count) "'' --> \""
d2ddb974 7946 (interactive "p")
3dcb36b7 7947 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7948 (if (= (preceding-char) last-input-char)
7949 (progn (delete-backward-char 1) (insert-char ?\" 1))
7950 (insert-char ?\' 1))
7951 (self-insert-command count)))
d2ddb974 7952
5eabfe72 7953(defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
d2ddb974 7954 (interactive "p")
3dcb36b7 7955 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7956 (cond ((= (preceding-char) last-input-char)
7957 (progn (delete-char -1)
3dcb36b7 7958 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
7959 (insert ": ")
7960 (setq this-command 'vhdl-electric-colon)))
7961 ((and
7962 (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
7963 (progn (delete-char -1) (insert "= ")))
7964 (t (insert-char ?\; 1)))
7965 (self-insert-command count)))
7966
7967(defun vhdl-electric-comma (count) "',,' --> ' <= '"
d2ddb974 7968 (interactive "p")
3dcb36b7 7969 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
7970 (cond ((= (preceding-char) last-input-char)
7971 (progn (delete-char -1)
3dcb36b7 7972 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 7973 (insert "<= ")))
5eabfe72
KH
7974 (t (insert-char ?\, 1)))
7975 (self-insert-command count)))
d2ddb974 7976
5eabfe72 7977(defun vhdl-electric-period (count) "'..' --> ' => '"
d2ddb974 7978 (interactive "p")
3dcb36b7 7979 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
d2ddb974
KH
7980 (cond ((= (preceding-char) last-input-char)
7981 (progn (delete-char -1)
3dcb36b7 7982 (unless (eq (preceding-char) ? ) (insert " "))
d2ddb974 7983 (insert "=> ")))
5eabfe72
KH
7984 (t (insert-char ?\. 1)))
7985 (self-insert-command count)))
d2ddb974 7986
5eabfe72 7987(defun vhdl-electric-equal (count) "'==' --> ' == '"
d2ddb974 7988 (interactive "p")
3dcb36b7 7989 (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
5eabfe72
KH
7990 (cond ((= (preceding-char) last-input-char)
7991 (progn (delete-char -1)
3dcb36b7 7992 (unless (eq (preceding-char) ? ) (insert " "))
5eabfe72
KH
7993 (insert "== ")))
7994 (t (insert-char ?\= 1)))
7995 (self-insert-command count)))
d2ddb974 7996
5eabfe72 7997;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
7998;; VHDL templates
7999
5eabfe72
KH
8000(defun vhdl-template-paired-parens ()
8001 "Insert a pair of round parentheses, placing point between them."
d2ddb974 8002 (interactive)
5eabfe72
KH
8003 (insert "()")
8004 (backward-char))
d2ddb974 8005
5eabfe72
KH
8006(defun vhdl-template-alias ()
8007 "Insert alias declaration."
d2ddb974 8008 (interactive)
5eabfe72
KH
8009 (let ((start (point)))
8010 (vhdl-insert-keyword "ALIAS ")
8011 (when (vhdl-template-field "name" nil t start (point))
8012 (insert " : ")
8013 (unless (vhdl-template-field
8014 (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
8015 nil t)
3dcb36b7 8016 (delete-backward-char 3))
5eabfe72
KH
8017 (vhdl-insert-keyword " IS ")
8018 (vhdl-template-field "name" ";")
8019 (vhdl-comment-insert-inline))))
8020
8021(defun vhdl-template-architecture ()
8022 "Insert architecture."
8023 (interactive)
8024 (let ((margin (current-indentation))
8025 (start (point))
3dcb36b7 8026 arch-name)
d2ddb974 8027 (vhdl-insert-keyword "ARCHITECTURE ")
5eabfe72
KH
8028 (when (setq arch-name
8029 (vhdl-template-field "name" nil t start (point)))
d2ddb974 8030 (vhdl-insert-keyword " OF ")
3dcb36b7
JB
8031 (if (save-excursion
8032 (vhdl-prepare-search-1
8033 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
8034 (insert (match-string 1))
5eabfe72 8035 (vhdl-template-field "entity name"))
3dcb36b7 8036 (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8037 (vhdl-template-begin-end
8038 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8039 (memq vhdl-insert-empty-lines '(unit all))))))
d2ddb974 8040
5eabfe72 8041(defun vhdl-template-array (kind &optional secondary)
d2ddb974
KH
8042 "Insert array type definition."
8043 (interactive)
5eabfe72
KH
8044 (let ((start (point)))
8045 (vhdl-insert-keyword "ARRAY (")
8046 (when (or (vhdl-template-field "range" nil (not secondary) start (point))
8047 secondary)
8048 (vhdl-insert-keyword ") OF ")
8049 (vhdl-template-field (if (eq kind 'type) "type" "nature"))
8050 (vhdl-insert-keyword ";"))))
8051
8052(defun vhdl-template-assert ()
8053 "Insert an assertion statement."
8054 (interactive)
8055 (let ((start (point)))
8056 (vhdl-insert-keyword "ASSERT ")
8057 (when vhdl-conditions-in-parenthesis (insert "("))
8058 (when (vhdl-template-field "condition (negated)" nil t start (point))
8059 (when vhdl-conditions-in-parenthesis (insert ")"))
8060 (setq start (point))
8061 (vhdl-insert-keyword " REPORT ")
8062 (unless (vhdl-template-field "string expression" nil nil nil nil t)
8063 (delete-region start (point)))
8064 (setq start (point))
8065 (vhdl-insert-keyword " SEVERITY ")
8066 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
8067 (delete-region start (point)))
8068 (insert ";"))))
8069
8070(defun vhdl-template-attribute ()
8071 "Insert an attribute declaration or specification."
8072 (interactive)
8073 (if (eq (vhdl-decision-query
8074 "attribute" "(d)eclaration or (s)pecification?" t) ?s)
8075 (vhdl-template-attribute-spec)
8076 (vhdl-template-attribute-decl)))
d2ddb974 8077
5eabfe72
KH
8078(defun vhdl-template-attribute-decl ()
8079 "Insert an attribute declaration."
d2ddb974 8080 (interactive)
5eabfe72
KH
8081 (let ((start (point)))
8082 (vhdl-insert-keyword "ATTRIBUTE ")
8083 (when (vhdl-template-field "name" " : " t start (point))
8084 (vhdl-template-field "type" ";")
8085 (vhdl-comment-insert-inline))))
8086
8087(defun vhdl-template-attribute-spec ()
8088 "Insert an attribute specification."
8089 (interactive)
8090 (let ((start (point)))
8091 (vhdl-insert-keyword "ATTRIBUTE ")
8092 (when (vhdl-template-field "name" nil t start (point))
8093 (vhdl-insert-keyword " OF ")
8094 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8095 (vhdl-template-field "entity class")
8096 (vhdl-insert-keyword " IS ")
8097 (vhdl-template-field "expression" ";"))))
d2ddb974 8098
5eabfe72
KH
8099(defun vhdl-template-block ()
8100 "Insert a block."
d2ddb974 8101 (interactive)
5eabfe72
KH
8102 (let ((margin (current-indentation))
8103 (start (point))
8104 label)
8105 (vhdl-insert-keyword ": BLOCK ")
8106 (goto-char start)
8107 (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
8108 (forward-word 1)
8109 (forward-char 1)
d2ddb974 8110 (insert "(")
5eabfe72
KH
8111 (if (vhdl-template-field "[guard expression]" nil t)
8112 (insert ")")
8113 (delete-char -2))
8114 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 8115 (insert "\n")
5eabfe72
KH
8116 (vhdl-template-begin-end "BLOCK" label margin)
8117 (vhdl-comment-block))))
d2ddb974 8118
5eabfe72 8119(defun vhdl-template-block-configuration ()
d2ddb974
KH
8120 "Insert a block configuration statement."
8121 (interactive)
5eabfe72
KH
8122 (let ((margin (current-indentation))
8123 (start (point)))
d2ddb974 8124 (vhdl-insert-keyword "FOR ")
5eabfe72 8125 (when (vhdl-template-field "block name" nil t start (point))
d2ddb974
KH
8126 (vhdl-insert-keyword "\n\n")
8127 (indent-to margin)
8128 (vhdl-insert-keyword "END FOR;")
8129 (end-of-line 0)
5eabfe72 8130 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8131
5eabfe72
KH
8132(defun vhdl-template-break ()
8133 "Insert a break statement."
d2ddb974 8134 (interactive)
5eabfe72
KH
8135 (let (position)
8136 (vhdl-insert-keyword "BREAK")
8137 (setq position (point))
8138 (insert " ")
8139 (while (or
8140 (progn (vhdl-insert-keyword "FOR ")
8141 (if (vhdl-template-field "[quantity name]" " USE " t)
8142 (progn (vhdl-template-field "quantity name" " => ") t)
8143 (kill-word -1) nil))
8144 (vhdl-template-field "[quantity name]" " => " t))
8145 (vhdl-template-field "expression")
8146 (setq position (point))
8147 (insert ", "))
8148 (delete-region position (point))
8149 (unless (vhdl-sequential-statement-p)
8150 (vhdl-insert-keyword " ON ")
8151 (if (vhdl-template-field "[sensitivity list]" nil t)
8152 (setq position (point))
8153 (delete-region position (point))))
8154 (vhdl-insert-keyword " WHEN ")
8155 (when vhdl-conditions-in-parenthesis (insert "("))
8156 (if (vhdl-template-field "[condition]" nil t)
8157 (when vhdl-conditions-in-parenthesis (insert ")"))
8158 (delete-region position (point)))
8159 (insert ";")))
8160
8161(defun vhdl-template-case (&optional kind)
8162 "Insert a case statement."
8163 (interactive)
8164 (let ((margin (current-indentation))
8165 (start (point))
8166 label)
8167 (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
8168 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8169 (vhdl-insert-keyword "CASE ")
8170 (vhdl-insert-keyword ": CASE ")
8171 (goto-char start)
8172 (setq label (vhdl-template-field "[label]" nil t))
8173 (unless label (delete-char 2))
8174 (forward-word 1)
8175 (forward-char 1))
8176 (when (vhdl-template-field "expression" nil t start (point))
8177 (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
d2ddb974 8178 (indent-to margin)
5eabfe72
KH
8179 (vhdl-insert-keyword "END CASE")
8180 (when label (insert " " label))
8181 (insert ";")
d2ddb974
KH
8182 (forward-line -1)
8183 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8184 (vhdl-insert-keyword "WHEN ")
8185 (let ((position (point)))
8186 (insert " => ;\n")
8187 (indent-to (+ margin vhdl-basic-offset))
8188 (vhdl-insert-keyword "WHEN OTHERS => null;")
8189 (goto-char position)))))
d2ddb974 8190
5eabfe72
KH
8191(defun vhdl-template-case-is ()
8192 "Insert a sequential case statement."
d2ddb974 8193 (interactive)
5eabfe72
KH
8194 (vhdl-template-case 'is))
8195
8196(defun vhdl-template-case-use ()
8197 "Insert a simultaneous case statement."
8198 (interactive)
8199 (vhdl-template-case 'use))
8200
8201(defun vhdl-template-component ()
8202 "Insert a component declaration."
8203 (interactive)
8204 (vhdl-template-component-decl))
8205
8206(defun vhdl-template-component-conf ()
8207 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8208since these are almost equivalent)."
8209 (interactive)
8210 (let ((margin (current-indentation))
8211 (result (vhdl-template-configuration-spec t)))
8212 (when result
8213 (insert "\n")
8214 (indent-to margin)
8215 (vhdl-insert-keyword "END FOR;")
8216 (when (eq result 'no-use)
8217 (end-of-line -0)))))
8218
8219(defun vhdl-template-component-decl ()
8220 "Insert a component declaration."
8221 (interactive)
8222 (let ((margin (current-indentation))
8223 (start (point))
8224 name end-column)
d2ddb974 8225 (vhdl-insert-keyword "COMPONENT ")
5eabfe72 8226 (when (setq name (vhdl-template-field "name" nil t start (point)))
3dcb36b7 8227 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
d2ddb974
KH
8228 (insert "\n\n")
8229 (indent-to margin)
5eabfe72
KH
8230 (vhdl-insert-keyword "END COMPONENT")
8231 (unless (vhdl-standard-p '87) (insert " " name))
8232 (insert ";")
8233 (setq end-column (current-column))
d2ddb974
KH
8234 (end-of-line -0)
8235 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 8236 (vhdl-template-generic-list t t)
d2ddb974
KH
8237 (insert "\n")
8238 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8239 (vhdl-template-port-list t)
8240 (beginning-of-line 2)
8241 (forward-char end-column))))
d2ddb974 8242
5eabfe72
KH
8243(defun vhdl-template-component-inst ()
8244 "Insert a component instantiation statement."
d2ddb974 8245 (interactive)
5eabfe72
KH
8246 (let ((margin (current-indentation))
8247 (start (point))
8248 unit position)
8249 (when (vhdl-template-field "instance label" nil t start (point))
8250 (insert ": ")
3dcb36b7 8251 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
8252 (vhdl-template-field "component name")
8253 ;; direct instantiation
8254 (setq unit (vhdl-template-field
8255 "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
8256 (setq unit (upcase (or unit "")))
8257 (cond ((equal unit "ENTITY")
3dcb36b7
JB
8258 (vhdl-template-field "library name" "." nil nil nil nil
8259 (vhdl-work-library))
5eabfe72
KH
8260 (vhdl-template-field "entity name" "(")
8261 (if (vhdl-template-field "[architecture name]" nil t)
8262 (insert ")")
8263 (delete-char -1)))
8264 ((equal unit "CONFIGURATION")
3dcb36b7
JB
8265 (vhdl-template-field "library name" "." nil nil nil nil
8266 (vhdl-work-library))
5eabfe72
KH
8267 (vhdl-template-field "configuration name"))
8268 (t (vhdl-template-field "component name"))))
8269 (insert "\n")
d2ddb974 8270 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8271 (setq position (point))
8272 (vhdl-insert-keyword "GENERIC ")
8273 (when (vhdl-template-map position t t)
8274 (insert "\n")
8275 (indent-to (+ margin vhdl-basic-offset)))
8276 (setq position (point))
8277 (vhdl-insert-keyword "PORT ")
8278 (unless (vhdl-template-map position t t)
8279 (kill-line -0)
8280 (delete-char -1))
8281 (insert ";"))))
d2ddb974 8282
5eabfe72
KH
8283(defun vhdl-template-conditional-signal-asst ()
8284 "Insert a conditional signal assignment."
d2ddb974 8285 (interactive)
5eabfe72 8286 (when (vhdl-template-field "target signal")
d2ddb974 8287 (insert " <= ")
5eabfe72
KH
8288; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8289; (insert " "))
d2ddb974 8290 (let ((margin (current-column))
5eabfe72
KH
8291 (start (point))
8292 position)
8293 (vhdl-template-field "waveform")
8294 (setq position (point))
d2ddb974 8295 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8296 (when vhdl-conditions-in-parenthesis (insert "("))
8297 (while (and (vhdl-template-field "[condition]" nil t)
8298 (progn
8299 (when vhdl-conditions-in-parenthesis (insert ")"))
8300 (setq position (point))
8301 (vhdl-insert-keyword " ELSE")
8302 (insert "\n")
8303 (indent-to margin)
8304 (vhdl-template-field "[waveform]" nil t)))
8305 (setq position (point))
d2ddb974 8306 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
8307 (when vhdl-conditions-in-parenthesis (insert "(")))
8308 (delete-region position (point))
d2ddb974 8309 (insert ";")
3dcb36b7 8310 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 8311
5eabfe72
KH
8312(defun vhdl-template-configuration ()
8313 "Insert a configuration specification if within an architecture,
d2ddb974
KH
8314a block or component configuration if within a configuration declaration,
8315a configuration declaration if not within a design unit."
8316 (interactive)
3dcb36b7
JB
8317 (vhdl-prepare-search-1
8318 (cond
8319 ((and (save-excursion ; architecture body
8320 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
8321 (equal "ARCHITECTURE" (upcase (match-string 1))))
8322 (vhdl-template-configuration-spec))
8323 ((and (save-excursion ; configuration declaration
8324 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8325 (equal "CONFIGURATION" (upcase (match-string 1))))
8326 (if (eq (vhdl-decision-query
8327 "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
8328 (vhdl-template-component-conf)
8329 (vhdl-template-block-configuration)))
8330 (t (vhdl-template-configuration-decl))))) ; otherwise
5eabfe72
KH
8331
8332(defun vhdl-template-configuration-spec (&optional optional-use)
8333 "Insert a configuration specification."
d2ddb974 8334 (interactive)
5eabfe72
KH
8335 (let ((margin (current-indentation))
8336 (start (point))
8337 aspect position)
d2ddb974 8338 (vhdl-insert-keyword "FOR ")
3dcb36b7 8339 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
5eabfe72 8340 t start (point))
3dcb36b7 8341 (vhdl-template-field "component name" "\n")
d2ddb974 8342 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8343 (setq start (point))
8344 (vhdl-insert-keyword "USE ")
8345 (if (and optional-use
8346 (not (setq aspect (vhdl-template-field
8347 "[ENTITY | CONFIGURATION | OPEN]" " " t))))
8348 (progn (delete-region start (point)) 'no-use)
8349 (unless optional-use
8350 (setq aspect (vhdl-template-field
8351 "ENTITY | CONFIGURATION | OPEN" " ")))
8352 (setq aspect (upcase (or aspect "")))
8353 (cond ((equal aspect "ENTITY")
3dcb36b7
JB
8354 (vhdl-template-field "library name" "." nil nil nil nil
8355 (vhdl-work-library))
5eabfe72
KH
8356 (vhdl-template-field "entity name" "(")
8357 (if (vhdl-template-field "[architecture name]" nil t)
8358 (insert ")")
d2ddb974 8359 (delete-char -1))
5eabfe72
KH
8360 (insert "\n")
8361 (indent-to (+ margin (* 2 vhdl-basic-offset)))
8362 (setq position (point))
8363 (vhdl-insert-keyword "GENERIC ")
8364 (when (vhdl-template-map position t t)
8365 (insert "\n")
8366 (indent-to (+ margin (* 2 vhdl-basic-offset))))
8367 (setq position (point))
8368 (vhdl-insert-keyword "PORT ")
8369 (unless (vhdl-template-map position t t)
8370 (kill-line -0)
8371 (delete-char -1))
8372 (insert ";")
8373 t)
8374 ((equal aspect "CONFIGURATION")
3dcb36b7
JB
8375 (vhdl-template-field "library name" "." nil nil nil nil
8376 (vhdl-work-library))
5eabfe72 8377 (vhdl-template-field "configuration name" ";"))
3dcb36b7 8378 (t (delete-backward-char 1) (insert ";") t))))))
5eabfe72 8379
d2ddb974 8380
5eabfe72
KH
8381(defun vhdl-template-configuration-decl ()
8382 "Insert a configuration declaration."
d2ddb974 8383 (interactive)
5eabfe72
KH
8384 (let ((margin (current-indentation))
8385 (start (point))
5eabfe72 8386 entity-exists string name position)
d2ddb974 8387 (vhdl-insert-keyword "CONFIGURATION ")
5eabfe72 8388 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974 8389 (vhdl-insert-keyword " OF ")
5eabfe72 8390 (save-excursion
3dcb36b7
JB
8391 (vhdl-prepare-search-1
8392 (setq entity-exists (vhdl-re-search-backward
5eabfe72
KH
8393 "\\<entity \\(\\w*\\) is\\>" nil t))
8394 (setq string (match-string 1))))
d2ddb974 8395 (if (and entity-exists (not (equal string "")))
5eabfe72
KH
8396 (insert string)
8397 (vhdl-template-field "entity name"))
8398 (vhdl-insert-keyword " IS\n")
8399 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8400 (indent-to (+ margin vhdl-basic-offset))
8401 (setq position (point))
8402 (insert "\n")
8403 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
d2ddb974
KH
8404 (indent-to margin)
8405 (vhdl-insert-keyword "END ")
5eabfe72
KH
8406 (unless (vhdl-standard-p '87)
8407 (vhdl-insert-keyword "CONFIGURATION "))
d2ddb974 8408 (insert name ";")
5eabfe72 8409 (goto-char position))))
d2ddb974 8410
5eabfe72
KH
8411(defun vhdl-template-constant ()
8412 "Insert a constant declaration."
8413 (interactive)
8414 (let ((start (point))
8415 (in-arglist (vhdl-in-argument-list-p)))
8416 (vhdl-insert-keyword "CONSTANT ")
8417 (when (vhdl-template-field "name" nil t start (point))
d2ddb974 8418 (insert " : ")
5eabfe72
KH
8419 (when in-arglist (vhdl-insert-keyword "IN "))
8420 (vhdl-template-field "type")
d2ddb974 8421 (if in-arglist
5eabfe72
KH
8422 (progn (insert ";")
8423 (vhdl-comment-insert-inline))
d2ddb974
KH
8424 (let ((position (point)))
8425 (insert " := ")
5eabfe72
KH
8426 (unless (vhdl-template-field "[initialization]" nil t)
8427 (delete-region position (point)))
8428 (insert ";")
8429 (vhdl-comment-insert-inline))))))
d2ddb974 8430
5eabfe72 8431(defun vhdl-template-default ()
d2ddb974
KH
8432 "Insert nothing."
8433 (interactive)
8434 (insert " ")
8435 (unexpand-abbrev)
8436 (backward-word 1)
8437 (vhdl-case-word 1)
5eabfe72 8438 (forward-char 1))
d2ddb974 8439
5eabfe72 8440(defun vhdl-template-default-indent ()
d2ddb974
KH
8441 "Insert nothing and indent."
8442 (interactive)
8443 (insert " ")
8444 (unexpand-abbrev)
8445 (backward-word 1)
8446 (vhdl-case-word 1)
8447 (forward-char 1)
3dcb36b7 8448 (indent-according-to-mode))
d2ddb974 8449
5eabfe72 8450(defun vhdl-template-disconnect ()
d2ddb974
KH
8451 "Insert a disconnect statement."
8452 (interactive)
5eabfe72
KH
8453 (let ((start (point)))
8454 (vhdl-insert-keyword "DISCONNECT ")
8455 (when (vhdl-template-field "signal names | OTHERS | ALL"
8456 " : " t start (point))
8457 (vhdl-template-field "type")
8458 (vhdl-insert-keyword " AFTER ")
8459 (vhdl-template-field "time expression" ";"))))
8460
8461(defun vhdl-template-else ()
d2ddb974
KH
8462 "Insert an else statement."
8463 (interactive)
3dcb36b7
JB
8464 (let (margin)
8465 (vhdl-prepare-search-1
5eabfe72 8466 (vhdl-insert-keyword "ELSE")
3dcb36b7
JB
8467 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
8468 (equal "WHEN" (upcase (match-string 1))))
5eabfe72 8469 (insert " ")
3dcb36b7 8470 (indent-according-to-mode)
5eabfe72
KH
8471 (setq margin (current-indentation))
8472 (insert "\n")
8473 (indent-to (+ margin vhdl-basic-offset))))))
8474
8475(defun vhdl-template-elsif ()
d2ddb974
KH
8476 "Insert an elsif statement."
8477 (interactive)
5eabfe72
KH
8478 (let ((start (point))
8479 margin)
d2ddb974 8480 (vhdl-insert-keyword "ELSIF ")
3dcb36b7
JB
8481 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
8482 (when vhdl-conditions-in-parenthesis (insert "("))
8483 (when (vhdl-template-field "condition" nil t start (point))
8484 (when vhdl-conditions-in-parenthesis (insert ")"))
8485 (indent-according-to-mode)
8486 (setq margin (current-indentation))
8487 (vhdl-insert-keyword
8488 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
8489 (indent-to (+ margin vhdl-basic-offset))))))
d2ddb974 8490
5eabfe72
KH
8491(defun vhdl-template-entity ()
8492 "Insert an entity."
d2ddb974 8493 (interactive)
5eabfe72
KH
8494 (let ((margin (current-indentation))
8495 (start (point))
8496 name end-column)
d2ddb974 8497 (vhdl-insert-keyword "ENTITY ")
5eabfe72 8498 (when (setq name (vhdl-template-field "name" nil t start (point)))
d2ddb974
KH
8499 (vhdl-insert-keyword " IS\n\n")
8500 (indent-to margin)
8501 (vhdl-insert-keyword "END ")
5eabfe72
KH
8502 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
8503 (insert name ";")
8504 (setq end-column (current-column))
d2ddb974
KH
8505 (end-of-line -0)
8506 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8507 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8508 (indent-to (+ margin vhdl-basic-offset))
8509 (when (vhdl-template-generic-list t)
8510 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8511 (insert "\n")
8512 (indent-to (+ margin vhdl-basic-offset))
8513 (when (vhdl-template-port-list t)
8514 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
8515 (beginning-of-line 2)
8516 (forward-char end-column))))
d2ddb974 8517
5eabfe72 8518(defun vhdl-template-exit ()
d2ddb974
KH
8519 "Insert an exit statement."
8520 (interactive)
5eabfe72
KH
8521 (let ((start (point)))
8522 (vhdl-insert-keyword "EXIT ")
3dcb36b7
JB
8523 (if (vhdl-template-field "[loop label]" nil t start (point))
8524 (let ((position (point)))
8525 (vhdl-insert-keyword " WHEN ")
8526 (when vhdl-conditions-in-parenthesis (insert "("))
8527 (if (vhdl-template-field "[condition]" nil t)
8528 (when vhdl-conditions-in-parenthesis (insert ")"))
8529 (delete-region position (point))))
d2ddb974 8530 (delete-char -1))
5eabfe72
KH
8531 (insert ";")))
8532
8533(defun vhdl-template-file ()
8534 "Insert a file declaration."
8535 (interactive)
8536 (let ((start (point)))
8537 (vhdl-insert-keyword "FILE ")
8538 (when (vhdl-template-field "name" nil t start (point))
8539 (insert " : ")
8540 (vhdl-template-field "type")
8541 (unless (vhdl-standard-p '87)
8542 (vhdl-insert-keyword " OPEN ")
8543 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
8544 nil t)
3dcb36b7 8545 (delete-backward-char 6)))
5eabfe72
KH
8546 (vhdl-insert-keyword " IS ")
8547 (when (vhdl-standard-p '87)
8548 (vhdl-template-field "[IN | OUT]" " " t))
8549 (vhdl-template-field "filename-string" nil nil nil nil t)
8550 (insert ";")
8551 (vhdl-comment-insert-inline))))
d2ddb974 8552
5eabfe72
KH
8553(defun vhdl-template-for ()
8554 "Insert a block or component configuration if within a configuration
8555declaration, a configuration specification if within an architecture
3dcb36b7
JB
8556declarative part (and not within a subprogram), a for-loop if within a
8557sequential statement part (subprogram or process), and a for-generate
8558otherwise."
5eabfe72 8559 (interactive)
3dcb36b7
JB
8560 (vhdl-prepare-search-1
8561 (cond
8562 ((vhdl-sequential-statement-p) ; sequential statement
8563 (vhdl-template-for-loop))
8564 ((and (save-excursion ; configuration declaration
8565 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
8566 (equal "CONFIGURATION" (upcase (match-string 1))))
8567 (if (eq (vhdl-decision-query
8568 "for" "(b)lock or (c)omponent configuration?" t) ?c)
8569 (vhdl-template-component-conf)
8570 (vhdl-template-block-configuration)))
8571 ((and (save-excursion
8572 (re-search-backward ; architecture declarative part
8573 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
8574 (equal "ARCHITECTURE" (upcase (match-string 1))))
8575 (vhdl-template-configuration-spec))
8576 (t (vhdl-template-for-generate))))) ; concurrent statement
5eabfe72
KH
8577
8578(defun vhdl-template-for-generate ()
8579 "Insert a for-generate."
d2ddb974 8580 (interactive)
5eabfe72
KH
8581 (let ((margin (current-indentation))
8582 (start (point))
3dcb36b7 8583 label position)
5eabfe72
KH
8584 (vhdl-insert-keyword ": FOR ")
8585 (setq position (point-marker))
8586 (goto-char start)
8587 (when (setq label (vhdl-template-field "label" nil t start position))
8588 (goto-char position)
8589 (vhdl-template-field "loop variable")
8590 (vhdl-insert-keyword " IN ")
8591 (vhdl-template-field "range")
8592 (vhdl-template-generate-body margin label))))
d2ddb974 8593
5eabfe72
KH
8594(defun vhdl-template-for-loop ()
8595 "Insert a for loop."
d2ddb974 8596 (interactive)
5eabfe72
KH
8597 (let ((margin (current-indentation))
8598 (start (point))
8599 label index)
8600 (if (not (eq vhdl-optional-labels 'all))
8601 (vhdl-insert-keyword "FOR ")
8602 (vhdl-insert-keyword ": FOR ")
8603 (goto-char start)
8604 (setq label (vhdl-template-field "[label]" nil t))
8605 (unless label (delete-char 2))
8606 (forward-word 1)
8607 (forward-char 1))
8608 (when (setq index (vhdl-template-field "loop variable"
8609 nil t start (point)))
d2ddb974 8610 (vhdl-insert-keyword " IN ")
5eabfe72 8611 (vhdl-template-field "range")
d2ddb974
KH
8612 (vhdl-insert-keyword " LOOP\n\n")
8613 (indent-to margin)
8614 (vhdl-insert-keyword "END LOOP")
5eabfe72
KH
8615 (if label
8616 (insert " " label ";")
d2ddb974 8617 (insert ";")
5eabfe72 8618 (when vhdl-self-insert-comments (insert " -- " index)))
d2ddb974 8619 (forward-line -1)
5eabfe72 8620 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 8621
5eabfe72
KH
8622(defun vhdl-template-function (&optional kind)
8623 "Insert a function declaration or body."
d2ddb974 8624 (interactive)
5eabfe72
KH
8625 (let ((margin (current-indentation))
8626 (start (point))
8627 name)
8628 (vhdl-insert-keyword "FUNCTION ")
8629 (when (setq name (vhdl-template-field "name" nil t start (point)))
8630 (vhdl-template-argument-list t)
3dcb36b7 8631 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
d2ddb974 8632 (end-of-line)
5eabfe72 8633 (insert "\n")
d2ddb974 8634 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
8635 (vhdl-insert-keyword "RETURN ")
8636 (vhdl-template-field "type")
8637 (if (if kind (eq kind 'body)
8638 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
3dcb36b7 8639 (progn (vhdl-insert-keyword " IS\n")
5eabfe72
KH
8640 (vhdl-template-begin-end
8641 (unless (vhdl-standard-p '87) "FUNCTION") name margin)
8642 (vhdl-comment-block))
8643 (insert ";")))))
8644
8645(defun vhdl-template-function-decl ()
8646 "Insert a function declaration."
8647 (interactive)
8648 (vhdl-template-function 'decl))
d2ddb974 8649
5eabfe72
KH
8650(defun vhdl-template-function-body ()
8651 "Insert a function declaration."
d2ddb974 8652 (interactive)
5eabfe72
KH
8653 (vhdl-template-function 'body))
8654
8655(defun vhdl-template-generate ()
8656 "Insert a generation scheme."
8657 (interactive)
8658 (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
8659 (vhdl-template-if-generate)
8660 (vhdl-template-for-generate)))
d2ddb974 8661
5eabfe72
KH
8662(defun vhdl-template-generic ()
8663 "Insert generic declaration, or generic map in instantiation statements."
8664 (interactive)
3dcb36b7
JB
8665 (let ((start (point)))
8666 (vhdl-prepare-search-1
5eabfe72
KH
8667 (cond
8668 ((and (save-excursion ; entity declaration
8669 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
8670 (equal "ENTITY" (upcase (match-string 1))))
8671 (vhdl-template-generic-list nil))
8672 ((or (save-excursion
8673 (or (beginning-of-line)
8674 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 8675 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
8676 (vhdl-insert-keyword "GENERIC ")
8677 (vhdl-template-map start))
8678 (t (vhdl-template-generic-list nil t))))))
8679
8680(defun vhdl-template-group ()
8681 "Insert group or group template declaration."
8682 (interactive)
8683 (let ((start (point)))
8684 (if (eq (vhdl-decision-query
8685 "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
8686 (vhdl-template-group-template)
8687 (vhdl-template-group-decl))))
8688
8689(defun vhdl-template-group-decl ()
8690 "Insert group declaration."
8691 (interactive)
8692 (let ((start (point)))
8693 (vhdl-insert-keyword "GROUP ")
8694 (when (vhdl-template-field "name" " : " t start (point))
8695 (vhdl-template-field "template name" " (")
8696 (vhdl-template-field "constituent list" ");")
8697 (vhdl-comment-insert-inline))))
8698
8699(defun vhdl-template-group-template ()
8700 "Insert group template declaration."
8701 (interactive)
8702 (let ((start (point)))
8703 (vhdl-insert-keyword "GROUP ")
8704 (when (vhdl-template-field "template name" nil t start (point))
8705 (vhdl-insert-keyword " IS (")
8706 (vhdl-template-field "entity class list" ");")
8707 (vhdl-comment-insert-inline))))
8708
5eabfe72
KH
8709(defun vhdl-template-if ()
8710 "Insert a sequential if statement or an if-generate statement."
8711 (interactive)
8712 (if (vhdl-sequential-statement-p)
8713 (vhdl-template-if-then)
8714 (if (and (vhdl-standard-p 'ams)
8715 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
8716 (vhdl-template-if-use)
8717 (vhdl-template-if-generate))))
8718
8719(defun vhdl-template-if-generate ()
8720 "Insert an if-generate."
8721 (interactive)
8722 (let ((margin (current-indentation))
8723 (start (point))
3dcb36b7 8724 label position)
5eabfe72
KH
8725 (vhdl-insert-keyword ": IF ")
8726 (setq position (point-marker))
8727 (goto-char start)
8728 (when (setq label (vhdl-template-field "label" nil t start position))
8729 (goto-char position)
8730 (when vhdl-conditions-in-parenthesis (insert "("))
8731 (vhdl-template-field "condition")
8732 (when vhdl-conditions-in-parenthesis (insert ")"))
8733 (vhdl-template-generate-body margin label))))
d2ddb974 8734
5eabfe72
KH
8735(defun vhdl-template-if-then-use (kind)
8736 "Insert a sequential if statement."
8737 (interactive)
8738 (let ((margin (current-indentation))
8739 (start (point))
8740 label)
8741 (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
8742 (vhdl-insert-keyword "IF ")
8743 (vhdl-insert-keyword ": IF ")
8744 (goto-char start)
8745 (setq label (vhdl-template-field "[label]" nil t))
8746 (unless label (delete-char 2))
8747 (forward-word 1)
8748 (forward-char 1))
8749 (when vhdl-conditions-in-parenthesis (insert "("))
8750 (when (vhdl-template-field "condition" nil t start (point))
8751 (when vhdl-conditions-in-parenthesis (insert ")"))
8752 (vhdl-insert-keyword
8753 (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
d2ddb974 8754 (indent-to margin)
5eabfe72
KH
8755 (vhdl-insert-keyword "END IF")
8756 (when label (insert " " label))
8757 (insert ";")
d2ddb974 8758 (forward-line -1)
5eabfe72
KH
8759 (indent-to (+ margin vhdl-basic-offset)))))
8760
8761(defun vhdl-template-if-then ()
8762 "Insert a sequential if statement."
8763 (interactive)
8764 (vhdl-template-if-then-use 'then))
8765
8766(defun vhdl-template-if-use ()
8767 "Insert a simultaneous if statement."
8768 (interactive)
8769 (vhdl-template-if-then-use 'use))
8770
8771(defun vhdl-template-instance ()
8772 "Insert a component instantiation statement."
8773 (interactive)
8774 (vhdl-template-component-inst))
d2ddb974 8775
5eabfe72 8776(defun vhdl-template-library ()
d2ddb974
KH
8777 "Insert a library specification."
8778 (interactive)
5eabfe72
KH
8779 (let ((margin (current-indentation))
8780 (start (point))
8781 name end-pos)
d2ddb974 8782 (vhdl-insert-keyword "LIBRARY ")
5eabfe72
KH
8783 (when (setq name (vhdl-template-field "names" nil t start (point)))
8784 (insert ";")
8785 (unless (string-match "," name)
8786 (setq end-pos (point))
8787 (insert "\n")
8788 (indent-to margin)
8789 (vhdl-insert-keyword "USE ")
8790 (insert name)
8791 (vhdl-insert-keyword "..ALL;")
8792 (backward-char 5)
8793 (if (vhdl-template-field "package name")
8794 (forward-char 5)
8795 (delete-region end-pos (+ (point) 5)))))))
8796
8797(defun vhdl-template-limit ()
8798 "Insert a limit."
d2ddb974 8799 (interactive)
5eabfe72
KH
8800 (let ((start (point)))
8801 (vhdl-insert-keyword "LIMIT ")
8802 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
8803 t start (point))
8804 (vhdl-template-field "type")
8805 (vhdl-insert-keyword " WITH ")
8806 (vhdl-template-field "real expression" ";"))))
8807
8808(defun vhdl-template-loop ()
8809 "Insert a loop."
8810 (interactive)
8811 (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
8812 (cond ((eq char ?w)
8813 (vhdl-template-while-loop))
8814 ((eq char ?f)
8815 (vhdl-template-for-loop))
8816 (t (vhdl-template-bare-loop)))))
8817
8818(defun vhdl-template-bare-loop ()
8819 "Insert a loop."
8820 (interactive)
8821 (let ((margin (current-indentation))
8822 (start (point))
8823 label)
8824 (if (not (eq vhdl-optional-labels 'all))
8825 (vhdl-insert-keyword "LOOP ")
8826 (vhdl-insert-keyword ": LOOP ")
8827 (goto-char start)
8828 (setq label (vhdl-template-field "[label]" nil t))
8829 (unless label (delete-char 2))
8830 (forward-word 1)
8831 (delete-char 1))
d2ddb974
KH
8832 (insert "\n\n")
8833 (indent-to margin)
8834 (vhdl-insert-keyword "END LOOP")
5eabfe72 8835 (insert (if label (concat " " label ";") ";"))
d2ddb974 8836 (forward-line -1)
5eabfe72 8837 (indent-to (+ margin vhdl-basic-offset))))
d2ddb974 8838
5eabfe72
KH
8839(defun vhdl-template-map (&optional start optional secondary)
8840 "Insert a map specification with association list."
d2ddb974 8841 (interactive)
5eabfe72
KH
8842 (let ((start (or start (point)))
8843 margin end-pos)
8844 (vhdl-insert-keyword "MAP (")
8845 (if (not vhdl-association-list-with-formals)
8846 (if (vhdl-template-field
8847 (concat (and optional "[") "association list" (and optional "]"))
8848 ")" (or (not secondary) optional)
8849 (and (not secondary) start) (point))
8850 t
8851 (if (and optional secondary) (delete-region start (point)))
8852 nil)
8853 (if vhdl-argument-list-indent
8854 (setq margin (current-column))
8855 (setq margin (+ (current-indentation) vhdl-basic-offset))
8856 (insert "\n")
8857 (indent-to margin))
8858 (if (vhdl-template-field
8859 (concat (and optional "[") "formal" (and optional "]"))
8860 " => " (or (not secondary) optional)
8861 (and (not secondary) start) (point))
8862 (progn
8863 (vhdl-template-field "actual" ",")
8864 (setq end-pos (point))
8865 (insert "\n")
8866 (indent-to margin)
8867 (while (vhdl-template-field "[formal]" " => " t)
8868 (vhdl-template-field "actual" ",")
8869 (setq end-pos (point))
8870 (insert "\n")
8871 (indent-to margin))
8872 (delete-region end-pos (point))
3dcb36b7 8873 (delete-backward-char 1)
5eabfe72 8874 (insert ")")
3dcb36b7 8875 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
8876 t)
8877 (when (and optional secondary) (delete-region start (point)))
8878 nil))))
d2ddb974 8879
5eabfe72 8880(defun vhdl-template-modify (&optional noerror)
d2ddb974
KH
8881 "Actualize modification date."
8882 (interactive)
3dcb36b7
JB
8883 (vhdl-prepare-search-2
8884 (save-excursion
8885 (goto-char (point-min))
8886 (if (re-search-forward vhdl-modify-date-prefix-string nil t)
8887 (progn (delete-region (point) (progn (end-of-line) (point)))
8888 (vhdl-template-insert-date))
8889 (unless noerror
8890 (error (concat "ERROR: Modification date prefix string \""
8891 vhdl-modify-date-prefix-string "\" not found")))))))
5eabfe72
KH
8892
8893(defun vhdl-template-modify-noerror ()
8894 "Call `vhdl-template-modify' with NOERROR non-nil."
8895 (vhdl-template-modify t))
8896
8897(defun vhdl-template-nature ()
8898 "Insert a nature declaration."
8899 (interactive)
8900 (let ((start (point))
8901 name mid-pos end-pos)
8902 (vhdl-insert-keyword "NATURE ")
8903 (when (setq name (vhdl-template-field "name" nil t start (point)))
8904 (vhdl-insert-keyword " IS ")
8905 (let ((definition
8906 (upcase
8907 (or (vhdl-template-field
8908 "across type | ARRAY | RECORD")
8909 ""))))
8910 (cond ((equal definition "")
8911 (insert ";"))
8912 ((equal definition "ARRAY")
8913 (kill-word -1)
8914 (vhdl-template-array 'nature t))
8915 ((equal definition "RECORD")
8916 (setq mid-pos (point-marker))
8917 (kill-word -1)
8918 (vhdl-template-record 'nature name t))
8919 (t
8920 (vhdl-insert-keyword " ACROSS ")
8921 (vhdl-template-field "through type")
8922 (vhdl-insert-keyword " THROUGH ")
8923 (vhdl-template-field "reference name")
8924 (vhdl-insert-keyword " REFERENCE;")))
8925 (when mid-pos
8926 (setq end-pos (point-marker))
8927 (goto-char mid-pos)
8928 (end-of-line))
8929 (vhdl-comment-insert-inline)
8930 (when end-pos (goto-char end-pos))))))
8931
8932(defun vhdl-template-next ()
8933 "Insert a next statement."
d2ddb974 8934 (interactive)
3dcb36b7
JB
8935 (let ((start (point)))
8936 (vhdl-insert-keyword "NEXT ")
8937 (if (vhdl-template-field "[loop label]" nil t start (point))
8938 (let ((position (point)))
8939 (vhdl-insert-keyword " WHEN ")
8940 (when vhdl-conditions-in-parenthesis (insert "("))
8941 (if (vhdl-template-field "[condition]" nil t)
8942 (when vhdl-conditions-in-parenthesis (insert ")"))
8943 (delete-region position (point))))
8944 (delete-char -1))
5eabfe72
KH
8945 (insert ";")))
8946
8947(defun vhdl-template-others ()
8948 "Insert an others aggregate."
8949 (interactive)
3dcb36b7
JB
8950 (let ((start (point)))
8951 (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
8952 (progn (unless vhdl-template-invoked-by-hook (insert "("))
8953 (vhdl-insert-keyword "OTHERS => '")
8954 (when (vhdl-template-field "value" nil t start (point))
8955 (insert "')")))
8956 (vhdl-insert-keyword "OTHERS "))))
d2ddb974 8957
5eabfe72 8958(defun vhdl-template-package (&optional kind)
d2ddb974
KH
8959 "Insert a package specification or body."
8960 (interactive)
5eabfe72
KH
8961 (let ((margin (current-indentation))
8962 (start (point))
8963 name body position)
d2ddb974 8964 (vhdl-insert-keyword "PACKAGE ")
5eabfe72
KH
8965 (setq body (if kind (eq kind 'body)
8966 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
3dcb36b7
JB
8967 (when body
8968 (vhdl-insert-keyword "BODY ")
8969 (when (save-excursion
8970 (vhdl-prepare-search-1
8971 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
8972 (insert (setq name (match-string 1)))))
8973 (when (or name
8974 (setq name (vhdl-template-field "name" nil t start (point))))
5eabfe72
KH
8975 (vhdl-insert-keyword " IS\n")
8976 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8977 (indent-to (+ margin vhdl-basic-offset))
8978 (setq position (point))
8979 (insert "\n")
8980 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
8981 (indent-to margin)
8982 (vhdl-insert-keyword "END ")
8983 (unless (vhdl-standard-p '87)
8984 (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
8985 (insert (or name "") ";")
8986 (goto-char position))))
d2ddb974 8987
5eabfe72
KH
8988(defun vhdl-template-package-decl ()
8989 "Insert a package specification."
d2ddb974 8990 (interactive)
5eabfe72 8991 (vhdl-template-package 'decl))
d2ddb974 8992
5eabfe72
KH
8993(defun vhdl-template-package-body ()
8994 "Insert a package body."
d2ddb974 8995 (interactive)
5eabfe72 8996 (vhdl-template-package 'body))
d2ddb974 8997
5eabfe72
KH
8998(defun vhdl-template-port ()
8999 "Insert a port declaration, or port map in instantiation statements."
d2ddb974 9000 (interactive)
3dcb36b7
JB
9001 (let ((start (point)))
9002 (vhdl-prepare-search-1
5eabfe72
KH
9003 (cond
9004 ((and (save-excursion ; entity declaration
9005 (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
9006 (equal "ENTITY" (upcase (match-string 1))))
9007 (vhdl-template-port-list nil))
9008 ((or (save-excursion
9009 (or (beginning-of-line)
9010 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
3dcb36b7 9011 (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
5eabfe72
KH
9012 (vhdl-insert-keyword "PORT ")
9013 (vhdl-template-map start))
9014 (t (vhdl-template-port-list nil))))))
9015
9016(defun vhdl-template-procedural ()
9017 "Insert a procedural."
9018 (interactive)
9019 (let ((margin (current-indentation))
9020 (start (point))
9021 (case-fold-search t)
9022 label)
9023 (vhdl-insert-keyword "PROCEDURAL ")
9024 (when (memq vhdl-optional-labels '(process all))
9025 (goto-char start)
9026 (insert ": ")
9027 (goto-char start)
9028 (setq label (vhdl-template-field "[label]" nil t))
9029 (unless label (delete-char 2))
9030 (forward-word 1)
9031 (forward-char 1))
9032 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
3dcb36b7 9033 (insert "\n")
5eabfe72
KH
9034 (vhdl-template-begin-end "PROCEDURAL" label margin)
9035 (vhdl-comment-block)))
9036
9037(defun vhdl-template-procedure (&optional kind)
9038 "Insert a procedure declaration or body."
9039 (interactive)
9040 (let ((margin (current-indentation))
9041 (start (point))
9042 name)
9043 (vhdl-insert-keyword "PROCEDURE ")
9044 (when (setq name (vhdl-template-field "name" nil t start (point)))
9045 (vhdl-template-argument-list)
9046 (if (if kind (eq kind 'body)
9047 (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
9048 (progn (vhdl-insert-keyword " IS")
9049 (when vhdl-auto-align
3dcb36b7
JB
9050 (vhdl-align-region-groups start (point) 1))
9051 (end-of-line) (insert "\n")
5eabfe72
KH
9052 (vhdl-template-begin-end
9053 (unless (vhdl-standard-p '87) "PROCEDURE")
9054 name margin)
9055 (vhdl-comment-block))
9056 (insert ";")
3dcb36b7 9057 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
9058 (end-of-line)))))
9059
9060(defun vhdl-template-procedure-decl ()
9061 "Insert a procedure declaration."
9062 (interactive)
9063 (vhdl-template-procedure 'decl))
d2ddb974 9064
5eabfe72
KH
9065(defun vhdl-template-procedure-body ()
9066 "Insert a procedure body."
9067 (interactive)
9068 (vhdl-template-procedure 'body))
9069
9070(defun vhdl-template-process (&optional kind)
9071 "Insert a process."
9072 (interactive)
9073 (let ((margin (current-indentation))
9074 (start (point))
5eabfe72
KH
9075 label seq input-signals clock reset final-pos)
9076 (setq seq (if kind (eq kind 'seq)
9077 (eq (vhdl-decision-query
9078 "process" "(c)ombinational or (s)equential?" t) ?s)))
9079 (vhdl-insert-keyword "PROCESS ")
9080 (when (memq vhdl-optional-labels '(process all))
9081 (goto-char start)
9082 (insert ": ")
9083 (goto-char start)
9084 (setq label (vhdl-template-field "[label]" nil t))
9085 (unless label (delete-char 2))
9086 (forward-word 1)
9087 (forward-char 1))
9088 (insert "(")
9089 (if (not seq)
9090 (unless (setq input-signals
9091 (vhdl-template-field "[sensitivity list]" ")" t))
9092 (setq input-signals "")
9093 (delete-char -2))
9094 (setq clock (or (and (not (equal "" vhdl-clock-name))
9095 (progn (insert vhdl-clock-name) vhdl-clock-name))
9096 (vhdl-template-field "clock name") "<clock>"))
9097 (when (eq vhdl-reset-kind 'async)
9098 (insert ", ")
9099 (setq reset (or (and (not (equal "" vhdl-reset-name))
9100 (progn (insert vhdl-reset-name) vhdl-reset-name))
9101 (vhdl-template-field "reset name") "<reset>")))
9102 (insert ")"))
9103 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
3dcb36b7 9104 (insert "\n")
5eabfe72
KH
9105 (vhdl-template-begin-end "PROCESS" label margin)
9106 (when seq (setq reset (vhdl-template-seq-process clock reset)))
9107 (when vhdl-prompt-for-comments
9108 (setq final-pos (point-marker))
3dcb36b7
JB
9109 (vhdl-prepare-search-2
9110 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
9111 (vhdl-re-search-backward "\\<process\\>" nil t))
5eabfe72
KH
9112 (end-of-line -0)
9113 (if (bobp)
9114 (progn (insert "\n") (forward-line -1))
9115 (insert "\n"))
9116 (indent-to margin)
9117 (insert "-- purpose: ")
9118 (if (not (vhdl-template-field "[description]" nil t))
9119 (vhdl-line-kill-entire)
9120 (insert "\n")
9121 (indent-to margin)
9122 (insert "-- type : ")
9123 (insert (if seq "sequential" "combinational") "\n")
9124 (indent-to margin)
9125 (insert "-- inputs : ")
9126 (if (not seq)
9127 (insert input-signals)
9128 (insert clock ", ")
9129 (when reset (insert reset ", "))
9130 (unless (vhdl-template-field "[signal names]" nil t)
9131 (delete-char -2)))
9132 (insert "\n")
9133 (indent-to margin)
9134 (insert "-- outputs: ")
9135 (vhdl-template-field "[signal names]" nil t))))
9136 (goto-char final-pos))))
9137
9138(defun vhdl-template-process-comb ()
9139 "Insert a combinational process."
9140 (interactive)
9141 (vhdl-template-process 'comb))
9142
9143(defun vhdl-template-process-seq ()
9144 "Insert a sequential process."
9145 (interactive)
9146 (vhdl-template-process 'seq))
9147
9148(defun vhdl-template-quantity ()
9149 "Insert a quantity declaration."
9150 (interactive)
9151 (if (vhdl-in-argument-list-p)
9152 (let ((start (point)))
9153 (vhdl-insert-keyword "QUANTITY ")
9154 (when (vhdl-template-field "names" nil t start (point))
9155 (insert " : ")
9156 (vhdl-template-field "[IN | OUT]" " " t)
9157 (vhdl-template-field "type")
9158 (insert ";")
9159 (vhdl-comment-insert-inline)))
9160 (let ((char (vhdl-decision-query
9161 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
9162 (cond ((eq char ?f) (vhdl-template-quantity-free))
9163 ((eq char ?b) (vhdl-template-quantity-branch))
9164 ((eq char ?s) (vhdl-template-quantity-source))
9165 (t (vhdl-template-undo (point) (point)))))))
9166
9167(defun vhdl-template-quantity-free ()
9168 "Insert a free quantity declaration."
9169 (interactive)
9170 (vhdl-insert-keyword "QUANTITY ")
9171 (vhdl-template-field "names")
9172 (insert " : ")
9173 (vhdl-template-field "type")
9174 (let ((position (point)))
9175 (insert " := ")
9176 (unless (vhdl-template-field "[initialization]" nil t)
9177 (delete-region position (point)))
9178 (insert ";")
9179 (vhdl-comment-insert-inline)))
9180
9181(defun vhdl-template-quantity-branch ()
9182 "Insert a branch quantity declaration."
9183 (interactive)
9184 (let (position)
9185 (vhdl-insert-keyword "QUANTITY ")
9186 (when (vhdl-template-field "[across names]" " " t)
9187 (vhdl-insert-keyword "ACROSS "))
9188 (when (vhdl-template-field "[through names]" " " t)
9189 (vhdl-insert-keyword "THROUGH "))
9190 (vhdl-template-field "plus terminal name")
9191 (setq position (point))
9192 (vhdl-insert-keyword " TO ")
9193 (unless (vhdl-template-field "[minus terminal name]" nil t)
9194 (delete-region position (point)))
9195 (insert ";")
9196 (vhdl-comment-insert-inline)))
9197
9198(defun vhdl-template-quantity-source ()
9199 "Insert a source quantity declaration."
9200 (interactive)
9201 (vhdl-insert-keyword "QUANTITY ")
9202 (vhdl-template-field "names")
9203 (insert " : ")
9204 (vhdl-template-field "type" " ")
9205 (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
9206 (progn (vhdl-insert-keyword "NOISE ")
9207 (vhdl-template-field "power expression"))
9208 (vhdl-insert-keyword "SPECTRUM ")
9209 (vhdl-template-field "magnitude expression" ", ")
9210 (vhdl-template-field "phase expression"))
9211 (insert ";")
9212 (vhdl-comment-insert-inline))
9213
9214(defun vhdl-template-record (kind &optional name secondary)
d2ddb974
KH
9215 "Insert a record type declaration."
9216 (interactive)
9217 (let ((margin (current-column))
9218 (start (point))
9219 (first t))
9220 (vhdl-insert-keyword "RECORD\n")
9221 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9222 (when (or (vhdl-template-field "element names"
9223 nil (not secondary) start (point))
9224 secondary)
9225 (while (or first (vhdl-template-field "[element names]" nil t))
9226 (insert " : ")
9227 (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
9228 (vhdl-comment-insert-inline)
9229 (insert "\n")
d2ddb974 9230 (indent-to (+ margin vhdl-basic-offset))
5eabfe72 9231 (setq first nil))
d2ddb974
KH
9232 (kill-line -0)
9233 (indent-to margin)
5eabfe72
KH
9234 (vhdl-insert-keyword "END RECORD")
9235 (unless (vhdl-standard-p '87) (and name (insert " " name)))
9236 (insert ";")
3dcb36b7 9237 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9238
5eabfe72
KH
9239(defun vhdl-template-report ()
9240 "Insert a report statement."
9241 (interactive)
9242 (let ((start (point)))
9243 (vhdl-insert-keyword "REPORT ")
9244 (if (equal "\"\"" (vhdl-template-field
9245 "string expression" nil t start (point) t))
3dcb36b7 9246 (delete-backward-char 2)
5eabfe72
KH
9247 (setq start (point))
9248 (vhdl-insert-keyword " SEVERITY ")
9249 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
9250 (delete-region start (point)))
9251 (insert ";"))))
9252
9253(defun vhdl-template-return ()
d2ddb974
KH
9254 "Insert a return statement."
9255 (interactive)
3dcb36b7
JB
9256 (let ((start (point)))
9257 (vhdl-insert-keyword "RETURN ")
9258 (unless (vhdl-template-field "[expression]" nil t start (point))
9259 (delete-char -1))
9260 (insert ";")))
d2ddb974 9261
5eabfe72 9262(defun vhdl-template-selected-signal-asst ()
d2ddb974
KH
9263 "Insert a selected signal assignment."
9264 (interactive)
5eabfe72
KH
9265 (let ((margin (current-indentation))
9266 (start (point))
9267 (choices t))
d2ddb974 9268 (let ((position (point)))
5eabfe72 9269 (vhdl-insert-keyword " SELECT ")
d2ddb974
KH
9270 (goto-char position))
9271 (vhdl-insert-keyword "WITH ")
5eabfe72
KH
9272 (when (vhdl-template-field "selector expression"
9273 nil t start (+ (point) 7))
9274 (forward-word 1)
9275 (delete-char 1)
d2ddb974
KH
9276 (insert "\n")
9277 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9278 (vhdl-template-field "target signal" " <= ")
9279; (vhdl-template-field "[GUARDED] [TRANSPORT]")
d2ddb974
KH
9280 (insert "\n")
9281 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9282 (vhdl-template-field "waveform")
9283 (vhdl-insert-keyword " WHEN ")
9284 (vhdl-template-field "choices" ",")
9285 (insert "\n")
9286 (indent-to (+ margin vhdl-basic-offset))
9287 (while (and choices (vhdl-template-field "[waveform]" nil t))
d2ddb974 9288 (vhdl-insert-keyword " WHEN ")
5eabfe72
KH
9289 (if (setq choices (vhdl-template-field "[choices]" "," t))
9290 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
9291 (vhdl-insert-keyword "OTHERS")))
9292 (when choices
d2ddb974
KH
9293 (fixup-whitespace)
9294 (delete-char -2))
9295 (insert ";")
3dcb36b7 9296 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
d2ddb974 9297
5eabfe72 9298(defun vhdl-template-signal ()
d2ddb974
KH
9299 "Insert a signal declaration."
9300 (interactive)
5eabfe72
KH
9301 (let ((start (point))
9302 (in-arglist (vhdl-in-argument-list-p)))
9303 (vhdl-insert-keyword "SIGNAL ")
9304 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9305 (insert " : ")
5eabfe72
KH
9306 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9307 (vhdl-template-field "type")
d2ddb974 9308 (if in-arglist
5eabfe72
KH
9309 (progn (insert ";")
9310 (vhdl-comment-insert-inline))
d2ddb974
KH
9311 (let ((position (point)))
9312 (insert " := ")
5eabfe72
KH
9313 (unless (vhdl-template-field "[initialization]" nil t)
9314 (delete-region position (point)))
9315 (insert ";")
9316 (vhdl-comment-insert-inline))))))
9317
9318(defun vhdl-template-subnature ()
9319 "Insert a subnature declaration."
9320 (interactive)
9321 (let ((start (point))
9322 position)
9323 (vhdl-insert-keyword "SUBNATURE ")
9324 (when (vhdl-template-field "name" nil t start (point))
9325 (vhdl-insert-keyword " IS ")
9326 (vhdl-template-field "nature" " (")
9327 (if (vhdl-template-field "[index range]" nil t)
9328 (insert ")")
9329 (delete-char -2))
9330 (setq position (point))
9331 (vhdl-insert-keyword " TOLERANCE ")
9332 (if (equal "\"\"" (vhdl-template-field "[string expression]"
9333 nil t nil nil t))
9334 (delete-region position (point))
9335 (vhdl-insert-keyword " ACROSS ")
9336 (vhdl-template-field "string expression" nil nil nil nil t)
9337 (vhdl-insert-keyword " THROUGH"))
9338 (insert ";")
9339 (vhdl-comment-insert-inline))))
9340
9341(defun vhdl-template-subprogram-body ()
9342 "Insert a subprogram body."
9343 (interactive)
9344 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9345 (vhdl-template-function-body)
9346 (vhdl-template-procedure-body)))
d2ddb974 9347
5eabfe72
KH
9348(defun vhdl-template-subprogram-decl ()
9349 "Insert a subprogram declaration."
9350 (interactive)
9351 (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
9352 (vhdl-template-function-decl)
9353 (vhdl-template-procedure-decl)))
9354
9355(defun vhdl-template-subtype ()
d2ddb974
KH
9356 "Insert a subtype declaration."
9357 (interactive)
5eabfe72
KH
9358 (let ((start (point)))
9359 (vhdl-insert-keyword "SUBTYPE ")
9360 (when (vhdl-template-field "name" nil t start (point))
9361 (vhdl-insert-keyword " IS ")
9362 (vhdl-template-field "type" " ")
9363 (unless
9364 (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
d2ddb974 9365 (delete-char -1))
5eabfe72
KH
9366 (insert ";")
9367 (vhdl-comment-insert-inline))))
d2ddb974 9368
5eabfe72
KH
9369(defun vhdl-template-terminal ()
9370 "Insert a terminal declaration."
d2ddb974 9371 (interactive)
5eabfe72
KH
9372 (let ((start (point)))
9373 (vhdl-insert-keyword "TERMINAL ")
9374 (when (vhdl-template-field "names" nil t start (point))
9375 (insert " : ")
9376 (vhdl-template-field "nature")
9377 (insert ";")
9378 (vhdl-comment-insert-inline))))
d2ddb974 9379
5eabfe72
KH
9380(defun vhdl-template-type ()
9381 "Insert a type declaration."
9382 (interactive)
9383 (let ((start (point))
9384 name mid-pos end-pos)
9385 (vhdl-insert-keyword "TYPE ")
9386 (when (setq name (vhdl-template-field "name" nil t start (point)))
9387 (vhdl-insert-keyword " IS ")
9388 (let ((definition
9389 (upcase
9390 (or (vhdl-template-field
9391 "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
9392 ""))))
9393 (cond ((equal definition "")
3dcb36b7 9394 (delete-backward-char 4)
5eabfe72
KH
9395 (insert ";"))
9396 ((equal definition "ARRAY")
9397 (kill-word -1)
9398 (vhdl-template-array 'type t))
9399 ((equal definition "RECORD")
9400 (setq mid-pos (point-marker))
9401 (kill-word -1)
9402 (vhdl-template-record 'type name t))
9403 ((equal definition "ACCESS")
9404 (insert " ")
9405 (vhdl-template-field "type" ";"))
9406 ((equal definition "FILE")
9407 (vhdl-insert-keyword " OF ")
9408 (vhdl-template-field "type" ";"))
9409 (t (insert ";")))
9410 (when mid-pos
9411 (setq end-pos (point-marker))
9412 (goto-char mid-pos)
9413 (end-of-line))
9414 (vhdl-comment-insert-inline)
9415 (when end-pos (goto-char end-pos))))))
9416
9417(defun vhdl-template-use ()
d2ddb974
KH
9418 "Insert a use clause."
9419 (interactive)
3dcb36b7
JB
9420 (let ((start (point)))
9421 (vhdl-prepare-search-1
5eabfe72
KH
9422 (vhdl-insert-keyword "USE ")
9423 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
9424 (vhdl-insert-keyword "..ALL;")
9425 (backward-char 6)
9426 (when (vhdl-template-field "library name" nil t start (+ (point) 6))
9427 (forward-char 1)
9428 (vhdl-template-field "package name")
9429 (forward-char 5))))))
9430
9431(defun vhdl-template-variable ()
d2ddb974
KH
9432 "Insert a variable declaration."
9433 (interactive)
5eabfe72 9434 (let ((start (point))
5eabfe72 9435 (in-arglist (vhdl-in-argument-list-p)))
3dcb36b7 9436 (vhdl-prepare-search-2
5eabfe72 9437 (if (or (save-excursion
3dcb36b7 9438 (and (vhdl-re-search-backward
5eabfe72
KH
9439 "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
9440 nil t)
9441 (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
9442 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
9443 (vhdl-insert-keyword "VARIABLE ")
9444 (vhdl-insert-keyword "SHARED VARIABLE ")))
9445 (when (vhdl-template-field "names" nil t start (point))
d2ddb974 9446 (insert " : ")
5eabfe72
KH
9447 (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
9448 (vhdl-template-field "type")
d2ddb974 9449 (if in-arglist
5eabfe72
KH
9450 (progn (insert ";")
9451 (vhdl-comment-insert-inline))
d2ddb974
KH
9452 (let ((position (point)))
9453 (insert " := ")
5eabfe72
KH
9454 (unless (vhdl-template-field "[initialization]" nil t)
9455 (delete-region position (point)))
9456 (insert ";")
9457 (vhdl-comment-insert-inline))))))
d2ddb974 9458
5eabfe72 9459(defun vhdl-template-wait ()
d2ddb974
KH
9460 "Insert a wait statement."
9461 (interactive)
9462 (vhdl-insert-keyword "WAIT ")
5eabfe72
KH
9463 (unless (vhdl-template-field
9464 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
9465 nil t)
9466 (delete-char -1))
9467 (insert ";"))
d2ddb974 9468
5eabfe72 9469(defun vhdl-template-when ()
d2ddb974
KH
9470 "Indent correctly if within a case statement."
9471 (interactive)
9472 (let ((position (point))
5eabfe72 9473 margin)
3dcb36b7 9474 (vhdl-prepare-search-2
5eabfe72 9475 (if (and (= (current-column) (current-indentation))
3dcb36b7 9476 (vhdl-re-search-forward "\\<end\\>" nil t)
5eabfe72
KH
9477 (looking-at "\\s-*\\<case\\>"))
9478 (progn
9479 (setq margin (current-indentation))
9480 (goto-char position)
9481 (delete-horizontal-space)
9482 (indent-to (+ margin vhdl-basic-offset)))
9483 (goto-char position)))
9484 (vhdl-insert-keyword "WHEN ")))
9485
9486(defun vhdl-template-while-loop ()
9487 "Insert a while loop."
d2ddb974 9488 (interactive)
5eabfe72
KH
9489 (let* ((margin (current-indentation))
9490 (start (point))
9491 label)
9492 (if (not (eq vhdl-optional-labels 'all))
9493 (vhdl-insert-keyword "WHILE ")
9494 (vhdl-insert-keyword ": WHILE ")
9495 (goto-char start)
9496 (setq label (vhdl-template-field "[label]" nil t))
9497 (unless label (delete-char 2))
9498 (forward-word 1)
9499 (forward-char 1))
9500 (when vhdl-conditions-in-parenthesis (insert "("))
9501 (when (vhdl-template-field "condition" nil t start (point))
9502 (when vhdl-conditions-in-parenthesis (insert ")"))
d2ddb974
KH
9503 (vhdl-insert-keyword " LOOP\n\n")
9504 (indent-to margin)
9505 (vhdl-insert-keyword "END LOOP")
5eabfe72 9506 (insert (if label (concat " " label ";") ";"))
d2ddb974 9507 (forward-line -1)
5eabfe72 9508 (indent-to (+ margin vhdl-basic-offset)))))
d2ddb974 9509
5eabfe72 9510(defun vhdl-template-with ()
d2ddb974
KH
9511 "Insert a with statement (i.e. selected signal assignment)."
9512 (interactive)
3dcb36b7
JB
9513 (vhdl-prepare-search-1
9514 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
9515 (equal ";" (match-string 1)))
9516 (vhdl-template-selected-signal-asst)
9517 (vhdl-insert-keyword "WITH "))))
5eabfe72
KH
9518
9519;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9520;; Special templates
9521
9522(defun vhdl-template-clocked-wait ()
9523 "Insert a wait statement for rising/falling clock edge."
9524 (interactive)
9525 (let ((start (point))
9526 clock)
9527 (vhdl-insert-keyword "WAIT UNTIL ")
9528 (when (setq clock
9529 (or (and (not (equal "" vhdl-clock-name))
9530 (progn (insert vhdl-clock-name) vhdl-clock-name))
9531 (vhdl-template-field "clock name" nil t start (point))))
9532 (insert "'event")
9533 (vhdl-insert-keyword " AND ")
9534 (insert clock)
9535 (insert
9536 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
9537 (vhdl-comment-insert-inline
9538 (concat (if vhdl-clock-rising-edge "rising" "falling")
9539 " clock edge")))))
9540
9541(defun vhdl-template-seq-process (clock reset)
9542 "Insert a template for the body of a sequential process."
9543 (let ((margin (current-indentation))
9544 position)
d2ddb974 9545 (vhdl-insert-keyword "IF ")
5eabfe72
KH
9546 (when (eq vhdl-reset-kind 'async)
9547 (insert reset " = "
9548 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9549 (vhdl-insert-keyword " THEN")
9550 (vhdl-comment-insert-inline
9551 (concat "asynchronous reset (active "
9552 (if vhdl-reset-active-high "high" "low") ")"))
9553 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9554 (setq position (point))
9555 (insert "\n") (indent-to margin)
9556 (vhdl-insert-keyword "ELSIF "))
9557 (if (eq vhdl-clock-edge-condition 'function)
9558 (insert (if vhdl-clock-rising-edge "rising" "falling")
9559 "_edge(" clock ")")
9560 (insert clock "'event")
9561 (vhdl-insert-keyword " AND ")
9562 (insert clock " = "
9563 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
9564 (vhdl-insert-keyword " THEN")
9565 (vhdl-comment-insert-inline
9566 (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
9567 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9568 (when (eq vhdl-reset-kind 'sync)
9569 (vhdl-insert-keyword "IF ")
9570 (setq reset (or (and (not (equal "" vhdl-reset-name))
9571 (progn (insert vhdl-reset-name) vhdl-reset-name))
9572 (vhdl-template-field "reset name") "<reset>"))
9573 (insert " = "
9574 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
9575 (vhdl-insert-keyword " THEN")
9576 (vhdl-comment-insert-inline
9577 (concat "synchronous reset (active "
9578 (if vhdl-reset-active-high "high" "low") ")"))
9579 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9580 (setq position (point))
9581 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9582 (vhdl-insert-keyword "ELSE")
9583 (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
9584 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
9585 (vhdl-insert-keyword "END IF;"))
9586 (when (eq vhdl-reset-kind 'none)
9587 (setq position (point)))
9588 (insert "\n") (indent-to margin)
d2ddb974 9589 (vhdl-insert-keyword "END IF;")
5eabfe72
KH
9590 (goto-char position)
9591 reset))
d2ddb974 9592
5eabfe72
KH
9593(defun vhdl-template-standard-package (library package)
9594 "Insert specification of a standard package. Include a library
9595specification, if not already there."
3dcb36b7
JB
9596 (let ((margin (current-indentation)))
9597 (unless (equal library "std")
9598 (unless (or (save-excursion
9599 (vhdl-prepare-search-1
9600 (and (not (bobp))
9601 (re-search-backward
9602 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
9603 library "\\|end\\)\\>") nil t)
9604 (match-string 2))))
9605 (equal (downcase library) "work"))
9606 (vhdl-insert-keyword "LIBRARY ")
9607 (insert library ";\n")
9608 (indent-to margin))
9609 (vhdl-insert-keyword "USE ")
9610 (insert library "." package)
9611 (vhdl-insert-keyword ".ALL;"))))
d2ddb974 9612
5eabfe72
KH
9613(defun vhdl-template-package-math-complex ()
9614 "Insert specification of `math_complex' package."
d2ddb974 9615 (interactive)
5eabfe72 9616 (vhdl-template-standard-package "ieee" "math_complex"))
d2ddb974 9617
5eabfe72
KH
9618(defun vhdl-template-package-math-real ()
9619 "Insert specification of `math_real' package."
d2ddb974 9620 (interactive)
5eabfe72 9621 (vhdl-template-standard-package "ieee" "math_real"))
d2ddb974 9622
5eabfe72
KH
9623(defun vhdl-template-package-numeric-bit ()
9624 "Insert specification of `numeric_bit' package."
d2ddb974 9625 (interactive)
5eabfe72 9626 (vhdl-template-standard-package "ieee" "numeric_bit"))
d2ddb974 9627
5eabfe72
KH
9628(defun vhdl-template-package-numeric-std ()
9629 "Insert specification of `numeric_std' package."
d2ddb974 9630 (interactive)
5eabfe72 9631 (vhdl-template-standard-package "ieee" "numeric_std"))
d2ddb974 9632
5eabfe72
KH
9633(defun vhdl-template-package-std-logic-1164 ()
9634 "Insert specification of `std_logic_1164' package."
9635 (interactive)
9636 (vhdl-template-standard-package "ieee" "std_logic_1164"))
d2ddb974 9637
5eabfe72
KH
9638(defun vhdl-template-package-std-logic-arith ()
9639 "Insert specification of `std_logic_arith' package."
9640 (interactive)
9641 (vhdl-template-standard-package "ieee" "std_logic_arith"))
9642
9643(defun vhdl-template-package-std-logic-misc ()
9644 "Insert specification of `std_logic_misc' package."
9645 (interactive)
9646 (vhdl-template-standard-package "ieee" "std_logic_misc"))
9647
9648(defun vhdl-template-package-std-logic-signed ()
9649 "Insert specification of `std_logic_signed' package."
9650 (interactive)
9651 (vhdl-template-standard-package "ieee" "std_logic_signed"))
d2ddb974 9652
5eabfe72
KH
9653(defun vhdl-template-package-std-logic-textio ()
9654 "Insert specification of `std_logic_textio' package."
9655 (interactive)
9656 (vhdl-template-standard-package "ieee" "std_logic_textio"))
9657
9658(defun vhdl-template-package-std-logic-unsigned ()
9659 "Insert specification of `std_logic_unsigned' package."
9660 (interactive)
9661 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
9662
9663(defun vhdl-template-package-textio ()
9664 "Insert specification of `textio' package."
9665 (interactive)
9666 (vhdl-template-standard-package "std" "textio"))
9667
9668(defun vhdl-template-directive (directive)
9669 "Insert directive."
9670 (unless (= (current-indentation) (current-column))
9671 (delete-horizontal-space)
9672 (insert " "))
9673 (insert "-- pragma " directive))
9674
9675(defun vhdl-template-directive-translate-on ()
9676 "Insert directive 'translate_on'."
9677 (interactive)
9678 (vhdl-template-directive "translate_on"))
9679
9680(defun vhdl-template-directive-translate-off ()
9681 "Insert directive 'translate_off'."
9682 (interactive)
9683 (vhdl-template-directive "translate_off"))
9684
9685(defun vhdl-template-directive-synthesis-on ()
9686 "Insert directive 'synthesis_on'."
9687 (interactive)
9688 (vhdl-template-directive "synthesis_on"))
9689
9690(defun vhdl-template-directive-synthesis-off ()
9691 "Insert directive 'synthesis_off'."
9692 (interactive)
9693 (vhdl-template-directive "synthesis_off"))
9694
3dcb36b7
JB
9695;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9696;; Header and footer templates
9697
9698(defun vhdl-template-header (&optional file-title)
9699 "Insert a VHDL file header."
9700 (interactive)
9701 (unless (equal vhdl-file-header "")
9702 (let (pos)
9703 (save-excursion
9704 (goto-char (point-min))
9705 (vhdl-insert-string-or-file vhdl-file-header)
9706 (setq pos (point-marker)))
9707 (vhdl-template-replace-header-keywords
9708 (point-min-marker) pos file-title))))
9709
9710(defun vhdl-template-footer ()
9711 "Insert a VHDL file footer."
9712 (interactive)
9713 (unless (equal vhdl-file-footer "")
9714 (let (pos)
9715 (save-excursion
9716 (goto-char (point-max))
9717 (setq pos (point-marker))
9718 (vhdl-insert-string-or-file vhdl-file-footer)
9719 (unless (= (preceding-char) ?\n)
9720 (insert "\n")))
9721 (vhdl-template-replace-header-keywords pos (point-max-marker)))))
9722
9723(defun vhdl-template-replace-header-keywords (beg end &optional file-title
9724 is-model)
9725 "Replace keywords in header and footer."
9726 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
9727 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
9728 pos)
9729 (vhdl-prepare-search-2
9730 (save-excursion
9731 (goto-char beg)
9732 (while (search-forward "<projectdesc>" end t)
9733 (replace-match project-desc t t))
9734 (goto-char beg)
9735 (while (search-forward "<filename>" end t)
9736 (replace-match (buffer-name) t t))
9737 (goto-char beg)
9738 (while (search-forward "<copyright>" end t)
9739 (replace-match vhdl-copyright-string t t))
9740 (goto-char beg)
9741 (while (search-forward "<author>" end t)
9742 (replace-match "" t t)
9743 (insert (user-full-name))
9744 (when user-mail-address (insert " <" user-mail-address ">")))
9745 (goto-char beg)
9746 (while (search-forward "<login>" end t)
9747 (replace-match (user-login-name) t t))
9748 (goto-char beg)
9749 (while (search-forward "<project>" end t)
9750 (replace-match project-title t t))
9751 (goto-char beg)
9752 (while (search-forward "<company>" end t)
9753 (replace-match vhdl-company-name t t))
9754 (goto-char beg)
9755 (while (search-forward "<platform>" end t)
9756 (replace-match vhdl-platform-spec t t))
9757 (goto-char beg)
9758 (while (search-forward "<standard>" end t)
9759 (replace-match
9760 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
9761 ((vhdl-standard-p '93) "'93"))
9762 (when (vhdl-standard-p 'ams) ", VHDL-AMS")
9763 (when (vhdl-standard-p 'math) ", Math Packages")) t t))
9764 (goto-char beg)
9765 ;; Replace <RCS> with $, so that RCS for the source is
9766 ;; not over-enthusiastic with replacements
9767 (while (search-forward "<RCS>" end t)
9768 (replace-match "$" nil t))
9769 (goto-char beg)
9770 (while (search-forward "<date>" end t)
9771 (replace-match "" t t)
9772 (vhdl-template-insert-date))
9773 (goto-char beg)
9774 (while (search-forward "<year>" end t)
9775 (replace-match (format-time-string "%Y" nil) t t))
9776 (goto-char beg)
9777 (when file-title
9778 (while (search-forward "<title string>" end t)
9779 (replace-match file-title t t))
9780 (goto-char beg))
9781 (let (string)
9782 (while
9783 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
9784 (setq string (read-string (concat (match-string 1) ": ")))
9785 (replace-match string t t)))
9786 (goto-char beg)
9787 (when (and (not is-model) (search-forward "<cursor>" end t))
9788 (replace-match "" t t)
9789 (setq pos (point))))
9790 (when pos (goto-char pos))
9791 (unless is-model
9792 (when (or (not project-title) (equal project-title ""))
9793 (message "You can specify a project title in user option `vhdl-project-alist'"))
9794 (when (or (not project-desc) (equal project-desc ""))
9795 (message "You can specify a project description in user option `vhdl-project-alist'"))
9796 (when (equal vhdl-platform-spec "")
9797 (message "You can specify a platform in user option `vhdl-platform-spec'"))
9798 (when (equal vhdl-company-name "")
9799 (message "You can specify a company name in user option `vhdl-company-name'"))))))
9800
5eabfe72
KH
9801;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9802;; Comment templates and functions
9803
9804(defun vhdl-comment-indent ()
9805 "Indent comments."
9806 (let* ((position (point))
9807 (col
9808 (progn
9809 (forward-line -1)
9810 (if (re-search-forward "--" position t)
9811 (- (current-column) 2) ; existing comment at bol stays there
9812 (goto-char position)
9813 (skip-chars-backward " \t")
9814 (max comment-column ; else indent to comment column
9815 (1+ (current-column))))))) ; except leave at least one space
9816 (goto-char position)
9817 col))
9818
9819(defun vhdl-comment-insert ()
d2ddb974 9820 "Start a comment at the end of the line.
5eabfe72
KH
9821If on line with code, indent at least `comment-column'.
9822If starting after end-comment-column, start a new line."
d2ddb974 9823 (interactive)
5eabfe72
KH
9824 (when (> (current-column) end-comment-column) (newline-and-indent))
9825 (if (or (looking-at "\\s-*$") ; end of line
d2ddb974
KH
9826 (and (not unread-command-events) ; called with key binding or menu
9827 (not (end-of-line))))
5eabfe72
KH
9828 (let (margin)
9829 (while (= (preceding-char) ?-) (delete-char -1))
d2ddb974 9830 (setq margin (current-column))
5eabfe72
KH
9831 (delete-horizontal-space)
9832 (if (bolp)
9833 (progn (indent-to margin) (insert "--"))
d2ddb974 9834 (insert " ")
5eabfe72
KH
9835 (indent-to comment-column)
9836 (insert "--"))
d2ddb974 9837 (if (not unread-command-events) (insert " ")))
5eabfe72 9838 ;; else code following current point implies commenting out code
d2ddb974
KH
9839 (let (next-input code)
9840 (while (= (preceding-char) ?-) (delete-char -2))
9841 (while (= (setq next-input (read-char)) 13) ; CR
5eabfe72 9842 (insert "--") ; or have a space after it?
d2ddb974
KH
9843 (forward-char -2)
9844 (forward-line 1)
9845 (message "Enter CR if commenting out a line of code.")
5eabfe72 9846 (setq code t))
3dcb36b7 9847 (unless code
5eabfe72 9848 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
d2ddb974 9849 (setq unread-command-events
5eabfe72 9850 (list (vhdl-character-to-event next-input)))))) ; pushback the char
d2ddb974 9851
5eabfe72 9852(defun vhdl-comment-display (&optional line-exists)
d2ddb974
KH
9853 "Add 2 comment lines at the current indent, making a display comment."
9854 (interactive)
5eabfe72 9855 (let ((margin (current-indentation)))
3dcb36b7 9856 (unless line-exists (vhdl-comment-display-line))
5eabfe72
KH
9857 (insert "\n") (indent-to margin)
9858 (insert "\n") (indent-to margin)
9859 (vhdl-comment-display-line)
9860 (end-of-line -0)
9861 (insert "-- ")))
9862
9863(defun vhdl-comment-display-line ()
d2ddb974
KH
9864 "Displays one line of dashes."
9865 (interactive)
9866 (while (= (preceding-char) ?-) (delete-char -2))
9867 (let* ((col (current-column))
9868 (len (- end-comment-column col)))
5eabfe72 9869 (insert-char ?- len)))
d2ddb974 9870
5eabfe72
KH
9871(defun vhdl-comment-append-inline ()
9872 "Append empty inline comment to current line."
9873 (interactive)
9874 (end-of-line)
9875 (delete-horizontal-space)
9876 (insert " ")
9877 (indent-to comment-column)
9878 (insert "-- "))
9879
9880(defun vhdl-comment-insert-inline (&optional string always-insert)
9881 "Insert inline comment."
9882 (when (or (and string (or vhdl-self-insert-comments always-insert))
9883 (and (not string) vhdl-prompt-for-comments))
9884 (let ((position (point)))
9885 (insert " ")
9886 (indent-to comment-column)
9887 (insert "-- ")
3dcb36b7
JB
9888 (if (not (or (and string (progn (insert string) t))
9889 (vhdl-template-field "[comment]" nil t)))
9890 (delete-region position (point))
9891 (while (= (preceding-char) ? ) (delete-backward-char 1))
9892; (when (> (current-column) end-comment-column)
9893; (setq position (point-marker))
9894; (re-search-backward "-- ")
9895; (insert "\n")
9896; (indent-to comment-column)
9897; (goto-char position))
9898 ))))
5eabfe72
KH
9899
9900(defun vhdl-comment-block ()
9901 "Insert comment for code block."
9902 (when vhdl-prompt-for-comments
3dcb36b7
JB
9903 (let ((final-pos (point-marker)))
9904 (vhdl-prepare-search-2
5eabfe72 9905 (when (and (re-search-backward "^\\s-*begin\\>" nil t)
3dcb36b7 9906 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
5eabfe72
KH
9907 (let (margin)
9908 (back-to-indentation)
9909 (setq margin (current-column))
9910 (end-of-line -0)
9911 (if (bobp)
9912 (progn (insert "\n") (forward-line -1))
9913 (insert "\n"))
9914 (indent-to margin)
9915 (insert "-- purpose: ")
9916 (unless (vhdl-template-field "[description]" nil t)
9917 (vhdl-line-kill-entire)))))
9918 (goto-char final-pos))))
d2ddb974
KH
9919
9920(defun vhdl-comment-uncomment-region (beg end &optional arg)
5eabfe72 9921 "Comment out region if not commented out, uncomment otherwise."
d2ddb974 9922 (interactive "r\nP")
5eabfe72
KH
9923 (save-excursion
9924 (goto-char (1- end))
9925 (end-of-line)
9926 (setq end (point-marker))
9927 (goto-char beg)
9928 (beginning-of-line)
9929 (setq beg (point))
9930 (if (looking-at comment-start)
3dcb36b7 9931 (comment-region beg end '(4))
5eabfe72
KH
9932 (comment-region beg end))))
9933
9934(defun vhdl-comment-uncomment-line (&optional arg)
9935 "Comment out line if not commented out, uncomment otherwise."
d2ddb974 9936 (interactive "p")
5eabfe72
KH
9937 (save-excursion
9938 (beginning-of-line)
9939 (let ((position (point)))
9940 (forward-line (or arg 1))
9941 (vhdl-comment-uncomment-region position (point)))))
d2ddb974 9942
5eabfe72
KH
9943(defun vhdl-comment-kill-region (beg end)
9944 "Kill comments in region."
9945 (interactive "r")
9946 (save-excursion
9947 (goto-char end)
9948 (setq end (point-marker))
9949 (goto-char beg)
9950 (beginning-of-line)
9951 (while (< (point) end)
9952 (if (looking-at "^\\(\\s-*--.*\n\\)")
9953 (progn (delete-region (match-beginning 1) (match-end 1)))
9954 (beginning-of-line 2)))))
9955
9956(defun vhdl-comment-kill-inline-region (beg end)
9957 "Kill inline comments in region."
9958 (interactive "r")
9959 (save-excursion
9960 (goto-char end)
9961 (setq end (point-marker))
9962 (goto-char beg)
9963 (beginning-of-line)
9964 (while (< (point) end)
9965 (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
9966 (delete-region (match-beginning 1) (match-end 1)))
9967 (beginning-of-line 2))))
9968
9969;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9970;; Subtemplates
9971
9972(defun vhdl-template-begin-end (construct name margin &optional empty-lines)
d2ddb974
KH
9973 "Insert a begin ... end pair with optional name after the end.
9974Point is left between them."
5eabfe72 9975 (let (position)
5eabfe72 9976 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
9977 (indent-to margin)
9978 (vhdl-insert-keyword "BEGIN")
5eabfe72
KH
9979 (when (and (or construct name) vhdl-self-insert-comments)
9980 (insert " --")
9981 (when construct (insert " ") (vhdl-insert-keyword construct))
9982 (when name (insert " " name)))
d2ddb974 9983 (insert "\n")
5eabfe72 9984 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974 9985 (indent-to (+ margin vhdl-basic-offset))
5eabfe72
KH
9986 (setq position (point))
9987 (insert "\n")
9988 (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
d2ddb974
KH
9989 (indent-to margin)
9990 (vhdl-insert-keyword "END")
5eabfe72
KH
9991 (when construct (insert " ") (vhdl-insert-keyword construct))
9992 (insert (if name (concat " " name) "") ";")
9993 (goto-char position)))
d2ddb974 9994
5eabfe72 9995(defun vhdl-template-argument-list (&optional is-function)
d2ddb974
KH
9996 "Read from user a procedure or function argument list."
9997 (insert " (")
d2ddb974 9998 (let ((margin (current-column))
5eabfe72
KH
9999 (start (point))
10000 (end-pos (point))
10001 not-empty interface semicolon-pos)
3dcb36b7 10002 (unless vhdl-argument-list-indent
5eabfe72
KH
10003 (setq margin (+ (current-indentation) vhdl-basic-offset))
10004 (insert "\n")
10005 (indent-to margin))
10006 (setq interface (vhdl-template-field
10007 (concat "[CONSTANT | SIGNAL"
10008 (unless is-function " | VARIABLE") "]") " " t))
10009 (while (vhdl-template-field "[names]" nil t)
10010 (setq not-empty t)
10011 (insert " : ")
3dcb36b7 10012 (unless is-function
5eabfe72
KH
10013 (if (and interface (equal (upcase interface) "CONSTANT"))
10014 (vhdl-insert-keyword "IN ")
10015 (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
10016 (vhdl-template-field "type")
10017 (setq semicolon-pos (point))
10018 (insert ";")
10019 (vhdl-comment-insert-inline)
10020 (setq end-pos (point))
10021 (insert "\n")
10022 (indent-to margin)
10023 (setq interface (vhdl-template-field
10024 (concat "[CONSTANT | SIGNAL"
10025 (unless is-function " | VARIABLE") "]") " " t)))
10026 (delete-region end-pos (point))
10027 (when semicolon-pos (goto-char semicolon-pos))
10028 (if not-empty
10029 (progn (delete-char 1) (insert ")"))
3dcb36b7 10030 (delete-backward-char 2))))
5eabfe72
KH
10031
10032(defun vhdl-template-generic-list (optional &optional no-value)
d2ddb974 10033 "Read from user a generic spec argument list."
5eabfe72 10034 (let (margin
d2ddb974 10035 (start (point)))
5eabfe72
KH
10036 (vhdl-insert-keyword "GENERIC (")
10037 (setq margin (current-column))
3dcb36b7 10038 (unless vhdl-argument-list-indent
5eabfe72
KH
10039 (let ((position (point)))
10040 (back-to-indentation)
10041 (setq margin (+ (current-column) vhdl-basic-offset))
10042 (goto-char position)
10043 (insert "\n")
10044 (indent-to margin)))
10045 (let ((vhdl-generics (vhdl-template-field
10046 (concat (and optional "[") "name"
10047 (and no-value "s") (and optional "]"))
10048 nil optional)))
10049 (if (not vhdl-generics)
d2ddb974 10050 (if optional
5eabfe72 10051 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10052 (unless vhdl-argument-list-indent
5eabfe72
KH
10053 (vhdl-line-kill-entire) (end-of-line -0)))
10054 (vhdl-template-undo start (point))
d2ddb974
KH
10055 nil )
10056 (insert " : ")
5eabfe72
KH
10057 (let (semicolon-pos end-pos)
10058 (while vhdl-generics
10059 (vhdl-template-field "type")
10060 (if no-value
10061 (progn (setq semicolon-pos (point))
10062 (insert ";"))
10063 (insert " := ")
10064 (unless (vhdl-template-field "[value]" nil t)
10065 (delete-char -4))
10066 (setq semicolon-pos (point))
10067 (insert ";"))
10068 (vhdl-comment-insert-inline)
10069 (setq end-pos (point))
10070 (insert "\n")
10071 (indent-to margin)
10072 (setq vhdl-generics (vhdl-template-field
10073 (concat "[name" (and no-value "s") "]")
10074 " : " t)))
10075 (delete-region end-pos (point))
10076 (goto-char semicolon-pos)
10077 (insert ")")
10078 (end-of-line)
3dcb36b7 10079 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
5eabfe72
KH
10080 t)))))
10081
10082(defun vhdl-template-port-list (optional)
10083 "Read from user a port spec argument list."
10084 (let ((start (point))
10085 margin vhdl-ports object)
10086 (vhdl-insert-keyword "PORT (")
10087 (setq margin (current-column))
3dcb36b7 10088 (unless vhdl-argument-list-indent
5eabfe72
KH
10089 (let ((position (point)))
10090 (back-to-indentation)
10091 (setq margin (+ (current-column) vhdl-basic-offset))
10092 (goto-char position)
10093 (insert "\n")
10094 (indent-to margin)))
10095 (when (vhdl-standard-p 'ams)
10096 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10097 " " t)))
10098 (setq vhdl-ports (vhdl-template-field
10099 (concat (and optional "[") "names" (and optional "]"))
10100 nil optional))
10101 (if (not vhdl-ports)
10102 (if optional
10103 (progn (vhdl-line-kill-entire) (end-of-line -0)
3dcb36b7 10104 (unless vhdl-argument-list-indent
5eabfe72
KH
10105 (vhdl-line-kill-entire) (end-of-line -0)))
10106 (vhdl-template-undo start (point))
10107 nil)
10108 (insert " : ")
10109 (let (semicolon-pos end-pos)
10110 (while vhdl-ports
10111 (cond ((or (null object) (equal "SIGNAL" (upcase object)))
10112 (vhdl-template-field "IN | OUT | INOUT" " "))
10113 ((equal "QUANTITY" (upcase object))
10114 (vhdl-template-field "[IN | OUT]" " " t)))
10115 (vhdl-template-field
10116 (if (and object (equal "TERMINAL" (upcase object)))
10117 "nature" "type"))
10118 (setq semicolon-pos (point))
10119 (insert ";")
10120 (vhdl-comment-insert-inline)
10121 (setq end-pos (point))
10122 (insert "\n")
10123 (indent-to margin)
10124 (when (vhdl-standard-p 'ams)
10125 (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10126 " " t)))
10127 (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
10128 (delete-region end-pos (point))
10129 (goto-char semicolon-pos)
10130 (insert ")")
10131 (end-of-line)
3dcb36b7 10132 (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
5eabfe72
KH
10133 t))))
10134
10135(defun vhdl-template-generate-body (margin label)
10136 "Insert body for generate template."
10137 (vhdl-insert-keyword " GENERATE")
3dcb36b7
JB
10138; (if (not (vhdl-standard-p '87))
10139; (vhdl-template-begin-end "GENERATE" label margin)
10140 (insert "\n\n")
10141 (indent-to margin)
10142 (vhdl-insert-keyword "END GENERATE ")
10143 (insert label ";")
10144 (end-of-line 0)
10145 (indent-to (+ margin vhdl-basic-offset)))
5eabfe72
KH
10146
10147(defun vhdl-template-insert-date ()
d2ddb974
KH
10148 "Insert date in appropriate format."
10149 (interactive)
5eabfe72
KH
10150 (insert
10151 (cond
3dcb36b7 10152 ;; 'american, 'european, 'scientific kept for backward compatibility
5eabfe72
KH
10153 ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
10154 ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
10155 ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
10156 (t (format-time-string vhdl-date-format nil)))))
10157
10158;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10159;; Help functions
10160
10161(defun vhdl-electric-space (count)
10162 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10163if in comment and past end-comment-column."
10164 (interactive "p")
10165 (cond ((vhdl-in-comment-p)
10166 (self-insert-command count)
10167 (cond ((>= (current-column) (+ 2 end-comment-column))
3dcb36b7
JB
10168 (backward-char 1)
10169 (skip-chars-backward "^ \t\n")
5eabfe72 10170 (indent-new-comment-line)
3dcb36b7 10171 (skip-chars-forward "^ \t\n")
5eabfe72
KH
10172 (forward-char 1))
10173 ((>= (current-column) end-comment-column)
10174 (indent-new-comment-line))
10175 (t nil)))
10176 ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
10177 (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
3dcb36b7
JB
10178 (vhdl-prepare-search-1
10179 (or (expand-abbrev) (vhdl-fix-case-word -1)))
5eabfe72
KH
10180 (self-insert-command count))
10181 (t (self-insert-command count))))
10182
10183(defun vhdl-template-field (prompt &optional follow-string optional
10184 begin end is-string default)
10185 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10186If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10187an empty string is inserted, return nil and call `vhdl-template-undo' for
10188the region between BEGIN and END. IS-STRING indicates whether a string
10189with double-quotes is to be inserted. DEFAULT specifies a default string."
10190 (let ((position (point))
10191 string)
10192 (insert "<" prompt ">")
10193 (setq string
10194 (condition-case ()
10195 (read-from-minibuffer (concat prompt ": ")
10196 (or (and is-string '("\"\"" . 2)) default)
10197 vhdl-minibuffer-local-map)
10198 (quit (if (and optional begin end)
10199 (progn (beep) "")
10200 (keyboard-quit)))))
10201 (when (or (not (equal string "")) optional)
10202 (delete-region position (point)))
10203 (when (and (equal string "") optional begin end)
10204 (vhdl-template-undo begin end)
10205 (message "Template aborted"))
3dcb36b7 10206 (unless (equal string "")
5eabfe72
KH
10207 (insert string)
10208 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
3dcb36b7
JB
10209 vhdl-keywords-regexp)
10210 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
10211 vhdl-types-regexp)
10212 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
10213 (concat "'" vhdl-attributes-regexp))
10214 (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
10215 vhdl-enum-values-regexp))
5eabfe72
KH
10216 (when (or (not (equal string "")) (not optional))
10217 (insert (or follow-string "")))
10218 (if (equal string "") nil string)))
10219
10220(defun vhdl-decision-query (string prompt &optional optional)
10221 "Query a decision from the user."
10222 (let ((start (point)))
10223 (when string (vhdl-insert-keyword (concat string " ")))
10224 (message prompt)
10225 (let ((char (read-char)))
10226 (delete-region start (point))
10227 (if (and optional (eq char ?\r))
10228 (progn (insert " ")
10229 (unexpand-abbrev)
3dcb36b7 10230 (throw 'abort "ERROR: Template aborted"))
5eabfe72 10231 char))))
d2ddb974
KH
10232
10233(defun vhdl-insert-keyword (keyword)
5eabfe72
KH
10234 "Insert KEYWORD and adjust case."
10235 (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
d2ddb974
KH
10236
10237(defun vhdl-case-keyword (keyword)
5eabfe72
KH
10238 "Adjust case of KEYWORD."
10239 (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
d2ddb974
KH
10240
10241(defun vhdl-case-word (num)
5eabfe72
KH
10242 "Adjust case or following NUM words."
10243 (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
10244
10245(defun vhdl-minibuffer-tab (&optional prefix-arg)
10246 "If preceeding character is part of a word or a paren then hippie-expand,
3dcb36b7 10247else insert tab (used for word completion in VHDL minibuffer)."
5eabfe72 10248 (interactive "P")
3dcb36b7
JB
10249 (cond
10250 ;; expand word
10251 ((= (char-syntax (preceding-char)) ?w)
10252 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10253 (case-replace nil)
10254 (hippie-expand-only-buffers
10255 (or (and (boundp 'hippie-expand-only-buffers)
10256 hippie-expand-only-buffers)
10257 '(vhdl-mode))))
10258 (vhdl-expand-abbrev prefix-arg)))
10259 ;; expand parenthesis
10260 ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
10261 (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
10262 (case-replace nil))
10263 (vhdl-expand-paren prefix-arg)))
10264 ;; insert tab
10265 (t (insert-tab))))
5eabfe72
KH
10266
10267(defun vhdl-template-search-prompt ()
10268 "Search for left out template prompts and query again."
10269 (interactive)
3dcb36b7
JB
10270 (vhdl-prepare-search-2
10271 (when (or (re-search-forward
10272 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
10273 (re-search-backward
10274 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
10275 (let ((string (match-string 1)))
10276 (replace-match "")
10277 (vhdl-template-field string)))))
5eabfe72
KH
10278
10279(defun vhdl-template-undo (begin end)
10280 "Undo aborted template by deleting region and unexpanding the keyword."
10281 (cond (vhdl-template-invoked-by-hook
10282 (goto-char end)
10283 (insert " ")
10284 (delete-region begin end)
10285 (unexpand-abbrev))
10286 (t (delete-region begin end))))
10287
10288(defun vhdl-insert-string-or-file (string)
10289 "Insert STRING or file contents if STRING is an existing file name."
10290 (unless (equal string "")
3dcb36b7
JB
10291 (let ((file-name
10292 (progn (string-match "^\\([^\n]+\\)" string)
10293 (vhdl-resolve-env-variable (match-string 1 string)))))
10294 (if (file-exists-p file-name)
10295 (forward-char (cadr (insert-file-contents file-name)))
10296 (insert string)))))
10297
10298(defun vhdl-beginning-of-block ()
10299 "Move cursor to the beginning of the enclosing block."
10300 (let (pos)
10301 (save-excursion
10302 (beginning-of-line)
10303 ;; search backward for block beginning or end
10304 (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))
10305 ;; not consider subprogram declarations
10306 (or (and (match-string 5)
10307 (save-match-data
10308 (save-excursion
10309 (goto-char (match-end 5))
10310 (forward-word 1) (forward-sexp)
10311 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10312 (match-string 1)))
10313 ;; not consider configuration specifications
10314 (and (match-string 6)
10315 (save-match-data
10316 (save-excursion
10317 (vhdl-end-of-block)
10318 (beginning-of-line)
10319 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10320 (match-string 2))
10321 ;; skip subblock if block end found
10322 (vhdl-beginning-of-block)))
10323 (when pos (goto-char pos))))
10324
10325(defun vhdl-end-of-block ()
10326 "Move cursor to the end of the enclosing block."
10327 (let (pos)
10328 (save-excursion
10329 (end-of-line)
10330 ;; search forward for block beginning or end
10331 (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))
10332 ;; not consider subprogram declarations
10333 (or (and (match-string 5)
10334 (save-match-data
10335 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
10336 (match-string 1)))
10337 ;; not consider configuration specifications
10338 (and (match-string 6)
10339 (save-match-data
10340 (save-excursion
10341 (vhdl-end-of-block)
10342 (beginning-of-line)
10343 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
10344 (not (match-string 2)))
10345 ;; skip subblock if block beginning found
10346 (vhdl-end-of-block)))
10347 (when pos (goto-char pos))))
5eabfe72
KH
10348
10349(defun vhdl-sequential-statement-p ()
10350 "Check if point is within sequential statement part."
3dcb36b7
JB
10351 (let ((start (point)))
10352 (save-excursion
10353 (vhdl-prepare-search-2
10354 ;; is sequential statement if ...
10355 (and (re-search-backward "^\\s-*begin\\>" nil t)
10356 ;; ... point is between "begin" and "end" of ...
10357 (progn (vhdl-end-of-block)
10358 (< start (point)))
10359 ;; ... a sequential block
10360 (progn (vhdl-beginning-of-block)
10361 (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
5eabfe72
KH
10362
10363(defun vhdl-in-argument-list-p ()
10364 "Check if within an argument list."
10365 (save-excursion
3dcb36b7
JB
10366 (vhdl-prepare-search-2
10367 (or (string-match "arglist"
10368 (format "%s" (caar (vhdl-get-syntactic-context))))
10369 (progn (beginning-of-line)
10370 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
5eabfe72
KH
10371
10372;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10373;; Abbrev hooks
10374
10375(defun vhdl-hooked-abbrev (func)
10376 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
10377but not if inside a comment or quote)."
3dcb36b7 10378 (if (or (vhdl-in-literal)
5eabfe72
KH
10379 (save-excursion
10380 (forward-word -1)
10381 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
10382 (progn
10383 (insert " ")
10384 (unexpand-abbrev)
10385 (delete-char -1))
10386 (if (not vhdl-electric-mode)
10387 (progn
10388 (insert " ")
10389 (unexpand-abbrev)
10390 (backward-word 1)
10391 (vhdl-case-word 1)
10392 (delete-char 1))
10393 (let ((invoke-char last-command-char)
10394 (abbrev-mode -1)
10395 (vhdl-template-invoked-by-hook t))
10396 (let ((caught (catch 'abort
10397 (funcall func))))
10398 (when (stringp caught) (message caught)))
10399 (when (= invoke-char ?-) (setq abbrev-start-location (point)))
10400 ;; delete CR which is still in event queue
3dcb36b7 10401 (if vhdl-xemacs
5eabfe72
KH
10402 (enqueue-eval-event 'delete-char -1)
10403 (setq unread-command-events ; push back a delete char
10404 (list (vhdl-character-to-event ?\177))))))))
10405
10406(defun vhdl-template-alias-hook ()
10407 (vhdl-hooked-abbrev 'vhdl-template-alias))
10408(defun vhdl-template-architecture-hook ()
10409 (vhdl-hooked-abbrev 'vhdl-template-architecture))
10410(defun vhdl-template-assert-hook ()
10411 (vhdl-hooked-abbrev 'vhdl-template-assert))
10412(defun vhdl-template-attribute-hook ()
10413 (vhdl-hooked-abbrev 'vhdl-template-attribute))
10414(defun vhdl-template-block-hook ()
10415 (vhdl-hooked-abbrev 'vhdl-template-block))
10416(defun vhdl-template-break-hook ()
10417 (vhdl-hooked-abbrev 'vhdl-template-break))
10418(defun vhdl-template-case-hook ()
10419 (vhdl-hooked-abbrev 'vhdl-template-case))
10420(defun vhdl-template-component-hook ()
10421 (vhdl-hooked-abbrev 'vhdl-template-component))
10422(defun vhdl-template-instance-hook ()
10423 (vhdl-hooked-abbrev 'vhdl-template-instance))
10424(defun vhdl-template-conditional-signal-asst-hook ()
10425 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
10426(defun vhdl-template-configuration-hook ()
10427 (vhdl-hooked-abbrev 'vhdl-template-configuration))
10428(defun vhdl-template-constant-hook ()
10429 (vhdl-hooked-abbrev 'vhdl-template-constant))
10430(defun vhdl-template-disconnect-hook ()
10431 (vhdl-hooked-abbrev 'vhdl-template-disconnect))
10432(defun vhdl-template-display-comment-hook ()
10433 (vhdl-hooked-abbrev 'vhdl-comment-display))
10434(defun vhdl-template-else-hook ()
10435 (vhdl-hooked-abbrev 'vhdl-template-else))
10436(defun vhdl-template-elsif-hook ()
10437 (vhdl-hooked-abbrev 'vhdl-template-elsif))
10438(defun vhdl-template-entity-hook ()
10439 (vhdl-hooked-abbrev 'vhdl-template-entity))
10440(defun vhdl-template-exit-hook ()
10441 (vhdl-hooked-abbrev 'vhdl-template-exit))
10442(defun vhdl-template-file-hook ()
10443 (vhdl-hooked-abbrev 'vhdl-template-file))
10444(defun vhdl-template-for-hook ()
10445 (vhdl-hooked-abbrev 'vhdl-template-for))
10446(defun vhdl-template-function-hook ()
10447 (vhdl-hooked-abbrev 'vhdl-template-function))
10448(defun vhdl-template-generic-hook ()
10449 (vhdl-hooked-abbrev 'vhdl-template-generic))
10450(defun vhdl-template-group-hook ()
10451 (vhdl-hooked-abbrev 'vhdl-template-group))
10452(defun vhdl-template-library-hook ()
10453 (vhdl-hooked-abbrev 'vhdl-template-library))
10454(defun vhdl-template-limit-hook ()
10455 (vhdl-hooked-abbrev 'vhdl-template-limit))
10456(defun vhdl-template-if-hook ()
10457 (vhdl-hooked-abbrev 'vhdl-template-if))
10458(defun vhdl-template-bare-loop-hook ()
10459 (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
10460(defun vhdl-template-map-hook ()
10461 (vhdl-hooked-abbrev 'vhdl-template-map))
10462(defun vhdl-template-nature-hook ()
10463 (vhdl-hooked-abbrev 'vhdl-template-nature))
10464(defun vhdl-template-next-hook ()
10465 (vhdl-hooked-abbrev 'vhdl-template-next))
3dcb36b7
JB
10466(defun vhdl-template-others-hook ()
10467 (vhdl-hooked-abbrev 'vhdl-template-others))
5eabfe72
KH
10468(defun vhdl-template-package-hook ()
10469 (vhdl-hooked-abbrev 'vhdl-template-package))
10470(defun vhdl-template-port-hook ()
10471 (vhdl-hooked-abbrev 'vhdl-template-port))
10472(defun vhdl-template-procedural-hook ()
10473 (vhdl-hooked-abbrev 'vhdl-template-procedural))
10474(defun vhdl-template-procedure-hook ()
10475 (vhdl-hooked-abbrev 'vhdl-template-procedure))
10476(defun vhdl-template-process-hook ()
10477 (vhdl-hooked-abbrev 'vhdl-template-process))
10478(defun vhdl-template-quantity-hook ()
10479 (vhdl-hooked-abbrev 'vhdl-template-quantity))
10480(defun vhdl-template-report-hook ()
10481 (vhdl-hooked-abbrev 'vhdl-template-report))
10482(defun vhdl-template-return-hook ()
10483 (vhdl-hooked-abbrev 'vhdl-template-return))
10484(defun vhdl-template-selected-signal-asst-hook ()
10485 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
10486(defun vhdl-template-signal-hook ()
10487 (vhdl-hooked-abbrev 'vhdl-template-signal))
10488(defun vhdl-template-subnature-hook ()
10489 (vhdl-hooked-abbrev 'vhdl-template-subnature))
10490(defun vhdl-template-subtype-hook ()
10491 (vhdl-hooked-abbrev 'vhdl-template-subtype))
10492(defun vhdl-template-terminal-hook ()
10493 (vhdl-hooked-abbrev 'vhdl-template-terminal))
10494(defun vhdl-template-type-hook ()
10495 (vhdl-hooked-abbrev 'vhdl-template-type))
10496(defun vhdl-template-use-hook ()
10497 (vhdl-hooked-abbrev 'vhdl-template-use))
10498(defun vhdl-template-variable-hook ()
10499 (vhdl-hooked-abbrev 'vhdl-template-variable))
10500(defun vhdl-template-wait-hook ()
10501 (vhdl-hooked-abbrev 'vhdl-template-wait))
10502(defun vhdl-template-when-hook ()
10503 (vhdl-hooked-abbrev 'vhdl-template-when))
10504(defun vhdl-template-while-loop-hook ()
10505 (vhdl-hooked-abbrev 'vhdl-template-while-loop))
10506(defun vhdl-template-with-hook ()
10507 (vhdl-hooked-abbrev 'vhdl-template-with))
10508(defun vhdl-template-and-hook ()
10509 (vhdl-hooked-abbrev 'vhdl-template-and))
10510(defun vhdl-template-or-hook ()
10511 (vhdl-hooked-abbrev 'vhdl-template-or))
10512(defun vhdl-template-nand-hook ()
10513 (vhdl-hooked-abbrev 'vhdl-template-nand))
10514(defun vhdl-template-nor-hook ()
10515 (vhdl-hooked-abbrev 'vhdl-template-nor))
10516(defun vhdl-template-xor-hook ()
10517 (vhdl-hooked-abbrev 'vhdl-template-xor))
10518(defun vhdl-template-xnor-hook ()
10519 (vhdl-hooked-abbrev 'vhdl-template-xnor))
10520(defun vhdl-template-not-hook ()
10521 (vhdl-hooked-abbrev 'vhdl-template-not))
10522
10523(defun vhdl-template-default-hook ()
10524 (vhdl-hooked-abbrev 'vhdl-template-default))
10525(defun vhdl-template-default-indent-hook ()
10526 (vhdl-hooked-abbrev 'vhdl-template-default-indent))
10527
10528;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10529;; Template insertion from completion list
10530
10531(defun vhdl-template-insert-construct (name)
10532 "Insert the built-in construct template with NAME."
10533 (interactive
10534 (list (let ((completion-ignore-case t))
10535 (completing-read "Construct name: "
10536 vhdl-template-construct-alist nil t))))
10537 (vhdl-template-insert-fun
3dcb36b7 10538 (cadr (assoc name vhdl-template-construct-alist))))
5eabfe72
KH
10539
10540(defun vhdl-template-insert-package (name)
10541 "Insert the built-in package template with NAME."
10542 (interactive
10543 (list (let ((completion-ignore-case t))
10544 (completing-read "Package name: "
10545 vhdl-template-package-alist nil t))))
10546 (vhdl-template-insert-fun
3dcb36b7 10547 (cadr (assoc name vhdl-template-package-alist))))
5eabfe72
KH
10548
10549(defun vhdl-template-insert-directive (name)
10550 "Insert the built-in directive template with NAME."
10551 (interactive
10552 (list (let ((completion-ignore-case t))
10553 (completing-read "Directive name: "
10554 vhdl-template-directive-alist nil t))))
10555 (vhdl-template-insert-fun
3dcb36b7 10556 (cadr (assoc name vhdl-template-directive-alist))))
5eabfe72
KH
10557
10558(defun vhdl-template-insert-fun (fun)
10559 "Call FUN to insert a built-in template."
10560 (let ((caught (catch 'abort (when fun (funcall fun)))))
10561 (when (stringp caught) (message caught))))
10562
10563
10564;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10565;;; Models
10566;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10567
10568(defun vhdl-model-insert (model-name)
10569 "Insert the user model with name MODEL-NAME."
10570 (interactive
10571 (let ((completion-ignore-case t))
10572 (list (completing-read "Model name: " vhdl-model-alist))))
3dcb36b7 10573 (indent-according-to-mode)
5eabfe72
KH
10574 (let ((start (point-marker))
10575 (margin (current-indentation))
5eabfe72 10576 model position prompt string end)
3dcb36b7 10577 (vhdl-prepare-search-2
5eabfe72
KH
10578 (when (setq model (assoc model-name vhdl-model-alist))
10579 ;; insert model
10580 (beginning-of-line)
10581 (delete-horizontal-space)
10582 (goto-char start)
10583 (vhdl-insert-string-or-file (nth 1 model))
10584 (setq end (point-marker))
10585 ;; indent code
10586 (goto-char start)
10587 (beginning-of-line)
10588 (while (< (point) end)
10589 (unless (looking-at "^$")
10590 (insert-char ? margin))
10591 (beginning-of-line 2))
10592 (goto-char start)
10593 ;; insert clock
10594 (unless (equal "" vhdl-clock-name)
10595 (while (re-search-forward "<clock>" end t)
10596 (replace-match vhdl-clock-name)))
10597 (goto-char start)
10598 ;; insert reset
10599 (unless (equal "" vhdl-reset-name)
10600 (while (re-search-forward "<reset>" end t)
10601 (replace-match vhdl-reset-name)))
3dcb36b7
JB
10602 ;; replace header prompts
10603 (vhdl-template-replace-header-keywords start end nil t)
5eabfe72 10604 (goto-char start)
3dcb36b7 10605 ;; query other prompts
5eabfe72
KH
10606 (while (re-search-forward
10607 (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
10608 (unless (equal "cursor" (match-string 1))
10609 (setq position (match-beginning 1))
10610 (setq prompt (match-string 1))
10611 (replace-match "")
10612 (setq string (vhdl-template-field prompt nil t))
a5a08b1f 10613 ;; replace occurrences of same prompt
5eabfe72
KH
10614 (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
10615 (replace-match (or string "")))
10616 (goto-char position)))
10617 (goto-char start)
10618 ;; goto final position
10619 (if (re-search-forward "<cursor>" end t)
10620 (replace-match "")
10621 (goto-char end))))))
10622
10623(defun vhdl-model-defun ()
10624 "Define help and hook functions for user models."
10625 (let ((model-alist vhdl-model-alist)
10626 model-name model-keyword)
10627 (while model-alist
10628 ;; define functions for user models that can be invoked from menu and key
10629 ;; bindings and which themselves call `vhdl-model-insert' with the model
10630 ;; name as argument
10631 (setq model-name (nth 0 (car model-alist)))
d4a5b644
GM
10632 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
10633 ,(concat "Insert model for \"" model-name "\".")
10634 (interactive)
10635 (vhdl-model-insert ,model-name)))
5eabfe72
KH
10636 ;; define hooks for user models that are invoked from keyword abbrevs
10637 (setq model-keyword (nth 3 (car model-alist)))
10638 (unless (equal model-keyword "")
d4a5b644
GM
10639 (eval `(defun
10640 ,(vhdl-function-name
10641 "vhdl-model" model-name "hook") ()
10642 (vhdl-hooked-abbrev
10643 ',(vhdl-function-name "vhdl-model" model-name)))))
5eabfe72
KH
10644 (setq model-alist (cdr model-alist)))))
10645
10646(vhdl-model-defun)
10647
10648
10649;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10650;;; Port translation
10651;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10652
10653(defvar vhdl-port-list nil
3dcb36b7 10654 "Variable to hold last port map parsed.")
5eabfe72 10655;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
10656;; (ent-name
10657;; ((generic-names) generic-type generic-init generic-comment group-comment)
10658;; ((port-names) port-object port-direct port-type port-comment group-comment)
10659;; (lib-name pack-key))
5eabfe72
KH
10660
10661(defun vhdl-parse-string (string &optional optional)
3dcb36b7 10662 "Check that the text following point matches the regexp in STRING."
5eabfe72 10663 (if (looking-at string)
3dcb36b7 10664 (goto-char (match-end 0))
5eabfe72 10665 (unless optional
3dcb36b7
JB
10666 (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
10667 (vhdl-current-line) string)))
5eabfe72
KH
10668 nil))
10669
10670(defun vhdl-replace-string (regexp-cons string)
10671 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
3dcb36b7 10672 (vhdl-prepare-search-1
5eabfe72 10673 (if (string-match (car regexp-cons) string)
3dcb36b7
JB
10674 (funcall vhdl-file-name-case
10675 (replace-match (cdr regexp-cons) t nil string))
5eabfe72
KH
10676 string)))
10677
3dcb36b7
JB
10678(defun vhdl-parse-group-comment ()
10679 "Parse comment and empty lines between groups of lines."
10680 (let ((start (point))
10681 string)
10682 (vhdl-forward-comment (point-max))
10683 (setq string (buffer-substring-no-properties start (point)))
10684 ;; strip off leading blanks and first newline
10685 (while (string-match "^\\(\\s-+\\)" string)
10686 (setq string (concat (substring string 0 (match-beginning 1))
10687 (substring string (match-end 1)))))
10688 (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
10689 (substring string 1)
10690 string)))
10691
10692(defun vhdl-paste-group-comment (string indent)
10693 "Paste comment and empty lines from STRING between groups of lines
10694with INDENT."
10695 (let ((pos (point-marker)))
10696 (when (> indent 0)
10697 (while (string-match "^\\(--\\)" string)
10698 (setq string (concat (substring string 0 (match-beginning 1))
10699 (make-string indent ? )
10700 (substring string (match-beginning 1))))))
10701 (beginning-of-line)
10702 (insert string)
10703 (goto-char pos)))
10704
10705(defvar vhdl-port-flattened nil
10706 "Indicates whether a port has been flattened.")
10707
10708(defun vhdl-port-flatten (&optional as-alist)
5eabfe72
KH
10709 "Flatten port list so that only one generic/port exists per line."
10710 (interactive)
10711 (if (not vhdl-port-list)
3dcb36b7 10712 (error "ERROR: No port has been read")
5eabfe72
KH
10713 (message "Flattening port...")
10714 (let ((new-vhdl-port-list (list (car vhdl-port-list)))
10715 (old-vhdl-port-list (cdr vhdl-port-list))
10716 old-port-list new-port-list old-port new-port names)
10717 ;; traverse port list and flatten entries
3dcb36b7 10718 (while (cdr old-vhdl-port-list)
5eabfe72
KH
10719 (setq old-port-list (car old-vhdl-port-list))
10720 (setq new-port-list nil)
10721 (while old-port-list
10722 (setq old-port (car old-port-list))
10723 (setq names (car old-port))
10724 (while names
3dcb36b7
JB
10725 (setq new-port (cons (if as-alist (car names) (list (car names)))
10726 (cdr old-port)))
5eabfe72
KH
10727 (setq new-port-list (append new-port-list (list new-port)))
10728 (setq names (cdr names)))
10729 (setq old-port-list (cdr old-port-list)))
10730 (setq old-vhdl-port-list (cdr old-vhdl-port-list))
10731 (setq new-vhdl-port-list (append new-vhdl-port-list
10732 (list new-port-list))))
3dcb36b7
JB
10733 (setq vhdl-port-list
10734 (append new-vhdl-port-list (list old-vhdl-port-list))
10735 vhdl-port-flattened t)
5eabfe72
KH
10736 (message "Flattening port...done"))))
10737
3dcb36b7
JB
10738(defvar vhdl-port-reversed-direction nil
10739 "Indicates whether port directions are reversed.")
10740
10741(defun vhdl-port-reverse-direction ()
10742 "Reverse direction for all ports (useful in testbenches)."
10743 (interactive)
10744 (if (not vhdl-port-list)
10745 (error "ERROR: No port has been read")
10746 (message "Reversing port directions...")
10747 (let ((port-list (nth 2 vhdl-port-list))
10748 port-dir-car port-dir)
10749 ;; traverse port list and reverse directions
10750 (while port-list
10751 (setq port-dir-car (cddr (car port-list))
10752 port-dir (car port-dir-car))
10753 (setcar port-dir-car
10754 (cond ((equal port-dir "in") "out")
10755 ((equal port-dir "out") "in")
10756 (t port-dir)))
10757 (setq port-list (cdr port-list)))
10758 (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
10759 (message "Reversing port directions...done"))))
10760
5eabfe72
KH
10761(defun vhdl-port-copy ()
10762 "Get generic and port information from an entity or component declaration."
10763 (interactive)
5eabfe72 10764 (save-excursion
3dcb36b7
JB
10765 (let (parse-error end-of-list
10766 decl-type name generic-list port-list context-clause
10767 object names direct type init comment group-comment)
10768 (vhdl-prepare-search-2
5eabfe72
KH
10769 (setq
10770 parse-error
10771 (catch 'parse
10772 ;; check if within entity or component declaration
3dcb36b7 10773 (end-of-line)
5eabfe72
KH
10774 (when (or (not (re-search-backward
10775 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
3dcb36b7
JB
10776 (equal "END" (upcase (match-string 1))))
10777 (throw 'parse "ERROR: Not within an entity or component declaration"))
10778 (setq decl-type (downcase (match-string-no-properties 1)))
5eabfe72 10779 (forward-word 1)
3dcb36b7
JB
10780 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
10781 (setq name (match-string-no-properties 1))
10782 (message "Reading port of %s \"%s\"..." decl-type name)
5eabfe72
KH
10783 (vhdl-forward-syntactic-ws)
10784 ;; parse generic clause
10785 (when (vhdl-parse-string "generic[ \t\n]*(" t)
3dcb36b7
JB
10786 ;; parse group comment and spacing
10787 (setq group-comment (vhdl-parse-group-comment))
10788 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
10789 (while (not end-of-list)
10790 ;; parse names
10791 (vhdl-parse-string "\\(\\w+\\)[ \t\n]*")
3dcb36b7 10792 (setq names (list (match-string-no-properties 1)))
5eabfe72 10793 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
3dcb36b7
JB
10794 (setq names
10795 (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10796 ;; parse type
10797 (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
3dcb36b7 10798 (setq type (match-string-no-properties 1))
5eabfe72
KH
10799 (setq comment nil)
10800 (while (looking-at "(")
10801 (setq type
10802 (concat type
3dcb36b7 10803 (buffer-substring-no-properties
5eabfe72
KH
10804 (point) (progn (forward-sexp) (point)))
10805 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
3dcb36b7 10806 (match-string-no-properties 1)))))
5eabfe72
KH
10807 ;; special case: closing parenthesis is on separate line
10808 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
10809 (setq comment (substring type (match-beginning 2)))
10810 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10811 ;; strip of trailing group-comment
5eabfe72
KH
10812 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10813 (setq type (substring type 0 (match-end 1)))
10814 ;; parse initialization expression
10815 (setq init nil)
10816 (when (vhdl-parse-string ":=[ \t\n]*" t)
10817 (vhdl-parse-string "\\([^();\n]*\\)")
3dcb36b7 10818 (setq init (match-string-no-properties 1))
5eabfe72
KH
10819 (while (looking-at "(")
10820 (setq init
10821 (concat init
3dcb36b7 10822 (buffer-substring-no-properties
5eabfe72
KH
10823 (point) (progn (forward-sexp) (point)))
10824 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 10825 (match-string-no-properties 1))))))
5eabfe72
KH
10826 ;; special case: closing parenthesis is on separate line
10827 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
10828 (setq comment (substring init (match-beginning 2)))
10829 (setq init (substring init 0 (match-beginning 1)))
10830 (vhdl-forward-syntactic-ws))
10831 (skip-chars-forward " \t")
10832 ;; parse inline comment, special case: as above, no initial.
10833 (unless comment
10834 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10835 (match-string-no-properties 1))))
5eabfe72
KH
10836 (vhdl-forward-syntactic-ws)
10837 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 10838 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
10839 ;; parse inline comment
10840 (unless comment
10841 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10842 (match-string-no-properties 1))))
5eabfe72 10843 ;; save everything in list
3dcb36b7
JB
10844 (setq generic-list (append generic-list
10845 (list (list names type init
10846 comment group-comment))))
10847 ;; parse group comment and spacing
10848 (setq group-comment (vhdl-parse-group-comment))))
5eabfe72
KH
10849 ;; parse port clause
10850 (when (vhdl-parse-string "port[ \t\n]*(" t)
3dcb36b7
JB
10851 ;; parse group comment and spacing
10852 (setq group-comment (vhdl-parse-group-comment))
10853 (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
5eabfe72
KH
10854 (while (not end-of-list)
10855 ;; parse object
10856 (setq object
3dcb36b7
JB
10857 (and (vhdl-parse-string "\\(signal\\|quantity\\|terminal\\)[ \t\n]*" t)
10858 (match-string-no-properties 1)))
10859 ;; parse names (accept extended identifiers)
10860 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
10861 (setq names (list (match-string-no-properties 1)))
10862 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
10863 (setq names (append names (list (match-string-no-properties 1)))))
5eabfe72
KH
10864 ;; parse direction
10865 (vhdl-parse-string ":[ \t\n]*")
10866 (setq direct
3dcb36b7
JB
10867 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
10868 (match-string-no-properties 1)))
5eabfe72
KH
10869 ;; parse type
10870 (vhdl-parse-string "\\([^();\n]+\\)")
3dcb36b7 10871 (setq type (match-string-no-properties 1))
5eabfe72
KH
10872 (setq comment nil)
10873 (while (looking-at "(")
10874 (setq type (concat type
3dcb36b7 10875 (buffer-substring-no-properties
5eabfe72
KH
10876 (point) (progn (forward-sexp) (point)))
10877 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
3dcb36b7 10878 (match-string-no-properties 1)))))
5eabfe72 10879 ;; special case: closing parenthesis is on separate line
3dcb36b7 10880 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
5eabfe72
KH
10881 (setq comment (substring type (match-beginning 2)))
10882 (setq type (substring type 0 (match-beginning 1))))
3dcb36b7 10883 ;; strip of trailing group-comment
5eabfe72
KH
10884 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
10885 (setq type (substring type 0 (match-end 1)))
10886 (vhdl-forward-syntactic-ws)
10887 (setq end-of-list (vhdl-parse-string ")" t))
3dcb36b7 10888 (vhdl-parse-string "\\s-*;\\s-*")
5eabfe72
KH
10889 ;; parse inline comment
10890 (unless comment
10891 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
3dcb36b7 10892 (match-string-no-properties 1))))
5eabfe72 10893 ;; save everything in list
3dcb36b7
JB
10894 (setq port-list (append port-list
10895 (list (list names object direct type
10896 comment group-comment))))
10897 ;; parse group comment and spacing
10898 (setq group-comment (vhdl-parse-group-comment))))
10899; (vhdl-parse-string "end\\>")
10900 ;; parse context clause
10901 (setq context-clause (vhdl-scan-context-clause))
10902; ;; add surrounding package to context clause
10903; (when (and (equal decl-type "component")
10904; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
10905; (setq context-clause
10906; (append context-clause
10907; (list (cons (vhdl-work-library)
10908; (match-string-no-properties 1))))))
10909 (message "Reading port of %s \"%s\"...done" decl-type name)
5eabfe72
KH
10910 nil)))
10911 ;; finish parsing
10912 (if parse-error
10913 (error parse-error)
3dcb36b7
JB
10914 (setq vhdl-port-list (list name generic-list port-list context-clause)
10915 vhdl-port-reversed-direction nil
10916 vhdl-port-flattened nil)))))
10917
10918(defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
10919 "Paste a context clause."
10920 (let ((margin (current-indentation))
10921 (clause-list (nth 3 vhdl-port-list))
10922 clause)
10923 (while clause-list
10924 (setq clause (car clause-list))
10925 (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
10926 (downcase exclude-pack-name)))
10927 (save-excursion
10928 (re-search-backward
10929 (concat "^\\s-*use\\s-+" (car clause)
10930 "\." (cdr clause) "\\>") nil t)))
10931 (vhdl-template-standard-package (car clause) (cdr clause))
10932 (insert "\n"))
10933 (setq clause-list (cdr clause-list)))))
5eabfe72
KH
10934
10935(defun vhdl-port-paste-generic (&optional no-init)
10936 "Paste a generic clause."
10937 (let ((margin (current-indentation))
3dcb36b7
JB
10938 (generic-list (nth 1 vhdl-port-list))
10939 list-margin start names generic)
5eabfe72 10940 ;; paste generic clause
3dcb36b7 10941 (when generic-list
5eabfe72
KH
10942 (setq start (point))
10943 (vhdl-insert-keyword "GENERIC (")
10944 (unless vhdl-argument-list-indent
10945 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10946 (setq list-margin (current-column))
3dcb36b7
JB
10947 (while generic-list
10948 (setq generic (car generic-list))
10949 ;; paste group comment and spacing
10950 (when (memq vhdl-include-group-comments '(decl always))
10951 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72 10952 ;; paste names
5eabfe72
KH
10953 (setq names (nth 0 generic))
10954 (while names
10955 (insert (car names))
10956 (setq names (cdr names))
10957 (when names (insert ", ")))
10958 ;; paste type
10959 (insert " : " (nth 1 generic))
10960 ;; paste initialization
10961 (when (and (not no-init) (nth 2 generic))
10962 (insert " := " (nth 2 generic)))
3dcb36b7 10963 (unless (cdr generic-list) (insert ")"))
5eabfe72
KH
10964 (insert ";")
10965 ;; paste comment
10966 (when (and vhdl-include-port-comments (nth 3 generic))
10967 (vhdl-comment-insert-inline (nth 3 generic) t))
3dcb36b7
JB
10968 (setq generic-list (cdr generic-list))
10969 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72 10970 ;; align generic clause
3dcb36b7 10971 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
5eabfe72
KH
10972
10973(defun vhdl-port-paste-port ()
10974 "Paste a port clause."
10975 (let ((margin (current-indentation))
3dcb36b7
JB
10976 (port-list (nth 2 vhdl-port-list))
10977 list-margin start names port)
5eabfe72 10978 ;; paste port clause
3dcb36b7 10979 (when port-list
5eabfe72
KH
10980 (setq start (point))
10981 (vhdl-insert-keyword "PORT (")
10982 (unless vhdl-argument-list-indent
10983 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
10984 (setq list-margin (current-column))
3dcb36b7
JB
10985 (while port-list
10986 (setq port (car port-list))
10987 ;; paste group comment and spacing
10988 (when (memq vhdl-include-group-comments '(decl always))
10989 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
10990 ;; paste object
10991 (when (nth 1 port) (insert (nth 1 port) " "))
10992 ;; paste names
10993 (setq names (nth 0 port))
10994 (while names
10995 (insert (car names))
10996 (setq names (cdr names))
10997 (when names (insert ", ")))
10998 ;; paste direction
10999 (insert " : ")
11000 (when (nth 2 port) (insert (nth 2 port) " "))
11001 ;; paste type
11002 (insert (nth 3 port))
3dcb36b7 11003 (unless (cdr port-list) (insert ")"))
5eabfe72
KH
11004 (insert ";")
11005 ;; paste comment
11006 (when (and vhdl-include-port-comments (nth 4 port))
11007 (vhdl-comment-insert-inline (nth 4 port) t))
3dcb36b7
JB
11008 (setq port-list (cdr port-list))
11009 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72 11010 ;; align port clause
3dcb36b7 11011 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
5eabfe72 11012
3dcb36b7 11013(defun vhdl-port-paste-declaration (kind &optional no-indent)
5eabfe72 11014 "Paste as an entity or component declaration."
3dcb36b7 11015 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11016 (let ((margin (current-indentation))
11017 (name (nth 0 vhdl-port-list)))
11018 (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
11019 (insert name)
3dcb36b7
JB
11020 (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
11021 (vhdl-insert-keyword " IS"))
11022 ;; paste generic and port clause
5eabfe72
KH
11023 (when (nth 1 vhdl-port-list)
11024 (insert "\n")
11025 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11026 (insert "\n"))
11027 (indent-to (+ margin vhdl-basic-offset))
11028 (vhdl-port-paste-generic (eq kind 'component)))
11029 (when (nth 2 vhdl-port-list)
11030 (insert "\n")
11031 (when (and (memq vhdl-insert-empty-lines '(unit all))
11032 (eq kind 'entity))
11033 (insert "\n"))
11034 (indent-to (+ margin vhdl-basic-offset)))
11035 (vhdl-port-paste-port)
11036 (insert "\n")
11037 (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
11038 (insert "\n"))
11039 (indent-to margin)
11040 (vhdl-insert-keyword "END")
11041 (if (eq kind 'entity)
11042 (progn
11043 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11044 (insert " " name))
11045 (vhdl-insert-keyword " COMPONENT")
11046 (unless (vhdl-standard-p '87) (insert " " name)))
11047 (insert ";")))
11048
3dcb36b7 11049(defun vhdl-port-paste-entity (&optional no-indent)
5eabfe72
KH
11050 "Paste as an entity declaration."
11051 (interactive)
11052 (if (not vhdl-port-list)
3dcb36b7
JB
11053 (error "ERROR: No port read")
11054 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
11055 (vhdl-port-paste-declaration 'entity no-indent)
11056 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
5eabfe72 11057
3dcb36b7 11058(defun vhdl-port-paste-component (&optional no-indent)
5eabfe72
KH
11059 "Paste as a component declaration."
11060 (interactive)
11061 (if (not vhdl-port-list)
3dcb36b7
JB
11062 (error "ERROR: No port read")
11063 (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
11064 (vhdl-port-paste-declaration 'component no-indent)
11065 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
5eabfe72
KH
11066
11067(defun vhdl-port-paste-generic-map (&optional secondary no-constants)
11068 "Paste as a generic map."
11069 (interactive)
3dcb36b7 11070 (unless secondary (indent-according-to-mode))
5eabfe72
KH
11071 (let ((margin (current-indentation))
11072 list-margin start generic
3dcb36b7
JB
11073 (generic-list (nth 1 vhdl-port-list)))
11074 (when generic-list
5eabfe72
KH
11075 (setq start (point))
11076 (vhdl-insert-keyword "GENERIC MAP (")
11077 (if (not vhdl-association-list-with-formals)
11078 ;; paste list of actual generics
3dcb36b7
JB
11079 (while generic-list
11080 (insert (if no-constants
11081 (car (nth 0 (car generic-list)))
11082 (or (nth 2 (car generic-list)) " ")))
11083 (setq generic-list (cdr generic-list))
11084 (insert (if generic-list ", " ")")))
5eabfe72 11085 (unless vhdl-argument-list-indent
3dcb36b7 11086 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11087 (setq list-margin (current-column))
3dcb36b7
JB
11088 (while generic-list
11089 (setq generic (car generic-list))
11090 ;; paste group comment and spacing
11091 (when (eq vhdl-include-group-comments 'always)
11092 (vhdl-paste-group-comment (nth 4 generic) list-margin))
5eabfe72
KH
11093 ;; paste formal and actual generic
11094 (insert (car (nth 0 generic)) " => "
11095 (if no-constants
11096 (car (nth 0 generic))
11097 (or (nth 2 generic) "")))
3dcb36b7
JB
11098 (setq generic-list (cdr generic-list))
11099 (insert (if generic-list "," ")"))
5eabfe72 11100 ;; paste comment
3dcb36b7
JB
11101 (when (or vhdl-include-type-comments
11102 (and vhdl-include-port-comments (nth 3 generic)))
11103 (vhdl-comment-insert-inline
11104 (concat
11105 (when vhdl-include-type-comments
11106 (concat "[" (nth 1 generic) "] "))
11107 (when vhdl-include-port-comments (nth 3 generic))) t))
11108 (when generic-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11109 ;; align generic map
11110 (when vhdl-auto-align
3dcb36b7 11111 (vhdl-align-region-groups start (point) 1 t))))))
5eabfe72
KH
11112
11113(defun vhdl-port-paste-port-map ()
11114 "Paste as a port map."
11115 (let ((margin (current-indentation))
11116 list-margin start port
3dcb36b7
JB
11117 (port-list (nth 2 vhdl-port-list)))
11118 (when port-list
5eabfe72
KH
11119 (setq start (point))
11120 (vhdl-insert-keyword "PORT MAP (")
11121 (if (not vhdl-association-list-with-formals)
11122 ;; paste list of actual ports
3dcb36b7 11123 (while port-list
5eabfe72 11124 (insert (vhdl-replace-string vhdl-actual-port-name
3dcb36b7
JB
11125 (car (nth 0 (car port-list)))))
11126 (setq port-list (cdr port-list))
11127 (insert (if port-list ", " ");")))
5eabfe72 11128 (unless vhdl-argument-list-indent
3dcb36b7 11129 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
5eabfe72 11130 (setq list-margin (current-column))
3dcb36b7
JB
11131 (while port-list
11132 (setq port (car port-list))
11133 ;; paste group comment and spacing
11134 (when (eq vhdl-include-group-comments 'always)
11135 (vhdl-paste-group-comment (nth 5 port) list-margin))
5eabfe72
KH
11136 ;; paste formal and actual port
11137 (insert (car (nth 0 port)) " => ")
11138 (insert (vhdl-replace-string vhdl-actual-port-name
11139 (car (nth 0 port))))
3dcb36b7
JB
11140 (setq port-list (cdr port-list))
11141 (insert (if port-list "," ");"))
5eabfe72
KH
11142 ;; paste comment
11143 (when (or vhdl-include-direction-comments
3dcb36b7 11144 vhdl-include-type-comments
5eabfe72
KH
11145 (and vhdl-include-port-comments (nth 4 port)))
11146 (vhdl-comment-insert-inline
11147 (concat
3dcb36b7
JB
11148 (cond ((and vhdl-include-direction-comments
11149 vhdl-include-type-comments)
11150 (concat "[" (format "%-4s" (concat (nth 2 port) " "))
11151 (nth 3 port) "] "))
11152 ((and vhdl-include-direction-comments (nth 2 port))
11153 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11154 (vhdl-include-direction-comments " ")
11155 (vhdl-include-type-comments
11156 (concat "[" (nth 3 port) "] ")))
11157 (when vhdl-include-port-comments (nth 4 port))) t))
11158 (when port-list (insert "\n") (indent-to list-margin)))
5eabfe72
KH
11159 ;; align port clause
11160 (when vhdl-auto-align
3dcb36b7 11161 (vhdl-align-region-groups start (point) 1))))))
5eabfe72 11162
3dcb36b7 11163(defun vhdl-port-paste-instance (&optional name no-indent title)
5eabfe72
KH
11164 "Paste as an instantiation."
11165 (interactive)
11166 (if (not vhdl-port-list)
3dcb36b7 11167 (error "ERROR: No port read")
5eabfe72
KH
11168 (let ((orig-vhdl-port-list vhdl-port-list))
11169 ;; flatten local copy of port list (must be flat for port mapping)
11170 (vhdl-port-flatten)
3dcb36b7
JB
11171 (unless no-indent (indent-according-to-mode))
11172 (let ((margin (current-indentation)))
5eabfe72 11173 ;; paste instantiation
3dcb36b7
JB
11174 (cond (name
11175 (insert name))
11176 ((equal (cdr vhdl-instance-name) "")
11177 (setq name (vhdl-template-field "instance name")))
11178 ((string-match "\%d" (cdr vhdl-instance-name))
11179 (let ((n 1))
11180 (while (save-excursion
11181 (setq name (format (vhdl-replace-string
11182 vhdl-instance-name
11183 (nth 0 vhdl-port-list)) n))
11184 (goto-char (point-min))
11185 (vhdl-re-search-forward name nil t))
11186 (setq n (1+ n)))
11187 (insert name)))
11188 (t (insert (vhdl-replace-string vhdl-instance-name
11189 (nth 0 vhdl-port-list)))))
11190 (message "Pasting port as instantiation \"%s\"..." name)
11191 (insert ": ")
11192 (when title
11193 (save-excursion
11194 (beginning-of-line)
11195 (indent-to vhdl-basic-offset)
11196 (insert "-- instance \"" name "\"\n")))
11197 (if (not (vhdl-use-direct-instantiation))
5eabfe72
KH
11198 (insert (nth 0 vhdl-port-list))
11199 (vhdl-insert-keyword "ENTITY ")
3dcb36b7 11200 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
5eabfe72
KH
11201 (when (nth 1 vhdl-port-list)
11202 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11203 (vhdl-port-paste-generic-map t t))
11204 (when (nth 2 vhdl-port-list)
11205 (insert "\n") (indent-to (+ margin vhdl-basic-offset))
11206 (vhdl-port-paste-port-map))
3dcb36b7
JB
11207 (message "Pasting port as instantiation \"%s\"...done" name))
11208 (setq vhdl-port-list orig-vhdl-port-list))))
11209
11210(defun vhdl-port-paste-constants (&optional no-indent)
11211 "Paste generics as constants."
11212 (interactive)
11213 (if (not vhdl-port-list)
11214 (error "ERROR: No port read")
11215 (let ((orig-vhdl-port-list vhdl-port-list))
11216 (message "Pasting port as constants...")
11217 ;; flatten local copy of port list (must be flat for constant initial.)
11218 (vhdl-port-flatten)
11219 (unless no-indent (indent-according-to-mode))
11220 (let ((margin (current-indentation))
11221 start generic name
11222 (generic-list (nth 1 vhdl-port-list)))
11223 (when generic-list
11224 (setq start (point))
11225 (while generic-list
11226 (setq generic (car generic-list))
11227 ;; paste group comment and spacing
11228 (when (memq vhdl-include-group-comments '(decl always))
11229 (vhdl-paste-group-comment (nth 4 generic) margin))
11230 (vhdl-insert-keyword "CONSTANT ")
11231 ;; paste generic constants
11232 (setq name (nth 0 generic))
11233 (when name
11234 (insert (car name))
11235 ;; paste type
11236 (insert " : " (nth 1 generic))
11237 ;; paste initialization
11238 (when (nth 2 generic)
11239 (insert " := " (nth 2 generic)))
11240 (insert ";")
11241 ;; paste comment
11242 (when (and vhdl-include-port-comments (nth 3 generic))
11243 (vhdl-comment-insert-inline (nth 3 generic) t))
11244 (setq generic-list (cdr generic-list))
11245 (when generic-list (insert "\n") (indent-to margin))))
11246 ;; align signal list
11247 (when vhdl-auto-align
11248 (vhdl-align-region-groups start (point) 1))))
11249 (message "Pasting port as constants...done")
5eabfe72
KH
11250 (setq vhdl-port-list orig-vhdl-port-list))))
11251
3dcb36b7 11252(defun vhdl-port-paste-signals (&optional initialize no-indent)
5eabfe72
KH
11253 "Paste ports as internal signals."
11254 (interactive)
11255 (if (not vhdl-port-list)
3dcb36b7 11256 (error "ERROR: No port read")
5eabfe72 11257 (message "Pasting port as signals...")
3dcb36b7 11258 (unless no-indent (indent-according-to-mode))
5eabfe72
KH
11259 (let ((margin (current-indentation))
11260 start port names
3dcb36b7
JB
11261 (port-list (nth 2 vhdl-port-list)))
11262 (when port-list
5eabfe72 11263 (setq start (point))
3dcb36b7
JB
11264 (while port-list
11265 (setq port (car port-list))
11266 ;; paste group comment and spacing
11267 (when (memq vhdl-include-group-comments '(decl always))
11268 (vhdl-paste-group-comment (nth 5 port) margin))
5eabfe72
KH
11269 ;; paste object
11270 (if (nth 1 port)
11271 (insert (nth 1 port) " ")
11272 (vhdl-insert-keyword "SIGNAL "))
11273 ;; paste actual port signals
11274 (setq names (nth 0 port))
11275 (while names
11276 (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
11277 (setq names (cdr names))
11278 (when names (insert ", ")))
11279 ;; paste type
11280 (insert " : " (nth 3 port))
11281 ;; paste initialization (inputs only)
3dcb36b7
JB
11282 (when (and initialize (equal "IN" (upcase (nth 2 port))))
11283 (insert " := " (if (string-match "(.+)" (nth 3 port))
11284 "(others => '0')" "'0'")))
5eabfe72
KH
11285 (insert ";")
11286 ;; paste comment
3dcb36b7
JB
11287 (when (or vhdl-include-direction-comments
11288 (and vhdl-include-port-comments (nth 4 port)))
11289 (vhdl-comment-insert-inline
11290 (concat
11291 (cond ((and vhdl-include-direction-comments (nth 2 port))
11292 (format "%-6s" (concat "[" (nth 2 port) "] ")))
11293 (vhdl-include-direction-comments " "))
11294 (when vhdl-include-port-comments (nth 4 port))) t))
11295 (setq port-list (cdr port-list))
11296 (when port-list (insert "\n") (indent-to margin)))
5eabfe72 11297 ;; align signal list
3dcb36b7 11298 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
5eabfe72
KH
11299 (message "Pasting port as signals...done")))
11300
3dcb36b7
JB
11301(defun vhdl-port-paste-initializations (&optional no-indent)
11302 "Paste ports as signal initializations."
5eabfe72
KH
11303 (interactive)
11304 (if (not vhdl-port-list)
3dcb36b7 11305 (error "ERROR: No port read")
5eabfe72 11306 (let ((orig-vhdl-port-list vhdl-port-list))
3dcb36b7
JB
11307 (message "Pasting port as initializations...")
11308 ;; flatten local copy of port list (must be flat for signal initial.)
5eabfe72 11309 (vhdl-port-flatten)
3dcb36b7 11310 (unless no-indent (indent-according-to-mode))
5eabfe72 11311 (let ((margin (current-indentation))
3dcb36b7
JB
11312 start port name
11313 (port-list (nth 2 vhdl-port-list)))
11314 (when port-list
5eabfe72 11315 (setq start (point))
3dcb36b7
JB
11316 (while port-list
11317 (setq port (car port-list))
11318 ;; paste actual port signal (inputs only)
11319 (when (equal "IN" (upcase (nth 2 port)))
11320 (setq name (car (nth 0 port)))
11321 (insert (vhdl-replace-string vhdl-actual-port-name name))
5eabfe72 11322 ;; paste initialization
3dcb36b7
JB
11323 (insert " <= " (if (string-match "(.+)" (nth 3 port))
11324 "(others => '0')" "'0'") ";"))
11325 (setq port-list (cdr port-list))
11326 (when (and port-list
11327 (equal "IN" (upcase (nth 2 (car port-list)))))
11328 (insert "\n") (indent-to margin)))
11329 ;; align signal list
11330 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
11331 (message "Pasting port as initializations...done")
5eabfe72
KH
11332 (setq vhdl-port-list orig-vhdl-port-list))))
11333
11334(defun vhdl-port-paste-testbench ()
3dcb36b7 11335 "Paste as a bare-bones testbench."
5eabfe72
KH
11336 (interactive)
11337 (if (not vhdl-port-list)
3dcb36b7 11338 (error "ERROR: No port read")
5eabfe72
KH
11339 (let ((case-fold-search t)
11340 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
11341 (nth 0 vhdl-port-list)))
11342 (source-buffer (current-buffer))
3dcb36b7
JB
11343 arch-name config-name ent-file-name arch-file-name
11344 ent-buffer arch-buffer position)
5eabfe72 11345 ;; open entity file
3dcb36b7 11346 (unless (eq vhdl-testbench-create-files 'none)
5eabfe72 11347 (setq ent-file-name
3dcb36b7
JB
11348 (concat ent-name "." (file-name-extension (buffer-file-name))))
11349 (if (file-exists-p ent-file-name)
5eabfe72 11350 (if (y-or-n-p
3dcb36b7
JB
11351 (concat "File \"" ent-file-name "\" exists; overwrite? "))
11352 (progn (find-file ent-file-name)
11353 (erase-buffer)
11354 (set-buffer-modified-p nil))
11355 (if (eq vhdl-testbench-create-files 'separate)
11356 (setq ent-file-name nil)
11357 (error "ERROR: Pasting port as testbench...aborted")))
11358 (find-file ent-file-name)))
11359 (unless (and (eq vhdl-testbench-create-files 'separate)
11360 (null ent-file-name))
11361 ;; paste entity header
11362 (if vhdl-testbench-include-header
11363 (progn (vhdl-template-header
11364 (concat "Testbench for design \""
11365 (nth 0 vhdl-port-list) "\""))
11366 (goto-char (point-max)))
11367 (vhdl-comment-display-line) (insert "\n\n"))
11368 ;; paste std_logic_1164 package
11369 (when vhdl-testbench-include-library
11370 (vhdl-template-package-std-logic-1164)
11371 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
11372 ;; paste entity declaration
11373 (vhdl-insert-keyword "ENTITY ")
5eabfe72
KH
11374 (insert ent-name)
11375 (vhdl-insert-keyword " IS")
3dcb36b7 11376 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
5eabfe72 11377 (insert "\n")
3dcb36b7
JB
11378 (vhdl-insert-keyword "END ")
11379 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
11380 (insert ent-name ";")
11381 (insert "\n\n")
11382 (vhdl-comment-display-line) (insert "\n"))
11383 ;; get architecture name
11384 (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
11385 (read-from-minibuffer "architecture name: "
11386 nil vhdl-minibuffer-local-map)
11387 (vhdl-replace-string vhdl-testbench-architecture-name
11388 (nth 0 vhdl-port-list))))
11389 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
11390 ;; open architecture file
11391 (if (not (eq vhdl-testbench-create-files 'separate))
5eabfe72 11392 (insert "\n")
3dcb36b7
JB
11393 (setq ent-buffer (current-buffer))
11394 (setq arch-file-name
11395 (concat ent-name "_" arch-name "."
11396 (file-name-extension (buffer-file-name))))
11397 (when (and (file-exists-p arch-file-name)
11398 (not (y-or-n-p (concat "File \"" arch-file-name
11399 "\" exists; overwrite? "))))
11400 (error "ERROR: Pasting port as testbench...aborted"))
11401 (find-file arch-file-name)
11402 (erase-buffer)
11403 (set-buffer-modified-p nil)
11404 ;; paste architecture header
11405 (if vhdl-testbench-include-header
11406 (progn (vhdl-template-header
11407 (concat "Testbench architecture for design \""
11408 (nth 0 vhdl-port-list) "\""))
11409 (goto-char (point-max)))
11410 (vhdl-comment-display-line) (insert "\n\n")))
11411 ;; paste architecture body
11412 (vhdl-insert-keyword "ARCHITECTURE ")
11413 (insert arch-name)
11414 (vhdl-insert-keyword " OF ")
11415 (insert ent-name)
11416 (vhdl-insert-keyword " IS")
11417 (insert "\n\n") (indent-to vhdl-basic-offset)
11418 ;; paste component declaration
11419 (unless (vhdl-use-direct-instantiation)
11420 (vhdl-port-paste-component t)
11421 (insert "\n\n") (indent-to vhdl-basic-offset))
11422 ;; paste constants
11423 (when (nth 1 vhdl-port-list)
11424 (insert "-- component generics\n") (indent-to vhdl-basic-offset)
11425 (vhdl-port-paste-constants t)
11426 (insert "\n\n") (indent-to vhdl-basic-offset))
11427 ;; paste internal signals
11428 (insert "-- component ports\n") (indent-to vhdl-basic-offset)
11429 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
11430 (insert "\n")
11431 ;; paste custom declarations
11432 (unless (equal "" vhdl-testbench-declarations)
5eabfe72 11433 (insert "\n")
3dcb36b7
JB
11434 (vhdl-insert-string-or-file vhdl-testbench-declarations))
11435 (setq position (point))
11436 (insert "\n\n")
11437 (vhdl-comment-display-line) (insert "\n")
11438 (when vhdl-testbench-include-configuration
11439 (setq config-name (vhdl-replace-string
11440 vhdl-testbench-configuration-name
11441 (concat ent-name " " arch-name)))
11442 (insert "\n")
11443 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
11444 (vhdl-insert-keyword " OF ") (insert ent-name)
11445 (vhdl-insert-keyword " IS\n")
11446 (indent-to vhdl-basic-offset)
11447 (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
11448 (indent-to vhdl-basic-offset)
11449 (vhdl-insert-keyword "END FOR;\n")
11450 (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
11451 (vhdl-comment-display-line) (insert "\n"))
11452 (goto-char position)
11453 (vhdl-template-begin-end
11454 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
11455 ;; paste instantiation
11456 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
11457 (vhdl-port-paste-instance
11458 (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
11459 (insert "\n")
11460 ;; paste custom statements
11461 (unless (equal "" vhdl-testbench-statements)
11462 (insert "\n")
11463 (vhdl-insert-string-or-file vhdl-testbench-statements))
11464 (insert "\n")
11465 (indent-to vhdl-basic-offset)
11466 (unless (eq vhdl-testbench-create-files 'none)
11467 (setq arch-buffer (current-buffer))
11468 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
11469 (set-buffer arch-buffer) (save-buffer))
11470 (message
11471 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
11472 ent-name arch-name)
11473 (and ent-file-name
11474 (format "\n File created: \"%s\"" ent-file-name))
11475 (and arch-file-name
11476 (format "\n File created: \"%s\"" arch-file-name)))))))
5eabfe72
KH
11477
11478
11479;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11480;;; Subprogram interface translation
5eabfe72
KH
11481;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11482
3dcb36b7
JB
11483(defvar vhdl-subprog-list nil
11484 "Variable to hold last subprogram interface parsed.")
11485;; structure: (parenthesised expression means list of such entries)
11486;; (subprog-name kind
11487;; ((names) object direct type init comment group-comment)
11488;; return-type return-comment group-comment)
5eabfe72 11489
3dcb36b7
JB
11490(defvar vhdl-subprog-flattened nil
11491 "Indicates whether an subprogram interface has been flattened.")
5eabfe72 11492
3dcb36b7
JB
11493(defun vhdl-subprog-flatten ()
11494 "Flatten interface list so that only one parameter exists per line."
11495 (interactive)
11496 (if (not vhdl-subprog-list)
11497 (error "ERROR: No subprogram interface has been read")
11498 (message "Flattening subprogram interface...")
11499 (let ((old-subprog-list (nth 2 vhdl-subprog-list))
11500 new-subprog-list old-subprog new-subprog names)
11501 ;; traverse parameter list and flatten entries
11502 (while old-subprog-list
11503 (setq old-subprog (car old-subprog-list))
11504 (setq names (car old-subprog))
11505 (while names
11506 (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
11507 (setq new-subprog-list (append new-subprog-list (list new-subprog)))
11508 (setq names (cdr names)))
11509 (setq old-subprog-list (cdr old-subprog-list)))
11510 (setq vhdl-subprog-list
11511 (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
11512 new-subprog-list (nth 3 vhdl-subprog-list)
11513 (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
11514 vhdl-subprog-flattened t)
11515 (message "Flattening subprogram interface...done"))))
11516
11517(defun vhdl-subprog-copy ()
11518 "Get interface information from a subprogram specification."
11519 (interactive)
11520 (save-excursion
11521 (let (parse-error pos end-of-list
11522 name kind param-list object names direct type init
11523 comment group-comment
11524 return-type return-comment return-group-comment)
11525 (vhdl-prepare-search-2
11526 (setq
11527 parse-error
11528 (catch 'parse
11529 ;; check if within function declaration
11530 (setq pos (point))
11531 (end-of-line)
11532 (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
11533 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
11534 (goto-char (match-end 0))
11535 (save-excursion (backward-char)
11536 (forward-sexp)
11537 (<= pos (point))))
11538 (throw 'parse "ERROR: Not within a subprogram specification"))
11539 (setq name (match-string-no-properties 5))
11540 (setq kind (if (match-string 2) 'procedure 'function))
11541 (setq end-of-list (not (match-string 7)))
11542 (message "Reading interface of subprogram \"%s\"..." name)
11543 ;; parse parameter list
11544 (setq group-comment (vhdl-parse-group-comment))
11545 (setq end-of-list (or end-of-list
11546 (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
11547 (while (not end-of-list)
11548 ;; parse object
11549 (setq object
11550 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
11551 (match-string-no-properties 1)))
11552 ;; parse names (accept extended identifiers)
11553 (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
11554 (setq names (list (match-string-no-properties 1)))
11555 (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
11556 (setq names (append names (list (match-string-no-properties 1)))))
11557 ;; parse direction
11558 (vhdl-parse-string ":[ \t\n]*")
11559 (setq direct
11560 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
11561 (match-string-no-properties 1)))
11562 ;; parse type
11563 (vhdl-parse-string "\\([^():;\n]+\\)")
11564 (setq type (match-string-no-properties 1))
11565 (setq comment nil)
11566 (while (looking-at "(")
11567 (setq type
11568 (concat type
11569 (buffer-substring-no-properties
11570 (point) (progn (forward-sexp) (point)))
11571 (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
11572 (match-string-no-properties 1)))))
11573 ;; special case: closing parenthesis is on separate line
11574 (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
11575 (setq comment (substring type (match-beginning 2)))
11576 (setq type (substring type 0 (match-beginning 1))))
11577 ;; strip off trailing group-comment
11578 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
11579 (setq type (substring type 0 (match-end 1)))
11580 ;; parse initialization expression
11581 (setq init nil)
11582 (when (vhdl-parse-string ":=[ \t\n]*" t)
11583 (vhdl-parse-string "\\([^();\n]*\\)")
11584 (setq init (match-string-no-properties 1))
11585 (while (looking-at "(")
11586 (setq init
11587 (concat init
11588 (buffer-substring-no-properties
11589 (point) (progn (forward-sexp) (point)))
11590 (and (vhdl-parse-string "\\([^();\n]*\\)" t)
11591 (match-string-no-properties 1))))))
11592 ;; special case: closing parenthesis is on separate line
11593 (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
11594 (setq comment (substring init (match-beginning 2)))
11595 (setq init (substring init 0 (match-beginning 1)))
11596 (vhdl-forward-syntactic-ws))
11597 (skip-chars-forward " \t")
11598 ;; parse inline comment, special case: as above, no initial.
11599 (unless comment
11600 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11601 (match-string-no-properties 1))))
11602 (vhdl-forward-syntactic-ws)
11603 (setq end-of-list (vhdl-parse-string ")\\s-*" t))
11604 ;; parse inline comment
11605 (unless comment
11606 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11607 (match-string-no-properties 1))))
11608 (setq return-group-comment (vhdl-parse-group-comment))
11609 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
11610 ;; parse return type
11611 (when (match-string 3)
11612 (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
11613 (setq return-type (match-string-no-properties 1))
11614 (when (and return-type
11615 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
11616 (setq return-comment (substring return-type (match-beginning 2)))
11617 (setq return-type (substring return-type 0 (match-beginning 1))))
11618 ;; strip of trailing group-comment
11619 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
11620 (setq return-type (substring return-type 0 (match-end 1)))
11621 ;; parse return comment
11622 (unless return-comment
11623 (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11624 (match-string-no-properties 1)))))
11625 ;; parse inline comment
11626 (unless comment
11627 (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
11628 (match-string-no-properties 1))))
11629 ;; save everything in list
11630 (setq param-list (append param-list
11631 (list (list names object direct type init
11632 comment group-comment))))
11633 ;; parse group comment and spacing
11634 (setq group-comment (vhdl-parse-group-comment)))
11635 (message "Reading interface of subprogram \"%s\"...done" name)
11636 nil)))
11637 ;; finish parsing
11638 (if parse-error
11639 (error parse-error)
11640 (setq vhdl-subprog-list
11641 (list name kind param-list return-type return-comment
11642 return-group-comment)
11643 vhdl-subprog-flattened nil)))))
11644
11645(defun vhdl-subprog-paste-specification (kind)
11646 "Paste as a subprogram specification."
11647 (indent-according-to-mode)
11648 (let ((margin (current-column))
11649 (param-list (nth 2 vhdl-subprog-list))
11650 list-margin start names param)
11651 ;; paste keyword and name
11652 (vhdl-insert-keyword
11653 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
11654 (insert (nth 0 vhdl-subprog-list))
11655 (if (not param-list)
11656 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11657 (setq start (point))
11658 ;; paste parameter list
11659 (insert " (")
11660 (unless vhdl-argument-list-indent
11661 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11662 (setq list-margin (current-column))
11663 (while param-list
11664 (setq param (car param-list))
11665 ;; paste group comment and spacing
11666 (when (memq vhdl-include-group-comments (list kind 'always))
11667 (vhdl-paste-group-comment (nth 6 param) list-margin))
11668 ;; paste object
11669 (when (nth 1 param) (insert (nth 1 param) " "))
11670 ;; paste names
11671 (setq names (nth 0 param))
11672 (while names
11673 (insert (car names))
11674 (setq names (cdr names))
11675 (when names (insert ", ")))
11676 ;; paste direction
11677 (insert " : ")
11678 (when (nth 2 param) (insert (nth 2 param) " "))
11679 ;; paste type
11680 (insert (nth 3 param))
11681 ;; paste initialization
11682 (when (nth 4 param) (insert " := " (nth 4 param)))
11683 ;; terminate line
11684 (if (cdr param-list)
11685 (insert ";")
11686 (insert ")")
11687 (when (null (nth 3 vhdl-subprog-list))
11688 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
11689 ;; paste comment
11690 (when (and vhdl-include-port-comments (nth 5 param))
11691 (vhdl-comment-insert-inline (nth 5 param) t))
11692 (setq param-list (cdr param-list))
11693 (when param-list (insert "\n") (indent-to list-margin)))
11694 (when (nth 3 vhdl-subprog-list)
11695 (insert "\n") (indent-to list-margin)
11696 ;; paste group comment and spacing
11697 (when (memq vhdl-include-group-comments (list kind 'always))
11698 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
11699 ;; paste return type
11700 (insert "return " (nth 3 vhdl-subprog-list))
11701 (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
11702 (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
11703 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
11704 ;; align parameter list
11705 (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
11706 ;; paste body
11707 (when (eq kind 'body)
11708 (insert "\n")
11709 (vhdl-template-begin-end
11710 (unless (vhdl-standard-p '87)
11711 (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
11712 (nth 0 vhdl-subprog-list) margin))))
11713
11714(defun vhdl-subprog-paste-declaration ()
11715 "Paste as a subprogram declaration."
11716 (interactive)
11717 (if (not vhdl-subprog-list)
11718 (error "ERROR: No subprogram interface read")
11719 (message "Pasting interface as subprogram declaration \"%s\"..."
11720 (car vhdl-subprog-list))
11721 ;; paste specification
11722 (vhdl-subprog-paste-specification 'decl)
11723 (message "Pasting interface as subprogram declaration \"%s\"...done"
11724 (car vhdl-subprog-list))))
11725
11726(defun vhdl-subprog-paste-body ()
11727 "Paste as a subprogram body."
11728 (interactive)
11729 (if (not vhdl-subprog-list)
11730 (error "ERROR: No subprogram interface read")
11731 (message "Pasting interface as subprogram body \"%s\"..."
11732 (car vhdl-subprog-list))
11733 ;; paste specification and body
11734 (vhdl-subprog-paste-specification 'body)
11735 (message "Pasting interface as subprogram body \"%s\"...done"
11736 (car vhdl-subprog-list))))
11737
11738(defun vhdl-subprog-paste-call ()
11739 "Paste as a subprogram call."
11740 (interactive)
11741 (if (not vhdl-subprog-list)
11742 (error "ERROR: No subprogram interface read")
11743 (let ((orig-vhdl-subprog-list vhdl-subprog-list)
11744 param-list margin list-margin param start)
11745 ;; flatten local copy of interface list (must be flat for parameter mapping)
11746 (vhdl-subprog-flatten)
11747 (setq param-list (nth 2 vhdl-subprog-list))
11748 (indent-according-to-mode)
11749 (setq margin (current-indentation))
11750 (message "Pasting interface as subprogram call \"%s\"..."
11751 (car vhdl-subprog-list))
11752 ;; paste name
11753 (insert (nth 0 vhdl-subprog-list))
11754 (if (not param-list)
11755 (insert ";")
11756 (setq start (point))
11757 ;; paste parameter list
11758 (insert " (")
11759 (unless vhdl-argument-list-indent
11760 (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
11761 (setq list-margin (current-column))
11762 (while param-list
11763 (setq param (car param-list))
11764 ;; paste group comment and spacing
11765 (when (eq vhdl-include-group-comments 'always)
11766 (vhdl-paste-group-comment (nth 6 param) list-margin))
11767 ;; paste formal port
11768 (insert (car (nth 0 param)) " => ")
11769 (setq param-list (cdr param-list))
11770 (insert (if param-list "," ");"))
11771 ;; paste comment
11772 (when (and vhdl-include-port-comments (nth 5 param))
11773 (vhdl-comment-insert-inline (nth 5 param)))
11774 (when param-list (insert "\n") (indent-to list-margin)))
11775 ;; align parameter list
11776 (when vhdl-auto-align
11777 (vhdl-align-region-groups start (point) 1)))
11778 (message "Pasting interface as subprogram call \"%s\"...done"
11779 (car vhdl-subprog-list))
11780 (setq vhdl-subprog-list orig-vhdl-subprog-list))))
11781
11782
11783;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11784;;; Miscellaneous
11785;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11786
11787;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11788;; Hippie expand customization
11789
11790(defvar vhdl-expand-upper-case nil)
11791
11792(defun vhdl-try-expand-abbrev (old)
11793 "Try expanding abbreviations from `vhdl-abbrev-list'."
11794 (unless old
11795 (he-init-string (he-dabbrev-beg) (point))
5eabfe72
KH
11796 (setq he-expand-list
11797 (let ((abbrev-list vhdl-abbrev-list)
11798 (sel-abbrev-list '()))
11799 (while abbrev-list
11800 (when (or (not (stringp (car abbrev-list)))
11801 (string-match
11802 (concat "^" he-search-string) (car abbrev-list)))
11803 (setq sel-abbrev-list
11804 (cons (car abbrev-list) sel-abbrev-list)))
11805 (setq abbrev-list (cdr abbrev-list)))
11806 (nreverse sel-abbrev-list))))
11807 (while (and he-expand-list
11808 (or (not (stringp (car he-expand-list)))
11809 (he-string-member (car he-expand-list) he-tried-table t)))
11810; (equal (car he-expand-list) he-search-string)))
11811 (unless (stringp (car he-expand-list))
11812 (setq vhdl-expand-upper-case (car he-expand-list)))
11813 (setq he-expand-list (cdr he-expand-list)))
11814 (if (null he-expand-list)
11815 (progn (when old (he-reset-string))
11816 nil)
11817 (he-substitute-string
11818 (if vhdl-expand-upper-case
11819 (upcase (car he-expand-list))
11820 (car he-expand-list))
11821 t)
11822 (setq he-expand-list (cdr he-expand-list))
11823 t))
11824
11825(defun vhdl-he-list-beg ()
11826 "Also looks at the word before `(' in order to better match parenthesized
11827expressions (e.g. for index ranges of types and signals)."
11828 (save-excursion
11829 (condition-case ()
11830 (progn (backward-up-list 1)
11831 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
11832 (error ()))
11833 (point)))
11834
11835;; override `he-list-beg' from `hippie-exp'
11836(unless (and (boundp 'viper-mode) viper-mode)
5eabfe72
KH
11837 (defalias 'he-list-beg 'vhdl-he-list-beg))
11838
11839;; function for expanding abbrevs and dabbrevs
3dcb36b7 11840(defun vhdl-expand-abbrev (arg))
5eabfe72
KH
11841(fset 'vhdl-expand-abbrev (make-hippie-expand-function
11842 '(try-expand-dabbrev
11843 try-expand-dabbrev-all-buffers
11844 vhdl-try-expand-abbrev)))
11845
11846;; function for expanding parenthesis
3dcb36b7 11847(defun vhdl-expand-paren (arg))
5eabfe72
KH
11848(fset 'vhdl-expand-paren (make-hippie-expand-function
11849 '(try-expand-list
11850 try-expand-list-all-buffers)))
11851
11852;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11853;; Case fixing
d2ddb974
KH
11854
11855(defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
11856 "Convert all words matching word-regexp in region to lower or upper case,
11857depending on parameter upper-case."
3dcb36b7 11858 (let ((case-replace nil)
5eabfe72 11859 (last-update 0))
3dcb36b7 11860 (vhdl-prepare-search-2
5eabfe72
KH
11861 (save-excursion
11862 (goto-char end)
11863 (setq end (point-marker))
11864 (goto-char beg)
11865 (while (re-search-forward word-regexp end t)
3dcb36b7 11866 (or (vhdl-in-literal)
5eabfe72
KH
11867 (if upper-case
11868 (upcase-word -1)
11869 (downcase-word -1)))
3dcb36b7 11870 (when (and count vhdl-progress-interval (not noninteractive)
5eabfe72
KH
11871 (< vhdl-progress-interval
11872 (- (nth 1 (current-time)) last-update)))
11873 (message "Fixing case... (%2d%s)"
11874 (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
11875 "%")
11876 (setq last-update (nth 1 (current-time)))))
3dcb36b7 11877 (goto-char end)))))
d2ddb974
KH
11878
11879(defun vhdl-fix-case-region (beg end &optional arg)
11880 "Convert all VHDL words in region to lower or upper case, depending on
3dcb36b7 11881options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974
KH
11882 (interactive "r\nP")
11883 (vhdl-fix-case-region-1
5eabfe72 11884 beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
d2ddb974 11885 (vhdl-fix-case-region-1
5eabfe72 11886 beg end vhdl-upper-case-types vhdl-types-regexp 1)
d2ddb974 11887 (vhdl-fix-case-region-1
5eabfe72
KH
11888 beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
11889 (vhdl-fix-case-region-1
3dcb36b7
JB
11890 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
11891 (when vhdl-progress-interval (message "Fixing case...done")))
d2ddb974 11892
5eabfe72
KH
11893(defun vhdl-fix-case-buffer ()
11894 "Convert all VHDL words in buffer to lower or upper case, depending on
3dcb36b7 11895options vhdl-upper-case-{keywords,types,attributes,enum-values}."
d2ddb974 11896 (interactive)
5eabfe72
KH
11897 (vhdl-fix-case-region (point-min) (point-max)))
11898
3dcb36b7
JB
11899(defun vhdl-fix-case-word (&optional arg)
11900 "Convert word after cursor to upper case if necessary."
11901 (interactive "p")
11902 (save-excursion
11903 (when arg (backward-word 1))
11904 (vhdl-prepare-search-1
11905 (when (and vhdl-upper-case-keywords
11906 (looking-at vhdl-keywords-regexp))
11907 (upcase-word 1))
11908 (when (and vhdl-upper-case-types
11909 (looking-at vhdl-types-regexp))
11910 (upcase-word 1))
11911 (when (and vhdl-upper-case-attributes
11912 (looking-at vhdl-attributes-regexp))
11913 (upcase-word 1))
11914 (when (and vhdl-upper-case-enum-values
11915 (looking-at vhdl-enum-values-regexp))
11916 (upcase-word 1)))))
11917
5eabfe72
KH
11918;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11919;; Line handling functions
d2ddb974
KH
11920
11921(defun vhdl-current-line ()
11922 "Return the line number of the line containing point."
11923 (save-restriction
11924 (widen)
11925 (save-excursion
11926 (beginning-of-line)
5eabfe72 11927 (1+ (count-lines 1 (point))))))
d2ddb974 11928
5eabfe72 11929(defun vhdl-line-kill-entire (&optional arg)
d2ddb974 11930 "Delete entire line."
5eabfe72
KH
11931 (interactive "p")
11932 (beginning-of-line)
11933 (kill-line (or arg 1)))
11934
11935(defun vhdl-line-kill (&optional arg)
11936 "Kill current line."
11937 (interactive "p")
11938 (vhdl-line-kill-entire arg))
11939
11940(defun vhdl-line-copy (&optional arg)
11941 "Copy current line."
11942 (interactive "p")
11943 (save-excursion
11944 (beginning-of-line)
11945 (let ((position (point)))
11946 (forward-line (or arg 1))
11947 (copy-region-as-kill position (point)))))
11948
11949(defun vhdl-line-yank ()
11950 "Yank entire line."
d2ddb974 11951 (interactive)
5eabfe72
KH
11952 (beginning-of-line)
11953 (yank))
d2ddb974 11954
5eabfe72
KH
11955(defun vhdl-line-expand (&optional prefix-arg)
11956 "Hippie-expand current line."
11957 (interactive "P")
11958 (let ((case-fold-search t) (case-replace nil)
11959 (hippie-expand-try-functions-list
11960 '(try-expand-line try-expand-line-all-buffers)))
11961 (hippie-expand prefix-arg)))
11962
11963(defun vhdl-line-transpose-next (&optional arg)
11964 "Interchange this line with next line."
11965 (interactive "p")
11966 (forward-line 1)
11967 (transpose-lines (or arg 1))
11968 (forward-line -1))
11969
11970(defun vhdl-line-transpose-previous (&optional arg)
11971 "Interchange this line with previous line."
11972 (interactive "p")
11973 (forward-line 1)
11974 (transpose-lines (- 0 (or arg 0)))
11975 (forward-line -1))
11976
11977(defun vhdl-line-open ()
d2ddb974
KH
11978 "Open a new line and indent."
11979 (interactive)
5eabfe72
KH
11980 (end-of-line -0)
11981 (newline-and-indent))
d2ddb974 11982
3dcb36b7
JB
11983(defun vhdl-delete-indentation ()
11984 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
11985it works within comments too."
11986 (interactive)
11987 (let ((fill-prefix "-- "))
11988 (delete-indentation)))
d2ddb974 11989
5eabfe72 11990;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 11991;; Move functions
d2ddb974 11992
3dcb36b7
JB
11993(defun vhdl-forward-same-indent ()
11994 "Move forward to next line with same indent."
11995 (interactive)
11996 (let ((pos (point))
11997 (indent (current-indentation)))
11998 (beginning-of-line 2)
11999 (while (and (not (eobp))
12000 (or (looking-at "^\\s-*\\(--.*\\)?$")
12001 (> (current-indentation) indent)))
12002 (beginning-of-line 2))
12003 (if (= (current-indentation) indent)
12004 (back-to-indentation)
12005 (message "No following line with same indent found in this block")
12006 (goto-char pos)
12007 nil)))
5eabfe72 12008
3dcb36b7
JB
12009(defun vhdl-backward-same-indent ()
12010 "Move backward to previous line with same indent."
12011 (interactive)
12012 (let ((pos (point))
12013 (indent (current-indentation)))
12014 (beginning-of-line -0)
12015 (while (and (not (bobp))
12016 (or (looking-at "^\\s-*\\(--.*\\)?$")
12017 (> (current-indentation) indent)))
12018 (beginning-of-line -0))
12019 (if (= (current-indentation) indent)
12020 (back-to-indentation)
12021 (message "No preceding line with same indent found in this block")
12022 (goto-char pos)
12023 nil)))
5eabfe72
KH
12024
12025;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
12026;; Statistics
12027
12028(defun vhdl-statistics-buffer ()
12029 "Get some file statistics."
12030 (interactive)
12031 (let ((no-stats 0)
12032 (no-code-lines 0)
12033 (no-lines (count-lines (point-min) (point-max))))
12034 (save-excursion
12035 ;; count statements
12036 (goto-char (point-min))
12037 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
12038 (if (match-string 1)
12039 (goto-char (match-end 1))
12040 (setq no-stats (1+ no-stats))))
12041 ;; count code lines
12042 (goto-char (point-min))
12043 (while (not (eobp))
12044 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12045 (setq no-code-lines (1+ no-code-lines)))
12046 (beginning-of-line 2)))
12047 ;; print results
12048 (message "\n\
12049File statistics: \"%s\"\n\
12050---------------------\n\
12051# statements : %5d\n\
12052# code lines : %5d\n\
12053# total lines : %5d\n\ "
12054 (buffer-file-name) no-stats no-code-lines no-lines)
12055 (unless vhdl-emacs-21 (vhdl-show-messages))))
12056
5eabfe72 12057;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12058;; Help functions
d2ddb974 12059
3dcb36b7
JB
12060(defun vhdl-re-search-forward (regexp &optional bound noerror count)
12061 "Like `re-search-forward', but does not match within literals."
12062 (let (pos)
12063 (save-excursion
12064 (while (and (setq pos (re-search-forward regexp bound noerror count))
12065 (vhdl-in-literal))))
12066 (when pos (goto-char pos))
12067 pos))
12068
12069(defun vhdl-re-search-backward (regexp &optional bound noerror count)
12070 "Like `re-search-backward', but does not match within literals."
12071 (let (pos)
12072 (save-excursion
12073 (while (and (setq pos (re-search-backward regexp bound noerror count))
12074 (vhdl-in-literal))))
12075 (when pos (goto-char pos))
12076 pos))
5eabfe72 12077
d2ddb974 12078
3dcb36b7
JB
12079;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12080;;; Project
12081;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12082
12083(defun vhdl-set-project (name)
12084 "Set current project to NAME."
12085 (interactive
12086 (list (let ((completion-ignore-case t))
12087 (completing-read "Project name: " vhdl-project-alist nil t))))
12088 (cond ((equal name "")
12089 (setq vhdl-project nil)
12090 (message "Current VHDL project: None"))
12091 ((assoc name vhdl-project-alist)
12092 (setq vhdl-project name)
12093 (message "Current VHDL project: \"%s\"" name))
12094 (t
12095 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
12096 (vhdl-speedbar-update-current-project))
12097
12098(defun vhdl-toggle-project (name token indent)
12099 "Set current project to NAME or unset if NAME is current project."
12100 (vhdl-set-project (if (equal name vhdl-project) "" name)))
12101
12102(defun vhdl-export-project (file-name)
12103 "Write project setup for current project."
12104 (interactive
12105 (let ((name (vhdl-resolve-env-variable
12106 (vhdl-replace-string
12107 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12108 (concat (subst-char-in-string
12109 ? ?_ (or (vhdl-project-p)
12110 (error "ERROR: No current project")))
12111 " " (user-login-name))))))
12112 (list (read-file-name
12113 "Write project file: "
12114 (when (file-name-absolute-p name) "") nil nil name))))
12115 (setq file-name (abbreviate-file-name file-name))
12116 (let ((orig-buffer (current-buffer)))
12117 (unless (file-exists-p (file-name-directory file-name))
12118 (make-directory (file-name-directory file-name) t))
12119 (if (not (file-writable-p file-name))
12120 (error "ERROR: File not writable: \"%s\"" file-name)
12121 (set-buffer (find-file-noselect file-name t t))
12122 (erase-buffer)
12123 (insert ";; -*- Emacs-Lisp -*-\n\n"
12124 ";;; " (file-name-nondirectory file-name)
12125 " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
12126 ";; Project : " vhdl-project "\n"
12127 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12128 (user-login-name) "\n\n\n"
12129 ";; project name\n"
12130 "(setq vhdl-project \"" vhdl-project "\")\n\n"
12131 ";; project setup\n"
12132 "(aput 'vhdl-project-alist vhdl-project\n'")
12133 (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
12134 (insert ")\n")
12135 (save-buffer)
12136 (kill-buffer (current-buffer))
12137 (set-buffer orig-buffer))))
12138
12139(defun vhdl-import-project (file-name &optional auto not-make-current)
12140 "Read project setup and set current project."
12141 (interactive
12142 (let ((name (vhdl-resolve-env-variable
12143 (vhdl-replace-string
12144 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
12145 (concat "" " " (user-login-name))))))
12146 (list (read-file-name
12147 "Read project file: " (when (file-name-absolute-p name) "") nil t
12148 (file-name-directory name)))))
12149 (when (file-exists-p file-name)
12150 (condition-case ()
12151 (let ((current-project vhdl-project))
12152 (load-file file-name)
12153 (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
12154 (adelete 'vhdl-project-alist vhdl-project)
12155 (error))
12156 (when not-make-current
12157 (setq vhdl-project current-project))
12158 (vhdl-update-mode-menu)
12159 (vhdl-speedbar-refresh)
12160 (unless not-make-current
12161 (message "Current VHDL project: \"%s\"%s"
12162 vhdl-project (if auto " (auto-loaded)" ""))))
12163 (error (vhdl-warning
12164 (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
12165
12166(defun vhdl-duplicate-project ()
12167 "Duplicate setup of current project."
5eabfe72 12168 (interactive)
3dcb36b7
JB
12169 (let ((new-name (read-from-minibuffer "New project name: "))
12170 (project-entry (aget vhdl-project-alist vhdl-project t)))
12171 (setq vhdl-project-alist
12172 (append vhdl-project-alist
12173 (list (cons new-name project-entry))))
12174 (vhdl-update-mode-menu)))
12175
12176(defun vhdl-auto-load-project ()
12177 "Automatically load project setup at startup."
12178 (let ((file-name-list vhdl-project-file-name)
12179 file-list list-length)
12180 (while file-name-list
12181 (setq file-list
12182 (append file-list
12183 (file-expand-wildcards
12184 (vhdl-resolve-env-variable
12185 (vhdl-replace-string
12186 (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
12187 (concat "\*" " " (user-login-name)))))))
12188 (setq list-length (or list-length (length file-list)))
12189 (setq file-name-list (cdr file-name-list)))
12190 (while file-list
12191 (vhdl-import-project (expand-file-name (car file-list)) t
12192 (not (> list-length 0)))
12193 (setq list-length (1- list-length))
12194 (setq file-list (cdr file-list)))))
12195
12196;; automatically load project setup when idle after startup
12197(when (memq 'startup vhdl-project-auto-load)
12198 (if noninteractive
12199 (vhdl-auto-load-project)
12200 (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
5eabfe72
KH
12201
12202
12203;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12204;;; Hideshow
12205;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12206;; (using `hideshow.el')
d2ddb974 12207
3dcb36b7
JB
12208(defconst vhdl-hs-start-regexp
12209 (concat
12210 "\\(^\\)\\s-*\\("
12211 ;; generic/port clause
12212 "\\(generic\\|port\\)[ \t\n]*(\\|"
12213 ;; component
12214 "component\\>\\|"
12215 ;; component instantiation
12216 "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
12217 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12218 "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
12219 "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
12220 ;; subprogram
12221 "\\(function\\|procedure\\)\\>\\|"
12222 ;; process, block
12223 "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
12224 ;; configuration declaration
12225 "configuration\\>"
12226 "\\)")
12227 "Regexp to match start of construct to hide.")
12228
12229(defun vhdl-hs-forward-sexp-func (count)
12230 "Find end of construct to hide (for hideshow). Only searches forward."
12231 (let ((pos (point)))
12232 (vhdl-prepare-search-2
12233 (beginning-of-line)
12234 (cond
12235 ;; generic/port clause
12236 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
12237 (goto-char (match-end 0))
12238 (backward-char)
12239 (forward-sexp))
12240 ;; component declaration
12241 ((looking-at "^\\s-*component\\>")
12242 (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
12243 ;; component instantiation
12244 ((looking-at
12245 (concat
12246 "^\\s-*\\w+\\s-*:[ \t\n]*"
12247 "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
12248 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
12249 "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
12250 (goto-char (match-end 0))
12251 (backward-char)
12252 (forward-sexp)
12253 (setq pos (point))
12254 (vhdl-forward-syntactic-ws)
12255 (when (looking-at "port\\s-+map[ \t\n]*(")
12256 (goto-char (match-end 0))
12257 (backward-char)
12258 (forward-sexp)
12259 (setq pos (point)))
12260 (goto-char pos))
12261 ;; subprogram declaration/body
12262 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
12263 (goto-char (match-end 0))
12264 (vhdl-forward-syntactic-ws)
12265 (when (looking-at "(")
12266 (forward-sexp))
12267 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
12268 (vhdl-in-literal)))
12269 ;; subprogram body
12270 (when (match-string 2)
12271 (re-search-forward "^\\s-*\\<begin\\>" nil t)
12272 (backward-word 1)
12273 (vhdl-forward-sexp)))
12274 ;; block (recursive)
12275 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
12276 (goto-char (match-end 0))
12277 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
12278 (match-beginning 2))
12279 (vhdl-hs-forward-sexp-func count)))
12280 ;; process
12281 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
12282 (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
12283 ;; configuration declaration
12284 ((looking-at "^\\s-*configuration\\>")
12285 (forward-word 4)
12286 (vhdl-forward-sexp))
12287 (t (goto-char pos))))))
5eabfe72
KH
12288
12289(defun vhdl-hideshow-init ()
12290 "Initialize `hideshow'."
3dcb36b7
JB
12291 (when vhdl-hideshow-menu
12292 (vhdl-hs-minor-mode 1)))
12293
12294(defun vhdl-hs-minor-mode (&optional arg)
12295 "Toggle hideshow minor mode and update menu bar."
12296 (interactive "P")
12297 (require 'hideshow)
12298 ;; check for hideshow version 5.x
12299 (if (not (boundp 'hs-block-start-mdata-select))
12300 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
12301 ;; initialize hideshow
12302 (unless (assoc 'vhdl-mode hs-special-modes-alist)
12303 (setq hs-special-modes-alist
12304 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
12305 'vhdl-hs-forward-sexp-func nil)
12306 hs-special-modes-alist)))
12307 (make-local-variable 'hs-minor-mode-hook)
12308 (if vhdl-hide-all-init
12309 (add-hook 'hs-minor-mode-hook 'hs-hide-all)
12310 (remove-hook 'hs-minor-mode-hook 'hs-hide-all))
12311 (hs-minor-mode arg)
12312 (vhdl-mode-line-update))) ; hack to update menu bar
5eabfe72
KH
12313
12314
12315;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12316;;; Font locking
12317;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12318;; (using `font-lock.el')
12319
5eabfe72 12320;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7 12321;; Help functions
5eabfe72
KH
12322
12323(defun vhdl-within-translate-off ()
12324 "Return point if within translate-off region, else nil."
12325 (and (save-excursion
12326 (re-search-backward
12327 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
12328 (equal "off" (match-string 1))
12329 (point)))
12330
12331(defun vhdl-start-translate-off (limit)
12332 "Return point before translate-off pragma if before LIMIT, else nil."
12333 (when (re-search-forward
12334 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
12335 (match-beginning 0)))
12336
12337(defun vhdl-end-translate-off (limit)
12338 "Return point after translate-on pragma if before LIMIT, else nil."
12339 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
12340
12341(defun vhdl-match-translate-off (limit)
12342 "Match a translate-off block, setting match-data and returning t, else nil."
12343 (when (< (point) limit)
12344 (let ((start (or (vhdl-within-translate-off)
12345 (vhdl-start-translate-off limit)))
12346 (case-fold-search t))
12347 (when start
12348 (let ((end (or (vhdl-end-translate-off limit) limit)))
12349 (set-match-data (list start end))
12350 (goto-char end))))))
12351
12352(defun vhdl-font-lock-match-item (limit)
12353 "Match, and move over, any declaration item after point. Adapted from
12354`font-lock-match-c-style-declaration-item-and-skip-to-next'."
12355 (condition-case nil
12356 (save-restriction
12357 (narrow-to-region (point-min) limit)
12358 ;; match item
3dcb36b7 12359 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5eabfe72
KH
12360 (save-match-data
12361 (goto-char (match-end 1))
12362 ;; move to next item
12363 (if (looking-at "\\(\\s-*,\\)")
12364 (goto-char (match-end 1))
12365 (end-of-line) t))))
12366 (error t)))
12367
12368;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12369;; Syntax definitions
12370
5eabfe72
KH
12371(defconst vhdl-font-lock-syntactic-keywords
12372 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
12373 "Mark single quotes as having string quote syntax in 'c' instances.")
12374
d2ddb974
KH
12375(defvar vhdl-font-lock-keywords nil
12376 "Regular expressions to highlight in VHDL Mode.")
12377
3dcb36b7
JB
12378(defvar vhdl-font-lock-keywords-0
12379 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12380 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12381This does highlighting of template prompts and directives (pragmas).")
d2ddb974 12382
5eabfe72 12383(defvar vhdl-font-lock-keywords-1 nil
3dcb36b7 12384 ;; set in `vhdl-font-lock-init' because dependent on user options
5eabfe72
KH
12385 "For consideration as a value of `vhdl-font-lock-keywords'.
12386This does highlighting of keywords and standard identifiers.")
12387
12388(defconst vhdl-font-lock-keywords-2
d2ddb974
KH
12389 (list
12390 ;; highlight names of units, subprograms, and components when declared
12391 (list
12392 (concat
12393 "^\\s-*\\("
3dcb36b7
JB
12394 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
12395 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
d2ddb974 12396 "\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12397 5 'font-lock-function-name-face)
12398
12399 ;; highlight entity names of architectures and configurations
12400 (list
12401 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
12402 2 'font-lock-function-name-face)
d2ddb974
KH
12403
12404 ;; highlight labels of common constructs
12405 (list
12406 (concat
3dcb36b7
JB
12407 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
12408 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
12409 "postponed\\|process\\|"
5eabfe72
KH
12410 (when (vhdl-standard-p 'ams) "procedural\\|")
12411 "with\\|while"
3dcb36b7 12412 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\)*\\s-*<=\\)")
d2ddb974
KH
12413 1 'font-lock-function-name-face)
12414
5eabfe72 12415 ;; highlight label and component name of component instantiations
d2ddb974 12416 (list
5eabfe72 12417 (concat
3dcb36b7
JB
12418 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
12419 "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
12420 '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
12421
12422 ;; highlight label and instantiated unit of component instantiations
12423 (list
12424 (concat
12425 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
12426 "\\(component\\|configuration\\|entity\\)\\s-+"
12427 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
12428 '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
12429 '(5 font-lock-function-name-face nil t)
12430 '(7 font-lock-function-name-face nil t))
d2ddb974
KH
12431
12432 ;; highlight names and labels at end of constructs
12433 (list
12434 (concat
5eabfe72
KH
12435 "^\\s-*end\\s-+\\(\\("
12436 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
3dcb36b7
JB
12437 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
12438 "procedure\\|\\(postponed\\s-+\\)?process\\|"
5eabfe72
KH
12439 (when (vhdl-standard-p 'ams) "procedural\\|")
12440 "units"
3dcb36b7 12441 "\\)\\s-+\\)?\\(\\w*\\)")
5eabfe72
KH
12442 5 'font-lock-function-name-face)
12443
12444 ;; highlight labels in exit and next statements
12445 (list
12446 (concat
12447 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
12448 3 'font-lock-function-name-face)
12449
12450 ;; highlight entity name in attribute specifications
12451 (list
12452 (concat
12453 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
12454 1 'font-lock-function-name-face)
12455
3dcb36b7
JB
12456 ;; highlight labels in block and component specifications
12457 (list
12458 (concat
12459 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
12460 "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
12461 '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
12462
12463 ;; highlight names in library clauses
12464 (list "^\\s-*library\\>"
12465 '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
12466
12467 ;; highlight names in use clauses
5eabfe72
KH
12468 (list
12469 (concat
3dcb36b7
JB
12470 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
12471 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
12472 '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
12473 '(7 font-lock-function-name-face nil t))
5eabfe72
KH
12474
12475 ;; highlight attribute name in attribute declarations/specifications
12476 (list
12477 (concat
12478 "^\\s-*attribute\\s-+\\(\\w+\\)")
12479 1 'vhdl-font-lock-attribute-face)
12480
12481 ;; highlight type/nature name in (sub)type/(sub)nature declarations
12482 (list
12483 (concat
3dcb36b7 12484 "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
5eabfe72
KH
12485 3 'font-lock-type-face)
12486
12487 ;; highlight signal/variable/constant declaration names
12488 (list "\\(:[^=]\\)"
12489 '(vhdl-font-lock-match-item
12490 (progn (goto-char (match-beginning 1))
12491 (skip-syntax-backward " ")
12492 (skip-syntax-backward "w_")
12493 (skip-syntax-backward " ")
12494 (while (= (preceding-char) ?,)
12495 (backward-char 1)
12496 (skip-syntax-backward " ")
12497 (skip-syntax-backward "w_")
12498 (skip-syntax-backward " ")))
12499; (skip-chars-backward "^-(\n\";")
12500 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12501
3dcb36b7
JB
12502 ;; highlight formal parameters in component instantiations and subprogram
12503 ;; calls
12504 (list "\\(=>\\)"
12505 '(vhdl-font-lock-match-item
12506 (progn (goto-char (match-beginning 1))
12507 (skip-syntax-backward " ")
12508 (while (= (preceding-char) ?\)) (backward-sexp))
12509 (skip-syntax-backward "w_")
12510 (skip-syntax-backward " ")
12511 (when (memq (preceding-char) '(?n ?N))
12512 (goto-char (point-max))))
12513 (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
12514
12515 ;; highlight alias/group/quantity declaration names and for-loop/-generate
12516 ;; variables
12517 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
5eabfe72
KH
12518 '(vhdl-font-lock-match-item
12519 (progn (goto-char (match-end 1)) (match-beginning 2))
12520 nil (1 font-lock-variable-name-face)))
d2ddb974 12521 )
5eabfe72
KH
12522 "For consideration as a value of `vhdl-font-lock-keywords'.
12523This does context sensitive highlighting of names and labels.")
d2ddb974 12524
5eabfe72 12525(defvar vhdl-font-lock-keywords-3 nil
3dcb36b7 12526 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12527 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72
KH
12528This does highlighting of words with special syntax.")
12529
12530(defvar vhdl-font-lock-keywords-4 nil
3dcb36b7 12531 ;; set in `vhdl-font-lock-init' because dependent on user options
d2ddb974 12532 "For consideration as a value of `vhdl-font-lock-keywords'.
5eabfe72 12533This does highlighting of additional reserved words.")
d2ddb974 12534
5eabfe72
KH
12535(defconst vhdl-font-lock-keywords-5
12536 ;; background highlight translate-off regions
12537 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
12538 "For consideration as a value of `vhdl-font-lock-keywords'.
12539This does background highlighting of translate-off regions.")
12540
12541;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12542;; Font and color definitions
12543
5eabfe72 12544(defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
d2ddb974
KH
12545 "Face name to use for prompts.")
12546
5eabfe72
KH
12547(defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
12548 "Face name to use for standardized attributes.")
12549
12550(defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
12551 "Face name to use for standardized enumeration values.")
d2ddb974 12552
5eabfe72
KH
12553(defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
12554 "Face name to use for standardized functions and packages.")
d2ddb974 12555
5eabfe72
KH
12556(defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
12557 "Face name to use for directives.")
d2ddb974 12558
5eabfe72
KH
12559(defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
12560 "Face name to use for additional reserved words.")
d2ddb974 12561
5eabfe72
KH
12562(defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
12563 "Face name to use for translate-off regions.")
d2ddb974 12564
5eabfe72
KH
12565;; face names to use for words with special syntax.
12566(let ((syntax-alist vhdl-special-syntax-alist)
12567 name)
12568 (while syntax-alist
12569 (setq name (vhdl-function-name
12570 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
d4a5b644
GM
12571 (eval `(defvar ,name ',name
12572 ,(concat "Face name to use for "
12573 (nth 0 (car syntax-alist)) ".")))
5eabfe72
KH
12574 (setq syntax-alist (cdr syntax-alist))))
12575
3dcb36b7 12576(defgroup vhdl-highlight-faces nil
5eabfe72
KH
12577 "Faces for highlighting."
12578 :group 'vhdl-highlight)
d2ddb974 12579
3dcb36b7
JB
12580;; add faces used from `font-lock'
12581(custom-add-to-group
12582 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
12583(custom-add-to-group
12584 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
12585(custom-add-to-group
12586 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
12587(custom-add-to-group
12588 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
12589(custom-add-to-group
12590 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
12591(custom-add-to-group
12592 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
12593
d2ddb974 12594(defface vhdl-font-lock-prompt-face
3dcb36b7
JB
12595 '((((class color) (background light)) (:foreground "Red" :bold t))
12596 (((class color) (background dark)) (:foreground "Pink" :bold t))
d2ddb974 12597 (t (:inverse-video t)))
5eabfe72
KH
12598 "Font lock mode face used to highlight prompts."
12599 :group 'vhdl-highlight-faces
d2ddb974
KH
12600 :group 'font-lock-highlighting-faces)
12601
12602(defface vhdl-font-lock-attribute-face
5eabfe72
KH
12603 '((((class color) (background light)) (:foreground "Orchid"))
12604 (((class color) (background dark)) (:foreground "LightSteelBlue"))
3dcb36b7 12605 (t (:italic t :bold t)))
5eabfe72
KH
12606 "Font lock mode face used to highlight standardized attributes."
12607 :group 'vhdl-highlight-faces
d2ddb974
KH
12608 :group 'font-lock-highlighting-faces)
12609
5eabfe72 12610(defface vhdl-font-lock-enumvalue-face
3dcb36b7 12611 '((((class color) (background light)) (:foreground "SaddleBrown"))
5eabfe72 12612 (((class color) (background dark)) (:foreground "BurlyWood"))
3dcb36b7 12613 (t (:italic t :bold t)))
5eabfe72
KH
12614 "Font lock mode face used to highlight standardized enumeration values."
12615 :group 'vhdl-highlight-faces
d2ddb974
KH
12616 :group 'font-lock-highlighting-faces)
12617
5eabfe72 12618(defface vhdl-font-lock-function-face
3dcb36b7 12619 '((((class color) (background light)) (:foreground "Cyan4"))
5eabfe72 12620 (((class color) (background dark)) (:foreground "Orchid1"))
3dcb36b7 12621 (t (:italic t :bold t)))
5eabfe72
KH
12622 "Font lock mode face used to highlight standardized functions and packages."
12623 :group 'vhdl-highlight-faces
d2ddb974
KH
12624 :group 'font-lock-highlighting-faces)
12625
5eabfe72
KH
12626(defface vhdl-font-lock-directive-face
12627 '((((class color) (background light)) (:foreground "CadetBlue"))
12628 (((class color) (background dark)) (:foreground "Aquamarine"))
3dcb36b7 12629 (t (:italic t :bold t)))
5eabfe72
KH
12630 "Font lock mode face used to highlight directives."
12631 :group 'vhdl-highlight-faces
d2ddb974
KH
12632 :group 'font-lock-highlighting-faces)
12633
5eabfe72 12634(defface vhdl-font-lock-reserved-words-face
3dcb36b7
JB
12635 '((((class color) (background light)) (:foreground "Orange" :bold t))
12636 (((class color) (background dark)) (:foreground "Yellow" :bold t))
d2ddb974 12637 (t ()))
5eabfe72
KH
12638 "Font lock mode face used to highlight additional reserved words."
12639 :group 'vhdl-highlight-faces
d2ddb974
KH
12640 :group 'font-lock-highlighting-faces)
12641
5eabfe72
KH
12642(defface vhdl-font-lock-translate-off-face
12643 '((((class color) (background light)) (:background "LightGray"))
12644 (((class color) (background dark)) (:background "DimGray"))
d2ddb974 12645 (t ()))
5eabfe72
KH
12646 "Font lock mode face used to background highlight translate-off regions."
12647 :group 'vhdl-highlight-faces
d2ddb974
KH
12648 :group 'font-lock-highlighting-faces)
12649
5eabfe72
KH
12650;; font lock mode faces used to highlight words with special syntax.
12651(let ((syntax-alist vhdl-special-syntax-alist))
12652 (while syntax-alist
d4a5b644 12653 (eval `(defface ,(vhdl-function-name
3dcb36b7 12654 "vhdl-font-lock" (caar syntax-alist) "face")
d4a5b644
GM
12655 '((((class color) (background light))
12656 (:foreground ,(nth 2 (car syntax-alist))))
12657 (((class color) (background dark))
12658 (:foreground ,(nth 3 (car syntax-alist))))
12659 (t ()))
12660 ,(concat "Font lock mode face used to highlight "
12661 (nth 0 (car syntax-alist)) ".")
12662 :group 'vhdl-highlight-faces
12663 :group 'font-lock-highlighting-faces))
5eabfe72
KH
12664 (setq syntax-alist (cdr syntax-alist))))
12665
12666;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
12667;; Font lock initialization
12668
12669(defun vhdl-font-lock-init ()
5eabfe72 12670 "Initialize fontification."
3dcb36b7
JB
12671 ;; highlight template prompts and directives
12672 (setq vhdl-font-lock-keywords-0
12673 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
12674 vhdl-template-prompt-syntax ">\\)")
12675 2 'vhdl-font-lock-prompt-face t)
12676 (list (concat "--\\s-*"
12677 vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
12678 2 'vhdl-font-lock-directive-face t)))
5eabfe72
KH
12679 ;; highlight keywords and standardized types, attributes, enumeration
12680 ;; values, and subprograms
12681 (setq vhdl-font-lock-keywords-1
12682 (list
12683 (list (concat "'" vhdl-attributes-regexp)
12684 1 'vhdl-font-lock-attribute-face)
12685 (list vhdl-types-regexp 1 'font-lock-type-face)
12686 (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
12687 (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
12688 (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
12689 (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
12690 ;; highlight words with special syntax.
12691 (setq vhdl-font-lock-keywords-3
12692 (let ((syntax-alist vhdl-special-syntax-alist)
12693 keywords)
12694 (while syntax-alist
12695 (setq keywords
12696 (cons
12697 (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
12698 (vhdl-function-name
12699 "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
12700 keywords))
12701 (setq syntax-alist (cdr syntax-alist)))
12702 keywords))
12703 ;; highlight additional reserved words
12704 (setq vhdl-font-lock-keywords-4
12705 (list (list vhdl-reserved-words-regexp 1
12706 'vhdl-font-lock-reserved-words-face)))
12707 ;; highlight everything together
d2ddb974 12708 (setq vhdl-font-lock-keywords
5eabfe72
KH
12709 (append
12710 vhdl-font-lock-keywords-0
12711 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
12712 (when (or vhdl-highlight-forbidden-words
12713 vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
12714 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
12715 (when vhdl-highlight-names vhdl-font-lock-keywords-2)
12716 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
12717
12718;; initialize fontification for VHDL Mode
12719(vhdl-font-lock-init)
12720
12721(defun vhdl-fontify-buffer ()
12722 "Re-initialize fontification and fontify buffer."
12723 (interactive)
12724 (setq font-lock-defaults
12725 (list
12726 'vhdl-font-lock-keywords nil
12727 (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line
12728 '(font-lock-syntactic-keywords . vhdl-font-lock-syntactic-keywords)))
12729 (when (fboundp 'font-lock-unset-defaults)
12730 (font-lock-unset-defaults)) ; not implemented in XEmacs
12731 (font-lock-set-defaults)
3dcb36b7
JB
12732 (font-lock-mode nil)
12733 (font-lock-mode t))
5eabfe72
KH
12734
12735;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12736;; Initialization for postscript printing
12737
12738(defun vhdl-ps-print-settings ()
12739 "Initialize custom face and page settings for postscript printing."
12740 ;; define custom face settings
12741 (unless (or (not vhdl-print-customize-faces)
d2ddb974
KH
12742 ps-print-color-p)
12743 (set (make-local-variable 'ps-bold-faces)
12744 '(font-lock-keyword-face
12745 font-lock-type-face
12746 vhdl-font-lock-attribute-face
5eabfe72
KH
12747 vhdl-font-lock-enumvalue-face
12748 vhdl-font-lock-directive-face))
d2ddb974
KH
12749 (set (make-local-variable 'ps-italic-faces)
12750 '(font-lock-comment-face
12751 font-lock-function-name-face
12752 font-lock-type-face
d2ddb974 12753 vhdl-font-lock-attribute-face
5eabfe72
KH
12754 vhdl-font-lock-enumvalue-face
12755 vhdl-font-lock-directive-face))
d2ddb974
KH
12756 (set (make-local-variable 'ps-underlined-faces)
12757 '(font-lock-string-face))
5eabfe72 12758 (setq ps-always-build-face-reference t))
d2ddb974
KH
12759 ;; define page settings, so that a line containing 79 characters (default)
12760 ;; fits into one column
5eabfe72
KH
12761 (when vhdl-print-two-column
12762 (set (make-local-variable 'ps-landscape-mode) t)
12763 (set (make-local-variable 'ps-number-of-columns) 2)
12764 (set (make-local-variable 'ps-font-size) 7.0)
12765 (set (make-local-variable 'ps-header-title-font-size) 10.0)
12766 (set (make-local-variable 'ps-header-font-size) 9.0)
12767 (set (make-local-variable 'ps-header-offset) 12.0)
12768 (when (eq ps-paper-type 'letter)
12769 (set (make-local-variable 'ps-inter-column) 40.0)
12770 (set (make-local-variable 'ps-left-margin) 40.0)
12771 (set (make-local-variable 'ps-right-margin) 40.0))))
12772
12773(defun vhdl-ps-print-init ()
12774 "Initialize postscript printing."
3dcb36b7
JB
12775 (if vhdl-xemacs
12776 (when (boundp 'ps-print-color-p)
12777 (vhdl-ps-print-settings))
5eabfe72
KH
12778 (make-local-variable 'ps-print-hook)
12779 (add-hook 'ps-print-hook 'vhdl-ps-print-settings)))
12780
12781
12782;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12783;;; Hierarchy browser (using `speedbar.el')
12784;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12785;; Allows displaying the hierarchy of all VHDL design units contained in a
12786;; directory by using the speedbar.
12787
12788;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12789;; Variables
12790
12791(defvar vhdl-entity-alist nil
3dcb36b7
JB
12792 "Cache with entities and corresponding architectures for each
12793project/directory.")
5eabfe72 12794;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12795;; (cache-key
12796;; (ent-key ent-name ent-file ent-line
12797;; (arch-key arch-name arch-file arch-line
12798;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
12799;; inst-arch-key inst-conf-key inst-lib-key)
12800;; (lib-name pack-key))
12801;; (lib-name pack-key))
12802
12803(defvar vhdl-config-alist nil
12804 "Cache with configurations for each project/directory.")
12805;; structure: (parenthesised expression means list of such entries)
12806;; (cache-key
12807;; (conf-key conf-name conf-file conf-line ent-key arch-key
12808;; (inst-key inst-comp-name inst-ent-key inst-arch-key
12809;; inst-conf-key inst-lib-key)
12810;; (lib-name pack-key)))
5eabfe72
KH
12811
12812(defvar vhdl-package-alist nil
3dcb36b7 12813 "Cache with packages for each project/directory.")
5eabfe72 12814;; structure: (parenthesised expression means list of such entries)
3dcb36b7
JB
12815;; (cache-key
12816;; (pack-key pack-name pack-file pack-line
12817;; (comp-key comp-name comp-file comp-line)
12818;; (func-key func-name func-file func-line)
12819;; (lib-name pack-key)
12820;; pack-body-file pack-body-line
12821;; (func-key func-name func-body-file func-body-line)
12822;; (lib-name pack-key)))
5eabfe72
KH
12823
12824(defvar vhdl-ent-inst-alist nil
3dcb36b7 12825 "Cache with instantiated entities for each project/directory.")
5eabfe72 12826;; structure: (parenthesised expression means list of such entries)
3dcb36b7 12827;; (cache-key (inst-ent-key))
5eabfe72 12828
3dcb36b7
JB
12829(defvar vhdl-file-alist nil
12830 "Cache with design units in each file for each project/directory.")
12831;; structure: (parenthesised expression means list of such entries)
12832;; (cache-key
12833;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
12834;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
5eabfe72 12835
3dcb36b7
JB
12836(defvar vhdl-directory-alist nil
12837 "Cache with source directories for each project.")
12838;; structure: (parenthesised expression means list of such entries)
12839;; (cache-key (directory))
5eabfe72 12840
3dcb36b7 12841(defvar vhdl-speedbar-shown-unit-alist nil
5eabfe72
KH
12842 "Alist of design units simultaneously open in the current speedbar for each
12843directory and project.")
12844
3dcb36b7
JB
12845(defvar vhdl-speedbar-shown-project-list nil
12846 "List of projects simultaneously open in the current speedbar.")
5eabfe72 12847
3dcb36b7
JB
12848(defvar vhdl-updated-project-list nil
12849 "List of projects and directories with updated files.")
12850
12851(defvar vhdl-modified-file-list nil
12852 "List of modified files to be rescanned for hierarchy updating.")
12853
12854(defvar vhdl-speedbar-hierarchy-depth 0
12855 "Depth of instantiation hierarchy to display.")
12856
12857(defvar vhdl-speedbar-show-projects nil
12858 "Non-nil means project hierarchy is displayed in speedbar, directory
12859hierarchy otherwise.")
12860
12861(defun vhdl-get-end-of-unit ()
12862 "Return position of end of current unit."
12863 (let ((pos (point)))
12864 (save-excursion
12865 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
12866 (save-excursion
12867 (goto-char (match-beginning 0))
12868 (vhdl-backward-syntactic-ws)
12869 (and (/= (preceding-char) ?\;) (not (bobp))))))
12870 (re-search-backward "^[ \t]*end\\>" pos 1)
12871 (point))))
12872
12873(defun vhdl-match-string-downcase (num &optional string)
12874 "Like `match-string-no-properties' with down-casing."
12875 (let ((match (match-string-no-properties num string)))
12876 (and match (downcase match))))
5eabfe72 12877
5eabfe72
KH
12878
12879;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12880;; Scan functions
12881
3dcb36b7
JB
12882(defun vhdl-scan-context-clause ()
12883 "Scan the context clause that preceeds a design unit."
12884 (let (lib-alist)
12885 (save-excursion
12886 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
12887 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
12888 (equal "USE" (upcase (match-string 1))))
12889 (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
12890 (setq lib-alist (cons (cons (match-string-no-properties 1)
12891 (vhdl-match-string-downcase 2))
12892 lib-alist))))))
12893 lib-alist))
12894
12895(defun vhdl-scan-directory-contents (name &optional project update num-string
12896 non-final)
12897 "Scan contents of VHDL files in directory or file pattern DIR-NAME."
12898 (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
5eabfe72
KH
12899; (unless (file-directory-p (match-string 1 name))
12900; (message "No such directory: \"%s\"" (match-string 1 name)))
3dcb36b7
JB
12901 (let* ((dir-name (match-string 1 name))
12902 (file-pattern (match-string 2 name))
12903 (is-directory (= 0 (length file-pattern)))
5eabfe72 12904 (file-list
3dcb36b7
JB
12905 (if update
12906 (list name)
12907 (if is-directory
12908 (vhdl-get-source-files t dir-name)
12909 (vhdl-directory-files
12910 dir-name t (wildcard-to-regexp file-pattern)))))
12911 (key (or project dir-name))
12912 (file-exclude-regexp
12913 (or (nth 3 (aget vhdl-project-alist project)) ""))
12914 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
12915 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
12916 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
12917 ent-alist conf-alist pack-alist ent-inst-list file-alist
12918 tmp-list tmp-entry no-files files-exist big-files)
12919 (when (or project update)
12920 (setq ent-alist (aget vhdl-entity-alist key t)
12921 conf-alist (aget vhdl-config-alist key t)
12922 pack-alist (aget vhdl-package-alist key t)
12923 ent-inst-list (car (aget vhdl-ent-inst-alist key t))
12924 file-alist (aget vhdl-file-alist key t)))
5eabfe72
KH
12925 (when (and (not is-directory) (null file-list))
12926 (message "No such file: \"%s\"" name))
3dcb36b7
JB
12927 (setq files-exist file-list)
12928 (when file-list
12929 (setq no-files (length file-list))
12930 (message "Scanning %s %s\"%s\"..."
12931 (if is-directory "directory" "files") (or num-string "") name)
12932 ;; exclude files
12933 (unless (equal file-exclude-regexp "")
12934 (let ((case-fold-search nil)
12935 file-tmp-list)
12936 (while file-list
12937 (unless (string-match file-exclude-regexp (car file-list))
12938 (setq file-tmp-list (cons (car file-list) file-tmp-list)))
12939 (setq file-list (cdr file-list)))
12940 (setq file-list (nreverse file-tmp-list))))
12941 ;; do for all files
12942 (while file-list
12943 (unless noninteractive
5eabfe72
KH
12944 (message "Scanning %s %s\"%s\"... (%2d%s)"
12945 (if is-directory "directory" "files")
12946 (or num-string "") name
3dcb36b7
JB
12947 (/ (* 100 (- no-files (length file-list))) no-files) "%"))
12948 (let ((file-name (abbreviate-file-name (car file-list)))
12949 ent-list arch-list arch-ent-list conf-list
12950 pack-list pack-body-list inst-list inst-ent-list)
12951 ;; scan file
12952 (vhdl-visit-file
12953 file-name nil
12954 (vhdl-prepare-search-2
12955 (save-excursion
12956 ;; scan for design units
12957 (if (and limit-design-file-size
12958 (< limit-design-file-size (buffer-size)))
12959 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
12960 (setq big-files t))
12961 ;; scan for entities
12962 (goto-char (point-min))
12963 (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12964 (let* ((ent-name (match-string-no-properties 1))
12965 (ent-key (downcase ent-name))
12966 (ent-entry (aget ent-alist ent-key t))
12967 (arch-alist (nth 3 ent-entry))
12968 (lib-alist (vhdl-scan-context-clause)))
12969 (if (nth 1 ent-entry)
12970 (vhdl-warning-when-idle
12971 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12972 ent-name (nth 1 ent-entry) (nth 2 ent-entry)
12973 file-name (vhdl-current-line))
12974 (setq ent-list (cons ent-key ent-list))
12975 (aput 'ent-alist ent-key
12976 (list ent-name file-name (vhdl-current-line)
12977 arch-alist lib-alist)))))
12978 ;; scan for architectures
12979 (goto-char (point-min))
12980 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
12981 (let* ((arch-name (match-string-no-properties 1))
12982 (arch-key (downcase arch-name))
12983 (ent-name (match-string-no-properties 2))
12984 (ent-key (downcase ent-name))
12985 (ent-entry (aget ent-alist ent-key t))
12986 (arch-alist (nth 3 ent-entry))
12987 (arch-entry (aget arch-alist arch-key t))
12988 (lib-arch-alist (vhdl-scan-context-clause)))
12989 (if arch-entry
12990 (vhdl-warning-when-idle
12991 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
12992 arch-name ent-name (nth 1 arch-entry)
12993 (nth 2 arch-entry) file-name (vhdl-current-line))
12994 (setq arch-list (cons arch-key arch-list)
12995 arch-ent-list (cons ent-key arch-ent-list))
12996 (aput 'arch-alist arch-key
12997 (list arch-name file-name (vhdl-current-line) nil
12998 lib-arch-alist))
12999 (aput 'ent-alist ent-key
13000 (list (or (nth 0 ent-entry) ent-name)
13001 (nth 1 ent-entry) (nth 2 ent-entry)
13002 (vhdl-sort-alist arch-alist)
13003 (nth 4 ent-entry))))))
13004 ;; scan for configurations
13005 (goto-char (point-min))
13006 (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13007 (let* ((conf-name (match-string-no-properties 1))
13008 (conf-key (downcase conf-name))
13009 (conf-entry (aget conf-alist conf-key t))
13010 (ent-name (match-string-no-properties 2))
13011 (ent-key (downcase ent-name))
13012 (lib-alist (vhdl-scan-context-clause))
13013 (conf-line (vhdl-current-line))
13014 (end-of-unit (vhdl-get-end-of-unit))
13015 arch-key comp-conf-list inst-key-list
13016 inst-comp-key inst-ent-key inst-arch-key
13017 inst-conf-key inst-lib-key)
13018 (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
13019 (setq arch-key (vhdl-match-string-downcase 1)))
13020 (if conf-entry
13021 (vhdl-warning-when-idle
13022 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13023 conf-name ent-name (nth 1 conf-entry)
13024 (nth 2 conf-entry) file-name conf-line)
13025 (setq conf-list (cons conf-key conf-list))
13026 ;; scan for subconfigurations and subentities
13027 (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)
13028 (setq inst-comp-key (vhdl-match-string-downcase 3)
13029 inst-key-list (split-string
13030 (vhdl-match-string-downcase 1)
13031 "[ \t\n]*,[ \t\n]*"))
13032 (vhdl-forward-syntactic-ws)
13033 (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
13034 (setq
13035 inst-lib-key (vhdl-match-string-downcase 3)
13036 inst-ent-key (and (match-string 2)
13037 (vhdl-match-string-downcase 4))
13038 inst-arch-key (and (match-string 2)
13039 (vhdl-match-string-downcase 6))
13040 inst-conf-key (and (not (match-string 2))
13041 (vhdl-match-string-downcase 4)))
13042 (while inst-key-list
13043 (setq comp-conf-list
13044 (cons (list (car inst-key-list)
13045 inst-comp-key inst-ent-key
13046 inst-arch-key inst-conf-key
13047 inst-lib-key)
13048 comp-conf-list))
13049 (setq inst-key-list (cdr inst-key-list)))))
13050 (aput 'conf-alist conf-key
13051 (list conf-name file-name conf-line ent-key
13052 arch-key comp-conf-list lib-alist)))))
13053 ;; scan for packages
13054 (goto-char (point-min))
13055 (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
13056 (let* ((pack-name (match-string-no-properties 2))
13057 (pack-key (downcase pack-name))
13058 (is-body (match-string-no-properties 1))
13059 (pack-entry (aget pack-alist pack-key t))
13060 (pack-line (vhdl-current-line))
13061 (end-of-unit (vhdl-get-end-of-unit))
13062 comp-name func-name comp-alist func-alist lib-alist)
13063 (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13064 (vhdl-warning-when-idle
13065 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13066 (if is-body " body" "") pack-name
13067 (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
13068 (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
13069 file-name (vhdl-current-line))
13070 ;; scan for context clauses
13071 (setq lib-alist (vhdl-scan-context-clause))
13072 ;; scan for component and subprogram declarations/bodies
13073 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
13074 (if (equal (upcase (match-string 1)) "COMPONENT")
13075 (setq comp-name (match-string-no-properties 2)
13076 comp-alist
13077 (cons (list (downcase comp-name) comp-name
13078 file-name (vhdl-current-line))
13079 comp-alist))
13080 (setq func-name (match-string-no-properties 2)
13081 func-alist
13082 (cons (list (downcase func-name) func-name
13083 file-name (vhdl-current-line))
13084 func-alist))))
13085 (setq func-alist (nreverse func-alist))
13086 (setq comp-alist (nreverse comp-alist))
13087 (if is-body
13088 (setq pack-body-list (cons pack-key pack-body-list))
13089 (setq pack-list (cons pack-key pack-list)))
13090 (aput
13091 'pack-alist pack-key
13092 (if is-body
13093 (list (or (nth 0 pack-entry) pack-name)
13094 (nth 1 pack-entry) (nth 2 pack-entry)
13095 (nth 3 pack-entry) (nth 4 pack-entry)
13096 (nth 5 pack-entry)
13097 file-name pack-line func-alist lib-alist)
13098 (list pack-name file-name pack-line
13099 comp-alist func-alist lib-alist
13100 (nth 6 pack-entry) (nth 7 pack-entry)
13101 (nth 8 pack-entry) (nth 9 pack-entry))))))))
13102 ;; scan for hierarchy
13103 (if (and limit-hier-file-size
13104 (< limit-hier-file-size (buffer-size)))
13105 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
13106 (setq big-files t))
13107 ;; scan for architectures
13108 (goto-char (point-min))
13109 (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
13110 (let* ((ent-name (match-string-no-properties 2))
13111 (ent-key (downcase ent-name))
13112 (arch-name (match-string-no-properties 1))
13113 (arch-key (downcase arch-name))
13114 (ent-entry (aget ent-alist ent-key t))
13115 (arch-alist (nth 3 ent-entry))
13116 (arch-entry (aget arch-alist arch-key t))
13117 (beg-of-unit (point))
13118 (end-of-unit (vhdl-get-end-of-unit))
13119 (inst-no 0)
13120 inst-alist)
13121 ;; scan for contained instantiations
13122 (while (and (re-search-forward
13123 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
13124 "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
13125 "component[ \t\n]+\\(\\w+\\)\\|"
13126 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\)") end-of-unit t)
13127 (or (not limit-hier-inst-no)
13128 (<= (setq inst-no (1+ inst-no))
13129 limit-hier-inst-no)))
13130 (let* ((inst-name (match-string-no-properties 1))
13131 (inst-key (downcase inst-name))
13132 (inst-comp-name
13133 (or (match-string-no-properties 3)
13134 (match-string-no-properties 6)))
13135 (inst-ent-key
13136 (or (and (match-string 8)
13137 (vhdl-match-string-downcase 11))
13138 (and inst-comp-name
13139 (downcase inst-comp-name))))
13140 (inst-arch-key (vhdl-match-string-downcase 13))
13141 (inst-conf-key
13142 (and (not (match-string 8))
13143 (vhdl-match-string-downcase 11)))
13144 (inst-lib-key (vhdl-match-string-downcase 10)))
13145 (goto-char (match-end 1))
13146 (setq inst-list (cons inst-key inst-list)
13147 inst-ent-list (cons inst-ent-key inst-ent-list))
13148 (setq inst-alist
13149 (append
13150 inst-alist
13151 (list (list inst-key inst-name file-name
13152 (vhdl-current-line) inst-comp-name
13153 inst-ent-key inst-arch-key
13154 inst-conf-key inst-lib-key))))))
13155 ;; scan for contained configuration specifications
13156 (goto-char beg-of-unit)
13157 (while (re-search-forward
13158 (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
13159 "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
13160 (let* ((inst-comp-name (match-string-no-properties 3))
13161 (inst-ent-key
13162 (and (match-string 6)
13163 (vhdl-match-string-downcase 9)))
13164 (inst-arch-key (vhdl-match-string-downcase 11))
13165 (inst-conf-key
13166 (and (not (match-string 6))
13167 (vhdl-match-string-downcase 9)))
13168 (inst-lib-key (vhdl-match-string-downcase 8))
13169 (inst-key-list
13170 (split-string (vhdl-match-string-downcase 1)
13171 "[ \t\n]*,[ \t\n]*"))
13172 (tmp-inst-alist inst-alist)
13173 inst-entry)
13174 (while tmp-inst-alist
13175 (when (and (or (equal "all" (car inst-key-list))
13176 (member (nth 0 (car tmp-inst-alist))
13177 inst-key-list))
13178 (equal
13179 (downcase
13180 (or (nth 4 (car tmp-inst-alist)) ""))
13181 (downcase inst-comp-name)))
13182 (setq inst-entry (car tmp-inst-alist))
13183 (setq inst-ent-list
13184 (cons (or inst-ent-key (nth 5 inst-entry))
13185 (vhdl-delete
13186 (nth 5 inst-entry) inst-ent-list)))
13187 (setq inst-entry
13188 (list (nth 0 inst-entry) (nth 1 inst-entry)
13189 (nth 2 inst-entry) (nth 3 inst-entry)
13190 (nth 4 inst-entry)
13191 (or inst-ent-key (nth 5 inst-entry))
13192 (or inst-arch-key (nth 6 inst-entry))
13193 inst-conf-key inst-lib-key))
13194 (setcar tmp-inst-alist inst-entry))
13195 (setq tmp-inst-alist (cdr tmp-inst-alist)))))
13196 ;; save in cache
13197 (aput 'arch-alist arch-key
13198 (list (nth 0 arch-entry) (nth 1 arch-entry)
13199 (nth 2 arch-entry) inst-alist
13200 (nth 4 arch-entry)))
13201 (aput 'ent-alist ent-key
13202 (list (nth 0 ent-entry) (nth 1 ent-entry)
13203 (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
13204 (nth 4 ent-entry)))
13205 (when (and limit-hier-inst-no
13206 (> inst-no limit-hier-inst-no))
13207 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
13208 (setq big-files t))
13209 (goto-char end-of-unit))))
13210 ;; remember design units for this file
13211 (aput 'file-alist file-name
13212 (list ent-list arch-list arch-ent-list conf-list
13213 pack-list pack-body-list inst-list inst-ent-list))
13214 (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
13215 (setq file-list (cdr file-list))))
13216 (when (or (and (not project) files-exist)
13217 (and project (not non-final)))
13218 ;; consistency checks:
13219 ;; check whether each architecture has a corresponding entity
13220 (setq tmp-list ent-alist)
13221 (while tmp-list
13222 (when (null (nth 2 (car tmp-list)))
13223 (setq tmp-entry (car (nth 4 (car tmp-list))))
13224 (vhdl-warning-when-idle
13225 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13226 (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
13227 (nth 3 tmp-entry)))
13228 (setq tmp-list (cdr tmp-list)))
13229 ;; check whether configuration has a corresponding entity/architecture
13230 (setq tmp-list conf-alist)
13231 (while tmp-list
13232 (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
13233 (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
13234 (setq tmp-entry (car tmp-list))
13235 (vhdl-warning-when-idle
13236 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
13237 (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
13238 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13239 (setq tmp-entry (car tmp-list))
13240 (vhdl-warning-when-idle
13241 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
13242 (nth 1 tmp-entry) (nth 4 tmp-entry)
13243 (nth 2 tmp-entry) (nth 3 tmp-entry)))
13244 (setq tmp-list (cdr tmp-list)))
13245 ;; check whether each package body has a package declaration
13246 (setq tmp-list pack-alist)
13247 (while tmp-list
13248 (when (null (nth 2 (car tmp-list)))
13249 (setq tmp-entry (car tmp-list))
13250 (vhdl-warning-when-idle
13251 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
13252 (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
13253 (setq tmp-list (cdr tmp-list)))
13254 ;; sort lists
13255 (setq ent-alist (vhdl-sort-alist ent-alist))
13256 (setq conf-alist (vhdl-sort-alist conf-alist))
13257 (setq pack-alist (vhdl-sort-alist pack-alist))
13258 ;; remember updated directory/project
13259 (add-to-list 'vhdl-updated-project-list (or project dir-name)))
13260 ;; clear directory alists
13261 (unless project
13262 (adelete 'vhdl-entity-alist key)
13263 (adelete 'vhdl-config-alist key)
13264 (adelete 'vhdl-package-alist key)
13265 (adelete 'vhdl-ent-inst-alist key)
13266 (adelete 'vhdl-file-alist key))
13267 ;; put directory contents into cache
13268 (aput 'vhdl-entity-alist key ent-alist)
13269 (aput 'vhdl-config-alist key conf-alist)
13270 (aput 'vhdl-package-alist key pack-alist)
13271 (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
13272 (aput 'vhdl-file-alist key file-alist)
13273 ;; final messages
13274 (message "Scanning %s %s\"%s\"...done"
13275 (if is-directory "directory" "files") (or num-string "") name)
13276 (unless project (message "Scanning directory...done"))
13277 (when big-files
13278 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
13279 ;; save cache when scanned non-interactively
13280 (when (or (not project) (not non-final))
13281 (when (and noninteractive vhdl-speedbar-save-cache)
13282 (vhdl-save-cache key)))
13283 t))
5eabfe72 13284
3dcb36b7 13285(defun vhdl-scan-project-contents (project)
5eabfe72
KH
13286 "Scan the contents of all VHDL files found in the directories and files
13287of PROJECT."
3dcb36b7
JB
13288 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
13289 (default-dir (vhdl-resolve-env-variable
13290 (nth 1 (aget vhdl-project-alist project))))
13291 (file-exclude-regexp
13292 (or (nth 3 (aget vhdl-project-alist project)) ""))
13293 dir-list-tmp dir dir-name num-dir act-dir recursive)
13294 ;; clear project alists
13295 (adelete 'vhdl-entity-alist project)
13296 (adelete 'vhdl-config-alist project)
13297 (adelete 'vhdl-package-alist project)
13298 (adelete 'vhdl-ent-inst-alist project)
13299 (adelete 'vhdl-file-alist project)
13300 ;; expand directory names by default-directory
13301 (message "Collecting source files...")
13302 (while dir-list
13303 (setq dir (vhdl-resolve-env-variable (car dir-list)))
13304 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
13305 (setq recursive (match-string 1 dir)
13306 dir-name (match-string 3 dir))
13307 (setq dir-list-tmp
13308 (cons (concat recursive
13309 (if (file-name-absolute-p dir-name) "" default-dir)
13310 dir-name)
13311 dir-list-tmp))
13312 (setq dir-list (cdr dir-list)))
13313 ;; resolve path wildcards
5eabfe72
KH
13314 (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
13315 ;; expand directories
13316 (while dir-list-tmp
13317 (setq dir (car dir-list-tmp))
13318 ;; get subdirectories
3dcb36b7 13319 (if (string-match "-r \\(.*[/\\]\\)" dir)
5eabfe72
KH
13320 (setq dir-list (append dir-list (vhdl-get-subdirs
13321 (match-string 1 dir))))
13322 (setq dir-list (append dir-list (list dir))))
13323 (setq dir-list-tmp (cdr dir-list-tmp)))
3dcb36b7
JB
13324 ;; exclude files
13325 (unless (equal file-exclude-regexp "")
13326 (let ((case-fold-search nil))
13327 (while dir-list
13328 (unless (string-match file-exclude-regexp (car dir-list))
13329 (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
13330 (setq dir-list (cdr dir-list)))
13331 (setq dir-list (nreverse dir-list-tmp))))
13332 (message "Collecting source files...done")
13333 ;; scan for design units for each directory in DIR-LIST
13334 (setq dir-list-tmp nil
13335 num-dir (length dir-list)
5eabfe72
KH
13336 act-dir 1)
13337 (while dir-list
3dcb36b7
JB
13338 (setq dir-name (abbreviate-file-name
13339 (expand-file-name (car dir-list))))
13340 (vhdl-scan-directory-contents dir-name project nil
13341 (format "(%s/%s) " act-dir num-dir)
13342 (cdr dir-list))
13343 (add-to-list 'dir-list-tmp (file-name-directory dir-name))
5eabfe72
KH
13344 (setq dir-list (cdr dir-list)
13345 act-dir (1+ act-dir)))
3dcb36b7
JB
13346 (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
13347 (message "Scanning project \"%s\"...done" project)))
13348
13349(defun vhdl-update-file-contents (file-name)
13350 "Update hierarchy information by contents of current buffer."
13351 (setq file-name (abbreviate-file-name file-name))
13352 (let* ((dir-name (file-name-directory file-name))
13353 (directory-alist vhdl-directory-alist)
13354 updated)
13355 (while directory-alist
13356 (when (member dir-name (nth 1 (car directory-alist)))
13357 (let* ((vhdl-project (nth 0 (car directory-alist)))
13358 (project (vhdl-project-p))
13359 (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
13360 (conf-alist (aget vhdl-config-alist (or project dir-name) t))
13361 (pack-alist (aget vhdl-package-alist (or project dir-name) t))
13362 (ent-inst-list (car (aget vhdl-ent-inst-alist
13363 (or project dir-name) t)))
13364 (file-alist (aget vhdl-file-alist (or project dir-name) t))
13365 (file-entry (aget file-alist file-name t))
13366 (ent-list (nth 0 file-entry))
13367 (arch-list (nth 1 file-entry))
13368 (arch-ent-list (nth 2 file-entry))
13369 (conf-list (nth 3 file-entry))
13370 (pack-list (nth 4 file-entry))
13371 (pack-body-list (nth 5 file-entry))
13372 (inst-ent-list (nth 7 file-entry))
13373 (cache-key (or project dir-name))
13374 arch-alist key ent-key entry)
13375 ;; delete design units previously contained in this file:
13376 ;; entities
13377 (while ent-list
13378 (setq key (car ent-list)
13379 entry (aget ent-alist key t))
13380 (when (equal file-name (nth 1 entry))
13381 (if (nth 3 entry)
13382 (aput 'ent-alist key
13383 (list (nth 0 entry) nil nil (nth 3 entry) nil))
13384 (adelete 'ent-alist key)))
13385 (setq ent-list (cdr ent-list)))
13386 ;; architectures
13387 (while arch-list
13388 (setq key (car arch-list)
13389 ent-key (car arch-ent-list)
13390 entry (aget ent-alist ent-key t)
13391 arch-alist (nth 3 entry))
13392 (when (equal file-name (nth 1 (aget arch-alist key t)))
13393 (adelete 'arch-alist key)
13394 (if (or (nth 1 entry) arch-alist)
13395 (aput 'ent-alist ent-key
13396 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13397 arch-alist (nth 4 entry)))
13398 (adelete 'ent-alist ent-key)))
13399 (setq arch-list (cdr arch-list)
13400 arch-ent-list (cdr arch-ent-list)))
13401 ;; configurations
13402 (while conf-list
13403 (setq key (car conf-list))
13404 (when (equal file-name (nth 1 (aget conf-alist key t)))
13405 (adelete 'conf-alist key))
13406 (setq conf-list (cdr conf-list)))
13407 ;; package declarations
13408 (while pack-list
13409 (setq key (car pack-list)
13410 entry (aget pack-alist key t))
13411 (when (equal file-name (nth 1 entry))
13412 (if (nth 6 entry)
13413 (aput 'pack-alist key
13414 (list (nth 0 entry) nil nil nil nil nil
13415 (nth 6 entry) (nth 7 entry) (nth 8 entry)
13416 (nth 9 entry)))
13417 (adelete 'pack-alist key)))
13418 (setq pack-list (cdr pack-list)))
13419 ;; package bodies
13420 (while pack-body-list
13421 (setq key (car pack-body-list)
13422 entry (aget pack-alist key t))
13423 (when (equal file-name (nth 6 entry))
13424 (if (nth 1 entry)
13425 (aput 'pack-alist key
13426 (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
13427 (nth 3 entry) (nth 4 entry) (nth 5 entry)
13428 nil nil nil nil))
13429 (adelete 'pack-alist key)))
13430 (setq pack-body-list (cdr pack-body-list)))
13431 ;; instantiated entities
13432 (while inst-ent-list
13433 (setq ent-inst-list
13434 (vhdl-delete (car inst-ent-list) ent-inst-list))
13435 (setq inst-ent-list (cdr inst-ent-list)))
13436 ;; update caches
13437 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
13438 (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
13439 (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
13440 (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
13441 ;; scan file
13442 (vhdl-scan-directory-contents file-name project t)
13443 (when (or (and vhdl-speedbar-show-projects project)
13444 (and (not vhdl-speedbar-show-projects) (not project)))
13445 (vhdl-speedbar-refresh project))
13446 (setq updated t)))
13447 (setq directory-alist (cdr directory-alist)))
13448 updated))
13449
13450(defun vhdl-update-hierarchy ()
13451 "Update directory and hierarchy information in speedbar."
13452 (let ((file-list (reverse vhdl-modified-file-list))
13453 updated)
13454 (when (and vhdl-speedbar-update-on-saving file-list)
13455 (while file-list
13456 (setq updated
13457 (or (vhdl-update-file-contents (car file-list))
13458 updated))
13459 (setq file-list (cdr file-list)))
13460 (setq vhdl-modified-file-list nil)
13461 (when updated (message "Updating hierarchy...done")))))
13462
13463;; structure (parenthesised expression means list of such entries)
13464;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
13465;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
13466;; comp-lib-name level)
13467(defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
13468 conf-inst-alist level indent
13469 &optional include-top ent-hier)
13470 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
13471entity ENT-KEY."
13472 (let* ((ent-entry (aget ent-alist ent-key t))
13473 (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
13474 (cdar (last (nth 3 ent-entry)))))
13475 (inst-alist (nth 3 arch-entry))
13476 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
13477 hier-list subcomp-list tmp-list inst-key inst-comp-name
13478 inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
5eabfe72 13479 (when (= level 0) (message "Extract design hierarchy..."))
3dcb36b7
JB
13480 (when include-top
13481 (setq level (1+ level)))
13482 (when (member ent-key ent-hier)
13483 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
13484 ;; check configured architecture (already checked during scanning)
13485; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
13486; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
13487 ;; process all instances
13488 (while inst-alist
13489 (setq inst-entry (car inst-alist)
13490 inst-key (nth 0 inst-entry)
13491 inst-comp-name (nth 4 inst-entry)
13492 inst-conf-key (nth 7 inst-entry))
13493 ;; search entry in configuration's instantiations list
13494 (setq tmp-list conf-inst-alist)
13495 (while (and tmp-list
13496 (not (and (member (nth 0 (car tmp-list))
13497 (list "all" inst-key))
13498 (equal (nth 1 (car tmp-list))
13499 (downcase (or inst-comp-name ""))))))
13500 (setq tmp-list (cdr tmp-list)))
13501 (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
13502 (setq inst-conf-entry (aget conf-alist inst-conf-key t))
13503 (when (and inst-conf-key (not inst-conf-entry))
13504 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
13505 ;; determine entity
13506 (setq inst-ent-key
13507 (or (nth 2 (car tmp-list)) ; from configuration
13508 (nth 3 inst-conf-entry) ; from subconfiguration
13509 (nth 3 (aget conf-alist (nth 7 inst-entry) t))
13510 ; from configuration spec.
13511 (nth 5 inst-entry))) ; from direct instantiation
13512 (setq inst-ent-entry (aget ent-alist inst-ent-key t))
13513 ;; determine architecture
13514 (setq inst-arch-key
13515 (or (nth 3 (car tmp-list)) ; from configuration
13516 (nth 4 inst-conf-entry) ; from subconfiguration
13517 (nth 6 inst-entry) ; from direct instantiation
13518 (nth 4 (aget conf-alist (nth 7 inst-entry)))
13519 ; from configuration spec.
13520 (caar (nth 3 inst-ent-entry)))) ; random (simplified MRA)
13521 (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
13522 ;; set library
13523 (setq inst-lib-key
13524 (or (nth 5 (car tmp-list)) ; from configuration
13525 (nth 8 inst-entry))) ; from direct instantiation
13526 ;; gather information for this instance
13527 (setq comp-entry
13528 (list (nth 1 inst-entry)
13529 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13530 (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
13531 (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
13532 (or (nth 0 inst-arch-entry) inst-arch-key)
13533 (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
13534 (or (nth 0 inst-conf-entry) inst-conf-key)
13535 (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
13536 inst-lib-key level))
13537 ;; get subcomponent hierarchy
13538 (setq subcomp-list (vhdl-get-hierarchy
13539 ent-alist conf-alist
13540 inst-ent-key inst-arch-key inst-conf-key
13541 (nth 5 inst-conf-entry)
13542 (1+ level) indent nil (cons ent-key ent-hier)))
13543 ;; add to list
13544 (setq hier-list (append hier-list (list comp-entry) subcomp-list))
13545 (setq inst-alist (cdr inst-alist)))
13546 (when include-top
5eabfe72 13547 (setq hier-list
3dcb36b7
JB
13548 (cons (list nil nil (nth 0 ent-entry)
13549 (cons (nth 1 ent-entry) (nth 2 ent-entry))
13550 (nth 0 arch-entry)
13551 (cons (nth 1 arch-entry) (nth 2 arch-entry))
13552 nil nil
13553 nil (1- level))
13554 hier-list)))
13555 (when (or (= level 0) (and include-top (= level 1))) (message ""))
5eabfe72
KH
13556 hier-list))
13557
3dcb36b7
JB
13558(defun vhdl-get-instantiations (ent-key indent)
13559 "Get all instantiations of entity ENT-KEY."
13560 (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
5eabfe72
KH
13561 arch-alist inst-alist ent-inst-list
13562 ent-entry arch-entry inst-entry)
13563 (while ent-alist
13564 (setq ent-entry (car ent-alist))
3dcb36b7 13565 (setq arch-alist (nth 4 ent-entry))
5eabfe72
KH
13566 (while arch-alist
13567 (setq arch-entry (car arch-alist))
3dcb36b7 13568 (setq inst-alist (nth 4 arch-entry))
5eabfe72
KH
13569 (while inst-alist
13570 (setq inst-entry (car inst-alist))
3dcb36b7 13571 (when (equal ent-key (nth 5 inst-entry))
5eabfe72 13572 (setq ent-inst-list
3dcb36b7
JB
13573 (cons (list (nth 1 inst-entry)
13574 (cons (nth 2 inst-entry) (nth 3 inst-entry))
13575 (nth 1 ent-entry)
13576 (cons (nth 2 ent-entry) (nth 3 ent-entry))
13577 (nth 1 arch-entry)
13578 (cons (nth 2 arch-entry) (nth 3 arch-entry)))
13579 ent-inst-list)))
5eabfe72
KH
13580 (setq inst-alist (cdr inst-alist)))
13581 (setq arch-alist (cdr arch-alist)))
13582 (setq ent-alist (cdr ent-alist)))
13583 (nreverse ent-inst-list)))
13584
13585;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3dcb36b7
JB
13586;; Caching in file
13587
13588(defun vhdl-save-caches ()
13589 "Save all updated hierarchy caches to file."
13590 (interactive)
13591 (condition-case nil
13592 (when vhdl-speedbar-save-cache
13593 ;; update hierarchy
13594 (vhdl-update-hierarchy)
13595 (let ((project-list vhdl-updated-project-list))
13596 (message "Saving hierarchy caches...")
13597 ;; write updated project caches
13598 (while project-list
13599 (vhdl-save-cache (car project-list))
13600 (setq project-list (cdr project-list)))
13601 (message "Saving hierarchy caches...done")))
13602 (error (progn (vhdl-warning "ERROR: An error occured while saving the hierarchy caches")
13603 (sit-for 2)))))
13604
13605(defun vhdl-save-cache (key)
13606 "Save current hierarchy cache to file."
13607 (let* ((orig-buffer (current-buffer))
13608 (vhdl-project key)
13609 (project (vhdl-project-p))
13610 (default-directory key)
13611 (directory (abbreviate-file-name (vhdl-default-directory)))
13612 (file-name (vhdl-resolve-env-variable
13613 (vhdl-replace-string
13614 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13615 (concat
13616 (subst-char-in-string ? ?_ (or project "dir"))
13617 " " (user-login-name)))))
13618 (file-dir-name (expand-file-name file-name directory))
13619 (cache-key (or project directory))
13620 (key (if project "project" "directory")))
13621 (unless (file-exists-p (file-name-directory file-dir-name))
13622 (make-directory (file-name-directory file-dir-name) t))
13623 (if (not (file-writable-p file-dir-name))
13624 (progn (vhdl-warning (format "File not writable: \"%s\""
13625 (abbreviate-file-name file-dir-name)))
13626 (sit-for 2))
13627 (message "Saving cache: \"%s\"" file-dir-name)
13628 (set-buffer (find-file-noselect file-dir-name t t))
13629 (erase-buffer)
13630 (insert ";; -*- Emacs-Lisp -*-\n\n"
13631 ";;; " (file-name-nondirectory file-name)
13632 " - design hierarchy cache file for Emacs VHDL Mode "
13633 vhdl-version "\n")
13634 (insert "\n;; " (if project "Project " "Directory") " : ")
13635 (if project (insert project) (prin1 directory (current-buffer)))
13636 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
13637 (user-login-name) "\n\n"
13638 "\n;; version number\n"
13639 "(setq vhdl-cache-version \"" vhdl-version "\")\n"
13640 "\n;; " (if project "project" "directory") " name"
13641 "\n(setq " key " ")
13642 (prin1 (or project directory) (current-buffer))
13643 (insert ")\n")
13644 (when (member 'hierarchy vhdl-speedbar-save-cache)
13645 (insert "\n;; entity and architecture cache\n"
13646 "(aput 'vhdl-entity-alist " key " '")
13647 (print (aget vhdl-entity-alist cache-key t) (current-buffer))
13648 (insert ")\n\n;; configuration cache\n"
13649 "(aput 'vhdl-config-alist " key " '")
13650 (print (aget vhdl-config-alist cache-key t) (current-buffer))
13651 (insert ")\n\n;; package cache\n"
13652 "(aput 'vhdl-package-alist " key " '")
13653 (print (aget vhdl-package-alist cache-key t) (current-buffer))
13654 (insert ")\n\n;; instantiated entities cache\n"
13655 "(aput 'vhdl-ent-inst-alist " key " '")
13656 (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
13657 (insert ")\n\n;; design units per file cache\n"
13658 "(aput 'vhdl-file-alist " key " '")
13659 (print (aget vhdl-file-alist cache-key t) (current-buffer))
13660 (when project
13661 (insert ")\n\n;; source directories in project cache\n"
13662 "(aput 'vhdl-directory-alist " key " '")
13663 (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
13664 (insert ")\n"))
13665 (when (member 'display vhdl-speedbar-save-cache)
13666 (insert "\n;; shown design units cache\n"
13667 "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
13668 (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
13669 (current-buffer))
13670 (insert ")\n"))
13671 (setq vhdl-updated-project-list
13672 (delete cache-key vhdl-updated-project-list))
13673 (save-buffer)
13674 (kill-buffer (current-buffer))
13675 (set-buffer orig-buffer))))
13676
13677(defun vhdl-load-cache (key)
13678 "Load hierarchy cache information from file."
13679 (let* ((vhdl-project key)
13680 (default-directory key)
13681 (directory (vhdl-default-directory))
13682 (file-name (vhdl-resolve-env-variable
13683 (vhdl-replace-string
13684 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
13685 (concat
13686 (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
13687 " " (user-login-name)))))
13688 (file-dir-name (expand-file-name file-name directory))
13689 vhdl-cache-version)
13690 (unless (memq 'vhdl-save-caches kill-emacs-hook)
13691 (add-hook 'kill-emacs-hook 'vhdl-save-caches))
13692 (when (file-exists-p file-dir-name)
13693 (condition-case ()
13694 (progn (load-file file-dir-name)
13695 (string< (mapconcat
13696 (lambda (a) (format "%3d" (string-to-int a)))
13697 (split-string "3.31.14" "\\.") "")
13698 (mapconcat
13699 (lambda (a) (format "%3d" (string-to-int a)))
13700 (split-string vhdl-cache-version "\\.") "")))
13701 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
13702 nil))))))
13703
13704(defun vhdl-require-hierarchy-info ()
13705 "Make sure that hierarchy information is available. Load cache or scan files
13706if required."
13707 (if (vhdl-project-p)
13708 (unless (or (assoc vhdl-project vhdl-file-alist)
13709 (vhdl-load-cache vhdl-project))
13710 (vhdl-scan-project-contents vhdl-project))
13711 (let ((directory (abbreviate-file-name default-directory)))
13712 (unless (or (assoc directory vhdl-file-alist)
13713 (vhdl-load-cache directory))
13714 (vhdl-scan-directory-contents directory)))))
13715
13716;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13717;; Add hierarchy browser functionality to speedbar
5eabfe72
KH
13718
13719(defvar vhdl-speedbar-key-map nil
13720 "Keymap used when in the VHDL hierarchy browser mode.")
13721
3dcb36b7 13722(defvar vhdl-speedbar-menu-items nil
5eabfe72
KH
13723 "Additional menu-items to add to speedbar frame.")
13724
13725(defun vhdl-speedbar-initialize ()
13726 "Initialize speedbar."
13727 ;; general settings
13728; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
13729 ;; VHDL file extensions (extracted from `auto-mode-alist')
13730 (let ((mode-alist auto-mode-alist))
13731 (while mode-alist
3dcb36b7
JB
13732 (when (eq (cdar mode-alist) 'vhdl-mode)
13733 (speedbar-add-supported-extension (caar mode-alist)))
5eabfe72
KH
13734 (setq mode-alist (cdr mode-alist))))
13735 ;; hierarchy browser settings
13736 (when (boundp 'speedbar-mode-functions-list)
3dcb36b7 13737 ;; special functions
5eabfe72 13738 (speedbar-add-mode-functions-list
3dcb36b7 13739 '("vhdl directory"
5eabfe72
KH
13740 (speedbar-item-info . vhdl-speedbar-item-info)
13741 (speedbar-line-path . speedbar-files-line-path)))
3dcb36b7
JB
13742 (speedbar-add-mode-functions-list
13743 '("vhdl project"
13744 (speedbar-item-info . vhdl-speedbar-item-info)
13745 (speedbar-line-path . vhdl-speedbar-line-project)))
13746 ;; keymap
5eabfe72
KH
13747 (unless vhdl-speedbar-key-map
13748 (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
13749 (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
13750 (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
13751 (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
3dcb36b7
JB
13752 (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
13753 (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
13754 (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
13755 (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
13756 (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
13757 (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
13758 (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
13759 (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
13760 (let ((key 0))
13761 (while (<= key 9)
13762 (define-key vhdl-speedbar-key-map (int-to-string key)
13763 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
13764 (setq key (1+ key)))))
5eabfe72
KH
13765 (define-key speedbar-key-map "h"
13766 (lambda () (interactive)
3dcb36b7
JB
13767 (speedbar-change-initial-expansion-list "vhdl directory")))
13768 (define-key speedbar-key-map "H"
13769 (lambda () (interactive)
13770 (speedbar-change-initial-expansion-list "vhdl project")))
13771 ;; menu
13772 (unless vhdl-speedbar-menu-items
13773 (setq
13774 vhdl-speedbar-menu-items
13775 `(["Edit" speedbar-edit-line t]
13776 ["Expand" speedbar-expand-line
13777 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
13778 ["Contract" vhdl-speedbar-contract-level t]
13779 ["Expand All" vhdl-speedbar-expand-all t]
13780 ["Contract All" vhdl-speedbar-contract-all t]
13781 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
13782 (while (<= key 9)
13783 (setq menu-list
13784 (cons `[,(if (= key 0) "All" (int-to-string key))
13785 (vhdl-speedbar-set-depth ,key)
13786 :style radio
13787 :selected (= vhdl-speedbar-hierarchy-depth ,key)
13788 :keys ,(int-to-string key)]
13789 menu-list))
13790 (setq key (1+ key)))
13791 (nreverse menu-list))
13792 "--"
13793 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
13794 (or (vhdl-speedbar-check-unit 'entity)
13795 (vhdl-speedbar-check-unit 'subprogram))]
13796 ["Place Component" vhdl-speedbar-place-component
13797 (vhdl-speedbar-check-unit 'entity)]
13798 ["Make" vhdl-speedbar-make-design
13799 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
13800 ["Generate Makefile" vhdl-speedbar-generate-makefile
13801 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
13802 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
13803 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13804 ,(if vhdl-xemacs :active :visible) (not vhdl-speedbar-show-projects)]
13805 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
13806 :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
13807 ,(if vhdl-xemacs :active :visible) vhdl-speedbar-show-projects]
13808 ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
13809 ;; hook-ups
13810 (speedbar-add-expansion-list
13811 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13812 vhdl-speedbar-display-directory))
13813 (speedbar-add-expansion-list
13814 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
13815 vhdl-speedbar-display-projects))
5eabfe72 13816 (setq speedbar-stealthy-function-list
3dcb36b7
JB
13817 (append
13818 '(("vhdl directory" vhdl-speedbar-update-current-unit)
13819 ("vhdl project" vhdl-speedbar-update-current-project
13820 vhdl-speedbar-update-current-unit)
13821; ("files" (lambda () (setq speedbar-ignored-path-regexp
13822; (speedbar-extension-list-to-regex
13823; speedbar-ignored-path-expressions))))
13824 )
13825 speedbar-stealthy-function-list))
13826 (when (eq vhdl-speedbar-display-mode 'directory)
13827 (setq speedbar-initial-expansion-list-name "vhdl directory"))
13828 (when (eq vhdl-speedbar-display-mode 'project)
13829 (setq speedbar-initial-expansion-list-name "vhdl project"))
13830 (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
5eabfe72
KH
13831
13832(defun vhdl-speedbar (&optional arg)
13833 "Open/close speedbar."
d2ddb974 13834 (interactive)
5eabfe72 13835 (if (not (fboundp 'speedbar))
3dcb36b7
JB
13836 (error "WARNING: Speedbar is not available or not installed")
13837 (condition-case ()
5eabfe72 13838 (speedbar-frame-mode arg)
3dcb36b7 13839 (error (error "WARNING: An error occurred while opening speedbar")))))
5eabfe72
KH
13840
13841;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13842;; Display functions
13843
3dcb36b7
JB
13844(defvar vhdl-speedbar-last-selected-project nil
13845 "Name of last selected project.")
13846
5eabfe72
KH
13847;; macros must be defined in the file they are used (copied from `speedbar.el')
13848(defmacro speedbar-with-writable (&rest forms)
13849 "Allow the buffer to be writable and evaluate FORMS."
13850 (list 'let '((inhibit-read-only t))
13851 (cons 'progn forms)))
13852(put 'speedbar-with-writable 'lisp-indent-function 0)
13853
3dcb36b7 13854(defun vhdl-speedbar-display-directory (directory depth &optional rescan)
5eabfe72 13855 "Display directory and hierarchy information in speedbar."
3dcb36b7
JB
13856 (setq vhdl-speedbar-show-projects nil)
13857 (setq speedbar-ignored-path-regexp
13858 (speedbar-extension-list-to-regex speedbar-ignored-path-expressions))
5eabfe72
KH
13859 (setq directory (abbreviate-file-name (file-name-as-directory directory)))
13860 (setq speedbar-last-selected-file nil)
13861 (speedbar-with-writable
3dcb36b7
JB
13862 (condition-case nil
13863 (progn
13864 ;; insert directory path
13865 (speedbar-directory-buttons directory depth)
13866 ;; insert subdirectories
13867 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
13868 ;; scan and insert hierarchy of current directory
13869 (vhdl-speedbar-insert-dir-hierarchy directory depth
13870 speedbar-power-click)
13871 ;; expand subdirectories
13872 (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
13873 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
13874
13875(defun vhdl-speedbar-display-projects (project depth &optional rescan)
13876 "Display projects and hierarchy information in speedbar."
13877 (setq vhdl-speedbar-show-projects t)
13878 (setq speedbar-ignored-path-regexp ".")
13879 (setq speedbar-last-selected-file nil)
13880 (setq vhdl-speedbar-last-selected-project nil)
13881 (speedbar-with-writable
13882 (condition-case nil
13883 ;; insert projects
13884 (vhdl-speedbar-insert-projects)
13885 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
13886 (setq speedbar-full-text-cache nil)) ; prevent caching
13887
13888(defun vhdl-speedbar-insert-projects ()
13889 "Insert all projects in speedbar."
13890 (vhdl-speedbar-make-title-line "Projects:")
13891 (let ((project-alist (if vhdl-project-sort
13892 (vhdl-sort-alist (copy-alist vhdl-project-alist))
13893 vhdl-project-alist))
13894 (vhdl-speedbar-update-current-unit nil))
13895 ;; insert projects
13896 (while project-alist
13897 (speedbar-make-tag-line
13898 'angle ?+ 'vhdl-speedbar-expand-project
13899 (caar project-alist) (caar project-alist)
13900 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
13901 (setq project-alist (cdr project-alist)))
13902 (setq project-alist vhdl-project-alist)
13903 ;; expand projects
13904 (while project-alist
13905 (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
13906 (goto-char (point-min))
13907 (when (re-search-forward
13908 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
13909 (goto-char (match-end 1))
13910 (speedbar-do-function-pointer)))
13911 (setq project-alist (cdr project-alist))))
13912; (vhdl-speedbar-update-current-project)
13913; (vhdl-speedbar-update-current-unit nil t)
13914 )
13915
13916(defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
13917 "Insert hierarchy of project. Rescan directories if RESCAN is non-nil,
13918otherwise use cached data."
13919 (when (or rescan (and (not (assoc project vhdl-file-alist))
13920 (not (vhdl-load-cache project))))
13921 (vhdl-scan-project-contents project))
13922 ;; insert design hierarchy
13923 (vhdl-speedbar-insert-hierarchy
13924 (aget vhdl-entity-alist project t)
13925 (aget vhdl-config-alist project t)
13926 (aget vhdl-package-alist project t)
13927 (car (aget vhdl-ent-inst-alist project t)) indent)
13928 (insert (int-to-string indent) ":\n")
13929 (put-text-property (- (point) 3) (1- (point)) 'invisible t)
13930 (put-text-property (1- (point)) (point) 'invisible nil)
13931 ;; expand design units
13932 (vhdl-speedbar-expand-units project))
13933
13934(defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
13935 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
13936otherwise use cached data."
13937 (when (or rescan (and (not (assoc directory vhdl-file-alist))
13938 (not (vhdl-load-cache directory))))
13939 (vhdl-scan-directory-contents directory))
13940 ;; insert design hierarchy
13941 (vhdl-speedbar-insert-hierarchy
13942 (aget vhdl-entity-alist directory t)
13943 (aget vhdl-config-alist directory t)
13944 (aget vhdl-package-alist directory t)
13945 (car (aget vhdl-ent-inst-alist directory t)) depth)
13946 ;; expand design units
13947 (vhdl-speedbar-expand-units directory)
13948 (aput 'vhdl-directory-alist directory (list (list directory))))
13949
13950(defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
5eabfe72 13951 ent-inst-list depth)
3dcb36b7
JB
13952 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
13953 (if (not (or ent-alist conf-alist pack-alist))
13954 (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
13955 (let (ent-entry conf-entry pack-entry)
5eabfe72
KH
13956 ;; insert entities
13957 (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
13958 (while ent-alist
13959 (setq ent-entry (car ent-alist))
13960 (speedbar-make-tag-line
13961 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
3dcb36b7
JB
13962 (nth 1 ent-entry) 'vhdl-speedbar-find-file
13963 (cons (nth 2 ent-entry) (nth 3 ent-entry))
5eabfe72 13964 'vhdl-speedbar-entity-face depth)
3dcb36b7
JB
13965 (unless (nth 2 ent-entry)
13966 (end-of-line 0) (insert "!") (forward-char 1))
13967 (unless (member (nth 0 ent-entry) ent-inst-list)
5eabfe72
KH
13968 (end-of-line 0) (insert " (top)") (forward-char 1))
13969 (setq ent-alist (cdr ent-alist)))
3dcb36b7
JB
13970 ;; insert configurations
13971 (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
13972 (while conf-alist
13973 (setq conf-entry (car conf-alist))
13974 (speedbar-make-tag-line
13975 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
13976 (nth 1 conf-entry) 'vhdl-speedbar-find-file
13977 (cons (nth 2 conf-entry) (nth 3 conf-entry))
13978 'vhdl-speedbar-configuration-face depth)
13979 (setq conf-alist (cdr conf-alist)))
5eabfe72
KH
13980 ;; insert packages
13981 (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
13982 (while pack-alist
13983 (setq pack-entry (car pack-alist))
13984 (vhdl-speedbar-make-pack-line
3dcb36b7
JB
13985 (nth 0 pack-entry) (nth 1 pack-entry)
13986 (cons (nth 2 pack-entry) (nth 3 pack-entry))
13987 (cons (nth 7 pack-entry) (nth 8 pack-entry))
5eabfe72
KH
13988 depth)
13989 (setq pack-alist (cdr pack-alist))))))
13990
5eabfe72 13991(defun vhdl-speedbar-rescan-hierarchy ()
3dcb36b7 13992 "Rescan hierarchy for the directory or project under the cursor."
d2ddb974 13993 (interactive)
3dcb36b7
JB
13994 (let (key path)
13995 (cond
13996 ;; current project
13997 (vhdl-speedbar-show-projects
13998 (setq key (vhdl-speedbar-line-project))
13999 (vhdl-scan-project-contents key))
14000 ;; top-level directory
14001 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14002 (re-search-forward "[0-9]+:" nil t)
14003 (vhdl-scan-directory-contents
14004 (abbreviate-file-name (speedbar-line-path))))
14005 ;; current directory
14006 (t (setq path (speedbar-line-path))
14007 (string-match "^\\(.+[/\\]\\)" path)
14008 (vhdl-scan-directory-contents
14009 (abbreviate-file-name (match-string 1 path)))))
14010 (vhdl-speedbar-refresh key)))
5eabfe72
KH
14011
14012(defun vhdl-speedbar-expand-dirs (directory)
14013 "Expand subdirectories in DIRECTORY according to
14014 `speedbar-shown-directories'."
14015 ;; (nicked from `speedbar-default-directory-list')
3dcb36b7
JB
14016 (let ((sf (cdr (reverse speedbar-shown-directories)))
14017 (vhdl-speedbar-update-current-unit nil))
5eabfe72
KH
14018 (setq speedbar-shown-directories
14019 (list (expand-file-name default-directory)))
14020 (while sf
14021 (when (speedbar-goto-this-file (car sf))
14022 (beginning-of-line)
14023 (when (looking-at "[0-9]+:\\s-*<")
14024 (goto-char (match-end 0))
3dcb36b7
JB
14025 (speedbar-do-function-pointer)))
14026 (setq sf (cdr sf))))
14027 (vhdl-speedbar-update-current-unit nil t))
14028
14029(defun vhdl-speedbar-expand-units (key)
14030 "Expand design units in directory/project KEY according to
14031`vhdl-speedbar-shown-unit-alist'."
14032 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14033 (vhdl-speedbar-update-current-unit nil)
14034 vhdl-updated-project-list)
14035 (adelete 'vhdl-speedbar-shown-unit-alist key)
14036 (vhdl-prepare-search-1
14037 (while unit-alist ; expand units
14038 (vhdl-speedbar-goto-this-unit key (caar unit-alist))
14039 (beginning-of-line)
14040 (let ((arch-alist (nth 1 (car unit-alist)))
14041 position)
14042 (when (looking-at "^[0-9]+:\\s-*\\[")
14043 (goto-char (match-end 0))
14044 (setq position (point))
14045 (speedbar-do-function-pointer)
14046 (select-frame speedbar-frame)
14047 (while arch-alist ; expand architectures
14048 (goto-char position)
14049 (when (re-search-forward
14050 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14051 (car arch-alist) "\\>\\)") nil t)
14052 (beginning-of-line)
14053 (when (looking-at "^[0-9]+:\\s-*{")
14054 (goto-char (match-end 0))
14055 (speedbar-do-function-pointer)
14056 (select-frame speedbar-frame)))
14057 (setq arch-alist (cdr arch-alist))))
14058 (setq unit-alist (cdr unit-alist))))))
14059 (vhdl-speedbar-update-current-unit nil t))
14060
14061(defun vhdl-speedbar-contract-level ()
14062 "Contract current level in current directory/project."
14063 (interactive)
14064 (when (or (save-excursion
14065 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14066 (and (save-excursion
14067 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14068 (re-search-backward
14069 (format "^[0-%d]:\\s-*[[{<]-"
14070 (max (1- (string-to-int (match-string 1))) 0)) nil t)))
14071 (goto-char (match-end 0))
14072 (speedbar-do-function-pointer)
14073 (speedbar-center-buffer-smartly)))
14074
14075(defun vhdl-speedbar-contract-all ()
14076 "Contract all expanded design units in current directory/project."
14077 (interactive)
14078 (if (and vhdl-speedbar-show-projects
14079 (save-excursion (beginning-of-line) (looking-at "^0:")))
14080 (progn (setq vhdl-speedbar-shown-project-list nil)
14081 (vhdl-speedbar-refresh))
14082 (let ((key (vhdl-speedbar-line-key)))
14083 (adelete 'vhdl-speedbar-shown-unit-alist key)
14084 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
14085 (when (memq 'display vhdl-speedbar-save-cache)
14086 (add-to-list 'vhdl-updated-project-list key)))))
14087
14088(defun vhdl-speedbar-expand-all ()
14089 "Expand all design units in current directory/project."
14090 (interactive)
14091 (let* ((key (vhdl-speedbar-line-key))
14092 (ent-alist (aget vhdl-entity-alist key t))
14093 (conf-alist (aget vhdl-config-alist key t))
14094 (pack-alist (aget vhdl-package-alist key t))
14095 arch-alist unit-alist subunit-alist)
14096 (add-to-list 'vhdl-speedbar-shown-project-list key)
14097 (while ent-alist
14098 (setq arch-alist (nth 4 (car ent-alist)))
14099 (setq subunit-alist nil)
14100 (while arch-alist
14101 (setq subunit-alist (cons (caar arch-alist) subunit-alist))
14102 (setq arch-alist (cdr arch-alist)))
14103 (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
14104 (setq ent-alist (cdr ent-alist)))
14105 (while conf-alist
14106 (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
14107 (setq conf-alist (cdr conf-alist)))
14108 (while pack-alist
14109 (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
14110 (setq pack-alist (cdr pack-alist)))
14111 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14112 (vhdl-speedbar-refresh)
14113 (when (memq 'display vhdl-speedbar-save-cache)
14114 (add-to-list 'vhdl-updated-project-list key))))
14115
14116(defun vhdl-speedbar-expand-project (text token indent)
14117 "Expand/contract the project under the cursor."
14118 (cond
14119 ((string-match "+" text) ; expand project
14120 (speedbar-change-expand-button-char ?-)
14121 (unless (member token vhdl-speedbar-shown-project-list)
14122 (setq vhdl-speedbar-shown-project-list
14123 (cons token vhdl-speedbar-shown-project-list)))
14124 (speedbar-with-writable
14125 (save-excursion
14126 (end-of-line) (forward-char 1)
14127 (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
14128 speedbar-power-click))))
14129 ((string-match "-" text) ; contract project
14130 (speedbar-change-expand-button-char ?+)
14131 (setq vhdl-speedbar-shown-project-list
14132 (delete token vhdl-speedbar-shown-project-list))
14133 (speedbar-delete-subblock indent))
14134 (t (error "Nothing to display")))
14135 (when (equal (selected-frame) speedbar-frame)
14136 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14137
14138(defun vhdl-speedbar-expand-entity (text token indent)
14139 "Expand/contract the entity under the cursor."
14140 (cond
14141 ((string-match "+" text) ; expand entity
3dcb36b7
JB
14142 (let* ((key (vhdl-speedbar-line-key indent))
14143 (ent-alist (aget vhdl-entity-alist key t))
14144 (ent-entry (aget ent-alist token t))
14145 (arch-alist (nth 3 ent-entry))
5eabfe72 14146 (inst-alist (vhdl-get-instantiations token indent))
3dcb36b7
JB
14147 (subpack-alist (nth 4 ent-entry))
14148 arch-entry inst-entry)
14149 (if (not (or arch-alist inst-alist subpack-alist))
5eabfe72
KH
14150 (speedbar-change-expand-button-char ??)
14151 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14152 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14153 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14154 (aput 'unit-alist token nil)
14155 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72 14156 (speedbar-with-writable
3dcb36b7
JB
14157 (save-excursion
14158 (end-of-line) (forward-char 1)
14159 ;; insert architectures
14160 (when arch-alist
14161 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
14162 (while arch-alist
14163 (setq arch-entry (car arch-alist))
14164 (speedbar-make-tag-line
14165 'curly ?+ 'vhdl-speedbar-expand-architecture
14166 (cons token (nth 0 arch-entry))
14167 (nth 1 arch-entry) 'vhdl-speedbar-find-file
14168 (cons (nth 2 arch-entry) (nth 3 arch-entry))
14169 'vhdl-speedbar-architecture-face (1+ indent))
14170 (setq arch-alist (cdr arch-alist)))
14171 ;; insert instantiations
14172 (when inst-alist
14173 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
14174 (while inst-alist
14175 (setq inst-entry (car inst-alist))
14176 (vhdl-speedbar-make-inst-line
14177 (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
14178 (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
14179 nil nil nil (1+ indent) 0 " in ")
14180 (setq inst-alist (cdr inst-alist)))
14181 ;; insert required packages
14182 (vhdl-speedbar-insert-subpackages
14183 subpack-alist (1+ indent) indent)))
14184 (when (memq 'display vhdl-speedbar-save-cache)
14185 (add-to-list 'vhdl-updated-project-list key))
14186 (vhdl-speedbar-update-current-unit t t))))
5eabfe72
KH
14187 ((string-match "-" text) ; contract entity
14188 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14189 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14190 (let* ((key (vhdl-speedbar-line-key indent))
14191 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14192 (adelete 'unit-alist token)
14193 (if unit-alist
14194 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14195 (adelete 'vhdl-speedbar-shown-unit-alist key))
14196 (speedbar-delete-subblock indent)
14197 (when (memq 'display vhdl-speedbar-save-cache)
14198 (add-to-list 'vhdl-updated-project-list key))))
14199 (t (error "Nothing to display")))
14200 (when (equal (selected-frame) speedbar-frame)
14201 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14202
14203(defun vhdl-speedbar-expand-architecture (text token indent)
14204 "Expand/contract the architecture under the cursor."
14205 (cond
14206 ((string-match "+" text) ; expand architecture
3dcb36b7
JB
14207 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14208 (ent-alist (aget vhdl-entity-alist key t))
14209 (conf-alist (aget vhdl-config-alist key t))
14210 (hier-alist (vhdl-get-hierarchy
14211 ent-alist conf-alist (car token) (cdr token) nil nil
14212 0 (1- indent)))
14213 (ent-entry (aget ent-alist (car token) t))
14214 (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
14215 (subpack-alist (nth 4 arch-entry))
14216 entry)
14217 (if (not (or hier-alist subpack-alist))
14218 (speedbar-change-expand-button-char ??)
14219 (speedbar-change-expand-button-char ?-)
14220 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
14221 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14222 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14223 (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
14224 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14225 (speedbar-with-writable
14226 (save-excursion
14227 (end-of-line) (forward-char 1)
14228 ;; insert instance hierarchy
14229 (when hier-alist
14230 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
14231 (1+ indent)))
14232 (while hier-alist
14233 (setq entry (car hier-alist))
14234 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14235 (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
14236 (vhdl-speedbar-make-inst-line
14237 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14238 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14239 (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
14240 (setq hier-alist (cdr hier-alist)))
14241 ;; insert required packages
14242 (vhdl-speedbar-insert-subpackages
14243 subpack-alist (1+ indent) (1- indent))))
14244 (when (memq 'display vhdl-speedbar-save-cache)
14245 (add-to-list 'vhdl-updated-project-list key))
14246 (vhdl-speedbar-update-current-unit t t))))
14247 ((string-match "-" text) ; contract architecture
14248 (speedbar-change-expand-button-char ?+)
14249 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
14250 (let* ((key (vhdl-speedbar-line-key (1- indent)))
14251 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
14252 (arch-alist (nth 0 (aget unit-alist (car token) t))))
14253 (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
14254 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14255 (speedbar-delete-subblock indent)
14256 (when (memq 'display vhdl-speedbar-save-cache)
14257 (add-to-list 'vhdl-updated-project-list key))))
14258 (t (error "Nothing to display")))
14259 (when (equal (selected-frame) speedbar-frame)
14260 (speedbar-center-buffer-smartly)))
14261
14262(defun vhdl-speedbar-expand-config (text token indent)
14263 "Expand/contract the configuration under the cursor."
14264 (cond
14265 ((string-match "+" text) ; expand configuration
14266 (let* ((key (vhdl-speedbar-line-key indent))
14267 (conf-alist (aget vhdl-config-alist key t))
14268 (conf-entry (aget conf-alist token))
14269 (ent-alist (aget vhdl-entity-alist key t))
14270 (hier-alist (vhdl-get-hierarchy
14271 ent-alist conf-alist (nth 3 conf-entry)
14272 (nth 4 conf-entry) token (nth 5 conf-entry)
14273 0 indent t))
14274 (subpack-alist (nth 6 conf-entry))
14275 entry)
14276 (if (not (or hier-alist subpack-alist))
5eabfe72
KH
14277 (speedbar-change-expand-button-char ??)
14278 (speedbar-change-expand-button-char ?-)
3dcb36b7
JB
14279 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
14280 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14281 (aput 'unit-alist token nil)
14282 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
5eabfe72
KH
14283 (speedbar-with-writable
14284 (save-excursion
14285 (end-of-line) (forward-char 1)
14286 ;; insert instance hierarchy
14287 (when hier-alist
3dcb36b7 14288 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
5eabfe72 14289 (while hier-alist
3dcb36b7
JB
14290 (setq entry (car hier-alist))
14291 (when (or (= vhdl-speedbar-hierarchy-depth 0)
14292 (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
5eabfe72 14293 (vhdl-speedbar-make-inst-line
3dcb36b7
JB
14294 (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
14295 (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
14296 (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
14297 (setq hier-alist (cdr hier-alist)))
14298 ;; insert required packages
14299 (vhdl-speedbar-insert-subpackages
14300 subpack-alist (1+ indent) indent)))
14301 (when (memq 'display vhdl-speedbar-save-cache)
14302 (add-to-list 'vhdl-updated-project-list key))
14303 (vhdl-speedbar-update-current-unit t t))))
14304 ((string-match "-" text) ; contract configuration
5eabfe72 14305 (speedbar-change-expand-button-char ?+)
3dcb36b7
JB
14306 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
14307 (let* ((key (vhdl-speedbar-line-key indent))
14308 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14309 (adelete 'unit-alist token)
14310 (if unit-alist
14311 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14312 (adelete 'vhdl-speedbar-shown-unit-alist key))
14313 (speedbar-delete-subblock indent)
14314 (when (memq 'display vhdl-speedbar-save-cache)
14315 (add-to-list 'vhdl-updated-project-list key))))
14316 (t (error "Nothing to display")))
14317 (when (equal (selected-frame) speedbar-frame)
14318 (speedbar-center-buffer-smartly)))
14319
14320(defun vhdl-speedbar-expand-package (text token indent)
14321 "Expand/contract the package under the cursor."
14322 (cond
14323 ((string-match "+" text) ; expand package
14324 (let* ((key (vhdl-speedbar-line-key indent))
14325 (pack-alist (aget vhdl-package-alist key t))
14326 (pack-entry (aget pack-alist token t))
14327 (comp-alist (nth 3 pack-entry))
14328 (func-alist (nth 4 pack-entry))
14329 (func-body-alist (nth 8 pack-entry))
14330 (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
14331 comp-entry func-entry func-body-entry)
14332 (if (not (or comp-alist func-alist subpack-alist))
14333 (speedbar-change-expand-button-char ??)
14334 (speedbar-change-expand-button-char ?-)
14335 ;; add package to `vhdl-speedbar-shown-unit-alist'
14336 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14337 (aput 'unit-alist token nil)
14338 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
14339 (speedbar-with-writable
14340 (save-excursion
14341 (end-of-line) (forward-char 1)
14342 ;; insert components
14343 (when comp-alist
14344 (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
14345 (while comp-alist
14346 (setq comp-entry (car comp-alist))
14347 (speedbar-make-tag-line
14348 nil nil nil
14349 (cons token (nth 0 comp-entry))
14350 (nth 1 comp-entry) 'vhdl-speedbar-find-file
14351 (cons (nth 2 comp-entry) (nth 3 comp-entry))
14352 'vhdl-speedbar-entity-face (1+ indent))
14353 (setq comp-alist (cdr comp-alist)))
14354 ;; insert subprograms
14355 (when func-alist
14356 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
14357 (while func-alist
14358 (setq func-entry (car func-alist)
14359 func-body-entry (aget func-body-alist (car func-entry) t))
14360 (when (nth 2 func-entry)
14361 (vhdl-speedbar-make-subprogram-line
14362 (nth 1 func-entry)
14363 (cons (nth 2 func-entry) (nth 3 func-entry))
14364 (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
14365 (1+ indent)))
14366 (setq func-alist (cdr func-alist)))
14367 ;; insert required packages
14368 (vhdl-speedbar-insert-subpackages
14369 subpack-alist (1+ indent) indent)))
14370 (when (memq 'display vhdl-speedbar-save-cache)
14371 (add-to-list 'vhdl-updated-project-list key))
14372 (vhdl-speedbar-update-current-unit t t))))
14373 ((string-match "-" text) ; contract package
14374 (speedbar-change-expand-button-char ?+)
14375 ;; remove package from `vhdl-speedbar-shown-unit-alist'
14376 (let* ((key (vhdl-speedbar-line-key indent))
14377 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
14378 (adelete 'unit-alist token)
14379 (if unit-alist
14380 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
14381 (adelete 'vhdl-speedbar-shown-unit-alist key))
14382 (speedbar-delete-subblock indent)
14383 (when (memq 'display vhdl-speedbar-save-cache)
14384 (add-to-list 'vhdl-updated-project-list key))))
14385 (t (error "Nothing to display")))
14386 (when (equal (selected-frame) speedbar-frame)
14387 (speedbar-center-buffer-smartly)))
14388
14389(defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
14390 "Insert required packages."
14391 (let* ((pack-alist (aget vhdl-package-alist
14392 (vhdl-speedbar-line-key dir-indent) t))
14393 pack-key lib-name pack-entry)
14394 (when subpack-alist
14395 (vhdl-speedbar-make-title-line "Packages Used:" indent))
14396 (while subpack-alist
14397 (setq pack-key (cdar subpack-alist)
14398 lib-name (caar subpack-alist))
14399 (setq pack-entry (aget pack-alist pack-key t))
14400 (vhdl-speedbar-make-subpack-line
14401 (or (nth 0 pack-entry) pack-key) lib-name
14402 (cons (nth 1 pack-entry) (nth 2 pack-entry)) indent)
14403 (setq subpack-alist (cdr subpack-alist)))))
5eabfe72
KH
14404
14405;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14406;; Display help functions
14407
3dcb36b7
JB
14408(defvar vhdl-speedbar-update-current-unit t
14409 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
14410
14411(defun vhdl-speedbar-update-current-project ()
14412 "Highlight project that is currently active."
14413 (when (and vhdl-speedbar-show-projects
14414 (not (equal vhdl-speedbar-last-selected-project vhdl-project))
14415 (and (boundp 'speedbar-frame)
14416 (frame-live-p speedbar-frame)))
14417 (let ((last-frame (selected-frame))
14418 (project-alist vhdl-project-alist)
14419 pos)
14420 (select-frame speedbar-frame)
14421 (speedbar-with-writable
14422 (save-excursion
14423 (while project-alist
14424 (goto-char (point-min))
14425 (when (re-search-forward
14426 (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
14427 (put-text-property (match-beginning 1) (match-end 1) 'face
14428 (if (equal (caar project-alist) vhdl-project)
14429 'speedbar-selected-face
14430 'speedbar-directory-face))
14431 (when (equal (caar project-alist) vhdl-project)
14432 (setq pos (1- (match-beginning 1)))))
14433 (setq project-alist (cdr project-alist))))
14434 (when pos (goto-char pos)))
14435 (select-frame last-frame)
14436 (setq vhdl-speedbar-last-selected-project vhdl-project)))
14437 t)
14438
14439(defun vhdl-speedbar-update-current-unit (&optional no-position always)
5eabfe72
KH
14440 "Highlight all design units that are contained in the current file.
14441NO-POSITION non-nil means do not re-position cursor."
14442 (let ((last-frame (selected-frame))
3dcb36b7
JB
14443 (project-list vhdl-speedbar-shown-project-list)
14444 file-alist pos file-name)
5eabfe72 14445 ;; get current file name
3dcb36b7
JB
14446 (if (fboundp 'speedbar-select-attached-frame)
14447 (speedbar-select-attached-frame)
14448 (select-frame speedbar-attached-frame))
5eabfe72 14449 (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
3dcb36b7
JB
14450 (when (and vhdl-speedbar-update-current-unit
14451 (or always (not (equal file-name speedbar-last-selected-file))))
14452 (if vhdl-speedbar-show-projects
14453 (while project-list
14454 (setq file-alist (append file-alist (aget vhdl-file-alist
14455 (car project-list) t)))
14456 (setq project-list (cdr project-list)))
14457 (setq file-alist (aget vhdl-file-alist
14458 (abbreviate-file-name default-directory) t)))
5eabfe72
KH
14459 (select-frame speedbar-frame)
14460 (set-buffer speedbar-buffer)
14461 (speedbar-with-writable
3dcb36b7 14462 (vhdl-prepare-search-1
5eabfe72
KH
14463 (save-excursion
14464 ;; unhighlight last units
3dcb36b7 14465 (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
5eabfe72 14466 (vhdl-speedbar-update-units
3dcb36b7 14467 "\\[.\\] " (nth 0 file-entry)
5eabfe72
KH
14468 speedbar-last-selected-file 'vhdl-speedbar-entity-face)
14469 (vhdl-speedbar-update-units
3dcb36b7 14470 "{.} " (nth 1 file-entry)
5eabfe72
KH
14471 speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
14472 (vhdl-speedbar-update-units
3dcb36b7 14473 "\\[.\\] " (nth 3 file-entry)
5eabfe72
KH
14474 speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
14475 (vhdl-speedbar-update-units
3dcb36b7 14476 "[]>] " (nth 4 file-entry)
5eabfe72
KH
14477 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14478 (vhdl-speedbar-update-units
3dcb36b7
JB
14479 "\\[.\\].+(" '("body")
14480 speedbar-last-selected-file 'vhdl-speedbar-package-face)
14481 (vhdl-speedbar-update-units
14482 "> " (nth 6 file-entry)
5eabfe72
KH
14483 speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
14484 ;; highlight current units
3dcb36b7
JB
14485 (let* ((file-entry (aget file-alist file-name t)))
14486 (setq
14487 pos (vhdl-speedbar-update-units
14488 "\\[.\\] " (nth 0 file-entry)
14489 file-name 'vhdl-speedbar-entity-selected-face pos)
14490 pos (vhdl-speedbar-update-units
14491 "{.} " (nth 1 file-entry)
14492 file-name 'vhdl-speedbar-architecture-selected-face pos)
14493 pos (vhdl-speedbar-update-units
14494 "\\[.\\] " (nth 3 file-entry)
14495 file-name 'vhdl-speedbar-configuration-selected-face pos)
14496 pos (vhdl-speedbar-update-units
14497 "[]>] " (nth 4 file-entry)
14498 file-name 'vhdl-speedbar-package-selected-face pos)
14499 pos (vhdl-speedbar-update-units
14500 "\\[.\\].+(" '("body")
14501 file-name 'vhdl-speedbar-package-selected-face pos)
14502 pos (vhdl-speedbar-update-units
14503 "> " (nth 6 file-entry)
14504 file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
5eabfe72 14505 ;; move speedbar so the first highlighted unit is visible
3dcb36b7
JB
14506 (when (and pos (not no-position))
14507 (goto-char pos)
14508 (speedbar-center-buffer-smartly)
5eabfe72
KH
14509 (speedbar-position-cursor-on-line))
14510 (setq speedbar-last-selected-file file-name))
14511 (select-frame last-frame)
14512 t))
14513
3dcb36b7
JB
14514(defun vhdl-speedbar-update-units (text unit-list file-name face
14515 &optional pos)
5eabfe72 14516 "Help function to highlight design units."
3dcb36b7
JB
14517 (while unit-list
14518 (goto-char (point-min))
14519 (while (re-search-forward
14520 (concat text "\\(" (car unit-list) "\\)\\>") nil t)
14521 (when (equal file-name (car (get-text-property
14522 (match-beginning 1) 'speedbar-token)))
14523 (setq pos (or pos (point-marker)))
14524 (put-text-property (match-beginning 1) (match-end 1) 'face face)))
14525 (setq unit-list (cdr unit-list)))
14526 pos)
5eabfe72
KH
14527
14528(defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
3dcb36b7
JB
14529 ent-name ent-file-marker
14530 arch-name arch-file-marker
14531 conf-name conf-file-marker
14532 lib-name depth offset delimiter)
5eabfe72 14533 "Insert instantiation entry."
3dcb36b7
JB
14534 (let ((start (point))
14535 visible-start)
5eabfe72
KH
14536 (insert (int-to-string depth) ":")
14537 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14538 (setq visible-start (point))
14539 (insert-char ? (* depth speedbar-indentation-width))
14540 (while (> offset 0)
14541 (insert "|")
14542 (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
14543 (setq offset (1- offset)))
14544 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14545 (setq start (point))
3dcb36b7
JB
14546 (insert ">")
14547 (speedbar-make-button start (point) nil nil nil)
14548 (setq visible-start (point))
14549 (insert " ")
5eabfe72 14550 (setq start (point))
3dcb36b7
JB
14551 (if (not inst-name)
14552 (insert "(top)")
14553 (insert inst-name)
14554 (speedbar-make-button
14555 start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
14556 'vhdl-speedbar-find-file inst-file-marker))
14557 (insert delimiter)
14558 (when ent-name
5eabfe72 14559 (setq start (point))
3dcb36b7 14560 (insert ent-name)
5eabfe72 14561 (speedbar-make-button
3dcb36b7
JB
14562 start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
14563 'vhdl-speedbar-find-file ent-file-marker)
14564 (when arch-name
14565 (insert " (")
14566 (setq start (point))
14567 (insert arch-name)
14568 (speedbar-make-button
14569 start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
14570 'vhdl-speedbar-find-file arch-file-marker)
14571 (insert ")"))
14572 (when conf-name
14573 (insert " (")
14574 (setq start (point))
14575 (insert conf-name)
14576 (speedbar-make-button
14577 start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
14578 'vhdl-speedbar-find-file conf-file-marker)
14579 (insert ")")))
14580 (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
5eabfe72 14581 (setq start (point))
3dcb36b7
JB
14582 (insert " (" lib-name ")")
14583 (put-text-property (+ 2 start) (1- (point)) 'face
14584 'vhdl-speedbar-library-face))
5eabfe72 14585 (insert-char ?\n 1)
3dcb36b7 14586 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14587
3dcb36b7
JB
14588(defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
14589 body-file-marker depth)
5eabfe72 14590 "Insert package entry."
3dcb36b7
JB
14591 (let ((start (point))
14592 visible-start)
5eabfe72
KH
14593 (insert (int-to-string depth) ":")
14594 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14595 (setq visible-start (point))
14596 (insert-char ? (* depth speedbar-indentation-width))
14597 (put-text-property visible-start (point) 'invisible nil)
5eabfe72 14598 (setq start (point))
3dcb36b7
JB
14599 (insert "[+]")
14600 (speedbar-make-button
14601 start (point) 'speedbar-button-face 'speedbar-highlight-face
14602 'vhdl-speedbar-expand-package pack-key)
14603 (setq visible-start (point))
14604 (insert-char ? 1 nil)
5eabfe72
KH
14605 (setq start (point))
14606 (insert pack-name)
14607 (speedbar-make-button
14608 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14609 'vhdl-speedbar-find-file pack-file-marker)
3dcb36b7
JB
14610 (unless (car pack-file-marker)
14611 (insert "!"))
5eabfe72 14612 (when (car body-file-marker)
5eabfe72 14613 (insert " (")
5eabfe72
KH
14614 (setq start (point))
14615 (insert "body")
14616 (speedbar-make-button
14617 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14618 'vhdl-speedbar-find-file body-file-marker)
3dcb36b7 14619 (insert ")"))
5eabfe72 14620 (insert-char ?\n 1)
3dcb36b7 14621 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72 14622
3dcb36b7
JB
14623(defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
14624 depth)
14625 "Insert used package entry."
14626 (let ((start (point))
14627 visible-start)
14628 (insert (int-to-string depth) ":")
14629 (put-text-property start (point) 'invisible t)
14630 (setq visible-start (point))
14631 (insert-char ? (* depth speedbar-indentation-width))
14632 (put-text-property visible-start (point) 'invisible nil)
14633 (setq start (point))
14634 (insert ">")
14635 (speedbar-make-button start (point) nil nil nil)
14636 (setq visible-start (point))
14637 (insert " ")
14638 (setq start (point))
14639 (insert pack-name)
14640 (speedbar-make-button
14641 start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
14642 'vhdl-speedbar-find-file pack-file-marker)
14643 (setq start (point))
14644 (insert " (" lib-name ")")
14645 (put-text-property (+ 2 start) (1- (point)) 'face
14646 'vhdl-speedbar-library-face)
14647 (insert-char ?\n 1)
14648 (put-text-property visible-start (point) 'invisible nil)))
14649
14650(defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
14651 func-body-file-marker
14652 depth)
14653 "Insert subprogram entry."
14654 (let ((start (point))
14655 visible-start)
5eabfe72
KH
14656 (insert (int-to-string depth) ":")
14657 (put-text-property start (point) 'invisible t)
3dcb36b7
JB
14658 (setq visible-start (point))
14659 (insert-char ? (* depth speedbar-indentation-width))
14660 (put-text-property visible-start (point) 'invisible nil)
14661 (setq start (point))
14662 (insert ">")
14663 (speedbar-make-button start (point) nil nil nil)
14664 (setq visible-start (point))
14665 (insert " ")
5eabfe72 14666 (setq start (point))
3dcb36b7
JB
14667 (insert func-name)
14668 (speedbar-make-button
14669 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14670 'vhdl-speedbar-find-file func-file-marker)
14671 (when (car func-body-file-marker)
14672 (insert " (")
14673 (setq start (point))
14674 (insert "body")
14675 (speedbar-make-button
14676 start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
14677 'vhdl-speedbar-find-file func-body-file-marker)
14678 (insert ")"))
14679 (insert-char ?\n 1)
14680 (put-text-property visible-start (point) 'invisible nil)))
14681
14682(defun vhdl-speedbar-make-title-line (text &optional depth)
14683 "Insert design unit title entry."
14684 (let ((start (point))
14685 visible-start)
14686 (when depth
14687 (insert (int-to-string depth) ":")
14688 (put-text-property start (point) 'invisible t))
14689 (setq visible-start (point))
14690 (insert-char ? (* (or depth 0) speedbar-indentation-width))
5eabfe72
KH
14691 (setq start (point))
14692 (insert text)
14693 (speedbar-make-button start (point) nil nil nil nil)
14694 (insert-char ?\n 1)
3dcb36b7 14695 (put-text-property visible-start (point) 'invisible nil)))
5eabfe72
KH
14696
14697(defun vhdl-speedbar-insert-dirs (files level)
14698 "Insert subdirectories."
14699 (let ((dirs (car files)))
14700 (while dirs
14701 (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
14702 (car dirs) 'speedbar-dir-follow nil
14703 'speedbar-directory-face level)
14704 (setq dirs (cdr dirs)))))
14705
14706(defun vhdl-speedbar-dired (text token indent)
14707 "Speedbar click handler for directory expand button in hierarchy mode."
14708 (cond ((string-match "+" text) ; we have to expand this dir
14709 (setq speedbar-shown-directories
14710 (cons (expand-file-name
14711 (concat (speedbar-line-path indent) token "/"))
14712 speedbar-shown-directories))
14713 (speedbar-change-expand-button-char ?-)
14714 (speedbar-reset-scanners)
14715 (speedbar-with-writable
14716 (save-excursion
14717 (end-of-line) (forward-char 1)
14718 (vhdl-speedbar-insert-dirs
14719 (speedbar-file-lists
14720 (concat (speedbar-line-path indent) token "/"))
14721 (1+ indent))
14722 (speedbar-reset-scanners)
14723 (vhdl-speedbar-insert-dir-hierarchy
14724 (abbreviate-file-name
14725 (concat (speedbar-line-path indent) token "/"))
14726 (1+ indent) speedbar-power-click)))
3dcb36b7 14727 (vhdl-speedbar-update-current-unit t t))
5eabfe72
KH
14728 ((string-match "-" text) ; we have to contract this node
14729 (speedbar-reset-scanners)
14730 (let ((oldl speedbar-shown-directories)
14731 (newl nil)
14732 (td (expand-file-name
14733 (concat (speedbar-line-path indent) token))))
14734 (while oldl
14735 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
14736 (setq newl (cons (car oldl) newl)))
14737 (setq oldl (cdr oldl)))
14738 (setq speedbar-shown-directories (nreverse newl)))
14739 (speedbar-change-expand-button-char ?+)
14740 (speedbar-delete-subblock indent))
3dcb36b7
JB
14741 (t (error "Nothing to display")))
14742 (when (equal (selected-frame) speedbar-frame)
14743 (speedbar-center-buffer-smartly)))
5eabfe72
KH
14744
14745(defun vhdl-speedbar-item-info ()
14746 "Derive and display information about this line item."
14747 (save-excursion
14748 (beginning-of-line)
14749 ;; skip invisible number info
3dcb36b7 14750 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
5eabfe72 14751 (cond
3dcb36b7
JB
14752 ;; project/directory entry
14753 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
14754 (if vhdl-speedbar-show-projects
14755 (message "Project \"%s\"" (match-string-no-properties 1))
14756 (speedbar-files-item-info)))
5eabfe72 14757 ;; design unit entry
3dcb36b7
JB
14758 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
14759 (goto-char (match-end 1))
5eabfe72
KH
14760 (let ((face (get-text-property (point) 'face)))
14761 (message
14762 "%s \"%s\" in \"%s\""
14763 ;; design unit kind
14764 (cond ((or (eq face 'vhdl-speedbar-entity-face)
14765 (eq face 'vhdl-speedbar-entity-selected-face))
3dcb36b7 14766 (if (equal (match-string 2) ">") "Component" "Entity"))
5eabfe72
KH
14767 ((or (eq face 'vhdl-speedbar-architecture-face)
14768 (eq face 'vhdl-speedbar-architecture-selected-face))
14769 "Architecture")
14770 ((or (eq face 'vhdl-speedbar-configuration-face)
14771 (eq face 'vhdl-speedbar-configuration-selected-face))
14772 "Configuration")
14773 ((or (eq face 'vhdl-speedbar-package-face)
14774 (eq face 'vhdl-speedbar-package-selected-face))
14775 "Package")
14776 ((or (eq face 'vhdl-speedbar-instantiation-face)
14777 (eq face 'vhdl-speedbar-instantiation-selected-face))
14778 "Instantiation")
3dcb36b7
JB
14779 ((eq face 'vhdl-speedbar-subprogram-face)
14780 "Subprogram")
5eabfe72
KH
14781 (t ""))
14782 ;; design unit name
14783 (buffer-substring-no-properties
3dcb36b7
JB
14784 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
14785 (match-end 1))
5eabfe72 14786 ;; file name
3dcb36b7
JB
14787 (file-relative-name
14788 (or (car (get-text-property (point) 'speedbar-token))
14789 "?")
14790 (vhdl-default-directory)))))
14791 (t (message "")))))
14792
14793(defun vhdl-speedbar-line-text ()
14794 "Calls `speedbar-line-text' and removes text properties."
14795 (let ((string (speedbar-line-text)))
14796 (set-text-properties 0 (length string) nil string)
14797 string))
5eabfe72
KH
14798
14799;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14800;; Help functions
d2ddb974 14801
3dcb36b7
JB
14802(defun vhdl-speedbar-line-key (&optional indent)
14803 "Get currently displayed directory of project name."
14804 (if vhdl-speedbar-show-projects
14805 (vhdl-speedbar-line-project)
14806 (abbreviate-file-name
14807 (file-name-as-directory (speedbar-line-path indent)))))
14808
14809(defun vhdl-speedbar-line-project (&optional indent)
14810 "Get currently displayed project name."
14811 (and vhdl-speedbar-show-projects
14812 (save-excursion
14813 (end-of-line)
14814 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
14815 (match-string-no-properties 1))))
14816
14817(defun vhdl-add-modified-file ()
14818 "Add file to `vhdl-modified-file-list'."
14819 (when vhdl-file-alist
14820 (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
14821 nil)
5eabfe72
KH
14822
14823(defun vhdl-resolve-paths (path-list)
3dcb36b7
JB
14824 "Resolve path wildcards in PATH-LIST."
14825 (let (path-list-1 path-list-2 path-beg path-end dir)
14826 ;; eliminate non-existent directories
5eabfe72
KH
14827 (while path-list
14828 (setq dir (car path-list))
3dcb36b7
JB
14829 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
14830 (if (file-directory-p (match-string 2 dir))
14831 (setq path-list-1 (cons dir path-list-1))
14832 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
5eabfe72 14833 (setq path-list (cdr path-list)))
3dcb36b7 14834 ;; resolve path wildcards
5eabfe72
KH
14835 (while path-list-1
14836 (setq dir (car path-list-1))
3dcb36b7 14837 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
5eabfe72
KH
14838 (progn
14839 (setq path-beg (match-string 1 dir)
14840 path-end (match-string 5 dir))
3dcb36b7 14841 (setq path-list-1
5eabfe72
KH
14842 (append
14843 (mapcar
14844 (function
14845 (lambda (var) (concat path-beg var path-end)))
14846 (let ((all-list (vhdl-directory-files
14847 (match-string 2 dir) t
14848 (concat "\\<" (wildcard-to-regexp
14849 (match-string 4 dir)))))
14850 dir-list)
14851 (while all-list
14852 (when (file-directory-p (car all-list))
14853 (setq dir-list (cons (car all-list) dir-list)))
14854 (setq all-list (cdr all-list)))
14855 dir-list))
3dcb36b7
JB
14856 (cdr path-list-1))))
14857 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
5eabfe72 14858 (when (file-directory-p (match-string 2 dir))
3dcb36b7
JB
14859 (setq path-list-2 (cons dir path-list-2)))
14860 (setq path-list-1 (cdr path-list-1))))
14861 (nreverse path-list-2)))
5eabfe72
KH
14862
14863(defun vhdl-speedbar-goto-this-unit (directory unit)
14864 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
14865 (let ((dest (point)))
3dcb36b7 14866 (if (and (if vhdl-speedbar-show-projects
5eabfe72
KH
14867 (progn (goto-char (point-min)) t)
14868 (speedbar-goto-this-file directory))
14869 (re-search-forward (concat "[]}] " unit "\\>") nil t))
14870 (progn (speedbar-position-cursor-on-line)
14871 t)
14872 (goto-char dest)
14873 nil)))
14874
14875(defun vhdl-speedbar-find-file (text token indent)
3dcb36b7
JB
14876 "When user clicks on TEXT, load file with name and position in TOKEN.
14877Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
14878is already shown in a buffer."
5eabfe72 14879 (if (not (car token))
3dcb36b7
JB
14880 (error "ERROR: File cannot be found")
14881 (let ((buffer (get-file-buffer (car token))))
14882 (speedbar-find-file-in-frame (car token))
14883 (when (or vhdl-speedbar-jump-to-unit buffer)
14884 (goto-line (cdr token))
14885 (recenter))
14886 (vhdl-speedbar-update-current-unit t t)
14887 (speedbar-set-timer speedbar-update-speed)
14888 (speedbar-maybee-jump-to-attached-frame))))
5eabfe72
KH
14889
14890(defun vhdl-speedbar-port-copy ()
3dcb36b7 14891 "Copy the port of the entity/component or subprogram under the cursor."
5eabfe72 14892 (interactive)
3dcb36b7
JB
14893 (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
14894 (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
14895 (error "ERROR: No entity/component or subprogram under cursor")
14896 (beginning-of-line)
14897 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
14898 (condition-case info
14899 (let ((token (get-text-property
14900 (match-beginning 3) 'speedbar-token)))
14901 (vhdl-visit-file (car token) t
14902 (progn (goto-line (cdr token))
14903 (end-of-line)
14904 (if is-entity
14905 (vhdl-port-copy)
14906 (vhdl-subprog-copy)))))
14907 (error (error "ERROR: %s not scanned successfully\n (%s)"
14908 (if is-entity "Port" "Interface") (cadr info))))
14909 (error "ERROR: No entity/component or subprogram on current line")))))
14910
14911(defun vhdl-speedbar-place-component ()
14912 "Place the entity/component under the cursor as component."
14913 (interactive)
14914 (if (not (vhdl-speedbar-check-unit 'entity))
14915 (error "ERROR: No entity/component under cursor.")
14916 (vhdl-speedbar-port-copy)
14917 (if (fboundp 'speedbar-select-attached-frame)
14918 (speedbar-select-attached-frame)
14919 (select-frame speedbar-attached-frame))
14920 (vhdl-compose-place-component)
14921 (select-frame speedbar-frame)))
14922
14923(defun vhdl-speedbar-make-design ()
14924 "Make (compile) design unit or directory/project under the cursor."
14925 (interactive)
14926 (if (not (save-excursion (beginning-of-line)
14927 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
14928 (error "ERROR: No primary design unit or directory/project under cursor")
14929 (let ((is-unit (match-string 2))
14930 (unit-name (vhdl-speedbar-line-text))
14931 (vhdl-project (vhdl-speedbar-line-project))
14932 (directory (file-name-as-directory
14933 (or (speedbar-line-file) (speedbar-line-path)))))
14934 (if (fboundp 'speedbar-select-attached-frame)
14935 (speedbar-select-attached-frame)
14936 (select-frame speedbar-attached-frame))
14937 (let ((default-directory directory))
14938 (vhdl-make (and is-unit unit-name))))))
14939
14940(defun vhdl-speedbar-generate-makefile ()
14941 "Generate Makefile for directory/project under the cursor."
14942 (interactive)
14943 (let ((vhdl-project (vhdl-speedbar-line-project))
14944 (default-directory (file-name-as-directory
14945 (or (speedbar-line-file) (speedbar-line-path)))))
14946 (vhdl-generate-makefile)))
14947
14948(defun vhdl-speedbar-check-unit (design-unit)
14949 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
14950expansion function)."
14951 (save-excursion
14952 (speedbar-position-cursor-on-line)
14953 (cond ((eq design-unit 'entity)
14954 (memq (get-text-property (match-end 0) 'face)
14955 '(vhdl-speedbar-entity-face
14956 vhdl-speedbar-entity-selected-face)))
14957 ((eq design-unit 'subprogram)
14958 (eq (get-text-property (match-end 0) 'face)
14959 'vhdl-speedbar-subprogram-face))
14960 (t nil))))
14961
14962(defun vhdl-speedbar-set-depth (depth)
14963 "Set hierarchy display depth to DEPTH and refresh speedbar."
14964 (setq vhdl-speedbar-hierarchy-depth depth)
14965 (speedbar-refresh))
5eabfe72
KH
14966
14967;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14968;; Fontification
14969
14970(defface vhdl-speedbar-entity-face
14971 '((((class color) (background light)) (:foreground "ForestGreen"))
14972 (((class color) (background dark)) (:foreground "PaleGreen")))
14973 "Face used for displaying entity names."
14974 :group 'speedbar-faces)
14975
14976(defface vhdl-speedbar-architecture-face
14977 '((((class color) (background light)) (:foreground "Blue"))
14978 (((class color) (background dark)) (:foreground "LightSkyBlue")))
14979 "Face used for displaying architecture names."
14980 :group 'speedbar-faces)
d2ddb974 14981
5eabfe72
KH
14982(defface vhdl-speedbar-configuration-face
14983 '((((class color) (background light)) (:foreground "DarkGoldenrod"))
14984 (((class color) (background dark)) (:foreground "Salmon")))
14985 "Face used for displaying configuration names."
14986 :group 'speedbar-faces)
14987
14988(defface vhdl-speedbar-package-face
14989 '((((class color) (background light)) (:foreground "Grey50"))
14990 (((class color) (background dark)) (:foreground "Grey80")))
14991 "Face used for displaying package names."
14992 :group 'speedbar-faces)
14993
3dcb36b7
JB
14994(defface vhdl-speedbar-library-face
14995 '((((class color) (background light)) (:foreground "Purple"))
14996 (((class color) (background dark)) (:foreground "Orchid1")))
14997 "Face used for displaying library names."
14998 :group 'speedbar-faces)
14999
5eabfe72
KH
15000(defface vhdl-speedbar-instantiation-face
15001 '((((class color) (background light)) (:foreground "Brown"))
15002 (((class color) (background dark)) (:foreground "Yellow")))
15003 "Face used for displaying instantiation names."
15004 :group 'speedbar-faces)
15005
3dcb36b7
JB
15006(defface vhdl-speedbar-subprogram-face
15007 '((((class color) (background light)) (:foreground "Orchid4"))
15008 (((class color) (background dark)) (:foreground "BurlyWood2")))
15009 "Face used for displaying subprogram names."
15010 :group 'speedbar-faces)
15011
5eabfe72
KH
15012(defface vhdl-speedbar-entity-selected-face
15013 '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
15014 (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
15015 "Face used for displaying entity names."
15016 :group 'speedbar-faces)
15017
15018(defface vhdl-speedbar-architecture-selected-face
15019 '((((class color) (background light)) (:foreground "Blue" :underline t))
15020 (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
15021 "Face used for displaying architecture names."
15022 :group 'speedbar-faces)
15023
15024(defface vhdl-speedbar-configuration-selected-face
15025 '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
15026 (((class color) (background dark)) (:foreground "Salmon" :underline t)))
15027 "Face used for displaying configuration names."
15028 :group 'speedbar-faces)
15029
15030(defface vhdl-speedbar-package-selected-face
15031 '((((class color) (background light)) (:foreground "Grey50" :underline t))
15032 (((class color) (background dark)) (:foreground "Grey80" :underline t)))
15033 "Face used for displaying package names."
15034 :group 'speedbar-faces)
15035
15036(defface vhdl-speedbar-instantiation-selected-face
15037 '((((class color) (background light)) (:foreground "Brown" :underline t))
15038 (((class color) (background dark)) (:foreground "Yellow" :underline t)))
15039 "Face used for displaying instantiation names."
15040 :group 'speedbar-faces)
15041
3dcb36b7
JB
15042;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15043;; Initialization
15044
15045;; add speedbar
15046(when (fboundp 'speedbar)
15047 (condition-case ()
15048 (when (and vhdl-speedbar-auto-open
15049 (not (and (boundp 'speedbar-frame)
15050 (frame-live-p speedbar-frame))))
15051 (speedbar-frame-mode 1)
15052 (if (fboundp 'speedbar-select-attached-frame)
15053 (speedbar-select-attached-frame)
15054 (select-frame speedbar-attached-frame)))
15055 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15056
15057;; initialize speedbar
15058(if (not (boundp 'speedbar-frame))
15059 (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
15060 (vhdl-speedbar-initialize)
15061 (when speedbar-frame (vhdl-speedbar-refresh)))
15062
15063
15064;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15065;;; Structural composition
15066;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15067
15068(defun vhdl-get-components-package-name ()
15069 "Return the name of the components package."
15070 (let ((project (vhdl-project-p)))
15071 (if project
15072 (vhdl-replace-string (car vhdl-components-package-name)
15073 (subst-char-in-string ? ?_ project))
15074 (cdr vhdl-components-package-name))))
15075
15076(defun vhdl-compose-new-component ()
15077 "Create entity and architecture for new component."
15078 (interactive)
15079 (let* ((case-fold-search t)
15080 (ent-name (read-from-minibuffer "entity name: "
15081 nil vhdl-minibuffer-local-map))
15082 (arch-name
15083 (if (equal (cdr vhdl-compose-architecture-name) "")
15084 (read-from-minibuffer "architecture name: "
15085 nil vhdl-minibuffer-local-map)
15086 (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
15087 ent-file-name arch-file-name ent-buffer arch-buffer project)
15088 (message "Creating component \"%s(%s)\"..." ent-name arch-name)
15089 ;; open entity file
15090 (unless (eq vhdl-compose-create-files 'none)
15091 (setq ent-file-name
15092 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15093 "." (file-name-extension (buffer-file-name))))
15094 (when (and (file-exists-p ent-file-name)
15095 (not (y-or-n-p (concat "File \"" ent-file-name
15096 "\" exists; overwrite? "))))
15097 (error "ERROR: Creating component...aborted"))
15098 (find-file ent-file-name)
15099 (erase-buffer)
15100 (set-buffer-modified-p nil))
15101 ;; insert header
15102 (if vhdl-compose-include-header
15103 (progn (vhdl-template-header)
15104 (goto-char (point-max)))
15105 (vhdl-comment-display-line) (insert "\n\n"))
15106 ;; insert library clause
15107 (vhdl-template-package-std-logic-1164)
15108 (when vhdl-use-components-package
15109 (insert "\n")
15110 (vhdl-template-standard-package (vhdl-work-library)
15111 (vhdl-get-components-package-name)))
15112 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15113 ;; insert entity declaration
15114 (vhdl-insert-keyword "ENTITY ") (insert ent-name)
15115 (vhdl-insert-keyword " IS\n")
15116 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15117 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
15118 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15119 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15120 (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
15121 (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
15122 (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
15123 (vhdl-insert-keyword "END ")
15124 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15125 (insert ent-name ";\n\n")
15126 (vhdl-comment-display-line) (insert "\n")
15127 ;; open architecture file
15128 (if (not (eq vhdl-compose-create-files 'separate))
15129 (insert "\n")
15130 (setq ent-buffer (current-buffer))
15131 (setq arch-file-name
15132 (concat (vhdl-replace-string vhdl-architecture-file-name
15133 (concat ent-name " " arch-name))
15134 "." (file-name-extension (buffer-file-name))))
15135 (when (and (file-exists-p arch-file-name)
15136 (not (y-or-n-p (concat "File \"" arch-file-name
15137 "\" exists; overwrite? "))))
15138 (error "ERROR: Creating component...aborted"))
15139 (find-file arch-file-name)
15140 (erase-buffer)
15141 (set-buffer-modified-p nil)
15142 ;; insert header
15143 (if vhdl-compose-include-header
15144 (progn (vhdl-template-header)
15145 (goto-char (point-max)))
15146 (vhdl-comment-display-line) (insert "\n\n")))
15147 ;; insert architecture body
15148 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
15149 (vhdl-insert-keyword " OF ") (insert ent-name)
15150 (vhdl-insert-keyword " IS\n\n")
15151 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15152 (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
15153 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15154 (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
15155 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15156 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15157 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
15158 (vhdl-insert-keyword "BEGIN")
15159 (when vhdl-self-insert-comments
15160 (insert " -- ")
15161 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15162 (insert arch-name))
15163 (insert "\n\n")
15164 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15165 (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
15166 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15167 (vhdl-insert-keyword "END ")
15168 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
15169 (insert arch-name ";\n\n")
15170 ;; insert footer
15171 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15172 (vhdl-template-footer)
15173 (vhdl-comment-display-line) (insert "\n"))
15174 (goto-char (point-min))
15175 (setq arch-buffer (current-buffer))
15176 (when ent-buffer (set-buffer ent-buffer) (save-buffer))
15177 (set-buffer arch-buffer) (save-buffer)
15178 (message
15179 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
15180 (and ent-file-name
15181 (format "\n File created: \"%s\"" ent-file-name))
15182 (and arch-file-name
15183 (format "\n File created: \"%s\"" arch-file-name))))))
15184
15185(defun vhdl-compose-place-component ()
15186 "Place new component by pasting current port as component declaration and
15187component instantiation."
15188 (interactive)
15189 (if (not vhdl-port-list)
15190 (error "ERROR: No port has been read")
15191 (save-excursion
15192 (vhdl-prepare-search-2
15193 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15194 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15195 (error "ERROR: No architecture found"))
15196 (let* ((ent-name (match-string 1))
15197 (ent-file-name
15198 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15199 "." (file-name-extension (buffer-file-name))))
15200 (orig-buffer (current-buffer)))
15201 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
15202 ;; place component declaration
15203 (unless (or vhdl-use-components-package
15204 (vhdl-use-direct-instantiation)
15205 (save-excursion
15206 (re-search-forward
15207 (concat "^\\s-*component\\s-+"
15208 (car vhdl-port-list) "\\>") nil t)))
15209 (re-search-forward "^begin\\>" nil)
15210 (beginning-of-line)
15211 (skip-chars-backward " \t\n")
15212 (insert "\n\n") (indent-to vhdl-basic-offset)
15213 (vhdl-port-paste-component t))
15214 ;; place component instantiation
15215 (re-search-forward "^end\\>" nil)
15216 (beginning-of-line)
15217 (skip-chars-backward " \t\n")
15218 (insert "\n\n") (indent-to vhdl-basic-offset)
15219 (vhdl-port-paste-instance nil t t)
15220 ;; place use clause for used packages
15221 (when (nth 3 vhdl-port-list)
15222 ;; open entity file
15223 (when (file-exists-p ent-file-name)
15224 (find-file ent-file-name))
15225 (goto-char (point-min))
15226 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15227 (error "ERROR: Entity not found: \"%s\"" ent-name))
15228 (goto-char (match-beginning 0))
15229 (if (and (save-excursion
15230 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
15231 (match-string 1))
15232 (progn (goto-char (match-end 0))
15233 (beginning-of-line 2))
15234 (insert "\n")
15235 (backward-char))
15236 (vhdl-port-paste-context-clause)
15237 (switch-to-buffer orig-buffer))
15238 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
15239
15240(defun vhdl-compose-wire-components ()
15241 "Connect components."
15242 (interactive)
15243 (save-excursion
15244 (vhdl-prepare-search-2
15245 (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
15246 (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
15247 (error "ERROR: No architecture found"))
15248 (let* ((ent-name (match-string 1))
15249 (ent-file-name
15250 (concat (vhdl-replace-string vhdl-entity-file-name ent-name)
15251 "." (file-name-extension (buffer-file-name))))
15252 (arch-decl-pos (point-marker))
15253 (arch-stat-pos (re-search-forward "^begin\\>" nil))
15254 (arch-end-pos (re-search-forward "^end\\>" nil))
15255 (pack-name (vhdl-get-components-package-name))
15256 (pack-file-name
15257 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15258 "." (file-name-extension (buffer-file-name))))
15259 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
15260 port-alist generic-alist inst-alist
15261 signal-name signal-entry signal-alist local-list written-list
15262 single-in-list multi-in-list single-out-list multi-out-list
15263 constant-name constant-entry constant-alist single-list multi-list
15264 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
15265 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
15266 signal-beg-pos signal-pos
15267 constant-temp-pos port-temp-pos signal-temp-pos)
15268 (message "Wiring components...")
15269 ;; process all instances
15270 (goto-char arch-stat-pos)
15271 (while (re-search-forward
15272 (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
15273 "\\(component[ \t\n]+\\)?\\(\\w+\\)"
15274 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
15275 "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
15276 "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
15277 (setq inst-name (match-string-no-properties 1)
15278 comp-name (match-string-no-properties 4)
15279 comp-ent-name (match-string-no-properties 12)
15280 has-generic (or (match-string 7) (match-string 17)))
15281 ;; get port ...
15282 (if comp-name
15283 ;; ... from component declaration
15284 (vhdl-visit-file
15285 (when vhdl-use-components-package pack-file-name) t
15286 (save-excursion
15287 (goto-char (point-min))
15288 (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
15289 (error "ERROR: Component declaration not found: \"%s\"" comp-name))
15290 (vhdl-port-copy)))
15291 ;; ... from entity declaration (direct instantiation)
15292 (setq comp-ent-file-name
15293 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name)
15294 "." (file-name-extension (buffer-file-name))))
15295 (vhdl-visit-file
15296 comp-ent-file-name t
15297 (save-excursion
15298 (goto-char (point-min))
15299 (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
15300 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
15301 (vhdl-port-copy))))
15302 (vhdl-port-flatten t)
15303 (setq generic-alist (nth 1 vhdl-port-list)
15304 port-alist (nth 2 vhdl-port-list))
15305 (setq constant-alist nil
15306 signal-alist nil)
15307 (when has-generic
15308 ;; process all constants in generic map
15309 (vhdl-forward-syntactic-ws)
15310 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15311 (setq constant-name (match-string-no-properties 3))
15312 (setq constant-entry
15313 (cons constant-name
15314 (if (match-string 1)
15315 (or (aget generic-alist (match-string 2) t)
15316 (error (format "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15317 (cdar generic-alist))))
15318 (setq constant-alist (cons constant-entry constant-alist))
15319 (setq constant-name (downcase constant-name))
15320 (if (or (member constant-name single-list)
15321 (member constant-name multi-list))
15322 (progn (setq single-list (delete constant-name single-list))
15323 (add-to-list 'multi-list constant-name))
15324 (add-to-list 'single-list constant-name))
15325 (unless (match-string 1)
15326 (setq generic-alist (cdr generic-alist)))
15327 (vhdl-forward-syntactic-ws))
15328 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
15329 ;; process all signals in port map
15330 (vhdl-forward-syntactic-ws)
15331 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
15332 (setq signal-name (match-string-no-properties 3))
15333 (setq signal-entry (cons signal-name
15334 (if (match-string 1)
15335 (or (aget port-alist (match-string 2) t)
15336 (error (format "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name)))
15337 (cdar port-alist))))
15338 (setq signal-alist (cons signal-entry signal-alist))
15339 (setq signal-name (downcase signal-name))
15340 (if (equal (upcase (nth 2 signal-entry)) "IN")
15341 ;; input signal
15342 (cond
15343 ((member signal-name local-list)
15344 nil)
15345 ((or (member signal-name single-out-list)
15346 (member signal-name multi-out-list))
15347 (setq single-out-list (delete signal-name single-out-list))
15348 (setq multi-out-list (delete signal-name multi-out-list))
15349 (add-to-list 'local-list signal-name))
15350 ((member signal-name single-in-list)
15351 (setq single-in-list (delete signal-name single-in-list))
15352 (add-to-list 'multi-in-list signal-name))
15353 ((not (member signal-name multi-in-list))
15354 (add-to-list 'single-in-list signal-name)))
15355 ;; output signal
15356 (cond
15357 ((member signal-name local-list)
15358 nil)
15359 ((or (member signal-name single-in-list)
15360 (member signal-name multi-in-list))
15361 (setq single-in-list (delete signal-name single-in-list))
15362 (setq multi-in-list (delete signal-name multi-in-list))
15363 (add-to-list 'local-list signal-name))
15364 ((member signal-name single-out-list)
15365 (setq single-out-list (delete signal-name single-out-list))
15366 (add-to-list 'multi-out-list signal-name))
15367 ((not (member signal-name multi-out-list))
15368 (add-to-list 'single-out-list signal-name))))
15369 (unless (match-string 1)
15370 (setq port-alist (cdr port-alist)))
15371 (vhdl-forward-syntactic-ws))
15372 (setq inst-alist (cons (list inst-name (nreverse constant-alist)
15373 (nreverse signal-alist)) inst-alist)))
15374 ;; prepare signal insertion
15375 (vhdl-goto-marker arch-decl-pos)
15376 (forward-line 1)
15377 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
15378 (setq signal-pos (point-marker))
15379 (while (progn (vhdl-forward-syntactic-ws)
15380 (looking-at "signal\\>"))
15381 (beginning-of-line 2)
15382 (delete-region signal-pos (point)))
15383 (setq signal-beg-pos signal-pos)
15384 ;; open entity file
15385 (when (file-exists-p ent-file-name)
15386 (find-file ent-file-name))
15387 (goto-char (point-min))
15388 (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
15389 (error "ERROR: Entity not found: \"%s\"" ent-name))
15390 ;; prepare generic clause insertion
15391 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
15392 (match-string 1))
15393 (goto-char (match-beginning 0))
15394 (indent-to vhdl-basic-offset)
15395 (insert "generic ();\n\n")
15396 (backward-char 4))
15397 (backward-char)
15398 (setq generic-pos (point-marker))
15399 (forward-sexp) (end-of-line)
15400 (delete-region generic-pos (point)) (delete-char 1)
15401 (insert "(\n")
15402 (when multi-list
15403 (insert "\n")
15404 (indent-to (* 2 vhdl-basic-offset))
15405 (insert "-- global generics\n"))
15406 (setq generic-beg-pos (point-marker) generic-pos (point-marker)
15407 generic-inst-pos (point-marker) generic-end-pos (point-marker))
15408 ;; prepare port clause insertion
15409 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
15410 (match-string 1))
15411 (goto-char (match-beginning 0))
15412 (indent-to vhdl-basic-offset)
15413 (insert "port ();\n\n")
15414 (backward-char 4))
15415 (backward-char)
15416 (setq port-in-pos (point-marker))
15417 (forward-sexp) (end-of-line)
15418 (delete-region port-in-pos (point)) (delete-char 1)
15419 (insert "(\n")
15420 (when (or multi-in-list multi-out-list)
15421 (insert "\n")
15422 (indent-to (* 2 vhdl-basic-offset))
15423 (insert "-- global ports\n"))
15424 (setq port-beg-pos (point-marker) port-in-pos (point-marker)
15425 port-out-pos (point-marker) port-inst-pos (point-marker)
15426 port-end-pos (point-marker))
15427 ;; insert generics, ports and signals
15428 (setq inst-alist (nreverse inst-alist))
15429 (while inst-alist
15430 (setq inst-name (nth 0 (car inst-alist))
15431 constant-alist (nth 1 (car inst-alist))
15432 signal-alist (nth 2 (car inst-alist))
15433 constant-temp-pos generic-inst-pos
15434 port-temp-pos port-inst-pos
15435 signal-temp-pos signal-pos)
15436 ;; generics
15437 (while constant-alist
15438 (setq constant-name (downcase (caar constant-alist))
15439 constant-entry (car constant-alist))
15440 (cond ((member constant-name written-list)
15441 nil)
15442 ((member constant-name multi-list)
15443 (vhdl-goto-marker generic-pos)
15444 (setq generic-end-pos
15445 (vhdl-max-marker
15446 generic-end-pos
15447 (vhdl-compose-insert-generic constant-entry)))
15448 (setq generic-pos (point-marker))
15449 (add-to-list 'written-list constant-name))
15450 (t
15451 (vhdl-goto-marker
15452 (vhdl-max-marker generic-inst-pos generic-pos))
15453 (setq generic-end-pos
15454 (vhdl-compose-insert-generic constant-entry))
15455 (setq generic-inst-pos (point-marker))
15456 (add-to-list 'written-list constant-name)))
15457 (setq constant-alist (cdr constant-alist)))
15458 (when (/= constant-temp-pos generic-inst-pos)
15459 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
15460 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15461 (insert "-- generics for \"" inst-name "\"\n")
15462 (vhdl-goto-marker generic-inst-pos))
15463 ;; ports and signals
15464 (while signal-alist
15465 (setq signal-name (downcase (caar signal-alist))
15466 signal-entry (car signal-alist))
15467 (cond ((member signal-name written-list)
15468 nil)
15469 ((member signal-name multi-in-list)
15470 (vhdl-goto-marker port-in-pos)
15471 (setq port-end-pos
15472 (vhdl-max-marker
15473 port-end-pos (vhdl-compose-insert-port signal-entry)))
15474 (setq port-in-pos (point-marker))
15475 (add-to-list 'written-list signal-name))
15476 ((member signal-name multi-out-list)
15477 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
15478 (setq port-end-pos
15479 (vhdl-max-marker
15480 port-end-pos (vhdl-compose-insert-port signal-entry)))
15481 (setq port-out-pos (point-marker))
15482 (add-to-list 'written-list signal-name))
15483 ((or (member signal-name single-in-list)
15484 (member signal-name single-out-list))
15485 (vhdl-goto-marker
15486 (vhdl-max-marker
15487 port-inst-pos
15488 (vhdl-max-marker port-out-pos port-in-pos)))
15489 (setq port-end-pos (vhdl-compose-insert-port signal-entry))
15490 (setq port-inst-pos (point-marker))
15491 (add-to-list 'written-list signal-name))
15492 ((equal (upcase (nth 2 signal-entry)) "OUT")
15493 (vhdl-goto-marker signal-pos)
15494 (vhdl-compose-insert-signal signal-entry)
15495 (setq signal-pos (point-marker))
15496 (add-to-list 'written-list signal-name)))
15497 (setq signal-alist (cdr signal-alist)))
15498 (when (/= port-temp-pos port-inst-pos)
15499 (vhdl-goto-marker
15500 (vhdl-max-marker port-temp-pos
15501 (vhdl-max-marker port-in-pos port-out-pos)))
15502 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15503 (insert "-- ports to \"" inst-name "\"\n")
15504 (vhdl-goto-marker port-inst-pos))
15505 (when (/= signal-temp-pos signal-pos)
15506 (vhdl-goto-marker signal-temp-pos)
15507 (insert "\n") (indent-to vhdl-basic-offset)
15508 (insert "-- outputs of \"" inst-name "\"\n")
15509 (vhdl-goto-marker signal-pos))
15510 (setq inst-alist (cdr inst-alist)))
15511 ;; finalize generic/port clause
15512 (vhdl-goto-marker generic-end-pos) (backward-char)
15513 (when (= generic-beg-pos generic-end-pos)
15514 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15515 (insert ";") (backward-char))
15516 (insert ")")
15517 (vhdl-goto-marker port-end-pos) (backward-char)
15518 (when (= port-beg-pos port-end-pos)
15519 (insert "\n") (indent-to (* 2 vhdl-basic-offset))
15520 (insert ";") (backward-char))
15521 (insert ")")
15522 ;; align everything
15523 (when vhdl-auto-align
15524 (vhdl-goto-marker generic-beg-pos)
15525 (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
15526 (vhdl-align-region-groups port-beg-pos port-end-pos 1)
15527 (vhdl-goto-marker signal-beg-pos)
15528 (vhdl-align-region-groups signal-beg-pos signal-pos))
15529 (switch-to-buffer (marker-buffer signal-beg-pos))
15530 (message "Wiring components...done")))))
15531
15532(defun vhdl-compose-insert-generic (entry)
15533 "Insert ENTRY as generic declaration."
15534 (let (pos)
15535 (indent-to (* 2 vhdl-basic-offset))
15536 (insert (nth 0 entry) " : " (nth 1 entry))
15537 (when (nth 2 entry)
15538 (insert " := " (nth 2 entry)))
15539 (insert ";")
15540 (setq pos (point-marker))
15541 (when (and vhdl-include-port-comments (nth 3 entry))
15542 (vhdl-comment-insert-inline (nth 3 entry) t))
15543 (insert "\n")
15544 pos))
15545
15546(defun vhdl-compose-insert-port (entry)
15547 "Insert ENTRY as port declaration."
15548 (let (pos)
15549 (indent-to (* 2 vhdl-basic-offset))
15550 (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
15551 (setq pos (point-marker))
15552 (when (and vhdl-include-port-comments (nth 4 entry))
15553 (vhdl-comment-insert-inline (nth 4 entry) t))
15554 (insert "\n")
15555 pos))
15556
15557(defun vhdl-compose-insert-signal (entry)
15558 "Insert ENTRY as signal declaration."
15559 (indent-to vhdl-basic-offset)
15560 (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
15561 (when (and vhdl-include-port-comments (nth 4 entry))
15562 (vhdl-comment-insert-inline (nth 4 entry) t))
15563 (insert "\n"))
15564
15565(defun vhdl-compose-components-package ()
15566 "Generate a package containing component declarations for all entities in the
15567current project/directory."
15568 (interactive)
15569 (vhdl-require-hierarchy-info)
15570 (let* ((project (vhdl-project-p))
15571 (pack-name (vhdl-get-components-package-name))
15572 (pack-file-name
15573 (concat (vhdl-replace-string vhdl-package-file-name pack-name)
15574 "." (file-name-extension (buffer-file-name))))
15575 (ent-alist (aget vhdl-entity-alist
15576 (or project default-directory) t))
15577 (lazy-lock-minimum-size 0)
15578 clause-pos component-pos)
15579 (message "Generating components package \"%s\"..." pack-name)
15580 ;; open package file
15581 (when (and (file-exists-p pack-file-name)
15582 (not (y-or-n-p (concat "File \"" pack-file-name
15583 "\" exists; overwrite? "))))
15584 (error "ERROR: Generating components package...aborted"))
15585 (find-file pack-file-name)
15586 (erase-buffer)
15587 ;; insert header
15588 (if vhdl-compose-include-header
15589 (progn (vhdl-template-header
15590 (concat "Components package (generated by Emacs VHDL Mode "
15591 vhdl-version ")"))
15592 (goto-char (point-max)))
15593 (vhdl-comment-display-line) (insert "\n\n"))
15594 ;; insert std_logic_1164 package
15595 (vhdl-template-package-std-logic-1164)
15596 (insert "\n") (setq clause-pos (point-marker))
15597 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
15598 ;; insert package declaration
15599 (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
15600 (vhdl-insert-keyword " IS\n\n")
15601 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
15602 (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
15603 (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
15604 (indent-to vhdl-basic-offset)
15605 (setq component-pos (point-marker))
15606 (insert "\n\n") (vhdl-insert-keyword "END ")
15607 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
15608 (insert pack-name ";\n\n")
15609 ;; insert footer
15610 (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
15611 (vhdl-template-footer)
15612 (vhdl-comment-display-line) (insert "\n"))
15613 ;; insert component declarations
15614 (while ent-alist
15615 (vhdl-visit-file (nth 2 (car ent-alist)) nil
15616 (progn (goto-line (nth 3 (car ent-alist)))
15617 (end-of-line)
15618 (vhdl-port-copy)))
15619 (goto-char component-pos)
15620 (vhdl-port-paste-component t)
15621 (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
15622 (setq component-pos (point-marker))
15623 (goto-char clause-pos)
15624 (vhdl-port-paste-context-clause pack-name)
15625 (setq clause-pos (point-marker))
15626 (setq ent-alist (cdr ent-alist)))
15627 (goto-char (point-min))
15628 (save-buffer)
15629 (message "Generating components package \"%s\"...done\n File created: \"%s\""
15630 pack-name pack-file-name)))
15631
15632
15633;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15634;;; Compilation / Makefile generation
15635;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15636;; (using `compile.el')
15637
15638(defun vhdl-makefile-name ()
15639 "Return the Makefile name of the current project or the current compiler if
15640no project is defined."
15641 (let ((project-alist (aget vhdl-project-alist vhdl-project))
15642 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
15643 (vhdl-replace-string
15644 (cons "\\(.*\\)\n\\(.*\\)"
15645 (or (nth 8 project-alist) (nth 8 compiler-alist)))
15646 (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
15647
15648(defun vhdl-compile-directory ()
15649 "Return the directory where compilation/make should be run."
15650 (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
15651 (compiler (aget vhdl-compiler-alist vhdl-compiler))
15652 (directory (vhdl-resolve-env-variable
15653 (if project
15654 (vhdl-replace-string
15655 (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
15656 (nth 6 compiler)))))
15657 (file-name-as-directory
15658 (if (file-name-absolute-p directory)
15659 directory
15660 (expand-file-name directory (vhdl-default-directory))))))
15661
15662(defun vhdl-uniquify (in-list)
15663 "Remove duplicate elements from IN-LIST."
15664 (let (out-list)
15665 (while in-list
15666 (add-to-list 'out-list (car in-list))
15667 (setq in-list (cdr in-list)))
15668 out-list))
15669
15670(defun vhdl-set-compiler (name)
15671 "Set current compiler to NAME."
15672 (interactive
15673 (list (let ((completion-ignore-case t))
15674 (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
15675 (if (assoc name vhdl-compiler-alist)
15676 (progn (setq vhdl-compiler name)
15677 (message "Current compiler: \"%s\"" vhdl-compiler))
15678 (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
15679
15680;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15681;; Compilation
15682
15683(defun vhdl-compile-init ()
15684 "Initialize for compilation."
15685 (when (or (null compilation-error-regexp-alist)
15686 (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
15687 compilation-error-regexp-alist)))
15688 ;; `compilation-error-regexp-alist'
15689 (let ((commands-alist vhdl-compiler-alist)
15690 regexp-alist sublist)
15691 (while commands-alist
15692 (setq sublist (nth 11 (car commands-alist)))
15693 (unless (or (equal "" (car sublist))
15694 (assoc (car sublist) regexp-alist))
15695 (setq regexp-alist (cons (list (nth 0 sublist)
15696 (if (= 0 (nth 1 sublist))
15697 (if vhdl-xemacs 9 nil)
15698 (nth 1 sublist))
15699 (nth 2 sublist) (nth 3 sublist))
15700 regexp-alist)))
15701 (setq commands-alist (cdr commands-alist)))
15702 (setq compilation-error-regexp-alist
15703 (append compilation-error-regexp-alist (nreverse regexp-alist))))
15704 ;; `compilation-file-regexp-alist'
15705 (let ((commands-alist vhdl-compiler-alist)
15706 regexp-alist sublist)
15707 ;; matches vhdl-mode file name output
15708 (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
15709 (while commands-alist
15710 (setq sublist (nth 12 (car commands-alist)))
15711 (unless (or (equal "" (car sublist))
15712 (assoc (car sublist) regexp-alist))
15713 (setq regexp-alist (cons sublist regexp-alist)))
15714 (setq commands-alist (cdr commands-alist)))
15715 (setq compilation-file-regexp-alist
15716 (append compilation-file-regexp-alist (nreverse regexp-alist))))))
15717
15718(defvar vhdl-compile-file-name nil
15719 "Name of file to be compiled.")
15720
15721(defun vhdl-compile-print-file-name ()
15722 "Function called within `compile' to print out file name for compilers that
15723do not print any file names."
15724 (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
15725
15726(defun vhdl-get-compile-options (project compiler file-name
15727 &optional file-options-only)
15728 "Get compiler options. Returning nil means do not compile this file."
15729 (let* ((compiler-options (nth 1 compiler))
15730 (project-entry (aget (nth 4 project) vhdl-compiler))
15731 (project-options (nth 0 project-entry))
15732 (exception-list (and file-name (nth 2 project-entry)))
15733 (work-library (vhdl-work-library))
15734 (case-fold-search nil)
15735 file-options)
15736 (while (and exception-list
15737 (not (string-match (caar exception-list) file-name)))
15738 (setq exception-list (cdr exception-list)))
15739 (if (and exception-list (not (cdar exception-list)))
15740 nil
15741 (if (and file-options-only (not exception-list))
15742 'default
15743 (setq file-options (cdar exception-list))
15744 ;; insert library name in compiler-specific options
15745 (setq compiler-options
15746 (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
15747 work-library))
15748 ;; insert compiler-specific options in project-specific options
15749 (when project-options
15750 (setq project-options
15751 (vhdl-replace-string
15752 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15753 (concat work-library "\n" compiler-options))))
15754 ;; insert project-specific options in file-specific options
15755 (when file-options
15756 (setq file-options
15757 (vhdl-replace-string
15758 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
15759 (concat work-library "\n" compiler-options "\n"
15760 project-options))))
15761 ;; return options
15762 (or file-options project-options compiler-options)))))
15763
15764(defun vhdl-get-make-options (project compiler)
15765 "Get make options."
15766 (let* ((compiler-options (nth 3 compiler))
15767 (project-entry (aget (nth 4 project) vhdl-compiler))
15768 (project-options (nth 1 project-entry))
15769 (makefile-name (vhdl-makefile-name)))
15770 ;; insert Makefile name in compiler-specific options
15771 (setq compiler-options
15772 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
15773 makefile-name))
15774 ;; insert compiler-specific options in project-specific options
15775 (when project-options
15776 (setq project-options
15777 (vhdl-replace-string
15778 (cons "\\(.*\\)\n\\(.*\\)" project-options)
15779 (concat makefile-name "\n" compiler-options))))
15780 ;; return options
15781 (or project-options compiler-options)))
15782
15783(defun vhdl-compile ()
15784 "Compile current buffer using the VHDL compiler specified in
15785`vhdl-compiler'."
15786 (interactive)
15787 (vhdl-compile-init)
15788 (let* ((project (aget vhdl-project-alist vhdl-project))
15789 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
15790 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15791 (command (nth 0 compiler))
15792 (file-name (buffer-file-name))
15793 (options (vhdl-get-compile-options project compiler file-name))
15794 (default-directory (vhdl-compile-directory))
15795 compilation-process-setup-function)
15796 (unless (file-directory-p default-directory)
15797 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15798 ;; put file name into quotes if it contains spaces
15799 (when (string-match " " file-name)
15800 (setq file-name (concat "\"" file-name "\"")))
15801 ;; print out file name if compiler does not
15802 (setq vhdl-compile-file-name (buffer-file-name))
15803 (when (and (= 0 (nth 1 (nth 10 compiler)))
15804 (= 0 (nth 1 (nth 11 compiler))))
15805 (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
15806 ;; run compilation
15807 (if options
15808 (when command
15809 (compile (concat command " " options " " file-name)))
15810 (vhdl-warning "Your project settings tell me not to compile this file"))))
15811
15812(defun vhdl-make (&optional target)
15813 "Call make command for compilation of all updated source files (requires
15814`Makefile'). Optional argument TARGET allows to compile the design
15815specified by a target."
15816 (interactive)
15817 (vhdl-compile-init)
15818 (let* ((project (aget vhdl-project-alist vhdl-project))
15819 (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15820 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15821 (command (nth 2 compiler))
15822 (options (vhdl-get-make-options project compiler))
15823 (default-directory (vhdl-compile-directory)))
15824 (unless (file-directory-p default-directory)
15825 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
15826 ;; run make
15827 (compile (concat (if (equal command "") "make" command)
15828 " " options " " target))))
15829
15830;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15831;; Makefile generation
15832
15833(defun vhdl-generate-makefile ()
15834 "Generate `Makefile'."
15835 (interactive)
15836 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
15837 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
15838 (command (nth 4 compiler)))
15839 ;; generate makefile
15840 (if command
15841 (let ((default-directory (vhdl-compile-directory)))
15842 (compile (vhdl-replace-string
15843 (cons "\\(.*\\) \\(.*\\)" command)
15844 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
15845 (vhdl-generate-makefile-1))))
15846
15847(defun vhdl-get-packages (lib-alist work-library)
15848 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
15849 (let (pack-list)
15850 (while lib-alist
15851 (when (equal (downcase (caar lib-alist)) (downcase work-library))
15852 (setq pack-list (cons (cdar lib-alist) pack-list)))
15853 (setq lib-alist (cdr lib-alist)))
15854 pack-list))
15855
15856(defun vhdl-generate-makefile-1 ()
15857 "Generate Makefile for current project or directory."
15858 ;; scan hierarchy if required
15859 (if (vhdl-project-p)
15860 (unless (or (assoc vhdl-project vhdl-file-alist)
15861 (vhdl-load-cache vhdl-project))
15862 (vhdl-scan-project-contents vhdl-project))
15863 (let ((directory (abbreviate-file-name default-directory)))
15864 (unless (or (assoc directory vhdl-file-alist)
15865 (vhdl-load-cache directory))
15866 (vhdl-scan-directory-contents directory))))
15867 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
15868 (project (vhdl-project-p))
15869 (ent-alist (aget vhdl-entity-alist (or project directory) t))
15870 (conf-alist (aget vhdl-config-alist (or project directory) t))
15871 (pack-alist (aget vhdl-package-alist (or project directory) t))
15872 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
15873 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
15874 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
15875 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
15876 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
15877 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
15878 (adjust-case (nth 5 regexp-list))
15879 (work-library (downcase (vhdl-work-library)))
15880 (compile-directory (expand-file-name (vhdl-compile-directory)
15881 default-directory))
15882 (makefile-name (vhdl-makefile-name))
15883 rule-alist arch-alist inst-alist
15884 target-list depend-list unit-list prim-list second-list subcomp-list
15885 lib-alist lib-body-alist pack-list all-pack-list
15886 ent-key ent-file-name arch-key arch-file-name ent-arch-key
15887 conf-key conf-file-name pack-key pack-file-name
15888 ent-entry arch-entry conf-entry pack-entry inst-entry
15889 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
15890 tmp-key tmp-list rule)
15891 ;; check prerequisites
15892 (unless (file-exists-p compile-directory)
15893 (make-directory compile-directory t))
15894 (unless regexp-list
15895 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
15896 vhdl-compiler))
15897 (message "Generating makefile \"%s\"..." makefile-name)
15898 ;; rules for all entities
15899 (setq tmp-list ent-alist)
15900 (while ent-alist
15901 (setq ent-entry (car ent-alist)
15902 ent-key (nth 0 ent-entry))
15903 (when (nth 2 ent-entry)
15904 (setq ent-file-name (file-relative-name
15905 (nth 2 ent-entry) compile-directory)
15906 arch-alist (nth 4 ent-entry)
15907 lib-alist (nth 5 ent-entry)
15908 rule (aget rule-alist ent-file-name)
15909 target-list (nth 0 rule)
15910 depend-list (nth 1 rule)
15911 second-list nil
15912 subcomp-list nil)
15913 (setq tmp-key (vhdl-replace-string
15914 ent-regexp (funcall adjust-case ent-key)))
15915 (setq unit-list (cons (cons ent-key tmp-key) unit-list))
15916 ;; rule target for this entity
15917 (setq target-list (cons ent-key target-list))
15918 ;; rule dependencies for all used packages
15919 (setq pack-list (vhdl-get-packages lib-alist work-library))
15920 (setq depend-list (append depend-list pack-list))
15921 (setq all-pack-list pack-list)
15922 ;; add rule
15923 (aput 'rule-alist ent-file-name (list target-list depend-list))
15924 ;; rules for all corresponding architectures
15925 (while arch-alist
15926 (setq arch-entry (car arch-alist)
15927 arch-key (nth 0 arch-entry)
15928 ent-arch-key (concat ent-key "-" arch-key)
15929 arch-file-name (file-relative-name (nth 2 arch-entry)
15930 compile-directory)
15931 inst-alist (nth 4 arch-entry)
15932 lib-alist (nth 5 arch-entry)
15933 rule (aget rule-alist arch-file-name)
15934 target-list (nth 0 rule)
15935 depend-list (nth 1 rule))
15936 (setq tmp-key (vhdl-replace-string
15937 arch-regexp
15938 (funcall adjust-case (concat arch-key " " ent-key))))
15939 (setq unit-list
15940 (cons (cons ent-arch-key tmp-key) unit-list))
15941 (setq second-list (cons ent-arch-key second-list))
15942 ;; rule target for this architecture
15943 (setq target-list (cons ent-arch-key target-list))
15944 ;; rule dependency for corresponding entity
15945 (setq depend-list (cons ent-key depend-list))
15946 ;; rule dependencies for contained component instantiations
15947 (while inst-alist
15948 (setq inst-entry (car inst-alist))
15949 (when (or (null (nth 8 inst-entry))
15950 (equal (downcase (nth 8 inst-entry)) work-library))
15951 (setq inst-ent-key (or (nth 7 inst-entry)
15952 (nth 5 inst-entry)))
15953 (setq depend-list (cons inst-ent-key depend-list)
15954 subcomp-list (cons inst-ent-key subcomp-list)))
15955 (setq inst-alist (cdr inst-alist)))
15956 ;; rule dependencies for all used packages
15957 (setq pack-list (vhdl-get-packages lib-alist work-library))
15958 (setq depend-list (append depend-list pack-list))
15959 (setq all-pack-list (append all-pack-list pack-list))
15960 ;; add rule
15961 (aput 'rule-alist arch-file-name (list target-list depend-list))
15962 (setq arch-alist (cdr arch-alist)))
15963 (setq prim-list (cons (list ent-key second-list
15964 (append subcomp-list all-pack-list))
15965 prim-list)))
15966 (setq ent-alist (cdr ent-alist)))
15967 (setq ent-alist tmp-list)
15968 ;; rules for all configurations
15969 (setq tmp-list conf-alist)
15970 (while conf-alist
15971 (setq conf-entry (car conf-alist)
15972 conf-key (nth 0 conf-entry)
15973 conf-file-name (file-relative-name
15974 (nth 2 conf-entry) compile-directory)
15975 ent-key (nth 4 conf-entry)
15976 arch-key (nth 5 conf-entry)
15977 inst-alist (nth 6 conf-entry)
15978 lib-alist (nth 7 conf-entry)
15979 rule (aget rule-alist conf-file-name)
15980 target-list (nth 0 rule)
15981 depend-list (nth 1 rule)
15982 subcomp-list (list ent-key))
15983 (setq tmp-key (vhdl-replace-string
15984 conf-regexp (funcall adjust-case conf-key)))
15985 (setq unit-list (cons (cons conf-key tmp-key) unit-list))
15986 ;; rule target for this configuration
15987 (setq target-list (cons conf-key target-list))
15988 ;; rule dependency for corresponding entity and architecture
15989 (setq depend-list
15990 (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
15991 ;; rule dependencies for used packages
15992 (setq pack-list (vhdl-get-packages lib-alist work-library))
15993 (setq depend-list (append depend-list pack-list))
15994 ;; rule dependencies for contained component configurations
15995 (while inst-alist
15996 (setq inst-entry (car inst-alist))
15997 (setq inst-ent-key (nth 2 inst-entry)
15998; comp-arch-key (nth 2 inst-entry))
15999 inst-conf-key (nth 4 inst-entry))
16000 (when (equal (downcase (nth 5 inst-entry)) work-library)
16001 (when inst-ent-key
16002 (setq depend-list (cons inst-ent-key depend-list)
16003 subcomp-list (cons inst-ent-key subcomp-list)))
16004; (when comp-arch-key
16005; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
16006; depend-list)))
16007 (when inst-conf-key
16008 (setq depend-list (cons inst-conf-key depend-list)
16009 subcomp-list (cons inst-conf-key subcomp-list))))
16010 (setq inst-alist (cdr inst-alist)))
16011 ;; add rule
16012 (aput 'rule-alist conf-file-name (list target-list depend-list))
16013 (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
16014 prim-list))
16015 (setq conf-alist (cdr conf-alist)))
16016 (setq conf-alist tmp-list)
16017 ;; rules for all packages
16018 (setq tmp-list pack-alist)
16019 (while pack-alist
16020 (setq pack-entry (car pack-alist)
16021 pack-key (nth 0 pack-entry)
16022 pack-body-key nil)
16023 (when (nth 2 pack-entry)
16024 (setq pack-file-name (file-relative-name (nth 2 pack-entry)
16025 compile-directory)
16026 lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
16027 rule (aget rule-alist pack-file-name)
16028 target-list (nth 0 rule) depend-list (nth 1 rule))
16029 (setq tmp-key (vhdl-replace-string
16030 pack-regexp (funcall adjust-case pack-key)))
16031 (setq unit-list (cons (cons pack-key tmp-key) unit-list))
16032 ;; rule target for this package
16033 (setq target-list (cons pack-key target-list))
16034 ;; rule dependencies for all used packages
16035 (setq pack-list (vhdl-get-packages lib-alist work-library))
16036 (setq depend-list (append depend-list pack-list))
16037 (setq all-pack-list pack-list)
16038 ;; add rule
16039 (aput 'rule-alist pack-file-name (list target-list depend-list))
16040 ;; rules for this package's body
16041 (when (nth 7 pack-entry)
16042 (setq pack-body-key (concat pack-key "-body")
16043 pack-body-file-name (file-relative-name (nth 7 pack-entry)
16044 compile-directory)
16045 rule (aget rule-alist pack-body-file-name)
16046 target-list (nth 0 rule)
16047 depend-list (nth 1 rule))
16048 (setq tmp-key (vhdl-replace-string
16049 pack-body-regexp (funcall adjust-case pack-key)))
16050 (setq unit-list
16051 (cons (cons pack-body-key tmp-key) unit-list))
16052 ;; rule target for this package's body
16053 (setq target-list (cons pack-body-key target-list))
16054 ;; rule dependency for corresponding package declaration
16055 (setq depend-list (cons pack-key depend-list))
16056 ;; rule dependencies for all used packages
16057 (setq pack-list (vhdl-get-packages lib-body-alist work-library))
16058 (setq depend-list (append depend-list pack-list))
16059 (setq all-pack-list (append all-pack-list pack-list))
16060 ;; add rule
16061 (aput 'rule-alist pack-body-file-name
16062 (list target-list depend-list)))
16063 (setq prim-list
16064 (cons (list pack-key (when pack-body-key (list pack-body-key))
16065 all-pack-list)
16066 prim-list)))
16067 (setq pack-alist (cdr pack-alist)))
16068 (setq pack-alist tmp-list)
16069 ;; generate Makefile
16070 (let* ((project (aget vhdl-project-alist project))
16071 (compiler (aget vhdl-compiler-alist vhdl-compiler))
16072 (compiler-id (nth 9 compiler))
16073 (library-directory
16074 (vhdl-resolve-env-variable
16075 (vhdl-replace-string
16076 (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
16077 compiler-id)))
16078 (makefile-path-name (expand-file-name
16079 makefile-name compile-directory))
16080 (orig-buffer (current-buffer))
16081 cell second-list subcomp-list options unit-key unit-name)
16082 ;; sort lists
16083 (setq unit-list (vhdl-sort-alist unit-list))
16084 (setq prim-list (vhdl-sort-alist prim-list))
16085 (setq tmp-list rule-alist)
16086 (while tmp-list ; pre-sort rule targets
16087 (setq cell (cdar tmp-list))
16088 (setcar cell (sort (car cell) 'string<))
16089 (setq tmp-list (cdr tmp-list)))
16090 (setq rule-alist ; sort by first rule target
16091 (sort rule-alist
16092 (function (lambda (a b)
16093 (string< (car (cadr a)) (car (cadr b)))))))
16094 ;; open and clear Makefile
16095 (set-buffer (find-file-noselect makefile-path-name t t))
16096 (erase-buffer)
16097 (insert "# -*- Makefile -*-\n"
16098 "### " (file-name-nondirectory makefile-name)
16099 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
16100 "\n")
16101 (if project
16102 (insert "\n# Project : " (nth 0 project))
16103 (insert "\n# Directory : \"" directory "\""))
16104 (insert "\n# Platform : " vhdl-compiler
16105 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
16106 (user-login-name) "\n")
16107 ;; insert compile and option variable settings
16108 (insert "\n\n# Define compilation command and options\n"
16109 "\nCOMPILE = " (nth 0 compiler)
16110 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
16111 "\n")
16112 ;; insert library paths
16113 (setq library-directory
16114 (directory-file-name
16115 (if (file-name-absolute-p library-directory)
16116 library-directory
16117 (file-relative-name
16118 (expand-file-name library-directory directory)
16119 compile-directory))))
16120 (insert "\n\n# Define library paths\n"
16121 "\nLIBRARY-" work-library " = " library-directory "\n")
16122 ;; insert variable definitions for all library unit files
16123 (insert "\n\n# Define library unit files\n")
16124 (setq tmp-list unit-list)
16125 (while unit-list
16126 (insert "\nUNIT-" work-library "-" (caar unit-list)
16127 " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
16128 (setq unit-list (cdr unit-list)))
16129 ;; insert variable definition for list of all library unit files
16130 (insert "\n\n\n# Define list of all library unit files\n"
16131 "\nALL_UNITS =")
16132 (setq unit-list tmp-list)
16133 (while unit-list
16134 (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
16135 (setq unit-list (cdr unit-list)))
16136 (insert "\n")
16137 (setq unit-list tmp-list)
16138 ;; insert `make all' rule
16139 (insert "\n\n\n# Rule for compiling entire design\n"
16140 "\nall :"
16141 " \\\n\t\tlibrary"
16142 " \\\n\t\t$(ALL_UNITS)\n")
16143 ;; insert `make clean' rule
16144 (insert "\n\n# Rule for cleaning entire design\n"
16145 "\nclean : "
16146 "\n\t-rm -f $(ALL_UNITS)\n")
16147 ;; insert `make library' rule
16148 (insert "\n\n# Rule for creating library directory\n"
16149 "\nlibrary :"
16150 " \\\n\t\t$(LIBRARY-" work-library ")\n"
16151 "\n$(LIBRARY-" work-library ") :"
16152 "\n\t"
16153 (vhdl-replace-string
16154 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
16155 (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
16156 "\n")
16157 ;; insert rule for each library unit
16158 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
16159 (while prim-list
16160 (setq second-list (sort (nth 1 (car prim-list)) 'string<))
16161 (setq subcomp-list
16162 (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
16163 (setq unit-key (caar prim-list)
16164 unit-name (or (nth 0 (aget ent-alist unit-key t))
16165 (nth 0 (aget conf-alist unit-key t))
16166 (nth 0 (aget pack-alist unit-key t))))
16167 (insert "\n" unit-key)
16168 (unless (equal unit-key unit-name)
16169 (insert " \\\n" unit-name))
16170 (insert " :"
16171 " \\\n\t\tlibrary"
16172 " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
16173 (while second-list
16174 (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
16175 (setq second-list (cdr second-list)))
16176 (while subcomp-list
16177 (when (assoc (car subcomp-list) unit-list)
16178 (insert " \\\n\t\t" (car subcomp-list)))
16179 (setq subcomp-list (cdr subcomp-list)))
16180 (insert "\n")
16181 (setq prim-list (cdr prim-list)))
16182 ;; insert rule for each library unit file
16183 (insert "\n\n# Rules for compiling single library unit files\n")
16184 (while rule-alist
16185 (setq rule (car rule-alist))
16186 ;; get compiler options for this file
16187 (setq options
16188 (vhdl-get-compile-options project compiler (nth 0 rule) t))
16189 ;; insert rule if file is supposed to be compiled
16190 (setq target-list (nth 1 rule)
16191 depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
16192 ;; insert targets
16193 (setq tmp-list target-list)
16194 (while target-list
16195 (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
16196 (if (cdr target-list) " \\" " :"))
16197 (setq target-list (cdr target-list)))
16198 (setq target-list tmp-list)
16199 ;; insert file name as first dependency
16200 (insert " \\\n\t\t" (nth 0 rule))
16201 ;; insert dependencies (except if also target or unit does not exist)
16202 (while depend-list
16203 (when (and (not (member (car depend-list) target-list))
16204 (assoc (car depend-list) unit-list))
16205 (insert " \\\n\t\t"
16206 "$(UNIT-" work-library "-" (car depend-list) ")"))
16207 (setq depend-list (cdr depend-list)))
16208 ;; insert compile command
16209 (if options
16210 (insert "\n\t$(COMPILE) "
16211 (if (eq options 'default) "$(OPTIONS)" options) " "
16212 (nth 0 rule) "\n")
16213 (setq tmp-list target-list)
16214 (while target-list
16215 (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
16216 (if (cdr target-list) " \\" "\n"))
16217 (setq target-list (cdr target-list)))
16218 (setq target-list tmp-list))
16219 (setq rule-alist (cdr rule-alist)))
16220 (insert "\n\n### " makefile-name " ends here\n")
16221 ;; run Makefile generation hook
16222 (run-hooks 'vhdl-makefile-generation-hook)
16223 (message "Generating makefile \"%s\"...done" makefile-name)
16224 ;; save and close file
16225 (if (file-writable-p makefile-path-name)
16226 (progn (save-buffer)
16227 (kill-buffer (current-buffer))
16228 (set-buffer orig-buffer)
16229 (setq file-name-history
16230 (cons makefile-path-name file-name-history)))
16231 (vhdl-warning-when-idle
16232 (format "File not writable: \"%s\""
16233 (abbreviate-file-name makefile-path-name)))
16234 (switch-to-buffer (current-buffer))))))
16235
5eabfe72
KH
16236
16237;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16238;;; Bug reports
16239;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16240;; (using `reporter.el')
16241
3dcb36b7
JB
16242(defconst vhdl-mode-help-address
16243 "Reto Zimmermann <reto@gnu.org>"
d2ddb974
KH
16244 "Address for VHDL Mode bug reports.")
16245
3dcb36b7
JB
16246(defun vhdl-submit-bug-report ()
16247 "Submit via mail a bug report on VHDL Mode."
16248 (interactive)
16249 ;; load in reporter
16250 (and
16251 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
16252 (let ((reporter-prompt-for-summary-p t))
16253 (reporter-submit-bug-report
16254 vhdl-mode-help-address
16255 (concat "VHDL Mode " vhdl-version)
16256 (list
16257 ;; report all important user options
16258 'vhdl-offsets-alist
16259 'vhdl-comment-only-line-offset
16260 'tab-width
16261 'vhdl-electric-mode
16262 'vhdl-stutter-mode
16263 'vhdl-indent-tabs-mode
16264 'vhdl-project-alist
16265 'vhdl-project
16266 'vhdl-project-file-name
16267 'vhdl-project-auto-load
16268 'vhdl-project-sort
16269 'vhdl-compiler-alist
16270 'vhdl-compiler
16271 'vhdl-compile-use-local-error-regexp
16272 'vhdl-makefile-generation-hook
16273 'vhdl-default-library
16274 'vhdl-standard
16275 'vhdl-basic-offset
16276 'vhdl-upper-case-keywords
16277 'vhdl-upper-case-types
16278 'vhdl-upper-case-attributes
16279 'vhdl-upper-case-enum-values
16280 'vhdl-upper-case-constants
16281 'vhdl-use-direct-instantiation
16282 'vhdl-entity-file-name
16283 'vhdl-architecture-file-name
16284 'vhdl-package-file-name
16285 'vhdl-file-name-case
16286 'vhdl-electric-keywords
16287 'vhdl-optional-labels
16288 'vhdl-insert-empty-lines
16289 'vhdl-argument-list-indent
16290 'vhdl-association-list-with-formals
16291 'vhdl-conditions-in-parenthesis
16292 'vhdl-zero-string
16293 'vhdl-one-string
16294 'vhdl-file-header
16295 'vhdl-file-footer
16296 'vhdl-company-name
16297 'vhdl-copyright-string
16298 'vhdl-platform-spec
16299 'vhdl-date-format
16300 'vhdl-modify-date-prefix-string
16301 'vhdl-modify-date-on-saving
16302 'vhdl-reset-kind
16303 'vhdl-reset-active-high
16304 'vhdl-clock-rising-edge
16305 'vhdl-clock-edge-condition
16306 'vhdl-clock-name
16307 'vhdl-reset-name
16308 'vhdl-model-alist
16309 'vhdl-include-port-comments
16310 'vhdl-include-direction-comments
16311 'vhdl-include-type-comments
16312 'vhdl-include-group-comments
16313 'vhdl-actual-port-name
16314 'vhdl-instance-name
16315 'vhdl-testbench-entity-name
16316 'vhdl-testbench-architecture-name
16317 'vhdl-testbench-configuration-name
16318 'vhdl-testbench-dut-name
16319 'vhdl-testbench-include-header
16320 'vhdl-testbench-declarations
16321 'vhdl-testbench-statements
16322 'vhdl-testbench-initialize-signals
16323 'vhdl-testbench-include-library
16324 'vhdl-testbench-include-configuration
16325 'vhdl-testbench-create-files
16326 'vhdl-compose-create-files
16327 'vhdl-compose-include-header
16328 'vhdl-compose-architecture-name
16329 'vhdl-components-package-name
16330 'vhdl-use-components-package
16331 'vhdl-self-insert-comments
16332 'vhdl-prompt-for-comments
16333 'vhdl-inline-comment-column
16334 'vhdl-end-comment-column
16335 'vhdl-auto-align
16336 'vhdl-align-groups
16337 'vhdl-align-group-separate
16338 'vhdl-align-same-indent
16339 'vhdl-highlight-keywords
16340 'vhdl-highlight-names
16341 'vhdl-highlight-special-words
16342 'vhdl-highlight-forbidden-words
16343 'vhdl-highlight-verilog-keywords
16344 'vhdl-highlight-translate-off
16345 'vhdl-highlight-case-sensitive
16346 'vhdl-special-syntax-alist
16347 'vhdl-forbidden-words
16348 'vhdl-forbidden-syntax
16349 'vhdl-directive-keywords
16350 'vhdl-speedbar-auto-open
16351 'vhdl-speedbar-display-mode
16352 'vhdl-speedbar-scan-limit
16353 'vhdl-speedbar-jump-to-unit
16354 'vhdl-speedbar-update-on-saving
16355 'vhdl-speedbar-save-cache
16356 'vhdl-speedbar-cache-file-name
16357 'vhdl-index-menu
16358 'vhdl-source-file-menu
16359 'vhdl-hideshow-menu
16360 'vhdl-hide-all-init
16361 'vhdl-print-two-column
16362 'vhdl-print-customize-faces
16363 'vhdl-intelligent-tab
16364 'vhdl-indent-syntax-based
16365 'vhdl-word-completion-case-sensitive
16366 'vhdl-word-completion-in-minibuffer
16367 'vhdl-underscore-is-part-of-word
16368 'vhdl-mode-hook)
16369 (function
16370 (lambda ()
16371 (insert
16372 (if vhdl-special-indent-hook
16373 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
16374 "vhdl-special-indent-hook is set to '"
16375 (format "%s" vhdl-special-indent-hook)
16376 ".\nPerhaps this is your problem?\n"
16377 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
16378 "\n"))))
16379 nil
16380 "Hi Reto,"))))
16381
16382
16383;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16384;;; Documentation
16385;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16386
16387(defconst vhdl-doc-release-notes nil
16388 "\
16389Release Notes for VHDL Mode 3.32
16390================================
16391
16392 - New Features
16393 - Enhanced Features
16394 - User Options
16395 - Remarks
16396
16397
16398New Features
16399------------
16400
16401STRUCTURAL COMPOSITION:
16402 - Enables simple structural composition similar to graphical editors.
16403 Simplifies the creation of higher design levels where subcomponents
16404 are simply sticked together:
16405 1. Create a skeleton for a new component
16406 2. Place subcomponents in it directly from the hierarchy browser
16407 3. Automatically connect all subcomponents and create the ports
16408 for the new component (based on names of actual ports)
16409 - Automatic generation of a components package (package containing
16410 component declarations for all entities).
16411 - Find more information in the online documentation (`C-c C-h').
16412
16413PORT TRANSLATION:
16414 - Reverse direction of ports (useful for testbenches).
16415
16416SUBPROGRAM TRANSLATION:
16417 - Copy/paste of subprogram interfaces (similar to port translation).
16418
16419CODE FILLING:
16420 - Condense code using code-sensitive block filling.
16421
16422CODE STATISTICS:
16423 - Calculate number of code lines and statements in a buffer.
16424
16425
16426Enhanced Features
16427-----------------
16428
16429TESTBENCH GENERATION:
16430 - Enhanced templates and user option default values.
16431
16432Emacs 21 compatibility/enhancements:
16433 - `lazy-lock-mode' is not used anymore (built-in `jit-lock-mode' is faster).
16434
16435And many other minor fixes and enhancements.
16436
16437
16438User Options
16439------------
16440
16441`vhdl-project-file-name': (enhanced)
16442 Include user name in project setup file name.
16443`vhdl-speedbar-cache-file-name': (enhanced, changed default)
16444 Include user name in cache file name.
16445`vhdl-default-library': (new)
16446 Default working library if no project is active.
16447`vhdl-architecture-file-name': (new)
16448 Specify how the architecture file name is obtained.
16449`vhdl-package-file-name': (new)
16450 Specify how the package file name is obtained.
16451`vhdl-file-name-case': (new)
16452 Allows to change case when deriving file names.
16453`vhdl-compose-create-files': (new)
16454 Specify whether new files should be created for a new component.
16455`vhdl-compose-include-header': (new)
16456 Specify whether a header is included in a new component's file.
16457`vhdl-compose-architecture-name': (new)
16458 Specify how a new component's architecture name is obtained.
16459`vhdl-components-package-name': (new)
16460 Specify how the name for the components package is obtained.
16461`vhdl-use-components-package': (new)
16462 Specify whether component declarations go in a components package.
16463`vhdl-use-direct-instantiation': (new)
16464 Specify whether to use VHDL'93 direct component instantiation.
16465`vhdl-instance-name': (changed default)
16466 Allows insertion of a running number to generate unique instance names.
16467`vhdl-testbench-entity-header', `vhdl-testbench-architecture-header':(obsolete)
16468 Headers are now automatically derived from the standard header.
16469`vhdl-testbench-include-header': (new)
16470 Specify whether a header is included in testbench files.
16471`vhdl-testbench-declaration', `vhdl-testbench-statements': (changed default)
16472 Non-empty default values for more complete testbench templates.
16473
16474
16475Remarks
16476-------
16477
16478- Changed key binding for `vhdl-comment-uncomment-region': `C-c c'
16479 (`C-c C-c ...' is now used for structural composition).
16480
16481- Automatic buffer highlighting (font-lock) is now controlled by option
16482 `global-font-lock-mode' in GNU Emacs (`font-lock-auto-fontify' in XEmacs).
16483 \(Important: You MUST customize this option in order to turn automatic
16484 buffer highlighting on.)
16485")
16486
16487
16488(defconst vhdl-doc-keywords nil
16489 "\
16490Reserved words in VHDL
16491----------------------
16492
16493VHDL'93 (IEEE Std 1076-1993):
16494 `vhdl-93-keywords' : keywords
16495 `vhdl-93-types' : standardized types
16496 `vhdl-93-attributes' : standardized attributes
16497 `vhdl-93-enum-values' : standardized enumeration values
16498 `vhdl-93-functions' : standardized functions
16499 `vhdl-93-packages' : standardized packages and libraries
16500
16501VHDL-AMS (IEEE Std 1076.1):
16502 `vhdl-ams-keywords' : keywords
16503 `vhdl-ams-types' : standardized types
16504 `vhdl-ams-attributes' : standardized attributes
16505 `vhdl-ams-enum-values' : standardized enumeration values
16506 `vhdl-ams-functions' : standardized functions
16507
16508Math Packages (IEEE Std 1076.2):
16509 `vhdl-math-types' : standardized types
16510 `vhdl-math-constants' : standardized constants
16511 `vhdl-math-functions' : standardized functions
16512 `vhdl-math-packages' : standardized packages
16513
16514Forbidden words:
16515 `vhdl-verilog-keywords' : Verilog reserved words
16516
16517NOTE: click `mouse-2' on variable names above (not in XEmacs).")
16518
16519
16520(defconst vhdl-doc-coding-style nil
16521 "\
16522For VHDL coding style and naming convention guidelines, see the following
16523references:
16524
16525\[1] Ben Cohen.
16526 \"VHDL Coding Styles and Methodologies\".
16527 Kluwer Academic Publishers, 1999.
16528 http://members.aol.com/vhdlcohen/vhdl/
16529
16530\[2] Michael Keating and Pierre Bricaud.
16531 \"Reuse Methodology Manual, Second Edition\".
16532 Kluwer Academic Publishers, 1999.
16533 http://www.openmore.com/openmore/rmm2.html
16534
16535\[3] European Space Agency.
16536 \"VHDL Modelling Guidelines\".
16537 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
16538
16539Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
16540to visually support naming conventions.")
16541
16542
d2ddb974
KH
16543(defun vhdl-version ()
16544 "Echo the current version of VHDL Mode in the minibuffer."
16545 (interactive)
3dcb36b7 16546 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
d2ddb974
KH
16547 (vhdl-keep-region-active))
16548
3dcb36b7
JB
16549(defun vhdl-doc-variable (variable)
16550 "Display VARIABLE's documentation in *Help* buffer."
16551 (interactive)
16552 (with-output-to-temp-buffer "*Help*"
16553 (princ (documentation-property variable 'variable-documentation))
16554 (unless vhdl-xemacs
16555 (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
16556 (save-excursion
16557 (set-buffer standard-output)
16558 (help-mode))
16559 (print-help-return-message)))
d2ddb974 16560
3dcb36b7
JB
16561(defun vhdl-doc-mode ()
16562 "Display VHDL Mode documentation in *Help* buffer."
d2ddb974 16563 (interactive)
3dcb36b7
JB
16564 (with-output-to-temp-buffer "*Help*"
16565 (princ mode-name)
16566 (princ " mode:\n")
16567 (princ (documentation 'vhdl-mode))
16568 (unless vhdl-xemacs
16569 (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
16570 (save-excursion
16571 (set-buffer standard-output)
16572 (help-mode))
16573 (print-help-return-message)))
d2ddb974
KH
16574
16575
5eabfe72 16576;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d2ddb974
KH
16577
16578(provide 'vhdl-mode)
16579
6b61353c 16580;;; arch-tag: 780d7073-9b5d-4c6c-b0d8-26b28783aba3
d2ddb974 16581;;; vhdl-mode.el ends here