Function: vhdl-align-region-2
vhdl-align-region-2 is a byte-compiled function defined in
vhdl-mode.el.gz.
Signature
(vhdl-align-region-2 BEGIN END MATCH &optional SUBSTR SPACING)
Documentation
Align a range of lines from BEGIN to END.
The regular expression MATCH must match exactly one field: the whitespace to be contracted/expanded. The alignment column will equal the rightmost column of the widest whitespace block. SPACING is the amount of extra spaces to add to the calculated maximum required. SPACING defaults to 1 so that at least one space is inserted after the token in MATCH.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/vhdl-mode.el.gz
(defun vhdl-align-region-2 (begin end match &optional substr spacing)
"Align a range of lines from BEGIN to END.
The regular expression MATCH must match exactly one field: the
whitespace to be contracted/expanded. The alignment column will
equal the rightmost column of the widest whitespace block.
SPACING is the amount of extra spaces to add to the calculated
maximum required. SPACING defaults to 1 so that at least one
space is inserted after the token in MATCH."
(setq spacing (or spacing 1))
(setq substr (or substr 1))
(save-excursion
(let (distance (max 0) (lines 0) bol eol width)
;; Determine the greatest whitespace distance to the alignment
;; character
(goto-char begin)
(setq eol (line-end-position)
bol (setq begin (progn (beginning-of-line) (point))))
(while (< bol end)
(save-excursion
(when (and (vhdl-re-search-forward match eol t)
(save-excursion
(goto-char (match-beginning 0))
(forward-char)
(and (not (vhdl-in-literal))
(not (vhdl-in-quote-p))
(not (vhdl-in-extended-identifier-p))))
(not (looking-at "\\s-*$")))
(setq distance (- (match-beginning substr) bol))
(when (> distance max)
(setq max distance))))
(forward-line)
(setq bol (point)
eol (line-end-position))
(setq lines (1+ lines)))
;; Now insert enough maxs to push each assignment operator to
;; the same column. We need to use 'lines' as a counter, since
;; the location of the mark may change
(goto-char (setq bol begin))
(setq eol (line-end-position))
(while (> lines 0)
(when (and (vhdl-re-search-forward match eol t)
(save-excursion
(goto-char (match-beginning 0))
(forward-char)
(and (not (vhdl-in-literal))
(not (vhdl-in-quote-p))
(not (vhdl-in-extended-identifier-p))))
(not (looking-at "\\s-*$"))
(> (match-beginning 0) ; not if at boi
(save-excursion (back-to-indentation) (point))))
(setq width (- (match-end substr) (match-beginning substr)))
(setq distance (- (match-beginning substr) bol))
(goto-char (match-beginning substr))
(delete-char width)
(insert-char ? (+ (- max distance) spacing)))
(beginning-of-line)
(forward-line)
(setq bol (point)
eol (line-end-position))
(setq lines (1- lines))))))