Previous: Syntactic Analysis, Up: New Indentation Engine [Contents][Index]

### 3.2 Indentation Calculation

Indentation for the current line is calculated using the syntactic component list derived in step 1 above (see Syntactic Analysis). Each component contributes to the final total indentation of the line in two ways.

First, the syntactic symbols are looked up in the `vhdl-offsets-alist` variable, which is an association list of syntactic symbols and the offsets to apply for those symbols. These offsets are added to the running total.

Second, if the component has a relative buffer position, VHDL Mode adds the column number of that position to the running total. By adding up the offsets and columns for every syntactic component on the list, the final total indentation for the current line is computed.

Let’s use our code example above to see how this works. Here is our example again.

      1: inverter : process
      2: begin
      3:   q <= not d;
      4:   wait on d;
      5: end inverter;

Let’s say point is on line 3 and we hit the `TAB` key to re-indent the line. Remember that the syntactic component list for that line is:

    ((statement-block-intro . 20))

VHDL Mode looks up `statement-block-intro` in the `vhdl-offsets-alist` variable. Let’s say it finds the value ‘`2`’; it adds this to the running total (initialized to zero), yielding a running total indentation of 2 spaces.

Next VHDL Mode goes to buffer position 20 and asks for the current column. Since the `begin` keyword at buffer position 20 is in column zero, it adds ‘`0`’ to the running total. Since there is only one syntactic component on the list for this line, indentation calculation is complete, and the total indentation for the line is 2 spaces. Simple, huh?

Actually, the mode usually just does The Right Thing without you having to think about it in this much detail. But when customizing indentation, it’s helpful to understand the general indentation model being used.

To help you configure VHDL Mode, you can set the variable `vhdl-echo-syntactic-information-p` to non-`nil` so that the syntactic component list and calculated offset will always be echoed in the minibuffer when you hit `TAB`.

Previous: Syntactic Analysis, Up: New Indentation Engine [Contents][Index]