1 ;;; vhdl-mode.el --- major mode for editing VHDL code
3 ;; Copyright (C) 1992-2013 Free Software Foundation, Inc.
5 ;; Authors: Reto Zimmermann <reto@gnu.org>
6 ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
7 ;; Maintainer: Reto Zimmermann <reto@gnu.org>
8 ;; Keywords: languages vhdl
9 ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
11 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
12 ;; file on 18/3/2008, and the maintainer agreed that when a bug is
13 ;; filed in the Emacs bug reporting system against this file, a copy
14 ;; of the bug report be sent to the maintainer's email address.
16 (defconst vhdl-version
"3.34.2"
17 "VHDL Mode version number.")
19 (defconst vhdl-time-stamp
"2012-11-21"
20 "VHDL Mode time stamp for last update.")
22 ;; This file is part of GNU Emacs.
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;; This package provides an Emacs major mode for editing VHDL code.
42 ;; It includes the following features:
44 ;; - Syntax highlighting
46 ;; - Template insertion (electrification)
47 ;; - Insertion of file headers
48 ;; - Insertion of user-specified models
49 ;; - Port translation / testbench generation
50 ;; - Structural composition
51 ;; - Configuration generation
52 ;; - Sensitivity list updating
54 ;; - Design hierarchy browser
55 ;; - Source file compilation (syntax analysis)
56 ;; - Makefile generation
58 ;; - Word/keyword completion
60 ;; - Code fixing/alignment/beautification
61 ;; - PostScript printing
62 ;; - VHDL'87/'93 and VHDL-AMS supported
63 ;; - Comprehensive menu
64 ;; - Fully customizable
65 ;; - Works under GNU Emacs (recommended) and XEmacs
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ;; this updated version was only tested on: GNU Emacs 20.4
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 ;; Prerequisites: GNU Emacs 20.X/21.X/22.X/23.X, XEmacs 20.X/21.X.
82 ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
83 ;; or into an arbitrary directory that is added to the load path by the
84 ;; following line in your Emacs start-up file `.emacs':
86 ;; (push (expand-file-name "<directory-name>") load-path)
88 ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
89 ;; directory. Otherwise, byte-compile the source file:
90 ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
91 ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
93 ;; Add the following lines to the `site-start.el' file in the `site-lisp'
94 ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
95 ;; (not required in Emacs 20 and higher):
97 ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
98 ;; (push '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist)
100 ;; More detailed installation instructions are included in the official
101 ;; VHDL Mode distribution.
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106 ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
109 ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
110 ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
112 ;; Many thanks to all the users who sent me bug reports and enhancement
114 ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
115 ;; enhancement suggestions and the fruitful discussions.
116 ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
117 ;; Thanks to Ulf Klaperski for the indentation speedup hint.
119 ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
120 ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
121 ;; giving me the opportunity to develop this code.
122 ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
123 ;; of the Swiss Government.
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 ;; Emacs 21+ handling
130 (defconst vhdl-emacs-21
(and (<= 21 emacs-major-version
) (not (featurep 'xemacs
)))
131 "Non-nil if GNU Emacs 21, 22, ... is used.")
132 ;; Emacs 22+ handling
133 (defconst vhdl-emacs-22
(and (<= 22 emacs-major-version
) (not (featurep 'xemacs
)))
134 "Non-nil if GNU Emacs 22, ... is used.")
136 (defvar compilation-file-regexp-alist
)
141 (defvar itimer-version
)
142 (defvar lazy-lock-defer-contextually
)
143 (defvar lazy-lock-defer-on-scrolling
)
144 (defvar lazy-lock-defer-on-the-fly
)
145 (defvar speedbar-attached-frame
)
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 ;; help function for user options
153 (defun vhdl-custom-set (variable value
&rest functions
)
154 "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
155 (if (fboundp 'custom-set-default
)
156 (custom-set-default variable value
)
157 (set-default variable value
))
159 (when (fboundp (car functions
)) (funcall (car functions
)))
160 (setq functions
(cdr functions
))))
162 (defun vhdl-widget-directory-validate (widget)
163 "Check that the value of WIDGET is a valid directory entry (i.e. ends with
165 (let ((val (widget-value widget
)))
166 (unless (string-match "^\\(\\|.*/\\)$" val
)
167 (widget-put widget
:error
"Invalid directory entry: must end with '/'")
170 ;; help string for user options
171 (defconst vhdl-name-doc-string
"
173 FROM REGEXP is a regular expression matching the original name:
174 \".*\" matches the entire string
175 \"\\(...\\)\" matches a substring
176 TO STRING specifies the string to be inserted as new name:
177 \"\\&\" means substitute entire matched text
178 \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
180 \".*\" \"\\&\" inserts original string
181 \".*\" \"\\&_i\" attaches \"_i\" to original string
182 \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
183 \".*\" \"foo\" inserts constant string \"foo\"
184 \".*\" \"\" inserts empty string")
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ;; User variables (customization options)
190 "Customizations for VHDL Mode."
193 ; :version "21.2" ; comment out for XEmacs
196 (defgroup vhdl-mode nil
197 "Customizations for modes."
200 (defcustom vhdl-indent-tabs-mode nil
201 "Non-nil means indentation can insert tabs.
202 Overrides local variable `indent-tabs-mode'."
207 (defgroup vhdl-compile nil
208 "Customizations for compilation."
211 (defcustom vhdl-compiler-alist
213 ;; 60: docal <= false;
215 ;; [Error] Assignment error: variable is illegal target of signal assignment
216 ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
217 nil
"valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
218 ("^\\s-+\\([0-9]+\\):\\s-+" nil
1 nil
) ("Compiling file \\(.+\\)" 1)
219 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
220 "PACK/\\1.vif" "BODY/\\1.vif" upcase
))
222 ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
223 ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
224 nil
"vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
225 (".* ERROR [^:]+: \".*\" \"\\([^ \\t\\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
227 ;; Cadence Leapfrog: cv -file test.vhd
228 ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
229 ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
230 nil
"mkdir \\1" "./" "work/" "Makefile" "leapfrog"
231 ("duluth: \\*E,[0-9]+ (\\([^ \\t\\n]+\\),\\([0-9]+\\)):" 1 2 nil
) ("" 0)
232 ("\\1/entity" "\\2/\\1" "\\1/configuration"
233 "\\1/package" "\\1/body" downcase
))
234 ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
235 ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
236 ;; (PLL_400X_TOP) is not declared [10.3].
237 ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
238 nil
"mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
239 ("ncvhdl_p: \\*E,\\w+ (\\([^ \\t\\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
240 ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
241 "\\1/package/pc.db" "\\1/body/pc.db" downcase
))
242 ;; ghdl vhdl: ghdl test.vhd
243 ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
244 nil
"mkdir \\1" "./" "work/" "Makefile" "ghdl"
245 ("ghdl_p: \\*E,\\w+ (\\([^ \\t\\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
246 ("\\1/entity" "\\2/\\1" "\\1/configuration"
247 "\\1/package" "\\1/body" downcase
))
249 ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
250 ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
251 nil
"mkdir \\1" "./" "work/" "Makefile" "ibm"
252 ("[0-9]+ COACHDL.*: File: \\([^ \\t\\n]+\\), line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
254 ;; Ikos Voyager: analyze test.vhd
256 ;; E L4/C5: this library unit is inaccessible
257 ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
258 nil
"mkdir \\1" "./" "work/" "Makefile" "ikos"
259 ("E L\\([0-9]+\\)/C\\([0-9]+\\):" nil
1 2)
260 ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
262 ;; ModelSim, Model Technology: vcom test.vhd
263 ;; ERROR: test.vhd(14): Unknown identifier: positiv
264 ;; WARNING[2]: test.vhd(85): Possible infinite loop
265 ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
266 ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
267 ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
268 nil
"vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
269 ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\[[0-9]+\]\\)? \\([^ \\t\\n]+\\)(\\([0-9]+\\)):" 3 4 nil
) ("" 0)
270 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
271 "\\1/_primary.dat" "\\1/body.dat" downcase
))
272 ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
273 ;; test.vhd:34: error message
274 ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
275 nil
"mkdir \\1" "./" "work/" "Makefile" "provhdl"
276 ("\\([^ \\t\\n]+\\):\\([0-9]+\\): " 1 2 nil
) ("" 0)
277 ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
278 "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase
))
280 ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
281 ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
282 ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
283 ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
284 ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
285 ("Quartus" "make" "-work \\1" "make" "-f \\1"
286 nil
"mkdir \\1" "./" "work/" "Makefile" "quartus"
287 ("\\(Error\\|Warning\\): .* \\([^ \\t\\n]+\\)(\\([0-9]+\\))" 2 3 nil
) ("" 0)
289 ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
290 ;; ERROR: test.vhd(24): near "dnd": expecting: END
291 ;; WARNING[4]: test.vhd(30): A space is required between ...
292 ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
293 nil
"mkdir \\1" "./" "work/" "Makefile" "quickhdl"
294 ("\\(ERROR\\|WARNING\\)[^:]*: \\([^ \\t\\n]+\\)(\\([0-9]+\\)):" 2 3 nil
) ("" 0)
295 ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
296 "\\1/_primary.dat" "\\1/body.dat" downcase
))
297 ;; Savant: scram -publish-cc test.vhd
298 ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
299 ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
300 nil
"mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
301 ("\\([^ \\t\\n]+\\):\\([0-9]+\\): " 1 2 nil
) ("" 0)
302 ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
303 "\\1_config.vhdl" "\\1_package.vhdl"
304 "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase
))
305 ;; Simili: vhdlp -work test.vhd
306 ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
307 ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
308 nil
"mkdir \\1" "./" "work/" "Makefile" "simili"
309 ("\\(Error\\|Warning\\): \\w+: \\([^ \\t\\n]+\\): (line \\([0-9]+\\)): " 2 3 nil
) ("" 0)
310 ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
311 "\\1/prim.var" "\\1/_body.var" downcase
))
312 ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
313 ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
314 ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
315 nil
"mkdir \\1" "./" "work/" "Makefile" "speedwave"
316 ("^ *ERROR\[[0-9]+\]::File \\([^ \\t\\n]+\\) Line \\([0-9]+\\):" 1 2 nil
) ("" 0)
318 ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
319 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
320 ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
321 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys"
322 ("\\*\\*Error: vhdlan,[0-9]+ \\([^ \\t\\n]+\\)(\\([0-9]+\\)):" 1 2 nil
) ("" 0)
323 ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase
))
324 ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
325 ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
326 ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
327 nil
"mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
328 ("\\*\\*Error: vhdlan,[0-9]+ \\([^ \\t\\n]+\\)(\\([0-9]+\\)):" 1 2 nil
) ("" 0)
329 ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase
))
331 ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
332 ("Synplify" "n/a" "n/a" "make" "-f \\1"
333 nil
"mkdir \\1" "./" "work/" "Makefile" "synplify"
334 ("@[EWN]:\"\\([^ \\t\\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
336 ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
337 ;; Compiling "test.vhd" line 1...
338 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
339 ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
340 nil
"mkdir \\1" "./" "work/" "Makefile" "vantage"
341 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil
1 nil
)
342 ("^ *Compiling \"\\(.+\\)\" " 1)
344 ;; VeriBest: vc vhdl test.vhd
345 ;; (no file name printed out!)
346 ;; 32: Z <= A and BitA ;
348 ;; [Error] Name BITA is unknown
349 ("VeriBest" "vc" "vhdl" "make" "-f \\1"
350 nil
"mkdir \\1" "./" "work/" "Makefile" "veribest"
351 ("^ +\\([0-9]+\\): +[^ ]" nil
1 nil
) ("" 0)
353 ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
354 ;; Compiling "test.vhd" line 1...
355 ;; **Error: LINE 49 *** No aggregate value is valid in this context.
356 ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
357 nil
"mkdir \\1" "./" "work/" "Makefile" "viewlogic"
358 ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil
1 nil
)
359 ("^ *Compiling \"\\(.+\\)\" " 1)
362 ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
363 ("Xilinx XST" "xflow" "" "make" "-f \\1"
364 nil
"mkdir \\1" "./" "work/" "Makefile" "xilinx"
365 ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \\t\\n]+\\)\" Line \\([0-9]+\\)\." 1 2 nil
) ("" 0)
368 "List of available VHDL compilers and their properties.
369 Each list entry specifies the following items for a compiler:
371 Compiler name : name used in option `vhdl-compiler' to choose compiler
372 Compile command : command used for source file compilation
373 Compile options : compile options (\"\\1\" inserts library name)
374 Make command : command used for compilation using a Makefile
375 Make options : make options (\"\\1\" inserts Makefile name)
376 Generate Makefile: use built-in function or command to generate a Makefile
377 \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
378 Library command : command to create library directory \(\"\\1\" inserts
379 library directory, \"\\2\" inserts library name)
380 Compile directory: where compilation is run and the Makefile is placed
381 Library directory: directory of default library
382 Makefile name : name of Makefile (default is \"Makefile\")
383 ID string : compiler identification string (see `vhdl-project-alist')
385 Regexp : regular expression to match error messages (*)
386 File subexp index: index of subexpression that matches the file name
387 Line subexp index: index of subexpression that matches the line number
388 Column subexp idx: index of subexpression that matches the column number
390 Regexp : regular expression to match a file name message
391 File subexp index: index of subexpression that matches the file name
392 Unit-to-file name mapping: mapping of library unit names to names of files
393 generated by the compiler (used for Makefile generation)
394 To string : string a name is mapped to (\"\\1\" inserts the unit name,
395 \"\\2\" inserts the entity name for architectures)
396 Case adjustment : adjust case of inserted unit names
398 \(*) The regular expression must match the error message starting from the
399 beginning of the line (but not necessarily to the end of the line).
401 Compile options allows insertion of the library name (see `vhdl-project-alist')
402 in order to set the compilers library option (e.g. \"vcom -work my_lib\").
404 For Makefile generation, the built-in function can be used (requires
405 specification of the unit-to-file name mapping). Alternatively, an
406 external command can be specified. Work directory allows specification of
407 an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
408 used for Makefile generation). To use another library name than \"work\",
409 customize `vhdl-project-alist'. The library command is inserted in Makefiles
410 to automatically create the library directory if not existent.
412 Compile options, compile directory, library directory, and Makefile name are
413 overwritten by the project settings if a project is defined (see
414 `vhdl-project-alist'). Directory paths are relative to the source file
417 Some compilers do not include the file name in the error message, but print
418 out a file name message in advance. In this case, set \"File Subexp Index\"
419 under \"Error Message\" to 0 and fill out the \"File Message\" entries.
420 If no file name at all is printed out, set both \"File Message\" entries to 0
421 \(a default file name message will be printed out instead, does not work in
424 A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
425 assigning its name to option `vhdl-compiler'.
427 Please send any missing or erroneous compiler properties to the maintainer for
430 NOTE: Activate new error and file message regexps and reflect the new setting
431 in the choice list of option `vhdl-compiler' by restarting Emacs."
433 (list :tag
"Compiler" :indent
2
434 (string :tag
"Compiler name ")
435 (string :tag
"Compile command ")
436 (string :tag
"Compile options " "-work \\1")
437 (string :tag
"Make command " "make")
438 (string :tag
"Make options " "-f \\1")
439 (choice :tag
"Generate Makefile "
440 (const :tag
"Built-in function" nil
)
441 (string :tag
"Command" "vmake \\2 > \\1"))
442 (string :tag
"Library command " "mkdir \\1")
443 (directory :tag
"Compile directory "
444 :validate vhdl-widget-directory-validate
"./")
445 (directory :tag
"Library directory "
446 :validate vhdl-widget-directory-validate
"work/")
447 (file :tag
"Makefile name " "Makefile")
448 (string :tag
"ID string ")
449 (list :tag
"Error message" :indent
4
450 (regexp :tag
"Regexp ")
451 (choice :tag
"File subexp "
452 (integer :tag
"Index")
453 (const :tag
"No file name" nil
))
454 (integer :tag
"Line subexp index")
455 (choice :tag
"Column subexp "
456 (integer :tag
"Index")
457 (const :tag
"No column number" nil
)))
458 (list :tag
"File message" :indent
4
459 (regexp :tag
"Regexp ")
460 (integer :tag
"File subexp index"))
461 (choice :tag
"Unit-to-file name mapping"
462 :format
"%t: %[Value Menu%] %v\n"
463 (const :tag
"Not defined" nil
)
464 (list :tag
"To string" :indent
4
465 (string :tag
"Entity " "\\1.vhd")
466 (string :tag
"Architecture " "\\2_\\1.vhd")
467 (string :tag
"Configuration " "\\1.vhd")
468 (string :tag
"Package " "\\1.vhd")
469 (string :tag
"Package Body " "\\1_body.vhd")
470 (choice :tag
"Case adjustment "
471 (const :tag
"None" identity
)
472 (const :tag
"Upcase" upcase
)
473 (const :tag
"Downcase" downcase
))))))
474 :set
(lambda (variable value
)
475 (vhdl-custom-set variable value
'vhdl-update-mode-menu
))
477 :group
'vhdl-compile
)
479 (defcustom vhdl-compiler
"GHDL"
480 "Specifies the VHDL compiler to be used for syntax analysis.
481 Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
482 :type
(let ((alist vhdl-compiler-alist
) list
)
484 (push (list 'const
(caar alist
)) list
)
485 (setq alist
(cdr alist
)))
486 (append '(choice) (nreverse list
)))
487 :group
'vhdl-compile
)
489 (defcustom vhdl-compile-use-local-error-regexp t
490 "Non-nil means use buffer-local `compilation-error-regexp-alist'.
491 In this case, only error message regexps for VHDL compilers are active if
492 compilation is started from a VHDL buffer. Otherwise, the error message
493 regexps are appended to the predefined global regexps, and all regexps are
494 active all the time. Note that by doing that, the predefined global regexps
495 might result in erroneous parsing of error messages for some VHDL compilers.
497 NOTE: Activate the new setting by restarting Emacs."
499 :group
'vhdl-compile
)
501 (defcustom vhdl-makefile-default-targets
'("all" "clean" "library")
502 "List of default target names in Makefiles.
503 Automatically generated Makefiles include three default targets to compile
504 the entire design, clean the entire design and to create the design library.
505 This option allows to change the names of these targets to avoid conflicts
506 with other user Makefiles."
507 :type
'(list (string :tag
"Compile entire design")
508 (string :tag
"Clean entire design ")
509 (string :tag
"Create design library"))
511 :group
'vhdl-compile
)
513 (defcustom vhdl-makefile-generation-hook nil
514 "Functions to run at the end of Makefile generation.
515 Allows to insert user specific parts into a Makefile.
519 \(re-search-backward \"^# Rule for compiling entire design\")
520 \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
522 :group
'vhdl-compile
)
524 (defcustom vhdl-default-library
"work"
525 "Name of default library.
526 Is overwritten by project settings if a project is active."
528 :group
'vhdl-compile
)
531 (defgroup vhdl-project nil
532 "Customizations for projects."
535 (defcustom vhdl-project-alist
536 '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
537 "~/example1/" ("src/system/" "src/components/") ""
538 (("ModelSim" "-87 \\2" "-f \\1 top_level" nil
)
539 ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" .
"-optimize \\3") (".*_tb\\.vhd" . nil
))))
540 "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
541 ("Example 2" "Individual source files, multiple compilers in different directories"
542 "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
543 nil
"\\1/" "work" "\\1/work/" "Makefile" "")
544 ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
545 "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
546 nil
"./" "work" "work-\\1/" "Makefile-\\1" "\
547 -------------------------------------------------------------------------------
548 -- This is a multi-line project description
549 -- that can be used as a project dependent part of the file header.
551 "List of projects and their properties.
552 Name : name used in option `vhdl-project' to choose project
553 Title : title of project (single-line string)
554 Default directory: default project directory (absolute path)
555 Sources : a) source files : path + \"/\" + file name
556 b) directory : path + \"/\"
557 c) directory tree: \"-r \" + path + \"/\"
558 Exclude regexp : matches file/directory names to be excluded as sources
559 Compile options : project-specific options for each compiler
560 Compiler name : name of compiler for which these options are valid
561 Compile options: project-specific compiler options
562 (\"\\1\" inserts library name, \"\\2\" default options)
563 Make options: project-specific make options
564 (\"\\1\" inserts Makefile name, \"\\2\" default options)
565 Exceptions : file-specific exceptions
566 File name regexp: matches file names for which exceptions are valid
567 - Options : file-specific compiler options string
568 (\"\\1\" inserts library name, \"\\2\" default options,
569 \"\\3\" project-specific options)
570 - Do not compile: do not compile this file (in Makefile)
571 Compile directory: where compilation is run and the Makefile is placed
572 \(\"\\1\" inserts compiler ID string)
573 Library name : name of library (default is \"work\")
574 Library directory: path to library (\"\\1\" inserts compiler ID string)
575 Makefile name : name of Makefile
576 (\"\\1\" inserts compiler ID string, \"\\2\" library name)
577 Description : description of project (multi-line string)
579 Project title and description are used to insert into the file header (see
580 option `vhdl-file-header').
582 The default directory must have an absolute path (use `M-TAB' for completion).
583 All other paths can be absolute or relative to the default directory. All
584 paths must end with '/'.
586 The design units found in the sources (files and directories) are shown in the
587 hierarchy browser. Path and file name can contain wildcards `*' and `?' as
588 well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
589 Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
590 specified, the default directory is taken as source directory. Otherwise,
591 the default directory is only taken as source directory if there is a sources
592 entry with the empty string or \"./\". Exclude regexp allows to filter out
593 specific file and directory names from the list of sources (e.g. CVS
596 Files are compiled in the compile directory. Makefiles are also placed into
597 the compile directory. Library directory specifies which directory the
598 compiler compiles into (used to generate the Makefile).
600 Since different compile/library directories and Makefiles may exist for
601 different compilers within one project, these paths and names allow the
602 insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
603 Compile options, compile directory, library directory, and Makefile name
604 overwrite the settings of the current compiler.
606 File-specific compiler options (highest priority) overwrite project-specific
607 options which overwrite default options (lowest priority). Lower priority
608 options can be inserted in higher priority options. This allows to reuse
609 default options (e.g. \"-file\") in project- or file-specific options (e.g.
612 NOTE: Reflect the new setting in the choice list of option `vhdl-project'
613 by restarting Emacs."
615 (list :tag
"Project" :indent
2
616 (string :tag
"Name ")
617 (string :tag
"Title ")
618 (directory :tag
"Default directory"
619 :validate vhdl-widget-directory-validate
620 ,(abbreviate-file-name default-directory
))
621 (repeat :tag
"Sources " :indent
4
622 (directory :format
" %v" "./"))
623 (regexp :tag
"Exclude regexp ")
625 :tag
"Compile options " :indent
4
626 (list :tag
"Compiler" :indent
6
627 ,(let ((alist vhdl-compiler-alist
) list
)
629 (push (list 'const
(caar alist
)) list
)
630 (setq alist
(cdr alist
)))
631 (append '(choice :tag
"Compiler name")
633 (string :tag
"Compile options" "\\2")
634 (string :tag
"Make options " "\\2")
636 :tag
"Exceptions " :indent
8
638 (regexp :tag
"File name regexp ")
639 (choice :format
"%[Value Menu%] %v"
640 (string :tag
"Options" "\\3")
641 (const :tag
"Do not compile" nil
))))))
642 (directory :tag
"Compile directory"
643 :validate vhdl-widget-directory-validate
"./")
644 (string :tag
"Library name " "work")
645 (directory :tag
"Library directory"
646 :validate vhdl-widget-directory-validate
"work/")
647 (file :tag
"Makefile name " "Makefile")
648 (string :tag
"Description: (type `C-j' for newline)"
649 :format
"%t\n%v\n")))
650 :set
(lambda (variable value
)
651 (vhdl-custom-set variable value
652 'vhdl-update-mode-menu
653 'vhdl-speedbar-refresh
))
654 :group
'vhdl-project
)
656 (defcustom vhdl-project nil
657 "Specifies the default for the current project.
658 Select a project name from the ones defined in option `vhdl-project-alist'.
659 Is used to determine the project title and description to be inserted in file
660 headers and the source files/directories to be scanned in the hierarchy
661 browser. The current project can also be changed temporarily in the menu."
662 :type
(let ((alist vhdl-project-alist
) list
)
664 (push (list 'const
(caar alist
)) list
)
665 (setq alist
(cdr alist
)))
666 (append '(choice (const :tag
"None" nil
) (const :tag
"--"))
668 :group
'vhdl-project
)
670 (defcustom vhdl-project-file-name
'("\\1.prj")
671 "List of file names/paths for importing/exporting project setups.
672 \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
673 replaced by the user name (allows to have user-specific project setups).
674 The first entry is used as file name to import/export individual project
675 setups. All entries are used to automatically import project setups at
676 startup (see option `vhdl-project-auto-load'). Projects loaded from the
677 first entry are automatically made current. Hint: specify local project
678 setups in first entry, global setups in following entries; loading a local
679 project setup will make it current, while loading the global setups
680 is done without changing the current project.
681 Names can also have an absolute path (i.e. project setups can be stored
682 in global directories)."
683 :type
'(repeat (string :tag
"File name" "\\1.prj"))
684 :group
'vhdl-project
)
686 (defcustom vhdl-project-auto-load
'(startup)
687 "Automatically load project setups from files.
688 All project setup files that match the file names specified in option
689 `vhdl-project-file-name' are automatically loaded. The project of the
690 \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
692 A project setup file can be obtained by exporting a project (see menu).
693 At startup: project setup file is loaded at Emacs startup"
694 :type
'(set (const :tag
"At startup" startup
))
695 :group
'vhdl-project
)
697 (defcustom vhdl-project-sort t
698 "Non-nil means projects are displayed in alphabetical order."
700 :group
'vhdl-project
)
703 (defgroup vhdl-style nil
704 "Customizations for coding styles."
706 :group
'vhdl-template
708 :group
'vhdl-compose
)
710 (defcustom vhdl-standard
'(93 nil
)
711 "VHDL standards used.
713 VHDL'87 : IEEE Std 1076-1987
714 VHDL'93/02 : IEEE Std 1076-1993/2002
715 Additional standards:
716 VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
717 Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
719 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
720 \"Activate Options\"."
721 :type
'(list (choice :tag
"Basic standard"
722 (const :tag
"VHDL'87" 87)
723 (const :tag
"VHDL'93/02" 93))
724 (set :tag
"Additional standards" :indent
2
725 (const :tag
"VHDL-AMS" ams
)
726 (const :tag
"Math packages" math
)))
727 :set
(lambda (variable value
)
728 (vhdl-custom-set variable value
729 'vhdl-template-map-init
730 'vhdl-mode-abbrev-table-init
731 'vhdl-template-construct-alist-init
732 'vhdl-template-package-alist-init
733 'vhdl-update-mode-menu
734 'vhdl-words-init
'vhdl-font-lock-init
))
737 (defcustom vhdl-basic-offset
2
738 "Amount of basic offset used for indentation.
739 This value is used by + and - symbols in `vhdl-offsets-alist'."
743 (defcustom vhdl-upper-case-keywords nil
744 "Non-nil means convert keywords to upper case.
745 This is done when typed or expanded or by the fix case functions."
747 :set
(lambda (variable value
)
748 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
751 (defcustom vhdl-upper-case-types nil
752 "Non-nil means convert standardized types to upper case.
753 This is done when expanded or by the fix case functions."
755 :set
(lambda (variable value
)
756 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
759 (defcustom vhdl-upper-case-attributes nil
760 "Non-nil means convert standardized attributes to upper case.
761 This is done when expanded or by the fix case functions."
763 :set
(lambda (variable value
)
764 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
767 (defcustom vhdl-upper-case-enum-values nil
768 "Non-nil means convert standardized enumeration values to upper case.
769 This is done when expanded or by the fix case functions."
771 :set
(lambda (variable value
)
772 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
775 (defcustom vhdl-upper-case-constants t
776 "Non-nil means convert standardized constants to upper case.
777 This is done when expanded."
779 :set
(lambda (variable value
)
780 (vhdl-custom-set variable value
'vhdl-abbrev-list-init
))
783 (defcustom vhdl-use-direct-instantiation
'standard
784 "Non-nil means use VHDL'93 direct component instantiation.
786 Standard: only in VHDL standards that allow it (VHDL'93 and higher)
788 :type
'(choice (const :tag
"Never" never
)
789 (const :tag
"Standard" standard
)
790 (const :tag
"Always" always
))
793 (defcustom vhdl-array-index-record-field-in-sensitivity-list t
794 "Non-nil means include array indices / record fields in sensitivity list.
795 If a signal read in a process is a record field or pointed to by an array
796 index, the record field or array index is included with the record name in
797 the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
798 Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
803 (defgroup vhdl-naming nil
804 "Customizations for naming conventions."
807 (defcustom vhdl-entity-file-name
'(".*" .
"\\&")
809 "Specifies how the entity file name is obtained.
810 The entity file name can be obtained by modifying the entity name (e.g.
811 attaching or stripping off a substring). The file extension is automatically
812 taken from the file name of the current buffer."
813 vhdl-name-doc-string
)
814 :type
'(cons (regexp :tag
"From regexp")
815 (string :tag
"To string "))
817 :group
'vhdl-compose
)
819 (defcustom vhdl-architecture-file-name
'("\\(.*\\) \\(.*\\)" .
"\\1_\\2")
821 "Specifies how the architecture file name is obtained.
822 The architecture file name can be obtained by modifying the entity
823 and/or architecture name (e.g. attaching or stripping off a substring). The
824 file extension is automatically taken from the file name of the current
825 buffer. The string that is matched against the regexp is the concatenation
826 of the entity and the architecture name separated by a space. This gives
827 access to both names (see default setting as example)."
828 vhdl-name-doc-string
)
829 :type
'(cons (regexp :tag
"From regexp")
830 (string :tag
"To string "))
832 :group
'vhdl-compose
)
834 (defcustom vhdl-configuration-file-name
'(".*" .
"\\&")
836 "Specifies how the configuration file name is obtained.
837 The configuration file name can be obtained by modifying the configuration
838 name (e.g. attaching or stripping off a substring). The file extension is
839 automatically taken from the file name of the current buffer."
840 vhdl-name-doc-string
)
841 :type
'(cons (regexp :tag
"From regexp")
842 (string :tag
"To string "))
844 :group
'vhdl-compose
)
846 (defcustom vhdl-package-file-name
'(".*" .
"\\&")
848 "Specifies how the package file name is obtained.
849 The package file name can be obtained by modifying the package name (e.g.
850 attaching or stripping off a substring). The file extension is automatically
851 taken from the file name of the current buffer. Package files can be created
852 in a different directory by prepending a relative or absolute path to the
854 vhdl-name-doc-string
)
855 :type
'(cons (regexp :tag
"From regexp")
856 (string :tag
"To string "))
858 :group
'vhdl-compose
)
860 (defcustom vhdl-file-name-case
'identity
861 "Specifies how to change case for obtaining file names.
862 When deriving a file name from a VHDL unit name, case can be changed as
864 As Is: case is not changed (taken as is)
865 Lower Case: whole name is changed to lower case
866 Upper Case: whole name is changed to upper case
867 Capitalize: first letter of each word in name is capitalized"
868 :type
'(choice (const :tag
"As Is" identity
)
869 (const :tag
"Lower Case" downcase
)
870 (const :tag
"Upper Case" upcase
)
871 (const :tag
"Capitalize" capitalize
))
873 :group
'vhdl-compose
)
876 (defgroup vhdl-template nil
877 "Customizations for electrification."
880 (defcustom vhdl-electric-keywords
'(vhdl user
)
881 "Type of keywords for which electrification is enabled.
882 VHDL keywords: invoke built-in templates
883 User keywords: invoke user models (see option `vhdl-model-alist')"
884 :type
'(set (const :tag
"VHDL keywords" vhdl
)
885 (const :tag
"User model keywords" user
))
886 :set
(lambda (variable value
)
887 (vhdl-custom-set variable value
'vhdl-mode-abbrev-table-init
))
888 :group
'vhdl-template
)
890 (defcustom vhdl-optional-labels
'process
891 "Constructs for which labels are to be queried.
892 Template generators prompt for optional labels for:
894 Processes only: processes only (also procedurals in VHDL-AMS)
895 All constructs: all constructs with optional labels and keyword END"
896 :type
'(choice (const :tag
"None" none
)
897 (const :tag
"Processes only" process
)
898 (const :tag
"All constructs" all
))
899 :group
'vhdl-template
)
901 (defcustom vhdl-insert-empty-lines
'unit
902 "Specifies whether to insert empty lines in some templates.
903 This improves readability of code. Empty lines are inserted in:
905 Design units only: entities, architectures, configurations, packages only
906 All constructs : also all constructs with BEGIN...END parts
908 Replaces option `vhdl-additional-empty-lines'."
909 :type
'(choice (const :tag
"None" none
)
910 (const :tag
"Design units only" unit
)
911 (const :tag
"All constructs" all
))
912 :group
'vhdl-template
914 :group
'vhdl-compose
)
916 (defcustom vhdl-argument-list-indent nil
917 "Non-nil means indent argument lists relative to opening parenthesis.
918 That is, argument, association, and port lists start on the same line as the
919 opening parenthesis and subsequent lines are indented accordingly.
920 Otherwise, lists start on a new line and are indented as normal code."
922 :group
'vhdl-template
924 :group
'vhdl-compose
)
926 (defcustom vhdl-association-list-with-formals t
927 "Non-nil means write association lists with formal parameters.
928 Templates prompt for formal and actual parameters (ports/generics).
929 When pasting component instantiations, formals are included.
930 If nil, only a list of actual parameters is entered."
932 :group
'vhdl-template
934 :group
'vhdl-compose
)
936 (defcustom vhdl-conditions-in-parenthesis nil
937 "Non-nil means place parenthesis around condition expressions."
939 :group
'vhdl-template
)
941 (defcustom vhdl-zero-string
"'0'"
942 "String to use for a logic zero."
944 :group
'vhdl-template
)
946 (defcustom vhdl-one-string
"'1'"
947 "String to use for a logic one."
949 :group
'vhdl-template
)
952 (defgroup vhdl-header nil
953 "Customizations for file header."
954 :group
'vhdl-template
955 :group
'vhdl-compose
)
957 (defcustom vhdl-file-header
"\
958 -------------------------------------------------------------------------------
959 -- Title : <title string>
960 -- Project : <project>
961 -------------------------------------------------------------------------------
964 -- Company : <company>
966 -- Last update: <date>
967 -- Platform : <platform>
968 -- Standard : <standard>
969 <projectdesc>-------------------------------------------------------------------------------
970 -- Description: <cursor>
971 <copyright>-------------------------------------------------------------------------------
973 -- Date Version Author Description
974 -- <date> 1.0 <login>\tCreated
975 -------------------------------------------------------------------------------
978 "String or file to insert as file header.
979 If the string specifies an existing file name, the contents of the file is
980 inserted, otherwise the string itself is inserted as file header.
981 Type `C-j' for newlines.
982 If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
983 if the header needs to be version controlled.
985 The following keywords for template generation are supported:
986 <filename> : replaced by the name of the buffer
987 <author> : replaced by the user name and email address
988 \(`user-full-name',`mail-host-address', `user-mail-address')
989 <authorfull> : replaced by the user full name (`user-full-name')
990 <login> : replaced by user login name (`user-login-name')
991 <company> : replaced by contents of option `vhdl-company-name'
992 <date> : replaced by the current date
993 <year> : replaced by the current year
994 <project> : replaced by title of current project (`vhdl-project')
995 <projectdesc> : replaced by description of current project (`vhdl-project')
996 <copyright> : replaced by copyright string (`vhdl-copyright-string')
997 <platform> : replaced by contents of option `vhdl-platform-spec'
998 <standard> : replaced by the VHDL language standard(s) used
999 <... string> : replaced by a queried string (\"...\" is the prompt word)
1000 <title string>: replaced by file title in automatically generated files
1001 <cursor> : final cursor position
1003 The (multi-line) project description <projectdesc> can be used as a project
1004 dependent part of the file header and can also contain the above keywords."
1006 :group
'vhdl-header
)
1008 (defcustom vhdl-file-footer
""
1009 "String or file to insert as file footer.
1010 If the string specifies an existing file name, the contents of the file is
1011 inserted, otherwise the string itself is inserted as file footer (i.e. at
1012 the end of the file).
1013 Type `C-j' for newlines.
1014 The same keywords as in option `vhdl-file-header' can be used."
1016 :group
'vhdl-header
)
1018 (defcustom vhdl-company-name
""
1019 "Name of company to insert in file header.
1020 See option `vhdl-file-header'."
1022 :group
'vhdl-header
)
1024 (defcustom vhdl-copyright-string
"\
1025 -------------------------------------------------------------------------------
1026 -- Copyright (c) <year> <company>
1028 "Copyright string to insert in file header.
1029 Can be multi-line string (type `C-j' for newline) and contain other file
1030 header keywords (see option `vhdl-file-header')."
1032 :group
'vhdl-header
)
1034 (defcustom vhdl-platform-spec
""
1035 "Specification of VHDL platform to insert in file header.
1036 The platform specification should contain names and versions of the
1037 simulation and synthesis tools used.
1038 See option `vhdl-file-header'."
1040 :group
'vhdl-header
)
1042 (defcustom vhdl-date-format
"%Y-%m-%d"
1043 "Specifies the date format to use in the header.
1044 This string is passed as argument to the command `format-time-string'.
1045 For more information on format strings, see the documentation for the
1046 `format-time-string' command (C-h f `format-time-string')."
1048 :group
'vhdl-header
)
1050 (defcustom vhdl-modify-date-prefix-string
"-- Last update: "
1051 "Prefix string of modification date in VHDL file header.
1052 If actualization of the modification date is called (menu,
1053 `\\[vhdl-template-modify]'), this string is searched and the rest
1054 of the line replaced by the current date."
1056 :group
'vhdl-header
)
1058 (defcustom vhdl-modify-date-on-saving t
1059 "Non-nil means update the modification date when the buffer is saved.
1060 Calls function `\\[vhdl-template-modify]').
1062 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1063 \"Activate Options\"."
1065 :group
'vhdl-header
)
1068 (defgroup vhdl-sequential-process nil
1069 "Customizations for sequential processes."
1070 :group
'vhdl-template
)
1072 (defcustom vhdl-reset-kind
'async
1073 "Specifies which kind of reset to use in sequential processes."
1074 :type
'(choice (const :tag
"None" none
)
1075 (const :tag
"Synchronous" sync
)
1076 (const :tag
"Asynchronous" async
)
1077 (const :tag
"Query" query
))
1078 :group
'vhdl-sequential-process
)
1080 (defcustom vhdl-reset-active-high nil
1081 "Non-nil means reset in sequential processes is active high.
1082 Otherwise, reset is active low."
1084 :group
'vhdl-sequential-process
)
1086 (defcustom vhdl-clock-rising-edge t
1087 "Non-nil means rising edge of clock triggers sequential processes.
1088 Otherwise, falling edge triggers."
1090 :group
'vhdl-sequential-process
)
1092 (defcustom vhdl-clock-edge-condition
'standard
1093 "Syntax of the clock edge condition.
1094 Standard: \"clk'event and clk = '1'\"
1095 Function: \"rising_edge(clk)\""
1096 :type
'(choice (const :tag
"Standard" standard
)
1097 (const :tag
"Function" function
))
1098 :group
'vhdl-sequential-process
)
1100 (defcustom vhdl-clock-name
""
1101 "Name of clock signal to use in templates."
1103 :group
'vhdl-sequential-process
)
1105 (defcustom vhdl-reset-name
""
1106 "Name of reset signal to use in templates."
1108 :group
'vhdl-sequential-process
)
1111 (defgroup vhdl-model nil
1112 "Customizations for user models."
1115 (defcustom vhdl-model-alist
1117 "<label> : process (<clock>, <reset>)
1118 begin -- process <label>
1119 if <reset> = '0' then -- asynchronous reset (active low)
1121 elsif <clock>'event and <clock> = '1' then -- rising clock edge
1122 if <enable> = '1' then -- synchronous load
1126 end process <label>;"
1128 "List of user models.
1129 VHDL models (templates) can be specified by the user in this list. They can be
1130 invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
1131 electrification (i.e. overriding existing or creating new keywords, see
1132 option `vhdl-electric-keywords').
1133 Name : name of model (string of words and spaces)
1134 String : string or name of file to be inserted as model (newline: `C-j')
1135 Key Binding: key binding to invoke model, added to prefix `C-c C-m'
1136 (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
1137 Keyword : keyword to invoke model
1139 The models can contain prompts to be queried. A prompt is of the form \"<...>\".
1140 A prompt that appears several times is queried once and replaced throughout
1141 the model. Special prompts are:
1142 <clock> : name specified in `vhdl-clock-name' (if not empty)
1143 <reset> : name specified in `vhdl-reset-name' (if not empty)
1144 <cursor>: final cursor position
1145 File header prompts (see variable `vhdl-file-header') are automatically
1146 replaced, so that user models can also be used to insert different types of
1149 If the string specifies an existing file name, the contents of the file is
1150 inserted, otherwise the string itself is inserted.
1151 The code within the models should be correctly indented.
1152 Type `C-j' for newlines.
1154 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1155 \"Activate Options\"."
1156 :type
'(repeat (list :tag
"Model" :indent
2
1157 (string :tag
"Name ")
1158 (string :tag
"String : (type `C-j' for newline)"
1160 (sexp :tag
"Key binding" x
)
1161 (string :tag
"Keyword " :format
"%t: %v\n")))
1162 :set
(lambda (variable value
)
1163 (vhdl-custom-set variable value
1164 'vhdl-model-map-init
1166 'vhdl-mode-abbrev-table-init
1167 'vhdl-update-mode-menu
))
1171 (defgroup vhdl-compose nil
1172 "Customizations for structural composition."
1175 (defcustom vhdl-compose-architecture-name
'(".*" .
"str")
1177 "Specifies how the component architecture name is obtained.
1178 The component architecture name can be obtained by modifying the entity name
1179 \(e.g. attaching or stripping off a substring).
1180 If TO STRING is empty, the architecture name is queried."
1181 vhdl-name-doc-string
)
1182 :type
'(cons (regexp :tag
"From regexp")
1183 (string :tag
"To string "))
1184 :group
'vhdl-compose
)
1186 (defcustom vhdl-compose-configuration-name
1187 '("\\(.*\\) \\(.*\\)" .
"\\1_\\2_cfg")
1189 "Specifies how the configuration name is obtained.
1190 The configuration name can be obtained by modifying the entity and/or
1191 architecture name (e.g. attaching or stripping off a substring). The string
1192 that is matched against the regexp is the concatenation of the entity and the
1193 architecture name separated by a space. This gives access to both names (see
1194 default setting as example)."
1195 vhdl-name-doc-string
)
1196 :type
'(cons (regexp :tag
"From regexp")
1197 (string :tag
"To string "))
1198 :group
'vhdl-compose
)
1200 (defcustom vhdl-components-package-name
1201 '((".*" .
"\\&_components") .
"components")
1203 "Specifies how the name for the components package is obtained.
1204 The components package is a package containing all component declarations for
1205 the current design. Its name can be obtained by modifying the project name
1206 \(e.g. attaching or stripping off a substring). If no project is defined, the
1207 DIRECTORY entry is chosen."
1208 vhdl-name-doc-string
)
1209 :type
'(cons (cons :tag
"Project" :indent
2
1210 (regexp :tag
"From regexp")
1211 (string :tag
"To string "))
1212 (string :tag
"Directory:\n String "))
1213 :group
'vhdl-compose
)
1215 (defcustom vhdl-use-components-package nil
1216 "Non-nil means use a separate components package for component declarations.
1217 Otherwise, component declarations are inserted and searched for in the
1218 architecture declarative parts."
1220 :group
'vhdl-compose
)
1222 (defcustom vhdl-compose-include-header t
1223 "Non-nil means include a header in automatically generated files."
1225 :group
'vhdl-compose
)
1227 (defcustom vhdl-compose-create-files
'single
1228 "Specifies whether new files should be created for the new component.
1229 The component's entity and architecture are inserted:
1230 None : in current buffer
1231 Single file : in new single file
1232 Separate files: in two separate files
1233 The file names are obtained from variables `vhdl-entity-file-name' and
1234 `vhdl-architecture-file-name'."
1235 :type
'(choice (const :tag
"None" none
)
1236 (const :tag
"Single file" single
)
1237 (const :tag
"Separate files" separate
))
1238 :group
'vhdl-compose
)
1240 (defcustom vhdl-compose-configuration-create-file nil
1241 "Specifies whether a new file should be created for the configuration.
1242 If non-nil, a new file is created for the configuration.
1243 The file name is obtained from variable `vhdl-configuration-file-name'."
1245 :group
'vhdl-compose
)
1247 (defcustom vhdl-compose-configuration-hierarchical t
1248 "Specifies whether hierarchical configurations should be created.
1249 If non-nil, automatically created configurations are hierarchical and include
1250 the whole hierarchy of subcomponents. Otherwise the configuration only
1251 includes one level of subcomponents."
1253 :group
'vhdl-compose
)
1255 (defcustom vhdl-compose-configuration-use-subconfiguration t
1256 "Specifies whether subconfigurations should be used inside configurations.
1257 If non-nil, automatically created configurations use configurations in binding
1258 indications for subcomponents, if such configurations exist. Otherwise,
1259 entities are used in binding indications for subcomponents."
1261 :group
'vhdl-compose
)
1264 (defgroup vhdl-port nil
1265 "Customizations for port translation functions."
1267 :group
'vhdl-compose
)
1269 (defcustom vhdl-include-port-comments nil
1270 "Non-nil means include port comments when a port is pasted."
1274 (defcustom vhdl-include-direction-comments nil
1275 "Non-nil means include port direction in instantiations as comments."
1279 (defcustom vhdl-include-type-comments nil
1280 "Non-nil means include generic/port type in instantiations as comments."
1284 (defcustom vhdl-include-group-comments
'never
1285 "Specifies whether to include group comments and spacings.
1286 The comments and empty lines between groups of ports are pasted:
1288 Declarations: in entity/component/constant/signal declarations only
1289 Always : also in generic/port maps"
1290 :type
'(choice (const :tag
"Never" never
)
1291 (const :tag
"Declarations" decl
)
1292 (const :tag
"Always" always
))
1295 (defcustom vhdl-actual-generic-name
'(".*" .
"\\&")
1297 "Specifies how actual generic names are obtained from formal generic names.
1298 In a component instantiation, an actual generic name can be
1299 obtained by modifying the formal generic name (e.g. attaching or stripping
1301 vhdl-name-doc-string
)
1302 :type
'(cons (regexp :tag
"From regexp")
1303 (string :tag
"To string "))
1307 (defcustom vhdl-actual-port-name
'(".*" .
"\\&")
1309 "Specifies how actual port names are obtained from formal port names.
1310 In a component instantiation, an actual port name can be obtained by
1311 modifying the formal port name (e.g. attaching or stripping off a substring)."
1312 vhdl-name-doc-string
)
1313 :type
'(cons (regexp :tag
"From regexp")
1314 (string :tag
"To string "))
1317 (defcustom vhdl-instance-name
'(".*" .
"\\&_%d")
1319 "Specifies how an instance name is obtained.
1320 The instance name can be obtained by modifying the name of the component to be
1321 instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
1322 by a unique number (starting with 1).
1323 If TO STRING is empty, the instance name is queried."
1324 vhdl-name-doc-string
)
1325 :type
'(cons (regexp :tag
"From regexp")
1326 (string :tag
"To string "))
1330 (defgroup vhdl-testbench nil
1331 "Customizations for testbench generation."
1334 (defcustom vhdl-testbench-entity-name
'(".*" .
"\\&_tb")
1336 "Specifies how the testbench entity name is obtained.
1337 The entity name of a testbench can be obtained by modifying the name of
1338 the component to be tested (e.g. attaching or stripping off a substring)."
1339 vhdl-name-doc-string
)
1340 :type
'(cons (regexp :tag
"From regexp")
1341 (string :tag
"To string "))
1342 :group
'vhdl-testbench
)
1344 (defcustom vhdl-testbench-architecture-name
'(".*" .
"")
1346 "Specifies how the testbench architecture name is obtained.
1347 The testbench architecture name can be obtained by modifying the name of
1348 the component to be tested (e.g. attaching or stripping off a substring).
1349 If TO STRING is empty, the architecture name is queried."
1350 vhdl-name-doc-string
)
1351 :type
'(cons (regexp :tag
"From regexp")
1352 (string :tag
"To string "))
1353 :group
'vhdl-testbench
)
1355 (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
1357 "Specifies how the testbench configuration name is obtained.
1358 The configuration name of a testbench can be obtained by modifying the entity
1359 and/or architecture name (e.g. attaching or stripping off a substring). The
1360 string that is matched against the regexp is the concatenation of the entity
1361 and the architecture name separated by a space. This gives access to both
1362 names (see default setting as example)."
1363 vhdl-name-doc-string
)
1364 :type
'(cons (regexp :tag
"From regexp")
1365 (string :tag
"To string "))
1366 :group
'vhdl-testbench
)
1368 (defcustom vhdl-testbench-dut-name
'(".*" .
"DUT")
1370 "Specifies how a DUT instance name is obtained.
1371 The design-under-test instance name (i.e. the component instantiated in the
1372 testbench) can be obtained by modifying the component name (e.g. attaching
1373 or stripping off a substring)."
1374 vhdl-name-doc-string
)
1375 :type
'(cons (regexp :tag
"From regexp")
1376 (string :tag
"To string "))
1377 :group
'vhdl-testbench
)
1379 (defcustom vhdl-testbench-include-header t
1380 "Non-nil means include a header in automatically generated files."
1382 :group
'vhdl-testbench
)
1384 (defcustom vhdl-testbench-declarations
"\
1386 signal Clk : std_logic := '1';
1388 "String or file to be inserted in the testbench declarative part.
1389 If the string specifies an existing file name, the contents of the file is
1390 inserted, otherwise the string itself is inserted in the testbench
1391 architecture before the BEGIN keyword.
1392 Type `C-j' for newlines."
1394 :group
'vhdl-testbench
)
1396 (defcustom vhdl-testbench-statements
"\
1398 Clk <= not Clk after 10 ns;
1400 -- waveform generation
1401 WaveGen_Proc: process
1403 -- insert signal assignments here
1405 wait until Clk = '1';
1406 end process WaveGen_Proc;
1408 "String or file to be inserted in the testbench statement part.
1409 If the string specifies an existing file name, the contents of the file is
1410 inserted, otherwise the string itself is inserted in the testbench
1411 architecture before the END keyword.
1412 Type `C-j' for newlines."
1414 :group
'vhdl-testbench
)
1416 (defcustom vhdl-testbench-initialize-signals nil
1417 "Non-nil means initialize signals with `0' when declared in testbench."
1419 :group
'vhdl-testbench
)
1421 (defcustom vhdl-testbench-include-library t
1422 "Non-nil means a library/use clause for std_logic_1164 is included."
1424 :group
'vhdl-testbench
)
1426 (defcustom vhdl-testbench-include-configuration t
1427 "Non-nil means a testbench configuration is attached at the end."
1429 :group
'vhdl-testbench
)
1431 (defcustom vhdl-testbench-create-files
'single
1432 "Specifies whether new files should be created for the testbench.
1433 testbench entity and architecture are inserted:
1434 None : in current buffer
1435 Single file : in new single file
1436 Separate files: in two separate files
1437 The file names are obtained from variables `vhdl-testbench-entity-file-name'
1438 and `vhdl-testbench-architecture-file-name'."
1439 :type
'(choice (const :tag
"None" none
)
1440 (const :tag
"Single file" single
)
1441 (const :tag
"Separate files" separate
))
1442 :group
'vhdl-testbench
)
1444 (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
1446 "Specifies how the testbench entity file name is obtained.
1447 The entity file name can be obtained by modifying the testbench entity name
1448 \(e.g. attaching or stripping off a substring). The file extension is
1449 automatically taken from the file name of the current buffer. Testbench
1450 files can be created in a different directory by prepending a relative or
1451 absolute path to the file name."
1452 vhdl-name-doc-string
)
1453 :type
'(cons (regexp :tag
"From regexp")
1454 (string :tag
"To string "))
1455 :group
'vhdl-testbench
)
1457 (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
1459 "Specifies how the testbench architecture file name is obtained.
1460 The architecture file name can be obtained by modifying the testbench entity
1461 and/or architecture name (e.g. attaching or stripping off a substring). The
1462 string that is matched against the regexp is the concatenation of the entity
1463 and the architecture name separated by a space. This gives access to both
1464 names (see default setting as example). Testbench files can be created in
1465 a different directory by prepending a relative or absolute path to the file
1467 vhdl-name-doc-string
)
1468 :type
'(cons (regexp :tag
"From regexp")
1469 (string :tag
"To string "))
1470 :group
'vhdl-testbench
)
1473 (defgroup vhdl-comment nil
1474 "Customizations for comments."
1477 (defcustom vhdl-self-insert-comments t
1478 "Non-nil means various templates automatically insert help comments."
1480 :group
'vhdl-comment
)
1482 (defcustom vhdl-prompt-for-comments t
1483 "Non-nil means various templates prompt for user definable comments."
1485 :group
'vhdl-comment
)
1487 (defcustom vhdl-inline-comment-column
40
1488 "Column to indent and align inline comments to.
1489 Overrides local option `comment-column'.
1491 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1492 \"Activate Options\"."
1494 :group
'vhdl-comment
)
1496 (defcustom vhdl-end-comment-column
79
1497 "End of comment column.
1498 Comments that exceed this column number are wrapped.
1500 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1501 \"Activate Options\"."
1503 :group
'vhdl-comment
)
1505 (defvar end-comment-column
)
1508 (defgroup vhdl-beautify nil
1509 "Customizations for beautification."
1512 (defcustom vhdl-auto-align t
1513 "Non-nil means align some templates automatically after generation."
1515 :group
'vhdl-beautify
)
1517 (defcustom vhdl-align-groups t
1518 "Non-nil means align groups of code lines separately.
1519 A group of code lines is a region of consecutive lines between two lines that
1520 match the regexp in option `vhdl-align-group-separate'."
1522 :group
'vhdl-beautify
)
1524 (defcustom vhdl-align-group-separate
"^\\s-*$"
1525 "Regexp for matching a line that separates groups of lines for alignment.
1527 \"^\\s-*$\": matches an empty line
1528 \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
1530 :group
'vhdl-beautify
)
1532 (defcustom vhdl-align-same-indent t
1533 "Non-nil means align blocks with same indent separately.
1534 When a region or the entire buffer is aligned, the code is divided into
1535 blocks of same indent which are aligned separately (except for argument/port
1536 lists). This gives nicer alignment in most cases.
1537 Option `vhdl-align-groups' still applies within these blocks."
1539 :group
'vhdl-beautify
)
1541 (defcustom vhdl-beautify-options
'(t t t t t
)
1542 "List of options for beautifying code. Allows to disable individual
1543 features of code beautification."
1544 :type
'(list (boolean :tag
"Whitespace cleanup ")
1545 (boolean :tag
"Single statement per line")
1546 (boolean :tag
"Indentation ")
1547 (boolean :tag
"Alignment ")
1548 (boolean :tag
"Case fixing "))
1549 :group
'vhdl-beautify
1553 (defgroup vhdl-highlight nil
1554 "Customizations for highlighting."
1557 (defcustom vhdl-highlight-keywords t
1558 "Non-nil means highlight VHDL keywords and other standardized words.
1559 The following faces are used:
1560 `font-lock-keyword-face' : keywords
1561 `font-lock-type-face' : standardized types
1562 `vhdl-font-lock-attribute-face': standardized attributes
1563 `vhdl-font-lock-enumvalue-face': standardized enumeration values
1564 `vhdl-font-lock-function-face' : standardized function and package names
1566 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1567 entry \"Fontify Buffer\")."
1569 :set
(lambda (variable value
)
1570 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1571 :group
'vhdl-highlight
)
1573 (defcustom vhdl-highlight-names t
1574 "Non-nil means highlight declaration names and construct labels.
1575 The following faces are used:
1576 `font-lock-function-name-face' : names in declarations of units,
1577 subprograms, components, as well as labels of VHDL constructs
1578 `font-lock-type-face' : names in type/nature declarations
1579 `vhdl-font-lock-attribute-face': names in attribute declarations
1580 `font-lock-variable-name-face' : names in declarations of signals,
1581 variables, constants, subprogram parameters, generics, and ports
1583 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1584 entry \"Fontify Buffer\")."
1586 :set
(lambda (variable value
)
1587 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1588 :group
'vhdl-highlight
)
1590 (defcustom vhdl-highlight-special-words nil
1591 "Non-nil means highlight words with special syntax.
1592 The words with syntax and color specified in option `vhdl-special-syntax-alist'
1593 are highlighted accordingly.
1594 Can be used for visual support of naming conventions.
1596 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1597 entry \"Fontify Buffer\")."
1599 :set
(lambda (variable value
)
1600 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1601 :group
'vhdl-highlight
)
1603 (defcustom vhdl-highlight-forbidden-words nil
1604 "Non-nil means highlight forbidden words.
1605 The reserved words specified in option `vhdl-forbidden-words' or having the
1606 syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
1607 warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
1610 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1611 entry \"Fontify Buffer\")."
1613 :set
(lambda (variable value
)
1614 (vhdl-custom-set variable value
1615 'vhdl-words-init
'vhdl-font-lock-init
))
1616 :group
'vhdl-highlight
)
1618 (defcustom vhdl-highlight-verilog-keywords nil
1619 "Non-nil means highlight Verilog keywords as reserved words.
1620 Verilog keywords are highlighted in a warning color (face
1621 `vhdl-font-lock-reserved-words-face') to indicate not to use them.
1623 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1624 entry \"Fontify Buffer\")."
1626 :set
(lambda (variable value
)
1627 (vhdl-custom-set variable value
1628 'vhdl-words-init
'vhdl-font-lock-init
))
1629 :group
'vhdl-highlight
)
1631 (defcustom vhdl-highlight-translate-off nil
1632 "Non-nil means background-highlight code excluded from translation.
1633 That is, all code between \"-- pragma translate_off\" and
1634 \"-- pragma translate_on\" is highlighted using a different background color
1635 \(face `vhdl-font-lock-translate-off-face').
1636 Note: this might slow down on-the-fly fontification (and thus editing).
1638 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1639 entry \"Fontify Buffer\")."
1641 :set
(lambda (variable value
)
1642 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1643 :group
'vhdl-highlight
)
1645 (defcustom vhdl-highlight-case-sensitive nil
1646 "Non-nil means consider case for highlighting.
1648 non-nil also upper-case VHDL words are highlighted, but case of words with
1649 special syntax is not considered
1650 nil only lower-case VHDL words are highlighted, but case of words with
1651 special syntax is considered
1652 Overrides local option `font-lock-keywords-case-fold-search'.
1654 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1655 entry \"Fontify Buffer\")."
1657 :group
'vhdl-highlight
)
1659 (defcustom vhdl-special-syntax-alist
1660 '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil
)
1661 ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil
)
1662 ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil
))
1663 "List of special syntax to be highlighted.
1664 If option `vhdl-highlight-special-words' is non-nil, words with the specified
1665 syntax (as regular expression) are highlighted in the corresponding color.
1667 Name : string of words and spaces
1668 Regexp : regular expression describing word syntax
1669 (e.g. \"\\\\=\<\\\w+_c\\\\=\>\" matches word with suffix \"_c\")
1670 expression must start with \"\\\\=\<\" and end with \"\\\\=\>\"
1671 if only whole words should be matched (no substrings)
1672 Color (light): foreground color for light background
1673 (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
1674 LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
1675 Color (dark) : foreground color for dark background
1676 (matching color examples: BurlyWood1, Grey80, Green, Coral,
1677 AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
1678 In comments : If non-nil, words are also highlighted inside comments
1680 Can be used for visual support of naming conventions, such as highlighting
1681 different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
1682 \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
1683 common substrings or name suffices.
1684 For each entry, a new face is generated with the specified colors and name
1685 \"vhdl-font-lock-\" + name + \"-face\".
1687 NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
1688 entry \"Fontify Buffer\"). All other changes require restarting Emacs."
1689 :type
'(repeat (list :tag
"Face" :indent
2
1690 (string :tag
"Name ")
1691 (regexp :tag
"Regexp " "\\w+_")
1692 (string :tag
"Color (light)")
1693 (string :tag
"Color (dark) ")
1694 (boolean :tag
"In comments ")))
1695 :set
(lambda (variable value
)
1696 (vhdl-custom-set variable value
'vhdl-font-lock-init
))
1697 :group
'vhdl-highlight
)
1699 (defcustom vhdl-forbidden-words
'()
1700 "List of forbidden words to be highlighted.
1701 If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
1702 words are highlighted in a warning color to indicate not to use them.
1704 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1705 entry \"Fontify Buffer\")."
1706 :type
'(repeat (string :format
"%v"))
1707 :set
(lambda (variable value
)
1708 (vhdl-custom-set variable value
1709 'vhdl-words-init
'vhdl-font-lock-init
))
1710 :group
'vhdl-highlight
)
1712 (defcustom vhdl-forbidden-syntax
""
1713 "Syntax of forbidden words to be highlighted.
1714 If option `vhdl-highlight-forbidden-words' is non-nil, words with this
1715 syntax are highlighted in a warning color to indicate not to use them.
1716 Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
1717 highlights identifiers with 10 or more characters).
1719 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1720 entry \"Fontify Buffer\")."
1722 :set
(lambda (variable value
)
1723 (vhdl-custom-set variable value
1724 'vhdl-words-init
'vhdl-font-lock-init
))
1725 :group
'vhdl-highlight
)
1727 (defcustom vhdl-directive-keywords
'("pragma" "synopsys")
1728 "List of compiler directive keywords recognized for highlighting.
1730 NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
1731 entry \"Fontify Buffer\")."
1732 :type
'(repeat (string :format
"%v"))
1733 :set
(lambda (variable value
)
1734 (vhdl-custom-set variable value
1735 'vhdl-words-init
'vhdl-font-lock-init
))
1736 :group
'vhdl-highlight
)
1739 (defgroup vhdl-speedbar nil
1740 "Customizations for speedbar."
1743 (defcustom vhdl-speedbar-auto-open nil
1744 "Non-nil means automatically open speedbar at startup.
1745 Alternatively, the speedbar can be opened from the VHDL menu."
1747 :group
'vhdl-speedbar
)
1749 (defcustom vhdl-speedbar-display-mode
'files
1750 "Specifies the default displaying mode when opening speedbar.
1751 Alternatively, the displaying mode can be selected from the speedbar menu or
1752 by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
1753 :type
'(choice (const :tag
"Files" files
)
1754 (const :tag
"Directory hierarchy" directory
)
1755 (const :tag
"Project hierarchy" project
))
1756 :group
'vhdl-speedbar
)
1758 (defcustom vhdl-speedbar-scan-limit
'(10000000 (1000000 50))
1759 "Limits scanning of large files and netlists.
1760 Design units: maximum file size to scan for design units
1761 Hierarchy (instances of subcomponents):
1762 File size: maximum file size to scan for instances (in bytes)
1763 Instances per arch: maximum number of instances to scan per architecture
1765 \"None\" always means that there is no limit.
1766 In case of files not or incompletely scanned, a warning message and the file
1767 names are printed out.
1768 Background: scanning for instances is considerably slower than scanning for
1769 design units, especially when there are many instances. These limits should
1770 prevent the scanning of large netlists."
1771 :type
'(list (choice :tag
"Design units"
1772 :format
"%t : %[Value Menu%] %v"
1773 (const :tag
"None" nil
)
1774 (integer :tag
"File size"))
1775 (list :tag
"Hierarchy" :indent
2
1776 (choice :tag
"File size"
1777 :format
"%t : %[Value Menu%] %v"
1778 (const :tag
"None" nil
)
1779 (integer :tag
"Size "))
1780 (choice :tag
"Instances per arch"
1781 (const :tag
"None" nil
)
1782 (integer :tag
"Number "))))
1783 :group
'vhdl-speedbar
)
1785 (defcustom vhdl-speedbar-jump-to-unit t
1786 "Non-nil means jump to the design unit code when opened in a buffer.
1787 The buffer cursor position is left unchanged otherwise."
1789 :group
'vhdl-speedbar
)
1791 (defcustom vhdl-speedbar-update-on-saving t
1792 "Automatically update design hierarchy when buffer is saved."
1794 :group
'vhdl-speedbar
)
1796 (defcustom vhdl-speedbar-save-cache
'(hierarchy display
)
1797 "Automatically save modified hierarchy caches when exiting Emacs.
1798 Hierarchy: design hierarchy information
1799 Display: displaying information (which design units to expand)"
1800 :type
'(set (const :tag
"Hierarchy" hierarchy
)
1801 (const :tag
"Display" display
))
1802 :group
'vhdl-speedbar
)
1804 (defcustom vhdl-speedbar-cache-file-name
".emacs-vhdl-cache-\\1-\\2"
1805 "Name of file for saving hierarchy cache.
1806 \"\\1\" is replaced by the project name if a project is specified,
1807 \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
1808 different users to have cache files in the same directory). Can also have
1809 an absolute path (i.e. all caches can be stored in one global directory)."
1811 :group
'vhdl-speedbar
)
1814 (defgroup vhdl-menu nil
1815 "Customizations for menus."
1818 (defcustom vhdl-index-menu nil
1819 "Non-nil means add an index menu for a source file when loading.
1820 Alternatively, the speedbar can be used. Note that the index menu scans a file
1821 when it is opened, while speedbar only scans the file upon request."
1825 (defcustom vhdl-source-file-menu nil
1826 "Non-nil means add a menu of all source files in current directory.
1827 Alternatively, the speedbar can be used."
1831 (defcustom vhdl-hideshow-menu nil
1832 "Non-nil means add hideshow menu and functionality at startup.
1833 Hideshow can also be enabled from the VHDL Mode menu.
1834 Hideshow allows hiding code of various VHDL constructs.
1836 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1837 \"Activate Options\"."
1841 (defcustom vhdl-hide-all-init nil
1842 "Non-nil means hide all design units initially after a file is loaded."
1847 (defgroup vhdl-print nil
1848 "Customizations for printing."
1851 (defcustom vhdl-print-two-column t
1852 "Non-nil means print code in two columns and landscape format.
1853 Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
1854 prints VHDL files in a nice two-column landscape style.
1856 NOTE: Activate the new setting by restarting Emacs.
1857 Overrides `ps-print' settings locally."
1861 (defcustom vhdl-print-customize-faces t
1862 "Non-nil means use an optimized set of faces for PostScript printing.
1864 NOTE: Activate the new setting by restarting Emacs.
1865 Overrides `ps-print' settings locally."
1870 (defgroup vhdl-misc nil
1871 "Miscellaneous customizations."
1874 (defcustom vhdl-intelligent-tab t
1875 "Non-nil means `TAB' does indentation, word completion and tab insertion.
1876 That is, if preceding character is part of a word then complete word,
1877 else if not at beginning of line then insert tab,
1878 else if last command was a `TAB' or `RET' then dedent one step,
1879 else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
1880 If nil, TAB always indents current line (i.e. `TAB' is bound to
1881 `indent-according-to-mode').
1883 NOTE: Activate the new setting in a VHDL buffer by using the menu entry
1884 \"Activate Options\"."
1888 (defcustom vhdl-indent-syntax-based t
1889 "Non-nil means indent lines of code based on their syntactic context.
1890 Otherwise, a line is indented like the previous nonblank line. This can be
1891 useful in large files where syntax-based indentation gets very slow."
1895 (defcustom vhdl-indent-comment-like-next-code-line t
1896 "Non-nil means comment lines are indented like the following code line.
1897 Otherwise, comment lines are indented like the preceding code line.
1898 Indenting comment lines like the following code line gives nicer indentation
1899 when comments precede the code that they refer to."
1904 (defcustom vhdl-word-completion-case-sensitive nil
1905 "Non-nil means word completion using `TAB' is case sensitive.
1906 That is, `TAB' completes words that start with the same letters and case.
1907 Otherwise, case is ignored."
1911 (defcustom vhdl-word-completion-in-minibuffer t
1912 "Non-nil enables word completion in minibuffer (for template prompts).
1914 NOTE: Activate the new setting by restarting Emacs."
1918 (defcustom vhdl-underscore-is-part-of-word nil
1919 "Non-nil means consider the underscore character `_' as part of word.
1920 An identifier containing underscores is then treated as a single word in
1921 select and move operations. All parts of an identifier separated by underscore
1922 are treated as single words otherwise."
1925 (make-obsolete-variable 'vhdl-underscore-is-part-of-word
1926 'superword-mode
"24.4")
1929 (defgroup vhdl-related nil
1930 "Related general customizations."
1933 ;; add related general customizations
1934 (custom-add-to-group 'vhdl-related
'hideshow
'custom-group
)
1935 (if (featurep 'xemacs
)
1936 (custom-add-to-group 'vhdl-related
'paren-mode
'custom-variable
)
1937 (custom-add-to-group 'vhdl-related
'paren-showing
'custom-group
))
1938 (custom-add-to-group 'vhdl-related
'ps-print
'custom-group
)
1939 (custom-add-to-group 'vhdl-related
'speedbar
'custom-group
)
1940 (custom-add-to-group 'vhdl-related
'comment-style
'custom-variable
)
1941 (custom-add-to-group 'vhdl-related
'line-number-mode
'custom-variable
)
1942 (unless (featurep 'xemacs
)
1943 (custom-add-to-group 'vhdl-related
'transient-mark-mode
'custom-variable
))
1944 (custom-add-to-group 'vhdl-related
'user-full-name
'custom-variable
)
1945 (custom-add-to-group 'vhdl-related
'mail-host-address
'custom-variable
)
1946 (custom-add-to-group 'vhdl-related
'user-mail-address
'custom-variable
)
1948 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1949 ;; Hidden user variables
1951 (defvar vhdl-compile-absolute-path nil
1952 "If non-nil, use absolute instead of relative path for compiled files.")
1954 (defvar vhdl-comment-display-line-char ?-
1955 "Character to use in comment display line.")
1957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1958 ;; Internal variables
1960 (defvar vhdl-menu-max-size
20
1961 "Specifies the maximum size of a menu before splitting it into submenus.")
1963 (defvar vhdl-progress-interval
1
1964 "Interval used to update progress status during long operations.
1965 If a number, percentage complete gets updated after each interval of
1966 that many seconds. To inhibit all messages, set this option to nil.")
1968 (defvar vhdl-inhibit-startup-warnings-p nil
1969 "If non-nil, inhibits start up compatibility warnings.")
1971 (defvar vhdl-strict-syntax-p nil
1972 "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
1973 If the syntactic symbol for a particular line does not match a symbol
1974 in the offsets alist, an error is generated, otherwise no error is
1975 reported and the syntactic symbol is ignored.")
1977 (defvar vhdl-echo-syntactic-information-p nil
1978 "If non-nil, syntactic info is echoed when the line is indented.")
1980 (defconst vhdl-offsets-alist-default
1986 (statement-cont . vhdl-lineup-statement-cont
)
1987 (statement-block-intro .
+)
1988 (statement-case-intro .
+)
1989 (case-alternative .
+)
1990 (comment . vhdl-lineup-comment
)
1993 (arglist-cont-nonempty . vhdl-lineup-arglist
)
1994 (arglist-close . vhdl-lineup-arglist
)
2001 "Default settings for offsets of syntactic elements.
2002 Do not change this constant! See the variable `vhdl-offsets-alist' for
2005 (defvar vhdl-offsets-alist
(copy-alist vhdl-offsets-alist-default
)
2006 "Association list of syntactic element symbols and indentation offsets.
2007 As described below, each cons cell in this list has the form:
2009 (SYNTACTIC-SYMBOL . OFFSET)
2011 When a line is indented, `vhdl-mode' first determines the syntactic
2012 context of the line by generating a list of symbols called syntactic
2013 elements. This list can contain more than one syntactic element and
2014 the global variable `vhdl-syntactic-context' contains the context list
2015 for the line being indented. Each element in this list is actually a
2016 cons cell of the syntactic symbol and a buffer position. This buffer
2017 position is call the relative indent point for the line. Some
2018 syntactic symbols may not have a relative indent point associated with
2021 After the syntactic context list for a line is generated, `vhdl-mode'
2022 calculates the absolute indentation for the line by looking at each
2023 syntactic element in the list. First, it compares the syntactic
2024 element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
2025 finds a match, it adds the OFFSET to the column of the relative indent
2026 point. The sum of this calculation for each element in the syntactic
2027 list is the absolute offset for line being indented.
2029 If the syntactic element does not match any in the `vhdl-offsets-alist',
2030 an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
2031 the element is ignored.
2033 Actually, OFFSET can be an integer, a function, a variable, or one of
2034 the following symbols: `+', `-', `++', or `--'. These latter
2035 designate positive or negative multiples of `vhdl-basic-offset',
2036 respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
2037 called with a single argument containing the cons of the syntactic
2038 element symbol and the relative indent point. The function should
2039 return an integer offset.
2041 Here is the current list of valid syntactic element symbols:
2043 string -- inside multi-line string
2044 block-open -- statement block open
2045 block-close -- statement block close
2046 statement -- a VHDL statement
2047 statement-cont -- a continuation of a VHDL statement
2048 statement-block-intro -- the first line in a new statement block
2049 statement-case-intro -- the first line in a case alternative block
2050 case-alternative -- a case statement alternative clause
2051 comment -- a line containing only a comment
2052 arglist-intro -- the first line in an argument list
2053 arglist-cont -- subsequent argument list lines when no
2054 arguments follow on the same line as
2055 the arglist opening paren
2056 arglist-cont-nonempty -- subsequent argument list lines when at
2057 least one argument follows on the same
2058 line as the arglist opening paren
2059 arglist-close -- the solo close paren of an argument list
2060 entity -- inside an entity declaration
2061 configuration -- inside a configuration declaration
2062 package -- inside a package declaration
2063 architecture -- inside an architecture body
2064 package-body -- inside a package body")
2066 (defvar vhdl-comment-only-line-offset
0
2067 "Extra offset for line which contains only the start of a comment.
2068 Can contain an integer or a cons cell of the form:
2070 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
2072 Where NON-ANCHORED-OFFSET is the amount of offset given to
2073 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
2074 the amount of offset to give column-zero anchored comment-only lines.
2075 Just an integer as value is equivalent to (<val> . 0)")
2077 (defvar vhdl-special-indent-hook nil
2078 "Hook for user defined special indentation adjustments.
2079 This hook gets called after a line is indented by the mode.")
2081 (defvar vhdl-style-alist
2083 (vhdl-basic-offset .
4)
2084 (vhdl-offsets-alist .
())))
2085 "Styles of Indentation.
2086 Elements of this alist are of the form:
2088 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
2090 where STYLE-STRING is a short descriptive string used to select a
2091 style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
2092 value for that variable when using the selected style.
2094 There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
2095 case, the VALUE is a list containing elements of the form:
2097 (SYNTACTIC-SYMBOL . VALUE)
2099 as described in `vhdl-offsets-alist'. These are passed directly to
2100 `vhdl-set-offset' so there is no need to set every syntactic symbol in
2101 your style, only those that are different from the default.")
2103 ;; dynamically append the default value of most variables
2104 (or (assoc "Default" vhdl-style-alist
)
2105 (let* ((varlist '(vhdl-inhibit-startup-warnings-p
2106 vhdl-strict-syntax-p
2107 vhdl-echo-syntactic-information-p
2110 vhdl-comment-only-line-offset
))
2111 (default (cons "Default"
2115 (cons var
(symbol-value var
))))
2117 (push default vhdl-style-alist
)))
2119 (defvar vhdl-mode-hook nil
2120 "Hook called by `vhdl-mode'.")
2123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2124 ;;; Required packages
2125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2129 (require 'compile
) ; XEmacs
2131 (require 'hippie-exp
)
2133 ;; optional (minimize warning messages during compile)
2134 (unless (featurep 'xemacs
)
2136 (require 'font-lock
)
2138 (require 'speedbar
)))
2141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2146 ;; XEmacs compatibility
2149 (defun vhdl-keep-region-active ()
2150 "Do whatever is necessary to keep the region active in XEmacs.
2151 Ignore byte-compiler warnings you might see."
2152 (and (featurep 'xemacs
)
2153 (setq zmacs-region-stays t
)))
2155 ;; `wildcard-to-regexp' is included only in XEmacs 21
2156 (unless (fboundp 'wildcard-to-regexp
)
2157 (defun wildcard-to-regexp (wildcard)
2158 "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
2159 (let* ((i (string-match "[*?]" wildcard
))
2160 (result (substring wildcard
0 i
))
2161 (len (length wildcard
)))
2164 (let ((ch (aref wildcard i
)))
2165 (setq result
(concat result
2166 (cond ((eq ch ?
*) "[^\000]*")
2167 ((eq ch ??
) "[^\000]")
2168 (t (char-to-string ch
)))))
2170 (concat "\\`" result
"\\'"))))
2172 ;; `regexp-opt' undefined (`xemacs-devel' not installed)
2173 ;; `regexp-opt' accelerates fontification by 10-20%
2174 (unless (fboundp 'regexp-opt
)
2175 ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
2176 (defun regexp-opt (strings &optional paren
)
2177 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
2178 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
))))
2180 ;; `match-string-no-properties' undefined (XEmacs, what else?)
2181 (unless (fboundp 'match-string-no-properties
)
2182 (defalias 'match-string-no-properties
'match-string
))
2184 ;; `subst-char-in-string' undefined (XEmacs)
2185 (unless (fboundp 'subst-char-in-string
)
2186 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
2187 (let ((i (length string
))
2188 (newstr (if inplace string
(copy-sequence string
))))
2191 (if (eq (aref newstr i
) fromchar
) (aset newstr i tochar
)))
2194 ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
2195 (when (and (featurep 'xemacs
) (string< itimer-version
"1.09")
2196 (not noninteractive
))
2198 (when (string< itimer-version
"1.09")
2199 (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
2200 (beep) (sit-for 5)))
2202 ;; `file-expand-wildcards' undefined (XEmacs)
2203 (unless (fboundp 'file-expand-wildcards
)
2204 (defun file-expand-wildcards (pattern &optional full
)
2205 "Taken from Emacs's `files.el'."
2206 (let* ((nondir (file-name-nondirectory pattern
))
2207 (dirpart (file-name-directory pattern
))
2208 (dirs (if (and dirpart
(string-match "[[*?]" dirpart
))
2209 (mapcar 'file-name-as-directory
2210 (file-expand-wildcards (directory-file-name dirpart
)))
2214 (when (or (null (car dirs
)) ; Possible if DIRPART is not wild.
2215 (file-directory-p (directory-file-name (car dirs
))))
2216 (let ((this-dir-contents
2218 (mapcar #'(lambda (name)
2219 (unless (string-match "\\`\\.\\.?\\'"
2220 (file-name-nondirectory name
))
2222 (directory-files (or (car dirs
) ".") full
2223 (wildcard-to-regexp nondir
))))))
2226 (if (and (car dirs
) (not full
))
2227 (mapcar (function (lambda (name) (concat (car dirs
) name
)))
2231 (setq dirs
(cdr dirs
)))
2234 ;; `member-ignore-case' undefined (XEmacs)
2235 (unless (fboundp 'member-ignore-case
)
2236 (defalias 'member-ignore-case
'member
))
2238 ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
2239 ;; behavior in XEmacs
2240 (defvar vhdl-last-input-event
)
2241 (if (featurep 'xemacs
)
2242 (defvaralias 'vhdl-last-input-event
'last-input-char
)
2243 (defvaralias 'vhdl-last-input-event
'last-input-event
))
2245 ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
2246 ;;;(unless (fboundp 'help-print-return-message)
2247 ;;; (defalias 'help-print-return-message 'print-help-return-message))
2249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2250 ;; Compatibility with older VHDL Mode versions
2252 (defvar vhdl-warnings nil
2253 "Warnings to tell the user during start up.")
2255 (defun vhdl-run-when-idle (secs repeat function
)
2256 "Wait until idle, then run FUNCTION."
2257 (if (fboundp 'start-itimer
)
2258 (start-itimer "vhdl-mode" function secs repeat t
)
2259 ; (run-with-idle-timer secs repeat function)))
2260 ;; explicitly activate timer (necessary when Emacs is already idle)
2261 (aset (run-with-idle-timer secs repeat function
) 0 nil
)))
2263 (defun vhdl-warning-when-idle (&rest args
)
2264 "Wait until idle, then print out warning STRING and beep."
2266 (vhdl-warning (apply 'format args
) t
)
2267 (unless vhdl-warnings
2268 (vhdl-run-when-idle .1 nil
'vhdl-print-warnings
))
2269 (push (apply 'format args
) vhdl-warnings
)))
2271 (defun vhdl-warning (string &optional nobeep
)
2272 "Print out warning STRING and beep."
2273 (message "WARNING: %s" string
)
2274 (unless (or nobeep noninteractive
) (beep)))
2276 (defun vhdl-print-warnings ()
2277 "Print out messages in variable `vhdl-warnings'."
2278 (let ((no-warnings (length vhdl-warnings
)))
2279 (setq vhdl-warnings
(nreverse vhdl-warnings
))
2280 (while vhdl-warnings
2281 (message "WARNING: %s" (car vhdl-warnings
))
2282 (setq vhdl-warnings
(cdr vhdl-warnings
)))
2284 (when (> no-warnings
1)
2285 (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
2287 ;; Backward compatibility checks and fixes
2288 ;; option `vhdl-compiler' changed format
2289 (unless (stringp vhdl-compiler
)
2290 (setq vhdl-compiler
"ModelSim")
2291 (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
2293 ;; option `vhdl-standard' changed format
2294 (unless (listp vhdl-standard
)
2295 (setq vhdl-standard
'(87 nil
))
2296 (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
2298 ;; option `vhdl-model-alist' changed format
2299 (when (= (length (car vhdl-model-alist
)) 3)
2300 (let ((old-alist vhdl-model-alist
)
2303 (push (append (car old-alist
) '("")) new-alist
)
2304 (setq old-alist
(cdr old-alist
)))
2305 (setq vhdl-model-alist
(nreverse new-alist
)))
2306 (customize-save-variable 'vhdl-model-alist vhdl-model-alist
))
2308 ;; option `vhdl-project-alist' changed format
2309 (when (= (length (car vhdl-project-alist
)) 3)
2310 (let ((old-alist vhdl-project-alist
)
2313 (push (append (car old-alist
) '("")) new-alist
)
2314 (setq old-alist
(cdr old-alist
)))
2315 (setq vhdl-project-alist
(nreverse new-alist
)))
2316 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2318 ;; option `vhdl-project-alist' changed format (3.31.1)
2319 (when (= (length (car vhdl-project-alist
)) 4)
2320 (let ((old-alist vhdl-project-alist
)
2323 (setq elem
(car old-alist
))
2325 (cons (list (nth 0 elem
) (nth 1 elem
) "" (nth 2 elem
)
2326 nil
"./" "work" "work/" "Makefile" (nth 3 elem
))
2328 (setq old-alist
(cdr old-alist
)))
2329 (setq vhdl-project-alist
(nreverse new-alist
)))
2330 (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
2332 ;; option `vhdl-project-alist' changed format (3.31.12)
2333 (when (= (length (car vhdl-project-alist
)) 10)
2334 (let ((tmp-alist vhdl-project-alist
))
2336 (setcdr (nthcdr 3 (car tmp-alist
))
2337 (cons "" (nthcdr 4 (car tmp-alist
))))
2338 (setq tmp-alist
(cdr tmp-alist
))))
2339 (customize-save-variable 'vhdl-project-alist vhdl-project-alist
))
2341 ;; option `vhdl-compiler-alist' changed format (3.31.1)
2342 (when (= (length (car vhdl-compiler-alist
)) 7)
2343 (let ((old-alist vhdl-compiler-alist
)
2346 (setq elem
(car old-alist
))
2348 (cons (list (nth 0 elem
) (nth 1 elem
) "" "make -f \\1"
2349 (if (equal (nth 3 elem
) "") nil
(nth 3 elem
))
2350 (nth 4 elem
) "work/" "Makefile" (downcase (nth 0 elem
))
2351 (nth 5 elem
) (nth 6 elem
) nil
)
2353 (setq old-alist
(cdr old-alist
)))
2354 (setq vhdl-compiler-alist
(nreverse new-alist
)))
2355 (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
2357 ;; option `vhdl-compiler-alist' changed format (3.31.10)
2358 (when (= (length (car vhdl-compiler-alist
)) 12)
2359 (let ((tmp-alist vhdl-compiler-alist
))
2361 (setcdr (nthcdr 4 (car tmp-alist
))
2362 (cons "mkdir \\1" (nthcdr 5 (car tmp-alist
))))
2363 (setq tmp-alist
(cdr tmp-alist
))))
2364 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2366 ;; option `vhdl-compiler-alist' changed format (3.31.11)
2367 (when (= (length (car vhdl-compiler-alist
)) 13)
2368 (let ((tmp-alist vhdl-compiler-alist
))
2370 (setcdr (nthcdr 3 (car tmp-alist
))
2371 (cons "" (nthcdr 4 (car tmp-alist
))))
2372 (setq tmp-alist
(cdr tmp-alist
))))
2373 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2375 ;; option `vhdl-compiler-alist' changed format (3.32.7)
2376 (when (= (length (nth 11 (car vhdl-compiler-alist
))) 3)
2377 (let ((tmp-alist vhdl-compiler-alist
))
2379 (setcdr (nthcdr 2 (nth 11 (car tmp-alist
)))
2381 (setq tmp-alist
(cdr tmp-alist
))))
2382 (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist
))
2384 ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
2385 (when (equal vhdl-project
"")
2386 (setq vhdl-project nil
)
2387 (customize-save-variable 'vhdl-project vhdl-project
))
2389 ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
2390 (when (stringp vhdl-project-file-name
)
2391 (setq vhdl-project-file-name
(list vhdl-project-file-name
))
2392 (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name
))
2394 ;; option `speedbar-indentation-width': introduced in speedbar 0.10
2395 (if (not (boundp 'speedbar-indentation-width
))
2396 (defvar speedbar-indentation-width
2)
2397 ;; set default to 2 if not already customized
2398 (unless (get 'speedbar-indentation-width
'saved-value
)
2399 (setq speedbar-indentation-width
2)))
2401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2402 ;;; Help functions / inline substitutions / macros
2403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2405 (defun vhdl-standard-p (standard)
2406 "Check if STANDARD is specified as used standard."
2407 (or (eq standard
(car vhdl-standard
))
2408 (memq standard
(cadr vhdl-standard
))))
2410 (defun vhdl-project-p (&optional warning
)
2411 "Return non-nil if a project is displayed, i.e. directories or files are
2413 (if (assoc vhdl-project vhdl-project-alist
)
2415 (when (and vhdl-project warning
)
2416 (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project
))
2419 (defun vhdl-resolve-env-variable (string)
2420 "Resolve environment variables in STRING."
2421 (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string
)
2422 (setq string
(concat (match-string 1 string
)
2423 (getenv (match-string 2 string
))
2424 (match-string 4 string
))))
2427 (defun vhdl-default-directory ()
2428 "Return the default directory of the current project or the directory of the
2429 current buffer if no project is defined."
2430 (if (vhdl-project-p)
2431 (expand-file-name (vhdl-resolve-env-variable
2432 (nth 1 (aget vhdl-project-alist vhdl-project
))))
2435 (defmacro vhdl-prepare-search-1
(&rest body
)
2436 "Enable case insensitive search and switch to syntax table that includes '_',
2437 then execute BODY, and finally restore the old environment. Used for
2438 consistent searching."
2439 `(let ((case-fold-search t
)) ; case insensitive search
2440 ;; use extended syntax table
2441 (with-syntax-table vhdl-mode-ext-syntax-table
2444 (defmacro vhdl-prepare-search-2
(&rest body
)
2445 "Enable case insensitive search, switch to syntax table that includes '_',
2446 and remove `intangible' overlays, then execute BODY, and finally restore the
2447 old environment. Used for consistent searching."
2448 ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
2449 `(let ((case-fold-search t
) ; case insensitive search
2450 (current-syntax-table (syntax-table))
2451 overlay-all-list overlay-intangible-list overlay
)
2452 ;; use extended syntax table
2453 (set-syntax-table vhdl-mode-ext-syntax-table
)
2454 ;; remove `intangible' overlays
2455 (when (fboundp 'overlay-lists
)
2456 (setq overlay-all-list
(overlay-lists))
2457 (setq overlay-all-list
2458 (append (car overlay-all-list
) (cdr overlay-all-list
)))
2459 (while overlay-all-list
2460 (setq overlay
(car overlay-all-list
))
2461 (when (memq 'intangible
(overlay-properties overlay
))
2462 (setq overlay-intangible-list
2463 (cons overlay overlay-intangible-list
))
2464 (overlay-put overlay
'intangible nil
))
2465 (setq overlay-all-list
(cdr overlay-all-list
))))
2466 ;; execute BODY safely
2469 ;; restore syntax table
2470 (set-syntax-table current-syntax-table
)
2471 ;; restore `intangible' overlays
2472 (when (fboundp 'overlay-lists
)
2473 (while overlay-intangible-list
2474 (overlay-put (car overlay-intangible-list
) 'intangible t
)
2475 (setq overlay-intangible-list
2476 (cdr overlay-intangible-list
)))))))
2478 (defmacro vhdl-visit-file
(file-name issue-error
&rest body
)
2479 "Visit file FILE-NAME and execute BODY."
2480 `(if (null ,file-name
)
2482 (unless (file-directory-p ,file-name
)
2483 (let ((source-buffer (current-buffer))
2484 (visiting-buffer (find-buffer-visiting ,file-name
))
2486 (when (or (and visiting-buffer
(set-buffer visiting-buffer
))
2488 (progn (set-buffer (create-file-buffer ,file-name
))
2489 (setq file-opened t
)
2490 (vhdl-insert-file-contents ,file-name
)
2491 ;; FIXME: This modifies a global syntax-table!
2492 (modify-syntax-entry ?\-
". 12" (syntax-table))
2493 (modify-syntax-entry ?
\n ">" (syntax-table))
2494 (modify-syntax-entry ?\^M
">" (syntax-table))
2495 (modify-syntax-entry ?_
"w" (syntax-table))
2500 (when file-opened
(kill-buffer (current-buffer)))
2501 (set-buffer source-buffer
)
2502 (error "ERROR: File cannot be opened: \"%s\"" ,file-name
))
2503 (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name
) t
)
2505 (condition-case info
2510 (when file-opened
(kill-buffer (current-buffer)))
2511 (set-buffer source-buffer
)
2512 (error (cadr info
)))
2513 (vhdl-warning (cadr info
))))))
2514 (when file-opened
(kill-buffer (current-buffer)))
2515 (set-buffer source-buffer
)))))
2517 (defun vhdl-insert-file-contents (filename)
2518 "Nicked from `insert-file-contents-literally', but allow coding system
2520 (let ((format-alist nil
)
2521 (after-insert-file-functions nil
)
2522 (jka-compr-compression-info-list nil
))
2523 (insert-file-contents filename t
)))
2525 (defun vhdl-sort-alist (alist)
2527 (sort alist
(function (lambda (a b
) (string< (car a
) (car b
))))))
2529 (defun vhdl-get-subdirs (directory)
2530 "Recursively get subdirectories of DIRECTORY."
2531 (let ((dir-list (list (file-name-as-directory directory
)))
2533 (setq file-list
(vhdl-directory-files directory t
"\\w.*"))
2535 (when (file-directory-p (car file-list
))
2536 (setq dir-list
(append dir-list
(vhdl-get-subdirs (car file-list
)))))
2537 (setq file-list
(cdr file-list
)))
2540 (defun vhdl-aput (alist-symbol key
&optional value
)
2541 "As `aput', but delete key-value pair if VALUE is nil."
2543 (aput alist-symbol key value
)
2544 (adelete alist-symbol key
)))
2546 (defun vhdl-delete (elt list
)
2547 "Delete by side effect the first occurrence of ELT as a member of LIST."
2550 (while (and (cdr list1
) (not (equal elt
(cadr list1
))))
2551 (setq list1
(cdr list1
)))
2553 (setcdr list1
(cddr list1
))))
2556 (defun vhdl-speedbar-refresh (&optional key
)
2557 "Refresh directory or project with name KEY."
2558 (when (and (boundp 'speedbar-frame
)
2559 (frame-live-p speedbar-frame
))
2561 (last-frame (selected-frame)))
2564 (select-frame speedbar-frame
)
2565 (when (save-excursion
2566 (goto-char (point-min))
2567 (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key
"$") nil t
))
2568 (goto-char (match-end 1))
2569 (speedbar-do-function-pointer)
2571 (speedbar-do-function-pointer)
2572 (message "Refreshing speedbar...done"))
2573 (select-frame last-frame
)))))
2575 (defun vhdl-show-messages ()
2576 "Get *Messages* buffer to show recent messages."
2578 (display-buffer (if (featurep 'xemacs
) " *Message-Log*" "*Messages*")))
2580 (defun vhdl-use-direct-instantiation ()
2581 "Return whether direct instantiation is used."
2582 (or (eq vhdl-use-direct-instantiation
'always
)
2583 (and (eq vhdl-use-direct-instantiation
'standard
)
2584 (not (vhdl-standard-p '87)))))
2586 (defun vhdl-max-marker (marker1 marker2
)
2587 "Return larger marker."
2588 (if (> marker1 marker2
) marker1 marker2
))
2590 (defun vhdl-goto-marker (marker)
2591 "Goto marker in appropriate buffer."
2592 (when (markerp marker
)
2593 (set-buffer (marker-buffer marker
)))
2596 (defun vhdl-goto-line (line)
2597 "Use this instead of calling user level function `goto-line'."
2598 (goto-char (point-min))
2599 (forward-line (1- line
)))
2601 (defun vhdl-menu-split (list title
)
2602 "Split menu LIST into several submenus, if number of
2603 elements > `vhdl-menu-max-size'."
2604 (if (> (length list
) vhdl-menu-max-size
)
2611 (push (car remain
) sublist
)
2612 (setq remain
(cdr remain
))
2614 (if (= i vhdl-menu-max-size
)
2616 (push (cons (format "%s %s" title menuno
)
2617 (nreverse sublist
)) result
)
2619 (setq menuno
(+ menuno
1))
2620 (setq sublist
'()))))
2622 (push (cons (format "%s %s" title menuno
)
2623 (nreverse sublist
)) result
))
2628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2635 (defvar vhdl-template-map nil
2636 "Keymap for VHDL templates.")
2638 (defun vhdl-template-map-init ()
2639 "Initialize `vhdl-template-map'."
2640 (setq vhdl-template-map
(make-sparse-keymap))
2641 ;; key bindings for VHDL templates
2642 (define-key vhdl-template-map
"al" 'vhdl-template-alias
)
2643 (define-key vhdl-template-map
"ar" 'vhdl-template-architecture
)
2644 (define-key vhdl-template-map
"at" 'vhdl-template-assert
)
2645 (define-key vhdl-template-map
"ad" 'vhdl-template-attribute-decl
)
2646 (define-key vhdl-template-map
"as" 'vhdl-template-attribute-spec
)
2647 (define-key vhdl-template-map
"bl" 'vhdl-template-block
)
2648 (define-key vhdl-template-map
"ca" 'vhdl-template-case-is
)
2649 (define-key vhdl-template-map
"cd" 'vhdl-template-component-decl
)
2650 (define-key vhdl-template-map
"ci" 'vhdl-template-component-inst
)
2651 (define-key vhdl-template-map
"cs" 'vhdl-template-conditional-signal-asst
)
2652 (define-key vhdl-template-map
"Cb" 'vhdl-template-block-configuration
)
2653 (define-key vhdl-template-map
"Cc" 'vhdl-template-component-conf
)
2654 (define-key vhdl-template-map
"Cd" 'vhdl-template-configuration-decl
)
2655 (define-key vhdl-template-map
"Cs" 'vhdl-template-configuration-spec
)
2656 (define-key vhdl-template-map
"co" 'vhdl-template-constant
)
2657 (define-key vhdl-template-map
"di" 'vhdl-template-disconnect
)
2658 (define-key vhdl-template-map
"el" 'vhdl-template-else
)
2659 (define-key vhdl-template-map
"ei" 'vhdl-template-elsif
)
2660 (define-key vhdl-template-map
"en" 'vhdl-template-entity
)
2661 (define-key vhdl-template-map
"ex" 'vhdl-template-exit
)
2662 (define-key vhdl-template-map
"fi" 'vhdl-template-file
)
2663 (define-key vhdl-template-map
"fg" 'vhdl-template-for-generate
)
2664 (define-key vhdl-template-map
"fl" 'vhdl-template-for-loop
)
2665 (define-key vhdl-template-map
"\C-f" 'vhdl-template-footer
)
2666 (define-key vhdl-template-map
"fb" 'vhdl-template-function-body
)
2667 (define-key vhdl-template-map
"fd" 'vhdl-template-function-decl
)
2668 (define-key vhdl-template-map
"ge" 'vhdl-template-generic
)
2669 (define-key vhdl-template-map
"gd" 'vhdl-template-group-decl
)
2670 (define-key vhdl-template-map
"gt" 'vhdl-template-group-template
)
2671 (define-key vhdl-template-map
"\C-h" 'vhdl-template-header
)
2672 (define-key vhdl-template-map
"ig" 'vhdl-template-if-generate
)
2673 (define-key vhdl-template-map
"it" 'vhdl-template-if-then
)
2674 (define-key vhdl-template-map
"li" 'vhdl-template-library
)
2675 (define-key vhdl-template-map
"lo" 'vhdl-template-bare-loop
)
2676 (define-key vhdl-template-map
"\C-m" 'vhdl-template-modify
)
2677 (define-key vhdl-template-map
"\C-t" 'vhdl-template-insert-date
)
2678 (define-key vhdl-template-map
"ma" 'vhdl-template-map
)
2679 (define-key vhdl-template-map
"ne" 'vhdl-template-next
)
2680 (define-key vhdl-template-map
"ot" 'vhdl-template-others
)
2681 (define-key vhdl-template-map
"Pd" 'vhdl-template-package-decl
)
2682 (define-key vhdl-template-map
"Pb" 'vhdl-template-package-body
)
2683 (define-key vhdl-template-map
"(" 'vhdl-template-paired-parens
)
2684 (define-key vhdl-template-map
"po" 'vhdl-template-port
)
2685 (define-key vhdl-template-map
"pb" 'vhdl-template-procedure-body
)
2686 (define-key vhdl-template-map
"pd" 'vhdl-template-procedure-decl
)
2687 (define-key vhdl-template-map
"pc" 'vhdl-template-process-comb
)
2688 (define-key vhdl-template-map
"ps" 'vhdl-template-process-seq
)
2689 (define-key vhdl-template-map
"rp" 'vhdl-template-report
)
2690 (define-key vhdl-template-map
"rt" 'vhdl-template-return
)
2691 (define-key vhdl-template-map
"ss" 'vhdl-template-selected-signal-asst
)
2692 (define-key vhdl-template-map
"si" 'vhdl-template-signal
)
2693 (define-key vhdl-template-map
"su" 'vhdl-template-subtype
)
2694 (define-key vhdl-template-map
"ty" 'vhdl-template-type
)
2695 (define-key vhdl-template-map
"us" 'vhdl-template-use
)
2696 (define-key vhdl-template-map
"va" 'vhdl-template-variable
)
2697 (define-key vhdl-template-map
"wa" 'vhdl-template-wait
)
2698 (define-key vhdl-template-map
"wl" 'vhdl-template-while-loop
)
2699 (define-key vhdl-template-map
"wi" 'vhdl-template-with
)
2700 (define-key vhdl-template-map
"wc" 'vhdl-template-clocked-wait
)
2701 (define-key vhdl-template-map
"\C-pb" 'vhdl-template-package-numeric-bit
)
2702 (define-key vhdl-template-map
"\C-pn" 'vhdl-template-package-numeric-std
)
2703 (define-key vhdl-template-map
"\C-ps" 'vhdl-template-package-std-logic-1164
)
2704 (define-key vhdl-template-map
"\C-pA" 'vhdl-template-package-std-logic-arith
)
2705 (define-key vhdl-template-map
"\C-pM" 'vhdl-template-package-std-logic-misc
)
2706 (define-key vhdl-template-map
"\C-pS" 'vhdl-template-package-std-logic-signed
)
2707 (define-key vhdl-template-map
"\C-pT" 'vhdl-template-package-std-logic-textio
)
2708 (define-key vhdl-template-map
"\C-pU" 'vhdl-template-package-std-logic-unsigned
)
2709 (define-key vhdl-template-map
"\C-pt" 'vhdl-template-package-textio
)
2710 (define-key vhdl-template-map
"\C-dn" 'vhdl-template-directive-translate-on
)
2711 (define-key vhdl-template-map
"\C-df" 'vhdl-template-directive-translate-off
)
2712 (define-key vhdl-template-map
"\C-dN" 'vhdl-template-directive-synthesis-on
)
2713 (define-key vhdl-template-map
"\C-dF" 'vhdl-template-directive-synthesis-off
)
2714 (define-key vhdl-template-map
"\C-q" 'vhdl-template-search-prompt
)
2715 (when (vhdl-standard-p 'ams
)
2716 (define-key vhdl-template-map
"br" 'vhdl-template-break
)
2717 (define-key vhdl-template-map
"cu" 'vhdl-template-case-use
)
2718 (define-key vhdl-template-map
"iu" 'vhdl-template-if-use
)
2719 (define-key vhdl-template-map
"lm" 'vhdl-template-limit
)
2720 (define-key vhdl-template-map
"na" 'vhdl-template-nature
)
2721 (define-key vhdl-template-map
"pa" 'vhdl-template-procedural
)
2722 (define-key vhdl-template-map
"qf" 'vhdl-template-quantity-free
)
2723 (define-key vhdl-template-map
"qb" 'vhdl-template-quantity-branch
)
2724 (define-key vhdl-template-map
"qs" 'vhdl-template-quantity-source
)
2725 (define-key vhdl-template-map
"sn" 'vhdl-template-subnature
)
2726 (define-key vhdl-template-map
"te" 'vhdl-template-terminal
)
2728 (when (vhdl-standard-p 'math
)
2729 (define-key vhdl-template-map
"\C-pc" 'vhdl-template-package-math-complex
)
2730 (define-key vhdl-template-map
"\C-pr" 'vhdl-template-package-math-real
)
2733 ;; initialize template map for VHDL Mode
2734 (vhdl-template-map-init)
2736 (defun vhdl-function-name (prefix string
&optional postfix
)
2737 "Generate a Lisp function name.
2738 PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
2739 STRING are replaced by `-' and substrings are converted to lower case."
2740 (let ((name prefix
))
2741 (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string
)
2743 (concat name
"-" (downcase (substring string
0 (match-end 1)))))
2744 (setq string
(substring string
(match-beginning 2))))
2745 (when postfix
(setq name
(concat name
"-" postfix
)))
2748 (defvar vhdl-model-map nil
2749 "Keymap for VHDL models.")
2751 (defun vhdl-model-map-init ()
2752 "Initialize `vhdl-model-map'."
2753 (setq vhdl-model-map
(make-sparse-keymap))
2754 ;; key bindings for VHDL models
2755 (let ((model-alist vhdl-model-alist
) model
)
2757 (setq model
(car model-alist
))
2758 (define-key vhdl-model-map
(nth 2 model
)
2759 (vhdl-function-name "vhdl-model" (nth 0 model
)))
2760 (setq model-alist
(cdr model-alist
)))))
2762 ;; initialize user model map for VHDL Mode
2763 (vhdl-model-map-init)
2765 (defvar vhdl-mode-map nil
2766 "Keymap for VHDL Mode.")
2768 (defun vhdl-mode-map-init ()
2769 "Initialize `vhdl-mode-map'."
2770 (setq vhdl-mode-map
(make-sparse-keymap))
2771 ;; template key bindings
2772 (define-key vhdl-mode-map
"\C-c\C-t" vhdl-template-map
)
2773 ;; model key bindings
2774 (define-key vhdl-mode-map
"\C-c\C-m" vhdl-model-map
)
2775 ;; standard key bindings
2776 (define-key vhdl-mode-map
"\M-a" 'vhdl-beginning-of-statement
)
2777 (define-key vhdl-mode-map
"\M-e" 'vhdl-end-of-statement
)
2778 (define-key vhdl-mode-map
"\M-\C-f" 'vhdl-forward-sexp
)
2779 (define-key vhdl-mode-map
"\M-\C-b" 'vhdl-backward-sexp
)
2780 (define-key vhdl-mode-map
"\M-\C-u" 'vhdl-backward-up-list
)
2781 (define-key vhdl-mode-map
"\M-\C-a" 'vhdl-backward-same-indent
)
2782 (define-key vhdl-mode-map
"\M-\C-e" 'vhdl-forward-same-indent
)
2783 (unless (featurep 'xemacs
) ; would override `M-backspace' in XEmacs
2784 (define-key vhdl-mode-map
"\M-\C-h" 'vhdl-mark-defun
))
2785 (define-key vhdl-mode-map
"\M-\C-q" 'vhdl-indent-sexp
)
2786 (define-key vhdl-mode-map
"\M-^" 'vhdl-delete-indentation
)
2787 ;; mode specific key bindings
2788 (define-key vhdl-mode-map
"\C-c\C-m\C-e" 'vhdl-electric-mode
)
2789 (define-key vhdl-mode-map
"\C-c\C-m\C-s" 'vhdl-stutter-mode
)
2790 (define-key vhdl-mode-map
"\C-c\C-s\C-p" 'vhdl-set-project
)
2791 (define-key vhdl-mode-map
"\C-c\C-p\C-d" 'vhdl-duplicate-project
)
2792 (define-key vhdl-mode-map
"\C-c\C-p\C-m" 'vhdl-import-project
)
2793 (define-key vhdl-mode-map
"\C-c\C-p\C-x" 'vhdl-export-project
)
2794 (define-key vhdl-mode-map
"\C-c\C-s\C-k" 'vhdl-set-compiler
)
2795 (define-key vhdl-mode-map
"\C-c\C-k" 'vhdl-compile
)
2796 (define-key vhdl-mode-map
"\C-c\M-\C-k" 'vhdl-make
)
2797 (define-key vhdl-mode-map
"\C-c\M-k" 'vhdl-generate-makefile
)
2798 (define-key vhdl-mode-map
"\C-c\C-p\C-w" 'vhdl-port-copy
)
2799 (define-key vhdl-mode-map
"\C-c\C-p\M-w" 'vhdl-port-copy
)
2800 (define-key vhdl-mode-map
"\C-c\C-p\C-e" 'vhdl-port-paste-entity
)
2801 (define-key vhdl-mode-map
"\C-c\C-p\C-c" 'vhdl-port-paste-component
)
2802 (define-key vhdl-mode-map
"\C-c\C-p\C-i" 'vhdl-port-paste-instance
)
2803 (define-key vhdl-mode-map
"\C-c\C-p\C-s" 'vhdl-port-paste-signals
)
2804 (define-key vhdl-mode-map
"\C-c\C-p\M-c" 'vhdl-port-paste-constants
)
2805 (if (featurep 'xemacs
) ; `... C-g' not allowed in XEmacs
2806 (define-key vhdl-mode-map
"\C-c\C-p\M-g" 'vhdl-port-paste-generic-map
)
2807 (define-key vhdl-mode-map
"\C-c\C-p\C-g" 'vhdl-port-paste-generic-map
))
2808 (define-key vhdl-mode-map
"\C-c\C-p\C-z" 'vhdl-port-paste-initializations
)
2809 (define-key vhdl-mode-map
"\C-c\C-p\C-t" 'vhdl-port-paste-testbench
)
2810 (define-key vhdl-mode-map
"\C-c\C-p\C-f" 'vhdl-port-flatten
)
2811 (define-key vhdl-mode-map
"\C-c\C-p\C-r" 'vhdl-port-reverse-direction
)
2812 (define-key vhdl-mode-map
"\C-c\C-s\C-w" 'vhdl-subprog-copy
)
2813 (define-key vhdl-mode-map
"\C-c\C-s\M-w" 'vhdl-subprog-copy
)
2814 (define-key vhdl-mode-map
"\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration
)
2815 (define-key vhdl-mode-map
"\C-c\C-s\C-b" 'vhdl-subprog-paste-body
)
2816 (define-key vhdl-mode-map
"\C-c\C-s\C-c" 'vhdl-subprog-paste-call
)
2817 (define-key vhdl-mode-map
"\C-c\C-s\C-f" 'vhdl-subprog-flatten
)
2818 (define-key vhdl-mode-map
"\C-c\C-m\C-n" 'vhdl-compose-new-component
)
2819 (define-key vhdl-mode-map
"\C-c\C-m\C-p" 'vhdl-compose-place-component
)
2820 (define-key vhdl-mode-map
"\C-c\C-m\C-w" 'vhdl-compose-wire-components
)
2821 (define-key vhdl-mode-map
"\C-c\C-m\C-f" 'vhdl-compose-configuration
)
2822 (define-key vhdl-mode-map
"\C-c\C-m\C-k" 'vhdl-compose-components-package
)
2823 (define-key vhdl-mode-map
"\C-c\C-c" 'vhdl-comment-uncomment-region
)
2824 (define-key vhdl-mode-map
"\C-c-" 'vhdl-comment-append-inline
)
2825 (define-key vhdl-mode-map
"\C-c\M--" 'vhdl-comment-display-line
)
2826 (define-key vhdl-mode-map
"\C-c\C-i\C-l" 'indent-according-to-mode
)
2827 (define-key vhdl-mode-map
"\C-c\C-i\C-g" 'vhdl-indent-group
)
2828 (define-key vhdl-mode-map
"\M-\C-\\" 'vhdl-indent-region
)
2829 (define-key vhdl-mode-map
"\C-c\C-i\C-b" 'vhdl-indent-buffer
)
2830 (define-key vhdl-mode-map
"\C-c\C-a\C-g" 'vhdl-align-group
)
2831 (define-key vhdl-mode-map
"\C-c\C-a\C-a" 'vhdl-align-group
)
2832 (define-key vhdl-mode-map
"\C-c\C-a\C-i" 'vhdl-align-same-indent
)
2833 (define-key vhdl-mode-map
"\C-c\C-a\C-l" 'vhdl-align-list
)
2834 (define-key vhdl-mode-map
"\C-c\C-a\C-d" 'vhdl-align-declarations
)
2835 (define-key vhdl-mode-map
"\C-c\C-a\M-a" 'vhdl-align-region
)
2836 (define-key vhdl-mode-map
"\C-c\C-a\C-b" 'vhdl-align-buffer
)
2837 (define-key vhdl-mode-map
"\C-c\C-a\C-c" 'vhdl-align-inline-comment-group
)
2838 (define-key vhdl-mode-map
"\C-c\C-a\M-c" 'vhdl-align-inline-comment-region
)
2839 (define-key vhdl-mode-map
"\C-c\C-f\C-l" 'vhdl-fill-list
)
2840 (define-key vhdl-mode-map
"\C-c\C-f\C-f" 'vhdl-fill-list
)
2841 (define-key vhdl-mode-map
"\C-c\C-f\C-g" 'vhdl-fill-group
)
2842 (define-key vhdl-mode-map
"\C-c\C-f\C-i" 'vhdl-fill-same-indent
)
2843 (define-key vhdl-mode-map
"\C-c\C-f\M-f" 'vhdl-fill-region
)
2844 (define-key vhdl-mode-map
"\C-c\C-l\C-w" 'vhdl-line-kill
)
2845 (define-key vhdl-mode-map
"\C-c\C-l\M-w" 'vhdl-line-copy
)
2846 (define-key vhdl-mode-map
"\C-c\C-l\C-y" 'vhdl-line-yank
)
2847 (define-key vhdl-mode-map
"\C-c\C-l\t" 'vhdl-line-expand
)
2848 (define-key vhdl-mode-map
"\C-c\C-l\C-n" 'vhdl-line-transpose-next
)
2849 (define-key vhdl-mode-map
"\C-c\C-l\C-p" 'vhdl-line-transpose-previous
)
2850 (define-key vhdl-mode-map
"\C-c\C-l\C-o" 'vhdl-line-open
)
2851 (define-key vhdl-mode-map
"\C-c\C-l\C-g" 'goto-line
)
2852 (define-key vhdl-mode-map
"\C-c\C-l\C-c" 'vhdl-comment-uncomment-line
)
2853 (define-key vhdl-mode-map
"\C-c\C-x\C-s" 'vhdl-fix-statement-region
)
2854 (define-key vhdl-mode-map
"\C-c\C-x\M-s" 'vhdl-fix-statement-buffer
)
2855 (define-key vhdl-mode-map
"\C-c\C-x\C-p" 'vhdl-fix-clause
)
2856 (define-key vhdl-mode-map
"\C-c\C-x\M-c" 'vhdl-fix-case-region
)
2857 (define-key vhdl-mode-map
"\C-c\C-x\C-c" 'vhdl-fix-case-buffer
)
2858 (define-key vhdl-mode-map
"\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region
)
2859 (define-key vhdl-mode-map
"\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer
)
2860 (define-key vhdl-mode-map
"\C-c\M-b" 'vhdl-beautify-region
)
2861 (define-key vhdl-mode-map
"\C-c\C-b" 'vhdl-beautify-buffer
)
2862 (define-key vhdl-mode-map
"\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process
)
2863 (define-key vhdl-mode-map
"\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer
)
2864 (define-key vhdl-mode-map
"\C-c\C-i\C-f" 'vhdl-fontify-buffer
)
2865 (define-key vhdl-mode-map
"\C-c\C-i\C-s" 'vhdl-statistics-buffer
)
2866 (define-key vhdl-mode-map
"\C-c\M-m" 'vhdl-show-messages
)
2867 (define-key vhdl-mode-map
"\C-c\C-h" 'vhdl-doc-mode
)
2868 (define-key vhdl-mode-map
"\C-c\C-v" 'vhdl-version
)
2869 (define-key vhdl-mode-map
"\M-\t" 'insert-tab
)
2870 ;; insert commands bindings
2871 (define-key vhdl-mode-map
"\C-c\C-i\C-t" 'vhdl-template-insert-construct
)
2872 (define-key vhdl-mode-map
"\C-c\C-i\C-p" 'vhdl-template-insert-package
)
2873 (define-key vhdl-mode-map
"\C-c\C-i\C-d" 'vhdl-template-insert-directive
)
2874 (define-key vhdl-mode-map
"\C-c\C-i\C-m" 'vhdl-model-insert
)
2875 ;; electric key bindings
2876 (define-key vhdl-mode-map
" " 'vhdl-electric-space
)
2877 (when vhdl-intelligent-tab
2878 (define-key vhdl-mode-map
"\t" 'vhdl-electric-tab
))
2879 (define-key vhdl-mode-map
"\r" 'vhdl-electric-return
)
2880 (define-key vhdl-mode-map
"-" 'vhdl-electric-dash
)
2881 (define-key vhdl-mode-map
"[" 'vhdl-electric-open-bracket
)
2882 (define-key vhdl-mode-map
"]" 'vhdl-electric-close-bracket
)
2883 (define-key vhdl-mode-map
"'" 'vhdl-electric-quote
)
2884 (define-key vhdl-mode-map
";" 'vhdl-electric-semicolon
)
2885 (define-key vhdl-mode-map
"," 'vhdl-electric-comma
)
2886 (define-key vhdl-mode-map
"." 'vhdl-electric-period
)
2887 (when (vhdl-standard-p 'ams
)
2888 (define-key vhdl-mode-map
"=" 'vhdl-electric-equal
)))
2890 ;; initialize mode map for VHDL Mode
2891 (vhdl-mode-map-init)
2893 ;; define special minibuffer keymap for enabling word completion in minibuffer
2894 ;; (useful in template generator prompts)
2895 (defvar vhdl-minibuffer-local-map
2896 (let ((map (make-sparse-keymap)))
2897 (set-keymap-parent map minibuffer-local-map
)
2898 (when vhdl-word-completion-in-minibuffer
2899 (define-key map
"\t" 'vhdl-minibuffer-tab
))
2901 "Keymap for minibuffer used in VHDL Mode.")
2903 ;; set up electric character functions to work with
2904 ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
2908 (put sym
'delete-selection t
) ; for `delete-selection-mode' (Emacs)
2909 (put sym
'pending-delete t
))) ; for `pending-delete-mode' (XEmacs)
2910 '(vhdl-electric-space
2912 vhdl-electric-return
2914 vhdl-electric-open-bracket
2915 vhdl-electric-close-bracket
2917 vhdl-electric-semicolon
2919 vhdl-electric-period
2920 vhdl-electric-equal
))
2922 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2925 (defvar vhdl-mode-syntax-table
2926 (let ((st (make-syntax-table)))
2927 ;; define punctuation
2928 (modify-syntax-entry ?\
# "." st
)
2929 (modify-syntax-entry ?\$
"." st
)
2930 (modify-syntax-entry ?\%
"." st
)
2931 (modify-syntax-entry ?\
& "." st
)
2932 (modify-syntax-entry ?
\' "." st
)
2933 (modify-syntax-entry ?\
* "." st
)
2934 (modify-syntax-entry ?\
+ "." st
)
2935 (modify-syntax-entry ?\.
"." st
)
2936 (modify-syntax-entry ?\
/ "." st
)
2937 (modify-syntax-entry ?\
: "." st
)
2938 (modify-syntax-entry ?\
; "." st)
2939 (modify-syntax-entry ?\
< "." st
)
2940 (modify-syntax-entry ?\
= "." st
)
2941 (modify-syntax-entry ?\
> "." st
)
2942 (modify-syntax-entry ?
\\ "." st
)
2943 (modify-syntax-entry ?\|
"." st
)
2945 (modify-syntax-entry ?
\" "\"" st
)
2946 ;; define underscore
2947 (modify-syntax-entry ?\_
(if vhdl-underscore-is-part-of-word
"w" "_") st
)
2948 ;; a single hyphen is punctuation, but a double hyphen starts a comment
2949 (modify-syntax-entry ?\-
". 12" st
)
2950 ;; and \n and \^M end a comment
2951 (modify-syntax-entry ?
\n ">" st
)
2952 (modify-syntax-entry ?\^M
">" st
)
2953 ;; define parentheses to match
2954 (modify-syntax-entry ?\
( "()" st
)
2955 (modify-syntax-entry ?\
) ")(" st
)
2956 (modify-syntax-entry ?\
[ "(]" st
)
2957 (modify-syntax-entry ?\
] ")[" st
)
2958 (modify-syntax-entry ?\
{ "(}" st
)
2959 (modify-syntax-entry ?\
} "){" st
)
2961 "Syntax table used in `vhdl-mode' buffers.")
2963 (defvar vhdl-mode-ext-syntax-table
2964 ;; Extended syntax table including '_' (for simpler search regexps).
2965 (let ((st (copy-syntax-table vhdl-mode-syntax-table
)))
2966 (modify-syntax-entry ?_
"w" st
)
2968 "Syntax table extended by `_' used in `vhdl-mode' buffers.")
2970 (defvar vhdl-syntactic-context nil
2971 "Buffer local variable containing syntactic analysis list.")
2972 (make-variable-buffer-local 'vhdl-syntactic-context
)
2974 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2975 ;; Abbrev ook bindings
2977 (defvar vhdl-mode-abbrev-table nil
2978 "Abbrev table to use in `vhdl-mode' buffers.")
2980 (defun vhdl-mode-abbrev-table-init ()
2981 "Initialize `vhdl-mode-abbrev-table'."
2982 (define-abbrev-table 'vhdl-mode-abbrev-table
2984 (when (memq 'vhdl vhdl-electric-keywords
)
2986 (mapcar (lambda (x) (list (car x
) "" (cdr x
) 0 'system
))
2988 ("--" . vhdl-template-display-comment-hook
)
2989 ("abs" . vhdl-template-default-hook
)
2990 ("access" . vhdl-template-default-hook
)
2991 ("after" . vhdl-template-default-hook
)
2992 ("alias" . vhdl-template-alias-hook
)
2993 ("all" . vhdl-template-default-hook
)
2994 ("and" . vhdl-template-default-hook
)
2995 ("arch" . vhdl-template-architecture-hook
)
2996 ("architecture" . vhdl-template-architecture-hook
)
2997 ("array" . vhdl-template-default-hook
)
2998 ("assert" . vhdl-template-assert-hook
)
2999 ("attr" . vhdl-template-attribute-hook
)
3000 ("attribute" . vhdl-template-attribute-hook
)
3001 ("begin" . vhdl-template-default-indent-hook
)
3002 ("block" . vhdl-template-block-hook
)
3003 ("body" . vhdl-template-default-hook
)
3004 ("buffer" . vhdl-template-default-hook
)
3005 ("bus" . vhdl-template-default-hook
)
3006 ("case" . vhdl-template-case-hook
)
3007 ("comp" . vhdl-template-component-hook
)
3008 ("component" . vhdl-template-component-hook
)
3009 ("cond" . vhdl-template-conditional-signal-asst-hook
)
3010 ("conditional" . vhdl-template-conditional-signal-asst-hook
)
3011 ("conf" . vhdl-template-configuration-hook
)
3012 ("configuration" . vhdl-template-configuration-hook
)
3013 ("cons" . vhdl-template-constant-hook
)
3014 ("constant" . vhdl-template-constant-hook
)
3015 ("disconnect" . vhdl-template-disconnect-hook
)
3016 ("downto" . vhdl-template-default-hook
)
3017 ("else" . vhdl-template-else-hook
)
3018 ("elseif" . vhdl-template-elsif-hook
)
3019 ("elsif" . vhdl-template-elsif-hook
)
3020 ("end" . vhdl-template-default-indent-hook
)
3021 ("entity" . vhdl-template-entity-hook
)
3022 ("exit" . vhdl-template-exit-hook
)
3023 ("file" . vhdl-template-file-hook
)
3024 ("for" . vhdl-template-for-hook
)
3025 ("func" . vhdl-template-function-hook
)
3026 ("function" . vhdl-template-function-hook
)
3027 ("generic" . vhdl-template-generic-hook
)
3028 ("group" . vhdl-template-group-hook
)
3029 ("guarded" . vhdl-template-default-hook
)
3030 ("if" . vhdl-template-if-hook
)
3031 ("impure" . vhdl-template-default-hook
)
3032 ("in" . vhdl-template-default-hook
)
3033 ("inertial" . vhdl-template-default-hook
)
3034 ("inout" . vhdl-template-default-hook
)
3035 ("inst" . vhdl-template-instance-hook
)
3036 ("instance" . vhdl-template-instance-hook
)
3037 ("is" . vhdl-template-default-hook
)
3038 ("label" . vhdl-template-default-hook
)
3039 ("library" . vhdl-template-library-hook
)
3040 ("linkage" . vhdl-template-default-hook
)
3041 ("literal" . vhdl-template-default-hook
)
3042 ("loop" . vhdl-template-bare-loop-hook
)
3043 ("map" . vhdl-template-map-hook
)
3044 ("mod" . vhdl-template-default-hook
)
3045 ("nand" . vhdl-template-default-hook
)
3046 ("new" . vhdl-template-default-hook
)
3047 ("next" . vhdl-template-next-hook
)
3048 ("nor" . vhdl-template-default-hook
)
3049 ("not" . vhdl-template-default-hook
)
3050 ("null" . vhdl-template-default-hook
)
3051 ("of" . vhdl-template-default-hook
)
3052 ("on" . vhdl-template-default-hook
)
3053 ("open" . vhdl-template-default-hook
)
3054 ("or" . vhdl-template-default-hook
)
3055 ("others" . vhdl-template-others-hook
)
3056 ("out" . vhdl-template-default-hook
)
3057 ("pack" . vhdl-template-package-hook
)
3058 ("package" . vhdl-template-package-hook
)
3059 ("port" . vhdl-template-port-hook
)
3060 ("postponed" . vhdl-template-default-hook
)
3061 ("procedure" . vhdl-template-procedure-hook
)
3062 ("process" . vhdl-template-process-hook
)
3063 ("pure" . vhdl-template-default-hook
)
3064 ("range" . vhdl-template-default-hook
)
3065 ("record" . vhdl-template-default-hook
)
3066 ("register" . vhdl-template-default-hook
)
3067 ("reject" . vhdl-template-default-hook
)
3068 ("rem" . vhdl-template-default-hook
)
3069 ("report" . vhdl-template-report-hook
)
3070 ("return" . vhdl-template-return-hook
)
3071 ("rol" . vhdl-template-default-hook
)
3072 ("ror" . vhdl-template-default-hook
)
3073 ("select" . vhdl-template-selected-signal-asst-hook
)
3074 ("severity" . vhdl-template-default-hook
)
3075 ("shared" . vhdl-template-default-hook
)
3076 ("sig" . vhdl-template-signal-hook
)
3077 ("signal" . vhdl-template-signal-hook
)
3078 ("sla" . vhdl-template-default-hook
)
3079 ("sll" . vhdl-template-default-hook
)
3080 ("sra" . vhdl-template-default-hook
)
3081 ("srl" . vhdl-template-default-hook
)
3082 ("subtype" . vhdl-template-subtype-hook
)
3083 ("then" . vhdl-template-default-hook
)
3084 ("to" . vhdl-template-default-hook
)
3085 ("transport" . vhdl-template-default-hook
)
3086 ("type" . vhdl-template-type-hook
)
3087 ("unaffected" . vhdl-template-default-hook
)
3088 ("units" . vhdl-template-default-hook
)
3089 ("until" . vhdl-template-default-hook
)
3090 ("use" . vhdl-template-use-hook
)
3091 ("var" . vhdl-template-variable-hook
)
3092 ("variable" . vhdl-template-variable-hook
)
3093 ("wait" . vhdl-template-wait-hook
)
3094 ("when" . vhdl-template-when-hook
)
3095 ("while" . vhdl-template-while-loop-hook
)
3096 ("with" . vhdl-template-with-hook
)
3097 ("xnor" . vhdl-template-default-hook
)
3098 ("xor" . vhdl-template-default-hook
)
3100 ;; VHDL-AMS keywords
3101 (when (and (memq 'vhdl vhdl-electric-keywords
) (vhdl-standard-p 'ams
))
3102 (mapcar (lambda (x) (list (car x
) "" (cdr x
) 0 'system
))
3104 ("across" . vhdl-template-default-hook
)
3105 ("break" . vhdl-template-break-hook
)
3106 ("limit" . vhdl-template-limit-hook
)
3107 ("nature" . vhdl-template-nature-hook
)
3108 ("noise" . vhdl-template-default-hook
)
3109 ("procedural" . vhdl-template-procedural-hook
)
3110 ("quantity" . vhdl-template-quantity-hook
)
3111 ("reference" . vhdl-template-default-hook
)
3112 ("spectrum" . vhdl-template-default-hook
)
3113 ("subnature" . vhdl-template-subnature-hook
)
3114 ("terminal" . vhdl-template-terminal-hook
)
3115 ("through" . vhdl-template-default-hook
)
3116 ("tolerance" . vhdl-template-default-hook
)
3118 ;; user model keywords
3119 (when (memq 'user vhdl-electric-keywords
)
3120 (let (abbrev-list keyword
)
3121 (dolist (elem vhdl-model-alist
)
3122 (setq keyword
(nth 3 elem
))
3123 (unless (equal keyword
"")
3124 (push (list keyword
""
3126 "vhdl-model" (nth 0 elem
) "hook") 0 'system
)
3130 ;; initialize abbrev table for VHDL Mode
3131 (vhdl-mode-abbrev-table-init)
3133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3134 ;; Template completion lists
3136 (defvar vhdl-template-construct-alist nil
3137 "List of built-in construct templates.")
3139 (defun vhdl-template-construct-alist-init ()
3140 "Initialize `vhdl-template-construct-alist'."
3142 vhdl-template-construct-alist
3145 ("alias declaration" vhdl-template-alias
)
3146 ("architecture body" vhdl-template-architecture
)
3147 ("assertion" vhdl-template-assert
)
3148 ("attribute declaration" vhdl-template-attribute-decl
)
3149 ("attribute specification" vhdl-template-attribute-spec
)
3150 ("block configuration" vhdl-template-block-configuration
)
3151 ("block statement" vhdl-template-block
)
3152 ("case statement" vhdl-template-case-is
)
3153 ("component configuration" vhdl-template-component-conf
)
3154 ("component declaration" vhdl-template-component-decl
)
3155 ("component instantiation statement" vhdl-template-component-inst
)
3156 ("conditional signal assignment" vhdl-template-conditional-signal-asst
)
3157 ("configuration declaration" vhdl-template-configuration-decl
)
3158 ("configuration specification" vhdl-template-configuration-spec
)
3159 ("constant declaration" vhdl-template-constant
)
3160 ("disconnection specification" vhdl-template-disconnect
)
3161 ("entity declaration" vhdl-template-entity
)
3162 ("exit statement" vhdl-template-exit
)
3163 ("file declaration" vhdl-template-file
)
3164 ("generate statement" vhdl-template-generate
)
3165 ("generic clause" vhdl-template-generic
)
3166 ("group declaration" vhdl-template-group-decl
)
3167 ("group template declaration" vhdl-template-group-template
)
3168 ("if statement" vhdl-template-if-then
)
3169 ("library clause" vhdl-template-library
)
3170 ("loop statement" vhdl-template-loop
)
3171 ("next statement" vhdl-template-next
)
3172 ("package declaration" vhdl-template-package-decl
)
3173 ("package body" vhdl-template-package-body
)
3174 ("port clause" vhdl-template-port
)
3175 ("process statement" vhdl-template-process
)
3176 ("report statement" vhdl-template-report
)
3177 ("return statement" vhdl-template-return
)
3178 ("selected signal assignment" vhdl-template-selected-signal-asst
)
3179 ("signal declaration" vhdl-template-signal
)
3180 ("subprogram declaration" vhdl-template-subprogram-decl
)
3181 ("subprogram body" vhdl-template-subprogram-body
)
3182 ("subtype declaration" vhdl-template-subtype
)
3183 ("type declaration" vhdl-template-type
)
3184 ("use clause" vhdl-template-use
)
3185 ("variable declaration" vhdl-template-variable
)
3186 ("wait statement" vhdl-template-wait
)
3188 (when (vhdl-standard-p 'ams
)
3190 ("break statement" vhdl-template-break
)
3191 ("nature declaration" vhdl-template-nature
)
3192 ("quantity declaration" vhdl-template-quantity
)
3193 ("simultaneous case statement" vhdl-template-case-use
)
3194 ("simultaneous if statement" vhdl-template-if-use
)
3195 ("simultaneous procedural statement" vhdl-template-procedural
)
3196 ("step limit specification" vhdl-template-limit
)
3197 ("subnature declaration" vhdl-template-subnature
)
3198 ("terminal declaration" vhdl-template-terminal
)
3201 ;; initialize for VHDL Mode
3202 (vhdl-template-construct-alist-init)
3204 (defvar vhdl-template-package-alist nil
3205 "List of built-in package templates.")
3207 (defun vhdl-template-package-alist-init ()
3208 "Initialize `vhdl-template-package-alist'."
3210 vhdl-template-package-alist
3213 ("numeric_bit" vhdl-template-package-numeric-bit
)
3214 ("numeric_std" vhdl-template-package-numeric-std
)
3215 ("std_logic_1164" vhdl-template-package-std-logic-1164
)
3216 ("std_logic_arith" vhdl-template-package-std-logic-arith
)
3217 ("std_logic_misc" vhdl-template-package-std-logic-misc
)
3218 ("std_logic_signed" vhdl-template-package-std-logic-signed
)
3219 ("std_logic_textio" vhdl-template-package-std-logic-textio
)
3220 ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned
)
3221 ("textio" vhdl-template-package-textio
)
3223 (when (vhdl-standard-p 'math
)
3225 ("math_complex" vhdl-template-package-math-complex
)
3226 ("math_real" vhdl-template-package-math-real
)
3229 ;; initialize for VHDL Mode
3230 (vhdl-template-package-alist-init)
3232 (defvar vhdl-template-directive-alist
3234 ("translate_on" vhdl-template-directive-translate-on
)
3235 ("translate_off" vhdl-template-directive-translate-off
)
3236 ("synthesis_on" vhdl-template-directive-synthesis-on
)
3237 ("synthesis_off" vhdl-template-directive-synthesis-off
)
3239 "List of built-in directive templates.")
3242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3247 ;; VHDL menu (using `easy-menu.el')
3249 (defun vhdl-customize ()
3250 "Call the customize function with `vhdl' as argument."
3252 (customize-browse 'vhdl
))
3254 (defun vhdl-create-mode-menu ()
3255 "Create VHDL Mode menu."
3259 ["None" (vhdl-set-project "")
3260 :style radio
:selected
(null vhdl-project
)]
3262 ;; add menu entries for defined projects
3263 (let ((project-alist vhdl-project-alist
) menu-list name
)
3264 (while project-alist
3265 (setq name
(caar project-alist
))
3267 (cons `[,name
(vhdl-set-project ,name
)
3268 :style radio
:selected
(equal ,name vhdl-project
)]
3270 (setq project-alist
(cdr project-alist
)))
3272 (if vhdl-project-sort
3274 (function (lambda (a b
) (string< (elt a
0) (elt b
0)))))
3275 (nreverse menu-list
)))
3276 (vhdl-menu-split menu-list
"Project"))
3278 ["Select Project..." vhdl-set-project t
]
3279 ["Set As Default Project" vhdl-set-default-project t
]
3281 ["Duplicate Project" vhdl-duplicate-project vhdl-project
]
3282 ["Import Project..." vhdl-import-project
3283 :keys
"C-c C-p C-m" :active t
]
3284 ["Export Project" vhdl-export-project vhdl-project
]
3286 ["Customize Project..." (customize-option 'vhdl-project-alist
) t
]))
3289 ["Compile Buffer" vhdl-compile t
]
3290 ["Stop Compilation" kill-compilation t
]
3292 ["Make" vhdl-make t
]
3293 ["Generate Makefile" vhdl-generate-makefile t
]
3295 ["Next Error" next-error t
]
3296 ["Previous Error" previous-error t
]
3297 ["First Error" first-error t
]
3301 ;; add menu entries for defined compilers
3302 (let ((comp-alist vhdl-compiler-alist
) menu-list name
)
3304 (setq name
(caar comp-alist
))
3306 (cons `[,name
(setq vhdl-compiler
,name
)
3307 :style radio
:selected
(equal ,name vhdl-compiler
)]
3309 (setq comp-alist
(cdr comp-alist
)))
3310 (setq menu-list
(nreverse menu-list
))
3311 (vhdl-menu-split menu-list
"Compiler"))
3313 ["Select Compiler..." vhdl-set-compiler t
]
3315 ["Customize Compiler..."
3316 (customize-option 'vhdl-compiler-alist
) t
])))
3321 ["Alias" vhdl-template-alias t
]
3322 ["Architecture" vhdl-template-architecture t
]
3323 ["Assert" vhdl-template-assert t
]
3324 ["Attribute (Decl)" vhdl-template-attribute-decl t
]
3325 ["Attribute (Spec)" vhdl-template-attribute-spec t
]
3326 ["Block" vhdl-template-block t
]
3327 ["Case" vhdl-template-case-is t
]
3328 ["Component (Decl)" vhdl-template-component-decl t
]
3329 ["(Component) Instance" vhdl-template-component-inst t
]
3330 ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t
]
3331 ["Configuration (Block)" vhdl-template-block-configuration t
]
3332 ["Configuration (Comp)" vhdl-template-component-conf t
]
3333 ["Configuration (Decl)" vhdl-template-configuration-decl t
]
3334 ["Configuration (Spec)" vhdl-template-configuration-spec t
]
3335 ["Constant" vhdl-template-constant t
]
3336 ["Disconnect" vhdl-template-disconnect t
]
3337 ["Else" vhdl-template-else t
]
3338 ["Elsif" vhdl-template-elsif t
]
3339 ["Entity" vhdl-template-entity t
]
3340 ["Exit" vhdl-template-exit t
]
3341 ["File" vhdl-template-file t
]
3342 ["For (Generate)" vhdl-template-for-generate t
]
3343 ["For (Loop)" vhdl-template-for-loop t
]
3344 ["Function (Body)" vhdl-template-function-body t
]
3345 ["Function (Decl)" vhdl-template-function-decl t
]
3346 ["Generic" vhdl-template-generic t
]
3347 ["Group (Decl)" vhdl-template-group-decl t
]
3348 ["Group (Template)" vhdl-template-group-template t
])
3350 ["If (Generate)" vhdl-template-if-generate t
]
3351 ["If (Then)" vhdl-template-if-then t
]
3352 ["Library" vhdl-template-library t
]
3353 ["Loop" vhdl-template-bare-loop t
]
3354 ["Map" vhdl-template-map t
]
3355 ["Next" vhdl-template-next t
]
3356 ["Others (Aggregate)" vhdl-template-others t
]
3357 ["Package (Decl)" vhdl-template-package-decl t
]
3358 ["Package (Body)" vhdl-template-package-body t
]
3359 ["Port" vhdl-template-port t
]
3360 ["Procedure (Body)" vhdl-template-procedure-body t
]
3361 ["Procedure (Decl)" vhdl-template-procedure-decl t
]
3362 ["Process (Comb)" vhdl-template-process-comb t
]
3363 ["Process (Seq)" vhdl-template-process-seq t
]
3364 ["Report" vhdl-template-report t
]
3365 ["Return" vhdl-template-return t
]
3366 ["Select" vhdl-template-selected-signal-asst t
]
3367 ["Signal" vhdl-template-signal t
]
3368 ["Subtype" vhdl-template-subtype t
]
3369 ["Type" vhdl-template-type t
]
3370 ["Use" vhdl-template-use t
]
3371 ["Variable" vhdl-template-variable t
]
3372 ["Wait" vhdl-template-wait t
]
3373 ["(Clocked Wait)" vhdl-template-clocked-wait t
]
3374 ["When" vhdl-template-when t
]
3375 ["While (Loop)" vhdl-template-while-loop t
]
3376 ["With" vhdl-template-with t
]))
3377 (when (vhdl-standard-p 'ams
)
3378 '(("VHDL-AMS Construct"
3379 ["Break" vhdl-template-break t
]
3380 ["Case (Use)" vhdl-template-case-use t
]
3381 ["If (Use)" vhdl-template-if-use t
]
3382 ["Limit" vhdl-template-limit t
]
3383 ["Nature" vhdl-template-nature t
]
3384 ["Procedural" vhdl-template-procedural t
]
3385 ["Quantity (Free)" vhdl-template-quantity-free t
]
3386 ["Quantity (Branch)" vhdl-template-quantity-branch t
]
3387 ["Quantity (Source)" vhdl-template-quantity-source t
]
3388 ["Subnature" vhdl-template-subnature t
]
3389 ["Terminal" vhdl-template-terminal t
])))
3390 '(["Insert Construct..." vhdl-template-insert-construct
3391 :keys
"C-c C-i C-t"]
3396 '(["numeric_bit" vhdl-template-package-numeric-bit t
]
3397 ["numeric_std" vhdl-template-package-numeric-std t
]
3398 ["std_logic_1164" vhdl-template-package-std-logic-1164 t
]
3399 ["textio" vhdl-template-package-textio t
]
3401 ["std_logic_arith" vhdl-template-package-std-logic-arith t
]
3402 ["std_logic_signed" vhdl-template-package-std-logic-signed t
]
3403 ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t
]
3404 ["std_logic_misc" vhdl-template-package-std-logic-misc t
]
3405 ["std_logic_textio" vhdl-template-package-std-logic-textio t
]
3407 (when (vhdl-standard-p 'ams
)
3408 '(["fundamental_constants" vhdl-template-package-fundamental-constants t
]
3409 ["material_constants" vhdl-template-package-material-constants t
]
3410 ["energy_systems" vhdl-template-package-energy-systems t
]
3411 ["electrical_systems" vhdl-template-package-electrical-systems t
]
3412 ["mechanical_systems" vhdl-template-package-mechanical-systems t
]
3413 ["radiant_systems" vhdl-template-package-radiant-systems t
]
3414 ["thermal_systems" vhdl-template-package-thermal-systems t
]
3415 ["fluidic_systems" vhdl-template-package-fluidic-systems t
]
3417 (when (vhdl-standard-p 'math
)
3418 '(["math_complex" vhdl-template-package-math-complex t
]
3419 ["math_real" vhdl-template-package-math-real t
]
3421 '(["Insert Package..." vhdl-template-insert-package
3422 :keys
"C-c C-i C-p"])))
3424 ["translate_on" vhdl-template-directive-translate-on t
]
3425 ["translate_off" vhdl-template-directive-translate-off t
]
3426 ["synthesis_on" vhdl-template-directive-synthesis-on t
]
3427 ["synthesis_off" vhdl-template-directive-synthesis-off t
]
3429 ["Insert Directive..." vhdl-template-insert-directive
3430 :keys
"C-c C-i C-d"])
3432 ["Insert Header" vhdl-template-header
:keys
"C-c C-t C-h"]
3433 ["Insert Footer" vhdl-template-footer t
]
3434 ["Insert Date" vhdl-template-insert-date t
]
3435 ["Modify Date" vhdl-template-modify
:keys
"C-c C-t C-m"]
3437 ["Query Next Prompt" vhdl-template-search-prompt t
]))
3440 ;; add menu entries for defined models
3441 (let ((model-alist vhdl-model-alist
) menu-list model
)
3443 (setq model
(car model-alist
))
3448 (vhdl-function-name "vhdl-model" (nth 0 model
))
3449 :keys
(concat "C-c C-m " (key-description (nth 2 model
))))
3451 (setq model-alist
(cdr model-alist
)))
3452 (setq menu-list
(nreverse menu-list
))
3453 (vhdl-menu-split menu-list
"Model"))
3455 ["Insert Model..." vhdl-model-insert
:keys
"C-c C-i C-m"]
3456 ["Customize Model..." (customize-option 'vhdl-model-alist
) t
]))
3458 ["Copy" vhdl-port-copy t
]
3460 ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list
]
3461 ["Paste As Component" vhdl-port-paste-component vhdl-port-list
]
3462 ["Paste As Instance" vhdl-port-paste-instance
3463 :keys
"C-c C-p C-i" :active vhdl-port-list
]
3464 ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list
]
3465 ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list
]
3466 ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list
]
3467 ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list
]
3469 ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list
]
3471 ["Flatten" vhdl-port-flatten
3472 :style toggle
:selected vhdl-port-flattened
:active vhdl-port-list
]
3473 ["Reverse Direction" vhdl-port-reverse-direction
3474 :style toggle
:selected vhdl-port-reversed-direction
:active vhdl-port-list
])
3476 ["New Component" vhdl-compose-new-component t
]
3477 ["Copy Component" vhdl-port-copy t
]
3478 ["Place Component" vhdl-compose-place-component vhdl-port-list
]
3479 ["Wire Components" vhdl-compose-wire-components t
]
3481 ["Generate Configuration" vhdl-compose-configuration t
]
3482 ["Generate Components Package" vhdl-compose-components-package t
])
3484 ["Copy" vhdl-subprog-copy t
]
3486 ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list
]
3487 ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list
]
3488 ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list
]
3490 ["Flatten" vhdl-subprog-flatten
3491 :style toggle
:selected vhdl-subprog-flattened
:active vhdl-subprog-list
])
3494 ["(Un)Comment Out Region" vhdl-comment-uncomment-region
(mark)]
3496 ["Insert Inline Comment" vhdl-comment-append-inline t
]
3497 ["Insert Horizontal Line" vhdl-comment-display-line t
]
3498 ["Insert Display Comment" vhdl-comment-display t
]
3500 ["Fill Comment" fill-paragraph t
]
3501 ["Fill Comment Region" fill-region
(mark)]
3502 ["Kill Comment Region" vhdl-comment-kill-region
(mark)]
3503 ["Kill Inline Comment Region" vhdl-comment-kill-inline-region
(mark)])
3505 ["Kill" vhdl-line-kill t
]
3506 ["Copy" vhdl-line-copy t
]
3507 ["Yank" vhdl-line-yank t
]
3508 ["Expand" vhdl-line-expand t
]
3510 ["Transpose Next" vhdl-line-transpose-next t
]
3511 ["Transpose Prev" vhdl-line-transpose-previous t
]
3512 ["Open" vhdl-line-open t
]
3513 ["Join" vhdl-delete-indentation t
]
3515 ["Goto" goto-line t
]
3516 ["(Un)Comment Out" vhdl-comment-uncomment-line t
])
3518 ["Forward Statement" vhdl-end-of-statement t
]
3519 ["Backward Statement" vhdl-beginning-of-statement t
]
3520 ["Forward Expression" vhdl-forward-sexp t
]
3521 ["Backward Expression" vhdl-backward-sexp t
]
3522 ["Forward Same Indent" vhdl-forward-same-indent t
]
3523 ["Backward Same Indent" vhdl-backward-same-indent t
]
3524 ["Forward Function" vhdl-end-of-defun
t]
3525 ["Backward Function" vhdl-beginning-of-defun
t]
3526 ["Mark Function" vhdl-mark-defun
t])
3529 ["Line" indent-according-to-mode
:keys
"C-c C-i C-l"]
3530 ["Group" vhdl-indent-group
:keys
"C-c C-i C-g"]
3531 ["Region" vhdl-indent-region
(mark)]
3532 ["Buffer" vhdl-indent-buffer
:keys
"C-c C-i C-b"])
3534 ["Group" vhdl-align-group t
]
3535 ["Same Indent" vhdl-align-same-indent
:keys
"C-c C-a C-i"]
3536 ["List" vhdl-align-list t
]
3537 ["Declarations" vhdl-align-declarations t
]
3538 ["Region" vhdl-align-region
(mark)]
3539 ["Buffer" vhdl-align-buffer t
]
3541 ["Inline Comment Group" vhdl-align-inline-comment-group t
]
3542 ["Inline Comment Region" vhdl-align-inline-comment-region
(mark)]
3543 ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t
])
3545 ["List" vhdl-fill-list t
]
3546 ["Group" vhdl-fill-group t
]
3547 ["Same Indent" vhdl-fill-same-indent
:keys
"C-c C-f C-i"]
3548 ["Region" vhdl-fill-region
(mark)])
3550 ["Region" vhdl-beautify-region
(mark)]
3551 ["Buffer" vhdl-beautify-buffer t
])
3553 ["Generic/Port Clause" vhdl-fix-clause t
]
3554 ["Generic/Port Clause Buffer" vhdl-fix-clause t
]
3556 ["Case Region" vhdl-fix-case-region
(mark)]
3557 ["Case Buffer" vhdl-fix-case-buffer t
]
3559 ["Whitespace Region" vhdl-fixup-whitespace-region
(mark)]
3560 ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t
]
3562 ["Statement Region" vhdl-fix-statement-region
(mark)]
3563 ["Statement Buffer" vhdl-fix-statement-buffer t
]
3565 ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t
])
3567 ["Sensitivity List" vhdl-update-sensitivity-list-process t
]
3568 ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t
])
3570 ["Fontify Buffer" vhdl-fontify-buffer t
]
3571 ["Statistics Buffer" vhdl-statistics-buffer t
]
3572 ["Show Messages" vhdl-show-messages t
]
3573 ["Syntactic Info" vhdl-show-syntactic-information t
]
3575 ["Speedbar" vhdl-speedbar t
]
3576 ["Hide/Show" vhdl-hs-minor-mode t
]
3579 ["VHDL Mode" vhdl-doc-mode
:keys
"C-c C-h"]
3580 ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes
) t
]
3581 ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords
) t
]
3582 ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style
) t
])
3583 ["Version" vhdl-version t
]
3584 ["Bug Report..." vhdl-submit-bug-report t
]
3589 (progn (customize-set-variable 'vhdl-electric-mode
3590 (not vhdl-electric-mode
))
3591 (vhdl-mode-line-update))
3592 :style toggle
:selected vhdl-electric-mode
:keys
"C-c C-m C-e"]
3594 (progn (customize-set-variable 'vhdl-stutter-mode
3595 (not vhdl-stutter-mode
))
3596 (vhdl-mode-line-update))
3597 :style toggle
:selected vhdl-stutter-mode
:keys
"C-c C-m C-s"]
3599 (progn (customize-set-variable 'vhdl-indent-tabs-mode
3600 (not vhdl-indent-tabs-mode
))
3601 (setq indent-tabs-mode vhdl-indent-tabs-mode
))
3602 :style toggle
:selected vhdl-indent-tabs-mode
]
3604 ["Customize Group..." (customize-group 'vhdl-mode
) t
])
3606 ["Project Setup..." (customize-option 'vhdl-project-alist
) t
]
3608 '("Selected Project at Startup"
3609 ["None" (progn (customize-set-variable 'vhdl-project nil
)
3610 (vhdl-set-project ""))
3611 :style radio
:selected
(null vhdl-project
)]
3613 ;; add menu entries for defined projects
3614 (let ((project-alist vhdl-project-alist
) menu-list name
)
3615 (while project-alist
3616 (setq name
(caar project-alist
))
3618 (cons `[,name
(progn (customize-set-variable
3619 'vhdl-project
,name
)
3620 (vhdl-set-project ,name
))
3621 :style radio
:selected
(equal ,name vhdl-project
)]
3623 (setq project-alist
(cdr project-alist
)))
3624 (setq menu-list
(nreverse menu-list
))
3625 (vhdl-menu-split menu-list
"Project")))
3626 ["Setup File Name..." (customize-option 'vhdl-project-file-name
) t
]
3627 ("Auto Load Setup File"
3629 (customize-set-variable 'vhdl-project-auto-load
3630 (if (memq 'startup vhdl-project-auto-load
)
3631 (delq 'startup vhdl-project-auto-load
)
3632 (cons 'startup vhdl-project-auto-load
)))
3633 :style toggle
:selected
(memq 'startup vhdl-project-auto-load
)])
3635 (customize-set-variable 'vhdl-project-sort
(not vhdl-project-sort
))
3636 :style toggle
:selected vhdl-project-sort
]
3638 ["Customize Group..." (customize-group 'vhdl-project
) t
])
3640 ["Compiler Setup..." (customize-option 'vhdl-compiler-alist
) t
]
3642 '("Selected Compiler at Startup")
3643 ;; add menu entries for defined compilers
3644 (let ((comp-alist vhdl-compiler-alist
) menu-list name
)
3646 (setq name
(caar comp-alist
))
3648 (cons `[,name
(customize-set-variable 'vhdl-compiler
,name
)
3649 :style radio
:selected
(equal ,name vhdl-compiler
)]
3651 (setq comp-alist
(cdr comp-alist
)))
3652 (setq menu-list
(nreverse menu-list
))
3653 (vhdl-menu-split menu-list
"Compiler")))
3654 ["Use Local Error Regexp"
3655 (customize-set-variable 'vhdl-compile-use-local-error-regexp
3656 (not vhdl-compile-use-local-error-regexp
))
3657 :style toggle
:selected vhdl-compile-use-local-error-regexp
]
3658 ["Makefile Default Targets..."
3659 (customize-option 'vhdl-makefile-default-targets
) t
]
3660 ["Makefile Generation Hook..."
3661 (customize-option 'vhdl-makefile-generation-hook
) t
]
3662 ["Default Library Name" (customize-option 'vhdl-default-library
) t
]
3664 ["Customize Group..." (customize-group 'vhdl-compiler
) t
])
3668 (progn (customize-set-variable 'vhdl-standard
3669 (list '87 (cadr vhdl-standard
)))
3670 (vhdl-activate-customizations))
3671 :style radio
:selected
(eq '87 (car vhdl-standard
))]
3673 (progn (customize-set-variable 'vhdl-standard
3674 (list '93 (cadr vhdl-standard
)))
3675 (vhdl-activate-customizations))
3676 :style radio
:selected
(eq '93 (car vhdl-standard
))]
3679 (progn (customize-set-variable
3680 'vhdl-standard
(list (car vhdl-standard
)
3681 (if (memq 'ams
(cadr vhdl-standard
))
3682 (delq 'ams
(cadr vhdl-standard
))
3683 (cons 'ams
(cadr vhdl-standard
)))))
3684 (vhdl-activate-customizations))
3685 :style toggle
:selected
(memq 'ams
(cadr vhdl-standard
))]
3687 (progn (customize-set-variable
3688 'vhdl-standard
(list (car vhdl-standard
)
3689 (if (memq 'math
(cadr vhdl-standard
))
3690 (delq 'math
(cadr vhdl-standard
))
3691 (cons 'math
(cadr vhdl-standard
)))))
3692 (vhdl-activate-customizations))
3693 :style toggle
:selected
(memq 'math
(cadr vhdl-standard
))])
3694 ["Indentation Offset..." (customize-option 'vhdl-basic-offset
) t
]
3695 ["Upper Case Keywords"
3696 (customize-set-variable 'vhdl-upper-case-keywords
3697 (not vhdl-upper-case-keywords
))
3698 :style toggle
:selected vhdl-upper-case-keywords
]
3700 (customize-set-variable 'vhdl-upper-case-types
3701 (not vhdl-upper-case-types
))
3702 :style toggle
:selected vhdl-upper-case-types
]
3703 ["Upper Case Attributes"
3704 (customize-set-variable 'vhdl-upper-case-attributes
3705 (not vhdl-upper-case-attributes
))
3706 :style toggle
:selected vhdl-upper-case-attributes
]
3707 ["Upper Case Enumeration Values"
3708 (customize-set-variable 'vhdl-upper-case-enum-values
3709 (not vhdl-upper-case-enum-values
))
3710 :style toggle
:selected vhdl-upper-case-enum-values
]
3711 ["Upper Case Constants"
3712 (customize-set-variable 'vhdl-upper-case-constants
3713 (not vhdl-upper-case-constants
))
3714 :style toggle
:selected vhdl-upper-case-constants
]
3715 ("Use Direct Instantiation"
3717 (customize-set-variable 'vhdl-use-direct-instantiation
'never
)
3718 :style radio
:selected
(eq 'never vhdl-use-direct-instantiation
)]
3720 (customize-set-variable 'vhdl-use-direct-instantiation
'standard
)
3721 :style radio
:selected
(eq 'standard vhdl-use-direct-instantiation
)]
3723 (customize-set-variable 'vhdl-use-direct-instantiation
'always
)
3724 :style radio
:selected
(eq 'always vhdl-use-direct-instantiation
)])
3725 ["Include Array Index and Record Field in Sensitivity List"
3726 (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
3727 (not vhdl-array-index-record-field-in-sensitivity-list
))
3728 :style toggle
:selected vhdl-array-index-record-field-in-sensitivity-list
]
3730 ["Customize Group..." (customize-group 'vhdl-style
) t
])
3732 ["Entity File Name..." (customize-option 'vhdl-entity-file-name
) t
]
3733 ["Architecture File Name..."
3734 (customize-option 'vhdl-architecture-file-name
) t
]
3735 ["Configuration File Name..."
3736 (customize-option 'vhdl-configuration-file-name
) t
]
3737 ["Package File Name..." (customize-option 'vhdl-package-file-name
) t
]
3740 (customize-set-variable 'vhdl-file-name-case
'identity
)
3741 :style radio
:selected
(eq 'identity vhdl-file-name-case
)]
3743 (customize-set-variable 'vhdl-file-name-case
'downcase
)
3744 :style radio
:selected
(eq 'downcase vhdl-file-name-case
)]
3746 (customize-set-variable 'vhdl-file-name-case
'upcase
)
3747 :style radio
:selected
(eq 'upcase vhdl-file-name-case
)]
3749 (customize-set-variable 'vhdl-file-name-case
'capitalize
)
3750 :style radio
:selected
(eq 'capitalize vhdl-file-name-case
)])
3752 ["Customize Group..." (customize-group 'vhdl-naming
) t
])
3754 ("Electric Keywords"
3756 (customize-set-variable 'vhdl-electric-keywords
3757 (if (memq 'vhdl vhdl-electric-keywords
)
3758 (delq 'vhdl vhdl-electric-keywords
)
3759 (cons 'vhdl vhdl-electric-keywords
)))
3760 :style toggle
:selected
(memq 'vhdl vhdl-electric-keywords
)]
3761 ["User Model Keywords"
3762 (customize-set-variable 'vhdl-electric-keywords
3763 (if (memq 'user vhdl-electric-keywords
)
3764 (delq 'user vhdl-electric-keywords
)
3765 (cons 'user vhdl-electric-keywords
)))
3766 :style toggle
:selected
(memq 'user vhdl-electric-keywords
)])
3767 ("Insert Optional Labels"
3769 (customize-set-variable 'vhdl-optional-labels
'none
)
3770 :style radio
:selected
(eq 'none vhdl-optional-labels
)]
3772 (customize-set-variable 'vhdl-optional-labels
'process
)
3773 :style radio
:selected
(eq 'process vhdl-optional-labels
)]
3775 (customize-set-variable 'vhdl-optional-labels
'all
)
3776 :style radio
:selected
(eq 'all vhdl-optional-labels
)])
3777 ("Insert Empty Lines"
3779 (customize-set-variable 'vhdl-insert-empty-lines
'none
)
3780 :style radio
:selected
(eq 'none vhdl-insert-empty-lines
)]
3781 ["Design Units Only"
3782 (customize-set-variable 'vhdl-insert-empty-lines
'unit
)
3783 :style radio
:selected
(eq 'unit vhdl-insert-empty-lines
)]
3785 (customize-set-variable 'vhdl-insert-empty-lines
'all
)
3786 :style radio
:selected
(eq 'all vhdl-insert-empty-lines
)])
3787 ["Argument List Indent"
3788 (customize-set-variable 'vhdl-argument-list-indent
3789 (not vhdl-argument-list-indent
))
3790 :style toggle
:selected vhdl-argument-list-indent
]
3791 ["Association List with Formals"
3792 (customize-set-variable 'vhdl-association-list-with-formals
3793 (not vhdl-association-list-with-formals
))
3794 :style toggle
:selected vhdl-association-list-with-formals
]
3795 ["Conditions in Parenthesis"
3796 (customize-set-variable 'vhdl-conditions-in-parenthesis
3797 (not vhdl-conditions-in-parenthesis
))
3798 :style toggle
:selected vhdl-conditions-in-parenthesis
]
3799 ["Zero String..." (customize-option 'vhdl-zero-string
) t
]
3800 ["One String..." (customize-option 'vhdl-one-string
) t
]
3802 ["Header String..." (customize-option 'vhdl-file-header
) t
]
3803 ["Footer String..." (customize-option 'vhdl-file-footer
) t
]
3804 ["Company Name..." (customize-option 'vhdl-company-name
) t
]
3805 ["Copyright String..." (customize-option 'vhdl-copyright-string
) t
]
3806 ["Platform Specification..." (customize-option 'vhdl-platform-spec
) t
]
3807 ["Date Format..." (customize-option 'vhdl-date-format
) t
]
3808 ["Modify Date Prefix String..."
3809 (customize-option 'vhdl-modify-date-prefix-string
) t
]
3810 ["Modify Date on Saving"
3811 (progn (customize-set-variable 'vhdl-modify-date-on-saving
3812 (not vhdl-modify-date-on-saving
))
3813 (vhdl-activate-customizations))
3814 :style toggle
:selected vhdl-modify-date-on-saving
])
3815 ("Sequential Process"
3818 (customize-set-variable 'vhdl-reset-kind
'none
)
3819 :style radio
:selected
(eq 'none vhdl-reset-kind
)]
3821 (customize-set-variable 'vhdl-reset-kind
'sync
)
3822 :style radio
:selected
(eq 'sync vhdl-reset-kind
)]
3824 (customize-set-variable 'vhdl-reset-kind
'async
)
3825 :style radio
:selected
(eq 'async vhdl-reset-kind
)]
3827 (customize-set-variable 'vhdl-reset-kind
'query
)
3828 :style radio
:selected
(eq 'query vhdl-reset-kind
)])
3829 ["Reset is Active High"
3830 (customize-set-variable 'vhdl-reset-active-high
3831 (not vhdl-reset-active-high
))
3832 :style toggle
:selected vhdl-reset-active-high
]
3833 ["Use Rising Clock Edge"
3834 (customize-set-variable 'vhdl-clock-rising-edge
3835 (not vhdl-clock-rising-edge
))
3836 :style toggle
:selected vhdl-clock-rising-edge
]
3837 ("Clock Edge Condition"
3839 (customize-set-variable 'vhdl-clock-edge-condition
'standard
)
3840 :style radio
:selected
(eq 'standard vhdl-clock-edge-condition
)]
3841 ["Function \"rising_edge\""
3842 (customize-set-variable 'vhdl-clock-edge-condition
'function
)
3843 :style radio
:selected
(eq 'function vhdl-clock-edge-condition
)])
3844 ["Clock Name..." (customize-option 'vhdl-clock-name
) t
]
3845 ["Reset Name..." (customize-option 'vhdl-reset-name
) t
])
3847 ["Customize Group..." (customize-group 'vhdl-template
) t
])
3849 ["Model Definition..." (customize-option 'vhdl-model-alist
) t
])
3851 ["Include Port Comments"
3852 (customize-set-variable 'vhdl-include-port-comments
3853 (not vhdl-include-port-comments
))
3854 :style toggle
:selected vhdl-include-port-comments
]
3855 ["Include Direction Comments"
3856 (customize-set-variable 'vhdl-include-direction-comments
3857 (not vhdl-include-direction-comments
))
3858 :style toggle
:selected vhdl-include-direction-comments
]
3859 ["Include Type Comments"
3860 (customize-set-variable 'vhdl-include-type-comments
3861 (not vhdl-include-type-comments
))
3862 :style toggle
:selected vhdl-include-type-comments
]
3863 ("Include Group Comments"
3865 (customize-set-variable 'vhdl-include-group-comments
'never
)
3866 :style radio
:selected
(eq 'never vhdl-include-group-comments
)]
3868 (customize-set-variable 'vhdl-include-group-comments
'decl
)
3869 :style radio
:selected
(eq 'decl vhdl-include-group-comments
)]
3871 (customize-set-variable 'vhdl-include-group-comments
'always
)
3872 :style radio
:selected
(eq 'always vhdl-include-group-comments
)])
3873 ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name
) t
]
3874 ["Actual Port Name..." (customize-option 'vhdl-actual-port-name
) t
]
3875 ["Instance Name..." (customize-option 'vhdl-instance-name
) t
]
3877 ["Entity Name..." (customize-option 'vhdl-testbench-entity-name
) t
]
3878 ["Architecture Name..."
3879 (customize-option 'vhdl-testbench-architecture-name
) t
]
3880 ["Configuration Name..."
3881 (customize-option 'vhdl-testbench-configuration-name
) t
]
3882 ["DUT Name..." (customize-option 'vhdl-testbench-dut-name
) t
]
3884 (customize-set-variable 'vhdl-testbench-include-header
3885 (not vhdl-testbench-include-header
))
3886 :style toggle
:selected vhdl-testbench-include-header
]
3887 ["Declarations..." (customize-option 'vhdl-testbench-declarations
) t
]
3888 ["Statements..." (customize-option 'vhdl-testbench-statements
) t
]
3889 ["Initialize Signals"
3890 (customize-set-variable 'vhdl-testbench-initialize-signals
3891 (not vhdl-testbench-initialize-signals
))
3892 :style toggle
:selected vhdl-testbench-initialize-signals
]
3893 ["Include Library Clause"
3894 (customize-set-variable 'vhdl-testbench-include-library
3895 (not vhdl-testbench-include-library
))
3896 :style toggle
:selected vhdl-testbench-include-library
]
3897 ["Include Configuration"
3898 (customize-set-variable 'vhdl-testbench-include-configuration
3899 (not vhdl-testbench-include-configuration
))
3900 :style toggle
:selected vhdl-testbench-include-configuration
]
3903 (customize-set-variable 'vhdl-testbench-create-files
'none
)
3904 :style radio
:selected
(eq 'none vhdl-testbench-create-files
)]
3906 (customize-set-variable 'vhdl-testbench-create-files
'single
)
3907 :style radio
:selected
(eq 'single vhdl-testbench-create-files
)]
3909 (customize-set-variable 'vhdl-testbench-create-files
'separate
)
3910 :style radio
:selected
(eq 'separate vhdl-testbench-create-files
)])
3911 ["Testbench Entity File Name..."
3912 (customize-option 'vhdl-testbench-entity-file-name
) t
]
3913 ["Testbench Architecture File Name..."
3914 (customize-option 'vhdl-testbench-architecture-file-name
) t
])
3916 ["Customize Group..." (customize-group 'vhdl-port
) t
])
3918 ["Architecture Name..."
3919 (customize-option 'vhdl-compose-architecture-name
) t
]
3920 ["Configuration Name..."
3921 (customize-option 'vhdl-compose-configuration-name
) t
]
3922 ["Components Package Name..."
3923 (customize-option 'vhdl-components-package-name
) t
]
3924 ["Use Components Package"
3925 (customize-set-variable 'vhdl-use-components-package
3926 (not vhdl-use-components-package
))
3927 :style toggle
:selected vhdl-use-components-package
]
3929 (customize-set-variable 'vhdl-compose-include-header
3930 (not vhdl-compose-include-header
))
3931 :style toggle
:selected vhdl-compose-include-header
]
3932 ("Create Entity/Architecture Files"
3934 (customize-set-variable 'vhdl-compose-create-files
'none
)
3935 :style radio
:selected
(eq 'none vhdl-compose-create-files
)]
3937 (customize-set-variable 'vhdl-compose-create-files
'single
)
3938 :style radio
:selected
(eq 'single vhdl-compose-create-files
)]
3940 (customize-set-variable 'vhdl-compose-create-files
'separate
)
3941 :style radio
:selected
(eq 'separate vhdl-compose-create-files
)])
3942 ["Create Configuration File"
3943 (customize-set-variable 'vhdl-compose-configuration-create-file
3944 (not vhdl-compose-configuration-create-file
))
3945 :style toggle
:selected vhdl-compose-configuration-create-file
]
3946 ["Hierarchical Configuration"
3947 (customize-set-variable 'vhdl-compose-configuration-hierarchical
3948 (not vhdl-compose-configuration-hierarchical
))
3949 :style toggle
:selected vhdl-compose-configuration-hierarchical
]
3950 ["Use Subconfiguration"
3951 (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
3952 (not vhdl-compose-configuration-use-subconfiguration
))
3953 :style toggle
:selected vhdl-compose-configuration-use-subconfiguration
]
3955 ["Customize Group..." (customize-group 'vhdl-compose
) t
])
3957 ["Self Insert Comments"
3958 (customize-set-variable 'vhdl-self-insert-comments
3959 (not vhdl-self-insert-comments
))
3960 :style toggle
:selected vhdl-self-insert-comments
]
3961 ["Prompt for Comments"
3962 (customize-set-variable 'vhdl-prompt-for-comments
3963 (not vhdl-prompt-for-comments
))
3964 :style toggle
:selected vhdl-prompt-for-comments
]
3965 ["Inline Comment Column..."
3966 (customize-option 'vhdl-inline-comment-column
) t
]
3967 ["End Comment Column..." (customize-option 'vhdl-end-comment-column
) t
]
3969 ["Customize Group..." (customize-group 'vhdl-comment
) t
])
3971 ["Auto Align Templates"
3972 (customize-set-variable 'vhdl-auto-align
(not vhdl-auto-align
))
3973 :style toggle
:selected vhdl-auto-align
]
3974 ["Align Line Groups"
3975 (customize-set-variable 'vhdl-align-groups
(not vhdl-align-groups
))
3976 :style toggle
:selected vhdl-align-groups
]
3977 ["Group Separation String..."
3978 (customize-option 'vhdl-align-group-separate
) t
]
3979 ["Align Lines with Same Indent"
3980 (customize-set-variable 'vhdl-align-same-indent
3981 (not vhdl-align-same-indent
))
3982 :style toggle
:selected vhdl-align-same-indent
]
3983 ["Beautify Options..." (customize-option 'vhdl-beautify-options
) t
]
3985 ["Customize Group..." (customize-group 'vhdl-beautify
) t
])
3987 ["Highlighting On/Off..."
3989 (if (fboundp 'global-font-lock-mode
)
3990 'global-font-lock-mode
'font-lock-auto-fontify
)) t
]
3991 ["Highlight Keywords"
3992 (progn (customize-set-variable 'vhdl-highlight-keywords
3993 (not vhdl-highlight-keywords
))
3994 (vhdl-fontify-buffer))
3995 :style toggle
:selected vhdl-highlight-keywords
]
3997 (progn (customize-set-variable 'vhdl-highlight-names
3998 (not vhdl-highlight-names
))
3999 (vhdl-fontify-buffer))
4000 :style toggle
:selected vhdl-highlight-names
]
4001 ["Highlight Special Words"
4002 (progn (customize-set-variable 'vhdl-highlight-special-words
4003 (not vhdl-highlight-special-words
))
4004 (vhdl-fontify-buffer))
4005 :style toggle
:selected vhdl-highlight-special-words
]
4006 ["Highlight Forbidden Words"
4007 (progn (customize-set-variable 'vhdl-highlight-forbidden-words
4008 (not vhdl-highlight-forbidden-words
))
4009 (vhdl-fontify-buffer))
4010 :style toggle
:selected vhdl-highlight-forbidden-words
]
4011 ["Highlight Verilog Keywords"
4012 (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
4013 (not vhdl-highlight-verilog-keywords
))
4014 (vhdl-fontify-buffer))
4015 :style toggle
:selected vhdl-highlight-verilog-keywords
]
4016 ["Highlight \"translate_off\""
4017 (progn (customize-set-variable 'vhdl-highlight-translate-off
4018 (not vhdl-highlight-translate-off
))
4019 (vhdl-fontify-buffer))
4020 :style toggle
:selected vhdl-highlight-translate-off
]
4021 ["Case Sensitive Highlighting"
4022 (progn (customize-set-variable 'vhdl-highlight-case-sensitive
4023 (not vhdl-highlight-case-sensitive
))
4024 (vhdl-fontify-buffer))
4025 :style toggle
:selected vhdl-highlight-case-sensitive
]
4026 ["Special Syntax Definition..."
4027 (customize-option 'vhdl-special-syntax-alist
) t
]
4028 ["Forbidden Words..." (customize-option 'vhdl-forbidden-words
) t
]
4029 ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax
) t
]
4030 ["Directive Keywords..." (customize-option 'vhdl-directive-keywords
) t
]
4031 ["Colors..." (customize-group 'vhdl-highlight-faces
) t
]
4033 ["Customize Group..." (customize-group 'vhdl-highlight
) t
])
4035 ["Auto Open at Startup"
4036 (customize-set-variable 'vhdl-speedbar-auto-open
4037 (not vhdl-speedbar-auto-open
))
4038 :style toggle
:selected vhdl-speedbar-auto-open
]
4039 ("Default Displaying Mode"
4041 (customize-set-variable 'vhdl-speedbar-display-mode
'files
)
4042 :style radio
:selected
(eq 'files vhdl-speedbar-display-mode
)]
4043 ["Directory Hierarchy"
4044 (customize-set-variable 'vhdl-speedbar-display-mode
'directory
)
4045 :style radio
:selected
(eq 'directory vhdl-speedbar-display-mode
)]
4046 ["Project Hierarchy"
4047 (customize-set-variable 'vhdl-speedbar-display-mode
'project
)
4048 :style radio
:selected
(eq 'project vhdl-speedbar-display-mode
)])
4049 ["Indentation Offset..."
4050 (customize-option 'speedbar-indentation-width
) t
]
4051 ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit
) t
]
4052 ["Jump to Unit when Opening"
4053 (customize-set-variable 'vhdl-speedbar-jump-to-unit
4054 (not vhdl-speedbar-jump-to-unit
))
4055 :style toggle
:selected vhdl-speedbar-jump-to-unit
]
4056 ["Update Hierarchy on File Saving"
4057 (customize-set-variable 'vhdl-speedbar-update-on-saving
4058 (not vhdl-speedbar-update-on-saving
))
4059 :style toggle
:selected vhdl-speedbar-update-on-saving
]
4060 ("Save in Cache File"
4061 ["Hierarchy Information"
4062 (customize-set-variable 'vhdl-speedbar-save-cache
4063 (if (memq 'hierarchy vhdl-speedbar-save-cache
)
4064 (delq 'hierarchy vhdl-speedbar-save-cache
)
4065 (cons 'hierarchy vhdl-speedbar-save-cache
)))
4066 :style toggle
:selected
(memq 'hierarchy vhdl-speedbar-save-cache
)]
4067 ["Displaying Status"
4068 (customize-set-variable 'vhdl-speedbar-save-cache
4069 (if (memq 'display vhdl-speedbar-save-cache
)
4070 (delq 'display vhdl-speedbar-save-cache
)
4071 (cons 'display vhdl-speedbar-save-cache
)))
4072 :style toggle
:selected
(memq 'display vhdl-speedbar-save-cache
)])
4073 ["Cache File Name..."
4074 (customize-option 'vhdl-speedbar-cache-file-name
) t
]
4076 ["Customize Group..." (customize-group 'vhdl-speedbar
) t
])
4078 ["Add Index Menu when Loading File"
4079 (progn (customize-set-variable 'vhdl-index-menu
(not vhdl-index-menu
))
4080 (vhdl-index-menu-init))
4081 :style toggle
:selected vhdl-index-menu
]
4082 ["Add Source File Menu when Loading File"
4083 (progn (customize-set-variable 'vhdl-source-file-menu
4084 (not vhdl-source-file-menu
))
4085 (vhdl-add-source-files-menu))
4086 :style toggle
:selected vhdl-source-file-menu
]
4087 ["Add Hideshow Menu at Startup"
4088 (progn (customize-set-variable 'vhdl-hideshow-menu
4089 (not vhdl-hideshow-menu
))
4090 (vhdl-activate-customizations))
4091 :style toggle
:selected vhdl-hideshow-menu
]
4092 ["Hide Everything Initially"
4093 (customize-set-variable 'vhdl-hide-all-init
(not vhdl-hide-all-init
))
4094 :style toggle
:selected vhdl-hide-all-init
]
4096 ["Customize Group..." (customize-group 'vhdl-menu
) t
])
4098 ["In Two Column Format"
4099 (progn (customize-set-variable 'vhdl-print-two-column
4100 (not vhdl-print-two-column
))
4101 (message "Activate new setting by saving options and restarting Emacs"))
4102 :style toggle
:selected vhdl-print-two-column
]
4103 ["Use Customized Faces"
4104 (progn (customize-set-variable 'vhdl-print-customize-faces
4105 (not vhdl-print-customize-faces
))
4106 (message "Activate new setting by saving options and restarting Emacs"))
4107 :style toggle
:selected vhdl-print-customize-faces
]
4109 ["Customize Group..." (customize-group 'vhdl-print
) t
])
4111 ["Use Intelligent Tab"
4112 (progn (customize-set-variable 'vhdl-intelligent-tab
4113 (not vhdl-intelligent-tab
))
4114 (vhdl-activate-customizations))
4115 :style toggle
:selected vhdl-intelligent-tab
]
4116 ["Indent Syntax-Based"
4117 (customize-set-variable 'vhdl-indent-syntax-based
4118 (not vhdl-indent-syntax-based
))
4119 :style toggle
:selected vhdl-indent-syntax-based
]
4120 ["Indent Comments Like Next Code Line"
4121 (customize-set-variable 'vhdl-indent-comment-like-next-code-line
4122 (not vhdl-indent-comment-like-next-code-line
))
4123 :style toggle
:selected vhdl-indent-comment-like-next-code-line
]
4124 ["Word Completion is Case Sensitive"
4125 (customize-set-variable 'vhdl-word-completion-case-sensitive
4126 (not vhdl-word-completion-case-sensitive
))
4127 :style toggle
:selected vhdl-word-completion-case-sensitive
]
4128 ["Word Completion in Minibuffer"
4129 (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
4130 (not vhdl-word-completion-in-minibuffer
))
4131 (message "Activate new setting by saving options and restarting Emacs"))
4132 :style toggle
:selected vhdl-word-completion-in-minibuffer
]
4133 ["Underscore is Part of Word"
4134 (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
4135 (not vhdl-underscore-is-part-of-word
))
4136 (vhdl-activate-customizations))
4137 :style toggle
:selected vhdl-underscore-is-part-of-word
]
4139 ["Customize Group..." (customize-group 'vhdl-misc
) t
])
4140 ["Related..." (customize-browse 'vhdl-related
) t
]
4142 ["Save Options" customize-save-customized t
]
4143 ["Activate Options" vhdl-activate-customizations t
]
4144 ["Browse Options..." vhdl-customize t
])))
4146 (defvar vhdl-mode-menu-list
(vhdl-create-mode-menu)
4149 (defun vhdl-update-mode-menu ()
4150 "Update VHDL Mode menu."
4152 (easy-menu-remove vhdl-mode-menu-list
) ; for XEmacs
4153 (setq vhdl-mode-menu-list
(vhdl-create-mode-menu))
4154 (easy-menu-add vhdl-mode-menu-list
) ; for XEmacs
4155 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4156 "Menu keymap for VHDL Mode." vhdl-mode-menu-list
))
4158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4159 ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
4161 (defconst vhdl-imenu-generic-expression
4164 "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
4167 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
4170 "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4173 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
4176 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
4179 "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
4182 "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4185 "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4188 "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
4191 "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
4194 "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
4196 (defun vhdl-index-menu-init ()
4197 "Initialize index menu."
4198 (set (make-local-variable 'imenu-case-fold-search
) t
)
4199 (set (make-local-variable 'imenu-generic-expression
)
4200 vhdl-imenu-generic-expression
)
4201 (when (and vhdl-index-menu
(fboundp 'imenu
))
4202 (imenu-add-to-menubar "Index")))
4204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4205 ;; Source file menu (using `easy-menu.el')
4207 (defvar vhdl-sources-menu nil
)
4209 (defun vhdl-directory-files (directory &optional full match
)
4210 "Call `directory-files' if DIRECTORY exists, otherwise generate error
4212 (if (not (file-directory-p directory
))
4213 (vhdl-warning-when-idle "No such directory: \"%s\"" directory
)
4214 (let ((dir (directory-files directory full match
)))
4215 (setq dir
(delete "." dir
))
4216 (setq dir
(delete ".." dir
))
4219 (defun vhdl-get-source-files (&optional full directory
)
4220 "Get list of VHDL source files in DIRECTORY or current directory."
4221 (let ((mode-alist auto-mode-alist
)
4223 ;; create regular expressions for matching file names
4224 (setq filename-regexp
"\\`[^.].*\\(")
4226 (when (eq (cdar mode-alist
) 'vhdl-mode
)
4227 (setq filename-regexp
4228 (concat filename-regexp
(caar mode-alist
) "\\|")))
4229 (setq mode-alist
(cdr mode-alist
)))
4230 (setq filename-regexp
4231 (concat (substring filename-regexp
0
4232 (string-match "\\\\|$" filename-regexp
)) "\\)"))
4234 (vhdl-directory-files
4235 (or directory default-directory
) full filename-regexp
)))
4237 (defun vhdl-add-source-files-menu ()
4238 "Scan directory for all VHDL source files and generate menu.
4239 The directory of the current source file is scanned."
4241 (message "Scanning directory for source files ...")
4242 (let ((newmap (current-local-map))
4243 (file-list (vhdl-get-source-files))
4245 ;; Create list for menu
4249 (push (vector (car file-list
) (list 'find-file
(car file-list
)) t
)
4251 (setq file-list
(cdr file-list
)))
4252 (setq menu-list
(vhdl-menu-split menu-list
"Sources"))
4253 (when found
(push "--" menu-list
))
4254 (push ["*Rescan*" vhdl-add-source-files-menu t
] menu-list
)
4255 (push "Sources" menu-list
)
4257 (easy-menu-add menu-list
)
4258 (easy-menu-define vhdl-sources-menu newmap
4259 "VHDL source files menu" menu-list
))
4263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4266 ;; performs all buffer local initializations
4269 (define-derived-mode vhdl-mode prog-mode
4270 '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
4271 (vhdl-electric-mode "e")
4272 (vhdl-stutter-mode "s"))
4273 "Major mode for editing VHDL code.
4278 TEMPLATE INSERTION (electrification):
4279 After typing a VHDL keyword and entering `SPC', you are prompted for
4280 arguments while a template is generated for that VHDL construct. Typing
4281 `RET' or `C-g' at the first \(mandatory) prompt aborts the current
4282 template generation. Optional arguments are indicated by square
4283 brackets and removed if the queried string is left empty. Prompts for
4284 mandatory arguments remain in the code if the queried string is left
4285 empty. They can be queried again by `C-c C-t C-q'. Enabled
4286 electrification is indicated by `/e' in the mode line.
4288 Typing `M-SPC' after a keyword inserts a space without calling the
4289 template generator. Automatic template generation (i.e.
4290 electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
4291 setting option `vhdl-electric-mode' (see OPTIONS).
4293 Template generators can be invoked from the VHDL menu, by key
4294 bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
4295 the keyword (i.e. first word of menu entry not in parenthesis) and
4296 `SPC'. The following abbreviations can also be used: arch, attr, cond,
4297 conf, comp, cons, func, inst, pack, sig, var.
4299 Template styles can be customized in customization group
4300 `vhdl-template' \(see OPTIONS).
4304 A file header can be inserted by `C-c C-t C-h'. A file footer
4305 (template at the end of the file) can be inserted by `C-c C-t C-f'.
4306 See customization group `vhdl-header'.
4310 Double striking of some keys inserts cumbersome VHDL syntax elements.
4311 Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
4312 option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
4313 the mode line. The stuttering keys and their effects are:
4315 ;; --> \" : \" [ --> ( -- --> comment
4316 ;;; --> \" := \" [[ --> [ --CR --> comment-out code
4317 .. --> \" => \" ] --> ) --- --> horizontal line
4318 ,, --> \" <= \" ]] --> ] ---- --> display comment
4319 == --> \" == \" '' --> \\\"
4323 Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
4324 word in the buffer that starts alike, inserts it and adjusts case.
4325 Re-typing `TAB' toggles through alternative word completions. This also
4326 works in the minibuffer (i.e. in template generator prompts).
4328 Typing `TAB' after `(' looks for and inserts complete parenthesized
4329 expressions (e.g. for array index ranges). All keywords as well as
4330 standard types and subprograms of VHDL have predefined abbreviations
4331 \(e.g. type \"std\" and `TAB' will toggle through all standard types
4332 beginning with \"std\").
4334 Typing `TAB' after a non-word character indents the line if at the
4335 beginning of a line (i.e. no preceding non-blank characters), and
4336 inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
4341 `--' puts a single comment.
4342 `---' draws a horizontal line for separating code segments.
4343 `----' inserts a display comment, i.e. two horizontal lines
4344 with a comment in between.
4345 `--CR' comments out code on that line. Re-hitting CR comments
4346 out following lines.
4347 `C-c C-c' comments out a region if not commented out,
4348 uncomments a region if already commented out. Option
4349 `comment-style' defines where the comment characters
4350 should be placed (beginning of line, indent, etc.).
4352 You are prompted for comments after object definitions (i.e. signals,
4353 variables, constants, ports) and after subprogram and process
4354 specifications if option `vhdl-prompt-for-comments' is non-nil.
4355 Comments are automatically inserted as additional labels (e.g. after
4356 begin statements) and as help comments if `vhdl-self-insert-comments' is
4359 Inline comments (i.e. comments after a piece of code on the same line)
4360 are indented at least to `vhdl-inline-comment-column'. Comments go at
4361 maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
4362 will open a new comment line. Typing beyond `vhdl-end-comment-column'
4363 in a comment automatically opens a new comment line. `M-q' re-fills
4364 multi-line comments.
4368 `TAB' indents a line if at the beginning of the line. The amount of
4369 indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
4370 always indents the current line (is bound to `TAB' if option
4371 `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
4374 Indentation can be done for a group of lines (`C-c C-i C-g'), a region
4375 \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
4376 indented normally (nil) or relative to the opening parenthesis (non-nil)
4377 according to option `vhdl-argument-list-indent'.
4379 If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
4380 tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
4383 Syntax-based indentation can be very slow in large files. Option
4384 `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
4386 Option `vhdl-indent-comment-like-next-code-line' controls whether
4387 comment lines are indented like the preceding or like the following code
4392 The alignment functions align operators, keywords, and inline comments
4393 to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
4394 separated by blank lines, `C-c C-a C-i' a block of lines with same
4395 indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
4396 a pair of parentheses (e.g. port clause/map, argument list), and `C-c
4397 C-a C-d' all lines within the declarative part of a design unit. `C-c
4398 C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
4399 for a group of lines, and `C-c C-a M-c' for a region.
4401 If option `vhdl-align-groups' is non-nil, groups of code lines
4402 separated by special lines (see option `vhdl-align-group-separate') are
4403 aligned individually. If option `vhdl-align-same-indent' is non-nil,
4404 blocks of lines with same indent are aligned separately. Some templates
4405 are automatically aligned after generation if option `vhdl-auto-align'
4408 Alignment tries to align inline comments at
4409 `vhdl-inline-comment-column' and tries inline comment not to exceed
4410 `vhdl-end-comment-column'.
4412 `C-c C-x M-w' fixes up whitespace in a region. That is, operator
4413 symbols are surrounded by one space, and multiple spaces are eliminated.
4417 Code filling allows to condense code (e.g. sensitivity lists or port
4418 maps) by removing comments and newlines and re-wrapping so that all
4419 lines are maximally filled (block filling). `C-c C-f C-f' fills a list
4420 enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
4421 blank lines, `C-c C-f C-i' a block of lines with same indent, and
4422 `C-c C-f M-f' an entire region.
4425 CODE BEAUTIFICATION:
4426 `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
4427 buffer respectively. This includes indentation, alignment, and case
4428 fixing. Code beautification can also be run non-interactively using the
4431 emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
4435 Generic and port clauses from entity or component declarations can be
4436 copied (`C-c C-p C-w') and pasted as entity and component declarations,
4437 as component instantiations and corresponding internal constants and
4438 signals, as a generic map with constants as actual generics, and as
4439 internal signal initializations (menu).
4441 To include formals in component instantiations, see option
4442 `vhdl-association-list-with-formals'. To include comments in pasting,
4443 see options `vhdl-include-...-comments'.
4445 A clause with several generic/port names on the same line can be
4446 flattened (`C-c C-p C-f') so that only one name per line exists. The
4447 direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
4448 outputs and vice versa, which can be useful in testbenches. (This
4449 reversion is done on the internal data structure and is only reflected
4450 in subsequent paste operations.)
4452 Names for actual ports, instances, testbenches, and
4453 design-under-test instances can be derived from existing names according
4454 to options `vhdl-...-name'. See customization group `vhdl-port'.
4457 SUBPROGRAM TRANSLATION:
4458 Similar functionality exists for copying/pasting the interface of
4459 subprograms (function/procedure). A subprogram interface can be copied
4460 and then pasted as a subprogram declaration, body or call (uses
4461 association list with formals).
4464 TESTBENCH GENERATION:
4465 A copied port can also be pasted as a testbench. The generated
4466 testbench includes an entity, an architecture, and an optional
4467 configuration. The architecture contains the component declaration and
4468 instantiation of the DUT as well as internal constant and signal
4469 declarations. Additional user-defined templates can be inserted. The
4470 names used for entity/architecture/configuration/DUT as well as the file
4471 structure to be generated can be customized. See customization group
4476 Key bindings (`C-c ...') exist for most commands (see in menu).
4480 All commands can be found in the VHDL menu including their key bindings.
4484 The speedbar allows browsing of directories and file contents. It can
4485 be accessed from the VHDL menu and is automatically opened if option
4486 `vhdl-speedbar-auto-open' is non-nil.
4488 In speedbar, open files and directories with `mouse-2' on the name and
4489 browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
4492 DESIGN HIERARCHY BROWSER:
4493 The speedbar can also be used for browsing the hierarchy of design units
4494 contained in the source files of the current directory or the specified
4495 projects (see option `vhdl-project-alist').
4497 The speedbar can be switched between file, directory hierarchy and
4498 project hierarchy browsing mode in the speedbar menu or by typing `f',
4499 `h' or `H' in speedbar.
4501 In speedbar, open design units with `mouse-2' on the name and browse
4502 their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
4503 from entities and components (in packages). Individual design units and
4504 complete designs can directly be compiled (\"Make\" menu entry).
4506 The hierarchy is automatically updated upon saving a modified source
4507 file when option `vhdl-speedbar-update-on-saving' is non-nil. The
4508 hierarchy is only updated for projects that have been opened once in the
4509 speedbar. The hierarchy is cached between Emacs sessions in a file (see
4510 options in group `vhdl-speedbar').
4512 Simple design consistency checks are done during scanning, such as
4513 multiple declarations of the same unit or missing primary units that are
4514 required by secondary units.
4517 STRUCTURAL COMPOSITION:
4518 Enables simple structural composition. `C-c C-m C-n' creates a skeleton
4519 for a new component. Subcomponents (i.e. component declaration and
4520 instantiation) can be automatically placed from a previously read port
4521 \(`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
4522 all subcomponents can be automatically connected using internal signals
4523 and ports (`C-c C-m C-w') following these rules:
4524 - subcomponent actual ports with same name are considered to be
4525 connected by a signal (internal signal or port)
4526 - signals that are only inputs to subcomponents are considered as
4527 inputs to this component -> input port created
4528 - signals that are only outputs from subcomponents are considered as
4529 outputs from this component -> output port created
4530 - signals that are inputs to AND outputs from subcomponents are
4531 considered as internal connections -> internal signal created
4533 Purpose: With appropriate naming conventions it is possible to
4534 create higher design levels with only a few mouse clicks or key
4535 strokes. A new design level can be created by simply generating a new
4536 component, placing the required subcomponents from the hierarchy
4537 browser, and wiring everything automatically.
4539 Note: Automatic wiring only works reliably on templates of new
4540 components and component instantiations that were created by VHDL mode.
4542 Component declarations can be placed in a components package (option
4543 `vhdl-use-components-package') which can be automatically generated for
4544 an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
4545 component instantiation is also supported (option
4546 `vhdl-use-direct-instantiation').
4548 Configuration declarations can automatically be generated either from
4549 the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
4550 the speedbar menu (for the architecture under the cursor). The
4551 configurations can optionally be hierarchical (i.e. include all
4552 component levels of a hierarchical design, option
4553 `vhdl-compose-configuration-hierarchical') or include subconfigurations
4554 (option `vhdl-compose-configuration-use-subconfiguration'). For
4555 subcomponents in hierarchical configurations, the most-recently-analyzed
4556 (mra) architecture is selected. If another architecture is desired, it
4557 can be marked as most-recently-analyzed (speedbar menu) before
4558 generating the configuration.
4560 Note: Configurations of subcomponents (i.e. hierarchical configuration
4561 declarations) are currently not considered when displaying
4562 configurations in speedbar.
4564 See the options group `vhdl-compose' for all relevant user options.
4567 SOURCE FILE COMPILATION:
4568 The syntax of the current buffer can be analyzed by calling a VHDL
4569 compiler (menu, `C-c C-k'). The compiler to be used is specified by
4570 option `vhdl-compiler'. The available compilers are listed in option
4571 `vhdl-compiler-alist' including all required compilation command,
4572 command options, compilation directory, and error message syntax
4573 information. New compilers can be added.
4575 All the source files of an entire design can be compiled by the `make'
4576 command (menu, `C-c M-C-k') if an appropriate Makefile exists.
4579 MAKEFILE GENERATION:
4580 Makefiles can be generated automatically by an internal generation
4581 routine (`C-c M-k'). The library unit dependency information is
4582 obtained from the hierarchy browser. Makefile generation can be
4583 customized for each compiler in option `vhdl-compiler-alist'.
4585 Makefile generation can also be run non-interactively using the
4588 emacs -batch -l ~/.emacs -l vhdl-mode
4589 [-compiler compilername] [-project projectname]
4590 -f vhdl-generate-makefile
4592 The Makefile's default target \"all\" compiles the entire design, the
4593 target \"clean\" removes it and the target \"library\" creates the
4594 library directory if not existent. These target names can be customized
4595 by option `vhdl-makefile-default-targets'. The Makefile also includes a
4596 target for each primary library unit which allows selective compilation
4597 of this unit, its secondary units and its subhierarchy (example:
4598 compilation of a design specified by a configuration). User specific
4599 parts can be inserted into a Makefile with option
4600 `vhdl-makefile-generation-hook'.
4603 - Only library units and dependencies within the current library are
4604 considered. Makefiles for designs that span multiple libraries are
4605 not (yet) supported.
4606 - Only one-level configurations are supported (also hierarchical),
4607 but configurations that go down several levels are not.
4608 - The \"others\" keyword in configurations is not supported.
4612 Projects can be defined in option `vhdl-project-alist' and a current
4613 project be selected using option `vhdl-project' (permanently) or from
4614 the menu or speedbar (temporarily). For each project, title and
4615 description strings (for the file headers), source files/directories
4616 (for the hierarchy browser and Makefile generation), library name, and
4617 compiler-dependent options, exceptions and compilation directory can be
4618 specified. Compilation settings overwrite the settings of option
4619 `vhdl-compiler-alist'.
4621 Project setups can be exported (i.e. written to a file) and imported.
4622 Imported setups are not automatically saved in `vhdl-project-alist' but
4623 can be saved afterwards in its customization buffer. When starting
4624 Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
4625 vhdl-mode\") in a directory with an existing project setup file, it is
4626 automatically loaded and its project activated if option
4627 `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
4628 files can be specified in option `vhdl-project-file-name'. Multiple
4629 project setups can be automatically loaded from global directories.
4630 This is an alternative to specifying project setups with option
4631 `vhdl-project-alist'.
4635 As an alternative to the speedbar, an index menu can be added (set
4636 option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
4637 (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
4638 file) for browsing the file contents (is not populated if buffer is
4639 larger than 256000). Also, a source file menu can be
4640 added (set option `vhdl-source-file-menu' to non-nil) for browsing the
4641 current directory for VHDL source files.
4645 The VHDL standards to be used are specified in option `vhdl-standard'.
4646 Available standards are: VHDL'87/'93(02), VHDL-AMS, and Math Packages.
4650 Lower and upper case for keywords and standardized types, attributes,
4651 and enumeration values is supported. If the option
4652 `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
4653 lower case and are converted into upper case automatically (not for
4654 types, attributes, and enumeration values). The case of keywords,
4655 types, attributes,and enumeration values can be fixed for an entire
4656 region (menu) or buffer (`C-c C-x C-c') according to the options
4657 `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
4660 HIGHLIGHTING (fontification):
4661 Keywords and standardized types, attributes, enumeration values, and
4662 function names (controlled by option `vhdl-highlight-keywords'), as well
4663 as comments, strings, and template prompts are highlighted using
4664 different colors. Unit, subprogram, signal, variable, constant,
4665 parameter and generic/port names in declarations as well as labels are
4666 highlighted if option `vhdl-highlight-names' is non-nil.
4668 Additional reserved words or words with a forbidden syntax (e.g. words
4669 that should be avoided) can be specified in option
4670 `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
4671 a warning color (option `vhdl-highlight-forbidden-words'). Verilog
4672 keywords are highlighted as forbidden words if option
4673 `vhdl-highlight-verilog-keywords' is non-nil.
4675 Words with special syntax can be highlighted by specifying their
4676 syntax and color in option `vhdl-special-syntax-alist' and by setting
4677 option `vhdl-highlight-special-words' to non-nil. This allows to
4678 establish some naming conventions (e.g. to distinguish different kinds
4679 of signals or other objects by using name suffices) and to support them
4682 Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
4683 to support case-sensitive highlighting. However, keywords are then only
4684 highlighted if written in lower case.
4686 Code between \"translate_off\" and \"translate_on\" pragmas is
4687 highlighted using a different background color if option
4688 `vhdl-highlight-translate-off' is non-nil.
4690 For documentation and customization of the used colors see
4691 customization group `vhdl-highlight-faces' (`M-x customize-group'). For
4692 highlighting of matching parenthesis, see customization group
4693 `paren-showing'. Automatic buffer highlighting is turned on/off by
4694 option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
4698 VHDL models (templates) can be specified by the user and made accessible
4699 in the menu, through key bindings (`C-c C-m ...'), or by keyword
4700 electrification. See option `vhdl-model-alist'.
4704 The code of blocks, processes, subprograms, component declarations and
4705 instantiations, generic/port clauses, and configuration declarations can
4706 be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
4707 the code (see customization group `vhdl-menu'). XEmacs: limited
4708 functionality due to old `hideshow.el' package.
4712 - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
4713 current process, `C-c C-u M-s' of all processes in the current buffer.
4715 - Only declared local signals (ports, signals declared in
4716 architecture and blocks) are automatically inserted.
4717 - Global signals declared in packages are not automatically inserted.
4718 Insert them once manually (will be kept afterwards).
4719 - Out parameters of procedures are considered to be read.
4720 Use option `vhdl-entity-file-name' to specify the entity file name
4721 \(used to obtain the port names).
4722 Use option `vhdl-array-index-record-field-in-sensitivity-list' to
4723 specify whether to include array indices and record fields in
4728 `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
4729 \(e.g. if the closing parenthesis is on the wrong line or is missing).
4733 PostScript printing with different faces (an optimized set of faces is
4734 used if `vhdl-print-customize-faces' is non-nil) or colors \(if
4735 `ps-print-color-p' is non-nil) is possible using the standard Emacs
4736 PostScript printing commands. Option `vhdl-print-two-column' defines
4737 appropriate default settings for nice landscape two-column printing.
4738 The paper format can be set by option `ps-paper-type'. Do not forget to
4739 switch `ps-print-color-p' to nil for printing on black-and-white
4744 User options allow customization of VHDL Mode. All options are
4745 accessible from the \"Options\" menu entry. Simple options (switches
4746 and choices) can directly be changed, while for complex options a
4747 customization buffer is opened. Changed options can be saved for future
4748 sessions using the \"Save Options\" menu entry.
4750 Options and their detailed descriptions can also be accessed by using
4751 the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
4752 customize-group' for groups). Some customizations only take effect
4753 after some action (read the NOTE in the option documentation).
4754 Customization can also be done globally (i.e. site-wide, read the
4757 Not all options are described in this documentation, so go and see
4758 what other useful user options there are (`M-x vhdl-customize' or menu)!
4762 As default, files with extensions \".vhd\" and \".vhdl\" are
4763 automatically recognized as VHDL source files. To add an extension
4764 \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
4766 \(push '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist)
4770 - To start Emacs with open VHDL hierarchy browser without having to load
4771 a VHDL file first, use the command:
4773 emacs -l vhdl-mode -f speedbar-frame-mode
4775 - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
4777 - Some features only work on properly indented code.
4781 See also the release notes (menu) for added features in new releases.
4787 To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
4788 Add a description of the problem and include a reproducible test case.
4790 Questions and enhancement requests can be sent to <reto@gnu.org>.
4792 The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
4793 The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
4794 releases. You are kindly invited to participate in beta testing. Subscribe
4795 to above mailing lists by sending an email to <reto@gnu.org>.
4797 VHDL Mode is officially distributed at
4798 http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
4799 where the latest version can be found.
4805 - XEmacs: Incorrect start-up when automatically opening speedbar.
4806 - XEmacs: Indentation in XEmacs 21.4 (and higher).
4807 - Indentation incorrect for new 'postponed' VHDL keyword.
4808 - Indentation incorrect for 'protected body' construct.
4811 The VHDL Mode Authors
4812 Reto Zimmermann and Rod Whitby
4818 :abbrev-table vhdl-mode-abbrev-table
4820 ;; set local variables
4821 (set (make-local-variable 'paragraph-start
)
4822 "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
4823 (set (make-local-variable 'paragraph-separate
) paragraph-start
)
4824 (set (make-local-variable 'paragraph-ignore-fill-prefix
) t
)
4825 (set (make-local-variable 'parse-sexp-ignore-comments
) t
)
4826 (set (make-local-variable 'indent-line-function
) 'vhdl-indent-line
)
4827 (set (make-local-variable 'comment-start
) "--")
4828 (set (make-local-variable 'comment-end
) "")
4830 (set (make-local-variable 'comment-padding
) ""))
4831 (set (make-local-variable 'comment-column
) vhdl-inline-comment-column
)
4832 (set (make-local-variable 'end-comment-column
) vhdl-end-comment-column
)
4833 (set (make-local-variable 'comment-start-skip
) "--+\\s-*")
4834 (set (make-local-variable 'comment-multi-line
) nil
)
4835 (set (make-local-variable 'indent-tabs-mode
) vhdl-indent-tabs-mode
)
4836 (set (make-local-variable 'hippie-expand-verbose
) nil
)
4838 ;; setup the comment indent variable in a Emacs version portable way
4839 ;; ignore any byte compiler warnings you might get here
4840 (when (boundp 'comment-indent-function
)
4841 (set (make-local-variable 'comment-indent-function
) 'vhdl-comment-indent
))
4843 ;; initialize font locking
4844 (set (make-local-variable 'font-lock-defaults
)
4846 '(nil vhdl-font-lock-keywords
) nil
4847 (not vhdl-highlight-case-sensitive
) '((?\_ .
"w")) 'beginning-of-line
))
4848 (if (eval-when-compile (fboundp 'syntax-propertize-rules
))
4849 (set (make-local-variable 'syntax-propertize-function
)
4850 (syntax-propertize-rules
4851 ;; Mark single quotes as having string quote syntax in
4853 ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
4854 (set (make-local-variable 'font-lock-syntactic-keywords
)
4855 vhdl-font-lock-syntactic-keywords
))
4856 (unless vhdl-emacs-21
4857 (set (make-local-variable 'font-lock-support-mode
) 'lazy-lock-mode
)
4858 (set (make-local-variable 'lazy-lock-defer-contextually
) nil
)
4859 (set (make-local-variable 'lazy-lock-defer-on-the-fly
) t
)
4860 ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
4861 (set (make-local-variable 'lazy-lock-defer-on-scrolling
) t
))
4862 ; (turn-on-font-lock)
4864 ;; variables for source file compilation
4865 (when vhdl-compile-use-local-error-regexp
4866 (set (make-local-variable 'compilation-error-regexp-alist
) nil
)
4867 (set (make-local-variable 'compilation-file-regexp-alist
) nil
))
4870 (vhdl-index-menu-init)
4871 ;; add source file menu
4872 (if vhdl-source-file-menu
(vhdl-add-source-files-menu))
4874 (easy-menu-add vhdl-mode-menu-list
) ; for XEmacs
4875 (easy-menu-define vhdl-mode-menu vhdl-mode-map
4876 "Menu keymap for VHDL Mode." vhdl-mode-menu-list
)
4877 ;; initialize hideshow and add menu
4878 (vhdl-hideshow-init)
4879 (run-hooks 'menu-bar-update-hook
)
4882 (vhdl-ps-print-init)
4883 (vhdl-write-file-hooks-init)
4884 (message "VHDL Mode %s.%s" vhdl-version
4885 (if noninteractive
"" " See menu for documentation and release notes.")))
4887 (defun vhdl-activate-customizations ()
4888 "Activate all customizations on local variables."
4890 (vhdl-mode-map-init)
4891 (use-local-map vhdl-mode-map
)
4892 (set-syntax-table vhdl-mode-syntax-table
)
4893 (setq comment-column vhdl-inline-comment-column
)
4894 (setq end-comment-column vhdl-end-comment-column
)
4895 (vhdl-write-file-hooks-init)
4896 (vhdl-update-mode-menu)
4897 (vhdl-hideshow-init)
4898 (run-hooks 'menu-bar-update-hook
))
4900 (defun vhdl-write-file-hooks-init ()
4901 "Add/remove hooks when buffer is saved."
4902 (if vhdl-modify-date-on-saving
4903 (add-hook 'local-write-file-hooks
'vhdl-template-modify-noerror nil t
)
4904 (remove-hook 'local-write-file-hooks
'vhdl-template-modify-noerror t
))
4905 (if (featurep 'xemacs
) (make-local-hook 'after-save-hook
))
4906 (add-hook 'after-save-hook
'vhdl-add-modified-file nil t
))
4908 (defun vhdl-process-command-line-option (option)
4909 "Process command line options for VHDL Mode."
4912 ((equal option
"-compiler")
4913 (vhdl-set-compiler (car command-line-args-left
))
4914 (setq command-line-args-left
(cdr command-line-args-left
)))
4916 ((equal option
"-project")
4917 (vhdl-set-project (car command-line-args-left
))
4918 (setq command-line-args-left
(cdr command-line-args-left
)))))
4920 ;; make Emacs process VHDL Mode options
4921 (setq command-switch-alist
4922 (append command-switch-alist
4923 '(("-compiler" . vhdl-process-command-line-option
)
4924 ("-project" . vhdl-process-command-line-option
))))
4927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4928 ;;; Keywords and standardized words
4929 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4931 (defconst vhdl-02-keywords
4933 "abs" "access" "after" "alias" "all" "and" "architecture" "array"
4934 "assert" "attribute"
4935 "begin" "block" "body" "buffer" "bus"
4936 "case" "component" "configuration" "constant"
4937 "disconnect" "downto"
4938 "else" "elsif" "end" "entity" "exit"
4939 "file" "for" "function"
4940 "generate" "generic" "group" "guarded"
4941 "if" "impure" "in" "inertial" "inout" "is"
4942 "label" "library" "linkage" "literal" "loop"
4944 "nand" "new" "next" "nor" "not" "null"
4945 "of" "on" "open" "or" "others" "out"
4946 "package" "port" "postponed" "procedure" "process" "protected" "pure"
4947 "range" "record" "register" "reject" "rem" "report" "return"
4949 "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
4950 "then" "to" "transport" "type"
4951 "unaffected" "units" "until" "use"
4953 "wait" "when" "while" "with"
4956 "List of VHDL'02 keywords.")
4958 (defconst vhdl-ams-keywords
4960 "across" "break" "limit" "nature" "noise" "procedural" "quantity"
4961 "reference" "spectrum" "subnature" "terminal" "through"
4964 "List of VHDL-AMS keywords.")
4966 (defconst vhdl-verilog-keywords
4968 "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
4969 "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
4970 "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
4971 "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
4972 "endprimitive" "endspecify" "endtable" "endtask" "event"
4973 "for" "force" "forever" "fork" "function"
4974 "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
4975 "macromodule" "makefile" "medium" "module"
4976 "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
4977 "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
4979 "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
4980 "rtranif0" "rtranif1"
4981 "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
4982 "strong1" "supply" "supply0" "supply1"
4983 "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
4984 "triand" "trior" "trireg"
4985 "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
4987 "List of Verilog keywords as candidate for additional reserved words.")
4989 (defconst vhdl-02-types
4991 "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
4992 "real" "time" "natural" "positive" "string" "line" "text" "side"
4993 "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
4994 "std_logic" "std_logic_vector"
4995 "std_ulogic" "std_ulogic_vector"
4997 "List of VHDL'02 standardized types.")
4999 (defconst vhdl-ams-types
5000 ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
5002 ;; package `standard'
5003 "domain_type" "real_vector"
5004 ;; package `energy_systems'
5005 "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
5006 "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
5007 "real_across_vector" "real_through_vector"
5008 ;; package `electrical_systems'
5009 "voltage" "current" "charge" "resistance" "conductance" "capacitance"
5010 "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
5011 "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
5012 "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
5013 "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
5014 "magnetic_flux_vector" "charge_vector" "resistance_vector"
5015 "conductance_vector" "capacitance_vector" "electric_flux_vector"
5016 "electric_flux_density_vector" "electric_field_strength_vector"
5017 "magnetic_flux_density_vector" "magnetic_field_strength_vector"
5018 "inductance_vector" "reluctance_vector" "ground"
5019 ;; package `mechanical_systems'
5020 "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
5021 "damping" "momentum" "angle" "torque" "angular_velocity"
5022 "angular_acceleration" "moment_inertia" "angular_momentum"
5023 "angular_stiffness" "angular_damping" "translational"
5024 "translational_vector" "translational_velocity"
5025 "translational_velocity_vector" "rotational" "rotational_vector"
5026 "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
5027 "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
5028 "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
5029 "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
5030 "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
5031 "angular_momentum_vector" "angular_stiffness_vector"
5032 "angular_damping_vector" "anchor" "translational_v_ref"
5033 "rotational_v_ref" "translational_v" "rotational_v"
5034 ;; package `radiant_systems'
5035 "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
5036 "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
5037 "illuminance_vector" "irradiance_vector"
5038 ;; package `thermal_systems'
5039 "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
5040 "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
5041 "heat_flow_vector" "thermal_capacitance_vector"
5042 "thermal_resistance_vector" "thermal_conductance_vector"
5043 ;; package `fluidic_systems'
5044 "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
5045 "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
5046 "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
5047 "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
5048 "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
5049 "density_vector" "viscosity_vector" "fresistance_vector"
5050 "fconductance_vector" "fcapacitance_vector" "inertance_vector"
5051 "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
5052 "cfinertance_vector"
5054 "List of VHDL-AMS standardized types.")
5056 (defconst vhdl-math-types
5058 "complex" "complex_polar" "positive_real" "principal_value"
5060 "List of Math Packages standardized types.")
5062 (defconst vhdl-02-attributes
5064 "base" "left" "right" "high" "low" "pos" "val" "succ"
5065 "pred" "leftof" "rightof" "range" "reverse_range"
5066 "length" "delayed" "stable" "quiet" "transaction"
5067 "event" "active" "last_event" "last_active" "last_value"
5068 "driving" "driving_value" "ascending" "value" "image"
5069 "simple_name" "instance_name" "path_name"
5072 "List of VHDL'02 standardized attributes.")
5074 (defconst vhdl-ams-attributes
5077 "reference" "contribution" "tolerance"
5078 "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
5081 "List of VHDL-AMS standardized attributes.")
5083 (defconst vhdl-02-enum-values
5086 "note" "warning" "error" "failure"
5087 "read_mode" "write_mode" "append_mode"
5088 "open_ok" "status_error" "name_error" "mode_error"
5089 "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
5092 "List of VHDL'02 standardized enumeration values.")
5094 (defconst vhdl-ams-enum-values
5096 "quiescent_domain" "time_domain" "frequency_domain"
5097 ;; from `nature_pkg' package
5098 "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
5100 "List of VHDL-AMS standardized enumeration values.")
5102 (defconst vhdl-ams-constants
5103 ;; standard: IEEE Std 1076.1.1-2004
5105 ;; package `fundamental_constants'
5106 "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
5107 "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
5108 "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
5109 "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
5110 ;; package `material_constants'
5111 "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
5112 "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
5113 "ambient_temperature" "ambient_pressure" "ambient_illuminance"
5115 "List of VHDL-AMS standardized constants.")
5117 (defconst vhdl-math-constants
5118 ;; standard: IEEE Std 1076.2-1996
5120 "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
5121 "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
5122 "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
5123 "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
5124 "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
5127 "List of Math Packages standardized constants.")
5129 (defconst vhdl-02-functions
5131 "now" "resolved" "rising_edge" "falling_edge"
5132 "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
5134 "resize" "is_X" "std_match"
5135 "shift_left" "shift_right" "rotate_left" "rotate_right"
5136 "to_unsigned" "to_signed" "to_integer"
5137 "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
5138 "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
5139 "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
5140 "shl" "shr" "ext" "sxt"
5143 "List of VHDL'02 standardized functions.")
5145 (defconst vhdl-ams-functions
5147 ;; package `standard'
5150 "List of VHDL-AMS standardized functions.")
5152 (defconst vhdl-math-functions
5153 ;; standard: IEEE Std 1076.2-1996
5155 "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
5156 "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
5157 "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
5158 "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
5159 "tan" "tanh" "trunc" "uniform"
5161 "List of Math Packages standardized functions.")
5163 (defconst vhdl-02-packages
5165 "std_logic_1164" "numeric_std" "numeric_bit"
5167 "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
5168 "std_logic_misc" "std_logic_textio"
5171 "List of VHDL'02 standardized packages and libraries.")
5173 (defconst vhdl-ams-packages
5175 "fundamental_constants" "material_constants" "energy_systems"
5176 "electrical_systems" "mechanical_systems" "radiant_systems"
5177 "thermal_systems" "fluidic_systems"
5179 "List of VHDL-AMS standardized packages and libraries.")
5181 (defconst vhdl-math-packages
5183 "math_real" "math_complex"
5185 "List of Math Packages standardized packages and libraries.")
5187 (defvar vhdl-keywords nil
5188 "List of VHDL keywords.")
5190 (defvar vhdl-types nil
5191 "List of VHDL standardized types.")
5193 (defvar vhdl-attributes nil
5194 "List of VHDL standardized attributes.")
5196 (defvar vhdl-enum-values nil
5197 "List of VHDL standardized enumeration values.")
5199 (defvar vhdl-constants nil
5200 "List of VHDL standardized constants.")
5202 (defvar vhdl-functions nil
5203 "List of VHDL standardized functions.")
5205 (defvar vhdl-packages nil
5206 "List of VHDL standardized packages and libraries.")
5208 (defvar vhdl-reserved-words nil
5209 "List of additional reserved words.")
5211 (defvar vhdl-keywords-regexp nil
5212 "Regexp for VHDL keywords.")
5214 (defvar vhdl-types-regexp nil
5215 "Regexp for VHDL standardized types.")
5217 (defvar vhdl-attributes-regexp nil
5218 "Regexp for VHDL standardized attributes.")
5220 (defvar vhdl-enum-values-regexp nil
5221 "Regexp for VHDL standardized enumeration values.")
5223 (defvar vhdl-constants-regexp nil
5224 "Regexp for VHDL standardized constants.")
5226 (defvar vhdl-functions-regexp nil
5227 "Regexp for VHDL standardized functions.")
5229 (defvar vhdl-packages-regexp nil
5230 "Regexp for VHDL standardized packages and libraries.")
5232 (defvar vhdl-reserved-words-regexp nil
5233 "Regexp for additional reserved words.")
5235 (defvar vhdl-directive-keywords-regexp nil
5236 "Regexp for compiler directive keywords.")
5238 (defun vhdl-upcase-list (condition list
)
5239 "Upcase all elements in LIST based on CONDITION."
5241 (let ((tmp-list list
))
5243 (setcar tmp-list
(upcase (car tmp-list
)))
5244 (setq tmp-list
(cdr tmp-list
)))))
5247 (defun vhdl-words-init ()
5248 "Initialize reserved words."
5251 (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords
)
5252 (append vhdl-02-keywords
5253 (when (vhdl-standard-p 'ams
) vhdl-ams-keywords
))))
5256 (and vhdl-highlight-case-sensitive vhdl-upper-case-types
)
5257 (append vhdl-02-types
5258 (when (vhdl-standard-p 'ams
) vhdl-ams-types
)
5259 (when (vhdl-standard-p 'math
) vhdl-math-types
))))
5260 (setq vhdl-attributes
5262 (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes
)
5263 (append vhdl-02-attributes
5264 (when (vhdl-standard-p 'ams
) vhdl-ams-attributes
))))
5265 (setq vhdl-enum-values
5267 (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values
)
5268 (append vhdl-02-enum-values
5269 (when (vhdl-standard-p 'ams
) vhdl-ams-enum-values
))))
5270 (setq vhdl-constants
5272 (and vhdl-highlight-case-sensitive vhdl-upper-case-constants
)
5273 (append (when (vhdl-standard-p 'ams
) vhdl-ams-constants
)
5274 (when (vhdl-standard-p 'math
) vhdl-math-constants
)
5276 (setq vhdl-functions
5277 (append vhdl-02-functions
5278 (when (vhdl-standard-p 'ams
) vhdl-ams-functions
)
5279 (when (vhdl-standard-p 'math
) vhdl-math-functions
)))
5281 (append vhdl-02-packages
5282 (when (vhdl-standard-p 'ams
) vhdl-ams-packages
)
5283 (when (vhdl-standard-p 'math
) vhdl-math-packages
)))
5284 (setq vhdl-reserved-words
5285 (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words
)
5286 (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords
)
5288 (setq vhdl-keywords-regexp
5289 (concat "\\<\\(" (regexp-opt vhdl-keywords
) "\\)\\>"))
5290 (setq vhdl-types-regexp
5291 (concat "\\<\\(" (regexp-opt vhdl-types
) "\\)\\>"))
5292 (setq vhdl-attributes-regexp
5293 (concat "\\<\\(" (regexp-opt vhdl-attributes
) "\\)\\>"))
5294 (setq vhdl-enum-values-regexp
5295 (concat "\\<\\(" (regexp-opt vhdl-enum-values
) "\\)\\>"))
5296 (setq vhdl-constants-regexp
5297 (concat "\\<\\(" (regexp-opt vhdl-constants
) "\\)\\>"))
5298 (setq vhdl-functions-regexp
5299 (concat "\\<\\(" (regexp-opt vhdl-functions
) "\\)\\>"))
5300 (setq vhdl-packages-regexp
5301 (concat "\\<\\(" (regexp-opt vhdl-packages
) "\\)\\>"))
5302 (setq vhdl-reserved-words-regexp
5304 (unless (equal vhdl-forbidden-syntax
"")
5305 (concat vhdl-forbidden-syntax
"\\|"))
5306 (regexp-opt vhdl-reserved-words
)
5308 (setq vhdl-directive-keywords-regexp
5309 (concat "\\<\\(" (mapconcat 'regexp-quote
5310 vhdl-directive-keywords
"\\|") "\\)\\>"))
5311 (vhdl-abbrev-list-init))
5313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5316 (defvar vhdl-abbrev-list nil
5317 "Predefined abbreviations for VHDL.")
5319 (defun vhdl-abbrev-list-init ()
5320 (setq vhdl-abbrev-list
5322 (list vhdl-upper-case-keywords
) vhdl-keywords
5323 (list vhdl-upper-case-types
) vhdl-types
5324 (list vhdl-upper-case-attributes
) vhdl-attributes
5325 (list vhdl-upper-case-enum-values
) vhdl-enum-values
5326 (list vhdl-upper-case-constants
) vhdl-constants
5327 (list nil
) vhdl-functions
5328 (list nil
) vhdl-packages
)))
5330 ;; initialize reserved words for VHDL Mode
5334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5341 ;; constant regular expressions for looking at various constructs
5343 (defconst vhdl-symbol-key
"\\(\\w\\|\\s_\\)+"
5344 "Regexp describing a VHDL symbol.
5345 We cannot use just `word' syntax class since `_' cannot be in word
5346 class. Putting underscore in word class breaks forward word movement
5347 behavior that users are familiar with.")
5349 (defconst vhdl-case-header-key
"case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
5350 "Regexp describing a case statement header key.")
5352 (defconst vhdl-label-key
5353 (concat "\\(" vhdl-symbol-key
"\\s-*:\\)[^=]")
5354 "Regexp describing a VHDL label.")
5356 ;; Macro definitions:
5358 (defmacro vhdl-point
(position)
5359 "Return the value of point at certain commonly referenced POSITIONs.
5360 POSITION can be one of the following symbols:
5362 bol -- beginning of line
5364 bod -- beginning of defun
5365 boi -- back to indentation
5366 eoi -- last whitespace on line
5367 ionl -- indentation of next line
5368 iopl -- indentation of previous line
5369 bonl -- beginning of next line
5370 bopl -- beginning of previous line
5372 This function does not modify point or mark."
5373 (or (and (eq 'quote
(car-safe position
))
5374 (null (cddr position
)))
5375 (error "ERROR: Bad buffer position requested: %s" position
))
5376 (setq position
(nth 1 position
))
5377 `(let ((here (point)))
5379 ((eq position
'bol
) '((beginning-of-line)))
5380 ((eq position
'eol
) '((end-of-line)))
5381 ((eq position
'bod
) '((save-match-data
5382 (vhdl-beginning-of-defun))))
5383 ((eq position
'boi
) '((back-to-indentation)))
5384 ((eq position
'eoi
) '((end-of-line) (skip-chars-backward " \t")))
5385 ((eq position
'bonl
) '((forward-line 1)))
5386 ((eq position
'bopl
) '((forward-line -
1)))
5387 ((eq position
'iopl
)
5389 (back-to-indentation)))
5390 ((eq position
'ionl
)
5392 (back-to-indentation)))
5393 (t (error "ERROR: Unknown buffer position requested: %s" position
))
5398 ;; workaround for an Emacs18 bug -- blech! Well, at least it
5399 ;; doesn't hurt for v19
5403 (defmacro vhdl-safe
(&rest body
)
5404 "Safely execute BODY, return nil if an error occurred."
5405 `(condition-case nil
5409 (defmacro vhdl-add-syntax
(symbol &optional relpos
)
5410 "A simple macro to append the syntax in SYMBOL to the syntax list.
5411 Try to increase performance by using this macro."
5412 `(setq vhdl-syntactic-context
5413 (cons (cons ,symbol
,relpos
) vhdl-syntactic-context
)))
5415 (defmacro vhdl-has-syntax
(symbol)
5416 "A simple macro to return check the syntax list.
5417 Try to increase performance by using this macro."
5418 `(assoc ,symbol vhdl-syntactic-context
))
5420 ;; Syntactic element offset manipulation:
5422 (defun vhdl-read-offset (langelem)
5423 "Read new offset value for LANGELEM from minibuffer.
5424 Return a valid value only."
5425 (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist
))))
5426 (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
5428 offset input interned
)
5430 (setq input
(read-string prompt oldoff
)
5431 offset
(cond ((string-equal "+" input
) '+)
5432 ((string-equal "-" input
) '-
)
5433 ((string-equal "++" input
) '++)
5434 ((string-equal "--" input
) '--
)
5435 ((string-match "^-?[0-9]+$" input
)
5436 (string-to-number input
))
5437 ((fboundp (setq interned
(intern input
)))
5439 ((boundp interned
) interned
)
5440 ;; error, but don't signal one, keep trying
5441 ;; to read an input value
5443 (setq prompt errmsg
)
5447 (defun vhdl-set-offset (symbol offset
&optional add-p
)
5448 "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
5449 SYMBOL is the syntactic element symbol to change and OFFSET is the new
5450 offset for that syntactic element. Optional ADD-P says to add SYMBOL to
5451 `vhdl-offsets-alist' if it doesn't already appear there."
5454 (intern (completing-read
5455 (concat "Syntactic symbol to change"
5456 (if current-prefix-arg
" or add" "")
5461 (cons (format "%s" (car langelem
)) nil
)))
5463 nil
(not current-prefix-arg
)
5464 ;; initial contents tries to be the last element
5465 ;; on the syntactic analysis list for the current
5467 (let* ((syntax (vhdl-get-syntactic-context))
5468 (len (length syntax
))
5469 (ic (format "%s" (car (nth (1- len
) syntax
)))))
5472 (offset (vhdl-read-offset langelem
)))
5473 (list langelem offset current-prefix-arg
)))
5474 ;; sanity check offset
5482 (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
5484 (let ((entry (assq symbol vhdl-offsets-alist
)))
5486 (setcdr entry offset
)
5488 (setq vhdl-offsets-alist
5489 (cons (cons symbol offset
) vhdl-offsets-alist
))
5490 (error "ERROR: %s is not a valid syntactic symbol" symbol
))))
5491 (vhdl-keep-region-active))
5493 (defun vhdl-set-style (style &optional local
)
5494 "Set `vhdl-mode' variables to use one of several different indentation styles.
5495 STYLE is a string representing the desired style and optional LOCAL is
5496 a flag which, if non-nil, means to make the style variables being
5497 changed buffer local, instead of the default, which is to set the
5498 global variables. Interactively, the flag comes from the prefix
5499 argument. The styles are chosen from the `vhdl-style-alist' variable."
5500 (interactive (list (completing-read "Use which VHDL indentation style? "
5501 vhdl-style-alist nil t
)
5502 current-prefix-arg
))
5503 (let ((vars (cdr (assoc style vhdl-style-alist
))))
5505 (error "ERROR: Invalid VHDL indentation style `%s'" style
))
5506 ;; set all the variables
5510 (let ((var (car varentry
))
5511 (val (cdr varentry
)))
5512 ;; special case for vhdl-offsets-alist
5513 (if (not (eq var
'vhdl-offsets-alist
))
5514 (set (if local
(make-local-variable var
) var
) val
)
5515 ;; reset vhdl-offsets-alist to the default value first
5516 (set (if local
(make-local-variable var
) var
)
5517 (copy-alist vhdl-offsets-alist-default
))
5518 ;; now set the langelems that are different
5522 (let ((langelem (car langentry
))
5523 (offset (cdr langentry
)))
5524 (vhdl-set-offset langelem offset
)
5529 (vhdl-keep-region-active))
5531 (defun vhdl-get-offset (langelem)
5532 "Get offset from LANGELEM which is a cons cell of the form:
5533 \(SYMBOL . RELPOS). The symbol is matched against
5534 vhdl-offsets-alist and the offset found there is either returned,
5535 or added to the indentation at RELPOS. If RELPOS is nil, then
5536 the offset is simply returned."
5537 (let* ((symbol (car langelem
))
5538 (relpos (cdr langelem
))
5539 (match (assq symbol vhdl-offsets-alist
))
5540 (offset (cdr-safe match
)))
5541 ;; offset can be a number, a function, a variable, or one of the
5545 (if vhdl-strict-syntax-p
5546 (error "ERROR: Don't know how to indent a %s" symbol
)
5549 ((eq offset
'+) (setq offset vhdl-basic-offset
))
5550 ((eq offset
'-
) (setq offset
(- vhdl-basic-offset
)))
5551 ((eq offset
'++) (setq offset
(* 2 vhdl-basic-offset
)))
5552 ((eq offset
'--
) (setq offset
(* 2 (- vhdl-basic-offset
))))
5553 ((and (not (numberp offset
))
5555 (setq offset
(funcall offset langelem
)))
5556 ((not (numberp offset
))
5557 (setq offset
(eval offset
)))
5560 (< relpos
(vhdl-point 'bol
)))
5567 ;; Syntactic support functions:
5569 (defun vhdl-in-comment-p ()
5570 "Check if point is in a comment."
5571 (eq (vhdl-in-literal) 'comment
))
5573 (defun vhdl-in-string-p ()
5574 "Check if point is in a string."
5575 (eq (vhdl-in-literal) 'string
))
5577 (defun vhdl-in-quote-p ()
5578 "Check if point is in a quote ('x')."
5579 (or (and (> (point) (point-min))
5580 (< (1+ (point)) (point-max))
5581 (= (char-before (point)) ?
\')
5582 (= (char-after (1+ (point))) ?
\'))
5583 (and (> (1- (point)) (point-min))
5584 (< (point) (point-max))
5585 (= (char-before (1- (point))) ?
\')
5586 (= (char-after (point)) ?
\'))))
5588 (defun vhdl-in-literal ()
5589 "Determine if point is in a VHDL literal."
5591 (let ((state (parse-partial-sexp (vhdl-point 'bol
) (point))))
5593 ((nth 3 state
) 'string
)
5594 ((nth 4 state
) 'comment
)
5595 ((vhdl-beginning-of-macro) 'pound
)
5598 (defun vhdl-in-extended-identifier-p ()
5599 "Determine if point is inside extended identifier (delimited by '\')."
5601 (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol
) t
))
5602 (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol
) t
)))))
5604 (defun vhdl-forward-comment (&optional direction
)
5605 "Skip all comments (including whitespace). Skip backwards if DIRECTION is
5606 negative, skip forward otherwise."
5608 (if (and direction
(< direction
0))
5611 (skip-chars-backward " \t\n\r\f")
5612 (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol
) t
)
5613 (goto-char (match-beginning 3))
5614 (skip-chars-backward " \t\n\r\f")))
5616 (skip-chars-forward " \t\n\r\f")
5617 (while (looking-at "--.*")
5618 (goto-char (match-end 0))
5619 (skip-chars-forward " \t\n\r\f"))))
5621 ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
5622 (unless (and (featurep 'xemacs
) (string< "21.2" emacs-version
))
5623 (defalias 'vhdl-forward-comment
'forward-comment
))
5625 (defun vhdl-back-to-indentation ()
5626 "Move point to the first non-whitespace character on this line."
5628 (beginning-of-line 1)
5629 (skip-syntax-forward " " (vhdl-point 'eol
)))
5631 ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
5632 (when (featurep 'xemacs
)
5633 (defalias 'back-to-indentation
'vhdl-back-to-indentation
))
5635 ;; This is the best we can do in Win-Emacs.
5636 (defun vhdl-win-il (&optional lim
)
5637 "Determine if point is in a VHDL literal."
5639 (let* ((here (point))
5642 (lim (or lim
(vhdl-point 'bod
))))
5644 (while (< (point) here
)
5646 (and (re-search-forward "--\\|[\"']"
5648 (buffer-substring (match-beginning 0) (match-end 0))))
5653 ;; looking at the opening of a VHDL style comment
5654 ((string= "--" match
)
5655 (if (<= here
(progn (end-of-line) (point))) 'comment
))
5656 ;; looking at the opening of a double quote string
5657 ((string= "\"" match
)
5658 (if (not (save-restriction
5659 ;; this seems to be necessary since the
5660 ;; re-search-forward will not work without it
5661 (narrow-to-region (point) here
)
5663 ;; this regexp matches a double quote
5664 ;; which is preceded by an even number
5665 ;; of backslashes, including zero
5666 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here
'move
)))
5668 ;; looking at the opening of a single quote string
5669 ((string= "'" match
)
5670 (if (not (save-restriction
5671 ;; see comments from above
5672 (narrow-to-region (point) here
)
5674 ;; this matches a single quote which is
5675 ;; preceded by zero or two backslashes.
5676 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
5683 (and (string-match "Win-Emacs" emacs-version
)
5684 (fset 'vhdl-in-literal
'vhdl-win-il
))
5686 ;; Skipping of "syntactic whitespace". Syntactic whitespace is
5687 ;; defined as lexical whitespace or comments. Search no farther back
5688 ;; or forward than optional LIM. If LIM is omitted, (point-min) is
5689 ;; used for backward skipping, (point-max) is used for forward
5692 (defun vhdl-forward-syntactic-ws (&optional lim
)
5693 "Forward skip of syntactic whitespace."
5694 (let* ((here (point-max))
5695 (hugenum (point-max)))
5696 (while (/= here
(point))
5698 (vhdl-forward-comment hugenum
)
5699 ;; skip preprocessor directives
5700 (when (and (eq (char-after) ?
#)
5701 (= (vhdl-point 'boi
) (point)))
5702 (while (and (eq (char-before (vhdl-point 'eol
)) ?
\\)
5703 (= (forward-line 1) 0)))
5705 (if lim
(goto-char (min (point) lim
)))))
5708 ;; This is the best we can do in Win-Emacs.
5709 (defun vhdl-win-fsws (&optional lim
)
5710 "Forward skip syntactic whitespace for Win-Emacs."
5711 (let ((lim (or lim
(point-max)))
5714 (skip-chars-forward " \t\n\r\f" lim
)
5717 ((looking-at "--") (end-of-line))
5718 ;; none of the above
5719 (t (setq stop t
))))))
5721 (and (string-match "Win-Emacs" emacs-version
)
5722 (fset 'vhdl-forward-syntactic-ws
'vhdl-win-fsws
))
5724 (defun vhdl-beginning-of-macro (&optional lim
)
5725 "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
5726 (let ((here (point)))
5728 (while (eq (char-before (1- (point))) ?
\\)
5730 (back-to-indentation)
5731 (if (and (<= (point) here
)
5732 (eq (char-after) ?
#))
5737 (defun vhdl-backward-syntactic-ws (&optional lim
)
5738 "Backward skip over syntactic whitespace."
5739 (let* ((here (point-min))
5740 (hugenum (- (point-max))))
5741 (while (/= here
(point))
5743 (vhdl-forward-comment hugenum
)
5744 (vhdl-beginning-of-macro))
5745 (if lim
(goto-char (max (point) lim
)))))
5747 ;; This is the best we can do in Win-Emacs.
5748 (defun vhdl-win-bsws (&optional lim
)
5749 "Backward skip syntactic whitespace for Win-Emacs."
5750 (let ((lim (or lim
(vhdl-point 'bod
)))
5753 (skip-chars-backward " \t\n\r\f" lim
)
5756 ((eq (vhdl-in-literal) 'comment
)
5757 (skip-chars-backward "^-" lim
)
5758 (skip-chars-backward "-" lim
)
5759 (while (not (or (and (= (following-char) ?-
)
5760 (= (char-after (1+ (point))) ?-
))
5762 (skip-chars-backward "^-" lim
)
5763 (skip-chars-backward "-" lim
)))
5764 ;; none of the above
5765 (t (setq stop t
))))))
5767 (and (string-match "Win-Emacs" emacs-version
)
5768 (fset 'vhdl-backward-syntactic-ws
'vhdl-win-bsws
))
5770 ;; Functions to help finding the correct indentation column:
5772 (defun vhdl-first-word (point)
5773 "If the keyword at POINT is at boi, then return (current-column) at
5774 that point, else nil."
5776 (and (goto-char point
)
5777 (eq (point) (vhdl-point 'boi
))
5780 (defun vhdl-last-word (point)
5781 "If the keyword at POINT is at eoi, then return (current-column) at
5782 that point, else nil."
5784 (and (goto-char point
)
5785 (save-excursion (or (eq (progn (forward-sexp) (point))
5787 (looking-at "\\s-*\\(--\\)?")))
5790 ;; Core syntactic evaluation functions:
5792 (defconst vhdl-libunit-re
5793 "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
5795 (defun vhdl-libunit-p ()
5799 (skip-chars-forward " \t\n\r\f")
5800 (not (looking-at "is\\b[^_]")))
5803 (and (not (looking-at "use\\b[^_]"))
5806 (vhdl-forward-syntactic-ws)
5807 (/= (following-char) ?
:))))
5810 (defconst vhdl-defun-re
5811 "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
5813 (defun vhdl-defun-p ()
5815 (if (looking-at "block\\|process\\|procedural")
5816 ;; "block", "process", "procedural":
5819 (not (looking-at "end\\s-+\\w")))
5820 ;; "architecture", "configuration", "entity",
5821 ;; "package", "procedure", "function":
5824 (defun vhdl-corresponding-defun ()
5825 "If the word at the current position corresponds to a \"defun\"
5826 keyword, then return a string that can be used to find the
5827 corresponding \"begin\" keyword, else return nil."
5829 (and (looking-at vhdl-defun-re
)
5831 (if (looking-at "block\\|process\\|procedural")
5832 ;; "block", "process". "procedural:
5833 (buffer-substring (match-beginning 0) (match-end 0))
5834 ;; "architecture", "configuration", "entity", "package",
5835 ;; "procedure", "function":
5838 (defconst vhdl-begin-fwd-re
5839 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
5840 "A regular expression for searching forward that matches all known
5841 \"begin\" keywords.")
5843 (defconst vhdl-begin-bwd-re
5844 "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
5845 "A regular expression for searching backward that matches all known
5846 \"begin\" keywords.")
5848 (defun vhdl-begin-p (&optional lim
)
5849 "Return t if we are looking at a real \"begin\" keyword.
5850 Assumes that the caller will make sure that we are looking at
5851 vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
5852 the middle of an identifier that just happens to contain a \"begin\"
5855 ;; "[architecture|case|configuration|entity|package|
5856 ;; procedure|function] ... is":
5857 ((and (looking-at "i")
5859 ;; Skip backward over first sexp (needed to skip over a
5860 ;; procedure interface list, and is harmless in other
5861 ;; situations). Note that we need "return" in the
5862 ;; following search list so that we don't run into
5863 ;; semicolons in the function interface list.
5866 (while (and (not foundp
)
5868 ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
5870 (if (or (= (preceding-char) ?_
)
5874 (and (/= (following-char) ?\
;)
5875 (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
5877 ;; "begin", "then", "use":
5878 ((looking-at "be\\|t\\|use")
5881 ((and (looking-at "e")
5882 ;; make sure that the "else" isn't inside a
5883 ;; conditional signal assignment.
5885 (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim
'move
)
5886 (or (eq (following-char) ?\
;)
5889 ;; "block", "generate", "loop", "process", "procedural",
5890 ;; "units", "record", "protected body":
5891 ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
5894 (not (looking-at "end\\s-+\\w"))))
5897 ((and (looking-at "c")
5900 (not (looking-at "end\\s-+\\w")))
5901 ;; look out for the dreaded entity class in an attribute
5903 (vhdl-backward-syntactic-ws lim
)
5904 (/= (preceding-char) ?
:)))
5906 ;; "for" (inside configuration declaration):
5907 ((and (looking-at "f")
5910 (not (looking-at "end\\s-+\\w")))
5911 (vhdl-has-syntax 'configuration
))
5915 (defun vhdl-corresponding-mid (&optional lim
)
5917 ((looking-at "is\\|block\\|generate\\|process\\|procedural")
5919 ((looking-at "then\\|use")
5924 (defun vhdl-corresponding-end (&optional lim
)
5925 "If the word at the current position corresponds to a \"begin\"
5926 keyword, then return a vector containing enough information to find
5927 the corresponding \"end\" keyword, else return nil. The keyword to
5928 search forward for is aref 0. The column in which the keyword must
5929 appear is aref 1 or nil if any column is suitable.
5930 Assumes that the caller will make sure that we are not in the middle
5931 of an identifier that just happens to contain a \"begin\" keyword."
5933 (and (looking-at vhdl-begin-fwd-re
)
5934 (or (not (looking-at "\\<use\\>"))
5935 (save-excursion (back-to-indentation)
5936 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
5937 (/= (preceding-char) ?_
)
5938 (not (vhdl-in-literal))
5941 ;; "is", "generate", "loop":
5942 ((looking-at "[igl]")
5944 (and (vhdl-last-word (point))
5945 (or (vhdl-first-word (point))
5947 (vhdl-beginning-of-statement-1 lim
)
5948 (vhdl-backward-skip-label lim
)
5949 (vhdl-first-word (point)))))))
5950 ;; "begin", "else", "for":
5951 ((looking-at "be\\|[ef]")
5953 (and (vhdl-last-word (point))
5954 (or (vhdl-first-word (point))
5956 (vhdl-beginning-of-statement-1 lim
)
5957 (vhdl-backward-skip-label lim
)
5958 (vhdl-first-word (point)))))))
5959 ;; "component", "units", "record", "protected body":
5960 ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
5961 ;; The first end found will close the block
5963 ;; "block", "process", "procedural":
5964 ((looking-at "bl\\|p")
5966 (or (vhdl-first-word (point))
5968 (vhdl-beginning-of-statement-1 lim
)
5969 (vhdl-backward-skip-label lim
)
5970 (vhdl-first-word (point))))))
5972 ((looking-at "t\\|use")
5973 (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
5974 (and (vhdl-last-word (point))
5975 (or (vhdl-first-word (point))
5977 (vhdl-beginning-of-statement-1 lim
)
5978 (vhdl-backward-skip-label lim
)
5979 (vhdl-first-word (point)))))))
5982 (defconst vhdl-end-fwd-re
"\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
5984 (defconst vhdl-end-bwd-re
"\\b\\(end\\|else\\|elsif\\)\\b[^_]")
5986 (defun vhdl-end-p (&optional lim
)
5987 "Return t if we are looking at a real \"end\" keyword.
5988 Assumes that the caller will make sure that we are looking at
5989 vhdl-end-fwd-re, and are not inside a literal, and that we are not in
5990 the middle of an identifier that just happens to contain an \"end\"
5992 (or (not (looking-at "else"))
5993 ;; make sure that the "else" isn't inside a conditional signal
5996 (re-search-backward ";\\|\\bwhen\\b[^_]" lim
'move
)
5997 (or (eq (following-char) ?\
;)
5999 (vhdl-in-literal)))))
6001 (defun vhdl-corresponding-begin (&optional lim
)
6002 "If the word at the current position corresponds to an \"end\"
6003 keyword, then return a vector containing enough information to find
6004 the corresponding \"begin\" keyword, else return nil. The keyword to
6005 search backward for is aref 0. The column in which the keyword must
6006 appear is aref 1 or nil if any column is suitable. The supplementary
6007 keyword to search forward for is aref 2 or nil if this is not
6008 required. If aref 3 is t, then the \"begin\" keyword may be found in
6009 the middle of a statement.
6010 Assumes that the caller will make sure that we are not in the middle
6011 of an identifier that just happens to contain an \"end\" keyword."
6014 (if (and (looking-at vhdl-end-fwd-re
)
6015 (not (vhdl-in-literal))
6017 (if (looking-at "el")
6019 (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil
)
6023 (skip-chars-forward " \t\n\r\f")
6026 ((looking-at "if\\b[^_]")
6027 (vector "else\\|elsif\\|if"
6028 (vhdl-first-word pos
)
6029 "else\\|then\\|use" nil
))
6031 ((looking-at "component\\b[^_]")
6032 (vector (buffer-substring (match-beginning 1)
6034 (vhdl-first-word pos
)
6036 ;; "end units", "end record", "end protected":
6037 ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
6038 (vector (buffer-substring (match-beginning 1)
6040 (vhdl-first-word pos
)
6042 ;; "end block", "end process", "end procedural":
6043 ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
6044 (vector "begin" (vhdl-first-word pos
) nil nil
))
6046 ((looking-at "case\\b[^_]")
6047 (vector "case" (vhdl-first-word pos
) "is" nil
))
6049 ((looking-at "generate\\b[^_]")
6050 (vector "generate\\|for\\|if"
6051 (vhdl-first-word pos
)
6054 ((looking-at "loop\\b[^_]")
6055 (vector "loop\\|while\\|for"
6056 (vhdl-first-word pos
)
6058 ;; "end for" (inside configuration declaration):
6059 ((looking-at "for\\b[^_]")
6060 (vector "for" (vhdl-first-word pos
) nil nil
))
6063 (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
6064 (vhdl-first-word pos
)
6065 ;; return an alist of (statement . keyword) mappings
6067 ;; "begin ... end [id]":
6069 ;; "architecture ... is ... begin ... end [id]":
6070 ("architecture" .
"is")
6071 ;; "configuration ... is ... end [id]":
6072 ("configuration" .
"is")
6073 ;; "entity ... is ... end [id]":
6075 ;; "package ... is ... end [id]":
6077 ;; "procedure ... is ... begin ... end [id]":
6078 ("procedure" .
"is")
6079 ;; "function ... is ... begin ... end [id]":
6086 (defconst vhdl-leader-re
6087 "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
6089 (defun vhdl-end-of-leader ()
6091 (cond ((looking-at "block\\|process\\|procedural")
6094 (skip-chars-forward " \t\n\r\f")
6095 (= (following-char) ?\
())
6098 (when (looking-at "[ \t\n\r\f]*is")
6099 (goto-char (match-end 0)))
6101 ((looking-at "component")
6103 (when (looking-at "[ \t\n\r\f]*is")
6104 (goto-char (match-end 0)))
6108 (skip-chars-forward " \t\n\r\f")
6109 (while (looking-at "[,:(]")
6111 (skip-chars-forward " \t\n\r\f"))
6116 (defconst vhdl-trailer-re
6117 "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
6119 (defconst vhdl-statement-fwd-re
6120 "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
6121 "A regular expression for searching forward that matches all known
6122 \"statement\" keywords.")
6124 (defconst vhdl-statement-bwd-re
6125 "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
6126 "A regular expression for searching backward that matches all known
6127 \"statement\" keywords.")
6129 (defun vhdl-statement-p (&optional lim
)
6130 "Return t if we are looking at a real \"statement\" keyword.
6131 Assumes that the caller will make sure that we are looking at
6132 vhdl-statement-fwd-re, and are not inside a literal, and that we are not
6133 in the middle of an identifier that just happens to contain a
6134 \"statement\" keyword."
6136 ;; "for" ... "generate":
6137 ((and (looking-at "f")
6138 ;; Make sure it's the start of a parameter specification.
6141 (skip-chars-forward " \t\n\r\f")
6142 (looking-at "in\\b[^_]"))
6143 ;; Make sure it's not an "end for".
6146 (not (looking-at "end\\s-+\\w"))))
6148 ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
6149 ((and (looking-at "i")
6150 ;; Make sure it's not an "end if".
6153 (not (looking-at "end\\s-+\\w"))))
6155 ;; "while" ... "loop":
6160 (defconst vhdl-case-alternative-re
"when[( \t\n\r\f][^;=>]+=>"
6161 "Regexp describing a case statement alternative key.")
6163 (defun vhdl-case-alternative-p (&optional lim
)
6164 "Return t if we are looking at a real case alternative.
6165 Assumes that the caller will make sure that we are looking at
6166 vhdl-case-alternative-re, and are not inside a literal, and that
6167 we are not in the middle of an identifier that just happens to
6168 contain a \"when\" keyword."
6171 (while (and (not foundp
)
6172 (re-search-backward ";\\|<=" lim
'move
))
6173 (if (or (= (preceding-char) ?_
)
6177 (or (eq (following-char) ?\
;)
6181 ;; Core syntactic movement functions:
6183 (defconst vhdl-b-t-b-re
6184 (concat vhdl-begin-bwd-re
"\\|" vhdl-end-bwd-re
))
6186 (defun vhdl-backward-to-block (&optional lim
)
6187 "Move backward to the previous \"begin\" or \"end\" keyword."
6189 (while (and (not foundp
)
6190 (re-search-backward vhdl-b-t-b-re lim
'move
))
6191 (if (or (= (preceding-char) ?_
)
6196 ((and (looking-at vhdl-begin-fwd-re
)
6197 (or (not (looking-at "\\<use\\>"))
6198 (save-excursion (back-to-indentation)
6199 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6200 (/= (preceding-char) ?_
)
6202 (setq foundp
'begin
))
6204 ((and (looking-at vhdl-end-fwd-re
)
6205 (/= (preceding-char) ?_
)
6213 (defun vhdl-forward-sexp (&optional count lim
)
6214 "Move forward across one balanced expression (sexp).
6215 With COUNT, do it that many times."
6217 (let ((count (or count
1))
6218 (case-fold-search t
)
6223 (skip-chars-forward " \t\n\r\f")
6224 ;; Check for an unbalanced "end" keyword
6225 (if (and (looking-at vhdl-end-fwd-re
)
6226 (/= (preceding-char) ?_
)
6227 (not (vhdl-in-literal))
6229 (not (looking-at "else")))
6231 "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
6232 ;; If the current keyword is a "begin" keyword, then find the
6233 ;; corresponding "end" keyword.
6234 (if (setq end-vec
(vhdl-corresponding-end lim
))
6236 ;; end-re is the statement keyword to search for
6238 (concat "\\b\\(" (aref end-vec
0) "\\)\\b\\([^_]\\|\\'\\)"))
6239 ;; column is either the statement keyword target column
6241 (column (aref end-vec
1))
6242 (eol (vhdl-point 'eol
))
6243 foundp literal placeholder
)
6244 ;; Look for the statement keyword.
6245 (while (and (not foundp
)
6246 (re-search-forward end-re nil t
)
6247 (setq placeholder
(match-end 1))
6248 (goto-char (match-beginning 0)))
6249 ;; If we are in a literal, or not in the right target
6250 ;; column and not on the same line as the begin, then
6253 (/= (current-indentation) column
)
6255 (= (preceding-char) ?_
)
6256 (setq literal
(vhdl-in-literal)))
6257 (if (eq literal
'comment
)
6260 ;; An "else" keyword corresponds to both the opening brace
6261 ;; of the following sexp and the closing brace of the
6263 (if (not (looking-at "else"))
6264 (goto-char placeholder
))
6268 (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
6270 ;; If the current keyword is not a "begin" keyword, then just
6271 ;; perform the normal forward-sexp.
6274 (setq count
(1- count
))
6276 (setq target
(point)))
6280 (defun vhdl-backward-sexp (&optional count lim
)
6281 "Move backward across one balanced expression (sexp).
6282 With COUNT, do it that many times. LIM bounds any required backward
6285 (let ((count (or count
1))
6286 (case-fold-search t
)
6290 ;; Perform the normal backward-sexp, unless we are looking at
6291 ;; "else" - an "else" keyword corresponds to both the opening brace
6292 ;; of the following sexp and the closing brace of the previous sexp.
6293 (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
6294 (/= (preceding-char) ?_
)
6295 (not (vhdl-in-literal)))
6298 (if (and (looking-at vhdl-begin-fwd-re
)
6299 (or (not (looking-at "\\<use\\>"))
6301 (back-to-indentation)
6302 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6303 (/= (preceding-char) ?_
)
6304 (not (vhdl-in-literal))
6306 (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
6307 ;; If the current keyword is an "end" keyword, then find the
6308 ;; corresponding "begin" keyword.
6309 (if (and (setq begin-vec
(vhdl-corresponding-begin lim
))
6310 (/= (preceding-char) ?_
))
6312 ;; begin-re is the statement keyword to search for
6314 (concat "\\b\\(" (aref begin-vec
0) "\\)\\b[^_]"))
6315 ;; column is either the statement keyword target column
6317 (column (aref begin-vec
1))
6318 ;; internal-p controls where the statement keyword can
6320 (internal-p (aref begin-vec
3))
6321 (last-backward (point)) last-forward
6322 foundp literal keyword
)
6323 ;; Look for the statement keyword.
6324 (while (and (not foundp
)
6325 (re-search-backward begin-re lim t
)
6327 (buffer-substring (match-beginning 1)
6329 ;; If we are in a literal or in the wrong column,
6332 (and (/= (current-indentation) column
)
6333 ;; possibly accept current-column as
6334 ;; well as current-indentation.
6335 (or (not internal-p
)
6336 (/= (current-column) column
))))
6337 (= (preceding-char) ?_
)
6340 ;; If there is a supplementary keyword, then
6341 ;; search forward for it.
6342 (if (and (setq begin-re
(aref begin-vec
2))
6343 (or (not (listp begin-re
))
6344 ;; If begin-re is an alist, then find the
6345 ;; element corresponding to the actual
6346 ;; keyword that we found.
6349 (assoc keyword begin-re
))
6351 (setq begin-re
(cdr begin-re
))))))
6354 (concat "\\b\\(" begin-re
"\\)\\b[^_]"))
6356 (setq last-forward
(point))
6357 ;; Look for the supplementary keyword
6358 ;; (bounded by the backward search start
6360 (while (and (not foundp
)
6361 (re-search-forward begin-re
6363 (goto-char (match-beginning 1)))
6364 ;; If we are in a literal, then try again.
6365 (if (or (= (preceding-char) ?_
)
6368 (if (eq literal
'comment
)
6370 (min (vhdl-point 'eol
) last-backward
))
6372 ;; We have found the supplementary keyword.
6373 ;; Save the position of the keyword in foundp.
6374 (setq foundp
(point)))
6377 ;; If the supplementary keyword was found, then
6378 ;; move point to the supplementary keyword.
6380 ;; If there was no supplementary keyword, then
6381 ;; point is already at the statement keyword.
6383 ) ; end of the search for the statement keyword
6385 (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
6387 (setq count
(1- count
))
6389 (setq target
(point)))
6393 (defun vhdl-backward-up-list (&optional count limit
)
6394 "Move backward out of one level of blocks.
6395 With argument, do this that many times."
6397 (let ((count (or count
1))
6401 (if (looking-at vhdl-defun-re
)
6402 (error "ERROR: Unbalanced blocks"))
6403 (vhdl-backward-to-block limit
)
6404 (setq count
(1- count
)))
6405 (setq target
(point)))
6406 (goto-char target
)))
6408 (defun vhdl-end-of-defun (&optional count
)
6409 "Move forward to the end of a VHDL defun."
6411 (let ((case-fold-search t
))
6412 (vhdl-beginning-of-defun)
6413 (if (not (looking-at "block\\|process\\|procedural"))
6414 (re-search-forward "\\bis\\b"))
6415 (vhdl-forward-sexp)))
6417 (defun vhdl-mark-defun ()
6418 "Put mark at end of this \"defun\", point at beginning."
6420 (let ((case-fold-search t
))
6422 (vhdl-beginning-of-defun)
6424 (if (not (looking-at "block\\|process\\|procedural"))
6425 (re-search-forward "\\bis\\b"))
6427 (exchange-point-and-mark)))
6429 (defun vhdl-beginning-of-libunit ()
6430 "Move backward to the beginning of a VHDL library unit.
6431 Returns the location of the corresponding begin keyword, unless search
6432 stops due to beginning or end of buffer.
6433 Note that if point is between the \"libunit\" keyword and the
6434 corresponding \"begin\" keyword, then that libunit will not be
6435 recognized, and the search will continue backwards. If point is
6436 at the \"begin\" keyword, then the defun will be recognized. The
6437 returned point is at the first character of the \"libunit\" keyword."
6438 (let ((last-forward (point))
6440 ;; Just in case we are actually sitting on the "begin"
6441 ;; keyword, allow for the keyword and an extra character,
6442 ;; as this will be used when looking forward for the
6444 (save-excursion (forward-word 1) (1+ (point))))
6445 foundp literal placeholder
)
6446 ;; Find the "libunit" keyword.
6447 (while (and (not foundp
)
6448 (re-search-backward vhdl-libunit-re nil
'move
))
6449 ;; If we are in a literal, or not at a real libunit, then try again.
6450 (if (or (= (preceding-char) ?_
)
6452 (not (vhdl-libunit-p)))
6454 ;; Find the corresponding "begin" keyword.
6455 (setq last-forward
(point))
6456 (while (and (not foundp
)
6457 (re-search-forward "\\bis\\b[^_]" last-backward t
)
6458 (setq placeholder
(match-beginning 0)))
6459 (if (or (= (preceding-char) ?_
)
6460 (setq literal
(vhdl-in-literal)))
6461 ;; It wasn't a real keyword, so keep searching.
6462 (if (eq literal
'comment
)
6464 (min (vhdl-point 'eol
) last-backward
))
6466 ;; We have found the begin keyword, loop will exit.
6467 (setq foundp placeholder
)))
6468 ;; Go back to the libunit keyword
6469 (goto-char last-forward
)))
6472 (defun vhdl-beginning-of-defun (&optional count
)
6473 "Move backward to the beginning of a VHDL defun.
6474 With argument, do it that many times.
6475 Returns the location of the corresponding begin keyword, unless search
6476 stops due to beginning or end of buffer."
6477 ;; Note that if point is between the "defun" keyword and the
6478 ;; corresponding "begin" keyword, then that defun will not be
6479 ;; recognized, and the search will continue backwards. If point is
6480 ;; at the "begin" keyword, then the defun will be recognized. The
6481 ;; returned point is at the first character of the "defun" keyword.
6483 (let ((count (or count
1))
6484 (case-fold-search t
)
6485 (last-forward (point))
6489 (goto-char last-forward
)
6490 (let ((last-backward
6491 ;; Just in case we are actually sitting on the "begin"
6492 ;; keyword, allow for the keyword and an extra character,
6493 ;; as this will be used when looking forward for the
6495 (save-excursion (forward-word 1) (1+ (point))))
6496 begin-string literal
)
6497 (while (and (not foundp
)
6498 (re-search-backward vhdl-defun-re nil
'move
))
6499 ;; If we are in a literal, then try again.
6500 (if (or (= (preceding-char) ?_
)
6503 (if (setq begin-string
(vhdl-corresponding-defun))
6504 ;; This is a real defun keyword.
6505 ;; Find the corresponding "begin" keyword.
6506 ;; Look for the begin keyword.
6508 ;; Save the search start point.
6509 (setq last-forward
(point))
6510 (while (and (not foundp
)
6511 (search-forward begin-string last-backward t
))
6512 (if (or (= (preceding-char) ?_
)
6514 (setq literal
(vhdl-in-literal))))
6515 ;; It wasn't a real keyword, so keep searching.
6516 (if (eq literal
'comment
)
6518 (min (vhdl-point 'eol
) last-backward
))
6520 ;; We have found the begin keyword, loop will exit.
6521 (setq foundp
(match-beginning 0)))
6523 ;; Go back to the defun keyword
6524 (goto-char last-forward
)) ; end search for begin keyword
6526 ) ; end of the search for the defun keyword
6528 (setq count
(1- count
))
6530 (vhdl-keep-region-active)
6533 (defun vhdl-beginning-of-statement (&optional count lim interactive
)
6534 "Go to the beginning of the innermost VHDL statement.
6535 With prefix arg, go back N - 1 statements. If already at the
6536 beginning of a statement then go to the beginning of the preceding
6537 one. If within a string or comment, or next to a comment (only
6538 whitespace between), move by sentences instead of statements.
6540 When called from a program, this function takes 3 optional args: the
6541 prefix arg, a buffer position limit which is the farthest back to
6542 search, and an argument indicating an interactive call."
6543 (interactive "p\np")
6544 (let ((count (or count
1))
6545 (case-fold-search t
)
6546 (lim (or lim
(point-min)))
6551 (setq state
(parse-partial-sexp (point) here nil nil
)))
6552 (if (and interactive
6555 (looking-at (concat "[ \t]*" comment-start-skip
))))
6556 (forward-sentence (- count
))
6558 (vhdl-beginning-of-statement-1 lim
)
6559 (setq count
(1- count
))))
6560 ;; its possible we've been left up-buf of lim
6561 (goto-char (max (point) lim
))
6563 (vhdl-keep-region-active))
6565 (defconst vhdl-e-o-s-re
6566 (concat ";\\|" vhdl-begin-fwd-re
"\\|" vhdl-statement-fwd-re
))
6568 (defun vhdl-end-of-statement ()
6569 "Very simple implementation."
6571 (re-search-forward vhdl-e-o-s-re
))
6573 (defconst vhdl-b-o-s-re
6574 (concat ";[^_]\\|\([^_]\\|\)[^_]\\|\\bwhen\\b[^_]\\|"
6575 vhdl-begin-bwd-re
"\\|" vhdl-statement-bwd-re
))
6577 (defun vhdl-beginning-of-statement-1 (&optional lim
)
6578 "Move to the start of the current statement, or the previous
6579 statement if already at the beginning of one."
6580 (let ((lim (or lim
(point-min)))
6584 ;; go backwards one balanced expression, but be careful of
6585 ;; unbalanced paren being reached
6586 (if (not (vhdl-safe (progn (backward-sexp) t
)))
6588 (backward-up-list 1)
6590 (vhdl-forward-syntactic-ws here
)
6592 (while (and (not donep
)
6594 ;; look backwards for a statement boundary
6595 (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim
'move
)))
6596 (if (or (= (preceding-char) ?_
)
6600 ;; If we are looking at an open paren, then stop after it
6601 ((eq (following-char) ?\
()
6603 (vhdl-forward-syntactic-ws here
)
6605 ;; If we are looking at a close paren, then skip it
6606 ((eq (following-char) ?\
))
6611 (progn (goto-char pos
)
6612 (vhdl-forward-syntactic-ws here
)
6614 ;; If we are looking at a semicolon, then stop
6615 ((and (eq (following-char) ?\
;) (not (vhdl-in-quote-p)))
6618 (vhdl-forward-syntactic-ws here
)
6620 ;; If we are looking at a "begin", then stop
6621 ((and (looking-at vhdl-begin-fwd-re
)
6622 (or (not (looking-at "\\<use\\>"))
6624 (back-to-indentation)
6625 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6626 (/= (preceding-char) ?_
)
6628 ;; If it's a leader "begin", then find the
6630 (if (looking-at vhdl-leader-re
)
6632 ;; set a default stop point at the begin
6634 ;; is the start point inside the leader area ?
6635 (goto-char (vhdl-end-of-leader))
6636 (vhdl-forward-syntactic-ws here
)
6637 (if (< (point) here
)
6638 ;; start point was not inside leader area
6639 ;; set stop point at word after leader
6640 (setq pos
(point))))
6642 (vhdl-forward-syntactic-ws here
)
6646 ;; If we are looking at a "statement", then stop
6647 ((and (looking-at vhdl-statement-fwd-re
)
6648 (/= (preceding-char) ?_
)
6649 (vhdl-statement-p nil
))
6651 ;; If we are looking at a case alternative key, then stop
6652 ((and (looking-at vhdl-case-alternative-re
)
6653 (vhdl-case-alternative-p lim
))
6655 ;; set a default stop point at the when
6657 ;; is the start point inside the case alternative key ?
6658 (looking-at vhdl-case-alternative-re
)
6659 (goto-char (match-end 0))
6660 (vhdl-forward-syntactic-ws here
)
6661 (if (< (point) here
)
6662 ;; start point was not inside the case alternative key
6663 ;; set stop point at word after case alternative keyleader
6664 (setq pos
(point))))
6667 ;; Bogus find, continue
6672 ;; Defuns for calculating the current syntactic state:
6674 (defun vhdl-get-library-unit (bod placeholder
)
6675 "If there is an enclosing library unit at BOD, with its \"begin\"
6676 keyword at PLACEHOLDER, then return the library unit type."
6677 (let ((here (vhdl-point 'bol
)))
6679 (goto-char placeholder
)
6680 (vhdl-safe (vhdl-forward-sexp 1 bod
))
6685 ((looking-at "e") 'entity
)
6686 ((looking-at "a") 'architecture
)
6687 ((looking-at "c") 'configuration
)
6692 (vhdl-forward-syntactic-ws here
)
6693 (if (looking-at "body\\b[^_]")
6694 'package-body
'package
))))))
6697 (defun vhdl-get-block-state (&optional lim
)
6698 "Finds and records all the closest opens.
6699 LIM is the furthest back we need to search (it should be the
6700 previous libunit keyword)."
6701 (let ((here (point))
6702 (lim (or lim
(point-min)))
6703 keyword sexp-start sexp-mid sexp-end
6704 preceding-sexp containing-sexp
6705 containing-begin containing-mid containing-paren
)
6707 ;; Find the containing-paren, and use that as the limit
6708 (if (setq containing-paren
6710 (narrow-to-region lim
(point))
6711 (vhdl-safe (scan-lists (point) -
1 1))))
6712 (setq lim containing-paren
))
6713 ;; Look backwards for "begin" and "end" keywords.
6714 (while (and (> (point) lim
)
6715 (not containing-sexp
))
6716 (setq keyword
(vhdl-backward-to-block lim
))
6718 ((eq keyword
'begin
)
6719 ;; Found a "begin" keyword
6720 (setq sexp-start
(point))
6721 (setq sexp-mid
(vhdl-corresponding-mid lim
))
6722 (setq sexp-end
(vhdl-safe
6724 (vhdl-forward-sexp 1 lim
) (point))))
6725 (if (and sexp-end
(<= sexp-end here
))
6726 ;; we want to record this sexp, but we only want to
6727 ;; record the last-most of any of them before here
6729 (setq preceding-sexp sexp-start
))
6730 ;; we're contained in this sexp so put sexp-start on
6732 (setq containing-sexp sexp-start
)
6733 (setq containing-mid sexp-mid
)
6734 (setq containing-begin t
)))
6736 ;; Found an "end" keyword
6738 (setq sexp-end
(point))
6741 (or (vhdl-safe (vhdl-backward-sexp 1 lim
) (point))
6742 (progn (backward-sexp) (point))))
6743 ;; we want to record this sexp, but we only want to
6744 ;; record the last-most of any of them before here
6746 (setq preceding-sexp sexp-start
)))
6748 ;; Check if the containing-paren should be the containing-sexp
6749 (if (and containing-paren
6750 (or (null containing-sexp
)
6751 (< containing-sexp containing-paren
)))
6752 (setq containing-sexp containing-paren
6754 containing-begin nil
6755 containing-mid nil
))
6756 (vector containing-sexp preceding-sexp containing-begin containing-mid
)
6760 (defconst vhdl-s-c-a-re
6761 (concat vhdl-case-alternative-re
"\\|" vhdl-case-header-key
))
6763 (defun vhdl-skip-case-alternative (&optional lim
)
6764 "Skip forward over case/when bodies, with optional maximal
6765 limit. If no next case alternative is found, nil is returned and
6766 point is not moved."
6767 (let ((lim (or lim
(point-max)))
6770 (while (and (< (point) lim
)
6772 (if (and (re-search-forward vhdl-s-c-a-re lim
'move
)
6774 (not (vhdl-in-literal)))
6775 (/= (match-beginning 0) here
))
6777 (goto-char (match-beginning 0))
6779 ((and (looking-at "case")
6780 (re-search-forward "\\bis[^_]" lim t
))
6782 (vhdl-forward-sexp))
6790 (defun vhdl-backward-skip-label (&optional lim
)
6791 "Skip backward over a label, with optional maximal
6792 limit. If label is not found, nil is returned and point
6794 (let ((lim (or lim
(point-min)))
6797 (vhdl-backward-syntactic-ws lim
)
6798 (and (eq (preceding-char) ?
:)
6801 (setq placeholder
(point))
6802 (looking-at vhdl-label-key
))))
6803 (goto-char placeholder
))
6806 (defun vhdl-forward-skip-label (&optional lim
)
6807 "Skip forward over a label, with optional maximal
6808 limit. If label is not found, nil is returned and point
6810 (let ((lim (or lim
(point-max))))
6811 (if (looking-at vhdl-label-key
)
6813 (goto-char (match-end 0))
6814 (vhdl-forward-syntactic-ws lim
)))
6817 (defun vhdl-get-syntactic-context ()
6818 "Guess the syntactic description of the current line of VHDL code."
6822 (let* ((indent-point (point))
6823 (case-fold-search t
)
6824 vec literal containing-sexp preceding-sexp
6825 containing-begin containing-mid containing-leader
6826 char-before-ip char-after-ip begin-after-ip end-after-ip
6827 placeholder lim library-unit
6830 ;; Reset the syntactic context
6831 (setq vhdl-syntactic-context nil
)
6834 ;; Move to the start of the previous library unit, and
6835 ;; record the position of the "begin" keyword.
6836 (setq placeholder
(vhdl-beginning-of-libunit))
6837 ;; The position of the "libunit" keyword gives us a gross
6842 ;; If there is a previous library unit, and we are enclosed by
6843 ;; it, then set the syntax accordingly.
6845 (setq library-unit
(vhdl-get-library-unit lim placeholder
))
6846 (vhdl-add-syntax library-unit lim
))
6848 ;; Find the surrounding state.
6849 (if (setq vec
(vhdl-get-block-state lim
))
6851 (setq containing-sexp
(aref vec
0))
6852 (setq preceding-sexp
(aref vec
1))
6853 (setq containing-begin
(aref vec
2))
6854 (setq containing-mid
(aref vec
3))
6857 ;; set the limit on the farthest back we need to search
6858 (setq lim
(if containing-sexp
6860 (goto-char containing-sexp
)
6861 ;; set containing-leader if required
6862 (if (looking-at vhdl-leader-re
)
6863 (setq containing-leader
(vhdl-end-of-leader)))
6867 ;; cache char before and after indent point, and move point to
6868 ;; the most likely position to perform the majority of tests
6869 (goto-char indent-point
)
6870 (skip-chars-forward " \t")
6871 (setq literal
(vhdl-in-literal))
6872 (setq char-after-ip
(following-char))
6873 (setq begin-after-ip
(and
6875 (looking-at vhdl-begin-fwd-re
)
6876 (or (not (looking-at "\\<use\\>"))
6878 (back-to-indentation)
6879 (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
6881 (setq end-after-ip
(and
6883 (looking-at vhdl-end-fwd-re
)
6885 (vhdl-backward-syntactic-ws lim
)
6886 (setq char-before-ip
(preceding-char))
6887 (goto-char indent-point
)
6888 (skip-chars-forward " \t")
6890 ;; now figure out syntactic qualities of the current line
6892 ;; CASE 1: in a string or comment.
6893 ((memq literal
'(string comment
))
6894 (vhdl-add-syntax literal
(vhdl-point 'bopl
)))
6895 ;; CASE 2: Line is at top level.
6896 ((null containing-sexp
)
6897 ;; Find the point to which indentation will be relative
6899 (if (null preceding-sexp
)
6901 ;; no preceding-sexp -> use the preceding statement
6902 (vhdl-beginning-of-statement-1 lim
)
6904 ;; if there is a preceding-sexp then indent relative to it
6905 (goto-char preceding-sexp
)
6906 ;; if not at boi, then the block-opening keyword is
6907 ;; probably following a label, so we need a different
6909 (if (/= (point) (vhdl-point 'boi
))
6911 (vhdl-beginning-of-statement-1 lim
)))
6912 ;; v-b-o-s could have left us at point-min
6915 (vhdl-forward-syntactic-ws indent-point
))
6916 (setq placeholder
(point)))
6918 ;; CASE 2A : we are looking at a block-open
6920 (vhdl-add-syntax 'block-open placeholder
))
6921 ;; CASE 2B: we are looking at a block-close
6923 (vhdl-add-syntax 'block-close placeholder
))
6924 ;; CASE 2C: we are looking at a top-level statement
6926 (vhdl-backward-syntactic-ws lim
)
6928 (and (= (preceding-char) ?\
;)
6929 (not (vhdl-in-quote-p)))))
6930 (vhdl-add-syntax 'statement placeholder
))
6931 ;; CASE 2D: we are looking at a top-level statement-cont
6933 (vhdl-beginning-of-statement-1 lim
)
6934 ;; v-b-o-s could have left us at point-min
6937 (vhdl-forward-syntactic-ws indent-point
))
6938 (vhdl-add-syntax 'statement-cont
(point)))
6940 ;; CASE 3: line is inside parentheses. Most likely we are
6941 ;; either in a subprogram argument (interface) list, or a
6942 ;; continued expression containing parentheses.
6943 ((null containing-begin
)
6944 (vhdl-backward-syntactic-ws containing-sexp
)
6946 ;; CASE 3A: we are looking at the arglist closing paren
6947 ((eq char-after-ip ?\
))
6948 (goto-char containing-sexp
)
6949 (vhdl-add-syntax 'arglist-close
(vhdl-point 'boi
)))
6950 ;; CASE 3B: we are looking at the first argument in an empty
6952 ((eq char-before-ip ?\
()
6953 (goto-char containing-sexp
)
6954 (vhdl-add-syntax 'arglist-intro
(vhdl-point 'boi
)))
6955 ;; CASE 3C: we are looking at an arglist continuation line,
6956 ;; but the preceding argument is on the same line as the
6957 ;; opening paren. This case includes multi-line
6958 ;; expression paren groupings.
6959 ((and (save-excursion
6960 (goto-char (1+ containing-sexp
))
6961 (skip-chars-forward " \t")
6963 (not (looking-at "--")))
6965 (vhdl-beginning-of-statement-1 containing-sexp
)
6966 (skip-chars-backward " \t(")
6967 (while (and (= (preceding-char) ?\
;)
6968 (not (vhdl-in-quote-p)))
6969 (vhdl-beginning-of-statement-1 containing-sexp
)
6970 (skip-chars-backward " \t("))
6971 (<= (point) containing-sexp
)))
6972 (goto-char containing-sexp
)
6973 (vhdl-add-syntax 'arglist-cont-nonempty
(vhdl-point 'boi
)))
6974 ;; CASE 3D: we are looking at just a normal arglist
6975 ;; continuation line
6976 (t (vhdl-beginning-of-statement-1 containing-sexp
)
6977 (vhdl-forward-syntactic-ws indent-point
)
6978 (vhdl-add-syntax 'arglist-cont
(vhdl-point 'boi
)))
6980 ;; CASE 4: A block mid open
6981 ((and begin-after-ip
6982 (looking-at containing-mid
))
6983 (goto-char containing-sexp
)
6984 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6985 (if (looking-at vhdl-trailer-re
)
6987 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil
)))
6988 (vhdl-backward-skip-label (vhdl-point 'boi
))
6989 (vhdl-add-syntax 'block-open
(point)))
6990 ;; CASE 5: block close brace
6992 (goto-char containing-sexp
)
6993 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
6994 (if (looking-at vhdl-trailer-re
)
6996 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil
)))
6997 (vhdl-backward-skip-label (vhdl-point 'boi
))
6998 (vhdl-add-syntax 'block-close
(point)))
6999 ;; CASE 6: A continued statement
7000 ((and (/= char-before-ip ?\
;)
7001 ;; check it's not a trailer begin keyword, or a begin
7002 ;; keyword immediately following a label.
7003 (not (and begin-after-ip
7004 (or (looking-at vhdl-trailer-re
)
7006 (vhdl-backward-skip-label containing-sexp
)))))
7007 ;; check it's not a statement keyword
7008 (not (and (looking-at vhdl-statement-fwd-re
)
7009 (vhdl-statement-p)))
7010 ;; see if the b-o-s is before the indent point
7013 (vhdl-beginning-of-statement-1 containing-sexp
)
7014 ;; If we ended up after a leader, then this will
7015 ;; move us forward to the start of the first
7016 ;; statement. Note that a containing sexp here is
7017 ;; always a keyword, not a paren, so this will
7018 ;; have no effect if we hit the containing-sexp.
7019 (vhdl-forward-syntactic-ws indent-point
)
7020 (setq placeholder
(point))))
7021 ;; check it's not a block-intro
7022 (/= placeholder containing-sexp
)
7023 ;; check it's not a case block-intro
7025 (goto-char placeholder
)
7026 (or (not (looking-at vhdl-case-alternative-re
))
7027 (> (match-end 0) indent-point
))))
7028 ;; Make placeholder skip a label, but only if it puts us
7029 ;; before the indent point at the start of a line.
7030 (let ((new placeholder
))
7031 (if (and (> indent-point
7033 (goto-char placeholder
)
7034 (vhdl-forward-skip-label indent-point
)
7035 (setq new
(point))))
7038 (eq new
(progn (back-to-indentation) (point)))))
7039 (setq placeholder new
)))
7040 (vhdl-add-syntax 'statement-cont placeholder
)
7042 (vhdl-add-syntax 'block-open
)))
7043 ;; Statement. But what kind?
7044 ;; CASE 7: A case alternative key
7045 ((and (looking-at vhdl-case-alternative-re
)
7046 (vhdl-case-alternative-p containing-sexp
))
7047 ;; for a case alternative key, we set relpos to the first
7048 ;; non-whitespace char on the line containing the "case"
7050 (goto-char containing-sexp
)
7051 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7052 (if (looking-at vhdl-trailer-re
)
7053 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil
)))
7054 (vhdl-add-syntax 'case-alternative
(vhdl-point 'boi
)))
7055 ;; CASE 8: statement catchall
7057 ;; we know its a statement, but we need to find out if it is
7058 ;; the first statement in a block
7059 (if containing-leader
7060 (goto-char containing-leader
)
7061 (goto-char containing-sexp
)
7062 ;; Note that a containing sexp here is always a keyword,
7063 ;; not a paren, so skip over the keyword.
7065 ;; move to the start of the first statement
7066 (vhdl-forward-syntactic-ws indent-point
)
7067 (setq placeholder
(point))
7068 ;; we want to ignore case alternatives keys when skipping forward
7070 (while (looking-at vhdl-case-alternative-re
)
7071 (setq incase-p
(point))
7072 ;; we also want to skip over the body of the
7073 ;; case/when statement if that doesn't put us at
7074 ;; after the indent-point
7075 (while (vhdl-skip-case-alternative indent-point
))
7076 ;; set up the match end
7077 (looking-at vhdl-case-alternative-re
)
7078 (goto-char (match-end 0))
7079 ;; move to the start of the first case alternative statement
7080 (vhdl-forward-syntactic-ws indent-point
)
7081 (setq placeholder
(point)))
7083 ;; CASE 8A: we saw a case/when statement so we must be
7084 ;; in a switch statement. find out if we are at the
7085 ;; statement just after a case alternative key
7087 (= (point) indent-point
))
7088 ;; relpos is the "when" keyword
7089 (vhdl-add-syntax 'statement-case-intro incase-p
))
7090 ;; CASE 8B: any old statement
7091 ((< (point) indent-point
)
7092 ;; relpos is the first statement of the block
7093 (vhdl-add-syntax 'statement placeholder
)
7095 (vhdl-add-syntax 'block-open
)))
7096 ;; CASE 8C: first statement in a block
7098 (goto-char containing-sexp
)
7099 ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
7100 (if (looking-at vhdl-trailer-re
)
7101 (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil
)))
7102 (vhdl-backward-skip-label (vhdl-point 'boi
))
7103 (vhdl-add-syntax 'statement-block-intro
(point))
7105 (vhdl-add-syntax 'block-open
)))
7109 ;; now we need to look at any modifiers
7110 (goto-char indent-point
)
7111 (skip-chars-forward " \t")
7112 (if (looking-at "--")
7113 (vhdl-add-syntax 'comment
))
7114 (if (eq literal
'pound
)
7115 (vhdl-add-syntax 'cpp-macro
))
7116 ;; return the syntax
7117 vhdl-syntactic-context
))))
7119 ;; Standard indentation line-ups:
7121 (defun vhdl-lineup-arglist (langelem)
7122 "Lineup the current arglist line with the arglist appearing just
7123 after the containing paren which starts the arglist."
7125 (let* ((containing-sexp
7127 ;; arglist-cont-nonempty gives relpos ==
7128 ;; to boi of containing-sexp paren. This
7129 ;; is good when offset is +, but bad
7130 ;; when it is vhdl-lineup-arglist, so we
7131 ;; have to special case a kludge here.
7132 (if (memq (car langelem
) '(arglist-intro arglist-cont-nonempty
))
7135 (backward-up-list 1)
7136 (skip-chars-forward " \t" (vhdl-point 'eol
)))
7137 (goto-char (cdr langelem
)))
7139 (cs-curcol (save-excursion
7140 (goto-char (cdr langelem
))
7144 (looking-at "[ \t]*)"))
7145 (progn (goto-char (match-end 0))
7148 (vhdl-forward-syntactic-ws)
7149 (- (current-column) cs-curcol
))
7150 (goto-char containing-sexp
)
7152 (let ((eol (vhdl-point 'eol
))
7155 (skip-chars-forward " \t")
7157 (vhdl-forward-syntactic-ws)
7160 (- (current-column) cs-curcol
)
7163 (defun vhdl-lineup-arglist-intro (langelem)
7164 "Lineup an arglist-intro line to just after the open paren."
7166 (let ((cs-curcol (save-excursion
7167 (goto-char (cdr langelem
))
7169 (ce-curcol (save-excursion
7171 (backward-up-list 1)
7172 (skip-chars-forward " \t" (vhdl-point 'eol
))
7174 (- ce-curcol cs-curcol -
1))))
7176 (defun vhdl-lineup-comment (langelem)
7177 "Support old behavior for comment indentation. We look at
7178 vhdl-comment-only-line-offset to decide how to indent comment
7181 (back-to-indentation)
7182 ;; at or to the right of comment-column
7183 (if (>= (current-column) comment-column
)
7184 (vhdl-comment-indent)
7185 ;; otherwise, indent as specified by vhdl-comment-only-line-offset
7187 (or (car-safe vhdl-comment-only-line-offset
)
7188 vhdl-comment-only-line-offset
)
7189 (or (cdr-safe vhdl-comment-only-line-offset
)
7190 (car-safe vhdl-comment-only-line-offset
)
7191 -
1000 ;jam it against the left side
7194 (defun vhdl-lineup-statement-cont (langelem)
7195 "Line up statement-cont after the assignment operator."
7197 (let* ((relpos (cdr langelem
))
7198 (assignp (save-excursion
7199 (goto-char (vhdl-point 'boi
))
7200 (and (re-search-forward "\\(<\\|:\\|=\\)="
7201 (vhdl-point 'eol
) t
)
7202 (- (point) (vhdl-point 'boi
)))))
7207 (while (and (not foundp
)
7208 (< (point) (vhdl-point 'eol
)))
7209 (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol
) 'move
)
7210 (if (vhdl-in-literal)
7212 (if (= (preceding-char) ?\
()
7213 ;; skip over any parenthesized expressions
7214 (goto-char (min (vhdl-point 'eol
)
7215 (scan-lists (point) 1 1)))
7216 ;; found an assignment operator (not at eol)
7217 (setq foundp
(not (looking-at "\\s-*$"))))))
7219 ;; there's no assignment operator on the line
7221 ;; calculate indentation column after assign and ws, unless
7222 ;; our line contains an assignment operator
7226 (skip-chars-forward " \t")
7228 (- (current-column) assignp curcol
))
7231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7232 ;; Progress reporting
7234 (defvar vhdl-progress-info nil
7235 "Array variable for progress information: 0 begin, 1 end, 2 time.")
7237 (defun vhdl-update-progress-info (string pos
)
7238 "Update progress information."
7239 (when (and vhdl-progress-info
(not noninteractive
)
7240 (< vhdl-progress-interval
7241 (- (nth 1 (current-time)) (aref vhdl-progress-info
2))))
7242 (let ((delta (- (aref vhdl-progress-info
1)
7243 (aref vhdl-progress-info
0))))
7245 (message (concat string
"... (100%s)") "%")
7246 (message (concat string
"... (%2d%s)")
7247 (/ (* 100 (- pos
(aref vhdl-progress-info
0)))
7249 (aset vhdl-progress-info
2 (nth 1 (current-time)))))
7251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7252 ;; Indentation commands
7254 (defun vhdl-electric-tab (&optional prefix-arg
)
7255 "If preceding character is part of a word or a paren then hippie-expand,
7256 else if right of non whitespace on line then insert tab,
7257 else if last command was a tab or return then dedent one step or if a comment
7258 toggle between normal indent and inline comment indent,
7259 else indent `correctly'."
7261 (vhdl-prepare-search-2
7263 ;; indent region if region is active
7264 ((and (not (featurep 'xemacs
)) (use-region-p))
7265 (vhdl-indent-region (region-beginning) (region-end) nil
))
7267 ((= (char-syntax (preceding-char)) ?w
)
7268 (let ((case-fold-search (not vhdl-word-completion-case-sensitive
))
7270 (hippie-expand-only-buffers
7271 (or (and (boundp 'hippie-expand-only-buffers
)
7272 hippie-expand-only-buffers
)
7274 (vhdl-expand-abbrev prefix-arg
)))
7275 ;; expand parenthesis
7276 ((or (= (preceding-char) ?\
() (= (preceding-char) ?\
)))
7277 (let ((case-fold-search (not vhdl-word-completion-case-sensitive
))
7279 (vhdl-expand-paren prefix-arg
)))
7281 ((> (current-column) (current-indentation))
7283 ;; toggle comment indent
7284 ((and (looking-at "--")
7285 (or (eq last-command
'vhdl-electric-tab
)
7286 (eq last-command
'vhdl-electric-return
)))
7287 (cond ((= (current-indentation) 0) ; no indent
7289 (indent-according-to-mode))
7290 ((< (current-indentation) comment-column
) ; normal indent
7291 (indent-to comment-column
)
7292 (indent-according-to-mode))
7293 (t ; inline comment indent
7294 (delete-region (line-beginning-position) (point)))))
7296 ((and (>= (current-indentation) vhdl-basic-offset
)
7297 (or (eq last-command
'vhdl-electric-tab
)
7298 (eq last-command
'vhdl-electric-return
)))
7299 (backward-delete-char-untabify vhdl-basic-offset nil
))
7301 (t (indent-according-to-mode)))
7302 (setq this-command
'vhdl-electric-tab
)))
7304 (defun vhdl-electric-return ()
7305 "newline-and-indent or indent-new-comment-line if in comment and preceding
7306 character is a space."
7308 (if (and (= (preceding-char) ?
) (vhdl-in-comment-p))
7309 (indent-new-comment-line)
7310 (when (and (>= (preceding-char) ?a
) (<= (preceding-char) ?z
)
7311 (not (vhdl-in-comment-p)))
7312 (vhdl-fix-case-word -
1))
7313 (newline-and-indent)))
7315 (defun vhdl-indent-line ()
7316 "Indent the current line as VHDL code. Returns the amount of
7317 indentation change."
7319 (let* ((syntax (and vhdl-indent-syntax-based
(vhdl-get-syntactic-context)))
7320 (pos (- (point-max) (point)))
7324 ;; indent syntax-based
7325 (if (and (eq (caar syntax
) 'comment
)
7326 (>= (vhdl-get-offset (car syntax
)) comment-column
))
7327 ;; special case: comments at or right of comment-column
7328 (vhdl-get-offset (car syntax
))
7329 ;; align comments like following code line
7330 (when vhdl-indent-comment-like-next-code-line
7332 (while (eq (caar syntax
) 'comment
)
7334 (beginning-of-line 2)
7335 (setq syntax
(vhdl-get-syntactic-context)))))
7337 (push (cons 'comment nil
) syntax
))
7338 (apply '+ (mapcar 'vhdl-get-offset syntax
)))
7339 ;; indent like previous nonblank line
7340 (save-excursion (beginning-of-line)
7341 (re-search-backward "^[^\n]" nil t
)
7342 (current-indentation))))
7343 (shift-amt (- indent
(current-indentation))))
7344 (and vhdl-echo-syntactic-information-p
7345 (message "syntax: %s, indent= %d" syntax indent
))
7347 (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
7348 (when (or (not (zerop shift-amt
)) has-formfeed
)
7349 (delete-region (vhdl-point 'bol
) (vhdl-point 'boi
))
7351 (when has-formfeed
(insert "\f"))
7352 (indent-to indent
)))
7353 (if (< (point) (vhdl-point 'boi
))
7354 (back-to-indentation)
7355 ;; If initial point was within line's indentation, position after
7356 ;; the indentation. Else stay at same point in text.
7357 (when (> (- (point-max) pos
) (point))
7358 (goto-char (- (point-max) pos
))))
7359 (run-hooks 'vhdl-special-indent-hook
)
7360 (vhdl-update-progress-info "Indenting" (vhdl-current-line))
7363 (defun vhdl-indent-region (beg end
&optional column
)
7364 "Indent region as VHDL code.
7365 Adds progress reporting to `indent-region'."
7366 (interactive "r\nP")
7367 (when vhdl-progress-interval
7368 (setq vhdl-progress-info
(vector (count-lines (point-min) beg
)
7369 (count-lines (point-min) end
) 0)))
7370 (indent-region beg end column
)
7371 (when vhdl-progress-interval
(message "Indenting...done"))
7372 (setq vhdl-progress-info nil
))
7374 (defun vhdl-indent-buffer ()
7375 "Indent whole buffer as VHDL code.
7376 Calls `indent-region' for whole buffer and adds progress reporting."
7378 (vhdl-indent-region (point-min) (point-max)))
7380 (defun vhdl-indent-group ()
7381 "Indent group of lines between empty lines."
7383 (let ((beg (save-excursion
7384 (if (re-search-backward vhdl-align-group-separate nil t
)
7386 (point-min-marker))))
7387 (end (save-excursion
7388 (if (re-search-forward vhdl-align-group-separate nil t
)
7390 (point-max-marker)))))
7391 (vhdl-indent-region beg end
)))
7393 (defun vhdl-indent-sexp (&optional endpos
)
7394 "Indent each line of the list starting just after point.
7395 If optional arg ENDPOS is given, indent each line, stopping when
7396 ENDPOS is encountered."
7400 (end (progn (vhdl-forward-sexp nil endpos
) (point))))
7401 (indent-region beg end nil
))))
7403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7404 ;; Miscellaneous commands
7406 (defun vhdl-show-syntactic-information ()
7407 "Show syntactic information for current line."
7409 (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
7410 (vhdl-keep-region-active))
7412 ;; Verification and regression functions:
7414 (defun vhdl-regress-line (&optional arg
)
7415 "Check syntactic information for current line."
7417 (let ((expected (save-excursion
7419 (when (search-backward " -- ((" (vhdl-point 'bol
) t
)
7421 (read (current-buffer)))))
7422 (actual (vhdl-get-syntactic-context))
7424 ;; remove the library unit symbols
7428 (if (memq (car elt
) '(entity configuration package
7429 package-body architecture
))
7431 (setq expurgated
(append expurgated
(list elt
))))))
7433 (if (and (not arg
) expected
(listp expected
))
7434 (if (not (equal expected expurgated
))
7435 (error "ERROR: Should be: %s, is: %s" expected expurgated
))
7438 (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
7440 (if (search-backward " -- ((" (vhdl-point 'bol
) t
)
7441 (delete-region (point) (line-end-position)))
7443 (insert (format "%s" expurgated
))))))
7444 (vhdl-keep-region-active))
7447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7448 ;;; Alignment, beautifying
7449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7451 (defconst vhdl-align-alist
7453 ;; after some keywords
7454 (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
7455 "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
7457 (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
7458 ;; after direction specifications
7459 (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
7460 ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
7461 ;; before "==", ":=", "=>", and "<="
7462 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
7463 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7464 (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
7465 ;; before some keywords
7466 (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
7467 (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
7468 (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
7469 (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
7470 (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
7471 ;; before "=>" since "when/else ... =>" can occur
7472 (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
7474 "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
7475 It is searched in order. If REGEXP is found anywhere in the first
7476 line of a region to be aligned, ALIGN-PATTERN will be used for that
7477 region. ALIGN-PATTERN must include the whitespace to be expanded or
7478 contracted. It may also provide regexps for the text surrounding the
7479 whitespace. SUBEXP specifies which sub-expression of
7480 ALIGN-PATTERN matches the white space to be expanded/contracted.")
7482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7485 (defvar vhdl-align-try-all-clauses t
7486 "If REGEXP is not found on the first line of the region that clause
7487 is ignored. If this variable is non-nil, then the clause is tried anyway.")
7489 (defun vhdl-do-group (function &optional spacing
)
7490 "Apply FUNCTION on group of lines between empty lines."
7492 ;; search for group beginning
7493 ((beg (save-excursion
7494 (if (re-search-backward vhdl-align-group-separate nil t
)
7495 (progn (beginning-of-line 2) (back-to-indentation) (point))
7497 ;; search for group end
7498 (end (save-excursion
7499 (if (re-search-forward vhdl-align-group-separate nil t
)
7500 (progn (beginning-of-line) (point))
7503 (funcall function beg end spacing
)))
7505 (defun vhdl-do-list (function &optional spacing
)
7506 "Apply FUNCTION to the lines of a list surrounded by a balanced group of
7510 ;; search for beginning of balanced group of parentheses
7511 (setq beg
(vhdl-re-search-backward "[()]" nil t
))
7512 (while (looking-at ")")
7513 (forward-char) (backward-sexp)
7514 (setq beg
(vhdl-re-search-backward "[()]" nil t
)))
7515 ;; search for end of balanced group of parentheses
7519 (goto-char (1+ beg
))
7520 (skip-chars-forward " \t\n\r\f")
7521 (setq beg
(point))))
7524 (funcall function beg end spacing
)
7525 (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
7527 (defun vhdl-do-same-indent (function &optional spacing
)
7528 "Apply FUNCTION to block of lines with same indent."
7529 (let ((indent (current-indentation))
7531 ;; search for first line with same indent
7533 (while (and (not (bobp))
7534 (or (looking-at "^\\s-*\\(--.*\\)?$")
7535 (= (current-indentation) indent
)))
7536 (unless (looking-at "^\\s-*$")
7537 (back-to-indentation) (setq beg
(point)))
7538 (beginning-of-line -
0)))
7539 ;; search for last line with same indent
7541 (while (and (not (eobp))
7542 (or (looking-at "^\\s-*\\(--.*\\)?$")
7543 (= (current-indentation) indent
)))
7544 (if (looking-at "^\\s-*$")
7545 (beginning-of-line 2)
7546 (beginning-of-line 2)
7547 (setq end
(point)))))
7549 (funcall function beg end spacing
)))
7551 (defun vhdl-align-region-1 (begin end
&optional spacing alignment-list indent
)
7552 "Attempt to align a range of lines based on the content of the
7553 lines. The definition of `alignment-list' determines the matching
7554 order and the manner in which the lines are aligned. If ALIGNMENT-LIST
7555 is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
7556 indentation is done before aligning."
7557 (interactive "r\np")
7558 (setq alignment-list
(or alignment-list vhdl-align-alist
))
7559 (setq spacing
(or spacing
1))
7563 (setq end
(point-marker))
7565 (setq bol
(setq begin
(progn (beginning-of-line) (point))))
7566 ; (untabify bol end)
7568 (indent-region bol end nil
))))
7569 (let ((copy (copy-alist alignment-list
)))
7570 (vhdl-prepare-search-2
7575 (eol (point-at-eol)))
7576 (setq element
(nth 0 copy
))
7577 (when (and (or (and (listp (car element
))
7578 (memq major-mode
(car element
)))
7579 (eq major-mode
(car element
)))
7580 (or vhdl-align-try-all-clauses
7581 (re-search-forward (car (cdr element
)) eol t
)))
7582 (vhdl-align-region-2 begin end
(car (cdr (cdr element
)))
7583 (car (cdr (cdr (cdr element
)))) spacing
))
7584 (setq copy
(cdr copy
))))))))
7586 (defun vhdl-align-region-2 (begin end match
&optional substr spacing
)
7587 "Align a range of lines from BEGIN to END. The regular expression
7588 MATCH must match exactly one field: the whitespace to be
7589 contracted/expanded. The alignment column will equal the
7590 rightmost column of the widest whitespace block. SPACING is
7591 the amount of extra spaces to add to the calculated maximum required.
7592 SPACING defaults to 1 so that at least one space is inserted after
7593 the token in MATCH."
7594 (setq spacing
(or spacing
1))
7595 (setq substr
(or substr
1))
7597 (let (distance (max 0) (lines 0) bol eol width
)
7598 ;; Determine the greatest whitespace distance to the alignment
7601 (setq eol
(point-at-eol)
7602 bol
(setq begin
(progn (beginning-of-line) (point))))
7605 (when (and (vhdl-re-search-forward match eol t
)
7607 (goto-char (match-beginning 0))
7609 (and (not (vhdl-in-literal))
7610 (not (vhdl-in-quote-p))
7611 (not (vhdl-in-extended-identifier-p))))
7612 (not (looking-at "\\s-*$")))
7613 (setq distance
(- (match-beginning substr
) bol
))
7614 (when (> distance max
)
7615 (setq max distance
))))
7619 (setq lines
(1+ lines
)))
7620 ;; Now insert enough maxs to push each assignment operator to
7621 ;; the same column. We need to use 'lines' as a counter, since
7622 ;; the location of the mark may change
7623 (goto-char (setq bol begin
))
7624 (setq eol
(point-at-eol))
7626 (when (and (vhdl-re-search-forward match eol t
)
7628 (goto-char (match-beginning 0))
7630 (and (not (vhdl-in-literal))
7631 (not (vhdl-in-quote-p))
7632 (not (vhdl-in-extended-identifier-p))))
7633 (not (looking-at "\\s-*$"))
7634 (> (match-beginning 0) ; not if at boi
7635 (save-excursion (back-to-indentation) (point))))
7636 (setq width
(- (match-end substr
) (match-beginning substr
)))
7637 (setq distance
(- (match-beginning substr
) bol
))
7638 (goto-char (match-beginning substr
))
7640 (insert-char ?
(+ (- max distance
) spacing
)))
7645 (setq lines
(1- lines
))))))
7647 (defun vhdl-align-region-groups (beg end
&optional spacing
7648 no-message no-comments
)
7649 "Align region, treat groups of lines separately."
7650 (interactive "r\nP")
7655 (setq orig
(point-marker))
7658 (setq end
(point-marker))
7661 (when vhdl-progress-interval
7662 (setq vhdl-progress-info
(vector (count-lines (point-min) beg
)
7663 (count-lines (point-min) end
) 0))))
7664 (when (nth 0 vhdl-beautify-options
)
7665 (vhdl-fixup-whitespace-region beg end t
))
7667 (if (not vhdl-align-groups
)
7668 ;; align entire region
7669 (progn (vhdl-align-region-1 beg end spacing
)
7671 (vhdl-align-inline-comment-region-1 beg end
)))
7673 (while (and (< beg end
)
7674 (re-search-forward vhdl-align-group-separate end t
))
7675 (setq pos
(point-marker))
7676 (vhdl-align-region-1 beg pos spacing
)
7677 (unless no-comments
(vhdl-align-inline-comment-region-1 beg pos
))
7678 (vhdl-update-progress-info "Aligning" (vhdl-current-line))
7683 (vhdl-align-region-1 beg end spacing
)
7684 (unless no-comments
(vhdl-align-inline-comment-region-1 beg end
))
7685 (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
7686 (when vhdl-indent-tabs-mode
7689 (when vhdl-progress-interval
(message "Aligning...done"))
7690 (setq vhdl-progress-info nil
)))))
7692 (defun vhdl-align-region (beg end
&optional spacing
)
7693 "Align region, treat blocks with same indent and argument lists separately."
7694 (interactive "r\nP")
7695 (if (not vhdl-align-same-indent
)
7696 ;; align entire region
7697 (vhdl-align-region-groups beg end spacing
)
7698 ;; align blocks with same indent and argument lists
7702 (when vhdl-progress-interval
7703 (setq vhdl-progress-info
(vector (count-lines (point-min) beg
)
7704 (count-lines (point-min) end
) 0)))
7706 (setq end
(point-marker))
7708 (while (< (point) end
)
7709 ;; is argument list opening?
7710 (if (setq cur-beg
(nth 1 (save-excursion (parse-partial-sexp
7711 (point) (vhdl-point 'eol
)))))
7712 ;; determine region for argument list
7713 (progn (goto-char cur-beg
)
7715 (setq cur-end
(point))
7716 (beginning-of-line 2))
7717 ;; determine region with same indent
7718 (setq indent
(current-indentation))
7719 (setq cur-beg
(point))
7720 (setq cur-end
(vhdl-point 'bonl
))
7721 (beginning-of-line 2)
7722 (while (and (< (point) end
)
7723 (or (looking-at "^\\s-*\\(--.*\\)?$")
7724 (= (current-indentation) indent
))
7726 (nth 0 (parse-partial-sexp
7727 (point) (vhdl-point 'eol
)))) 0))
7728 (unless (looking-at "^\\s-*$")
7729 (setq cur-end
(vhdl-point 'bonl
)))
7730 (beginning-of-line 2)))
7732 (vhdl-align-region-groups cur-beg cur-end spacing t t
))
7733 (vhdl-align-inline-comment-region beg end spacing noninteractive
)
7734 (when vhdl-progress-interval
(message "Aligning...done"))
7735 (setq vhdl-progress-info nil
)))))
7737 (defun vhdl-align-group (&optional spacing
)
7738 "Align group of lines between empty lines."
7740 (vhdl-do-group 'vhdl-align-region spacing
))
7742 (defun vhdl-align-list (&optional spacing
)
7743 "Align the lines of a list surrounded by a balanced group of parentheses."
7745 (vhdl-do-list 'vhdl-align-region-groups spacing
))
7747 (defun vhdl-align-same-indent (&optional spacing
)
7748 "Align block of lines with same indent."
7750 (vhdl-do-same-indent 'vhdl-align-region-groups spacing
))
7752 (defun vhdl-align-declarations (&optional spacing
)
7753 "Align the lines within the declarative part of a design unit."
7756 (vhdl-prepare-search-2
7758 ;; search for declarative part
7759 (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t
)
7760 (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
7762 (re-search-forward "^\\(begin\\|end\\)\\>" nil t
)
7763 (setq end
(point)))))
7765 (vhdl-align-region-groups beg end spacing
)
7766 (error "ERROR: Not within the declarative part of a design unit"))))
7768 (defun vhdl-align-buffer ()
7771 (vhdl-align-region (point-min) (point-max)))
7773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7774 ;; Align inline comments
7776 (defun vhdl-align-inline-comment-region-1 (beg end
&optional spacing
)
7777 "Align inline comments in region."
7779 (let ((start-max comment-column
)
7781 comment-list start-list tmp-list start length
7782 cur-start prev-start no-code
)
7783 (setq spacing
(or spacing
2))
7784 (vhdl-prepare-search-2
7786 ;; search for comment start positions and lengths
7787 (while (< (point) end
)
7788 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7789 (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
7790 (not (save-excursion (goto-char (match-beginning 2))
7791 (vhdl-in-literal))))
7792 (setq start
(+ (- (match-end 1) (match-beginning 1)) spacing
))
7793 (setq length
(- (match-end 2) (match-beginning 2)))
7794 (setq start-max
(max start start-max
))
7795 (setq length-max
(max length length-max
))
7796 (push (cons start length
) comment-list
))
7797 (beginning-of-line 2))
7799 (sort comment-list
(function (lambda (a b
) (> (car a
) (car b
))))))
7800 ;; reduce start positions
7801 (setq start-list
(list (caar comment-list
)))
7802 (setq comment-list
(cdr comment-list
))
7804 (unless (or (= (caar comment-list
) (car start-list
))
7805 (<= (+ (car start-list
) (cdar comment-list
))
7806 end-comment-column
))
7807 (push (caar comment-list
) start-list
))
7808 (setq comment-list
(cdr comment-list
)))
7809 ;; align lines as nicely as possible
7811 (while (< (point) end
)
7812 (setq cur-start nil
)
7813 (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
7814 (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
7815 (not (save-excursion
7816 (goto-char (match-beginning 3))
7817 (vhdl-in-literal))))
7818 (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
7819 (>= (- (match-end 2) (match-beginning 2))
7821 (setq start
(+ (- (match-end 1) (match-beginning 1)) spacing
))
7822 (setq length
(- (match-end 3) (match-beginning 3)))
7823 (setq no-code
(= (match-beginning 1) (match-end 1)))
7824 ;; insert minimum whitespace
7825 (goto-char (match-end 2))
7826 (delete-region (match-beginning 2) (match-end 2))
7827 (insert-char ?\ spacing
)
7828 (setq tmp-list start-list
)
7829 ;; insert additional whitespace to align
7832 ;; align comment-only line to inline comment of previous line
7833 ((and no-code prev-start
7834 (<= length
(- end-comment-column prev-start
)))
7836 ;; align all comments at `start-max' if this is possible
7837 ((<= (+ start-max length-max
) end-comment-column
)
7839 ;; align at `comment-column' if possible
7840 ((and (<= start comment-column
)
7841 (<= length
(- end-comment-column comment-column
)))
7843 ;; align at left-most possible start position otherwise
7845 (while (and tmp-list
(< (car tmp-list
) start
))
7846 (setq tmp-list
(cdr tmp-list
)))
7848 (indent-to cur-start
))
7849 (setq prev-start cur-start
)
7850 (beginning-of-line 2))))))
7852 (defun vhdl-align-inline-comment-region (beg end
&optional spacing no-message
)
7853 "Align inline comments within a region. Groups of code lines separated by
7854 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7855 (interactive "r\nP")
7860 (setq orig
(point-marker))
7863 (setq end
(point-marker))
7865 (unless no-message
(message "Aligning inline comments..."))
7867 (if (not vhdl-align-groups
)
7868 ;; align entire region
7869 (vhdl-align-inline-comment-region-1 beg end spacing
)
7871 (while (and (< beg end
)
7872 (re-search-forward vhdl-align-group-separate end t
))
7873 (setq pos
(point-marker))
7874 (vhdl-align-inline-comment-region-1 beg pos spacing
)
7879 (vhdl-align-inline-comment-region-1 beg end spacing
)))
7880 (when vhdl-indent-tabs-mode
7882 (unless no-message
(message "Aligning inline comments...done")))))
7884 (defun vhdl-align-inline-comment-group (&optional spacing
)
7885 "Align inline comments within a group of lines between empty lines."
7888 (let ((start (point))
7890 (setq end
(if (re-search-forward vhdl-align-group-separate nil t
)
7891 (point-marker) (point-max)))
7893 (setq beg
(if (re-search-backward vhdl-align-group-separate nil t
)
7894 (point) (point-min)))
7896 (message "Aligning inline comments...")
7897 (vhdl-align-inline-comment-region-1 beg end
)
7898 (when vhdl-indent-tabs-mode
7900 (message "Aligning inline comments...done"))))
7902 (defun vhdl-align-inline-comment-buffer ()
7903 "Align inline comments within buffer. Groups of code lines separated by
7904 empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
7906 (vhdl-align-inline-comment-region (point-min) (point-max)))
7908 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7911 (defun vhdl-fixup-whitespace-region (beg end
&optional no-message
)
7912 "Fixup whitespace in region. Surround operator symbols by one space,
7913 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7914 end of line, do nothing in comments and strings."
7916 (unless no-message
(message "Fixing up whitespace..."))
7919 (setq end
(point-marker))
7920 ;; have no space before and one space after `,' and ';'
7922 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t
)
7923 (if (match-string 1)
7924 (goto-char (match-end 1))
7925 (replace-match "\\3 " nil nil nil
2)))
7926 ;; have no space after `('
7928 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t
)
7929 (if (match-string 1)
7930 (goto-char (match-end 1))
7931 (replace-match "\\2")))
7932 ;; have no space before `)'
7934 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t
)
7935 (if (match-string 1)
7936 (goto-char (match-end 1))
7937 (replace-match "\\2")))
7938 ;; surround operator symbols by one space
7940 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t
)
7941 (if (or (match-string 1)
7942 (<= (match-beginning 0) ; not if at boi
7943 (save-excursion (back-to-indentation) (point))))
7944 (goto-char (match-end 0))
7945 (replace-match "\\3 \\4 \\5")
7946 (goto-char (match-end 2))))
7947 ;; eliminate multiple spaces and spaces at end of line
7949 (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t
))
7950 (and (looking-at "--.*") (re-search-forward "--.*" end t
))
7951 (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t
))
7952 (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t
)
7953 (progn (replace-match "" nil nil
) t
))
7954 (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t
)
7955 (progn (replace-match ";" nil nil
) t
))
7956 (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t
))
7957 (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t
)
7958 (progn (replace-match " " nil nil
) t
))
7959 (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t
)
7960 (progn (replace-match " " nil nil
) t
))
7961 (and (looking-at "-") (re-search-forward "-" end t
))
7962 ; (re-search-forward "[^ \t-]+" end t))))
7963 (re-search-forward "[^ \t\"-]+" end t
))))
7964 (unless no-message
(message "Fixing up whitespace...done")))
7966 (defun vhdl-fixup-whitespace-buffer ()
7967 "Fixup whitespace in buffer. Surround operator symbols by one space,
7968 eliminate multiple spaces (except at beginning of line), eliminate spaces at
7969 end of line, do nothing in comments."
7971 (vhdl-fixup-whitespace-region (point-min) (point-max)))
7973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7976 (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp
&optional count
)
7977 "Convert all words matching WORD-REGEXP in region to lower or upper case,
7978 depending on parameter UPPER-CASE."
7979 (let ((case-replace nil
)
7981 (vhdl-prepare-search-2
7984 (setq end
(point-marker))
7986 (while (re-search-forward word-regexp end t
)
7987 (or (vhdl-in-literal)
7990 (downcase-word -
1)))
7991 (when (and count vhdl-progress-interval
(not noninteractive
)
7992 (< vhdl-progress-interval
7993 (- (nth 1 (current-time)) last-update
)))
7994 (message "Fixing case... (%2d%s)"
7995 (+ (* count
20) (/ (* 20 (- (point) beg
)) (- end beg
)))
7997 (setq last-update
(nth 1 (current-time)))))
8000 (defun vhdl-fix-case-region (beg end
&optional arg
)
8001 "Convert all VHDL words in region to lower or upper case, depending on
8002 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8003 (interactive "r\nP")
8004 (vhdl-fix-case-region-1
8005 beg end vhdl-upper-case-keywords vhdl-keywords-regexp
0)
8006 (vhdl-fix-case-region-1
8007 beg end vhdl-upper-case-types vhdl-types-regexp
1)
8008 (vhdl-fix-case-region-1
8009 beg end vhdl-upper-case-attributes
(concat "'" vhdl-attributes-regexp
) 2)
8010 (vhdl-fix-case-region-1
8011 beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp
3)
8012 (vhdl-fix-case-region-1
8013 beg end vhdl-upper-case-constants vhdl-constants-regexp
4)
8014 (when vhdl-progress-interval
(message "Fixing case...done")))
8016 (defun vhdl-fix-case-buffer ()
8017 "Convert all VHDL words in buffer to lower or upper case, depending on
8018 options vhdl-upper-case-{keywords,types,attributes,enum-values}."
8020 (vhdl-fix-case-region (point-min) (point-max)))
8022 (defun vhdl-fix-case-word (&optional arg
)
8023 "Convert word after cursor to upper case if necessary."
8026 (when arg
(backward-word 1))
8027 (vhdl-prepare-search-1
8028 (when (and vhdl-upper-case-keywords
8029 (looking-at vhdl-keywords-regexp
))
8031 (when (and vhdl-upper-case-types
8032 (looking-at vhdl-types-regexp
))
8034 (when (and vhdl-upper-case-attributes
8035 (looking-at vhdl-attributes-regexp
))
8037 (when (and vhdl-upper-case-enum-values
8038 (looking-at vhdl-enum-values-regexp
))
8040 (when (and vhdl-upper-case-constants
8041 (looking-at vhdl-constants-regexp
))
8044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8046 ;; - force each statement to be on a separate line except when on same line
8047 ;; with 'end' keyword
8049 (defun vhdl-fix-statement-region (beg end
&optional arg
)
8050 "Force statements in region on separate line except when on same line
8051 with 'end' keyword (necessary for correct indentation).
8052 Currently supported keywords: 'begin', 'if'."
8053 (interactive "r\nP")
8054 (vhdl-prepare-search-2
8058 (setq end
(point-marker))
8061 (while (re-search-forward
8062 "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t
)
8063 (goto-char (match-end 0))
8064 (setq point
(point-marker))
8065 (when (and (match-string 1)
8066 (or (not (match-string 2))
8067 (save-excursion (goto-char (match-end 2))
8069 (not (save-excursion (goto-char (match-beginning 1))
8070 (vhdl-in-literal))))
8071 (goto-char (match-beginning 1))
8073 (indent-according-to-mode))
8076 ;; `for', `if' keywords
8077 (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t
)
8078 (goto-char (match-end 1))
8079 (setq point
(point-marker))
8080 ;; exception: in literal or preceded by `end' or label
8081 (when (and (not (save-excursion (goto-char (match-beginning 1))
8084 (beginning-of-line 1)
8086 (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
8087 (match-beginning 1) t
)
8089 "\\(\\<end\\>\\|\\<wait\\>\\|\\w+\\s-*:\\)\\s-*$"
8090 (match-string 1)))))))
8091 (goto-char (match-beginning 1))
8093 (indent-according-to-mode))
8094 (goto-char point
))))))
8096 (defun vhdl-fix-statement-buffer ()
8097 "Force statements in buffer on separate line except when on same line
8098 with 'end' keyword (necessary for correct indentation)."
8100 (vhdl-fix-statement-region (point-min) (point-max)))
8102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8105 (defun vhdl-remove-trailing-spaces-region (beg end
&optional arg
)
8106 "Remove trailing spaces in region."
8107 (interactive "r\nP")
8110 (setq end
(point-marker))
8112 (while (re-search-forward "[ \t]+$" end t
)
8113 (unless (vhdl-in-literal)
8114 (replace-match "" nil nil
)))))
8116 (defun vhdl-remove-trailing-spaces ()
8117 "Remove trailing spaces in buffer."
8119 (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
8121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8124 (defun vhdl-beautify-region (beg end
)
8125 "Beautify region by applying indentation, whitespace fixup, alignment, and
8126 case fixing to a region. Calls functions `vhdl-indent-buffer',
8127 `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
8128 `vhdl-fix-case-buffer'."
8130 (setq end
(save-excursion (goto-char end
) (point-marker)))
8131 (save-excursion ; remove DOS EOL characters in UNIX file
8133 (while (search-forward "
" nil t
)
8134 (replace-match "" nil t
)))
8135 (when (nth 0 vhdl-beautify-options
) (vhdl-fixup-whitespace-region beg end t
))
8136 (when (nth 1 vhdl-beautify-options
) (vhdl-fix-statement-region beg end
))
8137 (when (nth 2 vhdl-beautify-options
) (vhdl-indent-region beg end
))
8138 (let ((vhdl-align-groups t
))
8139 (when (nth 3 vhdl-beautify-options
) (vhdl-align-region beg end
)))
8140 (when (nth 4 vhdl-beautify-options
) (vhdl-fix-case-region beg end
))
8141 (when (nth 0 vhdl-beautify-options
) (vhdl-remove-trailing-spaces-region beg end
)))
8143 (defun vhdl-beautify-buffer ()
8144 "Beautify buffer by applying indentation, whitespace fixup, alignment, and
8145 case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
8148 (vhdl-beautify-region (point-min) (point-max))
8149 (when noninteractive
(save-buffer)))
8151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8154 (defun vhdl-fill-region (beg end
&optional arg
)
8155 "Fill lines for a region of code."
8156 (interactive "r\np")
8159 (let ((margin (if arg
(current-indentation) (current-column))))
8161 (setq end
(point-marker))
8162 ;; remove inline comments, newlines and whitespace
8163 (vhdl-comment-kill-region beg end
)
8164 (vhdl-comment-kill-inline-region beg end
)
8165 (subst-char-in-region beg
(1- end
) ?
\n ?\
)
8166 (vhdl-fixup-whitespace-region beg end
)
8167 ;; wrap and end-comment-column
8169 (while (re-search-forward "\\s-" end t
)
8170 (when(> (current-column) vhdl-end-comment-column
)
8172 (when (re-search-backward "\\s-" beg t
)
8173 (replace-match "\n")
8174 (indent-to margin
)))))))
8176 (defun vhdl-fill-group ()
8177 "Fill group of lines between empty lines."
8179 (vhdl-do-group 'vhdl-fill-region
))
8181 (defun vhdl-fill-list ()
8182 "Fill the lines of a list surrounded by a balanced group of parentheses."
8184 (vhdl-do-list 'vhdl-fill-region
))
8186 (defun vhdl-fill-same-indent ()
8187 "Fill the lines of block of lines with same indent."
8189 (vhdl-do-same-indent 'vhdl-fill-region
))
8192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8193 ;;; Code updating/fixing
8194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8197 ;; Sensitivity list update
8200 ;; - no sensitivity list is generated for processes with wait statements
8201 ;; - otherwise, do the following:
8202 ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
8203 ;; 2. scan for all signals already in the sensitivity list (in order to catch
8204 ;; manually entered global signals)
8205 ;; 3. signals from 1. and 2. form the list of visible signals
8206 ;; 4. search for if/elsif conditions containing an event (sequential code)
8207 ;; 5. scan for strings that are within syntactical regions where signals are
8208 ;; read but not within sequential code, and that correspond to visible
8210 ;; 6. replace sensitivity list by list of signals from 5.
8212 (defun vhdl-update-sensitivity-list-process ()
8213 "Update sensitivity list of current process."
8216 (vhdl-prepare-search-2
8218 ;; look whether in process
8219 (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t
)
8220 (equal (upcase (match-string 2)) "PROCESS")
8221 (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t
))))
8222 (error "ERROR: Not within a process")
8223 (message "Updating sensitivity list...")
8224 (vhdl-update-sensitivity-list)
8225 (message "Updating sensitivity list...done")))))
8227 (defun vhdl-update-sensitivity-list-buffer ()
8228 "Update sensitivity list of all processes in current buffer."
8231 (vhdl-prepare-search-2
8232 (goto-char (point-min))
8233 (message "Updating sensitivity lists...")
8234 (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t
)
8235 (goto-char (match-beginning 0))
8236 (condition-case nil
(vhdl-update-sensitivity-list) (error "")))
8237 (message "Updating sensitivity lists...done")))
8238 (when noninteractive
(save-buffer)))
8240 (defun vhdl-update-sensitivity-list ()
8241 "Update sensitivity list."
8242 (let ((proc-beg (point))
8243 (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t
))
8244 (proc-mid (vhdl-re-search-backward
8245 "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t
))
8248 ;; error if 'begin' keyword missing
8249 ((not (match-string 2))
8250 (error "ERROR: No 'begin' keyword found"))
8251 ;; search for wait statement (no sensitivity list allowed)
8252 ((progn (goto-char proc-mid
)
8253 (vhdl-re-search-forward "\\<wait\\>" proc-end t
))
8254 (error "ERROR: Process with wait statement, sensitivity list not generated"))
8255 ;; combinational process (update sensitivity list)
8258 ;; scan for visible signals
8259 ((visible-list (vhdl-get-visible-signals))
8260 ;; define syntactic regions where signals are read
8262 '(;; right-hand side of signal/variable assignment
8263 ;; (special case: "<=" is relational operator in a condition)
8264 ((vhdl-re-search-forward "[<:]=" proc-end t
)
8265 (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t
))
8267 ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t
)
8268 (vhdl-re-search-forward "\\<then\\>" proc-end t
))
8270 ((vhdl-re-search-forward "\\<elsif\\>" proc-end t
)
8271 (vhdl-re-search-forward "\\<then\\>" proc-end t
))
8272 ;; while loop condition
8273 ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t
)
8274 (vhdl-re-search-forward "\\<loop\\>" proc-end t
))
8275 ;; exit/next condition
8276 ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t
)
8277 (vhdl-re-search-forward ";" proc-end t
))
8279 ((vhdl-re-search-forward "\\<assert\\>" proc-end t
)
8280 (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t
))
8282 ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t
)
8283 (vhdl-re-search-forward "\\<is\\>" proc-end t
))
8284 ;; parameter list of procedure call, array index
8285 ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t
)
8287 (progn (backward-char) (forward-sexp)
8288 (while (looking-at "(") (forward-sexp)) (point)))))
8289 name field read-list sens-list signal-list tmp-list
8290 sens-beg sens-end beg end margin
)
8291 ;; scan for signals in old sensitivity list
8292 (goto-char proc-beg
)
8293 (vhdl-re-search-forward "\\<process\\>" proc-mid t
)
8294 (if (not (looking-at "[ \t\n\r\f]*("))
8295 (setq sens-beg
(point))
8296 (setq sens-beg
(vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t
))
8297 (goto-char (match-end 1))
8299 (setq sens-end
(1- (point)))
8300 (goto-char sens-beg
)
8301 (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t
)
8303 (cons (downcase (match-string 0)) sens-list
))
8304 (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t
))))
8305 (setq signal-list
(append visible-list sens-list
))
8306 ;; search for sequential parts
8307 (goto-char proc-mid
)
8308 (while (setq beg
(re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t
))
8309 (setq end
(vhdl-re-search-forward "\\<then\\>" proc-end t
))
8310 (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t
)
8314 (push (cons end
(point)) seq-region-list
)
8315 (beginning-of-line)))
8316 ;; scan for signals read in process
8317 (while scan-regions-list
8318 (goto-char proc-mid
)
8319 (while (and (setq beg
(eval (nth 0 (car scan-regions-list
))))
8320 (setq end
(eval (nth 1 (car scan-regions-list
)))))
8322 (unless (or (vhdl-in-literal)
8323 (and seq-region-list
8324 (let ((tmp-list seq-region-list
))
8325 (while (and tmp-list
8326 (< (point) (caar tmp-list
)))
8327 (setq tmp-list
(cdr tmp-list
)))
8328 (and tmp-list
(< (point) (cdar tmp-list
))))))
8329 (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t
)
8330 (setq name
(match-string 1))
8331 ;; get array index range
8332 (when vhdl-array-index-record-field-in-sensitivity-list
8333 (setq field
(match-string 2))
8334 ;; not use if it includes a variable name
8336 (setq tmp-list visible-list
)
8337 (while (and field tmp-list
)
8339 (concat "\\<" (car tmp-list
) "\\>") field
)
8341 (setq tmp-list
(cdr tmp-list
)))))
8342 (when (and (not (match-string 6)) ; not when formal parameter
8343 (not (and (match-string 5) ; not event attribute
8344 (not (member (downcase (match-string 5))
8345 '("event" "last_event" "transaction")))))
8346 (member (downcase name
) signal-list
))
8347 ;; not add if name or name+field already exists
8349 (or (member-ignore-case name read-list
)
8350 (member-ignore-case (concat name field
) read-list
))
8351 (push (concat name field
) read-list
))
8352 (setq tmp-list read-list
)
8353 ;; remove existing name+field if name is added
8356 (when (string-match (concat "^" name field
"[(.]")
8358 (setq read-list
(delete (car tmp-list
) read-list
)))
8359 (setq tmp-list
(cdr tmp-list
)))))
8360 (goto-char (match-end 1)))))
8361 (setq scan-regions-list
(cdr scan-regions-list
)))
8362 ;; update sensitivity list
8363 (goto-char sens-beg
)
8365 (delete-region sens-beg sens-end
)
8367 (insert " ()") (backward-char)))
8368 (setq read-list
(sort read-list
'string
<))
8370 (setq margin
(current-column))
8371 (insert (car read-list
))
8372 (setq read-list
(cdr read-list
))
8375 (if (<= (+ (current-column) (length (car read-list
)) 2)
8378 (insert "\n") (indent-to margin
))
8379 (insert (car read-list
))
8380 (setq read-list
(cdr read-list
)))))))))
8382 (defun vhdl-get-visible-signals ()
8383 "Get all signals visible in the current block."
8384 (let (beg end signal-list entity-name file-name
)
8385 (vhdl-prepare-search-2
8388 (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t
)
8389 (not (equal "END" (upcase (match-string 1))))
8390 (setq entity-name
(match-string 2)))
8391 (error "ERROR: Not within an architecture")))
8392 ;; search for signals declared in entity port clause
8394 (goto-char (point-min))
8395 (unless (re-search-forward (concat "^entity\\s-+" entity-name
"\\>") nil t
)
8397 (concat (vhdl-replace-string vhdl-entity-file-name entity-name t
)
8398 "." (file-name-extension (buffer-file-name)))))
8401 (vhdl-prepare-search-2
8402 (goto-char (point-min))
8403 (if (not (re-search-forward (concat "^entity\\s-+" entity-name
"\\>") nil t
))
8404 (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name
)
8405 (when (setq beg
(vhdl-re-search-forward
8406 "\\<port[ \t\n\r\f]*("
8408 (re-search-forward "^end\\>" nil t
)) t
))
8409 (setq end
(save-excursion
8410 (backward-char) (forward-sexp) (point)))
8411 (vhdl-forward-syntactic-ws)
8412 (while (< (point) end
)
8413 (when (looking-at "signal[ \t\n\r\f]+")
8414 (goto-char (match-end 0)))
8415 (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
8417 (cons (downcase (match-string 1)) signal-list
))
8418 (goto-char (match-end 0))
8419 (vhdl-forward-syntactic-ws))
8420 (re-search-forward ";" end
1)
8421 (vhdl-forward-syntactic-ws)))))))
8422 ;; search for signals declared in architecture declarative part
8424 (if (not (and (setq beg
(re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t
))
8425 (not (equal "END" (upcase (match-string 1))))
8426 (setq end
(re-search-forward "^begin\\>" nil t
))))
8427 (error "ERROR: No architecture declarative part found")
8428 ;; scan for all declared signal and alias names
8430 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t
)
8431 (when (= 0 (nth 0 (parse-partial-sexp beg
(point))))
8432 (if (match-string 2)
8434 (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
8436 (cons (downcase (match-string 1)) signal-list
))
8437 (goto-char (match-end 0)))
8438 ;; scan alias name, check is alias of (declared) signal
8439 (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
8440 (member (downcase (match-string 2)) signal-list
))
8442 (cons (downcase (match-string 1)) signal-list
))
8443 (goto-char (match-end 0))))
8444 (setq beg
(point))))))
8445 ;; search for signals declared in surrounding block declarative parts
8447 (while (and (progn (while (and (setq beg
(re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t
))
8449 (goto-char (match-end 2))
8450 (vhdl-backward-sexp)
8451 (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t
))
8453 (setq end
(re-search-forward "^\\s-*begin\\>" nil t
)))
8454 ;; scan for all declared signal names
8456 (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t
)
8457 (when (= 0 (nth 0 (parse-partial-sexp beg
(point))))
8458 (if (match-string 2)
8460 (while (looking-at "[ \t\n,]+\\(\\w+\\)")
8462 (cons (downcase (match-string 1)) signal-list
))
8463 (goto-char (match-end 0)))
8464 ;; scan alias name, check is alias of (declared) signal
8465 (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
8466 (member (downcase (match-string 2)) signal-list
))
8468 (cons (downcase (match-string 1)) signal-list
))
8469 (goto-char (match-end 0))))))
8473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8474 ;; Generic/port clause fixing
8476 (defun vhdl-fix-clause-buffer ()
8477 "Fix all generic/port clauses in current buffer."
8480 (vhdl-prepare-search-2
8481 (goto-char (point-min))
8482 (message "Fixing generic/port clauses...")
8483 (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t
)
8484 (goto-char (match-end 0))
8485 (condition-case nil
(vhdl-fix-clause) (error "")))
8486 (message "Fixing generic/port clauses...done"))))
8488 (defun vhdl-fix-clause ()
8489 "Fix closing parenthesis within generic/port clause."
8492 (vhdl-prepare-search-2
8496 (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t
))
8497 (error "ERROR: Not within a generic/port clause")
8498 ;; search for end of clause
8499 (goto-char (match-end 0))
8500 (setq beg
(1- (point)))
8501 (vhdl-forward-syntactic-ws)
8502 (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
8503 (goto-char (1- (match-end 0)))
8504 (setq end
(point-marker))
8506 (vhdl-forward-syntactic-ws))
8508 (when (> pos
(point-at-eol))
8509 (error "ERROR: Not within a generic/port clause"))
8510 ;; delete closing parenthesis on separate line (not supported style)
8511 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
8513 (vhdl-backward-syntactic-ws)
8514 (setq end
(point-marker))
8516 ;; delete superfluous parentheses
8517 (while (progn (goto-char beg
)
8518 (condition-case () (forward-sexp)
8519 (error (goto-char (point-max))))
8522 ;; add closing parenthesis
8523 (when (> (point) end
)
8528 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8530 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8532 (defconst vhdl-template-prompt-syntax
"[^ =<>][^<>@.\n]*[^ =<>]"
8533 "Syntax of prompt inserted by template generators.")
8535 (defvar vhdl-template-invoked-by-hook nil
8536 "Indicates whether a template has been invoked by a hook or by key or menu.
8537 Used for undoing after template abortion.")
8539 ;; correct different behavior of function `unread-command-events' in XEmacs
8540 (defun vhdl-character-to-event (arg))
8541 (defalias 'vhdl-character-to-event
8542 (if (fboundp 'character-to-event
) 'character-to-event
'identity
))
8544 (defun vhdl-work-library ()
8545 "Return the working library name of the current project or \"work\" if no
8546 project is defined."
8547 (vhdl-resolve-env-variable
8548 (or (nth 6 (aget vhdl-project-alist vhdl-project
)) vhdl-default-library
)))
8550 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8551 ;; Enabling/disabling
8553 (define-minor-mode vhdl-electric-mode
8554 "Toggle VHDL electric mode.
8555 With a prefix argument ARG, enable the mode if ARG is positive,
8556 and disable it otherwise. If called from Lisp, enable it if ARG
8558 :global t
:group
'vhdl-mode
)
8560 (define-minor-mode vhdl-stutter-mode
8561 "Toggle VHDL stuttering mode.
8562 With a prefix argument ARG, enable the mode if ARG is positive,
8563 and disable it otherwise. If called from Lisp, enable it if ARG
8565 :global t
:group
'vhdl-mode
)
8567 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8570 (defun vhdl-electric-dash (count)
8571 "-- starts a comment, --- draws a horizontal line,
8572 ---- starts a display comment."
8574 (if (and vhdl-stutter-mode
(not (vhdl-in-literal)))
8576 ((and abbrev-start-location
(= abbrev-start-location
(point)))
8577 (setq abbrev-start-location nil
)
8578 (goto-char last-abbrev-location
)
8579 (beginning-of-line nil
)
8580 (vhdl-comment-display))
8581 ((/= (preceding-char) ?-
) ; standard dash (minus)
8582 (self-insert-command count
))
8583 (t (self-insert-command count
)
8584 (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
8585 (let ((next-input (read-char)))
8586 (if (= next-input ?-
) ; triple dash
8588 (vhdl-comment-display-line)
8590 "Enter '-' for display comment, else continue coding")
8591 (let ((next-input (read-char)))
8592 (if (= next-input ?-
) ; four dashes
8593 (vhdl-comment-display t
)
8594 (setq unread-command-events
; pushback the char
8595 (list (vhdl-character-to-event next-input
))))))
8596 (setq unread-command-events
; pushback the char
8597 (list (vhdl-character-to-event next-input
)))
8598 (vhdl-comment-insert)))))
8599 (self-insert-command count
)))
8601 (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
8603 (if (and vhdl-stutter-mode
(= count
1) (not (vhdl-in-literal)))
8604 (if (= (preceding-char) ?\
()
8605 (progn (delete-char -
1) (insert-char ?\
[ 1))
8606 (insert-char ?\
( 1))
8607 (self-insert-command count
)))
8609 (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
8611 (if (and vhdl-stutter-mode
(= count
1) (not (vhdl-in-literal)))
8613 (if (= (preceding-char) ?\
))
8614 (progn (delete-char -
1) (insert-char ?\
] 1))
8615 (insert-char ?\
) 1))
8616 (blink-matching-open))
8617 (self-insert-command count
)))
8619 (defun vhdl-electric-quote (count) "'' --> \""
8621 (if (and vhdl-stutter-mode
(= count
1) (not (vhdl-in-literal)))
8622 (if (= (preceding-char) vhdl-last-input-event
)
8623 (progn (delete-char -
1) (insert-char ?
\" 1))
8624 (insert-char ?
\' 1))
8625 (self-insert-command count
)))
8627 (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
8629 (if (and vhdl-stutter-mode
(= count
1) (not (vhdl-in-literal)))
8630 (cond ((= (preceding-char) vhdl-last-input-event
)
8631 (progn (delete-char -
1)
8632 (unless (eq (preceding-char) ?
) (insert " "))
8634 (setq this-command
'vhdl-electric-colon
)))
8636 (eq last-command
'vhdl-electric-colon
) (= (preceding-char) ?
))
8637 (progn (delete-char -
1) (insert "= ")))
8638 (t (insert-char ?\
; 1)))
8639 (self-insert-command count
)))
8641 (defun vhdl-electric-comma (count) "',,' --> ' <= '"
8643 (if (and vhdl-stutter-mode
(= count
1) (not (vhdl-in-literal)))
8644 (cond ((= (preceding-char) vhdl-last-input-event
)
8645 (progn (delete-char -
1)
8646 (unless (eq (preceding-char) ?
) (insert " "))
8648 (t (insert-char ?\
, 1)))
8649 (self-insert-command count
)))
8651 (defun vhdl-electric-period (count) "'..' --> ' => '"
8653 (if (and vhdl-stutter-mode
(= count
1) (not (vhdl-in-literal)))
8654 (cond ((= (preceding-char) vhdl-last-input-event
)
8655 (progn (delete-char -
1)
8656 (unless (eq (preceding-char) ?
) (insert " "))
8658 (t (insert-char ?\.
1)))
8659 (self-insert-command count
)))
8661 (defun vhdl-electric-equal (count) "'==' --> ' == '"
8663 (if (and vhdl-stutter-mode
(= count
1) (not (vhdl-in-literal)))
8664 (cond ((= (preceding-char) vhdl-last-input-event
)
8665 (progn (delete-char -
1)
8666 (unless (eq (preceding-char) ?
) (insert " "))
8668 (t (insert-char ?\
= 1)))
8669 (self-insert-command count
)))
8671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8674 (defun vhdl-template-paired-parens ()
8675 "Insert a pair of round parentheses, placing point between them."
8680 (defun vhdl-template-alias ()
8681 "Insert alias declaration."
8683 (let ((start (point)))
8684 (vhdl-insert-keyword "ALIAS ")
8685 (when (vhdl-template-field "name" nil t start
(point))
8687 (unless (vhdl-template-field
8688 (concat "[type" (and (vhdl-standard-p 'ams
) " or nature") "]")
8691 (vhdl-insert-keyword " IS ")
8692 (vhdl-template-field "name" ";")
8693 (vhdl-comment-insert-inline))))
8695 (defun vhdl-template-architecture ()
8696 "Insert architecture."
8698 (let ((margin (current-indentation))
8701 (vhdl-insert-keyword "ARCHITECTURE ")
8702 (when (setq arch-name
8703 (vhdl-template-field "name" nil t start
(point)))
8704 (vhdl-insert-keyword " OF ")
8706 (vhdl-prepare-search-1
8707 (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t
)))
8708 (insert (match-string 1))
8709 (vhdl-template-field "entity name"))
8710 (vhdl-insert-keyword " IS\n")
8711 (vhdl-template-begin-end
8712 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
8713 (memq vhdl-insert-empty-lines
'(unit all
))))))
8715 (defun vhdl-template-array (kind &optional secondary
)
8716 "Insert array type definition."
8718 (let ((start (point)))
8719 (vhdl-insert-keyword "ARRAY (")
8720 (when (or (vhdl-template-field "range" nil
(not secondary
) start
(point))
8722 (vhdl-insert-keyword ") OF ")
8723 (vhdl-template-field (if (eq kind
'type
) "type" "nature"))
8724 (vhdl-insert-keyword ";"))))
8726 (defun vhdl-template-assert ()
8727 "Insert an assertion statement."
8729 (let ((start (point)))
8730 (vhdl-insert-keyword "ASSERT ")
8731 (when vhdl-conditions-in-parenthesis
(insert "("))
8732 (when (vhdl-template-field "condition (negated)" nil t start
(point))
8733 (when vhdl-conditions-in-parenthesis
(insert ")"))
8734 (setq start
(point))
8735 (vhdl-insert-keyword " REPORT ")
8736 (unless (vhdl-template-field "string expression" nil nil nil nil t
)
8737 (delete-region start
(point)))
8738 (setq start
(point))
8739 (vhdl-insert-keyword " SEVERITY ")
8740 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t
)
8741 (delete-region start
(point)))
8744 (defun vhdl-template-attribute ()
8745 "Insert an attribute declaration or specification."
8747 (if (eq (vhdl-decision-query
8748 "attribute" "(d)eclaration or (s)pecification?" t
) ?s
)
8749 (vhdl-template-attribute-spec)
8750 (vhdl-template-attribute-decl)))
8752 (defun vhdl-template-attribute-decl ()
8753 "Insert an attribute declaration."
8755 (let ((start (point)))
8756 (vhdl-insert-keyword "ATTRIBUTE ")
8757 (when (vhdl-template-field "name" " : " t start
(point))
8758 (vhdl-template-field "type" ";")
8759 (vhdl-comment-insert-inline))))
8761 (defun vhdl-template-attribute-spec ()
8762 "Insert an attribute specification."
8764 (let ((start (point)))
8765 (vhdl-insert-keyword "ATTRIBUTE ")
8766 (when (vhdl-template-field "name" nil t start
(point))
8767 (vhdl-insert-keyword " OF ")
8768 (vhdl-template-field "entity names | OTHERS | ALL" " : ")
8769 (vhdl-template-field "entity class")
8770 (vhdl-insert-keyword " IS ")
8771 (vhdl-template-field "expression" ";"))))
8773 (defun vhdl-template-block ()
8776 (let ((margin (current-indentation))
8779 (vhdl-insert-keyword ": BLOCK ")
8781 (when (setq label
(vhdl-template-field "label" nil t start
(+ (point) 8)))
8785 (if (vhdl-template-field "[guard expression]" nil t
)
8788 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8790 (vhdl-template-begin-end "BLOCK" label margin
)
8791 (vhdl-comment-block))))
8793 (defun vhdl-template-block-configuration ()
8794 "Insert a block configuration statement."
8796 (let ((margin (current-indentation))
8798 (vhdl-insert-keyword "FOR ")
8799 (when (vhdl-template-field "block name" nil t start
(point))
8800 (vhdl-insert-keyword "\n\n")
8802 (vhdl-insert-keyword "END FOR;")
8804 (indent-to (+ margin vhdl-basic-offset
)))))
8806 (defun vhdl-template-break ()
8807 "Insert a break statement."
8810 (vhdl-insert-keyword "BREAK")
8811 (setq position
(point))
8814 (progn (vhdl-insert-keyword "FOR ")
8815 (if (vhdl-template-field "[quantity name]" " USE " t
)
8816 (progn (vhdl-template-field "quantity name" " => ") t
)
8817 (delete-region (point)
8818 (progn (forward-word -
1) (point)))
8820 (vhdl-template-field "[quantity name]" " => " t
))
8821 (vhdl-template-field "expression")
8822 (setq position
(point))
8824 (delete-region position
(point))
8825 (unless (vhdl-sequential-statement-p)
8826 (vhdl-insert-keyword " ON ")
8827 (if (vhdl-template-field "[sensitivity list]" nil t
)
8828 (setq position
(point))
8829 (delete-region position
(point))))
8830 (vhdl-insert-keyword " WHEN ")
8831 (when vhdl-conditions-in-parenthesis
(insert "("))
8832 (if (vhdl-template-field "[condition]" nil t
)
8833 (when vhdl-conditions-in-parenthesis
(insert ")"))
8834 (delete-region position
(point)))
8837 (defun vhdl-template-case (&optional kind
)
8838 "Insert a case statement."
8840 (let ((margin (current-indentation))
8843 (unless kind
(setq kind
(if (or (vhdl-sequential-statement-p)
8844 (not (vhdl-standard-p 'ams
))) 'is
'use
)))
8845 (if (or (not (eq vhdl-optional-labels
'all
)) (vhdl-standard-p '87))
8846 (vhdl-insert-keyword "CASE ")
8847 (vhdl-insert-keyword ": CASE ")
8849 (setq label
(vhdl-template-field "[label]" nil t
))
8850 (unless label
(delete-char 2))
8853 (when (vhdl-template-field "expression" nil t start
(point))
8854 (vhdl-insert-keyword (concat " " (if (eq kind
'is
) "IS" "USE") "\n\n"))
8856 (vhdl-insert-keyword "END CASE")
8857 (when label
(insert " " label
))
8860 (indent-to (+ margin vhdl-basic-offset
))
8861 (vhdl-insert-keyword "WHEN ")
8862 (let ((position (point)))
8864 (indent-to (+ margin vhdl-basic-offset
))
8865 (vhdl-insert-keyword "WHEN OTHERS => null;")
8866 (goto-char position
)))))
8868 (defun vhdl-template-case-is ()
8869 "Insert a sequential case statement."
8871 (vhdl-template-case 'is
))
8873 (defun vhdl-template-case-use ()
8874 "Insert a simultaneous case statement."
8876 (vhdl-template-case 'use
))
8878 (defun vhdl-template-component ()
8879 "Insert a component declaration."
8881 (vhdl-template-component-decl))
8883 (defun vhdl-template-component-conf ()
8884 "Insert a component configuration (uses `vhdl-template-configuration-spec'
8885 since these are almost equivalent)."
8887 (let ((margin (current-indentation))
8888 (result (vhdl-template-configuration-spec t
)))
8892 (vhdl-insert-keyword "END FOR;")
8893 (when (eq result
'no-use
)
8894 (end-of-line -
0)))))
8896 (defun vhdl-template-component-decl ()
8897 "Insert a component declaration."
8899 (let ((margin (current-indentation))
8902 (vhdl-insert-keyword "COMPONENT ")
8903 (when (setq name
(vhdl-template-field "name" nil t start
(point)))
8904 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
8907 (vhdl-insert-keyword "END COMPONENT")
8908 (unless (vhdl-standard-p '87) (insert " " name
))
8910 (setq end-column
(current-column))
8912 (indent-to (+ margin vhdl-basic-offset
))
8913 (vhdl-template-generic-list t t
)
8915 (indent-to (+ margin vhdl-basic-offset
))
8916 (vhdl-template-port-list t
)
8917 (beginning-of-line 2)
8918 (forward-char end-column
))))
8920 (defun vhdl-template-component-inst ()
8921 "Insert a component instantiation statement."
8923 (let ((margin (current-indentation))
8926 (when (vhdl-template-field "instance label" nil t start
(point))
8928 (if (not (vhdl-use-direct-instantiation))
8929 (vhdl-template-field "component name")
8930 ;; direct instantiation
8931 (setq unit
(vhdl-template-field
8932 "[COMPONENT | ENTITY | CONFIGURATION]" " " t
))
8933 (setq unit
(upcase (or unit
"")))
8934 (cond ((equal unit
"ENTITY")
8935 (let ((begin (point)))
8936 (vhdl-template-field "library name" "." t begin
(point) nil
8937 (vhdl-work-library))
8938 (vhdl-template-field "entity name" "(")
8939 (if (vhdl-template-field "[architecture name]" nil t
)
8942 ((equal unit
"CONFIGURATION")
8943 (vhdl-template-field "library name" "." nil nil nil nil
8944 (vhdl-work-library))
8945 (vhdl-template-field "configuration name"))
8946 (t (vhdl-template-field "component name"))))
8948 (indent-to (+ margin vhdl-basic-offset
))
8949 (setq position
(point))
8950 (vhdl-insert-keyword "GENERIC ")
8951 (when (vhdl-template-map position t t
)
8953 (indent-to (+ margin vhdl-basic-offset
)))
8954 (setq position
(point))
8955 (vhdl-insert-keyword "PORT ")
8956 (unless (vhdl-template-map position t t
)
8957 (delete-region (line-beginning-position) (point))
8961 (defun vhdl-template-conditional-signal-asst ()
8962 "Insert a conditional signal assignment."
8964 (when (vhdl-template-field "target signal")
8966 ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
8968 (let ((margin (current-column))
8971 (vhdl-template-field "waveform")
8972 (setq position
(point))
8973 (vhdl-insert-keyword " WHEN ")
8974 (when vhdl-conditions-in-parenthesis
(insert "("))
8975 (while (and (vhdl-template-field "[condition]" nil t
)
8977 (when vhdl-conditions-in-parenthesis
(insert ")"))
8978 (setq position
(point))
8979 (vhdl-insert-keyword " ELSE")
8982 (vhdl-template-field "[waveform]" nil t
)))
8983 (setq position
(point))
8984 (vhdl-insert-keyword " WHEN ")
8985 (when vhdl-conditions-in-parenthesis
(insert "(")))
8986 (delete-region position
(point))
8988 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1)))))
8990 (defun vhdl-template-configuration ()
8991 "Insert a configuration specification if within an architecture,
8992 a block or component configuration if within a configuration declaration,
8993 a configuration declaration if not within a design unit."
8995 (vhdl-prepare-search-1
8997 ((and (save-excursion ; architecture body
8998 (re-search-backward "^\\(architecture\\|end\\)\\>" nil t
))
8999 (equal "ARCHITECTURE" (upcase (match-string 1))))
9000 (vhdl-template-configuration-spec))
9001 ((and (save-excursion ; configuration declaration
9002 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t
))
9003 (equal "CONFIGURATION" (upcase (match-string 1))))
9004 (if (eq (vhdl-decision-query
9005 "configuration" "(b)lock or (c)omponent configuration?" t
) ?c
)
9006 (vhdl-template-component-conf)
9007 (vhdl-template-block-configuration)))
9008 (t (vhdl-template-configuration-decl))))) ; otherwise
9010 (defun vhdl-template-configuration-spec (&optional optional-use
)
9011 "Insert a configuration specification."
9013 (let ((margin (current-indentation))
9016 (vhdl-insert-keyword "FOR ")
9017 (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
9019 (vhdl-template-field "component name" "\n")
9020 (indent-to (+ margin vhdl-basic-offset
))
9021 (setq start
(point))
9022 (vhdl-insert-keyword "USE ")
9023 (if (and optional-use
9024 (not (setq aspect
(vhdl-template-field
9025 "[ENTITY | CONFIGURATION | OPEN]" " " t
))))
9026 (progn (delete-region start
(point)) 'no-use
)
9027 (unless optional-use
9028 (setq aspect
(vhdl-template-field
9029 "ENTITY | CONFIGURATION | OPEN" " ")))
9030 (setq aspect
(upcase (or aspect
"")))
9031 (cond ((equal aspect
"ENTITY")
9032 (vhdl-template-field "library name" "." nil nil nil nil
9033 (vhdl-work-library))
9034 (vhdl-template-field "entity name" "(")
9035 (if (vhdl-template-field "[architecture name]" nil t
)
9039 (indent-to (+ margin
(* 2 vhdl-basic-offset
)))
9040 (setq position
(point))
9041 (vhdl-insert-keyword "GENERIC ")
9042 (when (vhdl-template-map position t t
)
9044 (indent-to (+ margin
(* 2 vhdl-basic-offset
))))
9045 (setq position
(point))
9046 (vhdl-insert-keyword "PORT ")
9047 (unless (vhdl-template-map position t t
)
9048 (delete-region (line-beginning-position) (point))
9052 ((equal aspect
"CONFIGURATION")
9053 (vhdl-template-field "library name" "." nil nil nil nil
9054 (vhdl-work-library))
9055 (vhdl-template-field "configuration name" ";"))
9056 (t (delete-char -
1) (insert ";") t
))))))
9059 (defun vhdl-template-configuration-decl ()
9060 "Insert a configuration declaration."
9062 (let ((margin (current-indentation))
9064 entity-exists string name position
)
9065 (vhdl-insert-keyword "CONFIGURATION ")
9066 (when (setq name
(vhdl-template-field "name" nil t start
(point)))
9067 (vhdl-insert-keyword " OF ")
9069 (vhdl-prepare-search-1
9070 (setq entity-exists
(vhdl-re-search-backward
9071 "\\<entity \\(\\w*\\) is\\>" nil t
))
9072 (setq string
(match-string 1))))
9073 (if (and entity-exists
(not (equal string
"")))
9075 (vhdl-template-field "entity name"))
9076 (vhdl-insert-keyword " IS\n")
9077 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
9078 (indent-to (+ margin vhdl-basic-offset
))
9079 (setq position
(point))
9081 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
9083 (vhdl-insert-keyword "END ")
9084 (unless (vhdl-standard-p '87)
9085 (vhdl-insert-keyword "CONFIGURATION "))
9087 (goto-char position
))))
9089 (defun vhdl-template-constant ()
9090 "Insert a constant declaration."
9092 (let ((start (point))
9093 (in-arglist (vhdl-in-argument-list-p)))
9094 (vhdl-insert-keyword "CONSTANT ")
9095 (when (vhdl-template-field "name" nil t start
(point))
9097 (when in-arglist
(vhdl-insert-keyword "IN "))
9098 (vhdl-template-field "type")
9101 (vhdl-comment-insert-inline))
9102 (let ((position (point)))
9104 (unless (vhdl-template-field "[initialization]" nil t
)
9105 (delete-region position
(point)))
9107 (vhdl-comment-insert-inline))))))
9109 (defun vhdl-template-default ()
9118 (defun vhdl-template-default-indent ()
9119 "Insert nothing and indent."
9126 (indent-according-to-mode))
9128 (defun vhdl-template-disconnect ()
9129 "Insert a disconnect statement."
9131 (let ((start (point)))
9132 (vhdl-insert-keyword "DISCONNECT ")
9133 (when (vhdl-template-field "signal names | OTHERS | ALL"
9134 " : " t start
(point))
9135 (vhdl-template-field "type")
9136 (vhdl-insert-keyword " AFTER ")
9137 (vhdl-template-field "time expression" ";"))))
9139 (defun vhdl-template-else ()
9140 "Insert an else statement."
9143 (vhdl-prepare-search-1
9144 (vhdl-insert-keyword "ELSE")
9145 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t
))
9146 (equal "WHEN" (upcase (match-string 1))))
9148 (indent-according-to-mode)
9149 (setq margin
(current-indentation))
9151 (indent-to (+ margin vhdl-basic-offset
))))))
9153 (defun vhdl-template-elsif ()
9154 "Insert an elsif statement."
9156 (let ((start (point))
9158 (vhdl-insert-keyword "ELSIF ")
9159 (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams
))
9160 (when vhdl-conditions-in-parenthesis
(insert "("))
9161 (when (vhdl-template-field "condition" nil t start
(point))
9162 (when vhdl-conditions-in-parenthesis
(insert ")"))
9163 (indent-according-to-mode)
9164 (setq margin
(current-indentation))
9165 (vhdl-insert-keyword
9166 (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
9167 (indent-to (+ margin vhdl-basic-offset
))))))
9169 (defun vhdl-template-entity ()
9172 (let ((margin (current-indentation))
9175 (vhdl-insert-keyword "ENTITY ")
9176 (when (setq name
(vhdl-template-field "name" nil t start
(point)))
9177 (vhdl-insert-keyword " IS\n\n")
9179 (vhdl-insert-keyword "END ")
9180 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
9182 (setq end-column
(current-column))
9184 (indent-to (+ margin vhdl-basic-offset
))
9185 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
9186 (indent-to (+ margin vhdl-basic-offset
))
9187 (when (vhdl-template-generic-list t
)
9188 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n")))
9190 (indent-to (+ margin vhdl-basic-offset
))
9191 (when (vhdl-template-port-list t
)
9192 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n")))
9193 (beginning-of-line 2)
9194 (forward-char end-column
))))
9196 (defun vhdl-template-exit ()
9197 "Insert an exit statement."
9199 (let ((start (point)))
9200 (vhdl-insert-keyword "EXIT ")
9201 (if (vhdl-template-field "[loop label]" nil t start
(point))
9202 (let ((position (point)))
9203 (vhdl-insert-keyword " WHEN ")
9204 (when vhdl-conditions-in-parenthesis
(insert "("))
9205 (if (vhdl-template-field "[condition]" nil t
)
9206 (when vhdl-conditions-in-parenthesis
(insert ")"))
9207 (delete-region position
(point))))
9211 (defun vhdl-template-file ()
9212 "Insert a file declaration."
9214 (let ((start (point)))
9215 (vhdl-insert-keyword "FILE ")
9216 (when (vhdl-template-field "name" nil t start
(point))
9218 (vhdl-template-field "type")
9219 (unless (vhdl-standard-p '87)
9220 (vhdl-insert-keyword " OPEN ")
9221 (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
9224 (vhdl-insert-keyword " IS ")
9225 (when (vhdl-standard-p '87)
9226 (vhdl-template-field "[IN | OUT]" " " t
))
9227 (vhdl-template-field "filename-string" nil nil nil nil t
)
9229 (vhdl-comment-insert-inline))))
9231 (defun vhdl-template-for ()
9232 "Insert a block or component configuration if within a configuration
9233 declaration, a configuration specification if within an architecture
9234 declarative part (and not within a subprogram), a for-loop if within a
9235 sequential statement part (subprogram or process), and a for-generate
9238 (vhdl-prepare-search-1
9240 ((vhdl-sequential-statement-p) ; sequential statement
9241 (vhdl-template-for-loop))
9242 ((and (save-excursion ; configuration declaration
9243 (re-search-backward "^\\(configuration\\|end\\)\\>" nil t
))
9244 (equal "CONFIGURATION" (upcase (match-string 1))))
9245 (if (eq (vhdl-decision-query
9246 "for" "(b)lock or (c)omponent configuration?" t
) ?c
)
9247 (vhdl-template-component-conf)
9248 (vhdl-template-block-configuration)))
9249 ((and (save-excursion
9250 (re-search-backward ; architecture declarative part
9251 "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t
))
9252 (equal "ARCHITECTURE" (upcase (match-string 1))))
9253 (vhdl-template-configuration-spec))
9254 (t (vhdl-template-for-generate))))) ; concurrent statement
9256 (defun vhdl-template-for-generate ()
9257 "Insert a for-generate."
9259 (let ((margin (current-indentation))
9262 (vhdl-insert-keyword ": FOR ")
9263 (setq position
(point-marker))
9265 (when (setq label
(vhdl-template-field "label" nil t start position
))
9266 (goto-char position
)
9267 (vhdl-template-field "loop variable")
9268 (vhdl-insert-keyword " IN ")
9269 (vhdl-template-field "range")
9270 (vhdl-template-generate-body margin label
))))
9272 (defun vhdl-template-for-loop ()
9273 "Insert a for loop."
9275 (let ((margin (current-indentation))
9278 (if (not (eq vhdl-optional-labels
'all
))
9279 (vhdl-insert-keyword "FOR ")
9280 (vhdl-insert-keyword ": FOR ")
9282 (setq label
(vhdl-template-field "[label]" nil t
))
9283 (unless label
(delete-char 2))
9286 (when (setq index
(vhdl-template-field "loop variable"
9287 nil t start
(point)))
9288 (vhdl-insert-keyword " IN ")
9289 (vhdl-template-field "range")
9290 (vhdl-insert-keyword " LOOP\n\n")
9292 (vhdl-insert-keyword "END LOOP")
9294 (insert " " label
";")
9296 (when vhdl-self-insert-comments
(insert " -- " index
)))
9298 (indent-to (+ margin vhdl-basic-offset
)))))
9300 (defun vhdl-template-function (&optional kind
)
9301 "Insert a function declaration or body."
9303 (let ((margin (current-indentation))
9306 (vhdl-insert-keyword "FUNCTION ")
9307 (when (setq name
(vhdl-template-field "name" nil t start
(point)))
9308 (vhdl-template-argument-list t
)
9309 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1))
9312 (indent-to (+ margin vhdl-basic-offset
))
9313 (vhdl-insert-keyword "RETURN ")
9314 (vhdl-template-field "type")
9315 (if (if kind
(eq kind
'body
)
9316 (eq (vhdl-decision-query nil
"(d)eclaration or (b)ody?") ?b
))
9317 (progn (vhdl-insert-keyword " IS\n")
9318 (vhdl-template-begin-end
9319 (unless (vhdl-standard-p '87) "FUNCTION") name margin
)
9320 (vhdl-comment-block))
9323 (defun vhdl-template-function-decl ()
9324 "Insert a function declaration."
9326 (vhdl-template-function 'decl
))
9328 (defun vhdl-template-function-body ()
9329 "Insert a function declaration."
9331 (vhdl-template-function 'body
))
9333 (defun vhdl-template-generate ()
9334 "Insert a generation scheme."
9336 (if (eq (vhdl-decision-query nil
"(f)or or (i)f?" t
) ?i
)
9337 (vhdl-template-if-generate)
9338 (vhdl-template-for-generate)))
9340 (defun vhdl-template-generic ()
9341 "Insert generic declaration, or generic map in instantiation statements."
9343 (let ((start (point)))
9344 (vhdl-prepare-search-1
9346 ((and (save-excursion ; entity declaration
9347 (re-search-backward "^\\(entity\\|end\\)\\>" nil t
))
9348 (equal "ENTITY" (upcase (match-string 1))))
9349 (vhdl-template-generic-list nil
))
9350 ((or (save-excursion
9351 (or (beginning-of-line)
9352 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9353 (equal 'statement-cont
(caar (vhdl-get-syntactic-context))))
9354 (vhdl-insert-keyword "GENERIC ")
9355 (vhdl-template-map start
))
9356 (t (vhdl-template-generic-list nil t
))))))
9358 (defun vhdl-template-group ()
9359 "Insert group or group template declaration."
9361 (let ((start (point)))
9362 (if (eq (vhdl-decision-query
9363 "group" "(d)eclaration or (t)emplate declaration?" t
) ?t
)
9364 (vhdl-template-group-template)
9365 (vhdl-template-group-decl))))
9367 (defun vhdl-template-group-decl ()
9368 "Insert group declaration."
9370 (let ((start (point)))
9371 (vhdl-insert-keyword "GROUP ")
9372 (when (vhdl-template-field "name" " : " t start
(point))
9373 (vhdl-template-field "template name" " (")
9374 (vhdl-template-field "constituent list" ");")
9375 (vhdl-comment-insert-inline))))
9377 (defun vhdl-template-group-template ()
9378 "Insert group template declaration."
9380 (let ((start (point)))
9381 (vhdl-insert-keyword "GROUP ")
9382 (when (vhdl-template-field "template name" nil t start
(point))
9383 (vhdl-insert-keyword " IS (")
9384 (vhdl-template-field "entity class list" ");")
9385 (vhdl-comment-insert-inline))))
9387 (defun vhdl-template-if ()
9388 "Insert a sequential if statement or an if-generate statement."
9390 (if (vhdl-sequential-statement-p)
9391 (vhdl-template-if-then)
9392 (if (and (vhdl-standard-p 'ams
)
9393 (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t
) ?u
))
9394 (vhdl-template-if-use)
9395 (vhdl-template-if-generate))))
9397 (defun vhdl-template-if-generate ()
9398 "Insert an if-generate."
9400 (let ((margin (current-indentation))
9403 (vhdl-insert-keyword ": IF ")
9404 (setq position
(point-marker))
9406 (when (setq label
(vhdl-template-field "label" nil t start position
))
9407 (goto-char position
)
9408 (when vhdl-conditions-in-parenthesis
(insert "("))
9409 (vhdl-template-field "condition")
9410 (when vhdl-conditions-in-parenthesis
(insert ")"))
9411 (vhdl-template-generate-body margin label
))))
9413 (defun vhdl-template-if-then-use (kind)
9414 "Insert a sequential if statement."
9416 (let ((margin (current-indentation))
9419 (if (or (not (eq vhdl-optional-labels
'all
)) (vhdl-standard-p '87))
9420 (vhdl-insert-keyword "IF ")
9421 (vhdl-insert-keyword ": IF ")
9423 (setq label
(vhdl-template-field "[label]" nil t
))
9424 (unless label
(delete-char 2))
9427 (when vhdl-conditions-in-parenthesis
(insert "("))
9428 (when (vhdl-template-field "condition" nil t start
(point))
9429 (when vhdl-conditions-in-parenthesis
(insert ")"))
9430 (vhdl-insert-keyword
9431 (concat " " (if (eq kind
'then
) "THEN" "USE") "\n\n"))
9433 (vhdl-insert-keyword (concat "END " (if (eq kind
'then
) "IF" "USE")))
9434 (when label
(insert " " label
))
9437 (indent-to (+ margin vhdl-basic-offset
)))))
9439 (defun vhdl-template-if-then ()
9440 "Insert a sequential if statement."
9442 (vhdl-template-if-then-use 'then
))
9444 (defun vhdl-template-if-use ()
9445 "Insert a simultaneous if statement."
9447 (vhdl-template-if-then-use 'use
))
9449 (defun vhdl-template-instance ()
9450 "Insert a component instantiation statement."
9452 (vhdl-template-component-inst))
9454 (defun vhdl-template-library ()
9455 "Insert a library specification."
9457 (let ((margin (current-indentation))
9460 (vhdl-insert-keyword "LIBRARY ")
9461 (when (setq name
(vhdl-template-field "names" nil t start
(point)))
9463 (unless (string-match "," name
)
9464 (setq end-pos
(point))
9467 (vhdl-insert-keyword "USE ")
9469 (vhdl-insert-keyword "..ALL;")
9471 (if (vhdl-template-field "package name")
9473 (delete-region end-pos
(+ (point) 5)))))))
9475 (defun vhdl-template-limit ()
9478 (let ((start (point)))
9479 (vhdl-insert-keyword "LIMIT ")
9480 (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
9482 (vhdl-template-field "type")
9483 (vhdl-insert-keyword " WITH ")
9484 (vhdl-template-field "real expression" ";"))))
9486 (defun vhdl-template-loop ()
9489 (let ((char (vhdl-decision-query nil
"(w)hile, (f)or, or (b)are?" t
)))
9491 (vhdl-template-while-loop))
9493 (vhdl-template-for-loop))
9494 (t (vhdl-template-bare-loop)))))
9496 (defun vhdl-template-bare-loop ()
9499 (let ((margin (current-indentation))
9502 (if (not (eq vhdl-optional-labels
'all
))
9503 (vhdl-insert-keyword "LOOP ")
9504 (vhdl-insert-keyword ": LOOP ")
9506 (setq label
(vhdl-template-field "[label]" nil t
))
9507 (unless label
(delete-char 2))
9512 (vhdl-insert-keyword "END LOOP")
9513 (insert (if label
(concat " " label
";") ";"))
9515 (indent-to (+ margin vhdl-basic-offset
))))
9517 (defun vhdl-template-map (&optional start optional secondary
)
9518 "Insert a map specification with association list."
9520 (let ((start (or start
(point)))
9522 (vhdl-insert-keyword "MAP (")
9523 (if (not vhdl-association-list-with-formals
)
9524 (if (vhdl-template-field
9525 (concat (and optional
"[") "association list" (and optional
"]"))
9526 ")" (or (not secondary
) optional
)
9527 (and (not secondary
) start
) (point))
9529 (if (and optional secondary
) (delete-region start
(point)))
9531 (if vhdl-argument-list-indent
9532 (setq margin
(current-column))
9533 (setq margin
(+ (current-indentation) vhdl-basic-offset
))
9536 (if (vhdl-template-field
9537 (concat (and optional
"[") "formal" (and optional
"]"))
9538 " => " (or (not secondary
) optional
)
9539 (and (not secondary
) start
) (point))
9541 (vhdl-template-field "actual" ",")
9542 (setq end-pos
(point))
9545 (while (vhdl-template-field "[formal]" " => " t
)
9546 (vhdl-template-field "actual" ",")
9547 (setq end-pos
(point))
9550 (delete-region end-pos
(point))
9553 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1))
9555 (when (and optional secondary
) (delete-region start
(point)))
9558 (defun vhdl-template-modify (&optional noerror
)
9559 "Actualize modification date."
9561 (vhdl-prepare-search-2
9563 (goto-char (point-min))
9564 (if (re-search-forward vhdl-modify-date-prefix-string nil t
)
9565 (progn (delete-region (point) (progn (end-of-line) (point)))
9566 (vhdl-template-insert-date))
9568 (error "ERROR: Modification date prefix string \"%s\" not found"
9569 vhdl-modify-date-prefix-string
))))))
9572 (defun vhdl-template-modify-noerror ()
9573 "Call `vhdl-template-modify' with NOERROR non-nil."
9574 (vhdl-template-modify t
))
9576 (defun vhdl-template-nature ()
9577 "Insert a nature declaration."
9579 (let ((start (point))
9580 name mid-pos end-pos
)
9581 (vhdl-insert-keyword "NATURE ")
9582 (when (setq name
(vhdl-template-field "name" nil t start
(point)))
9583 (vhdl-insert-keyword " IS ")
9586 (or (vhdl-template-field
9587 "across type | ARRAY | RECORD")
9589 (cond ((equal definition
"")
9591 ((equal definition
"ARRAY")
9592 (delete-region (point) (progn (forward-word -
1) (point)))
9593 (vhdl-template-array 'nature t
))
9594 ((equal definition
"RECORD")
9595 (setq mid-pos
(point-marker))
9596 (delete-region (point) (progn (forward-word -
1) (point)))
9597 (vhdl-template-record 'nature name t
))
9599 (vhdl-insert-keyword " ACROSS ")
9600 (vhdl-template-field "through type")
9601 (vhdl-insert-keyword " THROUGH ")
9602 (vhdl-template-field "reference name")
9603 (vhdl-insert-keyword " REFERENCE;")))
9605 (setq end-pos
(point-marker))
9608 (vhdl-comment-insert-inline)
9609 (when end-pos
(goto-char end-pos
))))))
9611 (defun vhdl-template-next ()
9612 "Insert a next statement."
9614 (let ((start (point)))
9615 (vhdl-insert-keyword "NEXT ")
9616 (if (vhdl-template-field "[loop label]" nil t start
(point))
9617 (let ((position (point)))
9618 (vhdl-insert-keyword " WHEN ")
9619 (when vhdl-conditions-in-parenthesis
(insert "("))
9620 (if (vhdl-template-field "[condition]" nil t
)
9621 (when vhdl-conditions-in-parenthesis
(insert ")"))
9622 (delete-region position
(point))))
9626 (defun vhdl-template-others ()
9627 "Insert an others aggregate."
9629 (let ((start (point)))
9630 (if (or (= (preceding-char) ?\
() (not vhdl-template-invoked-by-hook
))
9631 (progn (unless vhdl-template-invoked-by-hook
(insert "("))
9632 (vhdl-insert-keyword "OTHERS => '")
9633 (when (vhdl-template-field "value" nil t start
(point))
9635 (vhdl-insert-keyword "OTHERS "))))
9637 (defun vhdl-template-package (&optional kind
)
9638 "Insert a package specification or body."
9640 (let ((margin (current-indentation))
9643 (vhdl-insert-keyword "PACKAGE ")
9644 (setq body
(if kind
(eq kind
'body
)
9645 (eq (vhdl-decision-query nil
"(d)eclaration or (b)ody?") ?b
)))
9647 (vhdl-insert-keyword "BODY ")
9648 (when (save-excursion
9649 (vhdl-prepare-search-1
9650 (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t
)))
9651 (insert (setq name
(match-string 1)))))
9653 (setq name
(vhdl-template-field "name" nil t start
(point))))
9654 (vhdl-insert-keyword " IS\n")
9655 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
9656 (indent-to (+ margin vhdl-basic-offset
))
9657 (setq position
(point))
9659 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
9661 (vhdl-insert-keyword "END ")
9662 (unless (vhdl-standard-p '87)
9663 (vhdl-insert-keyword (concat "PACKAGE " (and body
"BODY "))))
9664 (insert (or name
"") ";")
9665 (goto-char position
))))
9667 (defun vhdl-template-package-decl ()
9668 "Insert a package specification."
9670 (vhdl-template-package 'decl
))
9672 (defun vhdl-template-package-body ()
9673 "Insert a package body."
9675 (vhdl-template-package 'body
))
9677 (defun vhdl-template-port ()
9678 "Insert a port declaration, or port map in instantiation statements."
9680 (let ((start (point)))
9681 (vhdl-prepare-search-1
9683 ((and (save-excursion ; entity declaration
9684 (re-search-backward "^\\(entity\\|end\\)\\>" nil t
))
9685 (equal "ENTITY" (upcase (match-string 1))))
9686 (vhdl-template-port-list nil
))
9687 ((or (save-excursion
9688 (or (beginning-of-line)
9689 (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
9690 (equal 'statement-cont
(caar (vhdl-get-syntactic-context))))
9691 (vhdl-insert-keyword "PORT ")
9692 (vhdl-template-map start
))
9693 (t (vhdl-template-port-list nil
))))))
9695 (defun vhdl-template-procedural ()
9696 "Insert a procedural."
9698 (let ((margin (current-indentation))
9700 (case-fold-search t
)
9702 (vhdl-insert-keyword "PROCEDURAL ")
9703 (when (memq vhdl-optional-labels
'(process all
))
9707 (setq label
(vhdl-template-field "[label]" nil t
))
9708 (unless label
(delete-char 2))
9711 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
9713 (vhdl-template-begin-end "PROCEDURAL" label margin
)
9714 (vhdl-comment-block)))
9716 (defun vhdl-template-procedure (&optional kind
)
9717 "Insert a procedure declaration or body."
9719 (let ((margin (current-indentation))
9722 (vhdl-insert-keyword "PROCEDURE ")
9723 (when (setq name
(vhdl-template-field "name" nil t start
(point)))
9724 (vhdl-template-argument-list)
9725 (if (if kind
(eq kind
'body
)
9726 (eq (vhdl-decision-query nil
"(d)eclaration or (b)ody?") ?b
))
9727 (progn (vhdl-insert-keyword " IS")
9728 (when vhdl-auto-align
9729 (vhdl-align-region-groups start
(point) 1))
9730 (end-of-line) (insert "\n")
9731 (vhdl-template-begin-end
9732 (unless (vhdl-standard-p '87) "PROCEDURE")
9734 (vhdl-comment-block))
9736 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1))
9739 (defun vhdl-template-procedure-decl ()
9740 "Insert a procedure declaration."
9742 (vhdl-template-procedure 'decl
))
9744 (defun vhdl-template-procedure-body ()
9745 "Insert a procedure body."
9747 (vhdl-template-procedure 'body
))
9749 (defun vhdl-template-process (&optional kind
)
9752 (let ((margin (current-indentation))
9754 (reset-kind vhdl-reset-kind
)
9755 label seq input-signals clock reset final-pos
)
9756 (setq seq
(if kind
(eq kind
'seq
)
9757 (eq (vhdl-decision-query
9758 "process" "(c)ombinational or (s)equential?" t
) ?s
)))
9759 (vhdl-insert-keyword "PROCESS ")
9760 (when (memq vhdl-optional-labels
'(process all
))
9764 (setq label
(vhdl-template-field "[label]" nil t
))
9765 (unless label
(delete-char 2))
9770 (unless (setq input-signals
9771 (vhdl-template-field "[sensitivity list]" ")" t
))
9772 (setq input-signals
"")
9774 (setq clock
(or (and (not (equal "" vhdl-clock-name
))
9775 (progn (insert vhdl-clock-name
) vhdl-clock-name
))
9776 (vhdl-template-field "clock name") "<clock>"))
9777 (when (eq reset-kind
'query
)
9779 (if (eq (vhdl-decision-query
9780 "" "(a)synchronous or (s)ynchronous reset?" t
) ?a
)
9783 (when (eq reset-kind
'async
)
9785 (setq reset
(or (and (not (equal "" vhdl-reset-name
))
9786 (progn (insert vhdl-reset-name
) vhdl-reset-name
))
9787 (vhdl-template-field "reset name") "<reset>")))
9789 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
9791 (vhdl-template-begin-end "PROCESS" label margin
)
9792 (when seq
(setq reset
(vhdl-template-seq-process clock reset reset-kind
)))
9793 (when vhdl-prompt-for-comments
9794 (setq final-pos
(point-marker))
9795 (vhdl-prepare-search-2
9796 (when (and (vhdl-re-search-backward "\\<begin\\>" nil t
)
9797 (vhdl-re-search-backward "\\<process\\>" nil t
))
9800 (progn (insert "\n") (forward-line -
1))
9803 (insert "-- purpose: ")
9804 (if (not (vhdl-template-field "[description]" nil t
))
9805 (vhdl-line-kill-entire)
9808 (insert "-- type : ")
9809 (insert (if seq
"sequential" "combinational") "\n")
9811 (insert "-- inputs : ")
9813 (insert input-signals
)
9815 (when reset
(insert reset
", "))
9816 (unless (vhdl-template-field "[signal names]" nil t
)
9820 (insert "-- outputs: ")
9821 (vhdl-template-field "[signal names]" nil t
))))
9822 (goto-char final-pos
))))
9824 (defun vhdl-template-process-comb ()
9825 "Insert a combinational process."
9827 (vhdl-template-process 'comb
))
9829 (defun vhdl-template-process-seq ()
9830 "Insert a sequential process."
9832 (vhdl-template-process 'seq
))
9834 (defun vhdl-template-quantity ()
9835 "Insert a quantity declaration."
9837 (if (vhdl-in-argument-list-p)
9838 (let ((start (point)))
9839 (vhdl-insert-keyword "QUANTITY ")
9840 (when (vhdl-template-field "names" nil t start
(point))
9842 (vhdl-template-field "[IN | OUT]" " " t
)
9843 (vhdl-template-field "type")
9845 (vhdl-comment-insert-inline)))
9846 (let ((char (vhdl-decision-query
9847 "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t
)))
9848 (cond ((eq char ?f
) (vhdl-template-quantity-free))
9849 ((eq char ?b
) (vhdl-template-quantity-branch))
9850 ((eq char ?s
) (vhdl-template-quantity-source))
9851 (t (vhdl-template-undo (point) (point)))))))
9853 (defun vhdl-template-quantity-free ()
9854 "Insert a free quantity declaration."
9856 (vhdl-insert-keyword "QUANTITY ")
9857 (vhdl-template-field "names")
9859 (vhdl-template-field "type")
9860 (let ((position (point)))
9862 (unless (vhdl-template-field "[initialization]" nil t
)
9863 (delete-region position
(point)))
9865 (vhdl-comment-insert-inline)))
9867 (defun vhdl-template-quantity-branch ()
9868 "Insert a branch quantity declaration."
9871 (vhdl-insert-keyword "QUANTITY ")
9872 (when (vhdl-template-field "[across names]" " " t
)
9873 (vhdl-insert-keyword "ACROSS "))
9874 (when (vhdl-template-field "[through names]" " " t
)
9875 (vhdl-insert-keyword "THROUGH "))
9876 (vhdl-template-field "plus terminal name")
9877 (setq position
(point))
9878 (vhdl-insert-keyword " TO ")
9879 (unless (vhdl-template-field "[minus terminal name]" nil t
)
9880 (delete-region position
(point)))
9882 (vhdl-comment-insert-inline)))
9884 (defun vhdl-template-quantity-source ()
9885 "Insert a source quantity declaration."
9887 (vhdl-insert-keyword "QUANTITY ")
9888 (vhdl-template-field "names")
9890 (vhdl-template-field "type" " ")
9891 (if (eq (vhdl-decision-query nil
"(s)pectrum or (n)oise?") ?n
)
9892 (progn (vhdl-insert-keyword "NOISE ")
9893 (vhdl-template-field "power expression"))
9894 (vhdl-insert-keyword "SPECTRUM ")
9895 (vhdl-template-field "magnitude expression" ", ")
9896 (vhdl-template-field "phase expression"))
9898 (vhdl-comment-insert-inline))
9900 (defun vhdl-template-record (kind &optional name secondary
)
9901 "Insert a record type declaration."
9903 (let ((margin (current-column))
9906 (vhdl-insert-keyword "RECORD\n")
9907 (indent-to (+ margin vhdl-basic-offset
))
9908 (when (or (vhdl-template-field "element names"
9909 nil
(not secondary
) start
(point))
9911 (while (or first
(vhdl-template-field "[element names]" nil t
))
9913 (vhdl-template-field (if (eq kind
'type
) "type" "nature") ";")
9914 (vhdl-comment-insert-inline)
9916 (indent-to (+ margin vhdl-basic-offset
))
9918 (delete-region (line-beginning-position) (point))
9920 (vhdl-insert-keyword "END RECORD")
9921 (unless (vhdl-standard-p '87) (and name
(insert " " name
)))
9923 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1)))))
9925 (defun vhdl-template-report ()
9926 "Insert a report statement."
9928 (let ((start (point)))
9929 (vhdl-insert-keyword "REPORT ")
9930 (if (equal "\"\"" (vhdl-template-field
9931 "string expression" nil t start
(point) t
))
9933 (setq start
(point))
9934 (vhdl-insert-keyword " SEVERITY ")
9935 (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t
)
9936 (delete-region start
(point)))
9939 (defun vhdl-template-return ()
9940 "Insert a return statement."
9942 (let ((start (point)))
9943 (vhdl-insert-keyword "RETURN ")
9944 (unless (vhdl-template-field "[expression]" nil t start
(point))
9948 (defun vhdl-template-selected-signal-asst ()
9949 "Insert a selected signal assignment."
9951 (let ((margin (current-indentation))
9954 (let ((position (point)))
9955 (vhdl-insert-keyword " SELECT ")
9956 (goto-char position
))
9957 (vhdl-insert-keyword "WITH ")
9958 (when (vhdl-template-field "selector expression"
9959 nil t start
(+ (point) 7))
9963 (indent-to (+ margin vhdl-basic-offset
))
9964 (vhdl-template-field "target signal" " <= ")
9965 ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
9967 (indent-to (+ margin vhdl-basic-offset
))
9968 (vhdl-template-field "waveform")
9969 (vhdl-insert-keyword " WHEN ")
9970 (vhdl-template-field "choices" ",")
9972 (indent-to (+ margin vhdl-basic-offset
))
9973 (while (and choices
(vhdl-template-field "[waveform]" nil t
))
9974 (vhdl-insert-keyword " WHEN ")
9975 (if (setq choices
(vhdl-template-field "[choices]" "," t
))
9976 (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset
)))
9977 (vhdl-insert-keyword "OTHERS")))
9982 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1)))))
9984 (defun vhdl-template-signal ()
9985 "Insert a signal declaration."
9987 (let ((start (point))
9988 (in-arglist (vhdl-in-argument-list-p)))
9989 (vhdl-insert-keyword "SIGNAL ")
9990 (when (vhdl-template-field "names" nil t start
(point))
9992 (when in-arglist
(vhdl-template-field "[IN | OUT | INOUT]" " " t
))
9993 (vhdl-template-field "type")
9996 (vhdl-comment-insert-inline))
9997 (let ((position (point)))
9999 (unless (vhdl-template-field "[initialization]" nil t
)
10000 (delete-region position
(point)))
10002 (vhdl-comment-insert-inline))))))
10004 (defun vhdl-template-subnature ()
10005 "Insert a subnature declaration."
10007 (let ((start (point))
10009 (vhdl-insert-keyword "SUBNATURE ")
10010 (when (vhdl-template-field "name" nil t start
(point))
10011 (vhdl-insert-keyword " IS ")
10012 (vhdl-template-field "nature" " (")
10013 (if (vhdl-template-field "[index range]" nil t
)
10016 (setq position
(point))
10017 (vhdl-insert-keyword " TOLERANCE ")
10018 (if (equal "\"\"" (vhdl-template-field "[string expression]"
10020 (delete-region position
(point))
10021 (vhdl-insert-keyword " ACROSS ")
10022 (vhdl-template-field "string expression" nil nil nil nil t
)
10023 (vhdl-insert-keyword " THROUGH"))
10025 (vhdl-comment-insert-inline))))
10027 (defun vhdl-template-subprogram-body ()
10028 "Insert a subprogram body."
10030 (if (eq (vhdl-decision-query nil
"(p)rocedure or (f)unction?" t
) ?f
)
10031 (vhdl-template-function-body)
10032 (vhdl-template-procedure-body)))
10034 (defun vhdl-template-subprogram-decl ()
10035 "Insert a subprogram declaration."
10037 (if (eq (vhdl-decision-query nil
"(p)rocedure or (f)unction?" t
) ?f
)
10038 (vhdl-template-function-decl)
10039 (vhdl-template-procedure-decl)))
10041 (defun vhdl-template-subtype ()
10042 "Insert a subtype declaration."
10044 (let ((start (point)))
10045 (vhdl-insert-keyword "SUBTYPE ")
10046 (when (vhdl-template-field "name" nil t start
(point))
10047 (vhdl-insert-keyword " IS ")
10048 (vhdl-template-field "type" " ")
10050 (vhdl-template-field "[RANGE value range | ( index range )]" nil t
)
10053 (vhdl-comment-insert-inline))))
10055 (defun vhdl-template-terminal ()
10056 "Insert a terminal declaration."
10058 (let ((start (point)))
10059 (vhdl-insert-keyword "TERMINAL ")
10060 (when (vhdl-template-field "names" nil t start
(point))
10062 (vhdl-template-field "nature")
10064 (vhdl-comment-insert-inline))))
10066 (defun vhdl-template-type ()
10067 "Insert a type declaration."
10069 (let ((start (point))
10070 name mid-pos end-pos
)
10071 (vhdl-insert-keyword "TYPE ")
10072 (when (setq name
(vhdl-template-field "name" nil t start
(point)))
10073 (vhdl-insert-keyword " IS ")
10076 (or (vhdl-template-field
10077 "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t
)
10079 (cond ((equal definition
"")
10082 ((equal definition
"ARRAY")
10083 (delete-region (point) (progn (forward-word -
1) (point)))
10084 (vhdl-template-array 'type t
))
10085 ((equal definition
"RECORD")
10086 (setq mid-pos
(point-marker))
10087 (delete-region (point) (progn (forward-word -
1) (point)))
10088 (vhdl-template-record 'type name t
))
10089 ((equal definition
"ACCESS")
10091 (vhdl-template-field "type" ";"))
10092 ((equal definition
"FILE")
10093 (vhdl-insert-keyword " OF ")
10094 (vhdl-template-field "type" ";"))
10095 ((equal definition
"ENUM")
10098 (setq end-pos
(point-marker))
10102 (setq end-pos
(point-marker))
10103 (goto-char mid-pos
)
10105 (vhdl-comment-insert-inline)
10106 (when end-pos
(goto-char end-pos
))))))
10108 (defun vhdl-template-use ()
10109 "Insert a use clause."
10111 (let ((start (point)))
10112 (vhdl-prepare-search-1
10113 (vhdl-insert-keyword "USE ")
10114 (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
10115 (vhdl-insert-keyword "..ALL;")
10117 (when (vhdl-template-field "library name" nil t start
(+ (point) 6))
10119 (vhdl-template-field "package name")
10120 (forward-char 5))))))
10122 (defun vhdl-template-variable ()
10123 "Insert a variable declaration."
10125 (let ((start (point))
10126 (in-arglist (vhdl-in-argument-list-p)))
10127 (vhdl-prepare-search-2
10128 (if (or (save-excursion
10129 (progn (vhdl-beginning-of-block)
10130 (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
10131 (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
10132 (vhdl-insert-keyword "VARIABLE ")
10133 (if (vhdl-standard-p '87)
10134 (error "ERROR: Not within sequential block")
10135 (vhdl-insert-keyword "SHARED VARIABLE "))))
10136 (when (vhdl-template-field "names" nil t start
(point))
10138 (when in-arglist
(vhdl-template-field "[IN | OUT | INOUT]" " " t
))
10139 (vhdl-template-field "type")
10141 (progn (insert ";")
10142 (vhdl-comment-insert-inline))
10143 (let ((position (point)))
10145 (unless (vhdl-template-field "[initialization]" nil t
)
10146 (delete-region position
(point)))
10148 (vhdl-comment-insert-inline))))))
10150 (defun vhdl-template-wait ()
10151 "Insert a wait statement."
10153 (vhdl-insert-keyword "WAIT ")
10154 (unless (vhdl-template-field
10155 "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
10160 (defun vhdl-template-when ()
10161 "Indent correctly if within a case statement."
10163 (let ((position (point))
10165 (vhdl-prepare-search-2
10166 (if (and (= (current-column) (current-indentation))
10167 (vhdl-re-search-forward "\\<end\\>" nil t
)
10168 (looking-at "\\s-*\\<case\\>"))
10170 (setq margin
(current-indentation))
10171 (goto-char position
)
10172 (delete-horizontal-space)
10173 (indent-to (+ margin vhdl-basic-offset
)))
10174 (goto-char position
)))
10175 (vhdl-insert-keyword "WHEN ")))
10177 (defun vhdl-template-while-loop ()
10178 "Insert a while loop."
10180 (let* ((margin (current-indentation))
10183 (if (not (eq vhdl-optional-labels
'all
))
10184 (vhdl-insert-keyword "WHILE ")
10185 (vhdl-insert-keyword ": WHILE ")
10187 (setq label
(vhdl-template-field "[label]" nil t
))
10188 (unless label
(delete-char 2))
10191 (when vhdl-conditions-in-parenthesis
(insert "("))
10192 (when (vhdl-template-field "condition" nil t start
(point))
10193 (when vhdl-conditions-in-parenthesis
(insert ")"))
10194 (vhdl-insert-keyword " LOOP\n\n")
10196 (vhdl-insert-keyword "END LOOP")
10197 (insert (if label
(concat " " label
";") ";"))
10199 (indent-to (+ margin vhdl-basic-offset
)))))
10201 (defun vhdl-template-with ()
10202 "Insert a with statement (i.e. selected signal assignment)."
10204 (vhdl-prepare-search-1
10205 (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
10206 (equal ";" (match-string 1)))
10207 (vhdl-template-selected-signal-asst)
10208 (vhdl-insert-keyword "WITH "))))
10210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10211 ;; Special templates
10213 (defun vhdl-template-clocked-wait ()
10214 "Insert a wait statement for rising/falling clock edge."
10216 (let ((start (point))
10218 (vhdl-insert-keyword "WAIT UNTIL ")
10220 (or (and (not (equal "" vhdl-clock-name
))
10221 (progn (insert vhdl-clock-name
) vhdl-clock-name
))
10222 (vhdl-template-field "clock name" nil t start
(point))))
10224 (vhdl-insert-keyword " AND ")
10227 " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string
) ";")
10228 (vhdl-comment-insert-inline
10229 (concat (if vhdl-clock-rising-edge
"rising" "falling")
10232 (defun vhdl-template-seq-process (clock reset reset-kind
)
10233 "Insert a template for the body of a sequential process."
10234 (let ((margin (current-indentation))
10236 (vhdl-insert-keyword "IF ")
10237 (when vhdl-conditions-in-parenthesis
(insert "("))
10238 (when (eq reset-kind
'async
)
10239 (insert reset
" = "
10240 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string
))
10241 (when vhdl-conditions-in-parenthesis
(insert ")"))
10242 (vhdl-insert-keyword " THEN")
10243 (vhdl-comment-insert-inline
10244 (concat "asynchronous reset (active "
10245 (if vhdl-reset-active-high
"high" "low") ")"))
10246 (insert "\n") (indent-to (+ margin vhdl-basic-offset
))
10247 (setq position
(point))
10248 (insert "\n") (indent-to margin
)
10249 (vhdl-insert-keyword "ELSIF ")
10250 (when vhdl-conditions-in-parenthesis
(insert "(")))
10251 (if (eq vhdl-clock-edge-condition
'function
)
10252 (insert (if vhdl-clock-rising-edge
"rising" "falling")
10253 "_edge(" clock
")")
10254 (insert clock
"'event")
10255 (vhdl-insert-keyword " AND ")
10256 (insert clock
" = "
10257 (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string
)))
10258 (when vhdl-conditions-in-parenthesis
(insert ")"))
10259 (vhdl-insert-keyword " THEN")
10260 (vhdl-comment-insert-inline
10261 (concat (if vhdl-clock-rising-edge
"rising" "falling") " clock edge"))
10262 (insert "\n") (indent-to (+ margin vhdl-basic-offset
))
10263 (when (eq reset-kind
'sync
)
10264 (vhdl-insert-keyword "IF ")
10265 (when vhdl-conditions-in-parenthesis
(insert "("))
10266 (setq reset
(or (and (not (equal "" vhdl-reset-name
))
10267 (progn (insert vhdl-reset-name
) vhdl-reset-name
))
10268 (vhdl-template-field "reset name") "<reset>"))
10270 (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string
))
10271 (when vhdl-conditions-in-parenthesis
(insert ")"))
10272 (vhdl-insert-keyword " THEN")
10273 (vhdl-comment-insert-inline
10274 (concat "synchronous reset (active "
10275 (if vhdl-reset-active-high
"high" "low") ")"))
10276 (insert "\n") (indent-to (+ margin
(* 2 vhdl-basic-offset
)))
10277 (setq position
(point))
10278 (insert "\n") (indent-to (+ margin vhdl-basic-offset
))
10279 (vhdl-insert-keyword "ELSE")
10280 (insert "\n") (indent-to (+ margin
(* 2 vhdl-basic-offset
)))
10281 (insert "\n") (indent-to (+ margin vhdl-basic-offset
))
10282 (vhdl-insert-keyword "END IF;"))
10283 (when (eq reset-kind
'none
)
10284 (setq position
(point)))
10285 (insert "\n") (indent-to margin
)
10286 (vhdl-insert-keyword "END IF;")
10287 (goto-char position
)
10290 (defun vhdl-template-standard-package (library package
)
10291 "Insert specification of a standard package. Include a library
10292 specification, if not already there."
10293 (let ((margin (current-indentation)))
10294 (unless (equal library
"std")
10295 (unless (or (save-excursion
10296 (vhdl-prepare-search-1
10298 (re-search-backward
10299 (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
10300 library
"\\|end\\)\\>") nil t
)
10301 (match-string 2))))
10302 (equal (downcase library
) "work"))
10303 (vhdl-insert-keyword "LIBRARY ")
10304 (insert library
";")
10307 (indent-to margin
))))
10309 (vhdl-insert-keyword "USE ")
10310 (insert library
"." package
)
10311 (vhdl-insert-keyword ".ALL;"))))
10313 (defun vhdl-template-package-numeric-bit ()
10314 "Insert specification of `numeric_bit' package."
10316 (vhdl-template-standard-package "ieee" "numeric_bit"))
10318 (defun vhdl-template-package-numeric-std ()
10319 "Insert specification of `numeric_std' package."
10321 (vhdl-template-standard-package "ieee" "numeric_std"))
10323 (defun vhdl-template-package-std-logic-1164 ()
10324 "Insert specification of `std_logic_1164' package."
10326 (vhdl-template-standard-package "ieee" "std_logic_1164"))
10328 (defun vhdl-template-package-std-logic-arith ()
10329 "Insert specification of `std_logic_arith' package."
10331 (vhdl-template-standard-package "ieee" "std_logic_arith"))
10333 (defun vhdl-template-package-std-logic-misc ()
10334 "Insert specification of `std_logic_misc' package."
10336 (vhdl-template-standard-package "ieee" "std_logic_misc"))
10338 (defun vhdl-template-package-std-logic-signed ()
10339 "Insert specification of `std_logic_signed' package."
10341 (vhdl-template-standard-package "ieee" "std_logic_signed"))
10343 (defun vhdl-template-package-std-logic-textio ()
10344 "Insert specification of `std_logic_textio' package."
10346 (vhdl-template-standard-package "ieee" "std_logic_textio"))
10348 (defun vhdl-template-package-std-logic-unsigned ()
10349 "Insert specification of `std_logic_unsigned' package."
10351 (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
10353 (defun vhdl-template-package-textio ()
10354 "Insert specification of `textio' package."
10356 (vhdl-template-standard-package "std" "textio"))
10358 (defun vhdl-template-package-fundamental-constants ()
10359 "Insert specification of `fundamental_constants' package."
10361 (vhdl-template-standard-package "ieee" "fundamental_constants"))
10363 (defun vhdl-template-package-material-constants ()
10364 "Insert specification of `material_constants' package."
10366 (vhdl-template-standard-package "ieee" "material_constants"))
10368 (defun vhdl-template-package-energy-systems ()
10369 "Insert specification of `energy_systems' package."
10371 (vhdl-template-standard-package "ieee" "energy_systems"))
10373 (defun vhdl-template-package-electrical-systems ()
10374 "Insert specification of `electrical_systems' package."
10376 (vhdl-template-standard-package "ieee" "electrical_systems"))
10378 (defun vhdl-template-package-mechanical-systems ()
10379 "Insert specification of `mechanical_systems' package."
10381 (vhdl-template-standard-package "ieee" "mechanical_systems"))
10383 (defun vhdl-template-package-radiant-systems ()
10384 "Insert specification of `radiant_systems' package."
10386 (vhdl-template-standard-package "ieee" "radiant_systems"))
10388 (defun vhdl-template-package-thermal-systems ()
10389 "Insert specification of `thermal_systems' package."
10391 (vhdl-template-standard-package "ieee" "thermal_systems"))
10393 (defun vhdl-template-package-fluidic-systems ()
10394 "Insert specification of `fluidic_systems' package."
10396 (vhdl-template-standard-package "ieee" "fluidic_systems"))
10398 (defun vhdl-template-package-math-complex ()
10399 "Insert specification of `math_complex' package."
10401 (vhdl-template-standard-package "ieee" "math_complex"))
10403 (defun vhdl-template-package-math-real ()
10404 "Insert specification of `math_real' package."
10406 (vhdl-template-standard-package "ieee" "math_real"))
10408 (defun vhdl-template-directive (directive)
10409 "Insert directive."
10410 (unless (= (current-indentation) (current-column))
10411 (delete-horizontal-space)
10413 (insert "-- pragma " directive
))
10415 (defun vhdl-template-directive-translate-on ()
10416 "Insert directive 'translate_on'."
10418 (vhdl-template-directive "translate_on"))
10420 (defun vhdl-template-directive-translate-off ()
10421 "Insert directive 'translate_off'."
10423 (vhdl-template-directive "translate_off"))
10425 (defun vhdl-template-directive-synthesis-on ()
10426 "Insert directive 'synthesis_on'."
10428 (vhdl-template-directive "synthesis_on"))
10430 (defun vhdl-template-directive-synthesis-off ()
10431 "Insert directive 'synthesis_off'."
10433 (vhdl-template-directive "synthesis_off"))
10435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10436 ;; Header and footer templates
10438 (defun vhdl-template-header (&optional file-title
)
10439 "Insert a VHDL file header."
10441 (unless (equal vhdl-file-header
"")
10444 (goto-char (point-min))
10445 (vhdl-insert-string-or-file vhdl-file-header
)
10446 (setq pos
(point-marker)))
10447 (vhdl-template-replace-header-keywords
10448 (point-min-marker) pos file-title
))))
10450 (defun vhdl-template-footer ()
10451 "Insert a VHDL file footer."
10453 (unless (equal vhdl-file-footer
"")
10456 (goto-char (point-max))
10457 (setq pos
(point-marker))
10458 (vhdl-insert-string-or-file vhdl-file-footer
)
10459 (unless (= (preceding-char) ?
\n)
10461 (vhdl-template-replace-header-keywords pos
(point-max-marker)))))
10463 (defun vhdl-template-replace-header-keywords (beg end
&optional file-title
10465 "Replace keywords in header and footer."
10466 (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project
)) ""))
10467 (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project
)) ""))
10469 (vhdl-prepare-search-2
10472 (while (search-forward "<projectdesc>" end t
)
10473 (replace-match project-desc t t
))
10475 (while (search-forward "<filename>" end t
)
10476 (replace-match (buffer-name) t t
))
10478 (while (search-forward "<copyright>" end t
)
10479 (replace-match vhdl-copyright-string t t
))
10481 (while (search-forward "<author>" end t
)
10482 (replace-match "" t t
)
10483 (insert (user-full-name))
10484 (when user-mail-address
(insert " <" user-mail-address
">")))
10486 (while (search-forward "<authorfull>" end t
)
10487 (replace-match (user-full-name) t t
))
10489 (while (search-forward "<login>" end t
)
10490 (replace-match (user-login-name) t t
))
10492 (while (search-forward "<project>" end t
)
10493 (replace-match project-title t t
))
10495 (while (search-forward "<company>" end t
)
10496 (replace-match vhdl-company-name t t
))
10498 (while (search-forward "<platform>" end t
)
10499 (replace-match vhdl-platform-spec t t
))
10501 (while (search-forward "<standard>" end t
)
10503 (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
10504 ((vhdl-standard-p '93) "'93/02"))
10505 (when (vhdl-standard-p 'ams
) ", VHDL-AMS")
10506 (when (vhdl-standard-p 'math
) ", Math Packages")) t t
))
10508 ;; Replace <RCS> with $, so that RCS for the source is
10509 ;; not over-enthusiastic with replacements
10510 (while (search-forward "<RCS>" end t
)
10511 (replace-match "$" nil t
))
10513 (while (search-forward "<date>" end t
)
10514 (replace-match "" t t
)
10515 (vhdl-template-insert-date))
10517 (while (search-forward "<year>" end t
)
10518 (replace-match (format-time-string "%Y" nil
) t t
))
10521 (while (search-forward "<title string>" end t
)
10522 (replace-match file-title t t
))
10526 (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t
)
10527 (setq string
(read-string (concat (match-string 1) ": ")))
10528 (replace-match string t t
)))
10530 (when (and (not is-model
) (search-forward "<cursor>" end t
))
10531 (replace-match "" t t
)
10532 (setq pos
(point))))
10533 (when pos
(goto-char pos
))
10535 (when (or (not project-title
) (equal project-title
""))
10536 (message "You can specify a project title in user option `vhdl-project-alist'"))
10537 (when (or (not project-desc
) (equal project-desc
""))
10538 (message "You can specify a project description in user option `vhdl-project-alist'"))
10539 (when (equal vhdl-platform-spec
"")
10540 (message "You can specify a platform in user option `vhdl-platform-spec'"))
10541 (when (equal vhdl-company-name
"")
10542 (message "You can specify a company name in user option `vhdl-company-name'"))))))
10544 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10545 ;; Comment templates and functions
10547 (defun vhdl-comment-indent ()
10549 (let* ((position (point))
10553 (if (re-search-forward "--" position t
)
10554 (- (current-column) 2) ; existing comment at bol stays there
10555 (goto-char position
)
10556 (skip-chars-backward " \t")
10557 (max comment-column
; else indent to comment column
10558 (1+ (current-column))))))) ; except leave at least one space
10559 (goto-char position
)
10562 (defun vhdl-comment-insert ()
10563 "Start a comment at the end of the line.
10564 If on line with code, indent at least `comment-column'.
10565 If starting after end-comment-column, start a new line."
10567 (when (> (current-column) end-comment-column
) (newline-and-indent))
10568 (if (or (looking-at "\\s-*$") ; end of line
10569 (and (not unread-command-events
) ; called with key binding or menu
10570 (not (end-of-line))))
10572 (while (= (preceding-char) ?-
) (delete-char -
1))
10573 (setq margin
(current-column))
10574 (delete-horizontal-space)
10576 (progn (indent-to margin
) (insert "--"))
10578 (indent-to comment-column
)
10580 (if (not unread-command-events
) (insert " ")))
10581 ;; else code following current point implies commenting out code
10582 (let (next-input code
)
10583 (while (= (preceding-char) ?-
) (delete-char -
2))
10584 (while (= (setq next-input
(read-char)) 13) ; CR
10585 (insert "--") ; or have a space after it?
10588 (message "Enter CR if commenting out a line of code.")
10591 (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
10592 (setq unread-command-events
10593 (list (vhdl-character-to-event next-input
)))))) ; pushback the char
10595 (defun vhdl-comment-display (&optional line-exists
)
10596 "Add 2 comment lines at the current indent, making a display comment."
10598 (let ((margin (current-indentation)))
10599 (unless line-exists
(vhdl-comment-display-line))
10600 (insert "\n") (indent-to margin
)
10601 (insert "\n") (indent-to margin
)
10602 (vhdl-comment-display-line)
10606 (defun vhdl-comment-display-line ()
10607 "Displays one line of dashes."
10609 (while (= (preceding-char) ?-
) (delete-char -
2))
10611 (let* ((col (current-column))
10612 (len (- end-comment-column col
)))
10613 (insert-char vhdl-comment-display-line-char len
)))
10615 (defun vhdl-comment-append-inline ()
10616 "Append empty inline comment to current line."
10619 (delete-horizontal-space)
10621 (indent-to comment-column
)
10624 (defun vhdl-comment-insert-inline (&optional string always-insert
)
10625 "Insert inline comment."
10626 (when (or (and string
(or vhdl-self-insert-comments always-insert
))
10627 (and (not string
) vhdl-prompt-for-comments
))
10628 (let ((position (point)))
10630 (indent-to comment-column
)
10632 (if (not (or (and string
(progn (insert string
) t
))
10633 (vhdl-template-field "[comment]" nil t
)))
10634 (delete-region position
(point))
10635 (while (= (preceding-char) ?\
) (delete-char -
1))
10636 ;; (when (> (current-column) end-comment-column)
10637 ;; (setq position (point-marker))
10638 ;; (re-search-backward "-- ")
10640 ;; (indent-to comment-column)
10641 ;; (goto-char position))
10644 (defun vhdl-comment-block ()
10645 "Insert comment for code block."
10646 (when vhdl-prompt-for-comments
10647 (let ((final-pos (point-marker)))
10648 (vhdl-prepare-search-2
10649 (when (and (re-search-backward "^\\s-*begin\\>" nil t
)
10650 (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t
))
10652 (back-to-indentation)
10653 (setq margin
(current-column))
10656 (progn (insert "\n") (forward-line -
1))
10659 (insert "-- purpose: ")
10660 (unless (vhdl-template-field "[description]" nil t
)
10661 (vhdl-line-kill-entire)))))
10662 (goto-char final-pos
))))
10664 (defun vhdl-comment-uncomment-region (beg end
&optional arg
)
10665 "Comment out region if not commented out, uncomment otherwise."
10666 (interactive "r\nP")
10668 (goto-char (1- end
))
10670 (setq end
(point-marker))
10672 (beginning-of-line)
10674 (if (looking-at (concat "\\s-*" comment-start
))
10675 (comment-region beg end
'(4))
10676 (comment-region beg end
))))
10678 (defun vhdl-comment-uncomment-line (&optional arg
)
10679 "Comment out line if not commented out, uncomment otherwise."
10682 (beginning-of-line)
10683 (let ((position (point)))
10684 (forward-line (or arg
1))
10685 (vhdl-comment-uncomment-region position
(point)))))
10687 (defun vhdl-comment-kill-region (beg end
)
10688 "Kill comments in region."
10692 (setq end
(point-marker))
10694 (beginning-of-line)
10695 (while (< (point) end
)
10696 (if (looking-at "^\\(\\s-*--.*\n\\)")
10697 (progn (delete-region (match-beginning 1) (match-end 1)))
10698 (beginning-of-line 2)))))
10700 (defun vhdl-comment-kill-inline-region (beg end
)
10701 "Kill inline comments in region."
10705 (setq end
(point-marker))
10707 (beginning-of-line)
10708 (while (< (point) end
)
10709 (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
10710 (delete-region (match-beginning 1) (match-end 1)))
10711 (beginning-of-line 2))))
10713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10716 (defun vhdl-template-begin-end (construct name margin
&optional empty-lines
)
10717 "Insert a begin ... end pair with optional name after the end.
10718 Point is left between them."
10720 (when (or empty-lines
(eq vhdl-insert-empty-lines
'all
)) (insert "\n"))
10722 (vhdl-insert-keyword "BEGIN")
10723 (when (and (or construct name
) vhdl-self-insert-comments
)
10725 (when construct
(insert " ") (vhdl-insert-keyword construct
))
10726 (when name
(insert " " name
)))
10728 (when (or empty-lines
(eq vhdl-insert-empty-lines
'all
)) (insert "\n"))
10729 (indent-to (+ margin vhdl-basic-offset
))
10730 (setq position
(point))
10732 (when (or empty-lines
(eq vhdl-insert-empty-lines
'all
)) (insert "\n"))
10734 (vhdl-insert-keyword "END")
10735 (when construct
(insert " ") (vhdl-insert-keyword construct
))
10736 (insert (if name
(concat " " name
) "") ";")
10737 (goto-char position
)))
10739 (defun vhdl-template-argument-list (&optional is-function
)
10740 "Read from user a procedure or function argument list."
10742 (let ((margin (current-column))
10745 not-empty interface semicolon-pos
)
10746 (unless vhdl-argument-list-indent
10747 (setq margin
(+ (current-indentation) vhdl-basic-offset
))
10749 (indent-to margin
))
10750 (setq interface
(vhdl-template-field
10751 (concat "[CONSTANT | SIGNAL"
10752 (unless is-function
" | VARIABLE") "]") " " t
))
10753 (while (vhdl-template-field "[names]" nil t
)
10756 (unless is-function
10757 (if (and interface
(equal (upcase interface
) "CONSTANT"))
10758 (vhdl-insert-keyword "IN ")
10759 (vhdl-template-field "[IN | OUT | INOUT]" " " t
)))
10760 (vhdl-template-field "type")
10761 (setq semicolon-pos
(point))
10763 (vhdl-comment-insert-inline)
10764 (setq end-pos
(point))
10767 (setq interface
(vhdl-template-field
10768 (concat "[CONSTANT | SIGNAL"
10769 (unless is-function
" | VARIABLE") "]") " " t
)))
10770 (delete-region end-pos
(point))
10771 (when semicolon-pos
(goto-char semicolon-pos
))
10773 (progn (delete-char 1) (insert ")"))
10774 (delete-char -
2))))
10776 (defun vhdl-template-generic-list (optional &optional no-value
)
10777 "Read from user a generic spec argument list."
10780 (vhdl-insert-keyword "GENERIC (")
10781 (setq margin
(current-column))
10782 (unless vhdl-argument-list-indent
10783 (let ((position (point)))
10784 (back-to-indentation)
10785 (setq margin
(+ (current-column) vhdl-basic-offset
))
10786 (goto-char position
)
10788 (indent-to margin
)))
10789 (let ((vhdl-generics (vhdl-template-field
10790 (concat (and optional
"[") "name"
10791 (and no-value
"s") (and optional
"]"))
10793 (if (not vhdl-generics
)
10795 (progn (vhdl-line-kill-entire) (end-of-line -
0)
10796 (unless vhdl-argument-list-indent
10797 (vhdl-line-kill-entire) (end-of-line -
0)))
10798 (vhdl-template-undo start
(point))
10801 (let (semicolon-pos end-pos
)
10802 (while vhdl-generics
10803 (vhdl-template-field "type")
10805 (progn (setq semicolon-pos
(point))
10808 (unless (vhdl-template-field "[value]" nil t
)
10810 (setq semicolon-pos
(point))
10812 (vhdl-comment-insert-inline)
10813 (setq end-pos
(point))
10816 (setq vhdl-generics
(vhdl-template-field
10817 (concat "[name" (and no-value
"s") "]")
10819 (delete-region end-pos
(point))
10820 (goto-char semicolon-pos
)
10823 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1))
10826 (defun vhdl-template-port-list (optional)
10827 "Read from user a port spec argument list."
10828 (let ((start (point))
10829 margin vhdl-ports object
)
10830 (vhdl-insert-keyword "PORT (")
10831 (setq margin
(current-column))
10832 (unless vhdl-argument-list-indent
10833 (let ((position (point)))
10834 (back-to-indentation)
10835 (setq margin
(+ (current-column) vhdl-basic-offset
))
10836 (goto-char position
)
10838 (indent-to margin
)))
10839 (when (vhdl-standard-p 'ams
)
10840 (setq object
(vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10842 (setq vhdl-ports
(vhdl-template-field
10843 (concat (and optional
"[") "names" (and optional
"]"))
10845 (if (not vhdl-ports
)
10847 (progn (vhdl-line-kill-entire) (end-of-line -
0)
10848 (unless vhdl-argument-list-indent
10849 (vhdl-line-kill-entire) (end-of-line -
0)))
10850 (vhdl-template-undo start
(point))
10853 (let (semicolon-pos end-pos
)
10855 (cond ((or (null object
) (equal "SIGNAL" (upcase object
)))
10856 (vhdl-template-field "IN | OUT | INOUT" " "))
10857 ((equal "QUANTITY" (upcase object
))
10858 (vhdl-template-field "[IN | OUT]" " " t
)))
10859 (vhdl-template-field
10860 (if (and object
(equal "TERMINAL" (upcase object
)))
10862 (setq semicolon-pos
(point))
10864 (vhdl-comment-insert-inline)
10865 (setq end-pos
(point))
10868 (when (vhdl-standard-p 'ams
)
10869 (setq object
(vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
10871 (setq vhdl-ports
(vhdl-template-field "[names]" " : " t
)))
10872 (delete-region end-pos
(point))
10873 (goto-char semicolon-pos
)
10876 (when vhdl-auto-align
(vhdl-align-region-groups start end-pos
1))
10879 (defun vhdl-template-generate-body (margin label
)
10880 "Insert body for generate template."
10881 (vhdl-insert-keyword " GENERATE")
10882 ; (if (not (vhdl-standard-p '87))
10883 ; (vhdl-template-begin-end "GENERATE" label margin)
10886 (vhdl-insert-keyword "END GENERATE ")
10889 (indent-to (+ margin vhdl-basic-offset
)))
10891 (defun vhdl-template-insert-date ()
10892 "Insert date in appropriate format."
10896 ;; 'american, 'european, 'scientific kept for backward compatibility
10897 ((eq vhdl-date-format
'american
) (format-time-string "%m/%d/%Y" nil
))
10898 ((eq vhdl-date-format
'european
) (format-time-string "%d.%m.%Y" nil
))
10899 ((eq vhdl-date-format
'scientific
) (format-time-string "%Y/%m/%d" nil
))
10900 (t (format-time-string vhdl-date-format nil
)))))
10902 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10905 (defun vhdl-electric-space (count)
10906 "Expand abbreviations and self-insert space(s), do indent-new-comment-line
10907 if in comment and past end-comment-column."
10909 (cond ((vhdl-in-comment-p)
10910 (self-insert-command count
)
10911 (cond ((>= (current-column) (+ 2 end-comment-column
))
10913 (skip-chars-backward "^ \t\n\r\f")
10914 (indent-new-comment-line)
10915 (skip-chars-forward "^ \t\n\r\f")
10917 ((>= (current-column) end-comment-column
)
10918 (indent-new-comment-line))
10920 ((or (and (>= (preceding-char) ?a
) (<= (preceding-char) ?z
))
10921 (and (>= (preceding-char) ?A
) (<= (preceding-char) ?Z
)))
10922 (vhdl-prepare-search-1
10923 (or (expand-abbrev) (vhdl-fix-case-word -
1)))
10924 (self-insert-command count
))
10925 (t (self-insert-command count
))))
10927 (defun vhdl-template-field (prompt &optional follow-string optional
10928 begin end is-string default
)
10929 "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
10930 If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
10931 an empty string is inserted, return nil and call `vhdl-template-undo' for
10932 the region between BEGIN and END. IS-STRING indicates whether a string
10933 with double-quotes is to be inserted. DEFAULT specifies a default string."
10934 (let ((position (point))
10936 (insert "<" prompt
">")
10939 (read-from-minibuffer (concat prompt
": ")
10940 (or (and is-string
'("\"\"" .
2)) default
)
10941 vhdl-minibuffer-local-map
)
10942 (quit (if (and optional begin end
)
10944 (keyboard-quit)))))
10945 (when (or (not (equal string
"")) optional
)
10946 (delete-region position
(point)))
10947 (when (and (equal string
"") optional begin end
)
10948 (vhdl-template-undo begin end
)
10949 (message "Template aborted"))
10950 (unless (equal string
"")
10952 (vhdl-fix-case-region-1 position
(point) vhdl-upper-case-keywords
10953 vhdl-keywords-regexp
)
10954 (vhdl-fix-case-region-1 position
(point) vhdl-upper-case-types
10956 (vhdl-fix-case-region-1 position
(point) vhdl-upper-case-attributes
10957 (concat "'" vhdl-attributes-regexp
))
10958 (vhdl-fix-case-region-1 position
(point) vhdl-upper-case-enum-values
10959 vhdl-enum-values-regexp
)
10960 (vhdl-fix-case-region-1 position
(point) vhdl-upper-case-constants
10961 vhdl-constants-regexp
))
10962 (when (or (not (equal string
"")) (not optional
))
10963 (insert (or follow-string
"")))
10964 (if (equal string
"") nil string
)))
10966 (defun vhdl-decision-query (string prompt
&optional optional
)
10967 "Query a decision from the user."
10968 (let ((start (point)))
10969 (when string
(vhdl-insert-keyword (concat string
" ")))
10970 (message "%s" (or prompt
""))
10971 (let ((char (read-char)))
10972 (delete-region start
(point))
10973 (if (and optional
(eq char ?
\r))
10974 (progn (insert " ")
10976 (throw 'abort
"ERROR: Template aborted"))
10979 (defun vhdl-insert-keyword (keyword)
10980 "Insert KEYWORD and adjust case."
10981 (insert (if vhdl-upper-case-keywords
(upcase keyword
) (downcase keyword
))))
10983 (defun vhdl-case-keyword (keyword)
10984 "Adjust case of KEYWORD."
10985 (if vhdl-upper-case-keywords
(upcase keyword
) (downcase keyword
)))
10987 (defun vhdl-case-word (num)
10988 "Adjust case of following NUM words."
10989 (if vhdl-upper-case-keywords
(upcase-word num
) (downcase-word num
)))
10991 (defun vhdl-minibuffer-tab (&optional prefix-arg
)
10992 "If preceding character is part of a word or a paren then hippie-expand,
10993 else insert tab (used for word completion in VHDL minibuffer)."
10997 ((= (char-syntax (preceding-char)) ?w
)
10998 (let ((case-fold-search (not vhdl-word-completion-case-sensitive
))
11000 (hippie-expand-only-buffers
11001 (or (and (boundp 'hippie-expand-only-buffers
)
11002 hippie-expand-only-buffers
)
11004 (vhdl-expand-abbrev prefix-arg
)))
11005 ;; expand parenthesis
11006 ((or (= (preceding-char) ?\
() (= (preceding-char) ?\
)))
11007 (let ((case-fold-search (not vhdl-word-completion-case-sensitive
))
11008 (case-replace nil
))
11009 (vhdl-expand-paren prefix-arg
)))
11013 (defun vhdl-template-search-prompt ()
11014 "Search for left out template prompts and query again."
11016 (vhdl-prepare-search-2
11017 (when (or (re-search-forward
11018 (concat "<\\(" vhdl-template-prompt-syntax
"\\)>") nil t
)
11019 (re-search-backward
11020 (concat "<\\(" vhdl-template-prompt-syntax
"\\)>") nil t
))
11021 (let ((string (match-string 1)))
11023 (vhdl-template-field string
)))))
11025 (defun vhdl-template-undo (begin end
)
11026 "Undo aborted template by deleting region and unexpanding the keyword."
11027 (cond (vhdl-template-invoked-by-hook
11030 (delete-region begin end
)
11032 (t (delete-region begin end
))))
11034 (defun vhdl-insert-string-or-file (string)
11035 "Insert STRING or file contents if STRING is an existing file name."
11036 (unless (equal string
"")
11038 (progn (string-match "^\\([^\n]+\\)" string
)
11039 (vhdl-resolve-env-variable (match-string 1 string
)))))
11040 (if (file-exists-p file-name
)
11041 (forward-char (cadr (insert-file-contents file-name
)))
11042 (insert string
)))))
11044 (defun vhdl-beginning-of-block ()
11045 "Move cursor to the beginning of the enclosing block."
11047 (vhdl-prepare-search-2
11049 (beginning-of-line)
11050 ;; search backward for block beginning or end
11051 (while (or (while (and (setq pos
(re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t
))
11052 ;; not consider subprogram declarations
11053 (or (and (match-string 5)
11056 (goto-char (match-end 5))
11058 (vhdl-forward-syntactic-ws)
11059 (when (looking-at "(")
11061 (re-search-forward "\\<is\\>\\|\\(;\\)" nil t
))
11063 ;; not consider configuration specifications
11064 (and (match-string 6)
11067 (vhdl-end-of-block)
11068 (beginning-of-line)
11069 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11071 ;; skip subblock if block end found
11072 (vhdl-beginning-of-block))))
11073 (when pos
(goto-char pos
))))
11075 (defun vhdl-end-of-block ()
11076 "Move cursor to the end of the enclosing block."
11078 (vhdl-prepare-search-2
11081 ;; search forward for block beginning or end
11082 (while (or (while (and (setq pos
(re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t
))
11083 ;; not consider subprogram declarations
11084 (or (and (match-string 5)
11086 (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t
))
11088 ;; not consider configuration specifications
11089 (and (match-string 6)
11092 (vhdl-end-of-block)
11093 (beginning-of-line)
11094 (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
11095 (not (match-string 2)))
11096 ;; skip subblock if block beginning found
11097 (vhdl-end-of-block))))
11098 (when pos
(goto-char pos
))))
11100 (defun vhdl-sequential-statement-p ()
11101 "Check if point is within sequential statement part."
11102 (let ((start (point)))
11104 (vhdl-prepare-search-2
11105 ;; is sequential statement if ...
11106 (and (re-search-backward "^\\s-*begin\\>" nil t
)
11107 ;; ... point is between "begin" and "end" of ...
11108 (progn (vhdl-end-of-block)
11110 ;; ... a sequential block
11111 (progn (vhdl-beginning-of-block)
11112 (looking-at "^\\s-*\\(\\(\\w+[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(\\w+[ \t\n\r\f]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
11114 (defun vhdl-in-argument-list-p ()
11115 "Check if within an argument list."
11117 (vhdl-prepare-search-2
11118 (or (string-match "arglist"
11119 (format "%s" (caar (vhdl-get-syntactic-context))))
11120 (progn (beginning-of-line)
11121 (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
11123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11126 (defun vhdl-hooked-abbrev (func)
11127 "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
11128 but not if inside a comment or quote."
11129 (if (or (vhdl-in-literal)
11132 (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
11139 (if (not vhdl-electric-mode
)
11146 (let ((invoke-char vhdl-last-input-event
)
11148 (vhdl-template-invoked-by-hook t
))
11149 (let ((caught (catch 'abort
11151 (when (stringp caught
) (message "%s" caught
)))
11152 (when (= invoke-char ?-
) (setq abbrev-start-location
(point)))
11153 ;; delete CR which is still in event queue
11154 (if (fboundp 'enqueue-eval-event
)
11155 (enqueue-eval-event 'delete-char -
1)
11156 (setq unread-command-events
; push back a delete char
11157 (list (vhdl-character-to-event ?
\177))))))))
11159 (defun vhdl-template-alias-hook ()
11160 (vhdl-hooked-abbrev 'vhdl-template-alias
))
11161 (defun vhdl-template-architecture-hook ()
11162 (vhdl-hooked-abbrev 'vhdl-template-architecture
))
11163 (defun vhdl-template-assert-hook ()
11164 (vhdl-hooked-abbrev 'vhdl-template-assert
))
11165 (defun vhdl-template-attribute-hook ()
11166 (vhdl-hooked-abbrev 'vhdl-template-attribute
))
11167 (defun vhdl-template-block-hook ()
11168 (vhdl-hooked-abbrev 'vhdl-template-block
))
11169 (defun vhdl-template-break-hook ()
11170 (vhdl-hooked-abbrev 'vhdl-template-break
))
11171 (defun vhdl-template-case-hook ()
11172 (vhdl-hooked-abbrev 'vhdl-template-case
))
11173 (defun vhdl-template-component-hook ()
11174 (vhdl-hooked-abbrev 'vhdl-template-component
))
11175 (defun vhdl-template-instance-hook ()
11176 (vhdl-hooked-abbrev 'vhdl-template-instance
))
11177 (defun vhdl-template-conditional-signal-asst-hook ()
11178 (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst
))
11179 (defun vhdl-template-configuration-hook ()
11180 (vhdl-hooked-abbrev 'vhdl-template-configuration
))
11181 (defun vhdl-template-constant-hook ()
11182 (vhdl-hooked-abbrev 'vhdl-template-constant
))
11183 (defun vhdl-template-disconnect-hook ()
11184 (vhdl-hooked-abbrev 'vhdl-template-disconnect
))
11185 (defun vhdl-template-display-comment-hook ()
11186 (vhdl-hooked-abbrev 'vhdl-comment-display
))
11187 (defun vhdl-template-else-hook ()
11188 (vhdl-hooked-abbrev 'vhdl-template-else
))
11189 (defun vhdl-template-elsif-hook ()
11190 (vhdl-hooked-abbrev 'vhdl-template-elsif
))
11191 (defun vhdl-template-entity-hook ()
11192 (vhdl-hooked-abbrev 'vhdl-template-entity
))
11193 (defun vhdl-template-exit-hook ()
11194 (vhdl-hooked-abbrev 'vhdl-template-exit
))
11195 (defun vhdl-template-file-hook ()
11196 (vhdl-hooked-abbrev 'vhdl-template-file
))
11197 (defun vhdl-template-for-hook ()
11198 (vhdl-hooked-abbrev 'vhdl-template-for
))
11199 (defun vhdl-template-function-hook ()
11200 (vhdl-hooked-abbrev 'vhdl-template-function
))
11201 (defun vhdl-template-generic-hook ()
11202 (vhdl-hooked-abbrev 'vhdl-template-generic
))
11203 (defun vhdl-template-group-hook ()
11204 (vhdl-hooked-abbrev 'vhdl-template-group
))
11205 (defun vhdl-template-library-hook ()
11206 (vhdl-hooked-abbrev 'vhdl-template-library
))
11207 (defun vhdl-template-limit-hook ()
11208 (vhdl-hooked-abbrev 'vhdl-template-limit
))
11209 (defun vhdl-template-if-hook ()
11210 (vhdl-hooked-abbrev 'vhdl-template-if
))
11211 (defun vhdl-template-bare-loop-hook ()
11212 (vhdl-hooked-abbrev 'vhdl-template-bare-loop
))
11213 (defun vhdl-template-map-hook ()
11214 (vhdl-hooked-abbrev 'vhdl-template-map
))
11215 (defun vhdl-template-nature-hook ()
11216 (vhdl-hooked-abbrev 'vhdl-template-nature
))
11217 (defun vhdl-template-next-hook ()
11218 (vhdl-hooked-abbrev 'vhdl-template-next
))
11219 (defun vhdl-template-others-hook ()
11220 (vhdl-hooked-abbrev 'vhdl-template-others
))
11221 (defun vhdl-template-package-hook ()
11222 (vhdl-hooked-abbrev 'vhdl-template-package
))
11223 (defun vhdl-template-port-hook ()
11224 (vhdl-hooked-abbrev 'vhdl-template-port
))
11225 (defun vhdl-template-procedural-hook ()
11226 (vhdl-hooked-abbrev 'vhdl-template-procedural
))
11227 (defun vhdl-template-procedure-hook ()
11228 (vhdl-hooked-abbrev 'vhdl-template-procedure
))
11229 (defun vhdl-template-process-hook ()
11230 (vhdl-hooked-abbrev 'vhdl-template-process
))
11231 (defun vhdl-template-quantity-hook ()
11232 (vhdl-hooked-abbrev 'vhdl-template-quantity
))
11233 (defun vhdl-template-report-hook ()
11234 (vhdl-hooked-abbrev 'vhdl-template-report
))
11235 (defun vhdl-template-return-hook ()
11236 (vhdl-hooked-abbrev 'vhdl-template-return
))
11237 (defun vhdl-template-selected-signal-asst-hook ()
11238 (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst
))
11239 (defun vhdl-template-signal-hook ()
11240 (vhdl-hooked-abbrev 'vhdl-template-signal
))
11241 (defun vhdl-template-subnature-hook ()
11242 (vhdl-hooked-abbrev 'vhdl-template-subnature
))
11243 (defun vhdl-template-subtype-hook ()
11244 (vhdl-hooked-abbrev 'vhdl-template-subtype
))
11245 (defun vhdl-template-terminal-hook ()
11246 (vhdl-hooked-abbrev 'vhdl-template-terminal
))
11247 (defun vhdl-template-type-hook ()
11248 (vhdl-hooked-abbrev 'vhdl-template-type
))
11249 (defun vhdl-template-use-hook ()
11250 (vhdl-hooked-abbrev 'vhdl-template-use
))
11251 (defun vhdl-template-variable-hook ()
11252 (vhdl-hooked-abbrev 'vhdl-template-variable
))
11253 (defun vhdl-template-wait-hook ()
11254 (vhdl-hooked-abbrev 'vhdl-template-wait
))
11255 (defun vhdl-template-when-hook ()
11256 (vhdl-hooked-abbrev 'vhdl-template-when
))
11257 (defun vhdl-template-while-loop-hook ()
11258 (vhdl-hooked-abbrev 'vhdl-template-while-loop
))
11259 (defun vhdl-template-with-hook ()
11260 (vhdl-hooked-abbrev 'vhdl-template-with
))
11261 (defun vhdl-template-and-hook ()
11262 (vhdl-hooked-abbrev 'vhdl-template-and
))
11263 (defun vhdl-template-or-hook ()
11264 (vhdl-hooked-abbrev 'vhdl-template-or
))
11265 (defun vhdl-template-nand-hook ()
11266 (vhdl-hooked-abbrev 'vhdl-template-nand
))
11267 (defun vhdl-template-nor-hook ()
11268 (vhdl-hooked-abbrev 'vhdl-template-nor
))
11269 (defun vhdl-template-xor-hook ()
11270 (vhdl-hooked-abbrev 'vhdl-template-xor
))
11271 (defun vhdl-template-xnor-hook ()
11272 (vhdl-hooked-abbrev 'vhdl-template-xnor
))
11273 (defun vhdl-template-not-hook ()
11274 (vhdl-hooked-abbrev 'vhdl-template-not
))
11276 (defun vhdl-template-default-hook ()
11277 (vhdl-hooked-abbrev 'vhdl-template-default
))
11278 (defun vhdl-template-default-indent-hook ()
11279 (vhdl-hooked-abbrev 'vhdl-template-default-indent
))
11281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11282 ;; Template insertion from completion list
11284 (defun vhdl-template-insert-construct (name)
11285 "Insert the built-in construct template with NAME."
11287 (list (let ((completion-ignore-case t
))
11288 (completing-read "Construct name: "
11289 vhdl-template-construct-alist nil t
))))
11290 (vhdl-template-insert-fun
11291 (cadr (assoc name vhdl-template-construct-alist
))))
11293 (defun vhdl-template-insert-package (name)
11294 "Insert the built-in package template with NAME."
11296 (list (let ((completion-ignore-case t
))
11297 (completing-read "Package name: "
11298 vhdl-template-package-alist nil t
))))
11299 (vhdl-template-insert-fun
11300 (cadr (assoc name vhdl-template-package-alist
))))
11302 (defun vhdl-template-insert-directive (name)
11303 "Insert the built-in directive template with NAME."
11305 (list (let ((completion-ignore-case t
))
11306 (completing-read "Directive name: "
11307 vhdl-template-directive-alist nil t
))))
11308 (vhdl-template-insert-fun
11309 (cadr (assoc name vhdl-template-directive-alist
))))
11311 (defun vhdl-template-insert-fun (fun)
11312 "Call FUN to insert a built-in template."
11313 (let ((caught (catch 'abort
(when fun
(funcall fun
)))))
11314 (when (stringp caught
) (message "%s" caught
))))
11317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11321 (defun vhdl-model-insert (model-name)
11322 "Insert the user model with name MODEL-NAME."
11324 (let ((completion-ignore-case t
))
11325 (list (completing-read "Model name: " vhdl-model-alist
))))
11326 (indent-according-to-mode)
11327 (let ((start (point-marker))
11328 (margin (current-indentation))
11329 model position prompt string end
)
11330 (vhdl-prepare-search-2
11331 (when (setq model
(assoc model-name vhdl-model-alist
))
11333 (beginning-of-line)
11334 (delete-horizontal-space)
11336 (vhdl-insert-string-or-file (nth 1 model
))
11337 (setq end
(point-marker))
11340 (beginning-of-line)
11341 (while (< (point) end
)
11342 (unless (looking-at "^$")
11343 (insert-char ? margin
))
11344 (beginning-of-line 2))
11347 (unless (equal "" vhdl-clock-name
)
11348 (while (re-search-forward "<clock>" end t
)
11349 (replace-match vhdl-clock-name
)))
11352 (unless (equal "" vhdl-reset-name
)
11353 (while (re-search-forward "<reset>" end t
)
11354 (replace-match vhdl-reset-name
)))
11355 ;; replace header prompts
11356 (vhdl-template-replace-header-keywords start end nil t
)
11358 ;; query other prompts
11359 (while (re-search-forward
11360 (concat "<\\(" vhdl-template-prompt-syntax
"\\)>") end t
)
11361 (unless (equal "cursor" (match-string 1))
11362 (setq position
(match-beginning 1))
11363 (setq prompt
(match-string 1))
11365 (setq string
(vhdl-template-field prompt nil t
))
11366 ;; replace occurrences of same prompt
11367 (while (re-search-forward (concat "<\\(" prompt
"\\)>") end t
)
11368 (replace-match (or string
"")))
11369 (goto-char position
)))
11371 ;; goto final position
11372 (if (re-search-forward "<cursor>" end t
)
11374 (goto-char end
))))))
11376 (defun vhdl-model-defun ()
11377 "Define help and hook functions for user models."
11378 (let ((model-alist vhdl-model-alist
)
11379 model-name model-keyword
)
11381 ;; define functions for user models that can be invoked from menu and key
11382 ;; bindings and which themselves call `vhdl-model-insert' with the model
11383 ;; name as argument
11384 (setq model-name
(nth 0 (car model-alist
)))
11385 (eval `(defun ,(vhdl-function-name "vhdl-model" model-name
) ()
11386 ,(concat "Insert model for \"" model-name
"\".")
11388 (vhdl-model-insert ,model-name
)))
11389 ;; define hooks for user models that are invoked from keyword abbrevs
11390 (setq model-keyword
(nth 3 (car model-alist
)))
11391 (unless (equal model-keyword
"")
11393 ,(vhdl-function-name
11394 "vhdl-model" model-name
"hook") ()
11395 (vhdl-hooked-abbrev
11396 ',(vhdl-function-name "vhdl-model" model-name
)))))
11397 (setq model-alist
(cdr model-alist
)))))
11402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11403 ;;; Port translation
11404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11406 (defvar vhdl-port-list nil
11407 "Variable to hold last port map parsed.")
11408 ;; structure: (parenthesized expression means list of such entries)
11410 ;; ((generic-names) generic-type generic-init generic-comment group-comment)
11411 ;; ((port-names) port-object port-direct port-type port-comment group-comment)
11412 ;; (lib-name pack-key))
11414 (defun vhdl-parse-string (string &optional optional
)
11415 "Check that the text following point matches the regexp in STRING."
11416 (if (looking-at string
)
11417 (progn (goto-char (match-end 0))
11418 (when (vhdl-in-literal)
11422 (throw 'parse
(format "ERROR: Syntax error near line %s, expecting \"%s\""
11423 (vhdl-current-line) string
)))
11426 (defun vhdl-replace-string (regexp-cons string
&optional adjust-case
)
11427 "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
11428 (vhdl-prepare-search-1
11429 (if (string-match (car regexp-cons
) string
)
11431 (funcall vhdl-file-name-case
11432 (replace-match (cdr regexp-cons
) t nil string
))
11433 (replace-match (cdr regexp-cons
) t nil string
))
11436 (defun vhdl-parse-group-comment ()
11437 "Parse comment and empty lines between groups of lines."
11438 (let ((start (point))
11440 (vhdl-forward-comment (point-max))
11441 (setq string
(buffer-substring-no-properties start
(point)))
11442 (vhdl-forward-syntactic-ws)
11443 ;; strip off leading blanks and first newline
11444 (while (string-match "^\\(\\s-+\\)" string
)
11445 (setq string
(concat (substring string
0 (match-beginning 1))
11446 (substring string
(match-end 1)))))
11447 (if (and (not (equal string
"")) (equal (substring string
0 1) "\n"))
11448 (substring string
1)
11451 (defun vhdl-paste-group-comment (string indent
)
11452 "Paste comment and empty lines from STRING between groups of lines
11454 (let ((pos (point-marker)))
11456 (while (string-match "^\\(--\\)" string
)
11457 (setq string
(concat (substring string
0 (match-beginning 1))
11458 (make-string indent ?
)
11459 (substring string
(match-beginning 1))))))
11460 (beginning-of-line)
11464 (defvar vhdl-port-flattened nil
11465 "Indicates whether a port has been flattened.")
11467 (defun vhdl-port-flatten (&optional as-alist
)
11468 "Flatten port list so that only one generic/port exists per line.
11469 This operation is performed on an internally stored port and is only
11470 reflected in a subsequent paste operation."
11472 (if (not vhdl-port-list
)
11473 (error "ERROR: No port has been read")
11474 (message "Flattening port for next paste...")
11475 (let ((new-vhdl-port-list (list (car vhdl-port-list
)))
11476 (old-vhdl-port-list (cdr vhdl-port-list
))
11477 old-port-list new-port-list old-port new-port names
)
11478 ;; traverse port list and flatten entries
11479 (while (cdr old-vhdl-port-list
)
11480 (setq old-port-list
(car old-vhdl-port-list
))
11481 (setq new-port-list nil
)
11482 (while old-port-list
11483 (setq old-port
(car old-port-list
))
11484 (setq names
(car old-port
))
11486 (setq new-port
(cons (if as-alist
(car names
) (list (car names
)))
11488 (setq new-port-list
(append new-port-list
(list new-port
)))
11489 (setq names
(cdr names
)))
11490 (setq old-port-list
(cdr old-port-list
)))
11491 (setq old-vhdl-port-list
(cdr old-vhdl-port-list
))
11492 (setq new-vhdl-port-list
(append new-vhdl-port-list
11493 (list new-port-list
))))
11494 (setq vhdl-port-list
11495 (append new-vhdl-port-list
(list old-vhdl-port-list
))
11496 vhdl-port-flattened t
)
11497 (message "Flattening port for next paste...done"))))
11499 (defvar vhdl-port-reversed-direction nil
11500 "Indicates whether port directions are reversed.")
11502 (defun vhdl-port-reverse-direction ()
11503 "Reverse direction for all ports (useful in testbenches).
11504 This operation is performed on an internally stored port and is only
11505 reflected in a subsequent paste operation."
11507 (if (not vhdl-port-list
)
11508 (error "ERROR: No port has been read")
11509 (message "Reversing port directions for next paste...")
11510 (let ((port-list (nth 2 vhdl-port-list
))
11511 port-dir-car port-dir
)
11512 ;; traverse port list and reverse directions
11514 (setq port-dir-car
(cddr (car port-list
))
11515 port-dir
(car port-dir-car
))
11516 (setcar port-dir-car
11517 (cond ((equal port-dir
"in") "out")
11518 ((equal port-dir
"IN") "OUT")
11519 ((equal port-dir
"out") "in")
11520 ((equal port-dir
"OUT") "IN")
11522 (setq port-list
(cdr port-list
)))
11523 (setq vhdl-port-reversed-direction
(not vhdl-port-reversed-direction
))
11524 (message "Reversing port directions for next paste...done"))))
11526 (defun vhdl-port-copy ()
11527 "Get generic and port information from an entity or component declaration."
11530 (let (parse-error end-of-list
11531 decl-type name generic-list port-list context-clause
11532 object names direct type init comment group-comment
)
11533 (vhdl-prepare-search-2
11537 ;; check if within entity or component declaration
11539 (when (or (not (re-search-backward
11540 "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t
))
11541 (equal "END" (upcase (match-string 1))))
11542 (throw 'parse
"ERROR: Not within an entity or component declaration"))
11543 (setq decl-type
(downcase (match-string-no-properties 1)))
11545 (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
11546 (setq name
(match-string-no-properties 1))
11547 (message "Reading port of %s \"%s\"..." decl-type name
)
11548 (vhdl-forward-syntactic-ws)
11549 ;; parse generic clause
11550 (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t
)
11551 ;; parse group comment and spacing
11552 (setq group-comment
(vhdl-parse-group-comment))
11553 (setq end-of-list
(vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t
))
11554 (while (not end-of-list
)
11555 ;; parse names (accept extended identifiers)
11556 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11557 (setq names
(list (match-string-no-properties 1)))
11558 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t
)
11560 (append names
(list (match-string-no-properties 1)))))
11562 (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
11563 (setq type
(match-string-no-properties 1))
11564 (when (vhdl-in-comment-p) ; if stuck in comment
11565 (setq type
(concat type
(and (vhdl-parse-string ".*")
11566 (match-string-no-properties 0)))))
11568 (while (looking-at "(")
11571 (buffer-substring-no-properties
11572 (point) (progn (forward-sexp) (point)))
11573 (and (vhdl-parse-string "\\([^():;\n]*\\)" t
)
11574 (match-string-no-properties 1)))))
11575 ;; special case: closing parenthesis is on separate line
11576 (when (and type
(string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type
))
11577 (setq comment
(substring type
(match-beginning 2)))
11578 (setq type
(substring type
0 (match-beginning 1))))
11579 ;; strip of trailing group-comment
11580 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type
)
11581 (setq type
(substring type
0 (match-end 1)))
11582 ;; parse initialization expression
11584 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t
)
11585 (vhdl-parse-string "\\([^();\n]*\\)")
11586 (setq init
(match-string-no-properties 1))
11587 (while (looking-at "(")
11590 (buffer-substring-no-properties
11591 (point) (progn (forward-sexp) (point)))
11592 (and (vhdl-parse-string "\\([^();\n]*\\)" t
)
11593 (match-string-no-properties 1))))))
11594 ;; special case: closing parenthesis is on separate line
11595 (when (and init
(string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init
))
11596 (setq comment
(substring init
(match-beginning 2)))
11597 (setq init
(substring init
0 (match-beginning 1)))
11598 (vhdl-forward-syntactic-ws))
11599 (skip-chars-forward " \t")
11600 ;; parse inline comment, special case: as above, no initial.
11602 (setq comment
(and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t
)
11603 (match-string-no-properties 1))))
11604 (vhdl-forward-syntactic-ws)
11605 (setq end-of-list
(vhdl-parse-string ")" t
))
11606 (vhdl-parse-string "\\s-*;\\s-*")
11607 ;; parse inline comment
11609 (setq comment
(and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t
)
11610 (match-string-no-properties 1))))
11611 ;; save everything in list
11612 (setq generic-list
(append generic-list
11613 (list (list names type init
11614 comment group-comment
))))
11615 ;; parse group comment and spacing
11616 (setq group-comment
(vhdl-parse-group-comment))))
11617 ;; parse port clause
11618 (when (vhdl-parse-string "port[ \t\n\r\f]*(" t
)
11619 ;; parse group comment and spacing
11620 (setq group-comment
(vhdl-parse-group-comment))
11621 (setq end-of-list
(vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t
))
11622 (while (not end-of-list
)
11625 (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t
)
11626 (match-string-no-properties 1)))
11627 ;; parse names (accept extended identifiers)
11628 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
11629 (setq names
(list (match-string-no-properties 1)))
11630 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t
)
11631 (setq names
(append names
(list (match-string-no-properties 1)))))
11633 (vhdl-parse-string ":[ \t\n\r\f]*")
11635 (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t
)
11636 (match-string-no-properties 1)))
11638 (vhdl-parse-string "\\([^();\n]+\\)")
11639 (setq type
(match-string-no-properties 1))
11640 (when (vhdl-in-comment-p) ; if stuck in comment
11641 (setq type
(concat type
(and (vhdl-parse-string ".*")
11642 (match-string-no-properties 0)))))
11644 (while (looking-at "(")
11645 (setq type
(concat type
11646 (buffer-substring-no-properties
11647 (point) (progn (forward-sexp) (point)))
11648 (and (vhdl-parse-string "\\([^();\n]*\\)" t
)
11649 (match-string-no-properties 1)))))
11650 ;; special case: closing parenthesis is on separate line
11651 (when (and type
(string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type
))
11652 (setq comment
(substring type
(match-beginning 2)))
11653 (setq type
(substring type
0 (match-beginning 1))))
11654 ;; strip of trailing group-comment
11655 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type
)
11656 (setq type
(substring type
0 (match-end 1)))
11657 (vhdl-forward-syntactic-ws)
11658 (setq end-of-list
(vhdl-parse-string ")" t
))
11659 (vhdl-parse-string "\\s-*;\\s-*")
11660 ;; parse inline comment
11662 (setq comment
(and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t
)
11663 (match-string-no-properties 1))))
11664 ;; save everything in list
11665 (setq port-list
(append port-list
11666 (list (list names object direct type
11667 comment group-comment
))))
11668 ;; parse group comment and spacing
11669 (setq group-comment
(vhdl-parse-group-comment))))
11670 ; (vhdl-parse-string "end\\>")
11671 ;; parse context clause
11672 (setq context-clause
(vhdl-scan-context-clause))
11673 ; ;; add surrounding package to context clause
11674 ; (when (and (equal decl-type "component")
11675 ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
11676 ; (setq context-clause
11677 ; (append context-clause
11678 ; (list (cons (vhdl-work-library)
11679 ; (match-string-no-properties 1))))))
11680 (message "Reading port of %s \"%s\"...done" decl-type name
)
11684 (error parse-error
)
11685 (setq vhdl-port-list
(list name generic-list port-list context-clause
)
11686 vhdl-port-reversed-direction nil
11687 vhdl-port-flattened nil
)))))
11689 (defun vhdl-port-paste-context-clause (&optional exclude-pack-name
)
11690 "Paste a context clause."
11691 (let ((margin (current-indentation))
11692 (clause-list (nth 3 vhdl-port-list
))
11695 (setq clause
(car clause-list
))
11696 (unless (or (and exclude-pack-name
(equal (downcase (cdr clause
))
11697 (downcase exclude-pack-name
)))
11699 (re-search-backward
11700 (concat "^\\s-*use\\s-+" (car clause
)
11701 "\." (cdr clause
) "\\>") nil t
)))
11702 (vhdl-template-standard-package (car clause
) (cdr clause
))
11704 (setq clause-list
(cdr clause-list
)))))
11706 (defun vhdl-port-paste-generic (&optional no-init
)
11707 "Paste a generic clause."
11708 (let ((margin (current-indentation))
11709 (generic-list (nth 1 vhdl-port-list
))
11710 list-margin start names generic
)
11711 ;; paste generic clause
11713 (setq start
(point))
11714 (vhdl-insert-keyword "GENERIC (")
11715 (unless vhdl-argument-list-indent
11716 (insert "\n") (indent-to (+ margin vhdl-basic-offset
)))
11717 (setq list-margin
(current-column))
11718 (while generic-list
11719 (setq generic
(car generic-list
))
11720 ;; paste group comment and spacing
11721 (when (memq vhdl-include-group-comments
'(decl always
))
11722 (vhdl-paste-group-comment (nth 4 generic
) list-margin
))
11724 (setq names
(nth 0 generic
))
11726 (insert (car names
))
11727 (setq names
(cdr names
))
11728 (when names
(insert ", ")))
11730 (insert " : " (nth 1 generic
))
11731 ;; paste initialization
11732 (when (and (not no-init
) (nth 2 generic
))
11733 (insert " := " (nth 2 generic
)))
11734 (unless (cdr generic-list
) (insert ")"))
11737 (when (and vhdl-include-port-comments
(nth 3 generic
))
11738 (vhdl-comment-insert-inline (nth 3 generic
) t
))
11739 (setq generic-list
(cdr generic-list
))
11740 (when generic-list
(insert "\n") (indent-to list-margin
)))
11741 ;; align generic clause
11742 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1 t
)))))
11744 (defun vhdl-port-paste-port ()
11745 "Paste a port clause."
11746 (let ((margin (current-indentation))
11747 (port-list (nth 2 vhdl-port-list
))
11748 list-margin start names port
)
11749 ;; paste port clause
11751 (setq start
(point))
11752 (vhdl-insert-keyword "PORT (")
11753 (unless vhdl-argument-list-indent
11754 (insert "\n") (indent-to (+ margin vhdl-basic-offset
)))
11755 (setq list-margin
(current-column))
11757 (setq port
(car port-list
))
11758 ;; paste group comment and spacing
11759 (when (memq vhdl-include-group-comments
'(decl always
))
11760 (vhdl-paste-group-comment (nth 5 port
) list-margin
))
11762 (when (nth 1 port
) (insert (nth 1 port
) " "))
11764 (setq names
(nth 0 port
))
11766 (insert (car names
))
11767 (setq names
(cdr names
))
11768 (when names
(insert ", ")))
11771 (when (nth 2 port
) (insert (nth 2 port
) " "))
11773 (insert (nth 3 port
))
11774 (unless (cdr port-list
) (insert ")"))
11777 (when (and vhdl-include-port-comments
(nth 4 port
))
11778 (vhdl-comment-insert-inline (nth 4 port
) t
))
11779 (setq port-list
(cdr port-list
))
11780 (when port-list
(insert "\n") (indent-to list-margin
)))
11781 ;; align port clause
11782 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1)))))
11784 (defun vhdl-port-paste-declaration (kind &optional no-indent
)
11785 "Paste as an entity or component declaration."
11786 (unless no-indent
(indent-according-to-mode))
11787 (let ((margin (current-indentation))
11788 (name (nth 0 vhdl-port-list
)))
11789 (vhdl-insert-keyword (if (eq kind
'entity
) "ENTITY " "COMPONENT "))
11791 (when (or (eq kind
'entity
) (not (vhdl-standard-p '87)))
11792 (vhdl-insert-keyword " IS"))
11793 ;; paste generic and port clause
11794 (when (nth 1 vhdl-port-list
)
11796 (when (and (memq vhdl-insert-empty-lines
'(unit all
)) (eq kind
'entity
))
11798 (indent-to (+ margin vhdl-basic-offset
))
11799 (vhdl-port-paste-generic (eq kind
'component
)))
11800 (when (nth 2 vhdl-port-list
)
11802 (when (and (memq vhdl-insert-empty-lines
'(unit all
))
11805 (indent-to (+ margin vhdl-basic-offset
)))
11806 (vhdl-port-paste-port)
11808 (when (and (memq vhdl-insert-empty-lines
'(unit all
)) (eq kind
'entity
))
11811 (vhdl-insert-keyword "END")
11812 (if (eq kind
'entity
)
11814 (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
11816 (vhdl-insert-keyword " COMPONENT")
11817 (unless (vhdl-standard-p '87) (insert " " name
)))
11820 (defun vhdl-port-paste-entity (&optional no-indent
)
11821 "Paste as an entity declaration."
11823 (if (not vhdl-port-list
)
11824 (error "ERROR: No port read")
11825 (message "Pasting port as entity \"%s\"..." (car vhdl-port-list
))
11826 (vhdl-port-paste-declaration 'entity no-indent
)
11827 (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list
))))
11829 (defun vhdl-port-paste-component (&optional no-indent
)
11830 "Paste as a component declaration."
11832 (if (not vhdl-port-list
)
11833 (error "ERROR: No port read")
11834 (message "Pasting port as component \"%s\"..." (car vhdl-port-list
))
11835 (vhdl-port-paste-declaration 'component no-indent
)
11836 (message "Pasting port as component \"%s\"...done" (car vhdl-port-list
))))
11838 (defun vhdl-port-paste-generic-map (&optional secondary no-constants
)
11839 "Paste as a generic map."
11841 (unless secondary
(indent-according-to-mode))
11842 (let ((margin (current-indentation))
11843 list-margin start generic
11844 (generic-list (nth 1 vhdl-port-list
)))
11846 (setq start
(point))
11847 (vhdl-insert-keyword "GENERIC MAP (")
11848 (if (not vhdl-association-list-with-formals
)
11849 ;; paste list of actual generics
11850 (while generic-list
11851 (insert (if no-constants
11852 (car (nth 0 (car generic-list
)))
11853 (or (nth 2 (car generic-list
)) " ")))
11854 (setq generic-list
(cdr generic-list
))
11855 (insert (if generic-list
", " ")"))
11856 (when (and (not generic-list
) secondary
11857 (null (nth 2 vhdl-port-list
)))
11859 (unless vhdl-argument-list-indent
11860 (insert "\n") (indent-to (+ margin vhdl-basic-offset
)))
11861 (setq list-margin
(current-column))
11862 (while generic-list
11863 (setq generic
(car generic-list
))
11864 ;; paste group comment and spacing
11865 (when (eq vhdl-include-group-comments
'always
)
11866 (vhdl-paste-group-comment (nth 4 generic
) list-margin
))
11867 ;; paste formal and actual generic
11868 (insert (car (nth 0 generic
)) " => "
11870 (vhdl-replace-string vhdl-actual-generic-name
11871 (car (nth 0 generic
)))
11872 (or (nth 2 generic
) "")))
11873 (setq generic-list
(cdr generic-list
))
11874 (insert (if generic-list
"," ")"))
11875 (when (and (not generic-list
) secondary
11876 (null (nth 2 vhdl-port-list
)))
11879 (when (or vhdl-include-type-comments
11880 (and vhdl-include-port-comments
(nth 3 generic
)))
11881 (vhdl-comment-insert-inline
11883 (when vhdl-include-type-comments
11884 (concat "[" (nth 1 generic
) "] "))
11885 (when vhdl-include-port-comments
(nth 3 generic
))) t
))
11886 (when generic-list
(insert "\n") (indent-to list-margin
)))
11887 ;; align generic map
11888 (when vhdl-auto-align
11889 (vhdl-align-region-groups start
(point) 1 t
))))))
11891 (defun vhdl-port-paste-port-map ()
11892 "Paste as a port map."
11893 (let ((margin (current-indentation))
11894 list-margin start port
11895 (port-list (nth 2 vhdl-port-list
)))
11897 (setq start
(point))
11898 (vhdl-insert-keyword "PORT MAP (")
11899 (if (not vhdl-association-list-with-formals
)
11900 ;; paste list of actual ports
11902 (insert (vhdl-replace-string vhdl-actual-port-name
11903 (car (nth 0 (car port-list
)))))
11904 (setq port-list
(cdr port-list
))
11905 (insert (if port-list
", " ")")))
11906 (unless vhdl-argument-list-indent
11907 (insert "\n") (indent-to (+ margin vhdl-basic-offset
)))
11908 (setq list-margin
(current-column))
11910 (setq port
(car port-list
))
11911 ;; paste group comment and spacing
11912 (when (eq vhdl-include-group-comments
'always
)
11913 (vhdl-paste-group-comment (nth 5 port
) list-margin
))
11914 ;; paste formal and actual port
11915 (insert (car (nth 0 port
)) " => ")
11916 (insert (vhdl-replace-string vhdl-actual-port-name
11917 (car (nth 0 port
))))
11918 (setq port-list
(cdr port-list
))
11919 (insert (if port-list
"," ");"))
11921 (when (or (and vhdl-include-direction-comments
(nth 2 port
))
11922 vhdl-include-type-comments
11923 (and vhdl-include-port-comments
(nth 4 port
)))
11924 (vhdl-comment-insert-inline
11926 (cond ((and vhdl-include-direction-comments
11927 vhdl-include-type-comments
)
11928 (concat "[" (format "%-4s" (concat (nth 2 port
) " "))
11929 (nth 3 port
) "] "))
11930 ((and vhdl-include-direction-comments
(nth 2 port
))
11931 (format "%-6s" (concat "[" (nth 2 port
) "] ")))
11932 (vhdl-include-direction-comments " ")
11933 (vhdl-include-type-comments
11934 (concat "[" (nth 3 port
) "] ")))
11935 (when vhdl-include-port-comments
(nth 4 port
))) t
))
11936 (when port-list
(insert "\n") (indent-to list-margin
)))
11937 ;; align port clause
11938 (when vhdl-auto-align
11939 (vhdl-align-region-groups start
(point) 1))))))
11941 (defun vhdl-port-paste-instance (&optional name no-indent title
)
11942 "Paste as an instantiation."
11944 (if (not vhdl-port-list
)
11945 (error "ERROR: No port read")
11946 (let ((orig-vhdl-port-list vhdl-port-list
))
11947 ;; flatten local copy of port list (must be flat for port mapping)
11948 (vhdl-port-flatten)
11949 (unless no-indent
(indent-according-to-mode))
11950 (let ((margin (current-indentation)))
11951 ;; paste instantiation
11954 ((equal (cdr vhdl-instance-name
) "")
11955 (setq name
(vhdl-template-field "instance name")))
11956 ((string-match "\%d" (cdr vhdl-instance-name
))
11958 (while (save-excursion
11959 (setq name
(format (vhdl-replace-string
11961 (nth 0 vhdl-port-list
)) n
))
11962 (goto-char (point-min))
11963 (vhdl-re-search-forward name nil t
))
11966 (t (insert (vhdl-replace-string vhdl-instance-name
11967 (nth 0 vhdl-port-list
)))))
11968 (message "Pasting port as instantiation \"%s\"..." name
)
11972 (beginning-of-line)
11973 (indent-to vhdl-basic-offset
)
11974 (insert "-- instance \"" name
"\"\n")))
11975 (if (not (vhdl-use-direct-instantiation))
11976 (insert (nth 0 vhdl-port-list
))
11977 (vhdl-insert-keyword "ENTITY ")
11978 (insert (vhdl-work-library) "." (nth 0 vhdl-port-list
)))
11979 (when (nth 1 vhdl-port-list
)
11980 (insert "\n") (indent-to (+ margin vhdl-basic-offset
))
11981 (vhdl-port-paste-generic-map t t
))
11982 (when (nth 2 vhdl-port-list
)
11983 (insert "\n") (indent-to (+ margin vhdl-basic-offset
))
11984 (vhdl-port-paste-port-map))
11985 (unless (or (nth 1 vhdl-port-list
) (nth 2 vhdl-port-list
))
11987 (message "Pasting port as instantiation \"%s\"...done" name
))
11988 (setq vhdl-port-list orig-vhdl-port-list
))))
11990 (defun vhdl-port-paste-constants (&optional no-indent
)
11991 "Paste generics as constants."
11993 (if (not vhdl-port-list
)
11994 (error "ERROR: No port read")
11995 (let ((orig-vhdl-port-list vhdl-port-list
))
11996 (message "Pasting port as constants...")
11997 ;; flatten local copy of port list (must be flat for constant initial.)
11998 (vhdl-port-flatten)
11999 (unless no-indent
(indent-according-to-mode))
12000 (let ((margin (current-indentation))
12002 (generic-list (nth 1 vhdl-port-list
)))
12004 (setq start
(point))
12005 (while generic-list
12006 (setq generic
(car generic-list
))
12007 ;; paste group comment and spacing
12008 (when (memq vhdl-include-group-comments
'(decl always
))
12009 (vhdl-paste-group-comment (nth 4 generic
) margin
))
12010 (vhdl-insert-keyword "CONSTANT ")
12011 ;; paste generic constants
12012 (setq name
(nth 0 generic
))
12014 (insert (vhdl-replace-string vhdl-actual-generic-name
(car name
)))
12016 (insert " : " (nth 1 generic
))
12017 ;; paste initialization
12018 (when (nth 2 generic
)
12019 (insert " := " (nth 2 generic
)))
12022 (when (and vhdl-include-port-comments
(nth 3 generic
))
12023 (vhdl-comment-insert-inline (nth 3 generic
) t
))
12024 (setq generic-list
(cdr generic-list
))
12025 (when generic-list
(insert "\n") (indent-to margin
))))
12026 ;; align signal list
12027 (when vhdl-auto-align
12028 (vhdl-align-region-groups start
(point) 1))))
12029 (message "Pasting port as constants...done")
12030 (setq vhdl-port-list orig-vhdl-port-list
))))
12032 (defun vhdl-port-paste-signals (&optional initialize no-indent
)
12033 "Paste ports as internal signals."
12035 (if (not vhdl-port-list
)
12036 (error "ERROR: No port read")
12037 (message "Pasting port as signals...")
12038 (unless no-indent
(indent-according-to-mode))
12039 (let ((margin (current-indentation))
12040 start port names type generic-list port-name constant-name pos
12041 (port-list (nth 2 vhdl-port-list
)))
12043 (setq start
(point))
12045 (setq port
(car port-list
))
12046 ;; paste group comment and spacing
12047 (when (memq vhdl-include-group-comments
'(decl always
))
12048 (vhdl-paste-group-comment (nth 5 port
) margin
))
12051 (insert (nth 1 port
) " ")
12052 (vhdl-insert-keyword "SIGNAL "))
12053 ;; paste actual port signals
12054 (setq names
(nth 0 port
))
12056 (insert (vhdl-replace-string vhdl-actual-port-name
(car names
)))
12057 (setq names
(cdr names
))
12058 (when names
(insert ", ")))
12060 (setq type
(nth 3 port
))
12061 (setq generic-list
(nth 1 vhdl-port-list
))
12062 (vhdl-prepare-search-1
12064 ;; replace formal by actual generics
12065 (while generic-list
12066 (setq port-name
(car (nth 0 (car generic-list
))))
12067 (while (string-match (concat "\\<" port-name
"\\>") type pos
)
12068 (setq constant-name
12069 (save-match-data (vhdl-replace-string
12070 vhdl-actual-generic-name port-name
)))
12071 (setq type
(replace-match constant-name t nil type
))
12072 (setq pos
(match-end 0)))
12073 (setq generic-list
(cdr generic-list
))))
12074 (insert " : " type
)
12075 ;; paste initialization (inputs only)
12076 (when (and initialize
(nth 2 port
) (equal "IN" (upcase (nth 2 port
))))
12078 (cond ((string-match "integer" (nth 3 port
)) "0")
12079 ((string-match "natural" (nth 3 port
)) "0")
12080 ((string-match "positive" (nth 3 port
)) "0")
12081 ((string-match "real" (nth 3 port
)) "0.0")
12082 ((string-match "(.+)" (nth 3 port
)) "(others => '0')")
12086 (when (or (and vhdl-include-direction-comments
(nth 2 port
))
12087 (and vhdl-include-port-comments
(nth 4 port
)))
12088 (vhdl-comment-insert-inline
12090 (cond ((and vhdl-include-direction-comments
(nth 2 port
))
12091 (format "%-6s" (concat "[" (nth 2 port
) "] ")))
12092 (vhdl-include-direction-comments " "))
12093 (when vhdl-include-port-comments
(nth 4 port
))) t
))
12094 (setq port-list
(cdr port-list
))
12095 (when port-list
(insert "\n") (indent-to margin
)))
12096 ;; align signal list
12097 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1))))
12098 (message "Pasting port as signals...done")))
12100 (defun vhdl-port-paste-initializations (&optional no-indent
)
12101 "Paste ports as signal initializations."
12103 (if (not vhdl-port-list
)
12104 (error "ERROR: No port read")
12105 (let ((orig-vhdl-port-list vhdl-port-list
))
12106 (message "Pasting port as initializations...")
12107 ;; flatten local copy of port list (must be flat for signal initial.)
12108 (vhdl-port-flatten)
12109 (unless no-indent
(indent-according-to-mode))
12110 (let ((margin (current-indentation))
12112 (port-list (nth 2 vhdl-port-list
)))
12114 (setq start
(point))
12116 (setq port
(car port-list
))
12117 ;; paste actual port signal (inputs only)
12118 (when (equal "IN" (upcase (nth 2 port
)))
12119 (setq name
(car (nth 0 port
)))
12120 (insert (vhdl-replace-string vhdl-actual-port-name name
))
12121 ;; paste initialization
12123 (cond ((string-match "integer" (nth 3 port
)) "0")
12124 ((string-match "natural" (nth 3 port
)) "0")
12125 ((string-match "positive" (nth 3 port
)) "0")
12126 ((string-match "real" (nth 3 port
)) "0.0")
12127 ((string-match "(.+)" (nth 3 port
)) "(others => '0')")
12130 (setq port-list
(cdr port-list
))
12131 (when (and port-list
12132 (equal "IN" (upcase (nth 2 (car port-list
)))))
12133 (insert "\n") (indent-to margin
)))
12134 ;; align signal list
12135 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1))))
12136 (message "Pasting port as initializations...done")
12137 (setq vhdl-port-list orig-vhdl-port-list
))))
12139 (defun vhdl-port-paste-testbench ()
12140 "Paste as a bare-bones testbench."
12142 (if (not vhdl-port-list
)
12143 (error "ERROR: No port read")
12144 (let ((case-fold-search t
)
12145 (ent-name (vhdl-replace-string vhdl-testbench-entity-name
12146 (nth 0 vhdl-port-list
)))
12147 (source-buffer (current-buffer))
12148 arch-name config-name ent-file-name arch-file-name
12149 ent-buffer arch-buffer position
)
12150 ;; open entity file
12151 (unless (eq vhdl-testbench-create-files
'none
)
12152 (setq ent-file-name
12153 (concat (vhdl-replace-string vhdl-testbench-entity-file-name
12155 "." (file-name-extension (buffer-file-name))))
12156 (if (file-exists-p ent-file-name
)
12158 (concat "File \"" ent-file-name
"\" exists; overwrite? "))
12159 (progn (find-file ent-file-name
)
12161 (set-buffer-modified-p nil
))
12162 (if (eq vhdl-testbench-create-files
'separate
)
12163 (setq ent-file-name nil
)
12164 (error "ERROR: Pasting port as testbench...aborted")))
12165 (find-file ent-file-name
)))
12166 (unless (and (eq vhdl-testbench-create-files
'separate
)
12167 (null ent-file-name
))
12168 ;; paste entity header
12169 (if vhdl-testbench-include-header
12170 (progn (vhdl-template-header
12171 (concat "Testbench for design \""
12172 (nth 0 vhdl-port-list
) "\""))
12173 (goto-char (point-max)))
12174 (vhdl-comment-display-line) (insert "\n\n"))
12175 ;; paste std_logic_1164 package
12176 (when vhdl-testbench-include-library
12177 (vhdl-template-package-std-logic-1164)
12178 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
12179 ;; paste entity declaration
12180 (vhdl-insert-keyword "ENTITY ")
12182 (vhdl-insert-keyword " IS")
12183 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
12185 (vhdl-insert-keyword "END ")
12186 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
12187 (insert ent-name
";")
12189 (vhdl-comment-display-line) (insert "\n"))
12190 ;; get architecture name
12191 (setq arch-name
(if (equal (cdr vhdl-testbench-architecture-name
) "")
12192 (read-from-minibuffer "architecture name: "
12193 nil vhdl-minibuffer-local-map
)
12194 (vhdl-replace-string vhdl-testbench-architecture-name
12195 (nth 0 vhdl-port-list
))))
12196 (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name
)
12197 ;; open architecture file
12198 (if (not (eq vhdl-testbench-create-files
'separate
))
12200 (setq ent-buffer
(current-buffer))
12201 (setq arch-file-name
12202 (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
12203 (concat ent-name
" " arch-name
) t
)
12204 "." (file-name-extension (buffer-file-name))))
12205 (when (and (file-exists-p arch-file-name
)
12206 (not (y-or-n-p (concat "File \"" arch-file-name
12207 "\" exists; overwrite? "))))
12208 (error "ERROR: Pasting port as testbench...aborted"))
12209 (find-file arch-file-name
)
12211 (set-buffer-modified-p nil
)
12212 ;; paste architecture header
12213 (if vhdl-testbench-include-header
12214 (progn (vhdl-template-header
12215 (concat "Testbench architecture for design \""
12216 (nth 0 vhdl-port-list
) "\""))
12217 (goto-char (point-max)))
12218 (vhdl-comment-display-line) (insert "\n\n")))
12219 ;; paste architecture body
12220 (vhdl-insert-keyword "ARCHITECTURE ")
12222 (vhdl-insert-keyword " OF ")
12224 (vhdl-insert-keyword " IS")
12225 (insert "\n\n") (indent-to vhdl-basic-offset
)
12226 ;; paste component declaration
12227 (unless (vhdl-use-direct-instantiation)
12228 (vhdl-port-paste-component t
)
12229 (insert "\n\n") (indent-to vhdl-basic-offset
))
12231 (when (nth 1 vhdl-port-list
)
12232 (insert "-- component generics\n") (indent-to vhdl-basic-offset
)
12233 (vhdl-port-paste-constants t
)
12234 (insert "\n\n") (indent-to vhdl-basic-offset
))
12235 ;; paste internal signals
12236 (insert "-- component ports\n") (indent-to vhdl-basic-offset
)
12237 (vhdl-port-paste-signals vhdl-testbench-initialize-signals t
)
12239 ;; paste custom declarations
12240 (unless (equal "" vhdl-testbench-declarations
)
12242 (setq position
(point))
12243 (vhdl-insert-string-or-file vhdl-testbench-declarations
)
12244 (vhdl-indent-region position
(point)))
12245 (setq position
(point))
12247 (vhdl-comment-display-line) (insert "\n")
12248 (when vhdl-testbench-include-configuration
12249 (setq config-name
(vhdl-replace-string
12250 vhdl-testbench-configuration-name
12251 (concat ent-name
" " arch-name
)))
12253 (vhdl-insert-keyword "CONFIGURATION ") (insert config-name
)
12254 (vhdl-insert-keyword " OF ") (insert ent-name
)
12255 (vhdl-insert-keyword " IS\n")
12256 (indent-to vhdl-basic-offset
)
12257 (vhdl-insert-keyword "FOR ") (insert arch-name
"\n")
12258 (indent-to vhdl-basic-offset
)
12259 (vhdl-insert-keyword "END FOR;\n")
12260 (vhdl-insert-keyword "END ") (insert config-name
";\n\n")
12261 (vhdl-comment-display-line) (insert "\n"))
12262 (goto-char position
)
12263 (vhdl-template-begin-end
12264 (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name
0 t
)
12265 ;; paste instantiation
12266 (insert "-- component instantiation\n") (indent-to vhdl-basic-offset
)
12267 (vhdl-port-paste-instance
12268 (vhdl-replace-string vhdl-testbench-dut-name
(nth 0 vhdl-port-list
)) t
)
12270 ;; paste custom statements
12271 (unless (equal "" vhdl-testbench-statements
)
12273 (setq position
(point))
12274 (vhdl-insert-string-or-file vhdl-testbench-statements
)
12275 (vhdl-indent-region position
(point)))
12277 (indent-to vhdl-basic-offset
)
12278 (unless (eq vhdl-testbench-create-files
'none
)
12279 (setq arch-buffer
(current-buffer))
12280 (when ent-buffer
(set-buffer ent-buffer
) (save-buffer))
12281 (set-buffer arch-buffer
) (save-buffer))
12283 (concat (format "Pasting port as testbench \"%s(%s)\"...done"
12284 ent-name arch-name
)
12286 (format "\n File created: \"%s\"" ent-file-name
))
12287 (and arch-file-name
12288 (format "\n File created: \"%s\"" arch-file-name
)))))))
12291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12292 ;;; Subprogram interface translation
12293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12295 (defvar vhdl-subprog-list nil
12296 "Variable to hold last subprogram interface parsed.")
12297 ;; structure: (parenthesized expression means list of such entries)
12298 ;; (subprog-name kind
12299 ;; ((names) object direct type init comment group-comment)
12300 ;; return-type return-comment group-comment)
12302 (defvar vhdl-subprog-flattened nil
12303 "Indicates whether an subprogram interface has been flattened.")
12305 (defun vhdl-subprog-flatten ()
12306 "Flatten interface list so that only one parameter exists per line."
12308 (if (not vhdl-subprog-list
)
12309 (error "ERROR: No subprogram interface has been read")
12310 (message "Flattening subprogram interface...")
12311 (let ((old-subprog-list (nth 2 vhdl-subprog-list
))
12312 new-subprog-list old-subprog new-subprog names
)
12313 ;; traverse parameter list and flatten entries
12314 (while old-subprog-list
12315 (setq old-subprog
(car old-subprog-list
))
12316 (setq names
(car old-subprog
))
12318 (setq new-subprog
(cons (list (car names
)) (cdr old-subprog
)))
12319 (setq new-subprog-list
(append new-subprog-list
(list new-subprog
)))
12320 (setq names
(cdr names
)))
12321 (setq old-subprog-list
(cdr old-subprog-list
)))
12322 (setq vhdl-subprog-list
12323 (list (nth 0 vhdl-subprog-list
) (nth 1 vhdl-subprog-list
)
12324 new-subprog-list
(nth 3 vhdl-subprog-list
)
12325 (nth 4 vhdl-subprog-list
) (nth 5 vhdl-subprog-list
))
12326 vhdl-subprog-flattened t
)
12327 (message "Flattening subprogram interface...done"))))
12329 (defun vhdl-subprog-copy ()
12330 "Get interface information from a subprogram specification."
12333 (let (parse-error pos end-of-list
12334 name kind param-list object names direct type init
12335 comment group-comment
12336 return-type return-comment return-group-comment
)
12337 (vhdl-prepare-search-2
12341 ;; check if within function declaration
12344 (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
12345 (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t
)
12346 (goto-char (match-end 0))
12347 (save-excursion (backward-char)
12350 (throw 'parse
"ERROR: Not within a subprogram specification"))
12351 (setq name
(match-string-no-properties 5))
12352 (setq kind
(if (match-string 2) 'procedure
'function
))
12353 (setq end-of-list
(not (match-string 7)))
12354 (message "Reading interface of subprogram \"%s\"..." name
)
12355 ;; parse parameter list
12356 (setq group-comment
(vhdl-parse-group-comment))
12357 (setq end-of-list
(or end-of-list
12358 (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t
)))
12359 (while (not end-of-list
)
12362 (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t
)
12363 (match-string-no-properties 1)))
12364 ;; parse names (accept extended identifiers)
12365 (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
12366 (setq names
(list (match-string-no-properties 1)))
12367 (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t
)
12368 (setq names
(append names
(list (match-string-no-properties 1)))))
12370 (vhdl-parse-string ":[ \t\n\r\f]*")
12372 (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t
)
12373 (match-string-no-properties 1)))
12375 (vhdl-parse-string "\\([^():;\n]+\\)")
12376 (setq type
(match-string-no-properties 1))
12378 (while (looking-at "(")
12381 (buffer-substring-no-properties
12382 (point) (progn (forward-sexp) (point)))
12383 (and (vhdl-parse-string "\\([^():;\n]*\\)" t
)
12384 (match-string-no-properties 1)))))
12385 ;; special case: closing parenthesis is on separate line
12386 (when (and type
(string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type
))
12387 (setq comment
(substring type
(match-beginning 2)))
12388 (setq type
(substring type
0 (match-beginning 1))))
12389 ;; strip off trailing group-comment
12390 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type
)
12391 (setq type
(substring type
0 (match-end 1)))
12392 ;; parse initialization expression
12394 (when (vhdl-parse-string ":=[ \t\n\r\f]*" t
)
12395 (vhdl-parse-string "\\([^();\n]*\\)")
12396 (setq init
(match-string-no-properties 1))
12397 (while (looking-at "(")
12400 (buffer-substring-no-properties
12401 (point) (progn (forward-sexp) (point)))
12402 (and (vhdl-parse-string "\\([^();\n]*\\)" t
)
12403 (match-string-no-properties 1))))))
12404 ;; special case: closing parenthesis is on separate line
12405 (when (and init
(string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init
))
12406 (setq comment
(substring init
(match-beginning 2)))
12407 (setq init
(substring init
0 (match-beginning 1)))
12408 (vhdl-forward-syntactic-ws))
12409 (skip-chars-forward " \t")
12410 ;; parse inline comment, special case: as above, no initial.
12412 (setq comment
(and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t
)
12413 (match-string-no-properties 1))))
12414 (vhdl-forward-syntactic-ws)
12415 (setq end-of-list
(vhdl-parse-string ")\\s-*" t
))
12416 ;; parse inline comment
12418 (setq comment
(and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t
)
12419 (match-string-no-properties 1))))
12420 (setq return-group-comment
(vhdl-parse-group-comment))
12421 (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
12422 ;; parse return type
12423 (when (match-string 3)
12424 (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
12425 (setq return-type
(match-string-no-properties 1))
12426 (when (and return-type
12427 (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type
))
12428 (setq return-comment
(substring return-type
(match-beginning 2)))
12429 (setq return-type
(substring return-type
0 (match-beginning 1))))
12430 ;; strip of trailing group-comment
12431 (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type
)
12432 (setq return-type
(substring return-type
0 (match-end 1)))
12433 ;; parse return comment
12434 (unless return-comment
12435 (setq return-comment
(and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t
)
12436 (match-string-no-properties 1)))))
12437 ;; parse inline comment
12439 (setq comment
(and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t
)
12440 (match-string-no-properties 1))))
12441 ;; save everything in list
12442 (setq param-list
(append param-list
12443 (list (list names object direct type init
12444 comment group-comment
))))
12445 ;; parse group comment and spacing
12446 (setq group-comment
(vhdl-parse-group-comment)))
12447 (message "Reading interface of subprogram \"%s\"...done" name
)
12451 (error parse-error
)
12452 (setq vhdl-subprog-list
12453 (list name kind param-list return-type return-comment
12454 return-group-comment
)
12455 vhdl-subprog-flattened nil
)))))
12457 (defun vhdl-subprog-paste-specification (kind)
12458 "Paste as a subprogram specification."
12459 (indent-according-to-mode)
12460 (let ((margin (current-column))
12461 (param-list (nth 2 vhdl-subprog-list
))
12462 list-margin start names param
)
12463 ;; paste keyword and name
12464 (vhdl-insert-keyword
12465 (if (eq (nth 1 vhdl-subprog-list
) 'procedure
) "PROCEDURE " "FUNCTION "))
12466 (insert (nth 0 vhdl-subprog-list
))
12467 (if (not param-list
)
12468 (if (eq kind
'decl
) (insert ";") (vhdl-insert-keyword " is"))
12469 (setq start
(point))
12470 ;; paste parameter list
12472 (unless vhdl-argument-list-indent
12473 (insert "\n") (indent-to (+ margin vhdl-basic-offset
)))
12474 (setq list-margin
(current-column))
12476 (setq param
(car param-list
))
12477 ;; paste group comment and spacing
12478 (when (memq vhdl-include-group-comments
(list kind
'always
))
12479 (vhdl-paste-group-comment (nth 6 param
) list-margin
))
12481 (when (nth 1 param
) (insert (nth 1 param
) " "))
12483 (setq names
(nth 0 param
))
12485 (insert (car names
))
12486 (setq names
(cdr names
))
12487 (when names
(insert ", ")))
12490 (when (nth 2 param
) (insert (nth 2 param
) " "))
12492 (insert (nth 3 param
))
12493 ;; paste initialization
12494 (when (nth 4 param
) (insert " := " (nth 4 param
)))
12496 (if (cdr param-list
)
12499 (when (null (nth 3 vhdl-subprog-list
))
12500 (if (eq kind
'decl
) (insert ";") (vhdl-insert-keyword " is"))))
12502 (when (and vhdl-include-port-comments
(nth 5 param
))
12503 (vhdl-comment-insert-inline (nth 5 param
) t
))
12504 (setq param-list
(cdr param-list
))
12505 (when param-list
(insert "\n") (indent-to list-margin
)))
12506 (when (nth 3 vhdl-subprog-list
)
12507 (insert "\n") (indent-to list-margin
)
12508 ;; paste group comment and spacing
12509 (when (memq vhdl-include-group-comments
(list kind
'always
))
12510 (vhdl-paste-group-comment (nth 5 vhdl-subprog-list
) list-margin
))
12511 ;; paste return type
12512 (insert "return " (nth 3 vhdl-subprog-list
))
12513 (if (eq kind
'decl
) (insert ";") (vhdl-insert-keyword " is"))
12514 (when (and vhdl-include-port-comments
(nth 4 vhdl-subprog-list
))
12515 (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list
) t
)))
12516 ;; align parameter list
12517 (when vhdl-auto-align
(vhdl-align-region-groups start
(point) 1 t
)))
12519 (when (eq kind
'body
)
12521 (vhdl-template-begin-end
12522 (unless (vhdl-standard-p '87)
12523 (if (eq (nth 1 vhdl-subprog-list
) 'procedure
) "PROCEDURE" "FUNCTION"))
12524 (nth 0 vhdl-subprog-list
) margin
))))
12526 (defun vhdl-subprog-paste-declaration ()
12527 "Paste as a subprogram declaration."
12529 (if (not vhdl-subprog-list
)
12530 (error "ERROR: No subprogram interface read")
12531 (message "Pasting interface as subprogram declaration \"%s\"..."
12532 (car vhdl-subprog-list
))
12533 ;; paste specification
12534 (vhdl-subprog-paste-specification 'decl
)
12535 (message "Pasting interface as subprogram declaration \"%s\"...done"
12536 (car vhdl-subprog-list
))))
12538 (defun vhdl-subprog-paste-body ()
12539 "Paste as a subprogram body."
12541 (if (not vhdl-subprog-list
)
12542 (error "ERROR: No subprogram interface read")
12543 (message "Pasting interface as subprogram body \"%s\"..."
12544 (car vhdl-subprog-list
))
12545 ;; paste specification and body
12546 (vhdl-subprog-paste-specification 'body
)
12547 (message "Pasting interface as subprogram body \"%s\"...done"
12548 (car vhdl-subprog-list
))))
12550 (defun vhdl-subprog-paste-call ()
12551 "Paste as a subprogram call."
12553 (if (not vhdl-subprog-list
)
12554 (error "ERROR: No subprogram interface read")
12555 (let ((orig-vhdl-subprog-list vhdl-subprog-list
)
12556 param-list margin list-margin param start
)
12557 ;; flatten local copy of interface list (must be flat for parameter mapping)
12558 (vhdl-subprog-flatten)
12559 (setq param-list
(nth 2 vhdl-subprog-list
))
12560 (indent-according-to-mode)
12561 (setq margin
(current-indentation))
12562 (message "Pasting interface as subprogram call \"%s\"..."
12563 (car vhdl-subprog-list
))
12565 (insert (nth 0 vhdl-subprog-list
))
12566 (if (not param-list
)
12568 (setq start
(point))
12569 ;; paste parameter list
12571 (unless vhdl-argument-list-indent
12572 (insert "\n") (indent-to (+ margin vhdl-basic-offset
)))
12573 (setq list-margin
(current-column))
12575 (setq param
(car param-list
))
12576 ;; paste group comment and spacing
12577 (when (eq vhdl-include-group-comments
'always
)
12578 (vhdl-paste-group-comment (nth 6 param
) list-margin
))
12579 ;; paste formal port
12580 (insert (car (nth 0 param
)) " => ")
12581 (setq param-list
(cdr param-list
))
12582 (insert (if param-list
"," ");"))
12584 (when (and vhdl-include-port-comments
(nth 5 param
))
12585 (vhdl-comment-insert-inline (nth 5 param
)))
12586 (when param-list
(insert "\n") (indent-to list-margin
)))
12587 ;; align parameter list
12588 (when vhdl-auto-align
12589 (vhdl-align-region-groups start
(point) 1)))
12590 (message "Pasting interface as subprogram call \"%s\"...done"
12591 (car vhdl-subprog-list
))
12592 (setq vhdl-subprog-list orig-vhdl-subprog-list
))))
12595 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12600 ;; Hippie expand customization
12602 (defvar vhdl-expand-upper-case nil
)
12604 (defun vhdl-try-expand-abbrev (old)
12605 "Try expanding abbreviations from `vhdl-abbrev-list'."
12607 (he-init-string (he-dabbrev-beg) (point))
12608 (setq he-expand-list
12609 (let ((abbrev-list vhdl-abbrev-list
)
12610 (sel-abbrev-list '()))
12612 (when (or (not (stringp (car abbrev-list
)))
12614 (concat "^" he-search-string
) (car abbrev-list
)))
12615 (setq sel-abbrev-list
12616 (cons (car abbrev-list
) sel-abbrev-list
)))
12617 (setq abbrev-list
(cdr abbrev-list
)))
12618 (nreverse sel-abbrev-list
))))
12619 (while (and he-expand-list
12620 (or (not (stringp (car he-expand-list
)))
12621 (he-string-member (car he-expand-list
) he-tried-table t
)))
12622 ; (equal (car he-expand-list) he-search-string)))
12623 (unless (stringp (car he-expand-list
))
12624 (setq vhdl-expand-upper-case
(car he-expand-list
)))
12625 (setq he-expand-list
(cdr he-expand-list
)))
12626 (if (null he-expand-list
)
12627 (progn (when old
(he-reset-string))
12629 (he-substitute-string
12630 (if vhdl-expand-upper-case
12631 (upcase (car he-expand-list
))
12632 (car he-expand-list
))
12634 (setq he-expand-list
(cdr he-expand-list
))
12637 (defun vhdl-he-list-beg ()
12638 "Also looks at the word before `(' in order to better match parenthesized
12639 expressions (e.g. for index ranges of types and signals)."
12642 (progn (backward-up-list 1)
12643 (skip-syntax-backward "w_")) ; crashes in `viper-mode'
12647 ;; override `he-list-beg' from `hippie-exp'
12648 (unless (and (boundp 'viper-mode
) viper-mode
)
12649 (defalias 'he-list-beg
'vhdl-he-list-beg
))
12651 ;; function for expanding abbrevs and dabbrevs
12652 (defalias 'vhdl-expand-abbrev
(make-hippie-expand-function
12653 '(try-expand-dabbrev
12654 try-expand-dabbrev-all-buffers
12655 vhdl-try-expand-abbrev
)))
12657 ;; function for expanding parenthesis
12658 (defalias 'vhdl-expand-paren
(make-hippie-expand-function
12660 try-expand-list-all-buffers
)))
12662 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12663 ;; Line handling functions
12665 (defun vhdl-current-line ()
12666 "Return the line number of the line containing point."
12669 (1+ (count-lines (point-min) (point-at-bol)))))
12671 (defun vhdl-line-kill-entire (&optional arg
)
12672 "Delete entire line."
12674 (beginning-of-line)
12675 (kill-line (or arg
1)))
12677 (defun vhdl-line-kill (&optional arg
)
12678 "Kill current line."
12680 (vhdl-line-kill-entire arg
))
12682 (defun vhdl-line-copy (&optional arg
)
12683 "Copy current line."
12686 (let ((position (point-at-bol)))
12687 (forward-line (or arg
1))
12688 (copy-region-as-kill position
(point)))))
12690 (defun vhdl-line-yank ()
12691 "Yank entire line."
12693 (beginning-of-line)
12696 (defun vhdl-line-expand (&optional prefix-arg
)
12697 "Hippie-expand current line."
12699 (require 'hippie-exp
)
12700 (let ((case-fold-search t
) (case-replace nil
)
12701 (hippie-expand-try-functions-list
12702 '(try-expand-line try-expand-line-all-buffers
)))
12703 (hippie-expand prefix-arg
)))
12705 (defun vhdl-line-transpose-next (&optional arg
)
12706 "Interchange this line with next line."
12709 (transpose-lines (or arg
1))
12712 (defun vhdl-line-transpose-previous (&optional arg
)
12713 "Interchange this line with previous line."
12716 (transpose-lines (- 0 (or arg
0)))
12719 (defun vhdl-line-open ()
12720 "Open a new line and indent."
12723 (newline-and-indent))
12725 (defun vhdl-delete-indentation ()
12726 "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
12727 it works within comments too."
12729 (let ((fill-prefix "-- "))
12730 (delete-indentation)))
12732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12735 (defun vhdl-forward-same-indent ()
12736 "Move forward to next line with same indent."
12738 (let ((pos (point))
12739 (indent (current-indentation)))
12740 (beginning-of-line 2)
12741 (while (and (not (eobp))
12742 (or (looking-at "^\\s-*\\(--.*\\)?$")
12743 (> (current-indentation) indent
)))
12744 (beginning-of-line 2))
12745 (if (= (current-indentation) indent
)
12746 (back-to-indentation)
12747 (message "No following line with same indent found in this block")
12751 (defun vhdl-backward-same-indent ()
12752 "Move backward to previous line with same indent."
12754 (let ((pos (point))
12755 (indent (current-indentation)))
12756 (beginning-of-line -
0)
12757 (while (and (not (bobp))
12758 (or (looking-at "^\\s-*\\(--.*\\)?$")
12759 (> (current-indentation) indent
)))
12760 (beginning-of-line -
0))
12761 (if (= (current-indentation) indent
)
12762 (back-to-indentation)
12763 (message "No preceding line with same indent found in this block")
12767 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12770 (defun vhdl-statistics-buffer ()
12771 "Get some file statistics."
12778 (no-lines (count-lines (point-min) (point-max))))
12780 ;; count statements
12781 (goto-char (point-min))
12782 (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t
)
12783 (if (match-string 1)
12784 (goto-char (match-end 1))
12785 (setq no-stats
(1+ no-stats
))))
12786 ;; count code lines
12787 (goto-char (point-min))
12788 (while (not (eobp))
12789 (unless (looking-at "^\\s-*\\(--.*\\)?$")
12790 (setq no-code-lines
(1+ no-code-lines
)))
12791 (beginning-of-line 2))
12792 ;; count empty lines
12793 (goto-char (point-min))
12794 (while (and (re-search-forward "^\\s-*$" nil t
)
12795 (not (eq (point) (point-max))))
12796 (if (match-string 1)
12797 (goto-char (match-end 1))
12798 (setq no-empty-lines
(1+ no-empty-lines
))
12799 (unless (eq (point) (point-max))
12801 ;; count comment-only lines
12802 (goto-char (point-min))
12803 (while (re-search-forward "^\\s-*--.*" nil t
)
12804 (if (match-string 1)
12805 (goto-char (match-end 1))
12806 (setq no-comm-lines
(1+ no-comm-lines
))))
12808 (goto-char (point-min))
12809 (while (re-search-forward "--.*" nil t
)
12810 (if (match-string 1)
12811 (goto-char (match-end 1))
12812 (setq no-comments
(1+ no-comments
)))))
12815 File statistics: \"%s\"\n\
12816 -----------------------\n\
12817 # statements : %5d\n\
12818 # code lines : %5d\n\
12819 # empty lines : %5d\n\
12820 # comment lines : %5d\n\
12821 # comments : %5d\n\
12822 # total lines : %5d\n\ "
12823 (buffer-file-name) no-stats no-code-lines no-empty-lines
12824 no-comm-lines no-comments no-lines
)
12825 (unless vhdl-emacs-21
(vhdl-show-messages))))
12827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12830 (defun vhdl-re-search-forward (regexp &optional bound noerror count
)
12831 "Like `re-search-forward', but does not match within literals."
12834 (while (and (setq pos
(re-search-forward regexp bound noerror count
))
12835 (vhdl-in-literal))))
12836 (when pos
(goto-char pos
))
12839 (defun vhdl-re-search-backward (regexp &optional bound noerror count
)
12840 "Like `re-search-backward', but does not match within literals."
12843 (while (and (setq pos
(re-search-backward regexp bound noerror count
))
12844 (vhdl-in-literal))))
12845 (when pos
(goto-char pos
))
12849 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12851 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12853 (defun vhdl-set-project (name)
12854 "Set current project to NAME."
12856 (list (let ((completion-ignore-case t
))
12857 (completing-read "Project name: " vhdl-project-alist nil t
))))
12858 (cond ((equal name
"")
12859 (setq vhdl-project nil
)
12860 (message "Current VHDL project: None"))
12861 ((assoc name vhdl-project-alist
)
12862 (setq vhdl-project name
)
12863 (message "Current VHDL project: \"%s\"" name
))
12865 (vhdl-warning (format "Unknown VHDL project: \"%s\"" name
))))
12866 (vhdl-speedbar-update-current-project))
12868 (defun vhdl-set-default-project ()
12869 "Set current project as default on startup."
12871 (customize-set-variable 'vhdl-project vhdl-project
)
12872 (customize-save-customized))
12874 (defun vhdl-toggle-project (name token indent
)
12875 "Set current project to NAME or unset if NAME is current project."
12876 (vhdl-set-project (if (equal name vhdl-project
) "" name
)))
12878 (defun vhdl-export-project (file-name)
12879 "Write project setup for current project."
12881 (let ((name (vhdl-resolve-env-variable
12882 (vhdl-replace-string
12883 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name
))
12884 (concat (subst-char-in-string
12885 ? ?_
(or (vhdl-project-p)
12886 (error "ERROR: No current project")))
12887 " " (user-login-name))))))
12888 (list (read-file-name
12889 "Write project file: "
12890 (when (file-name-absolute-p name
) "") nil nil name
))))
12891 (setq file-name
(abbreviate-file-name file-name
))
12892 (let ((orig-buffer (current-buffer)))
12893 (unless (file-exists-p (file-name-directory file-name
))
12894 (make-directory (file-name-directory file-name
) t
))
12895 (if (not (file-writable-p file-name
))
12896 (error "ERROR: File not writable: \"%s\"" file-name
)
12897 (set-buffer (find-file-noselect file-name t t
))
12899 (insert ";; -*- Emacs-Lisp -*-\n\n"
12900 ";;; " (file-name-nondirectory file-name
)
12901 " - project setup file for Emacs VHDL Mode " vhdl-version
"\n\n"
12902 ";; Project : " vhdl-project
"\n"
12903 ";; Saved : " (format-time-string "%Y-%m-%d %T ")
12904 (user-login-name) "\n\n\n"
12905 ";; project name\n"
12906 "(setq vhdl-project \"" vhdl-project
"\")\n\n"
12907 ";; project setup\n"
12908 "(aput 'vhdl-project-alist vhdl-project\n'")
12909 (pp (aget vhdl-project-alist vhdl-project
) (current-buffer))
12912 (kill-buffer (current-buffer))
12913 (set-buffer orig-buffer
))))
12915 (defun vhdl-import-project (file-name &optional auto not-make-current
)
12916 "Read project setup and set current project."
12918 (let ((name (vhdl-resolve-env-variable
12919 (vhdl-replace-string
12920 (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name
))
12921 (concat "" " " (user-login-name))))))
12922 (list (read-file-name
12923 "Read project file: " (when (file-name-absolute-p name
) "") nil t
12924 (file-name-directory name
)))))
12925 (when (file-exists-p file-name
)
12927 (let ((current-project vhdl-project
))
12928 (load-file file-name
)
12929 (when (/= (length (aget vhdl-project-alist vhdl-project t
)) 10)
12930 (adelete 'vhdl-project-alist vhdl-project
)
12932 (when not-make-current
12933 (setq vhdl-project current-project
))
12934 (vhdl-update-mode-menu)
12935 (vhdl-speedbar-refresh)
12936 (unless not-make-current
12937 (message "Current VHDL project: \"%s\"%s"
12938 vhdl-project
(if auto
" (auto-loaded)" ""))))
12939 (error (vhdl-warning
12940 (format "ERROR: Invalid project setup file: \"%s\"" file-name
))))))
12942 (defun vhdl-duplicate-project ()
12943 "Duplicate setup of current project."
12945 (let ((new-name (read-from-minibuffer "New project name: "))
12946 (project-entry (aget vhdl-project-alist vhdl-project t
)))
12947 (setq vhdl-project-alist
12948 (append vhdl-project-alist
12949 (list (cons new-name project-entry
))))
12950 (vhdl-update-mode-menu)))
12952 (defun vhdl-auto-load-project ()
12953 "Automatically load project setup at startup."
12954 (let ((file-name-list vhdl-project-file-name
)
12955 file-list list-length
)
12956 (while file-name-list
12959 (file-expand-wildcards
12960 (vhdl-resolve-env-variable
12961 (vhdl-replace-string
12962 (cons "\\(.*\\) \\(.*\\)" (car file-name-list
))
12963 (concat "\*" " " (user-login-name)))))))
12964 (setq list-length
(or list-length
(length file-list
)))
12965 (setq file-name-list
(cdr file-name-list
)))
12967 (vhdl-import-project (expand-file-name (car file-list
)) t
12968 (not (> list-length
0)))
12969 (setq list-length
(1- list-length
))
12970 (setq file-list
(cdr file-list
)))))
12972 ;; automatically load project setup when idle after startup
12973 (when (memq 'startup vhdl-project-auto-load
)
12975 (vhdl-auto-load-project)
12976 (vhdl-run-when-idle .1 nil
'vhdl-auto-load-project
)))
12979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12982 ;; (using `hideshow.el')
12984 (defconst vhdl-hs-start-regexp
12987 ;; generic/port clause
12988 "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
12991 ;; component instantiation
12992 "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
12993 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
12994 "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
12995 "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
12997 "\\(function\\|procedure\\)\\>\\|"
12999 "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
13000 ;; configuration declaration
13003 "Regexp to match start of construct to hide.")
13005 (defun vhdl-hs-forward-sexp-func (count)
13006 "Find end of construct to hide (for hideshow). Only searches forward."
13007 (let ((pos (point)))
13008 (vhdl-prepare-search-2
13009 (beginning-of-line)
13011 ;; generic/port clause
13012 ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
13013 (goto-char (match-end 0))
13016 ;; component declaration
13017 ((looking-at "^\\s-*component\\>")
13018 (re-search-forward "^\\s-*end\\s-+component\\>" nil t
))
13019 ;; component instantiation
13022 "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
13023 "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
13024 "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
13025 "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
13026 (goto-char (match-end 0))
13030 (vhdl-forward-syntactic-ws)
13031 (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
13032 (goto-char (match-end 0))
13035 (setq pos
(point)))
13037 ;; subprogram declaration/body
13038 ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
13039 (goto-char (match-end 0))
13040 (vhdl-forward-syntactic-ws)
13041 (when (looking-at "(")
13043 (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t
)
13044 (vhdl-in-literal)))
13046 (when (match-string 2)
13047 (re-search-forward "^\\s-*\\<begin\\>" nil t
)
13049 (vhdl-forward-sexp)))
13050 ;; block (recursive)
13051 ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
13052 (goto-char (match-end 0))
13053 (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t
)
13054 (match-beginning 2))
13055 (vhdl-hs-forward-sexp-func count
)))
13057 ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
13058 (re-search-forward "^\\s-*end\\s-+process\\>" nil t
))
13059 ;; configuration declaration
13060 ((looking-at "^\\s-*configuration\\>")
13062 (vhdl-forward-sexp))
13063 (t (goto-char pos
))))))
13065 (defun vhdl-hideshow-init ()
13066 "Initialize `hideshow'."
13067 (when vhdl-hideshow-menu
13068 (vhdl-hs-minor-mode 1)))
13070 (defun vhdl-hs-minor-mode (&optional arg
)
13071 "Toggle hideshow minor mode and update menu bar."
13073 (require 'hideshow
)
13074 ;; check for hideshow version 5.x
13075 (if (not (boundp 'hs-block-start-mdata-select
))
13076 (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
13077 ;; initialize hideshow
13078 (unless (assoc 'vhdl-mode hs-special-modes-alist
)
13079 (setq hs-special-modes-alist
13080 (cons (list 'vhdl-mode vhdl-hs-start-regexp nil
"--\\( \\|$\\)"
13081 'vhdl-hs-forward-sexp-func nil
)
13082 hs-special-modes-alist
)))
13083 (if (featurep 'xemacs
) (make-local-hook 'hs-minor-mode-hook
))
13084 (if vhdl-hide-all-init
13085 (add-hook 'hs-minor-mode-hook
'hs-hide-all nil t
)
13086 (remove-hook 'hs-minor-mode-hook
'hs-hide-all t
))
13087 (hs-minor-mode arg
)
13088 (force-mode-line-update))) ; hack to update menu bar
13091 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13094 ;; (using `font-lock.el')
13096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13099 (defun vhdl-within-translate-off ()
13100 "Return point if within translate-off region, else nil."
13101 (and (save-excursion
13102 (re-search-backward
13103 "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t
))
13104 (equal "off" (match-string 1))
13107 (defun vhdl-start-translate-off (limit)
13108 "Return point before translate-off pragma if before LIMIT, else nil."
13109 (when (re-search-forward
13110 "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t
)
13111 (match-beginning 0)))
13113 (defun vhdl-end-translate-off (limit)
13114 "Return point after translate-on pragma if before LIMIT, else nil."
13115 (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t
))
13117 (defun vhdl-match-translate-off (limit)
13118 "Match a translate-off block, setting match-data and returning t, else nil."
13119 (when (< (point) limit
)
13120 (let ((start (or (vhdl-within-translate-off)
13121 (vhdl-start-translate-off limit
)))
13122 (case-fold-search t
))
13124 (let ((end (or (vhdl-end-translate-off limit
) limit
)))
13125 (set-match-data (list start end
))
13126 (goto-char end
))))))
13128 (defun vhdl-font-lock-match-item (limit)
13129 "Match, and move over, any declaration item after point. Adapted from
13130 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
13131 (condition-case nil
13133 (narrow-to-region (point-min) limit
)
13135 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
13137 (goto-char (match-end 1))
13138 ;; move to next item
13139 (if (looking-at "\\(\\s-*,\\)")
13140 (goto-char (match-end 1))
13141 (end-of-line) t
))))
13144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13145 ;; Syntax definitions
13147 (defconst vhdl-font-lock-syntactic-keywords
13148 '(("\\(\'\\).\\(\'\\)" (1 (7 . ?
\')) (2 (7 . ?
\'))))
13149 "Mark single quotes as having string quote syntax in 'c' instances.")
13151 (defvar vhdl-font-lock-keywords nil
13152 "Regular expressions to highlight in VHDL Mode.")
13154 (defvar vhdl-font-lock-keywords-0
13155 ;; set in `vhdl-font-lock-init' because dependent on user options
13156 "For consideration as a value of `vhdl-font-lock-keywords'.
13157 This does highlighting of template prompts and directives (pragmas).")
13159 (defvar vhdl-font-lock-keywords-1 nil
13160 ;; set in `vhdl-font-lock-init' because dependent on user options
13161 "For consideration as a value of `vhdl-font-lock-keywords'.
13162 This does highlighting of keywords and standard identifiers.")
13164 (defconst vhdl-font-lock-keywords-2
13166 ;; highlight names of units, subprograms, and components when declared
13170 "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
13171 "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
13172 "\\)\\s-+\\(\\w+\\)")
13173 5 'font-lock-function-name-face
)
13175 ;; highlight entity names of architectures and configurations
13177 "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
13178 2 'font-lock-function-name-face
)
13180 ;; highlight labels of common constructs
13183 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
13184 "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
13185 "postponed\\|process\\|"
13186 (when (vhdl-standard-p 'ams
) "procedural\\|")
13188 "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
13189 1 'font-lock-function-name-face
)
13191 ;; highlight label and component name of component instantiations
13194 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
13195 "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
13196 '(1 font-lock-function-name-face
) '(2 font-lock-function-name-face
))
13198 ;; highlight label and instantiated unit of component instantiations
13201 "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
13202 "\\(component\\|configuration\\|entity\\)\\s-+"
13203 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
13204 '(1 font-lock-function-name-face
) '(3 font-lock-function-name-face
)
13205 '(5 font-lock-function-name-face nil t
)
13206 '(7 font-lock-function-name-face nil t
))
13208 ;; highlight names and labels at end of constructs
13211 "^\\s-*end\\s-+\\(\\("
13212 "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
13213 "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
13214 "procedure\\|\\(postponed\\s-+\\)?process\\|"
13215 (when (vhdl-standard-p 'ams
) "procedural\\|")
13217 "\\)\\s-+\\)?\\(\\w*\\)")
13218 5 'font-lock-function-name-face
)
13220 ;; highlight labels in exit and next statements
13223 "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
13224 3 'font-lock-function-name-face
)
13226 ;; highlight entity name in attribute specifications
13229 "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
13230 1 'font-lock-function-name-face
)
13232 ;; highlight labels in block and component specifications
13235 "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
13236 "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
13237 '(1 font-lock-function-name-face
) '(4 font-lock-function-name-face nil t
))
13239 ;; highlight names in library clauses
13240 (list "^\\s-*library\\>"
13241 '(vhdl-font-lock-match-item nil nil
(1 font-lock-function-name-face
)))
13243 ;; highlight names in use clauses
13246 "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
13247 "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
13248 '(3 font-lock-function-name-face
) '(5 font-lock-function-name-face nil t
)
13249 '(7 font-lock-function-name-face nil t
))
13251 ;; highlight attribute name in attribute declarations/specifications
13254 "^\\s-*attribute\\s-+\\(\\w+\\)")
13255 1 'vhdl-font-lock-attribute-face
)
13257 ;; highlight type/nature name in (sub)type/(sub)nature declarations
13260 "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
13261 5 'font-lock-type-face
)
13263 ;; highlight signal/variable/constant declaration names
13264 (list "\\(:[^=]\\)"
13265 '(vhdl-font-lock-match-item
13266 (progn (goto-char (match-beginning 1))
13267 (skip-syntax-backward " ")
13268 (skip-syntax-backward "w_")
13269 (skip-syntax-backward " ")
13270 (while (= (preceding-char) ?
,)
13272 (skip-syntax-backward " ")
13273 (skip-syntax-backward "w_")
13274 (skip-syntax-backward " ")))
13275 ; (skip-chars-backward "^-(\n\";")
13276 (goto-char (match-end 1)) (1 font-lock-variable-name-face
)))
13278 ;; highlight formal parameters in component instantiations and subprogram
13281 '(vhdl-font-lock-match-item
13282 (progn (goto-char (match-beginning 1))
13283 (skip-syntax-backward " ")
13284 (while (= (preceding-char) ?\
)) (backward-sexp))
13285 (skip-syntax-backward "w_")
13286 (skip-syntax-backward " ")
13287 (when (memq (preceding-char) '(?n ?N ?|
))
13288 (goto-char (point-max))))
13289 (goto-char (match-end 1)) (1 font-lock-variable-name-face
)))
13291 ;; highlight alias/group/quantity declaration names and for-loop/-generate
13293 (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
13294 '(vhdl-font-lock-match-item
13295 (progn (goto-char (match-end 1)) (match-beginning 2))
13296 nil
(1 font-lock-variable-name-face
)))
13298 "For consideration as a value of `vhdl-font-lock-keywords'.
13299 This does context sensitive highlighting of names and labels.")
13301 (defvar vhdl-font-lock-keywords-3 nil
13302 ;; set in `vhdl-font-lock-init' because dependent on user options
13303 "For consideration as a value of `vhdl-font-lock-keywords'.
13304 This does highlighting of words with special syntax.")
13306 (defvar vhdl-font-lock-keywords-4 nil
13307 ;; set in `vhdl-font-lock-init' because dependent on user options
13308 "For consideration as a value of `vhdl-font-lock-keywords'.
13309 This does highlighting of additional reserved words.")
13311 (defconst vhdl-font-lock-keywords-5
13312 ;; background highlight translate-off regions
13313 '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append
)))
13314 "For consideration as a value of `vhdl-font-lock-keywords'.
13315 This does background highlighting of translate-off regions.")
13317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13318 ;; Font and color definitions
13320 (defvar vhdl-font-lock-prompt-face
'vhdl-font-lock-prompt-face
13321 "Face name to use for prompts.")
13323 (defvar vhdl-font-lock-attribute-face
'vhdl-font-lock-attribute-face
13324 "Face name to use for standardized attributes.")
13326 (defvar vhdl-font-lock-enumvalue-face
'vhdl-font-lock-enumvalue-face
13327 "Face name to use for standardized enumeration values.")
13329 (defvar vhdl-font-lock-function-face
'vhdl-font-lock-function-face
13330 "Face name to use for standardized functions and packages.")
13332 (defvar vhdl-font-lock-directive-face
'vhdl-font-lock-directive-face
13333 "Face name to use for directives.")
13335 (defvar vhdl-font-lock-reserved-words-face
'vhdl-font-lock-reserved-words-face
13336 "Face name to use for additional reserved words.")
13338 (defvar vhdl-font-lock-translate-off-face
'vhdl-font-lock-translate-off-face
13339 "Face name to use for translate-off regions.")
13341 ;; face names to use for words with special syntax.
13342 (let ((syntax-alist vhdl-special-syntax-alist
)
13344 (while syntax-alist
13345 (setq name
(vhdl-function-name
13346 "vhdl-font-lock" (nth 0 (car syntax-alist
)) "face"))
13347 (eval `(defvar ,name
',name
13348 ,(concat "Face name to use for "
13349 (nth 0 (car syntax-alist
)) ".")))
13350 (setq syntax-alist
(cdr syntax-alist
))))
13352 (defgroup vhdl-highlight-faces nil
13353 "Faces for highlighting."
13354 :group
'vhdl-highlight
)
13356 ;; add faces used from `font-lock'
13357 (custom-add-to-group
13358 'vhdl-highlight-faces
'font-lock-comment-face
'custom-face
)
13359 (custom-add-to-group
13360 'vhdl-highlight-faces
'font-lock-string-face
'custom-face
)
13361 (custom-add-to-group
13362 'vhdl-highlight-faces
'font-lock-keyword-face
'custom-face
)
13363 (custom-add-to-group
13364 'vhdl-highlight-faces
'font-lock-type-face
'custom-face
)
13365 (custom-add-to-group
13366 'vhdl-highlight-faces
'font-lock-function-name-face
'custom-face
)
13367 (custom-add-to-group
13368 'vhdl-highlight-faces
'font-lock-variable-name-face
'custom-face
)
13370 (defface vhdl-font-lock-prompt-face
13371 '((((min-colors 88) (class color
) (background light
))
13372 (:foreground
"Red1" :bold t
))
13373 (((class color
) (background light
)) (:foreground
"Red" :bold t
))
13374 (((class color
) (background dark
)) (:foreground
"Pink" :bold t
))
13375 (t (:inverse-video t
)))
13376 "Font lock mode face used to highlight prompts."
13377 :group
'vhdl-highlight-faces
)
13379 (defface vhdl-font-lock-attribute-face
13380 '((((class color
) (background light
)) (:foreground
"Orchid"))
13381 (((class color
) (background dark
)) (:foreground
"LightSteelBlue"))
13382 (t (:italic t
:bold t
)))
13383 "Font lock mode face used to highlight standardized attributes."
13384 :group
'vhdl-highlight-faces
)
13386 (defface vhdl-font-lock-enumvalue-face
13387 '((((class color
) (background light
)) (:foreground
"SaddleBrown"))
13388 (((class color
) (background dark
)) (:foreground
"BurlyWood"))
13389 (t (:italic t
:bold t
)))
13390 "Font lock mode face used to highlight standardized enumeration values."
13391 :group
'vhdl-highlight-faces
)
13393 (defface vhdl-font-lock-function-face
13394 '((((class color
) (background light
)) (:foreground
"Cyan4"))
13395 (((class color
) (background dark
)) (:foreground
"Orchid1"))
13396 (t (:italic t
:bold t
)))
13397 "Font lock mode face used to highlight standardized functions and packages."
13398 :group
'vhdl-highlight-faces
)
13400 (defface vhdl-font-lock-directive-face
13401 '((((class color
) (background light
)) (:foreground
"CadetBlue"))
13402 (((class color
) (background dark
)) (:foreground
"Aquamarine"))
13403 (t (:italic t
:bold t
)))
13404 "Font lock mode face used to highlight directives."
13405 :group
'vhdl-highlight-faces
)
13407 (defface vhdl-font-lock-reserved-words-face
13408 '((((class color
) (background light
)) (:foreground
"Orange" :bold t
))
13409 (((min-colors 88) (class color
) (background dark
))
13410 (:foreground
"Yellow1" :bold t
))
13411 (((class color
) (background dark
)) (:foreground
"Yellow" :bold t
))
13413 "Font lock mode face used to highlight additional reserved words."
13414 :group
'vhdl-highlight-faces
)
13416 (defface vhdl-font-lock-translate-off-face
13417 '((((class color
) (background light
)) (:background
"LightGray"))
13418 (((class color
) (background dark
)) (:background
"DimGray"))
13420 "Font lock mode face used to background highlight translate-off regions."
13421 :group
'vhdl-highlight-faces
)
13423 ;; font lock mode faces used to highlight words with special syntax.
13424 (let ((syntax-alist vhdl-special-syntax-alist
))
13425 (while syntax-alist
13426 (eval `(defface ,(vhdl-function-name
13427 "vhdl-font-lock" (caar syntax-alist
) "face")
13428 '((((class color
) (background light
))
13429 (:foreground
,(nth 2 (car syntax-alist
))))
13430 (((class color
) (background dark
))
13431 (:foreground
,(nth 3 (car syntax-alist
))))
13433 ,(concat "Font lock mode face used to highlight "
13434 (nth 0 (car syntax-alist
)) ".")
13435 :group
'vhdl-highlight-faces
))
13436 (setq syntax-alist
(cdr syntax-alist
))))
13438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13439 ;; Font lock initialization
13441 (defun vhdl-font-lock-init ()
13442 "Initialize fontification."
13443 ;; highlight template prompts and directives
13444 (setq vhdl-font-lock-keywords-0
13445 (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
13446 vhdl-template-prompt-syntax
">\\)")
13447 2 'vhdl-font-lock-prompt-face t
)
13448 (list (concat "--\\s-*"
13449 vhdl-directive-keywords-regexp
"\\s-+\\(.*\\)$")
13450 2 'vhdl-font-lock-directive-face t
)
13451 ;; highlight c-preprocessor directives
13452 (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
13453 '(1 font-lock-builtin-face
)
13454 '(3 font-lock-variable-name-face nil t
))))
13455 ;; highlight keywords and standardized types, attributes, enumeration
13456 ;; values, and subprograms
13457 (setq vhdl-font-lock-keywords-1
13459 (list (concat "'" vhdl-attributes-regexp
)
13460 1 'vhdl-font-lock-attribute-face
)
13461 (list vhdl-types-regexp
1 'font-lock-type-face
)
13462 (list vhdl-functions-regexp
1 'vhdl-font-lock-function-face
)
13463 (list vhdl-packages-regexp
1 'vhdl-font-lock-function-face
)
13464 (list vhdl-enum-values-regexp
1 'vhdl-font-lock-enumvalue-face
)
13465 (list vhdl-constants-regexp
1 'font-lock-constant-face
)
13466 (list vhdl-keywords-regexp
1 'font-lock-keyword-face
)))
13467 ;; highlight words with special syntax.
13468 (setq vhdl-font-lock-keywords-3
13469 (let ((syntax-alist vhdl-special-syntax-alist
)
13471 (while syntax-alist
13474 (list (concat "\\(" (nth 1 (car syntax-alist
)) "\\)") 1
13475 (vhdl-function-name
13476 "vhdl-font-lock" (nth 0 (car syntax-alist
)) "face")
13477 (nth 4 (car syntax-alist
)))
13479 (setq syntax-alist
(cdr syntax-alist
)))
13481 ;; highlight additional reserved words
13482 (setq vhdl-font-lock-keywords-4
13483 (list (list vhdl-reserved-words-regexp
1
13484 'vhdl-font-lock-reserved-words-face
)))
13485 ;; highlight everything together
13486 (setq vhdl-font-lock-keywords
13488 vhdl-font-lock-keywords-0
13489 (when vhdl-highlight-keywords vhdl-font-lock-keywords-1
)
13490 (when (or vhdl-highlight-forbidden-words
13491 vhdl-highlight-verilog-keywords
) vhdl-font-lock-keywords-4
)
13492 (when vhdl-highlight-special-words vhdl-font-lock-keywords-3
)
13493 (when vhdl-highlight-names vhdl-font-lock-keywords-2
)
13494 (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5
))))
13496 ;; initialize fontification for VHDL Mode
13497 (vhdl-font-lock-init)
13499 (defun vhdl-fontify-buffer ()
13500 "Re-initialize fontification and fontify buffer."
13502 (setq font-lock-defaults
13503 `(vhdl-font-lock-keywords
13504 nil
,(not vhdl-highlight-case-sensitive
) ((?\_ .
"w"))
13505 beginning-of-line
))
13506 (when (fboundp 'font-lock-unset-defaults
)
13507 (font-lock-unset-defaults)) ; not implemented in XEmacs
13508 (font-lock-set-defaults)
13509 (font-lock-mode nil
)
13510 (font-lock-mode t
))
13512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13513 ;; Initialization for PostScript printing
13515 (defun vhdl-ps-print-settings ()
13516 "Initialize custom face and page settings for PostScript printing."
13517 ;; define custom face settings
13518 (unless (or (not vhdl-print-customize-faces
)
13520 (set (make-local-variable 'ps-bold-faces
)
13521 '(font-lock-keyword-face
13522 font-lock-type-face
13523 vhdl-font-lock-attribute-face
13524 vhdl-font-lock-enumvalue-face
13525 vhdl-font-lock-directive-face
))
13526 (set (make-local-variable 'ps-italic-faces
)
13527 '(font-lock-comment-face
13528 font-lock-function-name-face
13529 font-lock-type-face
13530 vhdl-font-lock-attribute-face
13531 vhdl-font-lock-enumvalue-face
13532 vhdl-font-lock-directive-face
))
13533 (set (make-local-variable 'ps-underlined-faces
)
13534 '(font-lock-string-face))
13535 (setq ps-always-build-face-reference t
))
13536 ;; define page settings, so that a line containing 79 characters (default)
13537 ;; fits into one column
13538 (when vhdl-print-two-column
13539 (set (make-local-variable 'ps-landscape-mode
) t
)
13540 (set (make-local-variable 'ps-number-of-columns
) 2)
13541 (set (make-local-variable 'ps-font-size
) 7.0)
13542 (set (make-local-variable 'ps-header-title-font-size
) 10.0)
13543 (set (make-local-variable 'ps-header-font-size
) 9.0)
13544 (set (make-local-variable 'ps-header-offset
) 12.0)
13545 (when (eq ps-paper-type
'letter
)
13546 (set (make-local-variable 'ps-inter-column
) 40.0)
13547 (set (make-local-variable 'ps-left-margin
) 40.0)
13548 (set (make-local-variable 'ps-right-margin
) 40.0))))
13550 (defun vhdl-ps-print-init ()
13551 "Initialize PostScript printing."
13552 (if (featurep 'xemacs
)
13553 (when (boundp 'ps-print-color-p
)
13554 (vhdl-ps-print-settings))
13555 (if (featurep 'xemacs
) (make-local-hook 'ps-print-hook
))
13556 (add-hook 'ps-print-hook
'vhdl-ps-print-settings nil t
)))
13559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13560 ;;; Hierarchy browser (using `speedbar.el')
13561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13562 ;; Allows displaying the hierarchy of all VHDL design units contained in a
13563 ;; directory by using the speedbar.
13565 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13568 (defvar vhdl-entity-alist nil
13569 "Cache with entities and corresponding architectures for each
13570 project/directory.")
13571 ;; structure: (parenthesized expression means list of such entries)
13573 ;; (ent-key ent-name ent-file ent-line
13574 ;; (arch-key arch-name arch-file arch-line
13575 ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
13576 ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
13577 ;; (lib-name pack-key))
13578 ;; mra-key (lib-name pack-key))
13580 (defvar vhdl-config-alist nil
13581 "Cache with configurations for each project/directory.")
13582 ;; structure: (parenthesized expression means list of such entries)
13584 ;; (conf-key conf-name conf-file conf-line ent-key arch-key
13585 ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
13586 ;; inst-conf-key inst-lib-key)
13587 ;; (lib-name pack-key)))
13589 (defvar vhdl-package-alist nil
13590 "Cache with packages for each project/directory.")
13591 ;; structure: (parenthesized expression means list of such entries)
13593 ;; (pack-key pack-name pack-file pack-line
13594 ;; (comp-key comp-name comp-file comp-line)
13595 ;; (func-key func-name func-file func-line)
13596 ;; (lib-name pack-key)
13597 ;; pack-body-file pack-body-line
13598 ;; (func-key func-name func-body-file func-body-line)
13599 ;; (lib-name pack-key)))
13601 (defvar vhdl-ent-inst-alist nil
13602 "Cache with instantiated entities for each project/directory.")
13603 ;; structure: (parenthesized expression means list of such entries)
13604 ;; (cache-key (inst-ent-key))
13606 (defvar vhdl-file-alist nil
13607 "Cache with design units in each file for each project/directory.")
13608 ;; structure: (parenthesized expression means list of such entries)
13610 ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
13611 ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
13613 (defvar vhdl-directory-alist nil
13614 "Cache with source directories for each project.")
13615 ;; structure: (parenthesized expression means list of such entries)
13616 ;; (cache-key (directory))
13618 (defvar vhdl-speedbar-shown-unit-alist nil
13619 "Alist of design units simultaneously open in the current speedbar for each
13620 directory and project.")
13622 (defvar vhdl-speedbar-shown-project-list nil
13623 "List of projects simultaneously open in the current speedbar.")
13625 (defvar vhdl-updated-project-list nil
13626 "List of projects and directories with updated files.")
13628 (defvar vhdl-modified-file-list nil
13629 "List of modified files to be rescanned for hierarchy updating.")
13631 (defvar vhdl-speedbar-hierarchy-depth
0
13632 "Depth of instantiation hierarchy to display.")
13634 (defvar vhdl-speedbar-show-projects nil
13635 "Non-nil means project hierarchy is displayed in speedbar, directory
13636 hierarchy otherwise.")
13638 (defun vhdl-get-end-of-unit ()
13639 "Return position of end of current unit."
13640 (let ((pos (point)))
13642 (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil
1)
13644 (goto-char (match-beginning 0))
13645 (vhdl-backward-syntactic-ws)
13646 (and (/= (preceding-char) ?\
;) (not (bobp))))))
13647 (re-search-backward "^[ \t]*end\\>" pos
1)
13650 (defun vhdl-match-string-downcase (num &optional string
)
13651 "Like `match-string-no-properties' with down-casing."
13652 (let ((match (match-string-no-properties num string
)))
13653 (and match
(downcase match
))))
13656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13659 (defun vhdl-scan-context-clause ()
13660 "Scan the context clause that precedes a design unit."
13663 (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t
)
13664 (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t
)
13665 (equal "USE" (upcase (match-string 1))))
13666 (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
13667 (push (cons (match-string-no-properties 1)
13668 (vhdl-match-string-downcase 2))
13672 (defun vhdl-scan-directory-contents (name &optional project update num-string
13674 "Scan contents of VHDL files in directory or file pattern NAME."
13675 (string-match "\\(.*[/\\]\\)\\(.*\\)" name
)
13676 ; (unless (file-directory-p (match-string 1 name))
13677 ; (message "No such directory: \"%s\"" (match-string 1 name)))
13678 (let* ((dir-name (match-string 1 name
))
13679 (file-pattern (match-string 2 name
))
13680 (is-directory (= 0 (length file-pattern
)))
13685 (vhdl-get-source-files t dir-name
)
13686 (vhdl-directory-files
13687 dir-name t
(wildcard-to-regexp file-pattern
)))))
13688 (key (or project dir-name
))
13689 (file-exclude-regexp
13690 (or (nth 3 (aget vhdl-project-alist project
)) ""))
13691 (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit
))
13692 (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit
)))
13693 (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit
)))
13694 ent-alist conf-alist pack-alist ent-inst-list file-alist
13695 tmp-list tmp-entry no-files files-exist big-files
)
13696 (when (or project update
)
13697 (setq ent-alist
(aget vhdl-entity-alist key t
)
13698 conf-alist
(aget vhdl-config-alist key t
)
13699 pack-alist
(aget vhdl-package-alist key t
)
13700 ent-inst-list
(car (aget vhdl-ent-inst-alist key t
))
13701 file-alist
(aget vhdl-file-alist key t
)))
13702 (when (and (not is-directory
) (null file-list
))
13703 (message "No such file: \"%s\"" name
))
13704 (setq files-exist file-list
)
13706 (setq no-files
(length file-list
))
13707 (message "Scanning %s %s\"%s\"..."
13708 (if is-directory
"directory" "files") (or num-string
"") name
)
13710 (unless (equal file-exclude-regexp
"")
13711 (let ((case-fold-search nil
)
13714 (unless (string-match file-exclude-regexp
(car file-list
))
13715 (push (car file-list
) file-tmp-list
))
13716 (setq file-list
(cdr file-list
)))
13717 (setq file-list
(nreverse file-tmp-list
))))
13718 ;; do for all files
13720 (unless noninteractive
13721 (message "Scanning %s %s\"%s\"... (%2d%s)"
13722 (if is-directory
"directory" "files")
13723 (or num-string
"") name
13724 (/ (* 100 (- no-files
(length file-list
))) no-files
) "%"))
13725 (let ((file-name (abbreviate-file-name (car file-list
)))
13726 ent-list arch-list arch-ent-list conf-list
13727 pack-list pack-body-list inst-list inst-ent-list
)
13731 (vhdl-prepare-search-2
13733 ;; scan for design units
13734 (if (and limit-design-file-size
13735 (< limit-design-file-size
(buffer-size)))
13736 (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name
)
13737 (setq big-files t
))
13738 ;; scan for entities
13739 (goto-char (point-min))
13740 (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
)
13741 (let* ((ent-name (match-string-no-properties 1))
13742 (ent-key (downcase ent-name
))
13743 (ent-entry (aget ent-alist ent-key t
))
13744 (lib-alist (vhdl-scan-context-clause)))
13745 (if (nth 1 ent-entry
)
13746 (vhdl-warning-when-idle
13747 "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13748 ent-name
(nth 1 ent-entry
) (nth 2 ent-entry
)
13749 file-name
(vhdl-current-line))
13750 (push ent-key ent-list
)
13751 (aput 'ent-alist ent-key
13752 (list ent-name file-name
(vhdl-current-line)
13753 (nth 3 ent-entry
) (nth 4 ent-entry
)
13755 ;; scan for architectures
13756 (goto-char (point-min))
13757 (while (re-search-forward "^[ \t]*architecture[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
)
13758 (let* ((arch-name (match-string-no-properties 1))
13759 (arch-key (downcase arch-name
))
13760 (ent-name (match-string-no-properties 2))
13761 (ent-key (downcase ent-name
))
13762 (ent-entry (aget ent-alist ent-key t
))
13763 (arch-alist (nth 3 ent-entry
))
13764 (arch-entry (aget arch-alist arch-key t
))
13765 (lib-arch-alist (vhdl-scan-context-clause)))
13767 (vhdl-warning-when-idle
13768 "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13769 arch-name ent-name
(nth 1 arch-entry
)
13770 (nth 2 arch-entry
) file-name
(vhdl-current-line))
13771 (setq arch-list
(cons arch-key arch-list
)
13772 arch-ent-list
(cons ent-key arch-ent-list
))
13773 (aput 'arch-alist arch-key
13774 (list arch-name file-name
(vhdl-current-line) nil
13776 (aput 'ent-alist ent-key
13777 (list (or (nth 0 ent-entry
) ent-name
)
13778 (nth 1 ent-entry
) (nth 2 ent-entry
)
13779 (vhdl-sort-alist arch-alist
)
13780 arch-key
(nth 5 ent-entry
))))))
13781 ;; scan for configurations
13782 (goto-char (point-min))
13783 (while (re-search-forward "^[ \t]*configuration[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
)
13784 (let* ((conf-name (match-string-no-properties 1))
13785 (conf-key (downcase conf-name
))
13786 (conf-entry (aget conf-alist conf-key t
))
13787 (ent-name (match-string-no-properties 2))
13788 (ent-key (downcase ent-name
))
13789 (lib-alist (vhdl-scan-context-clause))
13790 (conf-line (vhdl-current-line))
13791 (end-of-unit (vhdl-get-end-of-unit))
13792 arch-key comp-conf-list inst-key-list
13793 inst-comp-key inst-ent-key inst-arch-key
13794 inst-conf-key inst-lib-key
)
13795 (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
13796 (setq arch-key
(vhdl-match-string-downcase 1)))
13798 (vhdl-warning-when-idle
13799 "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13800 conf-name ent-name
(nth 1 conf-entry
)
13801 (nth 2 conf-entry
) file-name conf-line
)
13802 (push conf-key conf-list
)
13803 ;; scan for subconfigurations and subentities
13804 (while (re-search-forward "^[ \t]*for[ \t\n\r\f]+\\(\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]+" end-of-unit t
)
13805 (setq inst-comp-key
(vhdl-match-string-downcase 3)
13806 inst-key-list
(split-string
13807 (vhdl-match-string-downcase 1)
13808 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13809 (vhdl-forward-syntactic-ws)
13810 (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
13812 inst-lib-key
(vhdl-match-string-downcase 3)
13813 inst-ent-key
(and (match-string 2)
13814 (vhdl-match-string-downcase 4))
13815 inst-arch-key
(and (match-string 2)
13816 (vhdl-match-string-downcase 6))
13817 inst-conf-key
(and (not (match-string 2))
13818 (vhdl-match-string-downcase 4)))
13819 (while inst-key-list
13820 (setq comp-conf-list
13821 (cons (list (car inst-key-list
)
13822 inst-comp-key inst-ent-key
13823 inst-arch-key inst-conf-key
13826 (setq inst-key-list
(cdr inst-key-list
)))))
13827 (aput 'conf-alist conf-key
13828 (list conf-name file-name conf-line ent-key
13829 arch-key comp-conf-list lib-alist
)))))
13830 ;; scan for packages
13831 (goto-char (point-min))
13832 (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
)
13833 (let* ((pack-name (match-string-no-properties 2))
13834 (pack-key (downcase pack-name
))
13835 (is-body (match-string-no-properties 1))
13836 (pack-entry (aget pack-alist pack-key t
))
13837 (pack-line (vhdl-current-line))
13838 (end-of-unit (vhdl-get-end-of-unit))
13839 comp-name func-name comp-alist func-alist lib-alist
)
13840 (if (if is-body
(nth 6 pack-entry
) (nth 1 pack-entry
))
13841 (vhdl-warning-when-idle
13842 "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
13843 (if is-body
" body" "") pack-name
13844 (if is-body
(nth 6 pack-entry
) (nth 1 pack-entry
))
13845 (if is-body
(nth 7 pack-entry
) (nth 2 pack-entry
))
13846 file-name
(vhdl-current-line))
13847 ;; scan for context clauses
13848 (setq lib-alist
(vhdl-scan-context-clause))
13849 ;; scan for component and subprogram declarations/bodies
13850 (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t
)
13851 (if (equal (upcase (match-string 1)) "COMPONENT")
13852 (setq comp-name
(match-string-no-properties 2)
13854 (cons (list (downcase comp-name
) comp-name
13855 file-name
(vhdl-current-line))
13857 (setq func-name
(match-string-no-properties 2)
13859 (cons (list (downcase func-name
) func-name
13860 file-name
(vhdl-current-line))
13862 (setq func-alist
(nreverse func-alist
))
13863 (setq comp-alist
(nreverse comp-alist
))
13865 (push pack-key pack-body-list
)
13866 (push pack-key pack-list
))
13868 'pack-alist pack-key
13870 (list (or (nth 0 pack-entry
) pack-name
)
13871 (nth 1 pack-entry
) (nth 2 pack-entry
)
13872 (nth 3 pack-entry
) (nth 4 pack-entry
)
13874 file-name pack-line func-alist lib-alist
)
13875 (list pack-name file-name pack-line
13876 comp-alist func-alist lib-alist
13877 (nth 6 pack-entry
) (nth 7 pack-entry
)
13878 (nth 8 pack-entry
) (nth 9 pack-entry
))))))))
13879 ;; scan for hierarchy
13880 (if (and limit-hier-file-size
13881 (< limit-hier-file-size
(buffer-size)))
13882 (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name
)
13883 (setq big-files t
))
13884 ;; scan for architectures
13885 (goto-char (point-min))
13886 (while (re-search-forward "^[ \t]*architecture[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
)
13887 (let* ((ent-name (match-string-no-properties 2))
13888 (ent-key (downcase ent-name
))
13889 (arch-name (match-string-no-properties 1))
13890 (arch-key (downcase arch-name
))
13891 (ent-entry (aget ent-alist ent-key t
))
13892 (arch-alist (nth 3 ent-entry
))
13893 (arch-entry (aget arch-alist arch-key t
))
13894 (beg-of-unit (point))
13895 (end-of-unit (vhdl-get-end-of-unit))
13897 inst-alist inst-path
)
13898 ;; scan for contained instantiations
13899 (while (and (re-search-forward
13900 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
13901 "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
13902 "component[ \t\n\r\f]+\\(\\w+\\)\\|"
13903 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
13904 "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
13905 "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t
)
13906 (or (not limit-hier-inst-no
)
13907 (<= (setq inst-no
(1+ inst-no
))
13908 limit-hier-inst-no
)))
13910 ;; block/generate beginning found
13913 (cons (match-string-no-properties 1) inst-path
)))
13914 ;; block/generate end found
13916 (setq inst-path
(cdr inst-path
)))
13917 ;; instantiation found
13919 (let* ((inst-name (match-string-no-properties 1))
13920 (inst-key (downcase inst-name
))
13922 (or (match-string-no-properties 3)
13923 (match-string-no-properties 6)))
13925 (or (and (match-string 8)
13926 (vhdl-match-string-downcase 11))
13927 (and inst-comp-name
13928 (downcase inst-comp-name
))))
13929 (inst-arch-key (vhdl-match-string-downcase 13))
13931 (and (not (match-string 8))
13932 (vhdl-match-string-downcase 11)))
13933 (inst-lib-key (vhdl-match-string-downcase 10)))
13934 (goto-char (match-end 1))
13935 (setq inst-list
(cons inst-key inst-list
)
13937 (cons inst-ent-key inst-ent-list
))
13941 (list (list inst-key inst-name file-name
13942 (vhdl-current-line) inst-comp-name
13943 inst-ent-key inst-arch-key
13944 inst-conf-key inst-lib-key
13945 (reverse inst-path
)))))))))
13946 ;; scan for contained configuration specifications
13947 (goto-char beg-of-unit
)
13948 (while (re-search-forward
13949 (concat "^[ \t]*for[ \t\n\r\f]+\\(\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*"
13950 "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t
)
13951 (let* ((inst-comp-name (match-string-no-properties 3))
13953 (and (match-string 6)
13954 (vhdl-match-string-downcase 9)))
13955 (inst-arch-key (vhdl-match-string-downcase 11))
13957 (and (not (match-string 6))
13958 (vhdl-match-string-downcase 9)))
13959 (inst-lib-key (vhdl-match-string-downcase 8))
13961 (split-string (vhdl-match-string-downcase 1)
13962 "[ \t\n\r\f]*,[ \t\n\r\f]*"))
13963 (tmp-inst-alist inst-alist
)
13965 (while tmp-inst-alist
13966 (when (and (or (equal "all" (car inst-key-list
))
13967 (member (nth 0 (car tmp-inst-alist
))
13971 (or (nth 4 (car tmp-inst-alist
)) ""))
13972 (downcase inst-comp-name
)))
13973 (setq inst-entry
(car tmp-inst-alist
))
13974 (setq inst-ent-list
13975 (cons (or inst-ent-key
(nth 5 inst-entry
))
13977 (nth 5 inst-entry
) inst-ent-list
)))
13979 (list (nth 0 inst-entry
) (nth 1 inst-entry
)
13980 (nth 2 inst-entry
) (nth 3 inst-entry
)
13982 (or inst-ent-key
(nth 5 inst-entry
))
13983 (or inst-arch-key
(nth 6 inst-entry
))
13984 inst-conf-key inst-lib-key
))
13985 (setcar tmp-inst-alist inst-entry
))
13986 (setq tmp-inst-alist
(cdr tmp-inst-alist
)))))
13988 (aput 'arch-alist arch-key
13989 (list (nth 0 arch-entry
) (nth 1 arch-entry
)
13990 (nth 2 arch-entry
) inst-alist
13991 (nth 4 arch-entry
)))
13992 (aput 'ent-alist ent-key
13993 (list (nth 0 ent-entry
) (nth 1 ent-entry
)
13994 (nth 2 ent-entry
) (vhdl-sort-alist arch-alist
)
13995 (nth 4 ent-entry
) (nth 5 ent-entry
)))
13996 (when (and limit-hier-inst-no
13997 (> inst-no limit-hier-inst-no
))
13998 (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name
)
13999 (setq big-files t
))
14000 (goto-char end-of-unit
))))
14001 ;; remember design units for this file
14002 (aput 'file-alist file-name
14003 (list ent-list arch-list arch-ent-list conf-list
14004 pack-list pack-body-list inst-list inst-ent-list
))
14005 (setq ent-inst-list
(append inst-ent-list ent-inst-list
))))))
14006 (setq file-list
(cdr file-list
))))
14007 (when (or (and (not project
) files-exist
)
14008 (and project
(not non-final
)))
14009 ;; consistency checks:
14010 ;; check whether each architecture has a corresponding entity
14011 (setq tmp-list ent-alist
)
14013 (when (null (nth 2 (car tmp-list
)))
14014 (setq tmp-entry
(car (nth 4 (car tmp-list
))))
14015 (vhdl-warning-when-idle
14016 "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14017 (nth 1 tmp-entry
) (nth 1 (car tmp-list
)) (nth 2 tmp-entry
)
14018 (nth 3 tmp-entry
)))
14019 (setq tmp-list
(cdr tmp-list
)))
14020 ;; check whether configuration has a corresponding entity/architecture
14021 (setq tmp-list conf-alist
)
14023 (if (setq tmp-entry
(aget ent-alist
(nth 4 (car tmp-list
)) t
))
14024 (unless (aget (nth 3 tmp-entry
) (nth 5 (car tmp-list
)) t
)
14025 (setq tmp-entry
(car tmp-list
))
14026 (vhdl-warning-when-idle
14027 "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
14028 (nth 1 tmp-entry
) (nth 4 tmp-entry
) (nth 5 tmp-entry
)
14029 (nth 2 tmp-entry
) (nth 3 tmp-entry
)))
14030 (setq tmp-entry
(car tmp-list
))
14031 (vhdl-warning-when-idle
14032 "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
14033 (nth 1 tmp-entry
) (nth 4 tmp-entry
)
14034 (nth 2 tmp-entry
) (nth 3 tmp-entry
)))
14035 (setq tmp-list
(cdr tmp-list
)))
14036 ;; check whether each package body has a package declaration
14037 (setq tmp-list pack-alist
)
14039 (when (null (nth 2 (car tmp-list
)))
14040 (setq tmp-entry
(car tmp-list
))
14041 (vhdl-warning-when-idle
14042 "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
14043 (nth 1 tmp-entry
) (nth 7 tmp-entry
) (nth 8 tmp-entry
)))
14044 (setq tmp-list
(cdr tmp-list
)))
14046 (setq ent-alist
(vhdl-sort-alist ent-alist
))
14047 (setq conf-alist
(vhdl-sort-alist conf-alist
))
14048 (setq pack-alist
(vhdl-sort-alist pack-alist
))
14049 ;; remember updated directory/project
14050 (add-to-list 'vhdl-updated-project-list
(or project dir-name
)))
14051 ;; clear directory alists
14053 (adelete 'vhdl-entity-alist key
)
14054 (adelete 'vhdl-config-alist key
)
14055 (adelete 'vhdl-package-alist key
)
14056 (adelete 'vhdl-ent-inst-alist key
)
14057 (adelete 'vhdl-file-alist key
))
14058 ;; put directory contents into cache
14059 (aput 'vhdl-entity-alist key ent-alist
)
14060 (aput 'vhdl-config-alist key conf-alist
)
14061 (aput 'vhdl-package-alist key pack-alist
)
14062 (aput 'vhdl-ent-inst-alist key
(list ent-inst-list
))
14063 (aput 'vhdl-file-alist key file-alist
)
14065 (message "Scanning %s %s\"%s\"...done"
14066 (if is-directory
"directory" "files") (or num-string
"") name
)
14067 (unless project
(message "Scanning directory...done"))
14069 (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
14070 ;; save cache when scanned non-interactively
14071 (when (or (not project
) (not non-final
))
14072 (when (and noninteractive vhdl-speedbar-save-cache
)
14073 (vhdl-save-cache key
)))
14076 (defun vhdl-scan-project-contents (project)
14077 "Scan the contents of all VHDL files found in the directories and files
14079 (let ((dir-list (or (nth 2 (aget vhdl-project-alist project
)) '("")))
14080 (default-dir (vhdl-resolve-env-variable
14081 (nth 1 (aget vhdl-project-alist project
))))
14082 (file-exclude-regexp
14083 (or (nth 3 (aget vhdl-project-alist project
)) ""))
14084 dir-list-tmp dir dir-name num-dir act-dir recursive
)
14085 ;; clear project alists
14086 (adelete 'vhdl-entity-alist project
)
14087 (adelete 'vhdl-config-alist project
)
14088 (adelete 'vhdl-package-alist project
)
14089 (adelete 'vhdl-ent-inst-alist project
)
14090 (adelete 'vhdl-file-alist project
)
14091 ;; expand directory names by default-directory
14092 (message "Collecting source files...")
14094 (setq dir
(vhdl-resolve-env-variable (car dir-list
)))
14095 (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir
)
14096 (setq recursive
(match-string 1 dir
)
14097 dir-name
(match-string 3 dir
))
14099 (cons (concat recursive
14100 (if (file-name-absolute-p dir-name
) "" default-dir
)
14103 (setq dir-list
(cdr dir-list
)))
14104 ;; resolve path wildcards
14105 (setq dir-list-tmp
(vhdl-resolve-paths dir-list-tmp
))
14106 ;; expand directories
14107 (while dir-list-tmp
14108 (setq dir
(car dir-list-tmp
))
14109 ;; get subdirectories
14110 (if (string-match "-r \\(.*[/\\]\\)" dir
)
14111 (setq dir-list
(append dir-list
(vhdl-get-subdirs
14112 (match-string 1 dir
))))
14113 (setq dir-list
(append dir-list
(list dir
))))
14114 (setq dir-list-tmp
(cdr dir-list-tmp
)))
14116 (unless (equal file-exclude-regexp
"")
14117 (let ((case-fold-search nil
))
14119 (unless (string-match file-exclude-regexp
(car dir-list
))
14120 (push (car dir-list
) dir-list-tmp
))
14121 (setq dir-list
(cdr dir-list
)))
14122 (setq dir-list
(nreverse dir-list-tmp
))))
14123 (message "Collecting source files...done")
14124 ;; scan for design units for each directory in DIR-LIST
14125 (setq dir-list-tmp nil
14126 num-dir
(length dir-list
)
14129 (setq dir-name
(abbreviate-file-name
14130 (expand-file-name (car dir-list
))))
14131 (vhdl-scan-directory-contents dir-name project nil
14132 (format "(%s/%s) " act-dir num-dir
)
14134 (add-to-list 'dir-list-tmp
(file-name-directory dir-name
))
14135 (setq dir-list
(cdr dir-list
)
14136 act-dir
(1+ act-dir
)))
14137 (aput 'vhdl-directory-alist project
(list (nreverse dir-list-tmp
)))
14138 (message "Scanning project \"%s\"...done" project
)))
14140 (defun vhdl-update-file-contents (file-name)
14141 "Update hierarchy information by contents of current buffer."
14142 (setq file-name
(abbreviate-file-name file-name
))
14143 (let* ((dir-name (file-name-directory file-name
))
14144 (directory-alist vhdl-directory-alist
)
14146 (while directory-alist
14147 (when (member dir-name
(nth 1 (car directory-alist
)))
14148 (let* ((vhdl-project (nth 0 (car directory-alist
)))
14149 (project (vhdl-project-p))
14150 (ent-alist (aget vhdl-entity-alist
(or project dir-name
) t
))
14151 (conf-alist (aget vhdl-config-alist
(or project dir-name
) t
))
14152 (pack-alist (aget vhdl-package-alist
(or project dir-name
) t
))
14153 (ent-inst-list (car (aget vhdl-ent-inst-alist
14154 (or project dir-name
) t
)))
14155 (file-alist (aget vhdl-file-alist
(or project dir-name
) t
))
14156 (file-entry (aget file-alist file-name t
))
14157 (ent-list (nth 0 file-entry
))
14158 (arch-list (nth 1 file-entry
))
14159 (arch-ent-list (nth 2 file-entry
))
14160 (conf-list (nth 3 file-entry
))
14161 (pack-list (nth 4 file-entry
))
14162 (pack-body-list (nth 5 file-entry
))
14163 (inst-ent-list (nth 7 file-entry
))
14164 (cache-key (or project dir-name
))
14165 arch-alist key ent-key entry
)
14166 ;; delete design units previously contained in this file:
14169 (setq key
(car ent-list
)
14170 entry
(aget ent-alist key t
))
14171 (when (equal file-name
(nth 1 entry
))
14173 (aput 'ent-alist key
14174 (list (nth 0 entry
) nil nil
(nth 3 entry
) nil
))
14175 (adelete 'ent-alist key
)))
14176 (setq ent-list
(cdr ent-list
)))
14179 (setq key
(car arch-list
)
14180 ent-key
(car arch-ent-list
)
14181 entry
(aget ent-alist ent-key t
)
14182 arch-alist
(nth 3 entry
))
14183 (when (equal file-name
(nth 1 (aget arch-alist key t
)))
14184 (adelete 'arch-alist key
)
14185 (if (or (nth 1 entry
) arch-alist
)
14186 (aput 'ent-alist ent-key
14187 (list (nth 0 entry
) (nth 1 entry
) (nth 2 entry
)
14188 arch-alist
(nth 4 entry
) (nth 5 entry
)))
14189 (adelete 'ent-alist ent-key
)))
14190 (setq arch-list
(cdr arch-list
)
14191 arch-ent-list
(cdr arch-ent-list
)))
14194 (setq key
(car conf-list
))
14195 (when (equal file-name
(nth 1 (aget conf-alist key t
)))
14196 (adelete 'conf-alist key
))
14197 (setq conf-list
(cdr conf-list
)))
14198 ;; package declarations
14200 (setq key
(car pack-list
)
14201 entry
(aget pack-alist key t
))
14202 (when (equal file-name
(nth 1 entry
))
14204 (aput 'pack-alist key
14205 (list (nth 0 entry
) nil nil nil nil nil
14206 (nth 6 entry
) (nth 7 entry
) (nth 8 entry
)
14208 (adelete 'pack-alist key
)))
14209 (setq pack-list
(cdr pack-list
)))
14211 (while pack-body-list
14212 (setq key
(car pack-body-list
)
14213 entry
(aget pack-alist key t
))
14214 (when (equal file-name
(nth 6 entry
))
14216 (aput 'pack-alist key
14217 (list (nth 0 entry
) (nth 1 entry
) (nth 2 entry
)
14218 (nth 3 entry
) (nth 4 entry
) (nth 5 entry
)
14220 (adelete 'pack-alist key
)))
14221 (setq pack-body-list
(cdr pack-body-list
)))
14222 ;; instantiated entities
14223 (while inst-ent-list
14224 (setq ent-inst-list
14225 (vhdl-delete (car inst-ent-list
) ent-inst-list
))
14226 (setq inst-ent-list
(cdr inst-ent-list
)))
14228 (vhdl-aput 'vhdl-entity-alist cache-key ent-alist
)
14229 (vhdl-aput 'vhdl-config-alist cache-key conf-alist
)
14230 (vhdl-aput 'vhdl-package-alist cache-key pack-alist
)
14231 (vhdl-aput 'vhdl-ent-inst-alist cache-key
(list ent-inst-list
))
14233 (vhdl-scan-directory-contents file-name project t
)
14234 (when (or (and vhdl-speedbar-show-projects project
)
14235 (and (not vhdl-speedbar-show-projects
) (not project
)))
14236 (vhdl-speedbar-refresh project
))
14238 (setq directory-alist
(cdr directory-alist
)))
14241 (defun vhdl-update-hierarchy ()
14242 "Update directory and hierarchy information in speedbar."
14243 (let ((file-list (reverse vhdl-modified-file-list
))
14245 (when (and vhdl-speedbar-update-on-saving file-list
)
14248 (or (vhdl-update-file-contents (car file-list
))
14250 (setq file-list
(cdr file-list
)))
14251 (setq vhdl-modified-file-list nil
)
14252 (vhdl-speedbar-update-current-unit)
14253 (when updated
(message "Updating hierarchy...done")))))
14255 ;; structure (parenthesized expression means list of such entries)
14256 ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
14257 ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
14258 ;; comp-lib-name level)
14259 (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
14260 conf-inst-alist level indent
14261 &optional include-top ent-hier
)
14262 "Get instantiation hierarchy beginning in architecture ARCH-KEY of
14264 (let* ((ent-entry (aget ent-alist ent-key t
))
14265 (arch-entry (if arch-key
(aget (nth 3 ent-entry
) arch-key t
)
14266 (cdar (last (nth 3 ent-entry
)))))
14267 (inst-alist (nth 3 arch-entry
))
14268 inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
14269 hier-list subcomp-list tmp-list inst-key inst-comp-name
14270 inst-ent-key inst-arch-key inst-conf-key inst-lib-key
)
14271 (when (= level
0) (message "Extract design hierarchy..."))
14273 (setq level
(1+ level
)))
14274 (when (member ent-key ent-hier
)
14275 (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key
))
14276 ;; check configured architecture (already checked during scanning)
14277 ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
14278 ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
14279 ;; process all instances
14281 (setq inst-entry
(car inst-alist
)
14282 inst-key
(nth 0 inst-entry
)
14283 inst-comp-name
(nth 4 inst-entry
)
14284 inst-conf-key
(nth 7 inst-entry
))
14285 ;; search entry in configuration's instantiations list
14286 (setq tmp-list conf-inst-alist
)
14287 (while (and tmp-list
14288 (not (and (member (nth 0 (car tmp-list
))
14289 (list "all" inst-key
))
14290 (equal (nth 1 (car tmp-list
))
14291 (downcase (or inst-comp-name
""))))))
14292 (setq tmp-list
(cdr tmp-list
)))
14293 (setq inst-conf-key
(or (nth 4 (car tmp-list
)) inst-conf-key
))
14294 (setq inst-conf-entry
(aget conf-alist inst-conf-key t
))
14295 (when (and inst-conf-key
(not inst-conf-entry
))
14296 (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key
))
14297 ;; determine entity
14299 (or (nth 2 (car tmp-list
)) ; from configuration
14300 (nth 3 inst-conf-entry
) ; from subconfiguration
14301 (nth 3 (aget conf-alist
(nth 7 inst-entry
) t
))
14302 ; from configuration spec.
14303 (nth 5 inst-entry
))) ; from direct instantiation
14304 (setq inst-ent-entry
(aget ent-alist inst-ent-key t
))
14305 ;; determine architecture
14306 (setq inst-arch-key
14307 (or (nth 3 (car tmp-list
)) ; from configuration
14308 (nth 4 inst-conf-entry
) ; from subconfiguration
14309 (nth 6 inst-entry
) ; from direct instantiation
14310 (nth 4 (aget conf-alist
(nth 7 inst-entry
)))
14311 ; from configuration spec.
14312 (nth 4 inst-ent-entry
) ; MRA
14313 (caar (nth 3 inst-ent-entry
)))) ; first alphabetically
14314 (setq inst-arch-entry
(aget (nth 3 inst-ent-entry
) inst-arch-key t
))
14317 (or (nth 5 (car tmp-list
)) ; from configuration
14318 (nth 8 inst-entry
))) ; from direct instantiation
14319 ;; gather information for this instance
14321 (list (nth 1 inst-entry
)
14322 (cons (nth 2 inst-entry
) (nth 3 inst-entry
))
14323 (or (nth 0 inst-ent-entry
) (nth 4 inst-entry
))
14324 (cons (nth 1 inst-ent-entry
) (nth 2 inst-ent-entry
))
14325 (or (nth 0 inst-arch-entry
) inst-arch-key
)
14326 (cons (nth 1 inst-arch-entry
) (nth 2 inst-arch-entry
))
14327 (or (nth 0 inst-conf-entry
) inst-conf-key
)
14328 (cons (nth 1 inst-conf-entry
) (nth 2 inst-conf-entry
))
14329 inst-lib-key level
))
14330 ;; get subcomponent hierarchy
14331 (setq subcomp-list
(vhdl-get-hierarchy
14332 ent-alist conf-alist
14333 inst-ent-key inst-arch-key inst-conf-key
14334 (nth 5 inst-conf-entry
)
14335 (1+ level
) indent nil
(cons ent-key ent-hier
)))
14337 (setq hier-list
(append hier-list
(list comp-entry
) subcomp-list
))
14338 (setq inst-alist
(cdr inst-alist
)))
14341 (cons (list nil nil
(nth 0 ent-entry
)
14342 (cons (nth 1 ent-entry
) (nth 2 ent-entry
))
14344 (cons (nth 1 arch-entry
) (nth 2 arch-entry
))
14348 (when (or (= level
0) (and include-top
(= level
1))) (message ""))
14351 (defun vhdl-get-instantiations (ent-key indent
)
14352 "Get all instantiations of entity ENT-KEY."
14353 (let ((ent-alist (aget vhdl-entity-alist
(vhdl-speedbar-line-key indent
) t
))
14354 arch-alist inst-alist ent-inst-list
14355 ent-entry arch-entry inst-entry
)
14357 (setq ent-entry
(car ent-alist
))
14358 (setq arch-alist
(nth 4 ent-entry
))
14360 (setq arch-entry
(car arch-alist
))
14361 (setq inst-alist
(nth 4 arch-entry
))
14363 (setq inst-entry
(car inst-alist
))
14364 (when (equal ent-key
(nth 5 inst-entry
))
14365 (setq ent-inst-list
14366 (cons (list (nth 1 inst-entry
)
14367 (cons (nth 2 inst-entry
) (nth 3 inst-entry
))
14369 (cons (nth 2 ent-entry
) (nth 3 ent-entry
))
14371 (cons (nth 2 arch-entry
) (nth 3 arch-entry
)))
14373 (setq inst-alist
(cdr inst-alist
)))
14374 (setq arch-alist
(cdr arch-alist
)))
14375 (setq ent-alist
(cdr ent-alist
)))
14376 (nreverse ent-inst-list
)))
14378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14381 (defun vhdl-save-caches ()
14382 "Save all updated hierarchy caches to file."
14384 (condition-case nil
14385 (when vhdl-speedbar-save-cache
14386 ;; update hierarchy
14387 (vhdl-update-hierarchy)
14388 (let ((project-list vhdl-updated-project-list
))
14389 (message "Saving hierarchy caches...")
14390 ;; write updated project caches
14391 (while project-list
14392 (vhdl-save-cache (car project-list
))
14393 (setq project-list
(cdr project-list
)))
14394 (message "Saving hierarchy caches...done")))
14395 (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
14398 (defun vhdl-save-cache (key)
14399 "Save current hierarchy cache to file."
14400 (let* ((orig-buffer (current-buffer))
14402 (project (vhdl-project-p))
14403 (default-directory key
)
14404 (directory (abbreviate-file-name (vhdl-default-directory)))
14405 (file-name (vhdl-resolve-env-variable
14406 (vhdl-replace-string
14407 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name
)
14409 (subst-char-in-string ? ?_
(or project
"dir"))
14410 " " (user-login-name)))))
14411 (file-dir-name (expand-file-name file-name directory
))
14412 (cache-key (or project directory
))
14413 (key (if project
"project" "directory")))
14414 (unless (file-exists-p (file-name-directory file-dir-name
))
14415 (make-directory (file-name-directory file-dir-name
) t
))
14416 (if (not (file-writable-p file-dir-name
))
14417 (progn (vhdl-warning (format "File not writable: \"%s\""
14418 (abbreviate-file-name file-dir-name
)))
14420 (message "Saving cache: \"%s\"" file-dir-name
)
14421 (set-buffer (find-file-noselect file-dir-name t t
))
14423 (insert ";; -*- Emacs-Lisp -*-\n\n"
14424 ";;; " (file-name-nondirectory file-name
)
14425 " - design hierarchy cache file for Emacs VHDL Mode "
14427 (insert "\n;; " (if project
"Project " "Directory") " : ")
14428 (if project
(insert project
) (prin1 directory
(current-buffer)))
14429 (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
14430 (user-login-name) "\n\n"
14431 "\n;; version number\n"
14432 "(setq vhdl-cache-version \"" vhdl-version
"\")\n"
14433 "\n;; " (if project
"project" "directory") " name"
14434 "\n(setq " key
" ")
14435 (prin1 (or project directory
) (current-buffer))
14437 (when (member 'hierarchy vhdl-speedbar-save-cache
)
14438 (insert "\n;; entity and architecture cache\n"
14439 "(aput 'vhdl-entity-alist " key
" '")
14440 (print (aget vhdl-entity-alist cache-key t
) (current-buffer))
14441 (insert ")\n\n;; configuration cache\n"
14442 "(aput 'vhdl-config-alist " key
" '")
14443 (print (aget vhdl-config-alist cache-key t
) (current-buffer))
14444 (insert ")\n\n;; package cache\n"
14445 "(aput 'vhdl-package-alist " key
" '")
14446 (print (aget vhdl-package-alist cache-key t
) (current-buffer))
14447 (insert ")\n\n;; instantiated entities cache\n"
14448 "(aput 'vhdl-ent-inst-alist " key
" '")
14449 (print (aget vhdl-ent-inst-alist cache-key t
) (current-buffer))
14450 (insert ")\n\n;; design units per file cache\n"
14451 "(aput 'vhdl-file-alist " key
" '")
14452 (print (aget vhdl-file-alist cache-key t
) (current-buffer))
14454 (insert ")\n\n;; source directories in project cache\n"
14455 "(aput 'vhdl-directory-alist " key
" '")
14456 (print (aget vhdl-directory-alist cache-key t
) (current-buffer)))
14458 (when (member 'display vhdl-speedbar-save-cache
)
14459 (insert "\n;; shown design units cache\n"
14460 "(aput 'vhdl-speedbar-shown-unit-alist " key
" '")
14461 (print (aget vhdl-speedbar-shown-unit-alist cache-key t
)
14464 (setq vhdl-updated-project-list
14465 (delete cache-key vhdl-updated-project-list
))
14467 (kill-buffer (current-buffer))
14468 (set-buffer orig-buffer
))))
14470 (defun vhdl-load-cache (key)
14471 "Load hierarchy cache information from file."
14472 (let* ((vhdl-project key
)
14473 (default-directory key
)
14474 (directory (vhdl-default-directory))
14475 (file-name (vhdl-resolve-env-variable
14476 (vhdl-replace-string
14477 (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name
)
14479 (subst-char-in-string ? ?_
(or (vhdl-project-p) "dir"))
14480 " " (user-login-name)))))
14481 (file-dir-name (expand-file-name file-name directory
))
14482 vhdl-cache-version
)
14483 (unless (memq 'vhdl-save-caches kill-emacs-hook
)
14484 (add-hook 'kill-emacs-hook
'vhdl-save-caches
))
14485 (when (file-exists-p file-dir-name
)
14487 (progn (load-file file-dir-name
)
14488 (string< (mapconcat
14489 (lambda (a) (format "%3d" (string-to-number a
)))
14490 (split-string "3.33" "\\.") "")
14492 (lambda (a) (format "%3d" (string-to-number a
)))
14493 (split-string vhdl-cache-version
"\\.") "")))
14494 (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name
))
14497 (defun vhdl-require-hierarchy-info ()
14498 "Make sure that hierarchy information is available. Load cache or scan files
14500 (if (vhdl-project-p)
14501 (unless (or (assoc vhdl-project vhdl-file-alist
)
14502 (vhdl-load-cache vhdl-project
))
14503 (vhdl-scan-project-contents vhdl-project
))
14504 (let ((directory (abbreviate-file-name default-directory
)))
14505 (unless (or (assoc directory vhdl-file-alist
)
14506 (vhdl-load-cache directory
))
14507 (vhdl-scan-directory-contents directory
)))))
14509 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14510 ;; Add hierarchy browser functionality to speedbar
14512 (defvar vhdl-speedbar-mode-map nil
14513 "Keymap used when in the VHDL hierarchy browser mode.")
14515 (defvar vhdl-speedbar-menu-items nil
14516 "Additional menu-items to add to speedbar frame.")
14518 (defun vhdl-speedbar-initialize ()
14519 "Initialize speedbar."
14520 ;; general settings
14521 ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
14522 ;; VHDL file extensions (extracted from `auto-mode-alist')
14523 (let ((mode-alist auto-mode-alist
))
14525 (when (eq (cdar mode-alist
) 'vhdl-mode
)
14526 (speedbar-add-supported-extension (caar mode-alist
)))
14527 (setq mode-alist
(cdr mode-alist
))))
14528 ;; hierarchy browser settings
14529 (when (boundp 'speedbar-mode-functions-list
)
14530 ;; special functions
14531 (speedbar-add-mode-functions-list
14533 (speedbar-item-info . vhdl-speedbar-item-info
)
14534 (speedbar-line-directory . speedbar-files-line-path
)))
14535 (speedbar-add-mode-functions-list
14537 (speedbar-item-info . vhdl-speedbar-item-info
)
14538 (speedbar-line-directory . vhdl-speedbar-line-project
)))
14540 (unless vhdl-speedbar-mode-map
14541 (setq vhdl-speedbar-mode-map
(speedbar-make-specialized-keymap))
14542 (define-key vhdl-speedbar-mode-map
"e" 'speedbar-edit-line
)
14543 (define-key vhdl-speedbar-mode-map
"\C-m" 'speedbar-edit-line
)
14544 (define-key vhdl-speedbar-mode-map
"+" 'speedbar-expand-line
)
14545 (define-key vhdl-speedbar-mode-map
"=" 'speedbar-expand-line
)
14546 (define-key vhdl-speedbar-mode-map
"-" 'vhdl-speedbar-contract-level
)
14547 (define-key vhdl-speedbar-mode-map
"_" 'vhdl-speedbar-contract-all
)
14548 (define-key vhdl-speedbar-mode-map
"C" 'vhdl-speedbar-port-copy
)
14549 (define-key vhdl-speedbar-mode-map
"P" 'vhdl-speedbar-place-component
)
14550 (define-key vhdl-speedbar-mode-map
"F" 'vhdl-speedbar-configuration
)
14551 (define-key vhdl-speedbar-mode-map
"A" 'vhdl-speedbar-select-mra
)
14552 (define-key vhdl-speedbar-mode-map
"K" 'vhdl-speedbar-make-design
)
14553 (define-key vhdl-speedbar-mode-map
"R" 'vhdl-speedbar-rescan-hierarchy
)
14554 (define-key vhdl-speedbar-mode-map
"S" 'vhdl-save-caches
)
14557 (define-key vhdl-speedbar-mode-map
(int-to-string key
)
14558 `(lambda () (interactive) (vhdl-speedbar-set-depth ,key
)))
14559 (setq key
(1+ key
)))))
14560 (define-key speedbar-mode-map
"h"
14561 (lambda () (interactive)
14562 (speedbar-change-initial-expansion-list "vhdl directory")))
14563 (define-key speedbar-mode-map
"H"
14564 (lambda () (interactive)
14565 (speedbar-change-initial-expansion-list "vhdl project")))
14567 (unless vhdl-speedbar-menu-items
14569 vhdl-speedbar-menu-items
14570 `(["Edit" speedbar-edit-line t
]
14571 ["Expand" speedbar-expand-line
14572 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
14573 ["Contract" vhdl-speedbar-contract-level t
]
14574 ["Expand All" vhdl-speedbar-expand-all t
]
14575 ["Contract All" vhdl-speedbar-contract-all t
]
14576 ,(let ((key 0) (menu-list '("Hierarchy Depth")))
14579 (cons `[,(if (= key
0) "All" (int-to-string key
))
14580 (vhdl-speedbar-set-depth ,key
)
14582 :selected
(= vhdl-speedbar-hierarchy-depth
,key
)
14583 :keys
,(int-to-string key
)]
14585 (setq key
(1+ key
)))
14586 (nreverse menu-list
))
14588 ["Copy Port/Subprogram" vhdl-speedbar-port-copy
14589 (or (vhdl-speedbar-check-unit 'entity
)
14590 (vhdl-speedbar-check-unit 'subprogram
))]
14591 ["Place Component" vhdl-speedbar-place-component
14592 (vhdl-speedbar-check-unit 'entity
)]
14593 ["Generate Configuration" vhdl-speedbar-configuration
14594 (vhdl-speedbar-check-unit 'architecture
)]
14595 ["Select as MRA" vhdl-speedbar-select-mra
14596 (vhdl-speedbar-check-unit 'architecture
)]
14597 ["Make" vhdl-speedbar-make-design
14598 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
14599 ["Generate Makefile" vhdl-speedbar-generate-makefile
14600 (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
14601 ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
14602 :active
(save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14603 ,(if (featurep 'xemacs
) :active
:visible
) (not vhdl-speedbar-show-projects
)]
14604 ["Rescan Project" vhdl-speedbar-rescan-hierarchy
14605 :active
(save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
14606 ,(if (featurep 'xemacs
) :active
:visible
) vhdl-speedbar-show-projects
]
14607 ["Save Caches" vhdl-save-caches vhdl-updated-project-list
])))
14609 (speedbar-add-expansion-list
14610 '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14611 vhdl-speedbar-display-directory
))
14612 (speedbar-add-expansion-list
14613 '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
14614 vhdl-speedbar-display-projects
))
14615 (setq speedbar-stealthy-function-list
14617 '(("vhdl directory" vhdl-speedbar-update-current-unit
)
14618 ("vhdl project" vhdl-speedbar-update-current-project
14619 vhdl-speedbar-update-current-unit
)
14620 ; ("files" (lambda () (setq speedbar-ignored-path-regexp
14621 ; (speedbar-extension-list-to-regex
14622 ; speedbar-ignored-path-expressions))))
14624 speedbar-stealthy-function-list
))
14625 (when (eq vhdl-speedbar-display-mode
'directory
)
14626 (setq speedbar-initial-expansion-list-name
"vhdl directory"))
14627 (when (eq vhdl-speedbar-display-mode
'project
)
14628 (setq speedbar-initial-expansion-list-name
"vhdl project"))
14629 (add-hook 'speedbar-timer-hook
'vhdl-update-hierarchy
)))
14631 (defun vhdl-speedbar (&optional arg
)
14632 "Open/close speedbar."
14634 (if (not (fboundp 'speedbar
))
14635 (error "WARNING: Speedbar is not available or not installed")
14637 (speedbar-frame-mode arg
)
14638 (error (error "WARNING: An error occurred while opening speedbar")))))
14640 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14641 ;; Display functions
14643 (defvar vhdl-speedbar-last-selected-project nil
14644 "Name of last selected project.")
14646 ;; macros must be defined in the file they are used (copied from `speedbar.el')
14647 (defmacro speedbar-with-writable
(&rest forms
)
14648 "Allow the buffer to be writable and evaluate FORMS."
14649 (list 'let
'((inhibit-read-only t
))
14650 (cons 'progn forms
)))
14651 (put 'speedbar-with-writable
'lisp-indent-function
0)
14653 (defun vhdl-speedbar-display-directory (directory depth
&optional rescan
)
14654 "Display directory and hierarchy information in speedbar."
14655 (setq vhdl-speedbar-show-projects nil
)
14656 (setq speedbar-ignored-directory-regexp
14657 (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions
))
14658 (setq directory
(abbreviate-file-name (file-name-as-directory directory
)))
14659 (setq speedbar-last-selected-file nil
)
14660 (speedbar-with-writable
14661 (condition-case nil
14663 ;; insert directory path
14664 (speedbar-directory-buttons directory depth
)
14665 ;; insert subdirectories
14666 (vhdl-speedbar-insert-dirs (speedbar-file-lists directory
) depth
)
14667 ;; scan and insert hierarchy of current directory
14668 (vhdl-speedbar-insert-dir-hierarchy directory depth
14669 speedbar-power-click
)
14670 ;; expand subdirectories
14671 (when (= depth
0) (vhdl-speedbar-expand-dirs directory
)))
14672 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
14674 (defun vhdl-speedbar-display-projects (project depth
&optional rescan
)
14675 "Display projects and hierarchy information in speedbar."
14676 (setq vhdl-speedbar-show-projects t
)
14677 (setq speedbar-ignored-directory-regexp
".")
14678 (setq speedbar-last-selected-file nil
)
14679 (setq vhdl-speedbar-last-selected-project nil
)
14680 (speedbar-with-writable
14681 (condition-case nil
14683 (vhdl-speedbar-insert-projects)
14684 (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
14685 (setq speedbar-full-text-cache nil
)) ; prevent caching
14687 (defun vhdl-speedbar-insert-projects ()
14688 "Insert all projects in speedbar."
14689 (vhdl-speedbar-make-title-line "Projects:")
14690 (let ((project-alist (if vhdl-project-sort
14691 (vhdl-sort-alist (copy-alist vhdl-project-alist
))
14692 vhdl-project-alist
))
14693 (vhdl-speedbar-update-current-unit nil
))
14695 (while project-alist
14696 (speedbar-make-tag-line
14697 'angle ?
+ 'vhdl-speedbar-expand-project
14698 (caar project-alist
) (caar project-alist
)
14699 'vhdl-toggle-project
(caar project-alist
) 'speedbar-directory-face
0)
14700 (setq project-alist
(cdr project-alist
)))
14701 (setq project-alist vhdl-project-alist
)
14703 (while project-alist
14704 (when (member (caar project-alist
) vhdl-speedbar-shown-project-list
)
14705 (goto-char (point-min))
14706 (when (re-search-forward
14707 (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist
) "$") nil t
)
14708 (goto-char (match-end 1))
14709 (speedbar-do-function-pointer)))
14710 (setq project-alist
(cdr project-alist
))))
14711 ; (vhdl-speedbar-update-current-project)
14712 ; (vhdl-speedbar-update-current-unit nil t)
14715 (defun vhdl-speedbar-insert-project-hierarchy (project indent
&optional rescan
)
14716 "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
14717 otherwise use cached data."
14718 (when (or rescan
(and (not (assoc project vhdl-file-alist
))
14719 (not (vhdl-load-cache project
))))
14720 (vhdl-scan-project-contents project
))
14721 ;; insert design hierarchy
14722 (vhdl-speedbar-insert-hierarchy
14723 (aget vhdl-entity-alist project t
)
14724 (aget vhdl-config-alist project t
)
14725 (aget vhdl-package-alist project t
)
14726 (car (aget vhdl-ent-inst-alist project t
)) indent
)
14727 (insert (int-to-string indent
) ":\n")
14728 (put-text-property (- (point) 3) (1- (point)) 'invisible t
)
14729 (put-text-property (1- (point)) (point) 'invisible nil
)
14730 ;; expand design units
14731 (vhdl-speedbar-expand-units project
))
14733 (defun vhdl-speedbar-insert-dir-hierarchy (directory depth
&optional rescan
)
14734 "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
14735 otherwise use cached data."
14736 (when (or rescan
(and (not (assoc directory vhdl-file-alist
))
14737 (not (vhdl-load-cache directory
))))
14738 (vhdl-scan-directory-contents directory
))
14739 ;; insert design hierarchy
14740 (vhdl-speedbar-insert-hierarchy
14741 (aget vhdl-entity-alist directory t
)
14742 (aget vhdl-config-alist directory t
)
14743 (aget vhdl-package-alist directory t
)
14744 (car (aget vhdl-ent-inst-alist directory t
)) depth
)
14745 ;; expand design units
14746 (vhdl-speedbar-expand-units directory
)
14747 (aput 'vhdl-directory-alist directory
(list (list directory
))))
14749 (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
14750 ent-inst-list depth
)
14751 "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
14752 (if (not (or ent-alist conf-alist pack-alist
))
14753 (vhdl-speedbar-make-title-line "No VHDL design units!" depth
)
14754 (let (ent-entry conf-entry pack-entry
)
14756 (when ent-alist
(vhdl-speedbar-make-title-line "Entities:" depth
))
14758 (setq ent-entry
(car ent-alist
))
14759 (speedbar-make-tag-line
14760 'bracket ?
+ 'vhdl-speedbar-expand-entity
(nth 0 ent-entry
)
14761 (nth 1 ent-entry
) 'vhdl-speedbar-find-file
14762 (cons (nth 2 ent-entry
) (nth 3 ent-entry
))
14763 'vhdl-speedbar-entity-face depth
)
14764 (unless (nth 2 ent-entry
)
14765 (end-of-line 0) (insert "!") (forward-char 1))
14766 (unless (member (nth 0 ent-entry
) ent-inst-list
)
14767 (end-of-line 0) (insert " (top)") (forward-char 1))
14768 (setq ent-alist
(cdr ent-alist
)))
14769 ;; insert configurations
14770 (when conf-alist
(vhdl-speedbar-make-title-line "Configurations:" depth
))
14772 (setq conf-entry
(car conf-alist
))
14773 (speedbar-make-tag-line
14774 'bracket ?
+ 'vhdl-speedbar-expand-config
(nth 0 conf-entry
)
14775 (nth 1 conf-entry
) 'vhdl-speedbar-find-file
14776 (cons (nth 2 conf-entry
) (nth 3 conf-entry
))
14777 'vhdl-speedbar-configuration-face depth
)
14778 (setq conf-alist
(cdr conf-alist
)))
14780 (when pack-alist
(vhdl-speedbar-make-title-line "Packages:" depth
))
14782 (setq pack-entry
(car pack-alist
))
14783 (vhdl-speedbar-make-pack-line
14784 (nth 0 pack-entry
) (nth 1 pack-entry
)
14785 (cons (nth 2 pack-entry
) (nth 3 pack-entry
))
14786 (cons (nth 7 pack-entry
) (nth 8 pack-entry
))
14788 (setq pack-alist
(cdr pack-alist
))))))
14790 (defun vhdl-speedbar-rescan-hierarchy ()
14791 "Rescan hierarchy for the directory or project under the cursor."
14796 (vhdl-speedbar-show-projects
14797 (setq key
(vhdl-speedbar-line-project))
14798 (vhdl-scan-project-contents key
))
14799 ;; top-level directory
14800 ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
14801 (re-search-forward "[0-9]+:" nil t
)
14802 (vhdl-scan-directory-contents
14803 (abbreviate-file-name (speedbar-line-directory))))
14804 ;; current directory
14805 (t (setq path
(speedbar-line-directory))
14806 (string-match "^\\(.+[/\\]\\)" path
)
14807 (vhdl-scan-directory-contents
14808 (abbreviate-file-name (match-string 1 path
)))))
14809 (vhdl-speedbar-refresh key
)))
14811 (defun vhdl-speedbar-expand-dirs (directory)
14812 "Expand subdirectories in DIRECTORY according to
14813 `speedbar-shown-directories'."
14814 ;; (nicked from `speedbar-default-directory-list')
14815 (let ((sf (cdr (reverse speedbar-shown-directories
)))
14816 (vhdl-speedbar-update-current-unit nil
))
14817 (setq speedbar-shown-directories
14818 (list (expand-file-name default-directory
)))
14820 (when (speedbar-goto-this-file (car sf
))
14821 (beginning-of-line)
14822 (when (looking-at "[0-9]+:\\s-*<")
14823 (goto-char (match-end 0))
14824 (speedbar-do-function-pointer)))
14825 (setq sf
(cdr sf
))))
14826 (vhdl-speedbar-update-current-unit nil t
))
14828 (defun vhdl-speedbar-expand-units (key)
14829 "Expand design units in directory/project KEY according to
14830 `vhdl-speedbar-shown-unit-alist'."
14831 (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t
))
14832 (vhdl-speedbar-update-current-unit nil
)
14833 vhdl-updated-project-list
)
14834 (adelete 'vhdl-speedbar-shown-unit-alist key
)
14835 (vhdl-prepare-search-1
14836 (while unit-alist
; expand units
14837 (vhdl-speedbar-goto-this-unit key
(caar unit-alist
))
14838 (beginning-of-line)
14839 (let ((arch-alist (nth 1 (car unit-alist
)))
14841 (when (looking-at "^[0-9]+:\\s-*\\[")
14842 (goto-char (match-end 0))
14843 (setq position
(point))
14844 (speedbar-do-function-pointer)
14845 (select-frame speedbar-frame
)
14846 (while arch-alist
; expand architectures
14847 (goto-char position
)
14848 (when (re-search-forward
14849 (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
14850 (car arch-alist
) "\\>\\)") nil t
)
14851 (beginning-of-line)
14852 (when (looking-at "^[0-9]+:\\s-*{")
14853 (goto-char (match-end 0))
14854 (speedbar-do-function-pointer)
14855 (select-frame speedbar-frame
)))
14856 (setq arch-alist
(cdr arch-alist
))))
14857 (setq unit-alist
(cdr unit-alist
))))))
14858 (vhdl-speedbar-update-current-unit nil t
))
14860 (defun vhdl-speedbar-contract-level ()
14861 "Contract current level in current directory/project."
14863 (when (or (save-excursion
14864 (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
14865 (and (save-excursion
14866 (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
14867 (re-search-backward
14868 (format "^[0-%d]:\\s-*[[{<]-"
14869 (max (1- (string-to-number (match-string 1))) 0)) nil t
)))
14870 (goto-char (match-end 0))
14871 (speedbar-do-function-pointer)
14872 (speedbar-center-buffer-smartly)))
14874 (defun vhdl-speedbar-contract-all ()
14875 "Contract all expanded design units in current directory/project."
14877 (if (and vhdl-speedbar-show-projects
14878 (save-excursion (beginning-of-line) (looking-at "^0:")))
14879 (progn (setq vhdl-speedbar-shown-project-list nil
)
14880 (vhdl-speedbar-refresh))
14881 (let ((key (vhdl-speedbar-line-key)))
14882 (adelete 'vhdl-speedbar-shown-unit-alist key
)
14883 (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key
))
14884 (when (memq 'display vhdl-speedbar-save-cache
)
14885 (add-to-list 'vhdl-updated-project-list key
)))))
14887 (defun vhdl-speedbar-expand-all ()
14888 "Expand all design units in current directory/project."
14890 (let* ((key (vhdl-speedbar-line-key))
14891 (ent-alist (aget vhdl-entity-alist key t
))
14892 (conf-alist (aget vhdl-config-alist key t
))
14893 (pack-alist (aget vhdl-package-alist key t
))
14894 arch-alist unit-alist subunit-alist
)
14895 (add-to-list 'vhdl-speedbar-shown-project-list key
)
14897 (setq arch-alist
(nth 4 (car ent-alist
)))
14898 (setq subunit-alist nil
)
14900 (push (caar arch-alist
) subunit-alist
)
14901 (setq arch-alist
(cdr arch-alist
)))
14902 (push (list (caar ent-alist
) subunit-alist
) unit-alist
)
14903 (setq ent-alist
(cdr ent-alist
)))
14905 (push (list (caar conf-alist
)) unit-alist
)
14906 (setq conf-alist
(cdr conf-alist
)))
14908 (push (list (caar pack-alist
)) unit-alist
)
14909 (setq pack-alist
(cdr pack-alist
)))
14910 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
)
14911 (vhdl-speedbar-refresh)
14912 (when (memq 'display vhdl-speedbar-save-cache
)
14913 (add-to-list 'vhdl-updated-project-list key
))))
14915 (defun vhdl-speedbar-expand-project (text token indent
)
14916 "Expand/contract the project under the cursor."
14918 ((string-match "+" text
) ; expand project
14919 (speedbar-change-expand-button-char ?-
)
14920 (unless (member token vhdl-speedbar-shown-project-list
)
14921 (setq vhdl-speedbar-shown-project-list
14922 (cons token vhdl-speedbar-shown-project-list
)))
14923 (speedbar-with-writable
14925 (end-of-line) (forward-char 1)
14926 (vhdl-speedbar-insert-project-hierarchy token
(1+ indent
)
14927 speedbar-power-click
))))
14928 ((string-match "-" text
) ; contract project
14929 (speedbar-change-expand-button-char ?
+)
14930 (setq vhdl-speedbar-shown-project-list
14931 (delete token vhdl-speedbar-shown-project-list
))
14932 (speedbar-delete-subblock indent
))
14933 (t (error "Nothing to display")))
14934 (when (equal (selected-frame) speedbar-frame
)
14935 (speedbar-center-buffer-smartly)))
14937 (defun vhdl-speedbar-expand-entity (text token indent
)
14938 "Expand/contract the entity under the cursor."
14940 ((string-match "+" text
) ; expand entity
14941 (let* ((key (vhdl-speedbar-line-key indent
))
14942 (ent-alist (aget vhdl-entity-alist key t
))
14943 (ent-entry (aget ent-alist token t
))
14944 (arch-alist (nth 3 ent-entry
))
14945 (inst-alist (vhdl-get-instantiations token indent
))
14946 (subpack-alist (nth 5 ent-entry
))
14947 (multiple-arch (> (length arch-alist
) 1))
14948 arch-entry inst-entry
)
14949 (if (not (or arch-alist inst-alist subpack-alist
))
14950 (speedbar-change-expand-button-char ??
)
14951 (speedbar-change-expand-button-char ?-
)
14952 ;; add entity to `vhdl-speedbar-shown-unit-alist'
14953 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t
)))
14954 (aput 'unit-alist token nil
)
14955 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
))
14956 (speedbar-with-writable
14958 (end-of-line) (forward-char 1)
14959 ;; insert architectures
14961 (vhdl-speedbar-make-title-line "Architectures:" (1+ indent
)))
14963 (setq arch-entry
(car arch-alist
))
14964 (speedbar-make-tag-line
14965 'curly ?
+ 'vhdl-speedbar-expand-architecture
14966 (cons token
(nth 0 arch-entry
))
14967 (nth 1 arch-entry
) 'vhdl-speedbar-find-file
14968 (cons (nth 2 arch-entry
) (nth 3 arch-entry
))
14969 'vhdl-speedbar-architecture-face
(1+ indent
))
14970 (when (and multiple-arch
14971 (equal (nth 0 arch-entry
) (nth 4 ent-entry
)))
14972 (end-of-line 0) (insert " (mra)") (forward-char 1))
14973 (setq arch-alist
(cdr arch-alist
)))
14974 ;; insert instantiations
14976 (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent
)))
14978 (setq inst-entry
(car inst-alist
))
14979 (vhdl-speedbar-make-inst-line
14980 (nth 0 inst-entry
) (nth 1 inst-entry
) (nth 2 inst-entry
)
14981 (nth 3 inst-entry
) (nth 4 inst-entry
) (nth 5 inst-entry
)
14982 nil nil nil
(1+ indent
) 0 " in ")
14983 (setq inst-alist
(cdr inst-alist
)))
14984 ;; insert required packages
14985 (vhdl-speedbar-insert-subpackages
14986 subpack-alist
(1+ indent
) indent
)))
14987 (when (memq 'display vhdl-speedbar-save-cache
)
14988 (add-to-list 'vhdl-updated-project-list key
))
14989 (vhdl-speedbar-update-current-unit t t
))))
14990 ((string-match "-" text
) ; contract entity
14991 (speedbar-change-expand-button-char ?
+)
14992 ;; remove entity from `vhdl-speedbar-shown-unit-alist'
14993 (let* ((key (vhdl-speedbar-line-key indent
))
14994 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t
)))
14995 (adelete 'unit-alist token
)
14997 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
)
14998 (adelete 'vhdl-speedbar-shown-unit-alist key
))
14999 (speedbar-delete-subblock indent
)
15000 (when (memq 'display vhdl-speedbar-save-cache
)
15001 (add-to-list 'vhdl-updated-project-list key
))))
15002 (t (error "Nothing to display")))
15003 (when (equal (selected-frame) speedbar-frame
)
15004 (speedbar-center-buffer-smartly)))
15006 (defun vhdl-speedbar-expand-architecture (text token indent
)
15007 "Expand/contract the architecture under the cursor."
15009 ((string-match "+" text
) ; expand architecture
15010 (let* ((key (vhdl-speedbar-line-key (1- indent
)))
15011 (ent-alist (aget vhdl-entity-alist key t
))
15012 (conf-alist (aget vhdl-config-alist key t
))
15013 (hier-alist (vhdl-get-hierarchy
15014 ent-alist conf-alist
(car token
) (cdr token
) nil nil
15016 (ent-entry (aget ent-alist
(car token
) t
))
15017 (arch-entry (aget (nth 3 ent-entry
) (cdr token
) t
))
15018 (subpack-alist (nth 4 arch-entry
))
15020 (if (not (or hier-alist subpack-alist
))
15021 (speedbar-change-expand-button-char ??
)
15022 (speedbar-change-expand-button-char ?-
)
15023 ;; add architecture to `vhdl-speedbar-shown-unit-alist'
15024 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t
))
15025 (arch-alist (nth 0 (aget unit-alist
(car token
) t
))))
15026 (aput 'unit-alist
(car token
) (list (cons (cdr token
) arch-alist
)))
15027 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
))
15028 (speedbar-with-writable
15030 (end-of-line) (forward-char 1)
15031 ;; insert instance hierarchy
15033 (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
15036 (setq entry
(car hier-alist
))
15037 (when (or (= vhdl-speedbar-hierarchy-depth
0)
15038 (< (nth 9 entry
) vhdl-speedbar-hierarchy-depth
))
15039 (vhdl-speedbar-make-inst-line
15040 (nth 0 entry
) (nth 1 entry
) (nth 2 entry
) (nth 3 entry
)
15041 (nth 4 entry
) (nth 5 entry
) (nth 6 entry
) (nth 7 entry
)
15042 (nth 8 entry
) (1+ indent
) (1+ (nth 9 entry
)) ": "))
15043 (setq hier-alist
(cdr hier-alist
)))
15044 ;; insert required packages
15045 (vhdl-speedbar-insert-subpackages
15046 subpack-alist
(1+ indent
) (1- indent
))))
15047 (when (memq 'display vhdl-speedbar-save-cache
)
15048 (add-to-list 'vhdl-updated-project-list key
))
15049 (vhdl-speedbar-update-current-unit t t
))))
15050 ((string-match "-" text
) ; contract architecture
15051 (speedbar-change-expand-button-char ?
+)
15052 ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
15053 (let* ((key (vhdl-speedbar-line-key (1- indent
)))
15054 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t
))
15055 (arch-alist (nth 0 (aget unit-alist
(car token
) t
))))
15056 (aput 'unit-alist
(car token
) (list (delete (cdr token
) arch-alist
)))
15057 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
)
15058 (speedbar-delete-subblock indent
)
15059 (when (memq 'display vhdl-speedbar-save-cache
)
15060 (add-to-list 'vhdl-updated-project-list key
))))
15061 (t (error "Nothing to display")))
15062 (when (equal (selected-frame) speedbar-frame
)
15063 (speedbar-center-buffer-smartly)))
15065 (defun vhdl-speedbar-expand-config (text token indent
)
15066 "Expand/contract the configuration under the cursor."
15068 ((string-match "+" text
) ; expand configuration
15069 (let* ((key (vhdl-speedbar-line-key indent
))
15070 (conf-alist (aget vhdl-config-alist key t
))
15071 (conf-entry (aget conf-alist token
))
15072 (ent-alist (aget vhdl-entity-alist key t
))
15073 (hier-alist (vhdl-get-hierarchy
15074 ent-alist conf-alist
(nth 3 conf-entry
)
15075 (nth 4 conf-entry
) token
(nth 5 conf-entry
)
15077 (subpack-alist (nth 6 conf-entry
))
15079 (if (not (or hier-alist subpack-alist
))
15080 (speedbar-change-expand-button-char ??
)
15081 (speedbar-change-expand-button-char ?-
)
15082 ;; add configuration to `vhdl-speedbar-shown-unit-alist'
15083 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t
)))
15084 (aput 'unit-alist token nil
)
15085 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
))
15086 (speedbar-with-writable
15088 (end-of-line) (forward-char 1)
15089 ;; insert instance hierarchy
15091 (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent
)))
15093 (setq entry
(car hier-alist
))
15094 (when (or (= vhdl-speedbar-hierarchy-depth
0)
15095 (<= (nth 9 entry
) vhdl-speedbar-hierarchy-depth
))
15096 (vhdl-speedbar-make-inst-line
15097 (nth 0 entry
) (nth 1 entry
) (nth 2 entry
) (nth 3 entry
)
15098 (nth 4 entry
) (nth 5 entry
) (nth 6 entry
) (nth 7 entry
)
15099 (nth 8 entry
) (1+ indent
) (nth 9 entry
) ": "))
15100 (setq hier-alist
(cdr hier-alist
)))
15101 ;; insert required packages
15102 (vhdl-speedbar-insert-subpackages
15103 subpack-alist
(1+ indent
) indent
)))
15104 (when (memq 'display vhdl-speedbar-save-cache
)
15105 (add-to-list 'vhdl-updated-project-list key
))
15106 (vhdl-speedbar-update-current-unit t t
))))
15107 ((string-match "-" text
) ; contract configuration
15108 (speedbar-change-expand-button-char ?
+)
15109 ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
15110 (let* ((key (vhdl-speedbar-line-key indent
))
15111 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t
)))
15112 (adelete 'unit-alist token
)
15114 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
)
15115 (adelete 'vhdl-speedbar-shown-unit-alist key
))
15116 (speedbar-delete-subblock indent
)
15117 (when (memq 'display vhdl-speedbar-save-cache
)
15118 (add-to-list 'vhdl-updated-project-list key
))))
15119 (t (error "Nothing to display")))
15120 (when (equal (selected-frame) speedbar-frame
)
15121 (speedbar-center-buffer-smartly)))
15123 (defun vhdl-speedbar-expand-package (text token indent
)
15124 "Expand/contract the package under the cursor."
15126 ((string-match "+" text
) ; expand package
15127 (let* ((key (vhdl-speedbar-line-key indent
))
15128 (pack-alist (aget vhdl-package-alist key t
))
15129 (pack-entry (aget pack-alist token t
))
15130 (comp-alist (nth 3 pack-entry
))
15131 (func-alist (nth 4 pack-entry
))
15132 (func-body-alist (nth 8 pack-entry
))
15133 (subpack-alist (append (nth 5 pack-entry
) (nth 9 pack-entry
)))
15134 comp-entry func-entry func-body-entry
)
15135 (if (not (or comp-alist func-alist subpack-alist
))
15136 (speedbar-change-expand-button-char ??
)
15137 (speedbar-change-expand-button-char ?-
)
15138 ;; add package to `vhdl-speedbar-shown-unit-alist'
15139 (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t
)))
15140 (aput 'unit-alist token nil
)
15141 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
))
15142 (speedbar-with-writable
15144 (end-of-line) (forward-char 1)
15145 ;; insert components
15147 (vhdl-speedbar-make-title-line "Components:" (1+ indent
)))
15149 (setq comp-entry
(car comp-alist
))
15150 (speedbar-make-tag-line
15152 (cons token
(nth 0 comp-entry
))
15153 (nth 1 comp-entry
) 'vhdl-speedbar-find-file
15154 (cons (nth 2 comp-entry
) (nth 3 comp-entry
))
15155 'vhdl-speedbar-entity-face
(1+ indent
))
15156 (setq comp-alist
(cdr comp-alist
)))
15157 ;; insert subprograms
15159 (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent
)))
15161 (setq func-entry
(car func-alist
)
15162 func-body-entry
(aget func-body-alist
(car func-entry
) t
))
15163 (when (nth 2 func-entry
)
15164 (vhdl-speedbar-make-subprogram-line
15166 (cons (nth 2 func-entry
) (nth 3 func-entry
))
15167 (cons (nth 1 func-body-entry
) (nth 2 func-body-entry
))
15169 (setq func-alist
(cdr func-alist
)))
15170 ;; insert required packages
15171 (vhdl-speedbar-insert-subpackages
15172 subpack-alist
(1+ indent
) indent
)))
15173 (when (memq 'display vhdl-speedbar-save-cache
)
15174 (add-to-list 'vhdl-updated-project-list key
))
15175 (vhdl-speedbar-update-current-unit t t
))))
15176 ((string-match "-" text
) ; contract package
15177 (speedbar-change-expand-button-char ?
+)
15178 ;; remove package from `vhdl-speedbar-shown-unit-alist'
15179 (let* ((key (vhdl-speedbar-line-key indent
))
15180 (unit-alist (aget vhdl-speedbar-shown-unit-alist key t
)))
15181 (adelete 'unit-alist token
)
15183 (aput 'vhdl-speedbar-shown-unit-alist key unit-alist
)
15184 (adelete 'vhdl-speedbar-shown-unit-alist key
))
15185 (speedbar-delete-subblock indent
)
15186 (when (memq 'display vhdl-speedbar-save-cache
)
15187 (add-to-list 'vhdl-updated-project-list key
))))
15188 (t (error "Nothing to display")))
15189 (when (equal (selected-frame) speedbar-frame
)
15190 (speedbar-center-buffer-smartly)))
15192 (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent
)
15193 "Insert required packages."
15194 (let* ((pack-alist (aget vhdl-package-alist
15195 (vhdl-speedbar-line-key dir-indent
) t
))
15196 pack-key lib-name pack-entry
)
15197 (when subpack-alist
15198 (vhdl-speedbar-make-title-line "Packages Used:" indent
))
15199 (while subpack-alist
15200 (setq pack-key
(cdar subpack-alist
)
15201 lib-name
(caar subpack-alist
))
15202 (setq pack-entry
(aget pack-alist pack-key t
))
15203 (vhdl-speedbar-make-subpack-line
15204 (or (nth 0 pack-entry
) pack-key
) lib-name
15205 (cons (nth 1 pack-entry
) (nth 2 pack-entry
))
15206 (cons (nth 6 pack-entry
) (nth 7 pack-entry
)) indent
)
15207 (setq subpack-alist
(cdr subpack-alist
)))))
15209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15210 ;; Display help functions
15212 (defvar vhdl-speedbar-update-current-unit t
15213 "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
15215 (defun vhdl-speedbar-update-current-project ()
15216 "Highlight project that is currently active."
15217 (when (and vhdl-speedbar-show-projects
15218 (not (equal vhdl-speedbar-last-selected-project vhdl-project
))
15219 (and (boundp 'speedbar-frame
)
15220 (frame-live-p speedbar-frame
)))
15221 (let ((last-frame (selected-frame))
15222 (project-alist vhdl-project-alist
)
15224 (select-frame speedbar-frame
)
15225 (speedbar-with-writable
15227 (while project-alist
15228 (goto-char (point-min))
15229 (when (re-search-forward
15230 (concat "<.> \\(" (caar project-alist
) "\\)$") nil t
)
15231 (put-text-property (match-beginning 1) (match-end 1) 'face
15232 (if (equal (caar project-alist
) vhdl-project
)
15233 'speedbar-selected-face
15234 'speedbar-directory-face
))
15235 (when (equal (caar project-alist
) vhdl-project
)
15236 (setq pos
(1- (match-beginning 1)))))
15237 (setq project-alist
(cdr project-alist
))))
15238 (when pos
(goto-char pos
)))
15239 (select-frame last-frame
)
15240 (setq vhdl-speedbar-last-selected-project vhdl-project
)))
15243 (defun vhdl-speedbar-update-current-unit (&optional no-position always
)
15244 "Highlight all design units that are contained in the current file.
15245 NO-POSITION non-nil means do not re-position cursor."
15246 (let ((last-frame (selected-frame))
15247 (project-list vhdl-speedbar-shown-project-list
)
15248 file-alist pos file-name
)
15249 ;; get current file name
15250 (if (fboundp 'speedbar-select-attached-frame
)
15251 (speedbar-select-attached-frame)
15252 (select-frame speedbar-attached-frame
))
15253 (setq file-name
(abbreviate-file-name (or (buffer-file-name) "")))
15254 (when (and vhdl-speedbar-update-current-unit
15255 (or always
(not (equal file-name speedbar-last-selected-file
))))
15256 (if vhdl-speedbar-show-projects
15257 (while project-list
15258 (setq file-alist
(append file-alist
(aget vhdl-file-alist
15259 (car project-list
) t
)))
15260 (setq project-list
(cdr project-list
)))
15261 (setq file-alist
(aget vhdl-file-alist
15262 (abbreviate-file-name default-directory
) t
)))
15263 (select-frame speedbar-frame
)
15264 (set-buffer speedbar-buffer
)
15265 (speedbar-with-writable
15266 (vhdl-prepare-search-1
15268 ;; unhighlight last units
15269 (let* ((file-entry (aget file-alist speedbar-last-selected-file t
)))
15270 (vhdl-speedbar-update-units
15271 "\\[.\\] " (nth 0 file-entry
)
15272 speedbar-last-selected-file
'vhdl-speedbar-entity-face
)
15273 (vhdl-speedbar-update-units
15274 "{.} " (nth 1 file-entry
)
15275 speedbar-last-selected-file
'vhdl-speedbar-architecture-face
)
15276 (vhdl-speedbar-update-units
15277 "\\[.\\] " (nth 3 file-entry
)
15278 speedbar-last-selected-file
'vhdl-speedbar-configuration-face
)
15279 (vhdl-speedbar-update-units
15280 "[]>] " (nth 4 file-entry
)
15281 speedbar-last-selected-file
'vhdl-speedbar-package-face
)
15282 (vhdl-speedbar-update-units
15283 "\\[.\\].+(" '("body")
15284 speedbar-last-selected-file
'vhdl-speedbar-package-face
)
15285 (vhdl-speedbar-update-units
15286 "> " (nth 6 file-entry
)
15287 speedbar-last-selected-file
'vhdl-speedbar-instantiation-face
))
15288 ;; highlight current units
15289 (let* ((file-entry (aget file-alist file-name t
)))
15291 pos
(vhdl-speedbar-update-units
15292 "\\[.\\] " (nth 0 file-entry
)
15293 file-name
'vhdl-speedbar-entity-selected-face pos
)
15294 pos
(vhdl-speedbar-update-units
15295 "{.} " (nth 1 file-entry
)
15296 file-name
'vhdl-speedbar-architecture-selected-face pos
)
15297 pos
(vhdl-speedbar-update-units
15298 "\\[.\\] " (nth 3 file-entry
)
15299 file-name
'vhdl-speedbar-configuration-selected-face pos
)
15300 pos
(vhdl-speedbar-update-units
15301 "[]>] " (nth 4 file-entry
)
15302 file-name
'vhdl-speedbar-package-selected-face pos
)
15303 pos
(vhdl-speedbar-update-units
15304 "\\[.\\].+(" '("body")
15305 file-name
'vhdl-speedbar-package-selected-face pos
)
15306 pos
(vhdl-speedbar-update-units
15307 "> " (nth 6 file-entry
)
15308 file-name
'vhdl-speedbar-instantiation-selected-face pos
))))))
15309 ;; move speedbar so the first highlighted unit is visible
15310 (when (and pos
(not no-position
))
15312 (speedbar-center-buffer-smartly)
15313 (speedbar-position-cursor-on-line))
15314 (setq speedbar-last-selected-file file-name
))
15315 (select-frame last-frame
)
15318 (defun vhdl-speedbar-update-units (text unit-list file-name face
15320 "Help function to highlight design units."
15322 (goto-char (point-min))
15323 (while (re-search-forward
15324 (concat text
"\\(" (car unit-list
) "\\)\\>") nil t
)
15325 (when (equal file-name
(car (get-text-property
15326 (match-beginning 1) 'speedbar-token
)))
15327 (setq pos
(or pos
(point-marker)))
15328 (put-text-property (match-beginning 1) (match-end 1) 'face face
)))
15329 (setq unit-list
(cdr unit-list
)))
15332 (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
15333 ent-name ent-file-marker
15334 arch-name arch-file-marker
15335 conf-name conf-file-marker
15336 lib-name depth offset delimiter
)
15337 "Insert instantiation entry."
15338 (let ((start (point))
15340 (insert (int-to-string depth
) ":")
15341 (put-text-property start
(point) 'invisible t
)
15342 (setq visible-start
(point))
15343 (insert-char ?
(* depth speedbar-indentation-width
))
15344 (while (> offset
0)
15346 (insert-char (if (= offset
1) ?- ?
) (1- speedbar-indentation-width
))
15347 (setq offset
(1- offset
)))
15348 (put-text-property visible-start
(point) 'invisible nil
)
15349 (setq start
(point))
15351 (speedbar-make-button start
(point) nil nil nil
)
15352 (setq visible-start
(point))
15354 (setq start
(point))
15355 (if (not inst-name
)
15358 (speedbar-make-button
15359 start
(point) 'vhdl-speedbar-instantiation-face
'speedbar-highlight-face
15360 'vhdl-speedbar-find-file inst-file-marker
))
15363 (setq start
(point))
15365 (speedbar-make-button
15366 start
(point) 'vhdl-speedbar-entity-face
'speedbar-highlight-face
15367 'vhdl-speedbar-find-file ent-file-marker
)
15370 (setq start
(point))
15372 (speedbar-make-button
15373 start
(point) 'vhdl-speedbar-architecture-face
'speedbar-highlight-face
15374 'vhdl-speedbar-find-file arch-file-marker
)
15378 (setq start
(point))
15380 (speedbar-make-button
15381 start
(point) 'vhdl-speedbar-configuration-face
'speedbar-highlight-face
15382 'vhdl-speedbar-find-file conf-file-marker
)
15384 (when (and lib-name
(not (equal lib-name
(downcase (vhdl-work-library)))))
15385 (setq start
(point))
15386 (insert " (" lib-name
")")
15387 (put-text-property (+ 2 start
) (1- (point)) 'face
15388 'vhdl-speedbar-library-face
))
15389 (insert-char ?
\n 1)
15390 (put-text-property visible-start
(point) 'invisible nil
)))
15392 (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
15393 body-file-marker depth
)
15394 "Insert package entry."
15395 (let ((start (point))
15397 (insert (int-to-string depth
) ":")
15398 (put-text-property start
(point) 'invisible t
)
15399 (setq visible-start
(point))
15400 (insert-char ?
(* depth speedbar-indentation-width
))
15401 (put-text-property visible-start
(point) 'invisible nil
)
15402 (setq start
(point))
15404 (speedbar-make-button
15405 start
(point) 'speedbar-button-face
'speedbar-highlight-face
15406 'vhdl-speedbar-expand-package pack-key
)
15407 (setq visible-start
(point))
15408 (insert-char ?
1 nil
)
15409 (setq start
(point))
15411 (speedbar-make-button
15412 start
(point) 'vhdl-speedbar-package-face
'speedbar-highlight-face
15413 'vhdl-speedbar-find-file pack-file-marker
)
15414 (unless (car pack-file-marker
)
15416 (when (car body-file-marker
)
15418 (setq start
(point))
15420 (speedbar-make-button
15421 start
(point) 'vhdl-speedbar-package-face
'speedbar-highlight-face
15422 'vhdl-speedbar-find-file body-file-marker
)
15424 (insert-char ?
\n 1)
15425 (put-text-property visible-start
(point) 'invisible nil
)))
15427 (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
15428 pack-body-file-marker depth
)
15429 "Insert used package entry."
15430 (let ((start (point))
15432 (insert (int-to-string depth
) ":")
15433 (put-text-property start
(point) 'invisible t
)
15434 (setq visible-start
(point))
15435 (insert-char ?
(* depth speedbar-indentation-width
))
15436 (put-text-property visible-start
(point) 'invisible nil
)
15437 (setq start
(point))
15439 (speedbar-make-button start
(point) nil nil nil
)
15440 (setq visible-start
(point))
15442 (setq start
(point))
15444 (speedbar-make-button
15445 start
(point) 'vhdl-speedbar-package-face
'speedbar-highlight-face
15446 'vhdl-speedbar-find-file pack-file-marker
)
15447 (when (car pack-body-file-marker
)
15449 (setq start
(point))
15451 (speedbar-make-button
15452 start
(point) 'vhdl-speedbar-package-face
'speedbar-highlight-face
15453 'vhdl-speedbar-find-file pack-body-file-marker
)
15455 (setq start
(point))
15456 (insert " (" lib-name
")")
15457 (put-text-property (+ 2 start
) (1- (point)) 'face
15458 'vhdl-speedbar-library-face
)
15459 (insert-char ?
\n 1)
15460 (put-text-property visible-start
(point) 'invisible nil
)))
15462 (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
15463 func-body-file-marker
15465 "Insert subprogram entry."
15466 (let ((start (point))
15468 (insert (int-to-string depth
) ":")
15469 (put-text-property start
(point) 'invisible t
)
15470 (setq visible-start
(point))
15471 (insert-char ?
(* depth speedbar-indentation-width
))
15472 (put-text-property visible-start
(point) 'invisible nil
)
15473 (setq start
(point))
15475 (speedbar-make-button start
(point) nil nil nil
)
15476 (setq visible-start
(point))
15478 (setq start
(point))
15480 (speedbar-make-button
15481 start
(point) 'vhdl-speedbar-subprogram-face
'speedbar-highlight-face
15482 'vhdl-speedbar-find-file func-file-marker
)
15483 (when (car func-body-file-marker
)
15485 (setq start
(point))
15487 (speedbar-make-button
15488 start
(point) 'vhdl-speedbar-subprogram-face
'speedbar-highlight-face
15489 'vhdl-speedbar-find-file func-body-file-marker
)
15491 (insert-char ?
\n 1)
15492 (put-text-property visible-start
(point) 'invisible nil
)))
15494 (defun vhdl-speedbar-make-title-line (text &optional depth
)
15495 "Insert design unit title entry."
15496 (let ((start (point))
15499 (insert (int-to-string depth
) ":")
15500 (put-text-property start
(point) 'invisible t
))
15501 (setq visible-start
(point))
15502 (insert-char ?
(* (or depth
0) speedbar-indentation-width
))
15503 (setq start
(point))
15505 (speedbar-make-button start
(point) nil nil nil nil
)
15506 (insert-char ?
\n 1)
15507 (put-text-property visible-start
(point) 'invisible nil
)))
15509 (defun vhdl-speedbar-insert-dirs (files level
)
15510 "Insert subdirectories."
15511 (let ((dirs (car files
)))
15513 (speedbar-make-tag-line 'angle ?
+ 'vhdl-speedbar-dired
(car dirs
)
15514 (car dirs
) 'speedbar-dir-follow nil
15515 'speedbar-directory-face level
)
15516 (setq dirs
(cdr dirs
)))))
15518 (defun vhdl-speedbar-dired (text token indent
)
15519 "Speedbar click handler for directory expand button in hierarchy mode."
15520 (cond ((string-match "+" text
) ; we have to expand this dir
15521 (setq speedbar-shown-directories
15522 (cons (expand-file-name
15523 (concat (speedbar-line-directory indent
) token
"/"))
15524 speedbar-shown-directories
))
15525 (speedbar-change-expand-button-char ?-
)
15526 (speedbar-reset-scanners)
15527 (speedbar-with-writable
15529 (end-of-line) (forward-char 1)
15530 (vhdl-speedbar-insert-dirs
15531 (speedbar-file-lists
15532 (concat (speedbar-line-directory indent
) token
"/"))
15534 (speedbar-reset-scanners)
15535 (vhdl-speedbar-insert-dir-hierarchy
15536 (abbreviate-file-name
15537 (concat (speedbar-line-directory indent
) token
"/"))
15538 (1+ indent
) speedbar-power-click
)))
15539 (vhdl-speedbar-update-current-unit t t
))
15540 ((string-match "-" text
) ; we have to contract this node
15541 (speedbar-reset-scanners)
15542 (let ((oldl speedbar-shown-directories
)
15544 (td (expand-file-name
15545 (concat (speedbar-line-directory indent
) token
))))
15547 (if (not (string-match (concat "^" (regexp-quote td
)) (car oldl
)))
15548 (push (car oldl
) newl
))
15549 (setq oldl
(cdr oldl
)))
15550 (setq speedbar-shown-directories
(nreverse newl
)))
15551 (speedbar-change-expand-button-char ?
+)
15552 (speedbar-delete-subblock indent
))
15553 (t (error "Nothing to display")))
15554 (when (equal (selected-frame) speedbar-frame
)
15555 (speedbar-center-buffer-smartly)))
15557 (defun vhdl-speedbar-item-info ()
15558 "Derive and display information about this line item."
15560 (beginning-of-line)
15561 ;; skip invisible number info
15562 (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
15564 ;; project/directory entry
15565 ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
15566 (if vhdl-speedbar-show-projects
15567 (message "Project \"%s\"" (match-string-no-properties 1))
15568 (speedbar-files-item-info)))
15569 ;; design unit entry
15570 ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
15571 (goto-char (match-end 1))
15572 (let ((face (get-text-property (point) 'face
)))
15574 "%s \"%s\" in \"%s\""
15575 ;; design unit kind
15576 (cond ((or (eq face
'vhdl-speedbar-entity-face
)
15577 (eq face
'vhdl-speedbar-entity-selected-face
))
15578 (if (equal (match-string 2) ">") "Component" "Entity"))
15579 ((or (eq face
'vhdl-speedbar-architecture-face
)
15580 (eq face
'vhdl-speedbar-architecture-selected-face
))
15582 ((or (eq face
'vhdl-speedbar-configuration-face
)
15583 (eq face
'vhdl-speedbar-configuration-selected-face
))
15585 ((or (eq face
'vhdl-speedbar-package-face
)
15586 (eq face
'vhdl-speedbar-package-selected-face
))
15588 ((or (eq face
'vhdl-speedbar-instantiation-face
)
15589 (eq face
'vhdl-speedbar-instantiation-selected-face
))
15591 ((eq face
'vhdl-speedbar-subprogram-face
)
15594 ;; design unit name
15595 (buffer-substring-no-properties
15596 (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
15599 (file-relative-name
15600 (or (car (get-text-property (point) 'speedbar-token
))
15602 (vhdl-default-directory)))))
15603 (t (message "")))))
15605 (defun vhdl-speedbar-line-text ()
15606 "Calls `speedbar-line-text' and removes text properties."
15607 (let ((string (speedbar-line-text)))
15608 (set-text-properties 0 (length string
) nil string
)
15611 (defun vhdl-speedbar-higher-text ()
15612 "Get speedbar-line-text of higher level."
15613 (let (depth string
)
15615 (beginning-of-line)
15616 (looking-at "^\\([0-9]+\\):")
15617 (setq depth
(string-to-number (match-string 1)))
15618 (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth
)) nil t
)
15619 (setq string
(match-string 1))
15620 (set-text-properties 0 (length string
) nil string
)
15623 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15626 (defun vhdl-speedbar-line-key (&optional indent
)
15627 "Get currently displayed directory of project name."
15628 (if vhdl-speedbar-show-projects
15629 (vhdl-speedbar-line-project)
15630 (abbreviate-file-name
15631 (file-name-as-directory (speedbar-line-directory indent
)))))
15633 (defun vhdl-speedbar-line-project (&optional indent
)
15634 "Get currently displayed project name."
15635 (and vhdl-speedbar-show-projects
15638 (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t
)
15639 (match-string-no-properties 1))))
15641 (defun vhdl-add-modified-file ()
15642 "Add file to `vhdl-modified-file-list'."
15643 (when vhdl-file-alist
15644 (add-to-list 'vhdl-modified-file-list
(buffer-file-name)))
15647 (defun vhdl-resolve-paths (path-list)
15648 "Resolve path wildcards in PATH-LIST."
15649 (let (path-list-1 path-list-2 path-beg path-end dir
)
15650 ;; eliminate non-existent directories
15652 (setq dir
(car path-list
))
15653 (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir
)
15654 (if (file-directory-p (match-string 2 dir
))
15655 (push dir path-list-1
)
15656 (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir
)))
15657 (setq path-list
(cdr path-list
)))
15658 ;; resolve path wildcards
15660 (setq dir
(car path-list-1
))
15661 (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir
)
15663 (setq path-beg
(match-string 1 dir
)
15664 path-end
(match-string 5 dir
))
15669 (lambda (var) (concat path-beg var path-end
)))
15670 (let ((all-list (vhdl-directory-files
15671 (match-string 2 dir
) t
15672 (concat "\\<" (wildcard-to-regexp
15673 (match-string 4 dir
)))))
15676 (when (file-directory-p (car all-list
))
15677 (push (car all-list
) dir-list
))
15678 (setq all-list
(cdr all-list
)))
15680 (cdr path-list-1
))))
15681 (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir
)
15682 (when (file-directory-p (match-string 2 dir
))
15683 (push dir path-list-2
))
15684 (setq path-list-1
(cdr path-list-1
))))
15685 (nreverse path-list-2
)))
15687 (defun vhdl-speedbar-goto-this-unit (directory unit
)
15688 "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
15689 (let ((dest (point)))
15690 (if (and (if vhdl-speedbar-show-projects
15691 (progn (goto-char (point-min)) t
)
15692 (speedbar-goto-this-file directory
))
15693 (re-search-forward (concat "[]}] " unit
"\\>") nil t
))
15694 (progn (speedbar-position-cursor-on-line)
15699 (defun vhdl-speedbar-find-file (text token indent
)
15700 "When user clicks on TEXT, load file with name and position in TOKEN.
15701 Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
15702 is already shown in a buffer."
15703 (if (not (car token
))
15704 (error "ERROR: File cannot be found")
15705 (let ((buffer (get-file-buffer (car token
))))
15706 (speedbar-find-file-in-frame (car token
))
15707 (when (or vhdl-speedbar-jump-to-unit buffer
)
15708 (vhdl-goto-line (cdr token
))
15710 (vhdl-speedbar-update-current-unit t t
)
15711 (speedbar-set-timer dframe-update-speed
)
15712 (speedbar-maybee-jump-to-attached-frame))))
15714 (defun vhdl-speedbar-port-copy ()
15715 "Copy the port of the entity/component or subprogram under the cursor."
15717 (let ((is-entity (vhdl-speedbar-check-unit 'entity
)))
15718 (if (not (or is-entity
(vhdl-speedbar-check-unit 'subprogram
)))
15719 (error "ERROR: No entity/component or subprogram under cursor")
15720 (beginning-of-line)
15721 (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
15722 (condition-case info
15723 (let ((token (get-text-property
15724 (match-beginning 3) 'speedbar-token
)))
15725 (vhdl-visit-file (car token
) t
15726 (progn (vhdl-goto-line (cdr token
))
15730 (vhdl-subprog-copy)))))
15731 (error (error "ERROR: %s not scanned successfully\n (%s)"
15732 (if is-entity
"Port" "Interface") (cadr info
))))
15733 (error "ERROR: No entity/component or subprogram on current line")))))
15735 (defun vhdl-speedbar-place-component ()
15736 "Place the entity/component under the cursor as component."
15738 (if (not (vhdl-speedbar-check-unit 'entity
))
15739 (error "ERROR: No entity/component under cursor")
15740 (vhdl-speedbar-port-copy)
15741 (if (fboundp 'speedbar-select-attached-frame
)
15742 (speedbar-select-attached-frame)
15743 (select-frame speedbar-attached-frame
))
15744 (vhdl-compose-place-component)
15745 (select-frame speedbar-frame
)))
15747 (defun vhdl-speedbar-configuration ()
15748 "Generate configuration for the architecture under the cursor."
15750 (if (not (vhdl-speedbar-check-unit 'architecture
))
15751 (error "ERROR: No architecture under cursor")
15752 (let ((arch-name (vhdl-speedbar-line-text))
15753 (ent-name (vhdl-speedbar-higher-text)))
15754 (if (fboundp 'speedbar-select-attached-frame
)
15755 (speedbar-select-attached-frame)
15756 (select-frame speedbar-attached-frame
))
15757 (vhdl-compose-configuration ent-name arch-name
))))
15759 (defun vhdl-speedbar-select-mra ()
15760 "Select the architecture under the cursor as MRA."
15762 (if (not (vhdl-speedbar-check-unit 'architecture
))
15763 (error "ERROR: No architecture under cursor")
15764 (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
15765 (ent-key (downcase (vhdl-speedbar-higher-text)))
15766 (ent-alist (aget vhdl-entity-alist
15767 (or (vhdl-project-p) default-directory
) t
))
15768 (ent-entry (aget ent-alist ent-key t
)))
15769 (setcar (cddr (cddr ent-entry
)) arch-key
) ; (nth 4 ent-entry)
15770 (speedbar-refresh))))
15772 (defun vhdl-speedbar-make-design ()
15773 "Make (compile) design unit or directory/project under the cursor."
15775 (if (not (save-excursion (beginning-of-line)
15776 (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
15777 (error "ERROR: No primary design unit or directory/project under cursor")
15778 (let ((is-unit (match-string 2))
15779 (unit-name (vhdl-speedbar-line-text))
15780 (vhdl-project (vhdl-speedbar-line-project))
15781 (directory (file-name-as-directory
15782 (or (speedbar-line-file) (speedbar-line-directory)))))
15783 (if (fboundp 'speedbar-select-attached-frame
)
15784 (speedbar-select-attached-frame)
15785 (select-frame speedbar-attached-frame
))
15786 (let ((default-directory directory
))
15787 (vhdl-make (and is-unit unit-name
))))))
15789 (defun vhdl-speedbar-generate-makefile ()
15790 "Generate Makefile for directory/project under the cursor."
15792 (let ((vhdl-project (vhdl-speedbar-line-project))
15793 (default-directory (file-name-as-directory
15794 (or (speedbar-line-file) (speedbar-line-directory)))))
15795 (vhdl-generate-makefile)))
15797 (defun vhdl-speedbar-check-unit (design-unit)
15798 "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
15799 expansion function)."
15801 (speedbar-position-cursor-on-line)
15802 (cond ((eq design-unit
'entity
)
15803 (memq (get-text-property (match-end 0) 'face
)
15804 '(vhdl-speedbar-entity-face
15805 vhdl-speedbar-entity-selected-face
)))
15806 ((eq design-unit
'architecture
)
15807 (memq (get-text-property (match-end 0) 'face
)
15808 '(vhdl-speedbar-architecture-face
15809 vhdl-speedbar-architecture-selected-face
)))
15810 ((eq design-unit
'subprogram
)
15811 (eq (get-text-property (match-end 0) 'face
)
15812 'vhdl-speedbar-subprogram-face
))
15815 (defun vhdl-speedbar-set-depth (depth)
15816 "Set hierarchy display depth to DEPTH and refresh speedbar."
15817 (setq vhdl-speedbar-hierarchy-depth depth
)
15818 (speedbar-refresh))
15820 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15823 (defface vhdl-speedbar-entity-face
15824 '((((class color
) (background light
)) (:foreground
"ForestGreen"))
15825 (((class color
) (background dark
)) (:foreground
"PaleGreen")))
15826 "Face used for displaying entity names."
15827 :group
'speedbar-faces
)
15829 (defface vhdl-speedbar-architecture-face
15830 '((((min-colors 88) (class color
) (background light
)) (:foreground
"Blue1"))
15831 (((class color
) (background light
)) (:foreground
"Blue"))
15833 (((class color
) (background dark
)) (:foreground
"LightSkyBlue")))
15834 "Face used for displaying architecture names."
15835 :group
'speedbar-faces
)
15837 (defface vhdl-speedbar-configuration-face
15838 '((((class color
) (background light
)) (:foreground
"DarkGoldenrod"))
15839 (((class color
) (background dark
)) (:foreground
"Salmon")))
15840 "Face used for displaying configuration names."
15841 :group
'speedbar-faces
)
15843 (defface vhdl-speedbar-package-face
15844 '((((class color
) (background light
)) (:foreground
"Grey50"))
15845 (((class color
) (background dark
)) (:foreground
"Grey80")))
15846 "Face used for displaying package names."
15847 :group
'speedbar-faces
)
15849 (defface vhdl-speedbar-library-face
15850 '((((class color
) (background light
)) (:foreground
"Purple"))
15851 (((class color
) (background dark
)) (:foreground
"Orchid1")))
15852 "Face used for displaying library names."
15853 :group
'speedbar-faces
)
15855 (defface vhdl-speedbar-instantiation-face
15856 '((((class color
) (background light
)) (:foreground
"Brown"))
15857 (((min-colors 88) (class color
) (background dark
)) (:foreground
"Yellow1"))
15858 (((class color
) (background dark
)) (:foreground
"Yellow")))
15859 "Face used for displaying instantiation names."
15860 :group
'speedbar-faces
)
15862 (defface vhdl-speedbar-subprogram-face
15863 '((((class color
) (background light
)) (:foreground
"Orchid4"))
15864 (((class color
) (background dark
)) (:foreground
"BurlyWood2")))
15865 "Face used for displaying subprogram names."
15866 :group
'speedbar-faces
)
15868 (defface vhdl-speedbar-entity-selected-face
15869 '((((class color
) (background light
)) (:foreground
"ForestGreen" :underline t
))
15870 (((class color
) (background dark
)) (:foreground
"PaleGreen" :underline t
)))
15871 "Face used for displaying entity names."
15872 :group
'speedbar-faces
)
15874 (defface vhdl-speedbar-architecture-selected-face
15875 '((((min-colors 88) (class color
) (background light
)) (:foreground
15876 "Blue1" :underline t
))
15877 (((class color
) (background light
)) (:foreground
"Blue" :underline t
))
15878 (((class color
) (background dark
)) (:foreground
"LightSkyBlue" :underline t
)))
15879 "Face used for displaying architecture names."
15880 :group
'speedbar-faces
)
15882 (defface vhdl-speedbar-configuration-selected-face
15883 '((((class color
) (background light
)) (:foreground
"DarkGoldenrod" :underline t
))
15884 (((class color
) (background dark
)) (:foreground
"Salmon" :underline t
)))
15885 "Face used for displaying configuration names."
15886 :group
'speedbar-faces
)
15888 (defface vhdl-speedbar-package-selected-face
15889 '((((class color
) (background light
)) (:foreground
"Grey50" :underline t
))
15890 (((class color
) (background dark
)) (:foreground
"Grey80" :underline t
)))
15891 "Face used for displaying package names."
15892 :group
'speedbar-faces
)
15894 (defface vhdl-speedbar-instantiation-selected-face
15895 '((((class color
) (background light
)) (:foreground
"Brown" :underline t
))
15896 (((class color
) (background dark
)) (:foreground
"Yellow" :underline t
)))
15897 "Face used for displaying instantiation names."
15898 :group
'speedbar-faces
)
15900 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15904 (when (fboundp 'speedbar
)
15906 (when (and vhdl-speedbar-auto-open
15907 (not (and (boundp 'speedbar-frame
)
15908 (frame-live-p speedbar-frame
))))
15909 (speedbar-frame-mode 1)
15910 (if (fboundp 'speedbar-select-attached-frame
)
15911 (speedbar-select-attached-frame)
15912 (select-frame speedbar-attached-frame
)))
15913 (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
15915 ;; initialize speedbar
15916 (if (not (boundp 'speedbar-frame
))
15917 (add-hook 'speedbar-load-hook
'vhdl-speedbar-initialize
)
15918 (vhdl-speedbar-initialize)
15919 (when speedbar-frame
(vhdl-speedbar-refresh)))
15922 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15923 ;;; Structural composition
15924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15926 (defun vhdl-get-components-package-name ()
15927 "Return the name of the components package."
15928 (let ((project (vhdl-project-p)))
15930 (vhdl-replace-string (car vhdl-components-package-name
)
15931 (subst-char-in-string ? ?_ project
))
15932 (cdr vhdl-components-package-name
))))
15934 (defun vhdl-compose-new-component ()
15935 "Create entity and architecture for new component."
15937 (let* ((case-fold-search t
)
15938 (ent-name (read-from-minibuffer "entity name: "
15939 nil vhdl-minibuffer-local-map
))
15941 (if (equal (cdr vhdl-compose-architecture-name
) "")
15942 (read-from-minibuffer "architecture name: "
15943 nil vhdl-minibuffer-local-map
)
15944 (vhdl-replace-string vhdl-compose-architecture-name ent-name
)))
15945 ent-file-name arch-file-name ent-buffer arch-buffer project end-pos
)
15946 (message "Creating component \"%s(%s)\"..." ent-name arch-name
)
15947 ;; open entity file
15948 (unless (eq vhdl-compose-create-files
'none
)
15949 (setq ent-file-name
15950 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t
)
15951 "." (file-name-extension (buffer-file-name))))
15952 (when (and (file-exists-p ent-file-name
)
15953 (not (y-or-n-p (concat "File \"" ent-file-name
15954 "\" exists; overwrite? "))))
15955 (error "ERROR: Creating component...aborted"))
15956 (find-file ent-file-name
)
15958 (set-buffer-modified-p nil
))
15960 (if vhdl-compose-include-header
15961 (progn (vhdl-template-header)
15962 (setq end-pos
(point))
15963 (goto-char (point-max)))
15964 (vhdl-comment-display-line) (insert "\n\n"))
15965 ;; insert library clause
15966 (vhdl-template-package-std-logic-1164)
15967 (when vhdl-use-components-package
15969 (vhdl-template-standard-package (vhdl-work-library)
15970 (vhdl-get-components-package-name)))
15971 (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
15972 ;; insert entity declaration
15973 (vhdl-insert-keyword "ENTITY ") (insert ent-name
)
15974 (vhdl-insert-keyword " IS\n")
15975 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
15976 (indent-to vhdl-basic-offset
) (vhdl-insert-keyword "GENERIC (\n")
15977 (indent-to (* 2 vhdl-basic-offset
)) (insert ");\n")
15978 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
15979 (indent-to vhdl-basic-offset
) (vhdl-insert-keyword "PORT (\n")
15980 (indent-to (* 2 vhdl-basic-offset
)) (insert ");\n")
15981 (when (memq vhdl-insert-empty-lines
'(unit all
)) (insert "\n"))
15982 (vhdl-insert-keyword "END ")
15983 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
15984 (insert ent-name
";\n\n")
15985 (vhdl-comment-display-line) (insert "\n")
15986 ;; open architecture file
15987 (if (not (eq vhdl-compose-create-files
'separate
))
15989 (goto-char (or end-pos
(point-min)))
15990 (setq ent-buffer
(current-buffer))
15991 (setq arch-file-name
15992 (concat (vhdl-replace-string vhdl-architecture-file-name
15993 (concat ent-name
" " arch-name
) t
)
15994 "." (file-name-extension (buffer-file-name))))
15995 (when (and (file-exists-p arch-file-name
)
15996 (not (y-or-n-p (concat "File \"" arch-file-name
15997 "\" exists; overwrite? "))))
15998 (error "ERROR: Creating component...aborted"))
15999 (find-file arch-file-name
)
16001 (set-buffer-modified-p nil
)
16003 (if vhdl-compose-include-header
16004 (progn (vhdl-template-header)
16005 (goto-char (point-max)))
16006 (vhdl-comment-display-line) (insert "\n\n")))
16007 ;; insert architecture body
16008 (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name
)
16009 (vhdl-insert-keyword " OF ") (insert ent-name
)
16010 (vhdl-insert-keyword " IS\n\n")
16011 (indent-to vhdl-basic-offset
) (vhdl-comment-display-line) (insert "\n")
16012 (indent-to vhdl-basic-offset
) (insert "-- Internal signal declarations\n")
16013 (indent-to vhdl-basic-offset
) (vhdl-comment-display-line) (insert "\n\n")
16014 (unless (or vhdl-use-components-package
(vhdl-use-direct-instantiation))
16015 (indent-to vhdl-basic-offset
) (vhdl-comment-display-line) (insert "\n")
16016 (indent-to vhdl-basic-offset
) (insert "-- Component declarations\n")
16017 (indent-to vhdl-basic-offset
) (vhdl-comment-display-line) (insert "\n\n"))
16018 (vhdl-insert-keyword "BEGIN")
16019 (when vhdl-self-insert-comments
16021 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16022 (insert arch-name
))
16024 (indent-to vhdl-basic-offset
) (vhdl-comment-display-line) (insert "\n")
16025 (indent-to vhdl-basic-offset
) (insert "-- Component instantiations\n")
16026 (indent-to vhdl-basic-offset
) (vhdl-comment-display-line) (insert "\n\n")
16027 (vhdl-insert-keyword "END ")
16028 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
16029 (insert arch-name
";\n\n")
16030 ;; insert footer and save
16031 (if (and vhdl-compose-include-header
(not (equal vhdl-file-footer
"")))
16032 (vhdl-template-footer)
16033 (vhdl-comment-display-line) (insert "\n"))
16034 (goto-char (or end-pos
(point-min)))
16035 (setq arch-buffer
(current-buffer))
16036 (when ent-buffer
(set-buffer ent-buffer
) (save-buffer))
16037 (set-buffer arch-buffer
) (save-buffer)
16039 (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name
)
16041 (format "\n File created: \"%s\"" ent-file-name
))
16042 (and arch-file-name
16043 (format "\n File created: \"%s\"" arch-file-name
))))))
16045 (defun vhdl-compose-place-component ()
16046 "Place new component by pasting current port as component declaration and
16047 component instantiation."
16049 (if (not vhdl-port-list
)
16050 (error "ERROR: No port has been read")
16052 (vhdl-prepare-search-2
16053 (unless (or (re-search-backward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
)
16054 (re-search-forward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
))
16055 (error "ERROR: No architecture found"))
16056 (let* ((ent-name (match-string 1))
16058 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t
)
16059 "." (file-name-extension (buffer-file-name))))
16060 (orig-buffer (current-buffer)))
16061 (message "Placing component \"%s\"..." (nth 0 vhdl-port-list
))
16062 ;; place component declaration
16063 (unless (or vhdl-use-components-package
16064 (vhdl-use-direct-instantiation)
16067 (concat "^\\s-*component\\s-+"
16068 (car vhdl-port-list
) "\\>") nil t
)))
16069 (re-search-forward "^begin\\>" nil
)
16070 (beginning-of-line)
16071 (skip-chars-backward " \t\n\r\f")
16072 (insert "\n\n") (indent-to vhdl-basic-offset
)
16073 (vhdl-port-paste-component t
))
16074 ;; place component instantiation
16075 (re-search-forward "^end\\>" nil
)
16076 (beginning-of-line)
16077 (skip-chars-backward " \t\n\r\f")
16078 (insert "\n\n") (indent-to vhdl-basic-offset
)
16079 (vhdl-port-paste-instance nil t t
)
16080 ;; place use clause for used packages
16081 (when (nth 3 vhdl-port-list
)
16082 ;; open entity file
16083 (when (file-exists-p ent-file-name
)
16084 (find-file ent-file-name
))
16085 (goto-char (point-min))
16086 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name
"[ \t\n\r\f]+is\\>") nil t
)
16087 (error "ERROR: Entity not found: \"%s\"" ent-name
))
16088 (goto-char (match-beginning 0))
16089 (if (and (save-excursion
16090 (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t
))
16092 (progn (goto-char (match-end 0))
16093 (beginning-of-line 2))
16096 (vhdl-port-paste-context-clause)
16097 (switch-to-buffer orig-buffer
))
16098 (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list
)))))))
16100 (defun vhdl-compose-wire-components ()
16101 "Connect components."
16104 (vhdl-prepare-search-2
16105 (unless (or (re-search-backward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
)
16106 (re-search-forward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t
))
16107 (error "ERROR: No architecture found"))
16108 (let* ((ent-name (match-string 1))
16110 (concat (vhdl-replace-string vhdl-entity-file-name ent-name t
)
16111 "." (file-name-extension (buffer-file-name))))
16112 (arch-decl-pos (point-marker))
16113 (arch-stat-pos (re-search-forward "^begin\\>" nil
))
16114 (arch-end-pos (re-search-forward "^end\\>" nil
))
16115 (pack-name (vhdl-get-components-package-name))
16117 (concat (vhdl-replace-string vhdl-package-file-name pack-name t
)
16118 "." (file-name-extension (buffer-file-name))))
16119 inst-name comp-name comp-ent-name comp-ent-file-name has-generic
16120 port-alist generic-alist inst-alist
16121 signal-name signal-entry signal-alist local-list written-list
16122 single-in-list multi-in-list single-out-list multi-out-list
16123 constant-name constant-entry constant-alist single-list multi-list
16124 port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
16125 generic-beg-pos generic-pos generic-inst-pos generic-end-pos
16126 signal-beg-pos signal-pos
16127 constant-temp-pos port-temp-pos signal-temp-pos
)
16128 (message "Wiring components...")
16129 ;; process all instances
16130 (goto-char arch-stat-pos
)
16131 (while (re-search-forward
16132 (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
16133 "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
16134 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
16135 "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
16136 "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\)[ \t\n\r\f]*(") arch-end-pos t
)
16137 (setq inst-name
(match-string-no-properties 1)
16138 comp-name
(match-string-no-properties 4)
16139 comp-ent-name
(match-string-no-properties 12)
16140 has-generic
(or (match-string 7) (match-string 17)))
16143 ;; ... from component declaration
16145 (when vhdl-use-components-package pack-file-name
) t
16147 (goto-char (point-min))
16148 (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name
"\\>") nil t
)
16149 (error "ERROR: Component declaration not found: \"%s\"" comp-name
))
16151 ;; ... from entity declaration (direct instantiation)
16152 (setq comp-ent-file-name
16153 (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t
)
16154 "." (file-name-extension (buffer-file-name))))
16156 comp-ent-file-name t
16158 (goto-char (point-min))
16159 (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name
"\\>") nil t
)
16160 (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name
))
16161 (vhdl-port-copy))))
16162 (vhdl-port-flatten t
)
16163 (setq generic-alist
(nth 1 vhdl-port-list
)
16164 port-alist
(nth 2 vhdl-port-list
)
16165 vhdl-port-list nil
)
16166 (setq constant-alist nil
16169 ;; process all constants in generic map
16170 (vhdl-forward-syntactic-ws)
16171 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t
)
16172 (setq constant-name
(match-string-no-properties 3))
16173 (setq constant-entry
16174 (cons constant-name
16175 (if (match-string 1)
16176 (or (aget generic-alist
(match-string 2) t
)
16177 (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name
))
16178 (cdar generic-alist
))))
16179 (push constant-entry constant-alist
)
16180 (setq constant-name
(downcase constant-name
))
16181 (if (or (member constant-name single-list
)
16182 (member constant-name multi-list
))
16183 (progn (setq single-list
(delete constant-name single-list
))
16184 (add-to-list 'multi-list constant-name
))
16185 (add-to-list 'single-list constant-name
))
16186 (unless (match-string 1)
16187 (setq generic-alist
(cdr generic-alist
)))
16188 (vhdl-forward-syntactic-ws))
16189 (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t
))
16190 ;; process all signals in port map
16191 (vhdl-forward-syntactic-ws)
16192 (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t
)
16193 (setq signal-name
(match-string-no-properties 3))
16194 (setq signal-entry
(cons signal-name
16195 (if (match-string 1)
16196 (or (aget port-alist
(match-string 2) t
)
16197 (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name
))
16198 (cdar port-alist
))))
16199 (push signal-entry signal-alist
)
16200 (setq signal-name
(downcase signal-name
))
16201 (if (equal (upcase (nth 2 signal-entry
)) "IN")
16204 ((member signal-name local-list
)
16206 ((or (member signal-name single-out-list
)
16207 (member signal-name multi-out-list
))
16208 (setq single-out-list
(delete signal-name single-out-list
))
16209 (setq multi-out-list
(delete signal-name multi-out-list
))
16210 (add-to-list 'local-list signal-name
))
16211 ((member signal-name single-in-list
)
16212 (setq single-in-list
(delete signal-name single-in-list
))
16213 (add-to-list 'multi-in-list signal-name
))
16214 ((not (member signal-name multi-in-list
))
16215 (add-to-list 'single-in-list signal-name
)))
16218 ((member signal-name local-list
)
16220 ((or (member signal-name single-in-list
)
16221 (member signal-name multi-in-list
))
16222 (setq single-in-list
(delete signal-name single-in-list
))
16223 (setq multi-in-list
(delete signal-name multi-in-list
))
16224 (add-to-list 'local-list signal-name
))
16225 ((member signal-name single-out-list
)
16226 (setq single-out-list
(delete signal-name single-out-list
))
16227 (add-to-list 'multi-out-list signal-name
))
16228 ((not (member signal-name multi-out-list
))
16229 (add-to-list 'single-out-list signal-name
))))
16230 (unless (match-string 1)
16231 (setq port-alist
(cdr port-alist
)))
16232 (vhdl-forward-syntactic-ws))
16233 (push (list inst-name
(nreverse constant-alist
)
16234 (nreverse signal-alist
)) inst-alist
))
16235 ;; prepare signal insertion
16236 (vhdl-goto-marker arch-decl-pos
)
16238 (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t
)
16239 (setq signal-pos
(point-marker))
16240 (while (progn (vhdl-forward-syntactic-ws)
16241 (looking-at "signal\\>"))
16242 (beginning-of-line 2)
16243 (delete-region signal-pos
(point)))
16244 (setq signal-beg-pos signal-pos
)
16245 ;; open entity file
16246 (when (file-exists-p ent-file-name
)
16247 (find-file ent-file-name
))
16248 (goto-char (point-min))
16249 (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name
"[ \t\n\r\f]+is\\>") nil t
)
16250 (error "ERROR: Entity not found: \"%s\"" ent-name
))
16251 ;; prepare generic clause insertion
16252 (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t
)
16254 (goto-char (match-beginning 0))
16255 (indent-to vhdl-basic-offset
)
16256 (insert "generic ();\n\n")
16259 (setq generic-pos
(point-marker))
16260 (forward-sexp) (end-of-line)
16261 (delete-region generic-pos
(point)) (delete-char 1)
16265 (indent-to (* 2 vhdl-basic-offset
))
16266 (insert "-- global generics\n"))
16267 (setq generic-beg-pos
(point-marker) generic-pos
(point-marker)
16268 generic-inst-pos
(point-marker) generic-end-pos
(point-marker))
16269 ;; prepare port clause insertion
16270 (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t
)
16272 (goto-char (match-beginning 0))
16273 (indent-to vhdl-basic-offset
)
16274 (insert "port ();\n\n")
16277 (setq port-in-pos
(point-marker))
16278 (forward-sexp) (end-of-line)
16279 (delete-region port-in-pos
(point)) (delete-char 1)
16281 (when (or multi-in-list multi-out-list
)
16283 (indent-to (* 2 vhdl-basic-offset
))
16284 (insert "-- global ports\n"))
16285 (setq port-beg-pos
(point-marker) port-in-pos
(point-marker)
16286 port-out-pos
(point-marker) port-inst-pos
(point-marker)
16287 port-end-pos
(point-marker))
16288 ;; insert generics, ports and signals
16289 (setq inst-alist
(nreverse inst-alist
))
16291 (setq inst-name
(nth 0 (car inst-alist
))
16292 constant-alist
(nth 1 (car inst-alist
))
16293 signal-alist
(nth 2 (car inst-alist
))
16294 constant-temp-pos generic-inst-pos
16295 port-temp-pos port-inst-pos
16296 signal-temp-pos signal-pos
)
16298 (while constant-alist
16299 (setq constant-name
(downcase (caar constant-alist
))
16300 constant-entry
(car constant-alist
))
16301 (unless (string-match "^[0-9]+" constant-name
)
16302 (cond ((member constant-name written-list
)
16304 ((member constant-name multi-list
)
16305 (vhdl-goto-marker generic-pos
)
16306 (setq generic-end-pos
16309 (vhdl-compose-insert-generic constant-entry
)))
16310 (setq generic-pos
(point-marker))
16311 (add-to-list 'written-list constant-name
))
16314 (vhdl-max-marker generic-inst-pos generic-pos
))
16315 (setq generic-end-pos
16316 (vhdl-compose-insert-generic constant-entry
))
16317 (setq generic-inst-pos
(point-marker))
16318 (add-to-list 'written-list constant-name
))))
16319 (setq constant-alist
(cdr constant-alist
)))
16320 (when (/= constant-temp-pos generic-inst-pos
)
16321 (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos
))
16322 (insert "\n") (indent-to (* 2 vhdl-basic-offset
))
16323 (insert "-- generics for \"" inst-name
"\"\n")
16324 (vhdl-goto-marker generic-inst-pos
))
16325 ;; ports and signals
16326 (while signal-alist
16327 (setq signal-name
(downcase (caar signal-alist
))
16328 signal-entry
(car signal-alist
))
16329 (cond ((member signal-name written-list
)
16331 ((member signal-name multi-in-list
)
16332 (vhdl-goto-marker port-in-pos
)
16335 port-end-pos
(vhdl-compose-insert-port signal-entry
)))
16336 (setq port-in-pos
(point-marker))
16337 (add-to-list 'written-list signal-name
))
16338 ((member signal-name multi-out-list
)
16339 (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos
))
16342 port-end-pos
(vhdl-compose-insert-port signal-entry
)))
16343 (setq port-out-pos
(point-marker))
16344 (add-to-list 'written-list signal-name
))
16345 ((or (member signal-name single-in-list
)
16346 (member signal-name single-out-list
))
16350 (vhdl-max-marker port-out-pos port-in-pos
)))
16351 (setq port-end-pos
(vhdl-compose-insert-port signal-entry
))
16352 (setq port-inst-pos
(point-marker))
16353 (add-to-list 'written-list signal-name
))
16354 ((equal (upcase (nth 2 signal-entry
)) "OUT")
16355 (vhdl-goto-marker signal-pos
)
16356 (vhdl-compose-insert-signal signal-entry
)
16357 (setq signal-pos
(point-marker))
16358 (add-to-list 'written-list signal-name
)))
16359 (setq signal-alist
(cdr signal-alist
)))
16360 (when (/= port-temp-pos port-inst-pos
)
16362 (vhdl-max-marker port-temp-pos
16363 (vhdl-max-marker port-in-pos port-out-pos
)))
16364 (insert "\n") (indent-to (* 2 vhdl-basic-offset
))
16365 (insert "-- ports to \"" inst-name
"\"\n")
16366 (vhdl-goto-marker port-inst-pos
))
16367 (when (/= signal-temp-pos signal-pos
)
16368 (vhdl-goto-marker signal-temp-pos
)
16369 (insert "\n") (indent-to vhdl-basic-offset
)
16370 (insert "-- outputs of \"" inst-name
"\"\n")
16371 (vhdl-goto-marker signal-pos
))
16372 (setq inst-alist
(cdr inst-alist
)))
16373 ;; finalize generic/port clause
16374 (vhdl-goto-marker generic-end-pos
) (backward-char)
16375 (when (= generic-beg-pos generic-end-pos
)
16376 (insert "\n") (indent-to (* 2 vhdl-basic-offset
))
16377 (insert ";") (backward-char))
16379 (vhdl-goto-marker port-end-pos
) (backward-char)
16380 (when (= port-beg-pos port-end-pos
)
16381 (insert "\n") (indent-to (* 2 vhdl-basic-offset
))
16382 (insert ";") (backward-char))
16384 ;; align everything
16385 (when vhdl-auto-align
16386 (vhdl-goto-marker generic-beg-pos
)
16387 (vhdl-align-region-groups generic-beg-pos generic-end-pos
1)
16388 (vhdl-align-region-groups port-beg-pos port-end-pos
1)
16389 (vhdl-goto-marker signal-beg-pos
)
16390 (vhdl-align-region-groups signal-beg-pos signal-pos
))
16391 (switch-to-buffer (marker-buffer signal-beg-pos
))
16392 (message "Wiring components...done")))))
16394 (defun vhdl-compose-insert-generic (entry)
16395 "Insert ENTRY as generic declaration."
16397 (indent-to (* 2 vhdl-basic-offset
))
16398 (insert (nth 0 entry
) " : " (nth 1 entry
))
16399 (when (nth 2 entry
)
16400 (insert " := " (nth 2 entry
)))
16402 (setq pos
(point-marker))
16403 (when (and vhdl-include-port-comments
(nth 3 entry
))
16404 (vhdl-comment-insert-inline (nth 3 entry
) t
))
16408 (defun vhdl-compose-insert-port (entry)
16409 "Insert ENTRY as port declaration."
16411 (indent-to (* 2 vhdl-basic-offset
))
16412 (insert (nth 0 entry
) " : " (nth 2 entry
) " " (nth 3 entry
) ";")
16413 (setq pos
(point-marker))
16414 (when (and vhdl-include-port-comments
(nth 4 entry
))
16415 (vhdl-comment-insert-inline (nth 4 entry
) t
))
16419 (defun vhdl-compose-insert-signal (entry)
16420 "Insert ENTRY as signal declaration."
16421 (indent-to vhdl-basic-offset
)
16422 (insert "signal " (nth 0 entry
) " : " (nth 3 entry
) ";")
16423 (when (and vhdl-include-port-comments
(nth 4 entry
))
16424 (vhdl-comment-insert-inline (nth 4 entry
) t
))
16427 (defun vhdl-compose-components-package ()
16428 "Generate a package containing component declarations for all entities in the
16429 current project/directory."
16431 (vhdl-require-hierarchy-info)
16432 (let* ((project (vhdl-project-p))
16433 (pack-name (vhdl-get-components-package-name))
16435 (concat (vhdl-replace-string vhdl-package-file-name pack-name t
)
16436 "." (file-name-extension (buffer-file-name))))
16437 (ent-alist (aget vhdl-entity-alist
16438 (or project default-directory
) t
))
16439 (lazy-lock-minimum-size 0)
16440 clause-pos component-pos
)
16441 (message "Generating components package \"%s\"..." pack-name
)
16442 ;; open package file
16443 (when (and (file-exists-p pack-file-name
)
16444 (not (y-or-n-p (concat "File \"" pack-file-name
16445 "\" exists; overwrite? "))))
16446 (error "ERROR: Generating components package...aborted"))
16447 (find-file pack-file-name
)
16450 (if vhdl-compose-include-header
16451 (progn (vhdl-template-header
16452 (concat "Components package (generated by Emacs VHDL Mode "
16454 (goto-char (point-max)))
16455 (vhdl-comment-display-line) (insert "\n\n"))
16456 ;; insert std_logic_1164 package
16457 (vhdl-template-package-std-logic-1164)
16458 (insert "\n") (setq clause-pos
(point-marker))
16459 (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
16460 ;; insert package declaration
16461 (vhdl-insert-keyword "PACKAGE ") (insert pack-name
)
16462 (vhdl-insert-keyword " IS\n\n")
16463 (indent-to vhdl-basic-offset
) (vhdl-comment-display-line) (insert "\n")
16464 (indent-to vhdl-basic-offset
) (insert "-- Component declarations\n")
16465 (indent-to vhdl-basic-offset
) (vhdl-comment-display-line) (insert "\n\n")
16466 (indent-to vhdl-basic-offset
)
16467 (setq component-pos
(point-marker))
16468 (insert "\n\n") (vhdl-insert-keyword "END ")
16469 (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
16470 (insert pack-name
";\n\n")
16472 (if (and vhdl-compose-include-header
(not (equal vhdl-file-footer
"")))
16473 (vhdl-template-footer)
16474 (vhdl-comment-display-line) (insert "\n"))
16475 ;; insert component declarations
16477 (vhdl-visit-file (nth 2 (car ent-alist
)) nil
16478 (progn (vhdl-goto-line (nth 3 (car ent-alist
)))
16481 (goto-char component-pos
)
16482 (vhdl-port-paste-component t
)
16483 (when (cdr ent-alist
) (insert "\n\n") (indent-to vhdl-basic-offset
))
16484 (setq component-pos
(point-marker))
16485 (goto-char clause-pos
)
16486 (vhdl-port-paste-context-clause pack-name
)
16487 (setq clause-pos
(point-marker))
16488 (setq ent-alist
(cdr ent-alist
)))
16489 (goto-char (point-min))
16491 (message "Generating components package \"%s\"...done\n File created: \"%s\""
16492 pack-name pack-file-name
)))
16494 (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
16495 conf-alist inst-alist
16496 &optional insert-conf
)
16497 "Generate block configuration for architecture."
16498 (let ((margin (current-indentation))
16499 (beg (point-at-bol))
16500 ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist
)
16501 ;; insert block configuration (for architecture)
16502 (vhdl-insert-keyword "FOR ") (insert arch-name
"\n")
16503 (setq margin
(+ margin vhdl-basic-offset
))
16504 ;; process all instances
16506 (setq inst-entry
(car inst-alist
))
16508 (when (nth 4 inst-entry
)
16509 (setq insert-conf t
)
16510 (setq inst-path
(nth 9 inst-entry
))
16511 ;; skip common path with previous instance
16512 (while (and inst-path
(equal (car inst-path
) (car inst-prev-path
)))
16513 (setq inst-path
(cdr inst-path
)
16514 inst-prev-path
(cdr inst-prev-path
)))
16515 ;; insert block configuration end (for previous block/generate)
16516 (while inst-prev-path
16517 (setq margin
(- margin vhdl-basic-offset
))
16519 (vhdl-insert-keyword "END FOR;\n")
16520 (setq inst-prev-path
(cdr inst-prev-path
)))
16521 ;; insert block configuration beginning (for current block/generate)
16524 (setq margin
(+ margin vhdl-basic-offset
))
16525 (vhdl-insert-keyword "FOR ")
16526 (insert (car inst-path
) "\n")
16528 (setq inst-path
(cdr inst-path
)))
16529 ;; insert component configuration beginning
16530 (vhdl-insert-keyword "FOR ")
16531 (insert (nth 1 inst-entry
) " : " (nth 4 inst-entry
) "\n")
16532 ;; find subconfiguration
16533 (setq conf-key
(nth 7 inst-entry
))
16534 (setq tmp-alist conf-alist
)
16535 ;; use first configuration found for instance's entity
16536 (while (and tmp-alist
(null conf-key
))
16537 (when (equal (nth 5 inst-entry
) (nth 4 (car tmp-alist
)))
16538 (setq conf-key
(nth 0 (car tmp-alist
))))
16539 (setq tmp-alist
(cdr tmp-alist
)))
16540 (setq conf-entry
(aget conf-alist conf-key t
))
16541 ;; insert binding indication ...
16542 ;; ... with subconfiguration (if exists)
16543 (if (and vhdl-compose-configuration-use-subconfiguration conf-entry
)
16545 (indent-to (+ margin vhdl-basic-offset
))
16546 (vhdl-insert-keyword "USE CONFIGURATION ")
16547 (insert (vhdl-work-library) "." (nth 0 conf-entry
))
16549 ;; ... with entity (if exists)
16550 (setq ent-entry
(aget ent-alist
(nth 5 inst-entry
) t
))
16552 (indent-to (+ margin vhdl-basic-offset
))
16553 (vhdl-insert-keyword "USE ENTITY ")
16554 (insert (vhdl-work-library) "." (nth 0 ent-entry
))
16555 ;; insert architecture name (if architecture exists)
16556 (when (nth 3 ent-entry
)
16558 ;; choose architecture name a) from configuration,
16559 ;; b) from mra, or c) from first architecture
16560 (or (nth 0 (aget (nth 3 ent-entry
)
16561 (or (nth 6 inst-entry
)
16562 (nth 4 ent-entry
)) t
))
16563 (nth 1 (car (nth 3 ent-entry
)))))
16564 (insert "(" arch-name
")"))
16566 ;; insert block configuration (for architecture of subcomponent)
16567 (when (and vhdl-compose-configuration-hierarchical
16569 (indent-to (+ margin vhdl-basic-offset
))
16570 (vhdl-compose-configuration-architecture
16571 (nth 0 ent-entry
) arch-name ent-alist conf-alist
16572 (nth 3 (aget (nth 3 ent-entry
) (downcase arch-name
) t
))))))
16573 ;; insert component configuration end
16575 (vhdl-insert-keyword "END FOR;\n")
16576 (setq inst-prev-path
(nth 9 inst-entry
)))
16577 (setq inst-alist
(cdr inst-alist
)))
16578 ;; insert block configuration end (for block/generate)
16579 (while inst-prev-path
16580 (setq margin
(- margin vhdl-basic-offset
))
16582 (vhdl-insert-keyword "END FOR;\n")
16583 (setq inst-prev-path
(cdr inst-prev-path
)))
16584 (indent-to (- margin vhdl-basic-offset
))
16585 ;; insert block configuration end or remove beginning (for architecture)
16587 (vhdl-insert-keyword "END FOR;\n")
16588 (delete-region beg
(point)))))
16590 (defun vhdl-compose-configuration (&optional ent-name arch-name
)
16591 "Generate configuration declaration."
16593 (vhdl-require-hierarchy-info)
16594 (let ((ent-alist (aget vhdl-entity-alist
16595 (or (vhdl-project-p) default-directory
) t
))
16596 (conf-alist (aget vhdl-config-alist
16597 (or (vhdl-project-p) default-directory
) t
))
16598 (from-speedbar ent-name
)
16599 inst-alist conf-name conf-file-name pos
)
16600 (vhdl-prepare-search-2
16601 ;; get entity and architecture name
16604 (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t
)
16605 (not (equal "END" (upcase (match-string 1))))
16606 (setq ent-name
(match-string-no-properties 3))
16607 (setq arch-name
(match-string-no-properties 2)))
16608 (error "ERROR: Not within an architecture"))))
16609 (setq conf-name
(vhdl-replace-string
16610 vhdl-compose-configuration-name
16611 (concat ent-name
" " arch-name
)))
16613 (nth 3 (aget (nth 3 (aget ent-alist
(downcase ent-name
) t
))
16614 (downcase arch-name
) t
))))
16615 (message "Generating configuration \"%s\"..." conf-name
)
16616 (if vhdl-compose-configuration-create-file
16617 ;; open configuration file
16619 (setq conf-file-name
16620 (concat (vhdl-replace-string vhdl-configuration-file-name
16622 "." (file-name-extension (buffer-file-name))))
16623 (when (and (file-exists-p conf-file-name
)
16624 (not (y-or-n-p (concat "File \"" conf-file-name
16625 "\" exists; overwrite? "))))
16626 (error "ERROR: Creating configuration...aborted"))
16627 (find-file conf-file-name
)
16629 (set-buffer-modified-p nil
)
16631 (if vhdl-compose-include-header
16632 (progn (vhdl-template-header
16633 (concat "Configuration declaration for design \""
16634 ent-name
"(" arch-name
")\""))
16635 (goto-char (point-max)))
16636 (vhdl-comment-display-line) (insert "\n\n")))
16637 ;; goto end of architecture
16638 (unless from-speedbar
16639 (re-search-forward "^end\\>" nil
)
16640 (end-of-line) (insert "\n\n")
16641 (vhdl-comment-display-line) (insert "\n\n")))
16642 ;; insert library clause
16644 (vhdl-template-standard-package (vhdl-work-library) nil
)
16645 (when (/= pos
(point))
16647 ;; insert configuration
16648 (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name
)
16649 (vhdl-insert-keyword " OF ") (insert ent-name
)
16650 (vhdl-insert-keyword " IS\n")
16651 (indent-to vhdl-basic-offset
)
16652 ;; insert block configuration (for architecture)
16653 (vhdl-compose-configuration-architecture
16654 ent-name arch-name ent-alist conf-alist inst-alist t
)
16655 (vhdl-insert-keyword "END ") (insert conf-name
";")
16656 (when conf-file-name
16657 ;; insert footer and save
16659 (if (and vhdl-compose-include-header
(not (equal vhdl-file-footer
"")))
16660 (vhdl-template-footer)
16661 (vhdl-comment-display-line) (insert "\n"))
16664 (concat (format "Generating configuration \"%s\"...done" conf-name
)
16665 (and conf-file-name
16666 (format "\n File created: \"%s\"" conf-file-name
))))))
16669 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16670 ;;; Compilation / Makefile generation
16671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16672 ;; (using `compile.el')
16674 (defvar vhdl-compile-post-command
""
16675 "String appended to compile command after file name.")
16677 (defun vhdl-makefile-name ()
16678 "Return the Makefile name of the current project or the current compiler if
16679 no project is defined."
16680 (let ((project-alist (aget vhdl-project-alist vhdl-project
))
16681 (compiler-alist (aget vhdl-compiler-alist vhdl-compiler
)))
16682 (vhdl-replace-string
16683 (cons "\\(.*\\)\n\\(.*\\)"
16684 (or (nth 8 project-alist
) (nth 8 compiler-alist
)))
16685 (concat (nth 9 compiler-alist
) "\n" (nth 6 project-alist
)))))
16687 (defun vhdl-compile-directory ()
16688 "Return the directory where compilation/make should be run."
16689 (let* ((project (aget vhdl-project-alist
(vhdl-project-p t
)))
16690 (compiler (aget vhdl-compiler-alist vhdl-compiler
))
16691 (directory (vhdl-resolve-env-variable
16693 (vhdl-replace-string
16694 (cons "\\(.*\\)" (nth 5 project
)) (nth 9 compiler
))
16695 (nth 6 compiler
)))))
16696 (file-name-as-directory
16697 (if (file-name-absolute-p directory
)
16699 (expand-file-name directory
(vhdl-default-directory))))))
16701 (defun vhdl-uniquify (in-list)
16702 "Remove duplicate elements from IN-LIST."
16705 (add-to-list 'out-list
(car in-list
))
16706 (setq in-list
(cdr in-list
)))
16709 (defun vhdl-set-compiler (name)
16710 "Set current compiler to NAME."
16712 (list (let ((completion-ignore-case t
))
16713 (completing-read "Compiler name: " vhdl-compiler-alist nil t
))))
16714 (if (assoc name vhdl-compiler-alist
)
16715 (progn (setq vhdl-compiler name
)
16716 (message "Current compiler: \"%s\"" vhdl-compiler
))
16717 (vhdl-warning (format "Unknown compiler: \"%s\"" name
))))
16719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16722 (defun vhdl-compile-init ()
16723 "Initialize for compilation."
16724 (when (or (null compilation-error-regexp-alist
)
16725 (not (assoc (car (nth 11 (car vhdl-compiler-alist
)))
16726 compilation-error-regexp-alist
)))
16727 ;; `compilation-error-regexp-alist'
16728 (let ((commands-alist vhdl-compiler-alist
)
16729 regexp-alist sublist
)
16730 (while commands-alist
16731 (setq sublist
(nth 11 (car commands-alist
)))
16732 (unless (or (equal "" (car sublist
))
16733 (assoc (car sublist
) regexp-alist
))
16734 (push (list (nth 0 sublist
)
16735 (if (and (featurep 'xemacs
) (not (nth 1 sublist
)))
16738 (nth 2 sublist
) (nth 3 sublist
))
16740 (setq commands-alist
(cdr commands-alist
)))
16741 (setq compilation-error-regexp-alist
16742 (append compilation-error-regexp-alist
(nreverse regexp-alist
))))
16743 ;; `compilation-file-regexp-alist'
16744 (let ((commands-alist vhdl-compiler-alist
)
16745 regexp-alist sublist
)
16746 ;; matches vhdl-mode file name output
16747 (setq regexp-alist
'(("^Compiling \"\\(.+\\)\"" 1)))
16748 (while commands-alist
16749 (setq sublist
(nth 12 (car commands-alist
)))
16750 (unless (or (equal "" (car sublist
))
16751 (assoc (car sublist
) regexp-alist
))
16752 (push sublist regexp-alist
))
16753 (setq commands-alist
(cdr commands-alist
)))
16754 (setq compilation-file-regexp-alist
16755 (append compilation-file-regexp-alist
(nreverse regexp-alist
))))))
16757 (defvar vhdl-compile-file-name nil
16758 "Name of file to be compiled.")
16760 (defun vhdl-compile-print-file-name ()
16761 "Function called within `compile' to print out file name for compilers that
16762 do not print any file names."
16763 (insert "Compiling \"" vhdl-compile-file-name
"\"\n"))
16765 (defun vhdl-get-compile-options (project compiler file-name
16766 &optional file-options-only
)
16767 "Get compiler options. Returning nil means do not compile this file."
16768 (let* ((compiler-options (nth 1 compiler
))
16769 (project-entry (aget (nth 4 project
) vhdl-compiler
))
16770 (project-options (nth 0 project-entry
))
16771 (exception-list (and file-name
(nth 2 project-entry
)))
16772 (work-library (vhdl-work-library))
16773 (case-fold-search nil
)
16775 (while (and exception-list
16776 (not (string-match (caar exception-list
) file-name
)))
16777 (setq exception-list
(cdr exception-list
)))
16778 (if (and exception-list
(not (cdar exception-list
)))
16780 (if (and file-options-only
(not exception-list
))
16782 (setq file-options
(cdar exception-list
))
16783 ;; insert library name in compiler-specific options
16784 (setq compiler-options
16785 (vhdl-replace-string (cons "\\(.*\\)" compiler-options
)
16787 ;; insert compiler-specific options in project-specific options
16788 (when project-options
16789 (setq project-options
16790 (vhdl-replace-string
16791 (cons "\\(.*\\)\n\\(.*\\)" project-options
)
16792 (concat work-library
"\n" compiler-options
))))
16793 ;; insert project-specific options in file-specific options
16796 (vhdl-replace-string
16797 (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options
)
16798 (concat work-library
"\n" compiler-options
"\n"
16799 project-options
))))
16801 (or file-options project-options compiler-options
)))))
16803 (defun vhdl-get-make-options (project compiler
)
16804 "Get make options."
16805 (let* ((compiler-options (nth 3 compiler
))
16806 (project-entry (aget (nth 4 project
) vhdl-compiler
))
16807 (project-options (nth 1 project-entry
))
16808 (makefile-name (vhdl-makefile-name)))
16809 ;; insert Makefile name in compiler-specific options
16810 (setq compiler-options
16811 (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler
))
16813 ;; insert compiler-specific options in project-specific options
16814 (when project-options
16815 (setq project-options
16816 (vhdl-replace-string
16817 (cons "\\(.*\\)\n\\(.*\\)" project-options
)
16818 (concat makefile-name
"\n" compiler-options
))))
16820 (or project-options compiler-options
)))
16822 (defun vhdl-compile ()
16823 "Compile current buffer using the VHDL compiler specified in
16826 (vhdl-compile-init)
16827 (let* ((project (aget vhdl-project-alist vhdl-project
))
16828 (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil
)
16829 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler
)))
16830 (command (nth 0 compiler
))
16831 (default-directory (vhdl-compile-directory))
16832 (file-name (if vhdl-compile-absolute-path
16834 (file-relative-name (buffer-file-name))))
16835 (options (vhdl-get-compile-options project compiler file-name
))
16836 compilation-process-setup-function
)
16837 (unless (file-directory-p default-directory
)
16838 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory
))
16839 ;; put file name into quotes if it contains spaces
16840 (when (string-match " " file-name
)
16841 (setq file-name
(concat "\"" file-name
"\"")))
16842 ;; print out file name if compiler does not
16843 (setq vhdl-compile-file-name
(if vhdl-compile-absolute-path
16845 (file-relative-name (buffer-file-name))))
16846 (when (and (= 0 (nth 1 (nth 10 compiler
)))
16847 (= 0 (nth 1 (nth 11 compiler
))))
16848 (setq compilation-process-setup-function
'vhdl-compile-print-file-name
))
16852 (compile (concat command
" " options
" " file-name
16853 (unless (equal vhdl-compile-post-command
"")
16854 (concat " " vhdl-compile-post-command
)))))
16855 (vhdl-warning "Your project settings tell me not to compile this file"))))
16857 (defvar vhdl-make-target
"all"
16858 "Default target for `vhdl-make' command.")
16860 (defun vhdl-make (&optional target
)
16861 "Call make command for compilation of all updated source files (requires
16862 `Makefile'). Optional argument TARGET allows to compile the design
16863 specified by a target."
16865 (setq vhdl-make-target
16866 (or target
(read-from-minibuffer "Target: " vhdl-make-target
16867 vhdl-minibuffer-local-map
)))
16868 (vhdl-compile-init)
16869 (let* ((project (aget vhdl-project-alist vhdl-project
))
16870 (compiler (or (aget vhdl-compiler-alist vhdl-compiler
)
16871 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler
)))
16872 (command (nth 2 compiler
))
16873 (options (vhdl-get-make-options project compiler
))
16874 (default-directory (vhdl-compile-directory)))
16875 (unless (file-directory-p default-directory
)
16876 (error "ERROR: Compile directory does not exist: \"%s\"" default-directory
))
16878 (compile (concat (if (equal command
"") "make" command
)
16879 " " options
" " vhdl-make-target
))))
16882 (defvar vhdl-error-regexp-emacs-alist
16883 ;; Get regexps from `vhdl-compiler-alist'
16884 (let ((compiler-alist vhdl-compiler-alist
)
16885 (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
16886 (while compiler-alist
16887 ;; add error message regexps
16888 (setq error-regexp-alist
16889 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?-
(downcase (nth 0 (car compiler-alist
)))))))
16890 (nth 11 (car compiler-alist
)))
16891 error-regexp-alist
))
16892 ;; add filename regexps
16893 (when (/= 0 (nth 1 (nth 12 (car compiler-alist
))))
16894 (setq error-regexp-alist
16895 (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?-
(downcase (nth 0 (car compiler-alist
)))) "-file")))
16896 (nth 12 (car compiler-alist
)))
16897 error-regexp-alist
)))
16898 (setq compiler-alist
(cdr compiler-alist
)))
16899 error-regexp-alist
)
16900 "List of regexps for VHDL compilers. For Emacs 22+.")
16902 ;; Add error regexps using compilation-mode-hook.
16903 (defun vhdl-error-regexp-add-emacs ()
16904 "Set up Emacs compile for VHDL."
16906 (when (and (boundp 'compilation-error-regexp-alist-alist
)
16907 (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist
)))
16910 (push (car item
) compilation-error-regexp-alist
)
16911 (push item compilation-error-regexp-alist-alist
))
16912 vhdl-error-regexp-emacs-alist
)))
16914 (when vhdl-emacs-22
16915 (add-hook 'compilation-mode-hook
'vhdl-error-regexp-add-emacs
))
16917 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16918 ;; Makefile generation
16920 (defun vhdl-generate-makefile ()
16921 "Generate `Makefile'."
16923 (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler
)
16924 (error "ERROR: No such compiler: \"%s\"" vhdl-compiler
)))
16925 (command (nth 4 compiler
)))
16926 ;; generate makefile
16928 (let ((default-directory (vhdl-compile-directory)))
16929 (compile (vhdl-replace-string
16930 (cons "\\(.*\\) \\(.*\\)" command
)
16931 (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
16932 (vhdl-generate-makefile-1))))
16934 (defun vhdl-get-packages (lib-alist work-library
)
16935 "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
16938 (when (equal (downcase (caar lib-alist
)) (downcase work-library
))
16939 (push (cdar lib-alist
) pack-list
))
16940 (setq lib-alist
(cdr lib-alist
)))
16943 (defun vhdl-generate-makefile-1 ()
16944 "Generate Makefile for current project or directory."
16945 ;; scan hierarchy if required
16946 (if (vhdl-project-p)
16947 (unless (or (assoc vhdl-project vhdl-file-alist
)
16948 (vhdl-load-cache vhdl-project
))
16949 (vhdl-scan-project-contents vhdl-project
))
16950 (let ((directory (abbreviate-file-name default-directory
)))
16951 (unless (or (assoc directory vhdl-file-alist
)
16952 (vhdl-load-cache directory
))
16953 (vhdl-scan-directory-contents directory
))))
16954 (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
16955 (project (vhdl-project-p))
16956 (ent-alist (aget vhdl-entity-alist
(or project directory
) t
))
16957 (conf-alist (aget vhdl-config-alist
(or project directory
) t
))
16958 (pack-alist (aget vhdl-package-alist
(or project directory
) t
))
16959 (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler
)))
16960 (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list
)))
16961 (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list
)))
16962 (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list
)))
16963 (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list
)))
16964 (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list
)))
16965 (adjust-case (nth 5 regexp-list
))
16966 (work-library (downcase (vhdl-work-library)))
16967 (compile-directory (expand-file-name (vhdl-compile-directory)
16968 default-directory
))
16969 (makefile-name (vhdl-makefile-name))
16970 rule-alist arch-alist inst-alist
16971 target-list depend-list unit-list prim-list second-list subcomp-list
16972 lib-alist lib-body-alist pack-list all-pack-list
16973 ent-key ent-file-name arch-key arch-file-name ent-arch-key
16974 conf-key conf-file-name pack-key pack-file-name
16975 ent-entry arch-entry conf-entry pack-entry inst-entry
16976 pack-body-key pack-body-file-name inst-ent-key inst-conf-key
16977 tmp-key tmp-list rule
)
16978 ;; check prerequisites
16979 (unless (file-exists-p compile-directory
)
16980 (make-directory compile-directory t
))
16981 (unless regexp-list
16982 (error "Please contact the VHDL Mode maintainer for support of \"%s\""
16984 (message "Generating makefile \"%s\"..." makefile-name
)
16985 ;; rules for all entities
16986 (setq tmp-list ent-alist
)
16988 (setq ent-entry
(car ent-alist
)
16989 ent-key
(nth 0 ent-entry
))
16990 (when (nth 2 ent-entry
)
16991 (setq ent-file-name
(if vhdl-compile-absolute-path
16993 (file-relative-name (nth 2 ent-entry
)
16994 compile-directory
))
16995 arch-alist
(nth 4 ent-entry
)
16996 lib-alist
(nth 6 ent-entry
)
16997 rule
(aget rule-alist ent-file-name
)
16998 target-list
(nth 0 rule
)
16999 depend-list
(nth 1 rule
)
17002 (setq tmp-key
(vhdl-replace-string
17003 ent-regexp
(funcall adjust-case ent-key
)))
17004 (push (cons ent-key tmp-key
) unit-list
)
17005 ;; rule target for this entity
17006 (push ent-key target-list
)
17007 ;; rule dependencies for all used packages
17008 (setq pack-list
(vhdl-get-packages lib-alist work-library
))
17009 (setq depend-list
(append depend-list pack-list
))
17010 (setq all-pack-list pack-list
)
17012 (aput 'rule-alist ent-file-name
(list target-list depend-list
))
17013 ;; rules for all corresponding architectures
17015 (setq arch-entry
(car arch-alist
)
17016 arch-key
(nth 0 arch-entry
)
17017 ent-arch-key
(concat ent-key
"-" arch-key
)
17018 arch-file-name
(if vhdl-compile-absolute-path
17020 (file-relative-name (nth 2 arch-entry
)
17021 compile-directory
))
17022 inst-alist
(nth 4 arch-entry
)
17023 lib-alist
(nth 5 arch-entry
)
17024 rule
(aget rule-alist arch-file-name
)
17025 target-list
(nth 0 rule
)
17026 depend-list
(nth 1 rule
))
17027 (setq tmp-key
(vhdl-replace-string
17029 (funcall adjust-case
(concat arch-key
" " ent-key
))))
17031 (cons (cons ent-arch-key tmp-key
) unit-list
))
17032 (push ent-arch-key second-list
)
17033 ;; rule target for this architecture
17034 (push ent-arch-key target-list
)
17035 ;; rule dependency for corresponding entity
17036 (push ent-key depend-list
)
17037 ;; rule dependencies for contained component instantiations
17039 (setq inst-entry
(car inst-alist
))
17040 (when (or (null (nth 8 inst-entry
))
17041 (equal (downcase (nth 8 inst-entry
)) work-library
))
17042 (setq inst-ent-key
(or (nth 7 inst-entry
)
17043 (nth 5 inst-entry
)))
17044 (setq depend-list
(cons inst-ent-key depend-list
)
17045 subcomp-list
(cons inst-ent-key subcomp-list
)))
17046 (setq inst-alist
(cdr inst-alist
)))
17047 ;; rule dependencies for all used packages
17048 (setq pack-list
(vhdl-get-packages lib-alist work-library
))
17049 (setq depend-list
(append depend-list pack-list
))
17050 (setq all-pack-list
(append all-pack-list pack-list
))
17052 (aput 'rule-alist arch-file-name
(list target-list depend-list
))
17053 (setq arch-alist
(cdr arch-alist
)))
17054 (push (list ent-key second-list
(append subcomp-list all-pack-list
))
17056 (setq ent-alist
(cdr ent-alist
)))
17057 (setq ent-alist tmp-list
)
17058 ;; rules for all configurations
17059 (setq tmp-list conf-alist
)
17061 (setq conf-entry
(car conf-alist
)
17062 conf-key
(nth 0 conf-entry
)
17063 conf-file-name
(if vhdl-compile-absolute-path
17065 (file-relative-name (nth 2 conf-entry
)
17066 compile-directory
))
17067 ent-key
(nth 4 conf-entry
)
17068 arch-key
(nth 5 conf-entry
)
17069 inst-alist
(nth 6 conf-entry
)
17070 lib-alist
(nth 7 conf-entry
)
17071 rule
(aget rule-alist conf-file-name
)
17072 target-list
(nth 0 rule
)
17073 depend-list
(nth 1 rule
)
17074 subcomp-list
(list ent-key
))
17075 (setq tmp-key
(vhdl-replace-string
17076 conf-regexp
(funcall adjust-case conf-key
)))
17077 (push (cons conf-key tmp-key
) unit-list
)
17078 ;; rule target for this configuration
17079 (push conf-key target-list
)
17080 ;; rule dependency for corresponding entity and architecture
17082 (cons ent-key
(cons (concat ent-key
"-" arch-key
) depend-list
)))
17083 ;; rule dependencies for used packages
17084 (setq pack-list
(vhdl-get-packages lib-alist work-library
))
17085 (setq depend-list
(append depend-list pack-list
))
17086 ;; rule dependencies for contained component configurations
17088 (setq inst-entry
(car inst-alist
))
17089 (setq inst-ent-key
(nth 2 inst-entry
)
17090 ; comp-arch-key (nth 2 inst-entry))
17091 inst-conf-key
(nth 4 inst-entry
))
17092 (when (equal (downcase (nth 5 inst-entry
)) work-library
)
17094 (setq depend-list
(cons inst-ent-key depend-list
)
17095 subcomp-list
(cons inst-ent-key subcomp-list
)))
17096 ; (when comp-arch-key
17097 ; (push (concat comp-ent-key "-" comp-arch-key) depend-list))
17098 (when inst-conf-key
17099 (setq depend-list
(cons inst-conf-key depend-list
)
17100 subcomp-list
(cons inst-conf-key subcomp-list
))))
17101 (setq inst-alist
(cdr inst-alist
)))
17103 (aput 'rule-alist conf-file-name
(list target-list depend-list
))
17104 (push (list conf-key nil
(append subcomp-list pack-list
)) prim-list
)
17105 (setq conf-alist
(cdr conf-alist
)))
17106 (setq conf-alist tmp-list
)
17107 ;; rules for all packages
17108 (setq tmp-list pack-alist
)
17110 (setq pack-entry
(car pack-alist
)
17111 pack-key
(nth 0 pack-entry
)
17113 (when (nth 2 pack-entry
)
17114 (setq pack-file-name
(if vhdl-compile-absolute-path
17116 (file-relative-name (nth 2 pack-entry
)
17117 compile-directory
))
17118 lib-alist
(nth 6 pack-entry
) lib-body-alist
(nth 10 pack-entry
)
17119 rule
(aget rule-alist pack-file-name
)
17120 target-list
(nth 0 rule
) depend-list
(nth 1 rule
))
17121 (setq tmp-key
(vhdl-replace-string
17122 pack-regexp
(funcall adjust-case pack-key
)))
17123 (push (cons pack-key tmp-key
) unit-list
)
17124 ;; rule target for this package
17125 (push pack-key target-list
)
17126 ;; rule dependencies for all used packages
17127 (setq pack-list
(vhdl-get-packages lib-alist work-library
))
17128 (setq depend-list
(append depend-list pack-list
))
17129 (setq all-pack-list pack-list
)
17131 (aput 'rule-alist pack-file-name
(list target-list depend-list
))
17132 ;; rules for this package's body
17133 (when (nth 7 pack-entry
)
17134 (setq pack-body-key
(concat pack-key
"-body")
17135 pack-body-file-name
(if vhdl-compile-absolute-path
17137 (file-relative-name (nth 7 pack-entry
)
17138 compile-directory
))
17139 rule
(aget rule-alist pack-body-file-name
)
17140 target-list
(nth 0 rule
)
17141 depend-list
(nth 1 rule
))
17142 (setq tmp-key
(vhdl-replace-string
17143 pack-body-regexp
(funcall adjust-case pack-key
)))
17145 (cons (cons pack-body-key tmp-key
) unit-list
))
17146 ;; rule target for this package's body
17147 (push pack-body-key target-list
)
17148 ;; rule dependency for corresponding package declaration
17149 (push pack-key depend-list
)
17150 ;; rule dependencies for all used packages
17151 (setq pack-list
(vhdl-get-packages lib-body-alist work-library
))
17152 (setq depend-list
(append depend-list pack-list
))
17153 (setq all-pack-list
(append all-pack-list pack-list
))
17155 (aput 'rule-alist pack-body-file-name
17156 (list target-list depend-list
)))
17158 (cons (list pack-key
(when pack-body-key
(list pack-body-key
))
17161 (setq pack-alist
(cdr pack-alist
)))
17162 (setq pack-alist tmp-list
)
17163 ;; generate Makefile
17164 (let* ((project (aget vhdl-project-alist project
))
17165 (compiler (aget vhdl-compiler-alist vhdl-compiler
))
17166 (compiler-id (nth 9 compiler
))
17168 (vhdl-resolve-env-variable
17169 (vhdl-replace-string
17170 (cons "\\(.*\\)" (or (nth 7 project
) (nth 7 compiler
)))
17172 (makefile-path-name (expand-file-name
17173 makefile-name compile-directory
))
17174 (orig-buffer (current-buffer))
17175 cell second-list subcomp-list options unit-key unit-name
)
17177 (setq unit-list
(vhdl-sort-alist unit-list
))
17178 (setq prim-list
(vhdl-sort-alist prim-list
))
17179 (setq tmp-list rule-alist
)
17180 (while tmp-list
; pre-sort rule targets
17181 (setq cell
(cdar tmp-list
))
17182 (setcar cell
(sort (car cell
) 'string
<))
17183 (setq tmp-list
(cdr tmp-list
)))
17184 (setq rule-alist
; sort by first rule target
17186 (function (lambda (a b
)
17187 (string< (car (cadr a
)) (car (cadr b
)))))))
17188 ;; open and clear Makefile
17189 (set-buffer (find-file-noselect makefile-path-name t t
))
17191 (insert "# -*- Makefile -*-\n"
17192 "### " (file-name-nondirectory makefile-name
)
17193 " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
17196 (insert "\n# Project : " (nth 0 project
))
17197 (insert "\n# Directory : \"" directory
"\""))
17198 (insert "\n# Platform : " vhdl-compiler
17199 "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
17200 (user-login-name) "\n")
17201 ;; insert compile and option variable settings
17202 (insert "\n\n# Define compilation command and options\n"
17203 "\nCOMPILE = " (nth 0 compiler
)
17204 "\nOPTIONS = " (vhdl-get-compile-options project compiler nil
)
17205 (if (equal vhdl-compile-post-command
"") ""
17206 (concat "\nPOST-COMPILE = " vhdl-compile-post-command
))
17208 ;; insert library paths
17209 (setq library-directory
17210 (directory-file-name
17211 (if (file-name-absolute-p library-directory
)
17213 (file-relative-name
17214 (expand-file-name library-directory directory
)
17215 compile-directory
))))
17216 (insert "\n\n# Define library paths\n"
17217 "\nLIBRARY-" work-library
" = " library-directory
"\n")
17218 ;; insert variable definitions for all library unit files
17219 (insert "\n\n# Define library unit files\n")
17220 (setq tmp-list unit-list
)
17222 (insert "\nUNIT-" work-library
"-" (caar unit-list
)
17223 " = \\\n\t$(LIBRARY-" work-library
")/" (cdar unit-list
))
17224 (setq unit-list
(cdr unit-list
)))
17225 ;; insert variable definition for list of all library unit files
17226 (insert "\n\n\n# Define list of all library unit files\n"
17228 (setq unit-list tmp-list
)
17230 (insert " \\\n\t" "$(UNIT-" work-library
"-" (caar unit-list
) ")")
17231 (setq unit-list
(cdr unit-list
)))
17233 (setq unit-list tmp-list
)
17234 ;; insert `make all' rule
17235 (insert "\n\n\n# Rule for compiling entire design\n"
17236 "\n" (nth 0 vhdl-makefile-default-targets
) " :"
17237 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets
)
17238 " \\\n\t\t$(ALL_UNITS)\n")
17239 ;; insert `make clean' rule
17240 (insert "\n\n# Rule for cleaning entire design\n"
17241 "\n" (nth 1 vhdl-makefile-default-targets
) " : "
17242 "\n\t-rm -f $(ALL_UNITS)\n")
17243 ;; insert `make library' rule
17244 (insert "\n\n# Rule for creating library directory\n"
17245 "\n" (nth 2 vhdl-makefile-default-targets
) " :"
17246 " \\\n\t\t$(LIBRARY-" work-library
")\n"
17247 "\n$(LIBRARY-" work-library
") :"
17249 (vhdl-replace-string
17250 (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler
))
17251 (concat "$(LIBRARY-" work-library
")\n" (vhdl-work-library)))
17253 ;; insert '.PHONY' declaration
17254 (insert "\n\n.PHONY : "
17255 (nth 0 vhdl-makefile-default-targets
) " "
17256 (nth 1 vhdl-makefile-default-targets
) " "
17257 (nth 2 vhdl-makefile-default-targets
) "\n")
17258 ;; insert rule for each library unit
17259 (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
17261 (setq second-list
(sort (nth 1 (car prim-list
)) 'string
<))
17263 (sort (vhdl-uniquify (nth 2 (car prim-list
))) 'string
<))
17264 (setq unit-key
(caar prim-list
)
17265 unit-name
(or (nth 0 (aget ent-alist unit-key t
))
17266 (nth 0 (aget conf-alist unit-key t
))
17267 (nth 0 (aget pack-alist unit-key t
))))
17268 (insert "\n" unit-key
)
17269 (unless (equal unit-key unit-name
)
17270 (insert " \\\n" unit-name
))
17272 " \\\n\t\t" (nth 2 vhdl-makefile-default-targets
))
17273 (while subcomp-list
17274 (when (and (assoc (car subcomp-list
) unit-list
)
17275 (not (equal unit-key
(car subcomp-list
))))
17276 (insert " \\\n\t\t" (car subcomp-list
)))
17277 (setq subcomp-list
(cdr subcomp-list
)))
17278 (insert " \\\n\t\t$(UNIT-" work-library
"-" unit-key
")")
17280 (insert " \\\n\t\t$(UNIT-" work-library
"-" (car second-list
) ")")
17281 (setq second-list
(cdr second-list
)))
17283 (setq prim-list
(cdr prim-list
)))
17284 ;; insert rule for each library unit file
17285 (insert "\n\n# Rules for compiling single library unit files\n")
17287 (setq rule
(car rule-alist
))
17288 ;; get compiler options for this file
17290 (vhdl-get-compile-options project compiler
(nth 0 rule
) t
))
17291 ;; insert rule if file is supposed to be compiled
17292 (setq target-list
(nth 1 rule
)
17293 depend-list
(sort (vhdl-uniquify (nth 2 rule
)) 'string
<))
17295 (setq tmp-list target-list
)
17297 (insert "\n$(UNIT-" work-library
"-" (car target-list
) ")"
17298 (if (cdr target-list
) " \\" " :"))
17299 (setq target-list
(cdr target-list
)))
17300 (setq target-list tmp-list
)
17301 ;; insert file name as first dependency
17302 (insert " \\\n\t\t" (nth 0 rule
))
17303 ;; insert dependencies (except if also target or unit does not exist)
17305 (when (and (not (member (car depend-list
) target-list
))
17306 (assoc (car depend-list
) unit-list
))
17307 (insert " \\\n\t\t"
17308 "$(UNIT-" work-library
"-" (car depend-list
) ")"))
17309 (setq depend-list
(cdr depend-list
)))
17310 ;; insert compile command
17312 (insert "\n\t$(COMPILE) "
17313 (if (eq options
'default
) "$(OPTIONS)" options
) " "
17315 (if (equal vhdl-compile-post-command
"") ""
17316 " $(POST-COMPILE)") "\n")
17317 (setq tmp-list target-list
)
17319 (insert "\n\t@touch $(UNIT-" work-library
"-" (car target-list
) ")"
17320 (if (cdr target-list
) " \\" "\n"))
17321 (setq target-list
(cdr target-list
)))
17322 (setq target-list tmp-list
))
17323 (setq rule-alist
(cdr rule-alist
)))
17324 (insert "\n\n### " makefile-name
" ends here\n")
17325 ;; run Makefile generation hook
17326 (run-hooks 'vhdl-makefile-generation-hook
)
17327 (message "Generating makefile \"%s\"...done" makefile-name
)
17328 ;; save and close file
17329 (if (file-writable-p makefile-path-name
)
17330 (progn (save-buffer)
17331 (kill-buffer (current-buffer))
17332 (set-buffer orig-buffer
)
17333 (add-to-history 'file-name-history makefile-path-name
))
17334 (vhdl-warning-when-idle
17335 (format "File not writable: \"%s\""
17336 (abbreviate-file-name makefile-path-name
)))
17337 (switch-to-buffer (current-buffer))))))
17340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17343 ;; (using `reporter.el')
17345 (defconst vhdl-mode-help-address
17346 "Reto Zimmermann <reto@gnu.org>"
17347 "Address for VHDL Mode bug reports.")
17349 (defun vhdl-submit-bug-report ()
17350 "Submit via mail a bug report on VHDL Mode."
17352 ;; load in reporter
17354 (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
17355 (let ((reporter-prompt-for-summary-p t
))
17356 (reporter-submit-bug-report
17357 vhdl-mode-help-address
17358 (concat "VHDL Mode " vhdl-version
)
17360 ;; report all important user options
17361 'vhdl-offsets-alist
17362 'vhdl-comment-only-line-offset
17364 'vhdl-electric-mode
17366 'vhdl-indent-tabs-mode
17367 'vhdl-project-alist
17369 'vhdl-project-file-name
17370 'vhdl-project-auto-load
17372 'vhdl-compiler-alist
17374 'vhdl-compile-use-local-error-regexp
17375 'vhdl-makefile-default-targets
17376 'vhdl-makefile-generation-hook
17377 'vhdl-default-library
17380 'vhdl-upper-case-keywords
17381 'vhdl-upper-case-types
17382 'vhdl-upper-case-attributes
17383 'vhdl-upper-case-enum-values
17384 'vhdl-upper-case-constants
17385 'vhdl-use-direct-instantiation
17386 'vhdl-array-index-record-field-in-sensitivity-list
17387 'vhdl-compose-configuration-name
17388 'vhdl-entity-file-name
17389 'vhdl-architecture-file-name
17390 'vhdl-configuration-file-name
17391 'vhdl-package-file-name
17392 'vhdl-file-name-case
17393 'vhdl-electric-keywords
17394 'vhdl-optional-labels
17395 'vhdl-insert-empty-lines
17396 'vhdl-argument-list-indent
17397 'vhdl-association-list-with-formals
17398 'vhdl-conditions-in-parenthesis
17404 'vhdl-copyright-string
17405 'vhdl-platform-spec
17407 'vhdl-modify-date-prefix-string
17408 'vhdl-modify-date-on-saving
17410 'vhdl-reset-active-high
17411 'vhdl-clock-rising-edge
17412 'vhdl-clock-edge-condition
17416 'vhdl-include-port-comments
17417 'vhdl-include-direction-comments
17418 'vhdl-include-type-comments
17419 'vhdl-include-group-comments
17420 'vhdl-actual-generic-name
17421 'vhdl-actual-port-name
17422 'vhdl-instance-name
17423 'vhdl-testbench-entity-name
17424 'vhdl-testbench-architecture-name
17425 'vhdl-testbench-configuration-name
17426 'vhdl-testbench-dut-name
17427 'vhdl-testbench-include-header
17428 'vhdl-testbench-declarations
17429 'vhdl-testbench-statements
17430 'vhdl-testbench-initialize-signals
17431 'vhdl-testbench-include-library
17432 'vhdl-testbench-include-configuration
17433 'vhdl-testbench-create-files
17434 'vhdl-testbench-entity-file-name
17435 'vhdl-testbench-architecture-file-name
17436 'vhdl-compose-create-files
17437 'vhdl-compose-configuration-create-file
17438 'vhdl-compose-configuration-hierarchical
17439 'vhdl-compose-configuration-use-subconfiguration
17440 'vhdl-compose-include-header
17441 'vhdl-compose-architecture-name
17442 'vhdl-components-package-name
17443 'vhdl-use-components-package
17444 'vhdl-self-insert-comments
17445 'vhdl-prompt-for-comments
17446 'vhdl-inline-comment-column
17447 'vhdl-end-comment-column
17450 'vhdl-align-group-separate
17451 'vhdl-align-same-indent
17452 'vhdl-highlight-keywords
17453 'vhdl-highlight-names
17454 'vhdl-highlight-special-words
17455 'vhdl-highlight-forbidden-words
17456 'vhdl-highlight-verilog-keywords
17457 'vhdl-highlight-translate-off
17458 'vhdl-highlight-case-sensitive
17459 'vhdl-special-syntax-alist
17460 'vhdl-forbidden-words
17461 'vhdl-forbidden-syntax
17462 'vhdl-directive-keywords
17463 'vhdl-speedbar-auto-open
17464 'vhdl-speedbar-display-mode
17465 'vhdl-speedbar-scan-limit
17466 'vhdl-speedbar-jump-to-unit
17467 'vhdl-speedbar-update-on-saving
17468 'vhdl-speedbar-save-cache
17469 'vhdl-speedbar-cache-file-name
17471 'vhdl-source-file-menu
17472 'vhdl-hideshow-menu
17473 'vhdl-hide-all-init
17474 'vhdl-print-two-column
17475 'vhdl-print-customize-faces
17476 'vhdl-intelligent-tab
17477 'vhdl-indent-syntax-based
17478 'vhdl-indent-comment-like-next-code-line
17479 'vhdl-word-completion-case-sensitive
17480 'vhdl-word-completion-in-minibuffer
17481 'vhdl-underscore-is-part-of-word
17486 (if vhdl-special-indent-hook
17487 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
17488 "vhdl-special-indent-hook is set to '"
17489 (format "%s" vhdl-special-indent-hook
)
17490 ".\nPerhaps this is your problem?\n"
17491 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
17497 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17501 (defconst vhdl-doc-release-notes nil
17503 Release Notes for VHDL Mode 3.34
17504 ================================
17506 - Added support for GNU Emacs 22/23/24:
17507 - Compilation error parsing fixed for new `compile.el' package.
17509 - Port translation: Derive actual generic name from formal generic name.
17511 - New user options:
17512 `vhdl-actual-generic-name': Specify how actual generic names are obtained.
17515 Release Notes for VHDL Mode 3.33
17516 ================================
17521 CONFIGURATION DECLARATION GENERATION:
17522 - Automatic generation of a configuration declaration for a design.
17523 (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
17529 For Emacs compliance the following key bindings have been changed:
17531 - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
17532 - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
17533 - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
17534 - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
17540 `vhdl-configuration-file-name': (new)
17541 Specify how the configuration file name is obtained.
17542 `vhdl-compose-configuration-name': (new)
17543 Specify how the configuration name is obtained.
17544 `vhdl-compose-configuration-create-file': (new)
17545 Specify whether a new file should be created for a configuration.
17546 `vhdl-compose-configuration-hierarchical': (new)
17547 Specify whether hierarchical configurations should be created.
17548 `vhdl-compose-configuration-use-subconfiguration': (new)
17549 Specify whether subconfigurations should be used inside configurations.
17550 `vhdl-makefile-default-targets': (new)
17551 Customize names of Makefile default targets.
17552 `vhdl-indent-comment-like-next-code-line': (new)
17553 Specify whether comment lines are indented like following code line.
17554 `vhdl-array-index-record-field-in-sensitivity-list': (new)
17555 Specify whether to include array indices / record fields in sensitivity list.
17559 (defconst vhdl-doc-keywords nil
17561 Reserved words in VHDL
17562 ----------------------
17564 VHDL'93/02 (IEEE Std 1076-1993/2002):
17565 `vhdl-02-keywords' : keywords
17566 `vhdl-02-types' : standardized types
17567 `vhdl-02-attributes' : standardized attributes
17568 `vhdl-02-enum-values' : standardized enumeration values
17569 `vhdl-02-functions' : standardized functions
17570 `vhdl-02-packages' : standardized packages and libraries
17572 VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
17573 `vhdl-ams-keywords' : keywords
17574 `vhdl-ams-types' : standardized types
17575 `vhdl-ams-attributes' : standardized attributes
17576 `vhdl-ams-enum-values' : standardized enumeration values
17577 `vhdl-ams-constants' : standardized constants
17578 `vhdl-ams-functions' : standardized functions
17580 Math Packages (IEEE Std 1076.2):
17581 `vhdl-math-types' : standardized types
17582 `vhdl-math-constants' : standardized constants
17583 `vhdl-math-functions' : standardized functions
17584 `vhdl-math-packages' : standardized packages
17587 `vhdl-verilog-keywords' : Verilog reserved words
17589 NOTE: click `mouse-2' on variable names above (not in XEmacs).")
17592 (defconst vhdl-doc-coding-style nil
17594 For VHDL coding style and naming convention guidelines, see the following
17598 \"VHDL Coding Styles and Methodologies\".
17599 Kluwer Academic Publishers, 1999.
17600 http://members.aol.com/vhdlcohen/vhdl/
17602 \[2] Michael Keating and Pierre Bricaud.
17603 \"Reuse Methodology Manual, Second Edition\".
17604 Kluwer Academic Publishers, 1999.
17605 http://www.openmore.com/openmore/rmm2.html
17607 \[3] European Space Agency.
17608 \"VHDL Modelling Guidelines\".
17609 ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
17611 Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
17612 to visually support naming conventions.")
17615 (defun vhdl-version ()
17616 "Echo the current version of VHDL Mode in the minibuffer."
17618 (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp
)
17619 (vhdl-keep-region-active))
17621 (defun vhdl-doc-variable (variable)
17622 "Display VARIABLE's documentation in *Help* buffer."
17624 (unless (featurep 'xemacs
)
17625 (help-setup-xref (list #'vhdl-doc-variable variable
)
17626 (called-interactively-p 'interactive
)))
17627 (with-output-to-temp-buffer
17628 (if (fboundp 'help-buffer
) (help-buffer) "*Help*")
17629 (princ (documentation-property variable
'variable-documentation
))
17630 (with-current-buffer standard-output
17632 (help-print-return-message)))
17634 (defun vhdl-doc-mode ()
17635 "Display VHDL Mode documentation in *Help* buffer."
17637 (unless (featurep 'xemacs
)
17638 (help-setup-xref (list #'vhdl-doc-mode
)
17639 (called-interactively-p 'interactive
)))
17640 (with-output-to-temp-buffer
17641 (if (fboundp 'help-buffer
) (help-buffer) "*Help*")
17644 (princ (documentation 'vhdl-mode
))
17645 (with-current-buffer standard-output
17647 (help-print-return-message)))
17650 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17652 (provide 'vhdl-mode
)
17654 ;;; vhdl-mode.el ends here