Function: verilog-pretty-expr
verilog-pretty-expr is an interactive and byte-compiled function
defined in verilog-mode.el.gz.
Signature
(verilog-pretty-expr &optional QUIET)
Documentation
Line up expressions around point.
If QUIET is non-nil, do not print messages showing the progress of line-up.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/verilog-mode.el.gz
(defun verilog-pretty-expr (&optional quiet)
"Line up expressions around point.
If QUIET is non-nil, do not print messages showing the progress of line-up."
(interactive)
(let* ((basic-complete-pretty-expr-re (if verilog-align-assign-expr
verilog-basic-complete-expr-no-assign-re
verilog-basic-complete-expr-re))
(complete-pretty-expr-re (concat verilog-extended-complete-re "\\|\\(" basic-complete-pretty-expr-re "\\)"))
(discard-re (concat "^\\s-*\\(" complete-pretty-expr-re "\\)"))
rstart rend)
(save-excursion
(when (region-active-p)
(setq rstart (region-beginning))
(setq rend (region-end))
(goto-char rstart))
(unless (verilog-in-comment-or-string-p)
(beginning-of-line)
(when (and (verilog--pretty-expr-assignment-found discard-re)
(save-excursion
(goto-char (match-end 2))
(and (not (verilog-in-attribute-p))
(not (verilog-in-comment-or-string-p)))))
(let* ((start (cond (;; Using region
(region-active-p)
rstart)
(;; Parameter list
(verilog-in-parenthesis-p)
(progn
(verilog-backward-up-list 1)
(forward-char)
(verilog-re-search-forward verilog-assignment-operation-re-2 nil 'move)
(goto-char (match-beginning 0))
(point)))
(t ;; Declarations
(save-excursion ; BOL of the first line of the assignment block
(beginning-of-line)
(let ((pt (point)))
(verilog-backward-syntactic-ws)
(beginning-of-line)
(while (and (verilog--pretty-expr-assignment-found discard-re)
(not (bobp)))
(setq pt (point))
(verilog-backward-syntactic-ws)
(beginning-of-line)) ; Ack, need to grok `define
pt)))))
(startpos (set-marker (make-marker) start))
(end (cond (;; Using region
(region-active-p)
(verilog--pretty-expr-find-end discard-re rend))
(;; Parameter list
(verilog-in-parenthesis-p)
(verilog--pretty-expr-find-end))
(t ;; Declarations
(verilog--pretty-expr-find-end discard-re))))
(endpos (set-marker (make-marker) end))
(contains-2-char-operator (string-match "<=" (buffer-substring-no-properties start end))))
;; Start with alignment
(goto-char startpos)
(unless (save-excursion
(beginning-of-line)
(looking-at discard-re))
(verilog-do-indent (verilog-calculate-indent)))
(when (and (not quiet)
(> (- (marker-position endpos) (marker-position startpos)) 100))
(message "Lining up expressions.. (please stand by)"))
;; Set indent to minimum throughout region
;; Rely on mark rather than on point as the indentation changes can
;; make the older point reference obsolete
(while (< (point) (marker-position endpos))
(beginning-of-line)
(save-excursion
(if (looking-at verilog-complete-re)
(progn (goto-char (marker-position startpos))
(verilog-just-one-space verilog-assignment-operation-re-2))
(verilog-just-one-space verilog-assignment-operation-re)))
(verilog-do-indent (verilog-calculate-indent))
(end-of-line)
(verilog-forward-syntactic-ws))
(let ((ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re (marker-position startpos) (marker-position endpos))) ; Find the biggest prefix
e)
;; Now indent each line.
(goto-char (marker-position startpos))
(while (progn
(setq e (marker-position endpos))
(> e (point)))
(unless quiet
(message " verilog-pretty-expr: %d" (- e (point))))
(setq e (point))
(cond
((or (looking-at verilog-assignment-operation-re)
(and (verilog-in-parenthesis-p)
(looking-at verilog-assignment-operation-re-2)))
(goto-char (match-beginning 2))
(unless (or (and (verilog-in-parenthesis-p) ; Leave attributes and comparisons alone
(save-excursion ; Allow alignment of some expressions inside param/port list
(verilog-backward-up-list 1)
(verilog-beg-of-statement-1)
(not (looking-at verilog-defun-level-re))))
(verilog-in-coverage-p))
(if (and contains-2-char-operator
(eq (char-after) ?=))
(indent-to (1+ ind)) ; Line up the = of the <= with surrounding =
(indent-to ind)))
(forward-line 1))
((and (save-excursion
(verilog-forward-syntactic-ws)
(not (looking-at verilog-complete-re)))
(verilog-continued-line-1 (marker-position startpos)))
(goto-char e)
(indent-line-to ind)
(forward-line 1))
(t ; Must be comment, white space or syntax error
(goto-char e)
(forward-line 1))))
;; Align comments if enabled
(when verilog-align-decl-expr-comments
(verilog-align-comments startpos endpos))
(unless quiet
(message "")))))))))