 ;;
 
 ;; This variable will always hold the version number of the mode
-(defconst verilog-mode-version "2017-05-08-eab72ed-vpo"
+(defconst verilog-mode-version "2017-05-09-eb40517-vpo"
   "Version of this Verilog mode.")
 (defconst verilog-mode-release-emacs nil
   "If non-nil, this version of Verilog mode was released with Emacs itself.")

	      (forward-line 1))
	    (unless quiet (message "")))))))

(defun verilog-pretty-expr (&optional quiet _myre)
  "Line up expressions around point, optionally QUIET with regexp _MYRE ignored."
  (interactive)
  (if (not (verilog-in-comment-or-string-p))
      (save-excursion
        (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
               (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
          (beginning-of-line)
          (if (and (not (looking-at rexp ))
                   (looking-at verilog-assignment-operation-re)
                   (save-excursion
                     (goto-char (match-end 2))
                     (and (not (verilog-in-attribute-p))
                          (not (verilog-in-parameter-p))
                          (not (verilog-in-comment-or-string-p)))))
              (let* ((here (point))
                     (e) (r)
                     (start
                      (progn
                        (beginning-of-line)
                        (setq e (point))
                        (verilog-backward-syntactic-ws)
                        (beginning-of-line)
                        (while (and (not (looking-at rexp1))
                                    (looking-at verilog-assignment-operation-re)
                                    (not (bobp))
                                    )
                          (setq e (point))
                          (verilog-backward-syntactic-ws)
                          (beginning-of-line)
                          ) ;Ack, need to grok `define
                        e))
                     (end
                      (progn
                        (goto-char here)
                        (end-of-line)
                        (setq e (point))	;Might be on last line
                        (verilog-forward-syntactic-ws)
                        (beginning-of-line)
                        (while (and
                                (not (looking-at rexp1 ))
                                (looking-at verilog-assignment-operation-re)
                                (progn
                                  (end-of-line)
                                  (not (eq e (point)))))
                          (setq e (point))
                          (verilog-forward-syntactic-ws)
                          (beginning-of-line)
                          )
                        e))
                     (endpos (set-marker (make-marker) end))
                     (ind)
                     )
                (goto-char start)
                (verilog-do-indent (verilog-calculate-indent))
                (if (and (not quiet)
                         (> (- end start) 100))
                    (message "Lining up expressions..(please stand by)"))

                ;; Set indent to minimum throughout region
                (while (< (point) (marker-position endpos))
                  (beginning-of-line)
                  (verilog-just-one-space verilog-assignment-operation-re)
                  (beginning-of-line)
                  (verilog-do-indent (verilog-calculate-indent))
                  (end-of-line)
                  (verilog-forward-syntactic-ws)
                  )

                ;; Now find biggest prefix
                (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))

                ;; Now indent each line.
                (goto-char start)
                (while (progn (setq e (marker-position endpos))
                              (setq r (- e (point)))
                              (> r 0))
                  (setq e (point))
                  (if (not quiet) (message "%d" r))
                  (cond
                   ((looking-at verilog-assignment-operation-re)
                    (goto-char (match-beginning 2))
                    (if (not (or (verilog-in-parenthesis-p)  ; leave attributes and comparisons alone
                                 (verilog-in-coverage-p)))
                        (if (eq (char-after) ?=)
                            (indent-to (1+ ind))	; line up the = of the <= with surrounding =
                          (indent-to ind)
                          ))
                    )
                   ((verilog-continued-line-1 start)
                    (goto-char e)
                    (indent-line-to ind))
                   (t		; Must be comment or white space
                    (goto-char e)
                    (verilog-forward-ws&directives)
                    (forward-line -1))
                   )
                  (forward-line 1))
                (unless quiet (message ""))
                ))))))

(defun verilog-just-one-space (myre)
  "Remove extra spaces around regular expression MYRE."

	;;(skip-chars-backward " \t")
	(1+ (current-column))))))

(defun verilog-get-lineup-indent-2 (regexp beg end)
  "Return the indent level that will line up several lines.
The lineup string is searched using REGEXP within the region between points
BEG and END."
  (save-excursion
    (let ((ind 0))
      (goto-char beg)
      ;; Get rightmost position
      (while (< (point) end)
	(when (and (verilog-re-search-forward regexp end 'move)
                   (not (verilog-in-attribute-p))) ; skip attribute exprs
	  (goto-char (match-beginning 2))
	  (verilog-backward-syntactic-ws)
	  (if (> (current-column) ind)
	      (setq ind (current-column)))
	  (goto-char (match-end 0))))
      (setq ind (if (> ind 0)
	            (1+ ind)
	          ;; No lineup-string found
	          (goto-char beg)
	          (end-of-line)
	          (skip-chars-backward " \t")
	          (1+ (current-column))))
      ind)))

(defun verilog-comment-depth (type val)
  "A useful mode debugging aide.  TYPE and VAL are comments for insertion."
