* verilog-mode.el (verilog-forward-sexp, verilog-calc-1): Support
[bpt/emacs.git] / lisp / progmodes / verilog-mode.el
index 8239cdd..05ce36c 100644 (file)
@@ -1,7 +1,7 @@
 ;; verilog-mode.el --- major mode for editing verilog source in Emacs
 
 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Michael McNamara (mac@verilog.com)
 ;;  http://www.verilog.com
@@ -79,7 +79,7 @@
 ;; .emacs, or in your site's site-load.el
 
 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
-; (add-to-list 'auto-mode-alist '("\\.[ds]?v\\'" . verilog-mode))
+; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
 
 ;; If you want to customize Verilog mode to fit your needs better,
 ;; you may add these lines (the values of the variables presented
 ;;; Code:
 
 ;; This variable will always hold the version number of the mode
-(defconst verilog-mode-version "547"
+(defconst verilog-mode-version "565"
   "Version of this Verilog mode.")
-(defconst verilog-mode-release-date "2009-11-05-GNU"
+(defconst verilog-mode-release-date "2010-03-01-GNU"
   "Release date of this Verilog mode.")
 (defconst verilog-mode-release-emacs t
   "If non-nil, this version of Verilog mode was released with Emacs itself.")
@@ -426,7 +426,7 @@ are lineup only when \\[verilog-pretty-declarations] is typed."
 
   :type '(radio (const :tag "Line up Assignments and Declarations" all)
                (const :tag "Line up Assignment statements" assignments )
-               (const :tag "Line up Declarartions" declarations)
+               (const :tag "Line up Declarations" declarations)
                (function :tag "Other"))
   :group 'verilog-mode-indent )
 
@@ -1203,7 +1203,7 @@ If set will become buffer local.")
        :help           "Help on AUTOARG - declaring module port list"]
       ["AUTOASCIIENUM"                 (describe-function 'verilog-auto-ascii-enum)
        :help           "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
-      ["AUTOINOUTCOMP"                 (describe-function 'verilog-auto-inout-complement)
+      ["AUTOINOUTCOMP"                 (describe-function 'verilog-auto-inout-comp)
        :help           "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
       ["AUTOINOUTMODULE"               (describe-function 'verilog-auto-inout-module)
        :help           "Help on AUTOINOUTMODULE - copying i/o from another file"]
@@ -1553,6 +1553,38 @@ find the errors."
        "`ovm_sequencer_utils_end"
        ) nil )))
 
+(defconst verilog-vmm-begin-re
+  (eval-when-compile
+    (verilog-regexp-opt
+     '(
+       "`vmm_data_member_begin"
+       "`vmm_env_member_begin"
+       "`vmm_scenario_member_begin"
+       "`vmm_subenv_member_begin"
+       "`vmm_xactor_member_begin"
+       ) nil ) ) )
+
+(defconst verilog-vmm-end-re
+  (eval-when-compile
+    (verilog-regexp-opt
+     '(
+       "`vmm_data_member_end"
+       "`vmm_env_member_end"
+       "`vmm_scenario_member_end"
+       "`vmm_subenv_member_end"
+       "`vmm_xactor_member_end"
+       ) nil ) ) )
+
+(defconst verilog-vmm-statement-re
+  (eval-when-compile
+    (verilog-regexp-opt
+     '(
+;;       "`vmm_xactor_member_enum_array"
+       "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
+;;       "`vmm_xactor_member_scalar_array"
+;;       "`vmm_xactor_member_scalar"
+       ) nil )))
+
 (defconst verilog-ovm-statement-re
   (eval-when-compile
     (verilog-regexp-opt
@@ -1679,7 +1711,8 @@ find the errors."
   (concat
    "\\(\\<else\\>\\)\\|"               ; 1
    "\\(\\<if\\>\\)\\|"                 ; 2
-   "\\(\\<end\\>\\)\\|"                        ; 3
+   "\\(\\<assert\\>\\)\\|"              ; 3
+   "\\(\\<end\\>\\)\\|"                        ; 3.1
    "\\(\\<endcase\\>\\)\\|"            ; 4
    "\\(\\<endfunction\\>\\)\\|"                ; 5
    "\\(\\<endtask\\>\\)\\|"            ; 6
@@ -1689,6 +1722,12 @@ find the errors."
    "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
    "\\(\\<endclass\\>\\)\\|"            ; 11
    "\\(\\<endgroup\\>\\)\\|"            ; 12
+   ;; VMM
+   "\\(\\<`vmm_data_member_end\\>\\)\\|"
+   "\\(\\<`vmm_env_member_end\\>\\)\\|"
+   "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
+   "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
+   "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
    ;; OVM
    "\\(\\<`ovm_component_utils_end\\>\\)\\|"
    "\\(\\<`ovm_field_utils_end\\>\\)\\|"
@@ -1777,7 +1816,12 @@ find the errors."
        "`ovm_object_utils_end"
        "`ovm_sequence_utils_end"
        "`ovm_sequencer_utils_end"
-
+       ;; VMM
+       "`vmm_data_member_end"
+       "`vmm_env_member_end"
+       "`vmm_scenario_member_end"
+       "`vmm_subenv_member_end"
+       "`vmm_xactor_member_end"
        ))))
 
 
@@ -1832,7 +1876,12 @@ find the errors."
        "`ovm_object_param_utils_begin"
        "`ovm_sequence_utils_begin"
        "`ovm_sequencer_utils_begin"
-
+       ;; VMM
+       "`vmm_data_member_begin"
+       "`vmm_env_member_begin"
+       "`vmm_scenario_member_begin"
+       "`vmm_subenv_member_begin"
+       "`vmm_xactor_member_begin"
        ))))
 ;; These are the same words, in a specific order in the regular
 ;; expression so that matching will work nicely for
@@ -1854,6 +1903,7 @@ find the errors."
           "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
           "\\|\\(\\<clocking\\>\\)"          ;22 27
           "\\|\\(\\<`ovm_[a-z_]+_begin\\>\\)" ;28
+           "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
           ;;
 
           ))
