vhdl-mode.texi 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. \input texinfo @c -*- texinfo -*-
  2. @setfilename ../../info/vhdl-mode.info
  3. @settitle VHDL Mode, an Emacs mode for editing VHDL code
  4. @include docstyle.texi
  5. @c Adapted from the VHDL Mode texinfo manual version 2 by Rodney J. Whitby.
  6. @c Adapted from the CC Mode texinfo manual by Barry A. Warsaw.
  7. @copying
  8. This file documents VHDL Mode, an Emacs mode for editing VHDL code.
  9. Copyright @copyright{} 1995--2008, 2010, 2012, 2015--2017 Free Software
  10. Foundation, Inc.
  11. @quotation
  12. Permission is granted to copy, distribute and/or modify this document
  13. under the terms of the GNU Free Documentation License, Version 1.3 or
  14. any later version published by the Free Software Foundation; with no
  15. Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
  16. and with the Back-Cover Texts as in (a) below. A copy of the license
  17. is included in the section entitled ``GNU Free Documentation License.''
  18. (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
  19. modify this GNU manual.''
  20. @end quotation
  21. @end copying
  22. @dircategory Emacs editing modes
  23. @direntry
  24. * VHDL Mode: (vhdl-mode). Emacs mode for editing VHDL code.
  25. @end direntry
  26. @finalout
  27. @titlepage
  28. @title VHDL Mode
  29. @sp 2
  30. @subtitle A GNU Emacs mode for editing VHDL code.
  31. @sp 2
  32. @author Reto Zimmermann
  33. @author @email{reto@@gnu.org}
  34. @author Rod Whitby
  35. @author @email{software.vhdl-mode@@rwhitby.net}
  36. @page
  37. @vskip 0pt plus 1filll
  38. @insertcopying
  39. @end titlepage
  40. @contents
  41. @ifnottex
  42. @node Top
  43. @top VHDL Mode, an Emacs mode for editing VHDL code
  44. @insertcopying
  45. @end ifnottex
  46. @menu
  47. * Introduction::
  48. * Getting Connected::
  49. * New Indentation Engine::
  50. * Customizing Indentation::
  51. * Syntactic Symbols::
  52. * Frequently Asked Questions::
  53. * Getting the latest VHDL Mode release::
  54. * Sample Init File::
  55. * Limitations and Known Bugs::
  56. * Mailing Lists and Submitting Bug Reports::
  57. * GNU Free Documentation License:: The license for this documentation.
  58. * Concept Index::
  59. * Command Index:: Command Index
  60. * Key Index:: Key Index
  61. * Variable Index:: Variable Index
  62. @end menu
  63. @node Introduction
  64. @chapter Introduction
  65. @cindex Introduction
  66. Welcome to VHDL Mode. This is a GNU Emacs mode for editing files
  67. containing VHDL code.
  68. This manual will describe the following:
  69. @itemize @bullet
  70. @item
  71. How to get started using VHDL Mode.
  72. @item
  73. How the indentation engine works.
  74. @item
  75. How to customize the indentation engine.
  76. @end itemize
  77. @findex vhdl-version
  78. The major version number was incremented to 3 with the addition of
  79. many new features for editing VHDL code to the new indentation engine,
  80. which was introduced in major version 2. To find the minor revision
  81. number of this release, use @kbd{M-x vhdl-version RET}.
  82. A special word of thanks goes to Rod Whitby, who wrote the
  83. VHDL Mode indentation engine, and to Barry Warsaw, who wrote
  84. the CC Mode indentation engine that formed the basis
  85. thereof. Their manuals were also the basis for this manual.
  86. This manual is not very up-to-date. It basically contains the
  87. indentation machine documentation by Rod Whitby with only minor
  88. adaptions. A short documentation of the entire VHDL Mode is available
  89. within the mode itself by typing @kbd{C-c C-h}. Also, all commands and
  90. customization of most variables are available through the menu, which
  91. makes everything highly self-explaining.
  92. @node Getting Connected
  93. @chapter Getting Connected
  94. @cindex Getting Connected
  95. To get started, simply visit a @file{.vhd} file in Emacs; or type
  96. @kbd{M-x vhdl-mode RET}.
  97. @node New Indentation Engine
  98. @chapter New Indentation Engine
  99. @cindex New Indentation Engine
  100. VHDL Mode has a new indentation engine, providing a simplified, yet
  101. flexible and general mechanism for customizing indentation. It breaks
  102. indentation calculation into two steps. First for the line of code being
  103. indented, VHDL Mode analyzes what kind of language construct it's
  104. looking at, then it applies user defined offsets to the current line
  105. based on this analysis.
  106. This section will briefly cover how indentation is calculated in
  107. VHDL Mode. It is important to understand the indentation model
  108. being used so that you will know how to customize VHDL Mode for
  109. your personal coding style.
  110. @menu
  111. * Syntactic Analysis:: Step 1 -- Syntactic Analysis
  112. * Indentation Calculation:: Step 2 -- Indentation Calculation
  113. @end menu
  114. @node Syntactic Analysis
  115. @section Syntactic Analysis
  116. @cindex Syntactic Analysis
  117. @vindex vhdl-offsets-alist
  118. @vindex offsets-alist (vhdl-)
  119. @cindex relative buffer position
  120. @cindex syntactic symbol
  121. @cindex syntactic component
  122. @cindex syntactic component list
  123. @cindex relative buffer position
  124. The first thing VHDL Mode does when indenting a line of code, is
  125. to analyze the line, determining the @dfn{syntactic component list} of
  126. the construct on that line. A @dfn{syntactic component} consists of a
  127. pair of information (in lisp parlance, a @emph{cons cell}), where the
  128. first part is a @dfn{syntactic symbol}, and the second part is a
  129. @dfn{relative buffer position}. Syntactic symbols describe elements of
  130. VHDL code, e.g., @code{statement}, @code{comment}, @code{block-open},
  131. @code{block-close}, etc. @xref{Syntactic Symbols}, for a complete list
  132. of currently recognized syntactic symbols and their semantics. Also,
  133. the variable @code{vhdl-offsets-alist} contains the list of currently
  134. supported syntactic symbols.
  135. Conceptually, a line of VHDL code is always indented relative to the
  136. indentation of some line higher up in the buffer. This is represented
  137. by the relative buffer position in the syntactic component.
  138. It might help to see an example. Suppose we had the following code as
  139. the only thing in a VHDL Mode buffer @footnote{The line numbers
  140. in this and future examples don't actually appear in the buffer.}:
  141. @example
  142. @group
  143. 1: inverter : process
  144. 2: begin
  145. 3: q <= not d;
  146. 4: wait on d;
  147. 5: end inverter;
  148. @end group
  149. @end example
  150. @kindex C-c C-x
  151. @findex vhdl-show-syntactic-information
  152. @findex show-syntactic-information (vhdl-)
  153. We can use the command @kbd{C-c C-x}
  154. (@code{vhdl-show-syntactic-information}) to simply report what the
  155. syntactic analysis is for the current line. Running this command on
  156. line 4 of example 1, we'd see in the echo area:
  157. @example
  158. ((statement . 28))
  159. @end example
  160. This tells us that the line is a statement and it is indented relative
  161. to buffer position 28, which happens to be the @samp{q} on line 3. If
  162. you were to move point to line 3 and hit @kbd{C-c C-x}, you would see:
  163. @example
  164. ((statement-block-intro . 20))
  165. @end example
  166. This indicates that line 3 is the first statement in a block, and is
  167. indented relative to buffer position 20, which is the @samp{b} in the
  168. @code{begin} keyword on line 2.
  169. @cindex comment only line
  170. Syntactic component lists can contain more than one component, and
  171. individual syntactic components need not have relative buffer positions.
  172. The most common example of this is a line that contains a @dfn{comment
  173. only line}.
  174. @example
  175. @group
  176. %%% TBD %%%
  177. @end group
  178. @end example
  179. @noindent
  180. Hitting @kbd{C-c C-x} on line 3 of the example gives us:
  181. @example
  182. ((comment-intro) (block-intro . 46))
  183. @end example
  184. @noindent
  185. so you can see that the syntactic component list contains two syntactic
  186. components. Also notice that the first component,
  187. @samp{(comment-intro)} has no relative buffer position.
  188. @node Indentation Calculation
  189. @section Indentation Calculation
  190. @cindex Indentation Calculation
  191. @vindex vhdl-offsets-alist
  192. @vindex offsets-alist (vhdl-)
  193. Indentation for the current line is calculated using the syntactic
  194. component list derived in step 1 above (see @ref{Syntactic
  195. Analysis}). Each component contributes to the final total indentation
  196. of the line in two ways.
  197. First, the syntactic symbols are looked up in the @code{vhdl-offsets-alist}
  198. variable, which is an association list of syntactic symbols and the
  199. offsets to apply for those symbols. These offsets are added to the
  200. running total.
  201. Second, if the component has a relative buffer position, VHDL Mode
  202. adds the column number of that position to the running total. By adding
  203. up the offsets and columns for every syntactic component on the list,
  204. the final total indentation for the current line is computed.
  205. Let's use our code example above to see how this works. Here is our
  206. example again.
  207. @example
  208. @group
  209. 1: inverter : process
  210. 2: begin
  211. 3: q <= not d;
  212. 4: wait on d;
  213. 5: end inverter;
  214. @end group
  215. @end example
  216. @kindex TAB
  217. Let's say point is on line 3 and we hit the @key{TAB} key to re-indent
  218. the line. Remember that the syntactic component list for that
  219. line is:
  220. @example
  221. ((statement-block-intro . 20))
  222. @end example
  223. @noindent
  224. VHDL Mode looks up @code{statement-block-intro} in the
  225. @code{vhdl-offsets-alist} variable. Let's say it finds the value @samp{2};
  226. it adds this to the running total (initialized to zero), yielding a
  227. running total indentation of 2 spaces.
  228. Next VHDL Mode goes to buffer position 20 and asks for the
  229. current column. Since the @code{begin} keyword at buffer position 20 is
  230. in column zero, it adds @samp{0} to the running total. Since there is
  231. only one syntactic component on the list for this line, indentation
  232. calculation is complete, and the total indentation for the line is 2
  233. spaces.
  234. Simple, huh?
  235. Actually, the mode usually just does The Right Thing without you having
  236. to think about it in this much detail. But when customizing
  237. indentation, it's helpful to understand the general indentation model
  238. being used.
  239. @vindex vhdl-echo-syntactic-information-p
  240. @vindex echo-syntactic-information-p (vhdl-)
  241. @cindex TAB
  242. To help you configure VHDL Mode, you can set the variable
  243. @code{vhdl-echo-syntactic-information-p} to non-@code{nil} so that the
  244. syntactic component list and calculated offset will always be echoed in
  245. the minibuffer when you hit @kbd{TAB}.
  246. @ignore
  247. @node Indentation Commands
  248. @chapter Indentation Commands
  249. @cindex Indentation Commands
  250. @strong{<TBD>}
  251. @end ignore
  252. @node Customizing Indentation
  253. @chapter Customizing Indentation
  254. @cindex Customizing Indentation
  255. @cindex vhdl-set-offset
  256. @cindex set-offset (vhdl-)
  257. The @code{vhdl-offsets-alist} variable is where you customize all your
  258. indentations. You simply need to decide what additional offset you want
  259. to add for every syntactic symbol. You can use the command @kbd{C-c
  260. O} (@code{vhdl-set-offset}) as the way to set offsets, both
  261. interactively and from your mode hook. Also, you can set up
  262. @emph{styles} of indentation. Most likely, you'll find one of the
  263. pre-defined styles will suit your needs, but if not, this section will
  264. describe how to set up basic editing configurations. @xref{Styles}, for
  265. an explanation of how to set up named styles.
  266. @cindex vhdl-basic-offset
  267. @cindex basic-offset (vhdl-)
  268. As mentioned previously, the variable @code{vhdl-offsets-alist} is an
  269. association list between syntactic symbols and the offsets to be applied
  270. for those symbols. In fact, these offset values can be an integer, a
  271. function or variable name, or one of the following symbols: @code{+},
  272. @code{-}, @code{++}, @code{--}, @code{*}, or @code{/}. The symbol
  273. values have the following meanings:
  274. @itemize @bullet
  275. @item
  276. @code{+} -- 1 x @code{vhdl-basic-offset}
  277. @item
  278. @code{-} -- -1 x @code{vhdl-basic-offset}
  279. @item
  280. @code{++} -- 2 x @code{vhdl-basic-offset}
  281. @item
  282. @code{--} -- -2 x @code{vhdl-basic-offset}
  283. @item
  284. @code{*} -- 0.5 x @code{vhdl-basic-offset}
  285. @item
  286. @code{/} -- -0.5 x @code{vhdl-basic-offset}
  287. @end itemize
  288. @noindent
  289. So, for example, because most of the default offsets are defined in
  290. terms of @code{+}, @code{-}, and @code{0}, if you like the general
  291. indentation style, but you use 2 spaces instead of 4 spaces per level,
  292. you can probably achieve your style just by changing
  293. @code{vhdl-basic-offset} like so (in your @file{.emacs} file):
  294. @example
  295. (setq vhdl-basic-offset 2)
  296. @end example
  297. To change indentation styles more radically, you will want to change the
  298. value associated with the syntactic symbols in the
  299. @code{vhdl-offsets-alist} variable. First, I'll show you how to do that
  300. interactively, then I'll describe how to make changes to your
  301. @file{.emacs} file so that your changes are more permanent.
  302. @menu
  303. * Interactive Customization::
  304. * Permanent Customization::
  305. * Styles::
  306. * Advanced Customizations::
  307. @end menu
  308. @node Interactive Customization
  309. @section Interactive Customization
  310. @cindex Interactive Customization
  311. As an example of how to customize indentation, let's change the
  312. style of the example above from:
  313. @example
  314. @group
  315. 1: inverter : process
  316. 2: begin
  317. 3: q <= not d;
  318. 4: wait on d;
  319. 5: end inverter;
  320. @end group
  321. @end example
  322. @noindent
  323. to:
  324. @example
  325. @group
  326. 1: inverter : process
  327. 2: begin
  328. 3: q <= not d;
  329. 4: wait on d;
  330. 5: end inverter;
  331. @end group
  332. @end example
  333. In other words, we want to change the indentation of the statements
  334. inside the inverter process. Notice that the construct we want to
  335. change starts on line 3. To change the indentation of a line, we need
  336. to see which syntactic component affect the offset calculations for that
  337. line. Hitting @kbd{C-c C-x} on line 3 yields:
  338. @example
  339. ((statement-block-intro . 20))
  340. @end example
  341. @findex vhdl-set-offset
  342. @findex set-offset (vhdl-)
  343. @kindex C-c O
  344. @noindent
  345. So we know that to change the offset of the first signal assignment, we need to
  346. change the indentation for the @code{statement-block-intro} syntactic
  347. symbol. To do this interactively, just hit @kbd{C-c O}
  348. (@code{vhdl-set-offset}). This prompts you for the syntactic symbol to
  349. change, providing a reasonable default. In this case, the default is
  350. @code{statement-block-intro}, which is just the syntactic symbol we want to
  351. change!
  352. After you hit return, VHDL Mode will then prompt you for the new
  353. offset value, with the old value as the default. The default in this
  354. case is @samp{+}, so hit backspace to delete the @samp{+}, then hit
  355. @samp{++} and @kbd{RET}. This will associate an offset of twice the
  356. basic indent with the syntactic symbol @code{statement-block-intro} in
  357. the @code{vhdl-offsets-alist} variable.
  358. @findex vhdl-indent-defun
  359. @findex indent-defun (vhdl-)
  360. To check your changes quickly, just enter @kbd{M-x vhdl-indent-defun} to
  361. reindent the entire function. The example should now look like:
  362. @example
  363. @group
  364. 1: inverter : process
  365. 2: begin
  366. 3: q <= not d;
  367. 4: wait on d;
  368. 5: end inverter;
  369. @end group
  370. @end example
  371. Notice how just changing the offset on line 3 is all we needed to do.
  372. Since the other affected lines are indented relative to line 3, they are
  373. automatically indented the way you'd expect. For more complicated
  374. examples, this may not always work. The general approach to take is to
  375. always start adjusting offsets for lines higher up in the file, then
  376. re-indent and see if any following lines need further adjustments.
  377. @node Permanent Customization
  378. @section Permanent Indentation
  379. @cindex Permanent Indentation
  380. @vindex vhdl-mode-hook
  381. @cindex hooks
  382. To make this change permanent, you need to add some lisp code to your
  383. @file{.emacs} file. VHDL Mode provides a @code{vhdl-mode-hook}
  384. that you can use to customize your language editing styles. This hook
  385. gets run as the last thing when you enter VHDL Mode.
  386. Here's a simplified example of what you can add to your @file{.emacs}
  387. file to make the changes described in the previous section
  388. (@ref{Interactive Customization}) more permanent. See the Emacs
  389. manuals for more information on customizing Emacs via hooks.
  390. @xref{Sample Init File}, for a more complete sample @file{.emacs} file.
  391. @example
  392. @group
  393. (defun my-vhdl-mode-hook ()
  394. ;; my customizations for all of vhdl-mode
  395. (vhdl-set-offset 'statement-block-intro '++)
  396. ;; other customizations can go here
  397. )
  398. (add-hook 'vhdl-mode-hook 'my-vhdl-mode-hook)
  399. @end group
  400. @end example
  401. For complex customizations, you will probably want to set up a
  402. @emph{style} that groups all your customizations under a single
  403. name. @xref{Styles}.
  404. The offset value can also be a function, and this is how power users
  405. gain enormous flexibility in customizing indentation. @xref{Advanced
  406. Customizations}.
  407. @node Styles
  408. @section Styles
  409. @cindex Styles
  410. Most people only need to edit code formatted in just a few well-defined
  411. and consistent styles. For example, their organization might impose a
  412. ``blessed'' style that all its programmers must conform to. Similarly,
  413. people who work on GNU software will have to use the GNU coding style on
  414. C code. Some shops are more lenient, allowing some variety of coding
  415. styles, and as programmers come and go, there could be a number of
  416. styles in use. For this reason, VHDL Mode makes it convenient for
  417. you to set up logical groupings of customizations called @dfn{styles},
  418. associate a single name for any particular style, and pretty easily
  419. start editing new or existing code using these styles. This chapter
  420. describes how to set up styles and how to edit your C code using styles.
  421. @menu
  422. * Built-in Styles::
  423. * Adding Styles::
  424. * File Styles::
  425. @end menu
  426. @node Built-in Styles
  427. @subsection Built-in Styles
  428. @cindex Built-in Styles
  429. If you're lucky, one of VHDL Mode's built-in styles might be just
  430. what you're looking for. Some of the most common VHDL styles are
  431. already built-in. These include:
  432. @itemize @bullet
  433. @item
  434. @cindex IEEE style
  435. @code{GNU} -- the coding style in the IEEE Language Reference Manual.
  436. @end itemize
  437. @findex vhdl-set-style
  438. @findex set-style (vhdl-)
  439. If you'd like to experiment with these built-in styles you can simply
  440. type @kbd{M-x vhdl-set-style RET} in a VHDL Mode buffer.
  441. You will be prompted for one of the above styles (with completion).
  442. Enter one of the styles and hit @kbd{RET}. Note however that setting a
  443. style in this way does @emph{not} automatically re-indent your file.
  444. @ignore
  445. For commands that you can use to view the effect of your changes, see
  446. @ref{Indentation Commands}.
  447. @end ignore
  448. Once you find a built-in style you like, you can make the change
  449. permanent by adding a call to your @file{.emacs} file. Let's say for
  450. example that you want to use the @code{IEEE} style in all your
  451. files. You would add this:
  452. @example
  453. @group
  454. (defun my-vhdl-mode-hook ()
  455. ;; use IEEE style for all VHDL code
  456. (vhdl-set-style "IEEE")
  457. ;; other customizations can go here
  458. )
  459. (add-hook 'vhdl-mode-hook 'my-vhdl-mode-hook)
  460. @end group
  461. @end example
  462. @noindent
  463. @xref{Permanent Customization}.
  464. @node Adding Styles
  465. @subsection Adding Styles
  466. @cindex Adding Styles
  467. @vindex vhdl-style-alist
  468. @vindex style-alist (vhdl-)
  469. @findex vhdl-add-style
  470. @findex add-style (vhdl-)
  471. If none of the built-in styles is appropriate, you'll probably want to
  472. add a new style definition. Styles are kept in the @code{vhdl-style-alist}
  473. variable, but you probably won't want to modify this variable directly.
  474. VHDL Mode provides a function, called @code{vhdl-add-style}, that you
  475. can use to easily add new styles or update existing styles. This
  476. function takes two arguments, a @var{stylename} string, and an
  477. association list @var{description} of style customizations. If
  478. @var{stylename} is not already in @code{vhdl-style-alist}, the new style is
  479. added, otherwise the style already associated with @var{stylename} is
  480. changed to the new @var{description}. This function also takes an
  481. optional third argument, which if non-@code{nil}, automatically
  482. institutes the new style in the current buffer.
  483. The sample @file{.emacs} file provides a concrete example of how a new
  484. style can be added and automatically set. @xref{Sample Init File}.
  485. @node File Styles
  486. @subsection File Styles
  487. @cindex File Styles
  488. @cindex local variables
  489. The Emacs manual describes how you can customize certain variables on a
  490. per-file basis by including a @dfn{Local Variable} block at the end of
  491. the file. So far, you've only seen a functional interface to
  492. VHDL Mode, which is highly inconvenient for use in a Local Variable
  493. block. VHDL Mode provides two variables that make it easier for
  494. you to customize your style on a per-file basis.
  495. @vindex vhdl-file-style
  496. @vindex file-style (vhdl-)
  497. @vindex vhdl-file-offsets
  498. @vindex file-offsets (vhdl-)
  499. The variable @code{vhdl-file-style} can be set to a style name string as
  500. described in @ref{Built-in Styles}. When the file is visited,
  501. VHDL Mode will automatically set the file's style to this style
  502. using @code{vhdl-set-style}.
  503. @vindex vhdl-offsets-alist
  504. @vindex offsets-alist (vhdl-)
  505. @findex vhdl-set-offset
  506. @findex set-offset (vhdl-)
  507. Another variable, @code{vhdl-file-offsets}, takes an association list
  508. similar to what is allowed in @code{vhdl-offsets-alist}. When the file is
  509. visited, VHDL Mode will automatically institute these offsets using
  510. @code{vhdl-set-offset}. @xref{Customizing Indentation}.
  511. Note that file style settings (i.e., @code{vhdl-file-style}) are applied
  512. before file offset settings (i.e., @code{vhdl-file-offsets}).
  513. @node Advanced Customizations
  514. @section Advanced Customizations
  515. @cindex Advanced Customizations
  516. @vindex vhdl-style-alist
  517. @vindex style-alist (vhdl-)
  518. @vindex vhdl-basic-offset
  519. @vindex basic-offset (vhdl-)
  520. For most users, VHDL Mode will support their coding styles with
  521. very little need for customizations. Usually, one of the standard
  522. styles defined in @code{vhdl-style-alist} will do the trick. Sometimes,
  523. one of the syntactic symbol offsets will need to be tweaked slightly, or
  524. perhaps @code{vhdl-basic-offset} will need to be changed. However, some
  525. styles require a more advanced ability for customization, and one of the
  526. real strengths of VHDL Mode is that the syntactic analysis model
  527. provides a very flexible framework for customizing indentation. This
  528. allows you to perform special indentation calculations for situations
  529. not handled by the mode directly.
  530. @menu
  531. * Custom Indentation Functions::
  532. * Other Special Indentations::
  533. @end menu
  534. @node Custom Indentation Functions
  535. @subsection Custom Indentation Functions
  536. @cindex Custom Indentation Functions
  537. @cindex custom indentation functions
  538. One of the most common ways to customize VHDL Mode is by writing
  539. @dfn{custom indentation functions} and associating them with specific
  540. syntactic symbols (see @ref{Syntactic Symbols}). VHDL Mode itself
  541. uses custom indentation functions to provide more sophisticated
  542. indentation, for example when lining up selected signal assignments:
  543. @example
  544. @group
  545. %%% TBD %%%
  546. @end group
  547. @end example
  548. In this example, the @code{statement-cont} syntactic symbol has an
  549. offset of @code{+}, and @code{vhdl-basic-offset} is 2, so lines 4
  550. through 6 are simply indented two spaces to the right of line 3. But
  551. perhaps we'd like VHDL Mode to be a little more intelligent so
  552. that it offsets the waveform descriptions relative to the signal
  553. assignment operator in line 3. To do this, we have to write a custom
  554. indentation function which finds the column of signal assignment
  555. operator on the first line of the statement. Here is the lisp code
  556. (from the @file{vhdl-mode.el} source file) that implements this:
  557. @example
  558. @group
  559. (defun vhdl-lineup-statement-cont (langelem)
  560. ;; line up statement-cont after the assignment operator
  561. (save-excursion
  562. (let* ((relpos (cdr langelem))
  563. (assignp (save-excursion
  564. (goto-char (vhdl-point 'boi))
  565. (and (re-search-forward "\\(<\\|:\\)="
  566. (vhdl-point 'eol) t)
  567. (- (point) (vhdl-point 'boi)))))
  568. (curcol (progn
  569. (goto-char relpos)
  570. (current-column)))
  571. foundp)
  572. (while (and (not foundp)
  573. (< (point) (vhdl-point 'eol)))
  574. (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
  575. (if (vhdl-in-literal (cdr langelem))
  576. (forward-char)
  577. (if (= (preceding-char) ?\()
  578. ;; skip over any parenthesized expressions
  579. (goto-char (min (vhdl-point 'eol)
  580. (scan-lists (point) 1 1)))
  581. ;; found an assignment operator (not at eol)
  582. (setq foundp (not (looking-at "\\s-*$"))))))
  583. (if (not foundp)
  584. ;; there's no assignment operator on the line
  585. vhdl-basic-offset
  586. ;; calculate indentation column after assign and ws, unless
  587. ;; our line contains an assignment operator
  588. (if (not assignp)
  589. (progn
  590. (forward-char)
  591. (skip-chars-forward " \t")
  592. (setq assignp 0)))
  593. (- (current-column) assignp curcol))
  594. )))
  595. @end group
  596. @end example
  597. @noindent
  598. Custom indent functions take a single argument, which is a syntactic
  599. component cons cell (see @ref{Syntactic Analysis}). The
  600. function returns an integer offset value that will be added to the
  601. running total indentation for the lne. Note that what actually gets
  602. returned is the difference between the column that the signal assignment
  603. operator is on, and the column of the buffer relative position passed in
  604. the function's argument. Remember that VHDL Mode automatically
  605. adds in the column of the component's relative buffer position and we
  606. don't want that value added into the final total twice.
  607. @cindex statement-cont syntactic symbol
  608. @findex vhdl-lineup-statement-cont
  609. @findex lineup-statement-cont (vhdl-)
  610. Now, to associate the function @code{vhdl-lineup-statement-cont} with the
  611. @code{statement-cont} syntactic symbol, we can add something like the
  612. following to our @code{vhdl-mode-hook}:
  613. @example
  614. (vhdl-set-offset 'statement-cont 'vhdl-lineup-statement-cont)
  615. @end example
  616. @findex vhdl-indent-defun
  617. Now the function looks like this after re-indenting (using @kbd{M-x
  618. vhdl-indent-defun}):
  619. @example
  620. @group
  621. %%% TBD %%%
  622. @end group
  623. @end example
  624. @vindex vhdl-offsets-alist
  625. @vindex offsets-alist (vhdl-)
  626. Custom indentation functions can be as simple or as complex as you like,
  627. and any syntactic symbol that appears in @code{vhdl-offsets-alist} can have
  628. a custom indentation function associated with it. Note however that
  629. using many custom indentation functions may have a performance impact on
  630. VHDL Mode.
  631. @node Other Special Indentations
  632. @subsection Other Special Indentations
  633. @cindex Other Special Indentations
  634. @vindex vhdl-special-indent-hook
  635. @vindex special-indent-hook (vhdl-)
  636. One other variable is available for you to customize VHDL Mode:
  637. @code{vhdl-special-indent-hook}. This is a standard hook variable that
  638. is called after every line is indented by VHDL Mode. You can use
  639. it to do any special indentation or line adjustments your style
  640. dictates, such as adding extra indentation to the port map clause in a
  641. component instantiation, etc. Note however, that you should not change
  642. @code{point} or @code{mark} inside your @code{vhdl-special-indent-hook}
  643. functions.
  644. @node Syntactic Symbols
  645. @chapter Syntactic Symbols
  646. @cindex Syntactic Symbols
  647. @vindex vhdl-offsets-alist
  648. The complete list of recognized syntactic symbols is described in the
  649. @code{vhdl-offsets-alist} variable. This chapter will provide some
  650. examples to help clarify these symbols.
  651. @cindex -open syntactic symbols
  652. @cindex -close syntactic symbols
  653. Most syntactic symbol names follow a general naming convention. When a
  654. line begins with a @code{begin} or @code{end} keyword, the syntactic
  655. symbol will contain the suffix @code{-open} or @code{-close}
  656. respectively.
  657. @cindex -intro syntactic symbols
  658. @cindex -cont syntactic symbols
  659. @cindex -block-intro syntactic symbols
  660. Usually, a distinction is made between the first line that introduces a
  661. construct and lines that continue a construct, and the syntactic symbols
  662. that represent these lines will contain the suffix @code{-intro} or
  663. @code{-cont} respectively. As a sub-classification of this scheme, a
  664. line which is the first of a particular block construct will contain the
  665. suffix @code{-block-intro}.
  666. @strong{<TBD> include the name and a brief example of every syntactic
  667. symbol currently recognized}
  668. @node Frequently Asked Questions
  669. @chapter Frequently Asked Questions
  670. @cindex Frequently Asked Questions
  671. @kindex C-x h
  672. @kindex ESC C-\
  673. @kindex ESC C-q
  674. @kindex ESC C-u
  675. @kindex RET
  676. @kindex LFD
  677. @findex newline-and-indent
  678. @quotation
  679. @strong{Q.} @emph{How do I re-indent the whole file?}
  680. @strong{A.} Visit the file and hit @kbd{C-x h} to mark the whole
  681. buffer. Then hit @kbd{@key{ESC} C-\} to re-indent the entire region
  682. which you've just marked. Or just enter @kbd{M-x vhdl-indent-buffer}.
  683. @sp 2
  684. @strong{Q.} @emph{How do I re-indent the entire function?}
  685. @strong{A.} Hit @kbd{@key{ESC} C-h} to mark the entire function. Then
  686. hit @kbd{@key{ESC} C-\} to re-indent the entire region which you've just
  687. marked.
  688. @sp 2
  689. @strong{Q.} @emph{How do I re-indent the current block?}
  690. @strong{A.} First move to the brace which opens the block with
  691. @kbd{@key{ESC} C-u}, then re-indent that expression with
  692. @kbd{@key{ESC} C-q}.
  693. @sp 2
  694. @strong{Q.} @emph{How do I re-indent the current statement?}
  695. @strong{A.} First move to the beginning of the statement with
  696. @kbd{@key{ESC} a}, then re-indent that expression with @kbd{@key{ESC}
  697. C-q}.
  698. @sp 2
  699. @strong{Q.} @emph{I put @code{(vhdl-set-offset 'statement-cont 0)}
  700. in my @file{.emacs} file but I get an error saying that
  701. @code{vhdl-set-offset}'s function definition is void.}
  702. @strong{A.} This means that VHDL Mode wasn't loaded into your
  703. Emacs session by the time the @code{vhdl-set-offset} call was reached,
  704. mostly likely because VHDL Mode is being autoloaded. Instead
  705. of putting the @code{vhdl-set-offset} line in your top-level
  706. @file{.emacs} file, put it in your @code{vhdl-mode-hook}, or
  707. simply add the following to the top of your @file{.emacs} file:
  708. @example
  709. (require 'vhdl-mode)
  710. @end example
  711. See the sample @file{.emacs} file @ref{Sample Init File} for
  712. details.
  713. @end quotation
  714. @node Getting the latest VHDL Mode release
  715. @chapter Getting the latest VHDL Mode release
  716. @cindex Getting the latest VHDL Mode release
  717. The best way to be sure you always have the latest VHDL Mode release
  718. is to join the @code{vhdl-mode-announce} mailing list. If you are a
  719. brave soul, and wish to participate in beta testing of new releases of
  720. VHDL Mode, you may also join the @code{vhdl-mode-victims} mailing
  721. list. Send email to the maintainer @email{reto@@gnu.org} to join
  722. either of these lists.
  723. The official Emacs VHDL Mode Home Page can be found at
  724. @uref{http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html}.
  725. @node Sample Init File
  726. @chapter Sample Init File
  727. @cindex Sample init file
  728. Most customizations can be done using the ``Customize'' entry in the
  729. VHDL Mode menu, which requires no editing of the .emacs file.
  730. If you want to customize indentation, here you go:
  731. @example
  732. ;; Here's a sample .emacs file that might help you along the way. Just
  733. ;; copy this region and paste it into your .emacs file. You may want to
  734. ;; change some of the actual values.
  735. (defconst my-vhdl-style
  736. '((vhdl-tab-always-indent . t)
  737. (vhdl-comment-only-line-offset . 4)
  738. (vhdl-offsets-alist . ((arglist-close . vhdl-lineup-arglist)
  739. (statement-cont . 0)
  740. (case-alternative . 4)
  741. (block-open . 0)))
  742. (vhdl-echo-syntactic-information-p . t)
  743. )
  744. "My VHDL Programming Style")
  745. ;; Customizations for vhdl-mode
  746. (defun my-vhdl-mode-hook ()
  747. ;; add my personal style and set it for the current buffer
  748. (vhdl-add-style "PERSONAL" my-vhdl-style t)
  749. ;; offset customizations not in my-vhdl-style
  750. (vhdl-set-offset 'statement-case-intro '++)
  751. ;; other customizations
  752. (setq tab-width 8
  753. ;; this will make sure spaces are used instead of tabs
  754. indent-tabs-mode nil)
  755. ;; keybindings for VHDL are put in vhdl-mode-map
  756. (define-key vhdl-mode-map "\C-m" 'newline-and-indent)
  757. )
  758. (add-hook 'vhdl-mode-hook 'my-vhdl-mode-hook)
  759. @end example
  760. @node Limitations and Known Bugs
  761. @chapter Limitations and Known Bugs
  762. @cindex Limitations and Known Bugs
  763. @itemize @bullet
  764. @item
  765. Re-indenting large regions or expressions can be slow.
  766. @ignore
  767. @item
  768. The index menu does not work on my XEmacs installation (don't know why).
  769. @end ignore
  770. @end itemize
  771. @node Mailing Lists and Submitting Bug Reports
  772. @chapter Mailing Lists and Submitting Bug Reports
  773. @cindex Mailing Lists and Submitting Bug Reports
  774. @kindex C-c C-b
  775. @findex vhdl-submit-bug-report
  776. @findex submit-bug-report (vhdl-)
  777. @cindex beta testers mailing list
  778. @cindex announcement mailing list
  779. To report bugs, use the @kbd{C-c C-b} (@code{vhdl-submit-bug-report})
  780. command. This provides vital information I need to reproduce your
  781. problem. Make sure you include a concise, but complete code example.
  782. Please try to boil your example down to just the essential code needed
  783. to reproduce the problem, and include an exact recipe of steps needed to
  784. expose the bug. Be especially sure to include any code that appears
  785. @emph{before} your bug example.
  786. For other help or suggestions, send a message to @email{reto@@gnu.org}.
  787. Send an add message to @email{reto@@gnu.org} to get on the
  788. @code{vhdl-mode-victims} beta testers list where beta releases of
  789. VHDL Mode are posted. Note that you shouldn't expect beta
  790. releases to be as stable as public releases.
  791. There is also an announce only list where the latest public releases
  792. of VHDL Mode are posted. Send an add message to
  793. @email{reto@@gnu.org} to be added to this list.
  794. @node GNU Free Documentation License
  795. @appendix GNU Free Documentation License
  796. @include doclicense.texi
  797. @node Concept Index
  798. @unnumbered Concept Index
  799. @printindex cp
  800. @node Command Index
  801. @unnumbered Command Index
  802. Since all VHDL Mode commands are prepended with the string
  803. @samp{vhdl-}, each appears under its @code{vhdl-<thing>} name and its
  804. @code{<thing> (vhdl-)} name.
  805. @iftex
  806. @sp 2
  807. @end iftex
  808. @printindex fn
  809. @node Key Index
  810. @unnumbered Key Index
  811. @printindex ky
  812. @node Variable Index
  813. @unnumbered Variable Index
  814. Since all VHDL Mode variables are prepended with the string
  815. @samp{vhdl-}, each appears under its @code{vhdl-<thing>} name and its
  816. @code{<thing> (vhdl-)} name.
  817. @iftex
  818. @sp 2
  819. @end iftex
  820. @printindex vr
  821. @bye