@@ -1888,7 +1938,7 @@ find the errors."
        "endfunction"
        "endgenerate"
        "endmodule"
-       "endprimative"
+       "endprimitive"
        "endinterface"
        "endpackage"
        "endspecify"
@@ -2025,6 +2075,18 @@ find the errors."
        "`ovm_object_utils_end"
        "`ovm_sequence_utils_end"
        "`ovm_sequencer_utils_end"
+       ;; VMM Begin tokens
+       "`vmm_data_member_begin"
+       "`vmm_env_member_begin"
+       "`vmm_scenario_member_begin"
+       "`vmm_subenv_member_begin"
+       "`vmm_xactor_member_begin"
+       ;; VMM End tokens
+       "`vmm_data_member_end"
+       "`vmm_env_member_end"
+       "`vmm_scenario_member_end"
+       "`vmm_subenv_member_end"
+       "`vmm_xactor_member_end"
        ))))
 
 (defconst verilog-defun-level-not-generate-re
@@ -2054,7 +2116,8 @@ find the errors."
      `(
        "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
        ))))
-(defconst verilog-disable-fork-re "disable\\s-+fork")
+(defconst verilog-disable-fork-re "disable\\s-+fork\\>")
+(defconst verilog-fork-wait-re "fork\\s-+wait\\>")
 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?")
 (defconst verilog-extended-complete-re
   (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)"
@@ -2136,6 +2199,11 @@ find the errors."
      "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
      "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
      "wire" "with" "within" "wor" "xnor" "xor"
+     ;; 1800-2009
+     "accept_on" "checker" "endchecker" "eventually" "global" "implies"
+     "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
+     "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
+     "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
  )
  "List of Verilog keywords.")
 
@@ -2252,7 +2320,7 @@ See also `verilog-font-lock-extra-types'.")
             "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
             "event" "genvar" "inout" "input" "integer" "localparam"
             "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
-            "output" "parameter" "pmos" "pull0" "pull1" "pullup"
+            "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
             "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
             "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
             "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
@@ -2266,7 +2334,7 @@ See also `verilog-font-lock-extra-types'.")
           '("surefire" "synopsys" "rtl_synthesis" "verilint" "leda" "0in") nil
            )))
 
-       (verilog-p1800-keywords
+       (verilog-1800-2005-keywords
        (eval-when-compile
          (verilog-regexp-opt
           '("alias" "assert" "assume" "automatic" "before" "bind"
@@ -2290,6 +2358,15 @@ See also `verilog-font-lock-extra-types'.")
             "wait_order" "weak0" "weak1" "wildcard" "with" "within"
             ) nil )))
 
+       (verilog-1800-2009-keywords
+       (eval-when-compile
+         (verilog-regexp-opt
+          '("accept_on" "checker" "endchecker" "eventually" "global"
+            "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
+            "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
+            "sync_accept_on" "sync_reject_on" "unique0" "until"
+            "until_with" "untyped" "weak" ) nil )))
+
        (verilog-ams-keywords
        (eval-when-compile
          (verilog-regexp-opt
@@ -2341,11 +2418,17 @@ See also `verilog-font-lock-extra-types'.")
                 'font-lock-type-face))
         (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
           'font-lock-type-face)
-        ;; Fontify IEEE-P1800 keywords appropriately
+        ;; Fontify IEEE-1800-2005 keywords appropriately
+        (if verilog-highlight-p1800-keywords
+            (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
+                  'verilog-font-lock-p1800-face)
+          (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
+                'font-lock-type-face))
+        ;; Fontify IEEE-1800-2009 keywords appropriately
         (if verilog-highlight-p1800-keywords
-            (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>")
+            (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
                   'verilog-font-lock-p1800-face)
-          (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>")
+          (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
                 'font-lock-type-face))
         ;; Fontify Verilog-AMS keywords
         (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
@@ -2518,20 +2601,28 @@ Use filename, if current buffer being edited shorten to just buffer name."
        (setq md 3) ;; ender is third item in regexp
        )
        ((match-end 4)
-       ;; might be "disable fork"
-       (if (or
-            (looking-at verilog-disable-fork-re)
-            (and (looking-at "fork")
-                 (progn
-                   (forward-word -1)
-                   (looking-at verilog-disable-fork-re))))
-           (progn
-             (goto-char (match-end 0))
-             (forward-word 1)
-             (setq reg nil))
-         (progn
-           ;; Search forward for matching join
-           (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))))
+       ;; might be "disable fork" or "fork wait"
+       (let
+           (here)
+         (if (looking-at verilog-fork-wait-re)
+             (progn  ;; it is a fork wait; ignore it
+               (goto-char (match-end 0))
+               (setq reg nil))
+           (if (or
+                (looking-at verilog-disable-fork-re)
+                (and (looking-at "fork")
+                     (progn 
+                       (setq here (point)) ;; sometimes a fork is just a fork
+                       (forward-word -1)
+                       (looking-at verilog-disable-fork-re))))
+               (progn ;; it is a disable fork; ignore it
+                 (goto-char (match-end 0))
+                 (forward-word 1)
+                 (setq reg nil))
+             (progn ;; it is a nice simple fork
+               (goto-char here)   ;; return from looking for "disable fork"
+               ;; Search forward for matching join
+               (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))))))
        ((match-end 6)
        ;; Search forward for matching endclass
        (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
@@ -2582,12 +2673,27 @@ Use filename, if current buffer being edited shorten to just buffer name."
                (let ((depth 1))
                  (while (verilog-re-search-forward reg nil 'move)
                    (cond
-                    ((match-end md) ; the closer in reg, so we are climbing out
+                    ((match-end md) ; a closer in regular expression, so we are climbing out
                      (setq depth (1- depth))
                      (if (= 0 depth) ; we are out!
                          (throw 'skip 1)))
-                    ((match-end 1) ; the opener in reg, so we are deeper now
-                     (setq depth (1+ depth))))))
+                    ((match-end 1) ; an opener in the r-e, so we are in deeper now
+                     (setq here (point)) ; remember where we started
+                     (goto-char (match-beginning 1))
+                     (cond
+                      ((looking-at verilog-fork-wait-re)
+                       (goto-char (match-end 0))) ; false alarm
+                      ((if (or
+                            (looking-at verilog-disable-fork-re)
+                            (and (looking-at "fork")
+                                 (progn 
+                                   (forward-word -1)
+                                   (looking-at verilog-disable-fork-re))))
+                           (progn ;; it is a disable fork; another false alarm
+                             (goto-char (match-end 0)))
+                         (progn ;; it is a simple fork (or has nothing to do with fork)
+                           (goto-char here)
+                           (setq depth (1+ depth))))))))))
              (if (verilog-re-search-forward reg nil 'move)
                  (throw 'skip 1))))))
 
@@ -3251,7 +3357,7 @@ With ARG, first kill any existing labels."
   (while
       ;; If the current point does not begin a new
       ;; statement, as in the character ahead of us is a ';', or SOF
-      ;; or the string after us unambiguosly starts a statement,
+      ;; or the string after us unambiguously starts a statement,
       ;; or the token before us unambiguously ends a statement,
       ;; then move back a token and test again.
       (not (or
@@ -4278,7 +4384,8 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
                   ;; if we have a directive, done.
                   (if (save-excursion (beginning-of-line)
                                       (and (looking-at verilog-directive-re-1)
-                                           (not (looking-at "[ \t]*`ovm_"))))
+                                           (not (or (looking-at "[ \t]*`ovm_") 
+                                 (looking-at "[ \t]*`vmm_")))))
                       (throw 'nesting 'directive))
            ;; indent structs as if there were module level
            (if (verilog-in-struct-p)
@@ -4338,6 +4445,14 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
                                       (beginning-of-line)
                                       (verilog-forward-syntactic-ws)
                                       (throw 'nesting 'statement)))))
+                             ((match-end 3) ; assert block
+                              (setq elsec (1- elsec))
+                              (verilog-beg-of-statement) ;; doesn't get to beginning
+                              (if (looking-at (concat "\\(" verilog-label-re "\\)?"
+                                                      "\\(assert\\|assume\\|cover\\)\\s-+property\\>"))
+                                  (throw 'nesting 'statement) ; We don't need an endproperty for these
+                                (throw 'nesting 'block)        ;We still need a endproperty
+                                ))
                              (t ; endblock
                                ; try to leap back to matching outward block by striding across
                                ; indent level changing tokens then immediately
@@ -4345,34 +4460,34 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
                               (let (( reg) (nest 1))
 ;;      verilog-ends =>  else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
                                 (cond
-                                 ((match-end 3) ; end
+                                 ((match-end 4) ; end
                                   ;; Search back for matching begin
                                   (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
-                                 ((match-end 4) ; endcase
+                                 ((match-end 5) ; endcase
                                   ;; Search back for matching case
                                   (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
-                                 ((match-end 5) ; endfunction
+                                 ((match-end 6) ; endfunction
                                   ;; Search back for matching function
                                   (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
-                                 ((match-end 6) ; endtask
+                                 ((match-end 7) ; endtask
                                   ;; Search back for matching task
                                   (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
-                                 ((match-end 7) ; endspecify
+                                 ((match-end 8) ; endspecify
                                   ;; Search back for matching specify
                                   (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
-                                 ((match-end 8) ; endtable
+                                 ((match-end 9) ; endtable
                                   ;; Search back for matching table
                                   (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
-                                 ((match-end 9) ; endgenerate
+                                 ((match-end 10) ; endgenerate
                                   ;; Search back for matching generate
                                   (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
-                                 ((match-end 10) ; joins
+                                 ((match-end 11) ; joins
                                   ;; Search back for matching fork
                                   (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
-                                 ((match-end 11) ; class
+                                 ((match-end 12) ; class
                                   ;; Search back for matching class
                                   (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
-                                 ((match-end 12) ; covergroup
+                                 ((match-end 13) ; covergroup
                                   ;; Search back for matching covergroup
                                   (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
                                 (catch 'skip
@@ -4442,7 +4557,7 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
 
           ((equal (char-after) ?\})
            (let ((there (verilog-at-close-constraint-p)))
-             (if there ;; we are at the } that closes a constraing.  Find the { that opens it
+             (if there ;; we are at the } that closes a constraint.  Find the { that opens it
                  (progn
                    (forward-char 1)
                    (backward-list 1)
@@ -4461,8 +4576,9 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
             ((match-end 4)  ; *sigh* could be "disable fork"
              (let ((here (point)))
                (verilog-beg-of-statement)
-               (if (looking-at verilog-disable-fork-re)
-                   t ; is disable fork, this is a normal statement
+               (if (or (looking-at verilog-disable-fork-re)
+                       (looking-at verilog-fork-wait-re))
+                   t ; this is a normal statement
                  (progn ; or is fork, starts a new block
                    (goto-char here)
                    (throw 'nesting 'block)))))
@@ -4624,6 +4740,9 @@ Jump from end to matching begin, from endcase to matching case, and so on."
      ((looking-at verilog-ovm-end-re)
       ;; 12: Search back for matching sequence
       (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
+     ((looking-at verilog-vmm-end-re)
+      ;; 12: Search back for matching sequence
+      (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
      ((looking-at "\\<endinterface\\>")
       ;; 12: Search back for matching interface
       (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
@@ -4640,7 +4759,13 @@ Jump from end to matching begin, from endcase to matching case, and so on."
                (while (verilog-re-search-backward reg nil 'move)
                  (cond
                   ((match-end 1) ; begin
-                   (setq nest (1- nest))
+                   (if (looking-at "fork")
+                       (let ((here (point)))
+                         (verilog-beg-of-statement)
+                         (unless (looking-at verilog-disable-fork-re)
+                           (goto-char here)
+                           (setq nest (1- nest))))
+                     (setq nest (1- nest)))
                    (if (= 0 nest)
                        ;; Now previous line describes syntax
                        (throw 'skip 1))
@@ -4745,6 +4870,16 @@ Set point to where line starts."
          t)
         ((looking-at verilog-ovm-end-re)
          t)
+     ;; JBA find VMM macros
+     ((looking-at verilog-vmm-statement-re)
+      nil )
+     ((looking-at verilog-vmm-begin-re)
+      t)
+     ((looking-at verilog-vmm-end-re)
+      nil)
+     ;; JBA trying to catch macro lines with no ; at end
+     ((looking-at "\\<`")
+      nil)
         (t
          (goto-char back)
          (cond
@@ -4760,6 +4895,8 @@ Set point to where line starts."
    (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
     t
     (forward-word -1)
+    (while (= (preceding-char) ?\_)
+      (forward-word -1))
     (cond
      ((looking-at "\\<else\\>")
       t)
@@ -4790,31 +4927,13 @@ Set point to where line starts."
          (goto-char back)
          t))))))))
 
-(defun verilog-backward-syntactic-ws (&optional bound)
-  "Backward skip over syntactic whitespace for Emacs 19.
-Optional BOUND limits search."
-  (save-restriction
-    (let* ((bound (or bound (point-min))) (here bound) )
-      (if (< bound (point))
-         (progn
-           (narrow-to-region bound (point))
-           (while (/= here (point))
-             (setq here (point))
-             (verilog-skip-backward-comments))))))
-  t)
+(defun verilog-backward-syntactic-ws ()
+  (verilog-skip-backward-comments)
+  (forward-comment (- (buffer-size))))
 
-(defun verilog-forward-syntactic-ws (&optional bound)
-  "Forward skip over syntactic whitespace for Emacs 19.
-Optional BOUND limits search."
-  (save-restriction
-    (let* ((bound (or bound (point-max)))
-          (here bound))
-      (if (> bound (point))
-         (progn
-           (narrow-to-region (point) bound)
-           (while (/= here (point))
-             (setq here (point))
-             (forward-comment (buffer-size))))))))
+(defun verilog-forward-syntactic-ws ()
+  (verilog-skip-forward-comment-p)
+  (forward-comment (buffer-size)))
 
 (defun verilog-backward-ws&directives (&optional bound)
   "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
@@ -4971,7 +5090,7 @@ Optional BOUND limits search."
   (save-excursion
     (if (and (equal (char-after) ?\{)
              (verilog-backward-token))
-        (looking-at "\\<struct\\|union\\|packed\\>")
+        (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
       nil)))
 
 (defun verilog-parenthesis-depth ()
@@ -5027,14 +5146,11 @@ Optional BOUND limits search."
               (search-backward "/*")
               (skip-chars-backward " \t\n\f")
               t)
-             ((and (not (bobp))
-                   (= (char-before) ?\/)
-                   (= (char-before (1- (point))) ?\*))
-              (goto-char (- (point) 2))
-              t)
-             (t
-              (skip-chars-backward " \t\n\f")
-              nil)))))))
+             ((if (and (not (bobp))
+                       (= (char-before) ?\/)
+                       (= (char-before (1- (point))) ?\*))
+                  (goto-char (- (point) 2))
+                (/= (skip-chars-backward " \t\n\f") 0)))))))))
 
 (defun verilog-skip-forward-comment-p ()
   "If in comment, move to end and return true."
@@ -5042,16 +5158,18 @@ Optional BOUND limits search."
     (progn
       (setq state (save-excursion (verilog-syntax-ppss)))
       (cond
-       ((nth 3 state)
+       ((nth 3 state)                   ;Inside string
        t)
        ((nth 7 state)                  ;Inside // comment
        (end-of-line)
        (forward-char 1)
        t)
        ((nth 4 state)                  ;Inside any comment
+       (search-forward "*/")
+       (skip-chars-forward " \t\n\f")
        t)
        (t
-       nil)))))
+       (skip-chars-forward " \t\n\f"))))))
 
 (defun verilog-indent-line-relative ()
   "Cheap version of indent line.
@@ -5284,117 +5402,153 @@ ARG is ignored, for `comment-indent-function' compatibility."
   "Line up declarations around point.
 Be verbose about progress unless optional QUIET set."
   (interactive)
-  (save-excursion
-    (if (progn
-          (verilog-beg-of-statement-1)
-          (and (not (verilog-in-directive-p)) ;; could have `define input foo
-               (not (verilog-parenthesis-depth)) ;; could be in a #(param block  )
+  (let* ((m1 (make-marker))
+         (e (point))
+        el
+         r
+        (here (point))
+         ind
+         start
+         startpos
+         end
+         endpos
+         base-ind
+         )
+    (save-excursion
+      (if (progn
+;          (verilog-beg-of-statement-1)
+          (beginning-of-line)
+          (verilog-forward-syntactic-ws)          
+          (and (not (verilog-in-directive-p))    ;; could have `define input foo
                (looking-at verilog-declaration-re)))
-        (let* ((m1 (make-marker))
-               (e (point))
-               (r)
-               (here (point))
-               ;; Start of declaration range
-               (start
-                (progn
-                  (verilog-beg-of-statement-1)
-                  (while (and (looking-at verilog-declaration-re)
-                              (not (bobp)))
-                    (skip-chars-backward " \t")
-                    (setq e (point))
-                    (beginning-of-line)
-                    (verilog-backward-syntactic-ws)
-                    (backward-char)
-                    (verilog-beg-of-statement-1))
-                  e))
-               ;; End of declaration range
-               (end
-                (progn
-                  (goto-char here)
-                  (verilog-end-of-statement)
-                  (setq e (point))     ;Might be on last line
-                  (verilog-forward-syntactic-ws)
-                  (while (looking-at verilog-declaration-re)
-                    ;;(beginning-of-line)
-                    (verilog-end-of-statement)
-                    (setq e (point))
-                    (verilog-forward-syntactic-ws))
-                  e))
-               (edpos (set-marker (make-marker) end))
-               (ind)
-               (base-ind
-                (progn
-                  (goto-char start)
-                  (verilog-do-indent (verilog-calculate-indent))
-                  (verilog-forward-ws&directives)
-                  (current-column))))
-          (goto-char start)
-          (if (and (not quiet)
-                   (> (- end start) 100))
-              (message "Lining up declarations..(please stand by)"))
-          ;; Get the beginning of line indent first
-          (while (progn (setq e (marker-position edpos))
-                        (< (point) e))
-            (cond
-             ( (save-excursion (skip-chars-backward " \t")
-                               (bolp))
-               (verilog-forward-ws&directives)
-               (indent-line-to base-ind)
-               (verilog-forward-ws&directives)
-               (verilog-re-search-forward "[ \t\n\f]" e 'move))
-             (t
-              (just-one-space)
-              (verilog-re-search-forward "[ \t\n\f]" e 'move)))
-            ;;(forward-line)
-            )
-          ;; Now find biggest prefix
-          (setq ind (verilog-get-lineup-indent start edpos))
-          ;; Now indent each line.
-          (goto-char start)
-          (while (progn (setq e (marker-position edpos))
-                        (setq r (- e (point)))
-                        (> r 0))
-            (setq e (point))
-            (unless quiet (message "%d" r))
-            (verilog-indent-line)
-            (cond
-             ((or (and verilog-indent-declaration-macros
-                       (looking-at verilog-declaration-re-2-macro))
-                  (looking-at verilog-declaration-re-2-no-macro))
-              (let ((p (match-end 0)))
-                (set-marker m1 p)
-                (if (verilog-re-search-forward "[[#`]" p 'move)
-                    (progn
-                      (forward-char -1)
-                      (just-one-space)
-                      (goto-char (marker-position m1))
-                      (just-one-space)
-                      (indent-to ind))
-                  (progn
-                    (just-one-space)
-                    (indent-to ind)))))
-             ((verilog-continued-line-1 start)
-              (goto-char e)
-              (indent-line-to ind))
-             ((verilog-in-struct-p)
-              ;; could have a declaration of a user defined item
-              (goto-char e)
-              (verilog-end-of-statement))
-             (t                ; Must be comment or white space
-              (goto-char e)
-              (verilog-forward-ws&directives)
-              (forward-line -1)))
-            (forward-line 1))
-          (unless quiet (message ""))))))
+         (progn
+           (if (verilog-parenthesis-depth)  
+               ;; in an argument list or parameter block               
+               (setq el (backward-up-list -1)                
+                     start (progn
+                             (goto-char e)
+                             (backward-up-list 1)
+                             (forward-line) ;; ignore ( input foo,
+                             (verilog-re-search-forward verilog-declaration-re el 'move)
+                             (goto-char (match-beginning 0))
+                             (skip-chars-backward " \t")
+                             (point))
+                     startpos (set-marker (make-marker) start)
+                     end (progn
+                           (goto-char start)
+                           (backward-up-list -1)
+                           (forward-char -1)
+                           (verilog-backward-syntactic-ws)
+                           (point))
+                     endpos (set-marker (make-marker) end)
+                     base-ind (progn
+                                (goto-char start)
+                                (verilog-do-indent (verilog-calculate-indent))
+                                (verilog-forward-ws&directives)
+                                (current-column))
+                     )
+             ;; in a declaration block (not in argument list)
+             (setq 
+              start (progn
+                      (verilog-beg-of-statement-1)
+                      (while (and (looking-at verilog-declaration-re)
+                                  (not (bobp)))
+                        (skip-chars-backward " \t")
+                        (setq e (point))
+                        (beginning-of-line)
+                        (verilog-backward-syntactic-ws)
+                        (backward-char)
+                        (verilog-beg-of-statement-1))
+                      e)
+              startpos (set-marker (make-marker) start)
+              end (progn
+                    (goto-char here)
+                    (verilog-end-of-statement)
+                    (setq e (point))   ;Might be on last line
+                    (verilog-forward-syntactic-ws)
+                    (while (looking-at verilog-declaration-re)
+                      ;;(beginning-of-line)
+                      (verilog-end-of-statement)
+                      (setq e (point))
+                      (verilog-forward-syntactic-ws))
+                    e)
+              endpos (set-marker (make-marker) end)
+              base-ind (progn
+                         (goto-char start)
+                         (verilog-do-indent (verilog-calculate-indent))
+                         (verilog-forward-ws&directives)
+                         (current-column))))
+           ;; OK, start and end are set
+           (goto-char (marker-position startpos))
+           (if (and (not quiet)
+                    (> (- end start) 100))
+               (message "Lining up declarations..(please stand by)"))
+           ;; Get the beginning of line indent first
+           (while (progn (setq e (marker-position endpos))
+                         (< (point) e))
+             (cond
+              ((save-excursion (skip-chars-backward " \t") 
+                               (bolp))
+                (verilog-forward-ws&directives)
+                (indent-line-to base-ind)
+                (verilog-forward-ws&directives)
+                (if (< (point) e)
+                    (verilog-re-search-forward "[ \t\n\f]" e 'move)))
+              (t
+               (just-one-space)
+               (verilog-re-search-forward "[ \t\n\f]" e 'move)))
+             ;;(forward-line)
+             )
+           ;; Now find biggest prefix
+           (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
+           ;; Now indent each line.
+           (goto-char (marker-position startpos))
+           (while (progn (setq e (marker-position endpos))
+                         (setq r (- e (point)))
+                         (> r 0))
+             (setq e (point))
+             (unless quiet (message "%d" r))
+             (verilog-indent-line)
+             (verilog-forward-ws&directives)
+             (cond
+              ((or (and verilog-indent-declaration-macros
+                        (looking-at verilog-declaration-re-2-macro))
+                   (looking-at verilog-declaration-re-2-no-macro))
+               (let ((p (match-end 0)))
+                 (set-marker m1 p)
+                 (if (verilog-re-search-forward "[[#`]" p 'move)
+                     (progn
+                       (forward-char -1)
+                       (just-one-space)
+                       (goto-char (marker-position m1))
+                       (just-one-space)
+                       (indent-to ind))
+                   (progn
+                     (just-one-space)
+                     (indent-to ind)))))
+              ((verilog-continued-line-1 (marker-position startpos))
+               (goto-char e)
+               (indent-line-to ind))
+              ((verilog-in-struct-p)
+               ;; could have a declaration of a user defined item
+               (goto-char e)
+               (verilog-end-of-statement))
+              (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-pretty-expr (&optional quiet myre)
-  "Line up expressions around point, or optional regexp MYRE."
+  "Line up expressions around point, optionally QUIET with regexp MYRE."
   (interactive "sRegular Expression: ((<|:)?=) ")
   (save-excursion
     (if (or (eq myre nil)
            (string-equal myre ""))
        (setq myre "\\(<\\|:\\)?="))
-    (setq myre (concat "\\(^[^;#:<=>]*\\)\\(" myre "\\)"))
+    ;; want to match the first <= |  := | = 
+    (setq myre (concat "\\(^.*?\\)\\(" myre "\\)"))
     (let ((rexp(concat "^\\s-*" verilog-complete-reg)))
       (beginning-of-line)
       (if (and (not (looking-at rexp ))
@@ -5437,7 +5591,7 @@ Be verbose about progress unless optional QUIET set."
                       (beginning-of-line)
                       )
                     e))
-                 (edpos (set-marker (make-marker) end))
+                 (endpos (set-marker (make-marker) end))
                  (ind)
                  )
             (goto-char start)
@@ -5447,7 +5601,7 @@ Be verbose about progress unless optional QUIET set."
                 (message "Lining up expressions..(please stand by)"))
 
             ;; Set indent to minimum throughout region
-            (while (< (point) (marker-position edpos))
+            (while (< (point) (marker-position endpos))
               (beginning-of-line)
               (verilog-just-one-space myre)
               (end-of-line)
@@ -5455,11 +5609,11 @@ Be verbose about progress unless optional QUIET set."
               )
 
             ;; Now find biggest prefix
-            (setq ind (verilog-get-lineup-indent-2 myre start edpos))
+            (setq ind (verilog-get-lineup-indent-2 myre start endpos))
 
             ;; Now indent each line.
             (goto-char start)
-            (while (progn (setq e (marker-position edpos))
+            (while (progn (setq e (marker-position endpos))
                           (setq r (- e (point)))
                           (> r 0))
               (setq e (point))
@@ -5467,7 +5621,7 @@ Be verbose about progress unless optional QUIET set."
               (cond
                ((looking-at myre)
                 (goto-char (match-beginning 2))
-                (if (not (verilog-parenthesis-depth)) ;; ignore parenthsized exprs
+                (if (not (verilog-parenthesis-depth)) ;; ignore parenthesized exprs
                     (if (eq (char-after) ?=)
                         (indent-to (1+ ind))   ; line up the = of the <= with surrounding =
                       (indent-to ind)
@@ -5587,7 +5741,8 @@ Region is defined by B and EDPOS."
        ;; No lineup-string found
        (goto-char b)
        (end-of-line)
-       (skip-chars-backward " \t")
+       (verilog-backward-syntactic-ws)
+       ;;(skip-chars-backward " \t")
        (1+ (current-column))))))
 
 (defun verilog-get-lineup-indent-2 (myre b edpos)
@@ -5599,7 +5754,7 @@ Region is defined by B and EDPOS."
       (while (progn (setq e (marker-position edpos))
                    (< (point) e))
        (if (and (verilog-re-search-forward myre e 'move)
-                (not (verilog-parenthesis-depth))) ;; skip parenthsized exprs
+                (not (verilog-parenthesis-depth))) ;; skip parenthesized exprs
            (progn
              (goto-char (match-beginning 2))
              (verilog-backward-syntactic-ws)
@@ -5655,19 +5810,19 @@ it displays a list of all possible completions.")
   '(
     "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
     "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
-    "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pullup"
+    "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
     "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
     "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
     "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
     )
   "*Keywords for types used when completing a word in a declaration or parmlist.
-\(Eg. integer, real, reg...)")
+\(integer, real, reg...)")
 
 (defvar verilog-cpp-keywords
   '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
     "endif")
   "*Keywords to complete when at first word of a line in declarative scope.
-\(Eg. initial, always, begin, assign.)
+\(initial, always, begin, assign...)
 The procedures and variables defined within the Verilog program
 will be completed at runtime and should not be added to this list.")
 
@@ -5681,7 +5836,7 @@ will be completed at runtime and should not be added to this list.")
      )
    verilog-type-keywords)
   "*Keywords to complete when at first word of a line in declarative scope.
-\(Eg. initial, always, begin, assign.)
+\(initial, always, begin, assign...)
 The procedures and variables defined within the Verilog program
 will be completed at runtime and should not be added to this list.")
 
@@ -5692,28 +5847,28 @@ will be completed at runtime and should not be added to this list.")
     "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
     "while")
   "*Keywords to complete when at first word of a line in behavioral scope.
-\(Eg. begin, if, then, else, for, fork.)
+\(begin, if, then, else, for, fork...)
 The procedures and variables defined within the Verilog program
 will be completed at runtime and should not be added to this list.")
 
 (defvar verilog-tf-keywords
   '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
   "*Keywords to complete when at first word of a line in a task or function.
-\(Eg. begin, if, then, else, for, fork.)
+\(begin, if, then, else, for, fork.)
 The procedures and variables defined within the Verilog program
 will be completed at runtime and should not be added to this list.")
 
 (defvar verilog-case-keywords
   '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
   "*Keywords to complete when at first word of a line in case scope.
-\(Eg. begin, if, then, else, for, fork.)
+\(begin, if, then, else, for, fork...)
 The procedures and variables defined within the Verilog program
 will be completed at runtime and should not be added to this list.")
 
 (defvar verilog-separator-keywords
   '("else" "then" "begin")
   "*Keywords to complete when NOT standing at the first word of a statement.
-\(Eg. else, then.)
+\(else, then, begin...)
 Variables and function names defined within the Verilog program
 will be completed at runtime and should not be added to this list.")
 
@@ -6637,8 +6792,14 @@ Return a array of [outputs inouts inputs wire reg assign const]."
         ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
          (goto-char (match-end 0))
          (setq keywd (match-string 1))
-         (when (string-match "^\\\\" keywd)
+         (when (string-match "^\\\\" (match-string 1))
            (setq keywd (concat keywd " ")))  ;; Escaped ID needs space at end
+         ;; Add any :: package names to same identifier
+         (while (looking-at "\\s-*::\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
+           (goto-char (match-end 0))
+           (setq keywd (concat keywd "::" (match-string 1)))
+           (when (string-match "^\\\\" (match-string 1))
+             (setq keywd (concat keywd " "))))  ;; Escaped ID needs space at end
          (cond ((equal keywd "input")
                 (setq vec nil enum nil  rvalue nil  newsig nil  signed nil  typedefed nil  multidim nil  sig-paren paren
                       expect-signal 'sigs-in  io t  modport nil))
@@ -6876,7 +7037,7 @@ Return the list of signals found, using submodi to look up each port."
                 (verilog-read-sub-decls-expr
                  submoddecls comment port
                  (buffer-substring
-                  (point) (1- (progn (backward-char 1) ; start at (
+                  (point) (1- (progn (search-backward "(") ; start at (
                                      (forward-sexp 1) (point)))))))) ; expr
        ;;
        (forward-line 1)))))
@@ -6927,10 +7088,10 @@ Outputs comments above subcell signals, for example:
                (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
                  (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
                (goto-char st-point)
-               (while (re-search-forward "\\s *// Inouts" end-inst-point t)
+               (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
                  (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
                (goto-char st-point)
-               (while (re-search-forward "\\s *// Inputs" end-inst-point t)
+               (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
                  (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in
                )))))
       ;; Combine duplicate bits
@@ -7730,11 +7891,13 @@ Or, just the existing dirnames themselves if there are no wildcards."
     dirlist))
 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
 
-(defun verilog-library-filenames (filename current &optional check-ext)
+(defun verilog-library-filenames (filename &optional current check-ext)
   "Return a search path to find the given FILENAME or module name.
-Uses the CURRENT filename, `verilog-library-directories' and
-`verilog-library-extensions' variables to build the path.
-With optional CHECK-EXT also check `verilog-library-extensions'."
+Uses the optional CURRENT filename or buffer-file-name, plus
+`verilog-library-directories' and `verilog-library-extensions'
+variables to build the path.  With optional CHECK-EXT also check
+`verilog-library-extensions'."
+  (unless current (setq current (buffer-file-name)))
   (unless verilog-dir-cache-preserving
     (setq verilog-dir-cache-lib-filenames nil))
   (let* ((cache-key (list filename current check-ext))
@@ -7907,7 +8070,7 @@ Cache the output of function so next call may have faster access."
             (nth 3 fass))
            (t
             ;; Read from file
-            ;; Clear then restore any hilighting to make emacs19 happy
+            ;; Clear then restore any highlighting to make emacs19 happy
             (let ((fontlocked (when (and (boundp 'font-lock-mode)
                                          font-lock-mode)
                                 (font-lock-mode 0)
@@ -7987,7 +8150,7 @@ and invalidating the cache."
       (nreverse out-list))))
 
 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
-  "Return all signals in IN-LIST matching the given directional REGEXP,
+  "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
 if non-nil."
   (if (or (not regexp) (equal regexp ""))
       in-list
@@ -8221,6 +8384,13 @@ This repairs those mis-inserted by a AUTOARG."
       (delete-region pt (point))
       (forward-line 1))))
 
+(defun verilog-delete-empty-auto-pair ()
+  "Delete begin/end auto pair at point, if empty."
+  (forward-line 0)
+  (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
+                           "\\s-*// End of automatics\n"))
+    (delete-region (point) (save-excursion (forward-line 2) (point)))))
+
 (defun verilog-forward-close-paren ()
   "Find the close parenthesis that match the current point.
 Ignore other close parenthesis with matching open parens."
@@ -8271,7 +8441,7 @@ Deletion stops at the matching end parenthesis."
   "Return if a .* AUTOINST is safe to delete or expand.
 It was created by the AUTOS themselves, or by the user."
   (and verilog-auto-star-expand
-       (looking-at "[ \t\n\f,]*\\([)]\\|// \\(Outputs\\|Inouts\\|Inputs\\)\\)")))
+       (looking-at "[ \t\n\f,]*\\([)]\\|// \\(Outputs\\|Inouts\\|Inputs\\|Interfaces\\)\\)")))
 
 (defun verilog-delete-auto-star-all ()
   "Delete a .* AUTOINST, if it is safe."
@@ -8303,7 +8473,7 @@ removed."
          (save-excursion
            (while (progn
                     (forward-line -1)
-                    (looking-at "\\s *//\\s *\\(Outputs\\|Inouts\\|Inputs\\)\n"))
+                    (looking-at "\\s *//\\s *\\(Outputs\\|Inouts\\|Inputs\\|Interfaces\\)\n"))
              (delete-region (match-beginning 0) (match-end 0))))
          ;; If it is simple, we can put the ); on the same line as the last text
          (let ((rtn-pt (point)))
@@ -8343,7 +8513,7 @@ called before and after this function, respectively."
                  "AUTOREG" "AUTOREGINPUT" "AUTORESET" "AUTOTIEOFF"
                  "AUTOUNUSED" "AUTOWIRE")))
             ;; Optional parens or quoted parameter or .* for (((...)))
-            "\\(\\|([^)]*)\\|(\"[^\"]*\")\\|.*?\\)"
+            "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
             "\\*/")
      'verilog-delete-autos-lined)
     ;; Remove those that are in parenthesis
@@ -8640,6 +8810,8 @@ Avoid declaring ports manually, as it makes code harder to maintain."
 (defvar vl-name  nil "See `verilog-auto-inst'.") ; Prevent compile warning
 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
 (defvar vl-dir   nil "See `verilog-auto-inst'.") ; Prevent compile warning
+(defvar vl-bits  nil "See `verilog-auto-inst'.") ; Prevent compile warning
+(defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
 
 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
   "Print out a instantiation connection for this PORT-ST.
@@ -8655,6 +8827,8 @@ If PAR-VALUES replace final strings with these parameter values."
         (vl-name (verilog-sig-name port-st))
         (vl-width (verilog-sig-width port-st))
         (vl-modport (verilog-sig-modport port-st))
+        (vl-mbits (if (verilog-sig-multidim port-st) 
+                       (verilog-sig-multidim-string port-st) ""))
         (vl-bits (if (or verilog-auto-inst-vector
                          (not (assoc port vector-skip-list))
                          (not (equal (verilog-sig-bits port-st)
@@ -8739,7 +8913,7 @@ If PAR-VALUES replace final strings with these parameter values."
   "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
   ;; Do we need a trailing comma?
   ;; There maybe a ifdef or something similar before us.  What a mess.  Thus
-  ;; to avoid trouble we only insert on preceeding ) or *.
+  ;; to avoid trouble we only insert on preceding ) or *.
   ;; Insert first port on new line
   (insert "\n")  ;; Must insert before search, so point will move forward if insert comma
   (save-excursion
@@ -8975,7 +9149,7 @@ Regexp Templates:
   inside the first set of \\( \\).  Thus pci_req2_l becomes pci_req_jtag_[2].
 
   Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
-  does the same thing. (Note a @ in the connection/replacement text is
+  does the same thing.  (Note a @ in the connection/replacement text is
   completely different -- still use \\1 there!)  Thus this is the same as
   the above template:
 
@@ -8995,11 +9169,15 @@ Lisp Templates:
   quotes will be evaluated as a Lisp expression, with @ replaced by the
   instantiation number.  The MAPVALIDP1X example above would put @+1 modulo
   4 into the brackets.  Quote all double-quotes inside the expression with
-  a leading backslash (\\\").  There are special variables defined that are
-  useful in these Lisp functions:
+  a leading backslash (\\\"...\\\"); or if the Lisp template is also a
+  regexp template backslash the backslash quote (\\\\\"...\\\\\").
+
+  There are special variables defined that are useful in these
+  Lisp functions:
 
        vl-name        Name portion of the input/output port.
        vl-bits        Bus bits portion of the input/output port ('[2:0]').
+       vl-mbits       Multidimensional array bits for port ('[2:0][3:0]').
        vl-width       Width of the input/output port ('3' for [2:0]).
                        May be a (...) expression if bits isn't a constant.
        vl-dir         Direction of the pin input/output/inout/interface.
@@ -9024,7 +9202,10 @@ Lisp Templates:
   `number-to-string' and `string-to-number'.
 
   After the evaluation is completed, @ substitution and [] substitution
-  occur."
+  occur.
+
+For more information see the \\[verilog-faq] and forums at URL
+`http://www.veripool.org'."
   (save-excursion
     ;; Find beginning
     (let* ((pt (point))
@@ -9917,17 +10098,14 @@ text:
                                       (point))) ;; Beginning paren
           (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
       (forward-line 1)
-      (let ((pre-eval-pt (point)))
-       ;;Debug: (insert cmd)
-       ;; Don't use eval-region as Xemacs has a bug where it goto-char's begin-pt
-       (eval (read cmd))
-       ;; If inserted something add the begin/end blocks
-       (when (not (equal pre-eval-pt (point)))
-         (when (not (bolp)) (insert "\n"))  ;; If user forgot final newline, add it
-         (save-excursion
-           (goto-char pre-eval-pt)
-           (verilog-insert-indent "// Beginning of automatic insert lisp\n"))
-         (verilog-insert-indent "// End of automatics\n"))))))
+      ;; Some commands don't move point (like insert-file) so we always
+      ;; add the begin/end comments, then delete it if not needed
+      (verilog-insert-indent "// Beginning of automatic insert lisp\n")
+      (verilog-insert-indent "// End of automatics\n")
+      (forward-line -1)
+      (eval (read cmd))
+      (forward-line -1)
+      (verilog-delete-empty-auto-pair))))
 
 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
   "Return list of signals for current AUTOSENSE block."
@@ -10047,7 +10225,7 @@ registers set elsewhere in the always block.
 Limitations:
   AUTORESET will not clear memories.
 
-  AUTORESET uses <= if there are any <= assigmnents in the block,
+  AUTORESET uses <= if there are any <= assignments in the block,
   else it uses =.
 
 /*AUTORESET*/ presumes that any signals mentioned between the previous
@@ -11123,7 +11301,7 @@ Files are checked based on `verilog-library-directories'."
   (interactive)
   (let ((reporter-prompt-for-summary-p t))
     (reporter-submit-bug-report
-     "mac@verilog.com"
+     "mac@verilog.com, wsnyder@wsnyder.org"
      (concat "verilog-mode v" verilog-mode-version)
      '(
        verilog-align-ifelse
@@ -11165,23 +11343,22 @@ Files are checked based on `verilog-library-directories'."
      nil nil
      (concat "Hi Mac,
 
-I want to report a bug.  I've read the `Bugs' section of `Info' on
-Emacs, so I know how to make a clear and unambiguous report.  To get
-to that Info section, I typed
-
-M-x info RET m " invocation-name " RET m bugs RET
+I want to report a bug.
 
 Before I go further, I want to say that Verilog mode has changed my life.
 I save so much time, my files are colored nicely, my co workers respect
 my coding ability... until now.  I'd really appreciate anything you
 could do to help me out with this minor deficiency in the product.
 
-If you have bugs with the AUTO functions, please CC the AUTOAUTHOR Wilson
-Snyder (wsnyder@wsnyder.org) and/or see http://www.veripool.org.
-You may also want to look at the Verilog-Mode FAQ, see
+I've taken a look at the Verilog-Mode FAQ at
 http://www.veripool.org/verilog-mode-faq.html.
 
-To reproduce the bug, start a fresh Emacs via " invocation-name "
+And, I've considered filing the bug on the issue tracker at
+http://www.veripool.org/verilog-mode-bugs
+since I realize that public bugs are easier for you to track,
+and for others to search, but would prefer to email.
+
+So, to reproduce the bug, start a fresh Emacs via " invocation-name "
 -no-init-file -no-site-file'.  In a new buffer, in Verilog mode, type
 the code included below.