Merge from emacs-24; up to 2014-05-01T10:21:17Z!rgm@gnu.org
[bpt/emacs.git] / lisp / progmodes / verilog-mode.el
index 5571a90..b07e2ba 100644 (file)
@@ -1,13 +1,12 @@
-;; verilog-mode.el --- major mode for editing verilog source in Emacs
+;;; verilog-mode.el --- major mode for editing verilog source in Emacs
 
-;; Copyright (C) 1996-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
 
-;; Author: Michael McNamara (mac@verilog.com),
-;;    Wilson Snyder (wsnyder@wsnyder.org)
-;; Please see our web sites:
+;; Author: Michael McNamara <mac@verilog.com>
+;;    Wilson Snyder <wsnyder@wsnyder.org>
 ;;    http://www.verilog.com
 ;;    http://www.veripool.org
-;;
+;; Created: 3 Jan 1996
 ;; Keywords: languages
 
 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
 
 ;;; Commentary:
 
-;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs
-
 ;; USAGE
 ;; =====
 
-;; A major mode for editing Verilog HDL source code.  When you have
-;; entered Verilog mode, you may get more info by pressing C-h m. You
-;; may also get online help describing various functions by: C-h f
-;; <Name of function you want described>
+;; A major mode for editing Verilog and SystemVerilog HDL source code (IEEE
+;; 1364-2005 and IEEE 1800-2012 standards).  When you have entered Verilog
+;; mode, you may get more info by pressing C-h m. You may also get online
+;; help describing various functions by: C-h f <Name of function you want
+;; described>
 
 ;; KNOWN BUGS / BUG REPORTS
 ;; =======================
 
-;; Verilog is a rapidly evolving language, and hence this mode is
-;; under continuous development.  Hence this is beta code, and likely
-;; has bugs.  Please report any issues to the issue tracker at
-;; http://www.veripool.org/verilog-mode
+;; SystemVerilog is a rapidly evolving language, and hence this mode is
+;; under continuous development.  Please report any issues to the issue
+;; tracker at
+;;
+;;    http://www.veripool.org/verilog-mode
+;;
 ;; Please use verilog-submit-bug-report to submit a report; type C-c
-;; C-b to invoke this and as a result I will have a much easier time
+;; C-b to invoke this and as a result we will have a much easier time
 ;; of reproducing the bug you find, and hence fixing it.
 
 ;; INSTALLING THE MODE
 ;       verilog-indent-begin-after-if    t
 ;       verilog-auto-lineup              'declarations
 ;       verilog-highlight-p1800-keywords nil
-;      verilog-linter                   "my_lint_shell_command"
-;      )
+;       verilog-linter                  "my_lint_shell_command"
+;       )
 
 ;; \f
 
 ;;; Code:
 
 ;; This variable will always hold the version number of the mode
-(defconst verilog-mode-version (substring "$$Revision: 820 $$" 12 -3)
+(defconst verilog-mode-version "2014-03-15-702457d-vpo"
   "Version of this Verilog mode.")
-(defconst verilog-mode-release-date (substring "$$Date: 2012-09-17 20:43:10 -0400 (Mon, 17 Sep 2012) $$" 8 -3)
-  "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.")
 
     (condition-case nil
         (if (fboundp 'store-match-data)
             nil ;; fab
-          (defmacro store-match-data (&rest args) nil))
+          (defmacro store-match-data (&rest _args) nil))
       (error nil))
     (condition-case nil
         (if (fboundp 'char-before)
             nil ;; great
-          (defmacro char-before (&rest body)
+          (defmacro char-before (&rest _body)
             (char-after (1- (point)))))
       (error nil))
     (condition-case nil
@@ -212,23 +210,23 @@ STRING should be given if the last search was by `string-match' on STRING."
     (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
         nil ;; We've got what we needed
       ;; We have the old custom-library, hack around it!
-      (defmacro defgroup (&rest args)  nil)
-      (defmacro customize (&rest args)
+      (defmacro defgroup (&rest _args)  nil)
+      (defmacro customize (&rest _args)
         (message
         "Sorry, Customize is not available with this version of Emacs"))
-      (defmacro defcustom (var value doc &rest args)
+      (defmacro defcustom (var value doc &rest _args)
         `(defvar ,var ,value ,doc))
       )
     (if (fboundp 'defface)
         nil                            ; great!
-      (defmacro defface (var values doc &rest args)
+      (defmacro defface (var values doc &rest _args)
         `(make-face ,var))
       )
 
     (if (and (featurep 'custom) (fboundp 'customize-group))
         nil ;; We've got what we needed
       ;; We have an intermediate custom-library, hack around it!
-      (defmacro customize-group (var &rest args)
+      (defmacro customize-group (var &rest _args)
         `(customize ,var))
       )
 
@@ -261,23 +259,23 @@ STRING should be given if the last search was by `string-match' on STRING."
                                        ;with just a two input regexp
                       (defun verilog-regexp-opt (a b)
                         "Deal with differing number of required arguments for  `regexp-opt'.
-         Call 'regexp-opt' on A and B."
-                        (regexp-opt a b 't))
+         Call `regexp-opt' on A and B."
+                        (regexp-opt a b t))
                     (error nil))
                   )
                  ((eq args 2) ;; It takes 2
                   (defun verilog-regexp-opt (a b)
-                    "Call 'regexp-opt' on A and B."
+                    "Call `regexp-opt' on A and B."
                     (regexp-opt a b))
                   )
                  (t nil)))
             ;; We can't tell; assume it takes 2
             (defun verilog-regexp-opt (a b)
-              "Call 'regexp-opt' on A and B."
+              "Call `regexp-opt' on A and B."
               (regexp-opt a b))
             )
         ;; There is no regexp-opt, provide our own
-        (defun verilog-regexp-opt (strings &optional paren shy)
+        (defun verilog-regexp-opt (strings &optional paren _shy)
           (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
             (concat open (mapconcat 'regexp-quote strings "\\|") close)))
         )
@@ -501,14 +499,14 @@ entry \"Fontify Buffer\").  XEmacs: turn off and on font locking."
   "Type of statements to lineup across multiple lines.
 If 'all' is selected, then all line ups described below are done.
 
-If 'declaration', then just declarations are lined up with any
+If 'declarations', then just declarations are lined up with any
 preceding declarations, taking into account widths and the like,
 so or example the code:
-       reg [31:0] a;
-       reg b;
+       reg [31:0] a;
+       reg b;
 would become
-       reg [31:0] a;
-       reg        b;
+       reg [31:0] a;
+       reg        b;
 
 If 'assignment', then assignments are lined up with any preceding
 assignments, so for example the code
@@ -663,7 +661,7 @@ to see the effect as font color choices are cached by Emacs."
 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
 
 (defcustom verilog-highlight-grouping-keywords nil
-  "Non-nil means highlight grouping keywords 'begin' and 'end' more dramatically.
+  "Non-nil means highlight grouping keywords more dramatically.
 If false, these words are in the `font-lock-type-face'; if True then they are in
 `verilog-font-lock-ams-face'.  Some find that special highlighting on these
 grouping constructs allow the structure of the code to be understood at a glance."
@@ -960,11 +958,11 @@ See also `verilog-library-flags', `verilog-library-directories'."
 (put 'verilog-library-extensions 'safe-local-variable 'listp)
 
 (defcustom verilog-active-low-regexp nil
-  "If set, treat signals matching this regexp as active low.
+  "If true, treat signals matching this regexp as active low.
 This is used for AUTORESET and AUTOTIEOFF.  For proper behavior,
 you will probably also need `verilog-auto-reset-widths' set."
   :group 'verilog-mode-auto
-  :type 'string)
+  :type '(choice (const nil) regexp))
 (put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
 
 (defcustom verilog-auto-sense-include-inputs nil
@@ -1003,7 +1001,7 @@ those temporaries reset.  See example in `verilog-auto-reset'."
   "True means AUTORESET should determine the width of signals.
 This is then used to set the width of the zero (32'h0 for example).  This
 is required by some lint tools that aren't smart enough to ignore widths of
-the constant zero. This may result in ugly code when parameters determine
+the constant zero.  This may result in ugly code when parameters determine
 the MSB or LSB of a signal inside an AUTORESET.
 
 If nil, AUTORESET uses \"0\" as the constant.
@@ -1062,7 +1060,7 @@ inputs.  This is then used by an upper module:
 
        module ExampInst;
           InstModule
-            #(PARAM(10))
+            #(.PARAM(10))
            instName
             (/*AUTOINST*/
              .i        (i[PARAM-1:0]));
@@ -1073,7 +1071,7 @@ instead expand to:
 
        module ExampInst;
           InstModule
-            #(PARAM(10))
+            #(.PARAM(10))
            instName
             (/*AUTOINST*/
              .i        (i[9:0]));"
@@ -1129,37 +1127,37 @@ won't merge conflict."
 
 (defcustom verilog-auto-inst-interfaced-ports nil
   "Non-nil means include interfaced ports in AUTOINST expansions."
+  :version "24.3"  ;; rev773, default change rev815
   :group 'verilog-mode-auto
-  :type 'boolean
-  :version "24.3")
+  :type 'boolean)
 (put 'verilog-auto-inst-interfaced-ports 'safe-local-variable 'verilog-booleanp)
 
 (defcustom verilog-auto-input-ignore-regexp nil
-  "If set, when creating AUTOINPUT list, ignore signals matching this regexp.
+  "If non-nil, when creating AUTOINPUT, ignore signals matching this regexp.
 See the \\[verilog-faq] for examples on using this."
   :group 'verilog-mode-auto
-  :type 'string)
+  :type '(choice (const nil) regexp))
 (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
 
 (defcustom verilog-auto-inout-ignore-regexp nil
-  "If set, when creating AUTOINOUT list, ignore signals matching this regexp.
+  "If non-nil, when creating AUTOINOUT, ignore signals matching this regexp.
 See the \\[verilog-faq] for examples on using this."
   :group 'verilog-mode-auto
-  :type 'string)
+  :type '(choice (const nil) regexp))
 (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
 
 (defcustom verilog-auto-output-ignore-regexp nil
-  "If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
+  "If non-nil, when creating AUTOOUTPUT, ignore signals matching this regexp.
 See the \\[verilog-faq] for examples on using this."
   :group 'verilog-mode-auto
-  :type 'string)
+  :type '(choice (const nil) regexp))
 (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
 
 (defcustom verilog-auto-template-warn-unused nil
   "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
 This feature is not supported before Emacs 21.1 or XEmacs 21.4."
+  :version "24.3"  ;;rev787
   :group 'verilog-mode-auto
-  :version "24.3"
   :type 'boolean)
 (put 'verilog-auto-template-warn-unused 'safe-local-variable 'verilog-booleanp)
 
@@ -1173,24 +1171,33 @@ assignment, else the data type for variable creation."
 (put 'verilog-auto-tieoff-declaration 'safe-local-variable 'stringp)
 
 (defcustom verilog-auto-tieoff-ignore-regexp nil
-  "If set, when creating AUTOTIEOFF list, ignore signals matching this regexp.
+  "If non-nil, when creating AUTOTIEOFF, ignore signals matching this regexp.
 See the \\[verilog-faq] for examples on using this."
   :group 'verilog-mode-auto
-  :type 'string)
+  :type '(choice (const nil) regexp))
 (put 'verilog-auto-tieoff-ignore-regexp 'safe-local-variable 'stringp)
 
 (defcustom verilog-auto-unused-ignore-regexp nil
-  "If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
+  "If non-nil, when creating AUTOUNUSED, ignore signals matching this regexp.
 See the \\[verilog-faq] for examples on using this."
   :group 'verilog-mode-auto
-  :type 'string)
+  :type '(choice (const nil) regexp))
 (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
 
+(defcustom verilog-case-fold t
+  "Non-nil means `verilog-mode' regexps should ignore case.
+This variable is t for backward compatibility; nil is suggested."
+  :version "24.4"
+  :group 'verilog-mode
+  :type 'boolean)
+(put 'verilog-case-fold 'safe-local-variable 'verilog-booleanp)
+
 (defcustom verilog-typedef-regexp nil
   "If non-nil, regular expression that matches Verilog-2001 typedef names.
-For example, \"_t$\" matches typedefs named with _t, as in the C language."
+For example, \"_t$\" matches typedefs named with _t, as in the C language.
+See also `verilog-case-fold'."
   :group 'verilog-mode-auto
-  :type 'string)
+  :type '(choice (const nil) regexp))
 (put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
 
 (defcustom verilog-mode-hook   'verilog-set-compile-command
@@ -1230,14 +1237,14 @@ For example, \"_t$\" matches typedefs named with _t, as in the C language."
 
 (defcustom verilog-before-save-font-hook nil
   "Hook run before `verilog-save-font-mods' removes highlighting."
+  :version "24.3"  ;;rev735
   :group 'verilog-mode-auto
-  :version "24.3"
   :type 'hook)
 
 (defcustom verilog-after-save-font-hook nil
   "Hook run after `verilog-save-font-mods' restores highlighting."
+  :version "24.3"  ;;rev735
   :group 'verilog-mode-auto
-  :version "24.3"
   :type 'hook)
 
 (defvar verilog-imenu-generic-expression
@@ -1437,6 +1444,8 @@ If set will become buffer local.")
        :help           "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
       ["AUTOASSIGNMODPORT"             (describe-function 'verilog-auto-assign-modport)
        :help           "Help on AUTOASSIGNMODPORT - creating assignments to/from modports"]
+      ["AUTOINOUT"                     (describe-function 'verilog-auto-inout)
+       :help           "Help on AUTOINOUT - adding inouts from cells"]
       ["AUTOINOUTCOMP"                 (describe-function 'verilog-auto-inout-comp)
        :help           "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
       ["AUTOINOUTIN"                   (describe-function 'verilog-auto-inout-in)
@@ -1447,12 +1456,10 @@ If set will become buffer local.")
        :help           "Help on AUTOINOUTMODULE - copying i/o from another file"]
       ["AUTOINOUTPARAM"                        (describe-function 'verilog-auto-inout-param)
        :help           "Help on AUTOINOUTPARAM - copying parameters from another file"]
-      ["AUTOINSERTLISP"                        (describe-function 'verilog-auto-insert-lisp)
-       :help           "Help on AUTOINSERTLISP - insert text from a lisp function"]
-      ["AUTOINOUT"                     (describe-function 'verilog-auto-inout)
-       :help           "Help on AUTOINOUT - adding inouts from cells"]
       ["AUTOINPUT"                     (describe-function 'verilog-auto-input)
        :help           "Help on AUTOINPUT - adding inputs from cells"]
+      ["AUTOINSERTLISP"                        (describe-function 'verilog-auto-insert-lisp)
+       :help           "Help on AUTOINSERTLISP - insert text from a lisp function"]
       ["AUTOINST"                      (describe-function 'verilog-auto-inst)
        :help           "Help on AUTOINST - adding pins for cells"]
       ["AUTOINST (.*)"                 (describe-function 'verilog-auto-star)
@@ -1471,7 +1478,7 @@ If set will become buffer local.")
        :help           "Help on AUTOREGINPUT - declaring inputs for non-wires"]
       ["AUTORESET"                     (describe-function 'verilog-auto-reset)
        :help           "Help on AUTORESET - resetting always blocks"]
-      ["AUTOSENSE"                     (describe-function 'verilog-auto-sense)
+      ["AUTOSENSE or AS"               (describe-function 'verilog-auto-sense)
        :help           "Help on AUTOSENSE - sensitivity lists for always blocks"]
       ["AUTOTIEOFF"                    (describe-function 'verilog-auto-tieoff)
        :help           "Help on AUTOTIEOFF - tying off unused outputs"]
@@ -1505,8 +1512,10 @@ If set will become buffer local.")
       :help            "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
      ["OVM Class"      verilog-sk-ovm-class
       :help            "Insert an OVM class block"]
-     ["UVM Class"      verilog-sk-uvm-class
-      :help            "Insert an UVM class block"]
+     ["UVM Object"     verilog-sk-uvm-object
+      :help            "Insert an UVM object block"]
+     ["UVM Component"  verilog-sk-uvm-component
+      :help            "Insert an UVM component block"]
      ["Primitive"      verilog-sk-primitive
       :help            "Insert a primitive .. (.. );.. endprimitive block"]
      "----"
@@ -1594,6 +1603,14 @@ If set will become buffer local.")
 (defsubst verilog-within-string ()
   (nth 3 (parse-partial-sexp (point-at-bol) (point))))
 
+(defsubst verilog-string-match-fold (regexp string &optional start)
+  "Like `string-match', but use `verilog-case-fold'.
+Return index of start of first match for REGEXP in STRING, or nil.
+Matching ignores case if `verilog-case-fold' is non-nil.
+If third arg START is non-nil, start search at that index in STRING."
+  (let ((case-fold-search verilog-case-fold))
+    (string-match regexp string start)))
+
 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
   "Replace occurrences of FROM-STRING with TO-STRING.
 FIXEDCASE and LITERAL as in `replace-match`.  STRING is what to replace.
@@ -1617,7 +1634,7 @@ will break, as the o's continuously replace.  xa -> x works ok though."
     string))
 
 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
-  ; checkdoc-params: (REGEXP BOUND NOERROR)
+  ;; checkdoc-params: (REGEXP BOUND NOERROR)
   "Like `re-search-forward', but skips over match in comments or strings."
   (let ((mdata '(nil nil)))  ;; So match-end will return nil if no matches found
     (while (and
@@ -1633,7 +1650,7 @@ will break, as the o's continuously replace.  xa -> x works ok though."
     (match-end 0)))
 
 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
-  ; checkdoc-params: (REGEXP BOUND NOERROR)
+  ;; checkdoc-params: (REGEXP BOUND NOERROR)
   "Like `re-search-backward', but skips over match in comments or strings."
   (let ((mdata '(nil nil)))  ;; So match-end will return nil if no matches found
     (while (and
@@ -1662,7 +1679,7 @@ so there may be a large up front penalty for the first search."
     pt))
 
 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
-  ; checkdoc-params: (REGEXP BOUND NOERROR)
+  ;; checkdoc-params: (REGEXP BOUND NOERROR)
   "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
 but trashes match data and is faster for REGEXP that doesn't match often.
 This uses `verilog-scan' and text properties to ignore comments,
@@ -1731,6 +1748,7 @@ To call on \\[verilog-auto], set `verilog-auto-delete-trailing-whitespace'."
     (unless (bolp) (insert "\n"))))
 
 (defvar compile-command)
+(defvar create-lockfiles)  ;; Emacs 24
 
 ;; compilation program
 (defun verilog-set-compile-command ()
@@ -2438,7 +2456,7 @@ find the errors."
 ;; verilog-forward-sexp and verilog-calc-indent
 (defconst verilog-beg-block-re-ordered
   ( concat "\\(\\<begin\\>\\)"         ;1
-          "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
+          "\\|\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
           "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
           "\\|\\(\\<class\\>\\)"               ;6
           "\\|\\(\\<table\\>\\)"               ;7
@@ -2570,6 +2588,9 @@ find the errors."
   (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
                                             "function" "task"))))
 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)"  )
+(defconst verilog-in-constraint-re ;; keywords legal in constraint blocks starting a statement/block
+  (eval-when-compile (verilog-regexp-words `("if" "else" "solve" "foreach"))))
+
 (defconst verilog-indent-re
   (eval-when-compile
     (verilog-regexp-words
@@ -2682,7 +2703,7 @@ find the errors."
        "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
        ))))
 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
-(defconst verilog-extended-case-re "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
+(defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
 (defconst verilog-extended-complete-re
   (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
          "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
@@ -2766,8 +2787,10 @@ find the errors."
      "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.")
+     ;; 1800-2012
+     "implements" "interconnect" "nettype" "soft"
+     )
+  "List of Verilog keywords.")
 
 (defconst verilog-comment-start-regexp "//\\|/\\*"
   "Dual comment value for `comment-start-regexp'.")
@@ -2784,7 +2807,9 @@ find the errors."
     (modify-syntax-entry ?> "." table)
     (modify-syntax-entry ?& "." table)
     (modify-syntax-entry ?| "." table)
-    (modify-syntax-entry ?` "w" table)
+    ;; FIXME: This goes against Emacs conventions.  Use "_" syntax instead and
+    ;; then use regexps with things like "\\_<...\\_>".
+    (modify-syntax-entry ?` "w" table) ;; ` is part of definition symbols in Verilog
     (modify-syntax-entry ?_ "w" table)
     (modify-syntax-entry ?\' "." table)
 
@@ -2930,6 +2955,11 @@ See also `verilog-font-lock-extra-types'.")
             "sync_accept_on" "sync_reject_on" "unique0" "until"
             "until_with" "untyped" "weak" ) nil )))
 
+       (verilog-1800-2012-keywords
+       (eval-when-compile
+         (verilog-regexp-opt
+          '("implements" "interconnect" "nettype" "soft" ) nil )))
+
        (verilog-ams-keywords
        (eval-when-compile
          (verilog-regexp-opt
@@ -2993,6 +3023,12 @@ See also `verilog-font-lock-extra-types'.")
                   'verilog-font-lock-p1800-face)
           (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
                 'font-lock-type-face))
+        ;; Fontify IEEE-1800-2012 keywords appropriately
+        (if verilog-highlight-p1800-keywords
+            (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
+                  'verilog-font-lock-p1800-face)
+          (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
+                'font-lock-type-face))
         ;; Fontify Verilog-AMS keywords
         (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
               'verilog-font-lock-ams-face)))
@@ -3111,7 +3147,7 @@ to full text form for parsing.  Additional actions may be specified with
 ;; Comment detection and caching
 
 (defvar verilog-scan-cache-preserving nil
-  "If set, the specified buffer's comment properties are static.
+  "If true, the specified buffer's comment properties are static.
 Buffer changes will be ignored.  See `verilog-inside-comment-or-string-p'
 and `verilog-scan'.")
 
@@ -3254,7 +3290,7 @@ inserted using a single call to `verilog-insert'."
 (defun verilog-point-text (&optional pointnum)
   "Return text describing where POINTNUM or current point is (for errors).
 Use filename, if current buffer being edited shorten to just buffer name."
-  (concat (or (and (equal (window-buffer (selected-window)) (current-buffer))
+  (concat (or (and (equal (window-buffer) (current-buffer))
                   (buffer-name))
              buffer-file-name
              (buffer-name))
@@ -3297,9 +3333,9 @@ Use filename, if current buffer being edited shorten to just buffer name."
                  (verilog-re-search-backward reg nil 'move))
        (cond
         ((match-end 1) ; matched verilog-end-block-re
-       ; try to leap back to matching outward block by striding across
-       ; indent level changing tokens then immediately
-       ; previous line governs indentation.
+         ;; try to leap back to matching outward block by striding across
+         ;; indent level changing tokens then immediately
+         ;; previous line governs indentation.
          (verilog-leap-to-head))
         ((match-end 2) ; else, we're in deep
          (setq elsec (1+ elsec)))
@@ -3348,7 +3384,7 @@ Use filename, if current buffer being edited shorten to just buffer name."
        (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
        ((match-end 2)
        ;; Search forward for matching endcase
-       (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
+       (setq reg "\\(\\<randcase\\>\\|\\(\\<unique0?\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
        (setq md 3) ;; ender is third item in regexp
        )
        ((match-end 4)
@@ -3588,7 +3624,8 @@ Some other functions are:
     \\[verilog-sk-fork]  Insert a fork begin .. end .. join block.
     \\[verilog-sk-module]  Insert a module .. (/*AUTOARG*/);.. endmodule block.
     \\[verilog-sk-ovm-class]  Insert an OVM Class block.
-    \\[verilog-sk-uvm-class]  Insert an UVM Class block.
+    \\[verilog-sk-uvm-object]  Insert an UVM Object block.
+    \\[verilog-sk-uvm-component]  Insert an UVM Component block.
     \\[verilog-sk-primitive]  Insert a primitive .. (.. );.. endprimitive block.
     \\[verilog-sk-repeat]  Insert a repeat (..) begin .. end block.
     \\[verilog-sk-specify]  Insert a specify .. endspecify block.
@@ -3621,7 +3658,7 @@ Key bindings specific to `verilog-mode-map' are:
   (set-syntax-table verilog-mode-syntax-table)
   (set (make-local-variable 'indent-line-function)
        #'verilog-indent-line-relative)
-  (setq comment-indent-function 'verilog-comment-indent)
+  (set (make-local-variable 'comment-indent-function) 'verilog-comment-indent)
   (set (make-local-variable 'parse-sexp-ignore-comments) nil)
   (set (make-local-variable 'comment-start) "// ")
   (set (make-local-variable 'comment-end) "")
@@ -3956,7 +3993,7 @@ This puts the mark at the end, and point at the beginning."
     (mark-defun)))
 
 (defun verilog-comment-region (start end)
-  ; checkdoc-params: (start end)
+  ;; checkdoc-params: (start end)
   "Put the region into a Verilog comment.
 The comments that are in this area are \"deformed\":
 `*)' becomes `!(*' and `}' becomes `!{'.
@@ -4045,14 +4082,7 @@ Uses `verilog-scan' cache."
   (interactive)
   (verilog-re-search-forward verilog-end-defun-re nil 'move))
 
-(defun verilog-get-beg-of-defun (&optional warn)
-  (save-excursion
-    (cond ((verilog-re-search-forward-quick verilog-defun-re nil t)
-          (point))
-         (t
-          (error "%s: Can't find module beginning" (verilog-point-text))
-          (point-max)))))
-(defun verilog-get-end-of-defun (&optional warn)
+(defun verilog-get-end-of-defun ()
   (save-excursion
     (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
           (point))
@@ -4060,9 +4090,8 @@ Uses `verilog-scan' cache."
           (error "%s: Can't find endmodule" (verilog-point-text))
           (point-max)))))
 
-(defun verilog-label-be (&optional arg)
-  "Label matching begin ... end, fork ... join and case ... endcase statements.
-With ARG, first kill any existing labels."
+(defun verilog-label-be ()
+  "Label matching begin ... end, fork ... join and case ... endcase statements."
   (interactive)
   (let ((cnt 0)
        (oldpos (point))
@@ -4195,7 +4224,7 @@ With ARG, first kill any existing labels."
      ((equal (char-after) ?\})
       (forward-char))
 
-      ;; Skip to end of statement
+     ;; Skip to end of statement
      ((condition-case nil
        (setq pos
              (catch 'found
@@ -4257,7 +4286,7 @@ More specifically, point @ in the line foo : @ begin"
                (setq nest (1+ nest)))
               ((match-end 2)
                (if (= nest 1)
-               (throw 'found 1))
+                   (throw 'found 1))
                (setq nest (1- nest)))
               (t
                (throw 'found (= nest 0)))))))
@@ -4402,6 +4431,7 @@ Limit search to point LIM."
          "\\(`ifdef\\>\\)\\|"
          "\\(`ifndef\\>\\)\\|"
          "\\(`elsif\\>\\)"))
+
 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
   "Add ending comment with given INDENT-STR.
 With KILL-EXISTING-COMMENT, remove what was there before.
@@ -4488,7 +4518,7 @@ primitive or interface named NAME."
                     ((looking-at "\\<randcase\\>")
                      (setq str "randcase")
                      (setq err nil))
-                    ((looking-at "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
+                    ((looking-at "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
                      (goto-char (match-end 0))
                      (setq str (concat (match-string 0) " " (verilog-get-expr)))
                      (setq err nil))
@@ -5050,13 +5080,13 @@ FILENAME to find directory to run in, or defaults to `buffer-file-name`."
    (list
     (let ((default (verilog-expand-command verilog-preprocessor)))
       (set (make-local-variable `verilog-preprocessor)
-             (read-from-minibuffer "Run Preprocessor (like this): "
-                                    default nil nil
-                                     'verilog-preprocess-history default)))))
+          (read-from-minibuffer "Run Preprocessor (like this): "
+                                default nil nil
+                                'verilog-preprocess-history default)))))
   (unless command (setq command (verilog-expand-command verilog-preprocessor)))
   (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
-         (dir (file-name-directory (or filename buffer-file-name)))
-          (cmd (concat "cd " dir "; " command)))
+        (dir (file-name-directory (or filename buffer-file-name)))
+        (cmd (concat "cd " dir "; " command)))
     (with-output-to-temp-buffer "*Verilog-Preprocessed*"
       (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
        (insert (concat "// " cmd "\n"))
@@ -5106,6 +5136,7 @@ Save the result unless optional NO-SAVE is t."
    (setq-default make-backup-files nil)
    (setq enable-local-variables t)
    (setq enable-local-eval t)
+   (setq create-lockfiles nil)
    ;; Make sure any sub-files we read get proper mode
    (setq-default major-mode 'verilog-mode)
    ;; Ditto files already read in
@@ -5226,6 +5257,7 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
           (par 0)
           (begin (looking-at "[ \t]*begin\\>"))
           (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
+           (structres nil)
           (type (catch 'nesting
                   ;; Keep working backwards until we can figure out
                   ;; what type of statement this is.
@@ -5241,11 +5273,15 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
                   (if (save-excursion (beginning-of-line)
                                       (and (looking-at verilog-directive-re-1)
                                            (not (or (looking-at "[ \t]*`[ou]vm_")
-                                 (looking-at "[ \t]*`vmm_")))))
+                                                    (looking-at "[ \t]*`vmm_")))))
                       (throw 'nesting 'directive))
            ;; indent structs as if there were module level
-           (if (verilog-in-struct-p)
-               (throw 'nesting 'block))
+           (setq structres (verilog-in-struct-nested-p))
+           (cond ((not structres) nil)
+                 ;;((and structres (equal (char-after) ?\})) (throw 'nesting 'struct-close))
+                 ((> structres 0) (throw 'nesting 'nested-struct))
+                 ((= structres 0) (throw 'nesting 'block))
+                 (t nil))
 
           ;; if we are in a parenthesized list, and the user likes to indent these, return.
           ;; unless we are in the newfangled coverpoint or constraint blocks
@@ -5262,7 +5298,9 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
             ;; trap out if we crawl off the top of the buffer
             (if (bobp) (throw 'nesting 'cpp))
 
-            (if (verilog-continued-line-1 lim)
+            (if (and (verilog-continued-line-1 lim)
+                      (or (not (verilog-in-coverage-p))
+                          (looking-at verilog-in-constraint-re) ))  ;; may still get hosed if concat in constraint
                 (let ((sp (point)))
                   (if (and
                        (not (looking-at verilog-complete-reg))
@@ -5271,10 +5309,15 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
                              (throw 'nesting 'cexp))
 
                     (goto-char sp))
-
+                   (if (and (verilog-in-coverage-p)
+                            (looking-at verilog-in-constraint-re))
+                       (progn
+                        (beginning-of-line)
+                        (skip-chars-forward " \t")
+                        (throw 'nesting 'constraint)))
                   (if (and begin
-                           (not verilog-indent-begin-after-if)
-                           (looking-at verilog-no-indent-begin-re))
+                            (not verilog-indent-begin-after-if)
+                            (looking-at verilog-no-indent-begin-re))
                       (progn
                         (beginning-of-line)
                         (skip-chars-forward " \t")
@@ -5371,6 +5414,10 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
           (list type (current-column)))
          ((eq type 'defun)
           (list type 0))
+         ((eq type 'constraint)
+          (list 'block (current-column)))
+         ((eq type 'nested-struct)
+          (list 'block structres))
          (t
           (list type (verilog-current-indent-level))))))))
 
@@ -5399,23 +5446,32 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
          (t
           (setq depth (verilog-current-indent-level)))))
       (message "You are at nesting %s depth %d" type depth))))
+
 (defun verilog-calc-1 ()
   (catch 'nesting
-    (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)")))
+    (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)"))
+          (inconstraint (verilog-in-coverage-p)))
       (while (verilog-re-search-backward re nil 'move)
        (catch 'continue
          (cond
           ((equal (char-after) ?\{)
+            ;; block type returned based on outer constraint { or inner
            (if (verilog-at-constraint-p)
-               (throw 'nesting 'block)))
-
+                (cond (inconstraint (throw 'nesting 'constraint))
+                      (t            (throw 'nesting 'statement)))))
           ((equal (char-after) ?\})
-           (let ((there (verilog-at-close-constraint-p)))
+           (let (par-pos
+                  (there (verilog-at-close-constraint-p)))
              (if there ;; we are at the } that closes a constraint.  Find the { that opens it
                  (progn
-                   (forward-char 1)
-                   (backward-list 1)
-                   (verilog-beg-of-statement)))))
+                   (if (> (verilog-in-paren-count) 0)
+                        (forward-char 1))
+                    (setq par-pos (verilog-parenthesis-depth))
+                    (cond (par-pos
+                          (goto-char par-pos)
+                          (forward-char 1))
+                         (t
+                          (backward-char 1)))))))
 
           ((looking-at verilog-beg-block-re-ordered)
            (cond
@@ -5456,10 +5512,10 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
                                        ; endfunction
              (verilog-beg-of-statement)
              (if (looking-at verilog-beg-block-re-ordered)
-              (throw 'nesting 'block)
-            (throw 'nesting 'defun)))
+                 (throw 'nesting 'block)
+               (throw 'nesting 'defun)))
 
-         ;;
+            ;;
             ((looking-at "\\<property\\>")
                                        ; *sigh*
                                        ;    {assert|assume|cover} property (); are complete
@@ -5533,7 +5589,7 @@ of the appropriate enclosing block."
     (while (/= 0 nest)
       (verilog-re-search-backward
        (concat
-       "\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
+       "\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
        "\\|\\(\\<endcase\\>\\)" )
        nil 'move)
       (cond
@@ -5650,7 +5706,7 @@ Jump from end to matching begin, from endcase to matching case, and so on."
                    (setq sreg reg)
                    (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
                   )))
-           ;no nesting
+           ;no nesting
            (if (and
                 (verilog-re-search-backward reg nil 'move)
                 (match-end 1)) ; task -> could be virtual and/or protected
@@ -5949,6 +6005,14 @@ May cache result using `verilog-syntax-ppss'."
  (let ((state (save-excursion (verilog-syntax-ppss))))
    (> (nth 0 state) 0 )))
 
+(defun verilog-in-paren-count ()
+ "Return paren depth, floor to 0.
+May cache result using `verilog-syntax-ppss'."
+ (let ((state (save-excursion (verilog-syntax-ppss))))
+   (if (> (nth 0 state) 0)
+       (nth 0 state)
+     0 )))
+
 (defun verilog-in-paren-quick ()
  "Return true if in a parenthetical expression.
 Always starts from `point-min', to allow inserts with hooks disabled."
@@ -5968,6 +6032,21 @@ Always starts from `point-min', to allow inserts with hooks disabled."
         )
      nil)))
 
+(defun verilog-in-struct-nested-p ()
+ "Return nil for not in struct.
+Return 0 for in non-nested struct.
+Return >0 for nested struct."
+ (interactive)
+ (let (col)
+   (save-excursion
+     (if (verilog-in-paren)
+         (progn
+           (verilog-backward-up-list 1)
+           (setq col (verilog-at-struct-mv-p))
+           (if col
+               (if (verilog-in-struct-p) (current-column) 0)))
+       nil))))
+
 (defun verilog-in-coverage-p ()
  "Return true if in a constraint or coverpoint expression."
  (interactive)
@@ -5982,11 +6061,13 @@ Always starts from `point-min', to allow inserts with hooks disabled."
   "If at the } that closes a constraint or covergroup, return true."
   (if (and
        (equal (char-after) ?\})
-       (verilog-in-paren))
+       (verilog-in-coverage-p))
 
       (save-excursion
        (verilog-backward-ws&directives)
-       (if (equal (char-before) ?\;)
+       (if (or (equal (char-before) ?\;)
+                (equal (char-before) ?\}) ;; can end with inner constraint { } block or ;
+                (equal (char-before) ?\{)) ;; empty constraint block
            (point)
          nil))))
 
@@ -5998,20 +6079,64 @@ Always starts from `point-min', to allow inserts with hooks disabled."
         (forward-list)
         (progn (backward-char 1)
                (verilog-backward-ws&directives)
-               (equal (char-before) ?\;))))
-      ;; maybe
-      (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move)
+               (or (equal (char-before) ?\{) ;; empty case
+                    (equal (char-before) ?\;)
+                    (equal (char-before) ?\})))))
+      (progn
+        (let ( (pt (point)) (pass 0))
+          (verilog-backward-ws&directives)
+          (verilog-backward-token)
+          (if (looking-at (concat "\\<constraint\\|coverpoint\\|cross\\|with\\>\\|" verilog-in-constraint-re))
+              (progn (setq pass 1)
+                     (if (looking-at "\\<with\\>")
+                         (progn (verilog-backward-ws&directives)
+                                (beginning-of-line) ;; 1
+                                (verilog-forward-ws&directives)
+                                1 )
+                       (verilog-beg-of-statement)
+                       ))
+            ;; if first word token not keyword, it maybe the instance name
+            ;;   check next word token
+            (if (looking-at "\\<\\w+\\>\\|\\s-*(\\s-*\\w+")
+                (progn (verilog-beg-of-statement)
+                       (if (looking-at (concat "\\<\\(constraint\\|"
+                                               "\\(?:\\w+\\s-*:\\s-*\\)?\\(coverpoint\\|cross\\)"
+                                               "\\|with\\)\\>\\|" verilog-in-constraint-re))
+                           (setq pass 1)))))
+          (if (eq pass 0)
+              (progn (goto-char pt) nil) 1)))
     ;; not
     nil))
 
 (defun verilog-at-struct-p ()
-  "If at the { of a struct, return true, moving point to struct."
+  "If at the { of a struct, return true, not moving point."
   (save-excursion
     (if (and (equal (char-after) ?\{)
              (verilog-backward-token))
         (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
       nil)))
 
+(defun verilog-at-struct-mv-p ()
+  "If at the { of a struct, return true, moving point to struct."
+  (let ((pt (point)))
+    (if (and (equal (char-after) ?\{)
+             (verilog-backward-token))
+        (if (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
+            (progn (verilog-beg-of-statement) (point))
+          (progn (goto-char pt) nil))
+      (progn (goto-char pt) nil))))
+
+(defun verilog-at-close-struct-p ()
+  "If at the } that closes a struct, return true."
+  (if (and
+       (equal (char-after) ?\})
+       (verilog-in-struct-p))
+      ;; true
+      (save-excursion
+       (if (looking-at "}\\(?:\\s-*\\w+\\s-*\\)?;") 1))
+    ;; false
+    nil))
+
 (defun verilog-parenthesis-depth ()
  "Return non zero if in parenthetical-expression."
  (save-excursion (nth 1 (verilog-syntax-ppss))))
@@ -6245,8 +6370,9 @@ Only look at a few lines to determine indent level."
 
      (;-- Handle the ends
       (or
-       (looking-at verilog-end-block-re )
-       (verilog-at-close-constraint-p))
+       (looking-at verilog-end-block-re)
+       (verilog-at-close-constraint-p)
+       (verilog-at-close-struct-p))
       (let ((val (if (eq type 'statement)
                     (- ind verilog-indent-level)
                   ind)))
@@ -6355,9 +6481,9 @@ Do not count named blocks or case-statements."
                 (looking-at "\*")))
          (insert "* ")))))
 
-(defun verilog-comment-indent (&optional arg)
+(defun verilog-comment-indent (&optional _arg)
   "Return the column number the line should be indented to.
-ARG is ignored, for `comment-indent-function' compatibility."
+_ARG is ignored, for `comment-indent-function' compatibility."
   (cond
    ((verilog-in-star-comment-p)
     (save-excursion
@@ -6423,10 +6549,9 @@ Be verbose about progress unless optional QUIET set."
                      endpos (set-marker (make-marker) end)
                      base-ind (progn
                                 (goto-char start)
-                 (forward-char 1)
-                 (skip-chars-forward " \t")
-                 (current-column))
-                     )
+                                (forward-char 1)
+                                (skip-chars-forward " \t")
+                                (current-column)))
              ;; in a declaration block (not in argument list)
              (setq
               start (progn
@@ -6519,8 +6644,8 @@ Be verbose about progress unless optional QUIET set."
              (forward-line 1))
            (unless quiet (message "")))))))
 
-(defun verilog-pretty-expr (&optional quiet myre)
-  "Line up expressions around point, optionally QUIET with regexp MYRE ignored."
+(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
@@ -6757,8 +6882,7 @@ Region is defined by B and EDPOS."
        ((b (prog2
                (beginning-of-line)
                (point-marker)
-             (end-of-line)))
-        (e (point-marker)))
+             (end-of-line))))
       (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t)
          (progn
            (replace-match " /* -#  ## */")
@@ -6950,24 +7074,6 @@ for matches of `str' and adding the occurrence tp `all' through point END."
       (forward-line 1)))
   verilog-all)
 
-(defun verilog-type-completion ()
-  "Calculate all possible completions for types."
-  (let ((start (point))
-       goon)
-    ;; Search for all reachable type declarations
-    (while (or (verilog-beg-of-defun)
-              (setq goon (not goon)))
-      (save-excursion
-       (if (and (< start (prog1 (save-excursion (verilog-end-of-defun)
-                                                (point))
-                           (forward-char 1)))
-                (verilog-re-search-forward
-                 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
-                 start t)
-                (not (match-end 1)))
-           ;; Check current type declaration
-           (verilog-get-completion-decl start))))))
-
 (defun verilog-var-completion ()
   "Calculate all possible completions for variables (or constants)."
   (let ((start (point)))
@@ -7051,6 +7157,7 @@ exact match, nil otherwise."
             ;; Return nil if there was no matching label
             nil
           ;; Get longest string common in the labels
+           ;; FIXME: Why not use `try-completion'?
           (let* ((elm (cdr verilog-all))
                  (match (car verilog-all))
                  (min (length match))
@@ -7087,6 +7194,7 @@ exact match, nil otherwise."
   "Complete word at current point.
 \(See also `verilog-toggle-completions', `verilog-type-keywords',
 and `verilog-separator-keywords'.)"
+  ;; FIXME: Provide completion-at-point-function.
   (interactive)
   (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
         (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
@@ -7464,11 +7572,11 @@ See also `verilog-sk-header' for an alternative format."
   (list name bits comment mem enum signed type multidim modport))
 (defsubst verilog-sig-name (sig)
   (car sig))
-(defsubst verilog-sig-bits (sig)
+(defsubst verilog-sig-bits (sig) ;; First element of packed array (pre signal-name)
   (nth 1 sig))
 (defsubst verilog-sig-comment (sig)
   (nth 2 sig))
-(defsubst verilog-sig-memory (sig)
+(defsubst verilog-sig-memory (sig) ;; Unpacked array (post signal-name)
   (nth 3 sig))
 (defsubst verilog-sig-enum (sig)
   (nth 4 sig))
@@ -7478,7 +7586,7 @@ See also `verilog-sk-header' for an alternative format."
   (nth 6 sig))
 (defsubst verilog-sig-type-set (sig type)
   (setcar (nthcdr 6 sig) type))
-(defsubst verilog-sig-multidim (sig)
+(defsubst verilog-sig-multidim (sig) ;; Second and additional elements of packed array
   (nth 7 sig))
 (defsubst verilog-sig-multidim-string (sig)
   (if (verilog-sig-multidim sig)
@@ -7658,13 +7766,14 @@ Signals must be in standard (base vector) form."
   "Return list of signals in IN-LIST that aren't parameters or numeric constants."
   (let (out-list)
     (while in-list
+      ;; Namespace intentionally short for AUTOs and compatibility
       (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
        (setq out-list (cons (car in-list) out-list)))
       (setq in-list (cdr in-list)))
     (nreverse out-list)))
 
 (defun verilog-signals-with (func in-list)
-  "Return IN-LIST with only signals where FUNC passed each signal is true."
+  "Return list of signals where FUNC is true executed on each signal in IN-LIST."
   (let (out-list)
     (while in-list
       (when (funcall func (car in-list))
@@ -7762,7 +7871,7 @@ Tieoff value uses `verilog-active-low-regexp' and
 `verilog-auto-reset-widths'."
   (concat
    (if (and verilog-active-low-regexp
-           (string-match verilog-active-low-regexp (verilog-sig-name sig)))
+           (verilog-string-match-fold verilog-active-low-regexp (verilog-sig-name sig)))
        "~" "")
    (cond ((not verilog-auto-reset-widths)
          "0")
@@ -7771,9 +7880,12 @@ Tieoff value uses `verilog-active-low-regexp' and
         ;; Else presume verilog-auto-reset-widths is true
         (t
          (let* ((width (verilog-sig-width sig)))
-           (if (string-match "^[0-9]+$" width)
-               (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))
-             (concat "{" width "{1'b0}}")))))))
+           (cond ((not width)
+                  "`0/*NOWIDTH*/")
+                 ((string-match "^[0-9]+$" width)
+                  (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
+                 (t
+                  (concat "{" width "{1'b0}}"))))))))
 
 ;;
 ;; Dumping
@@ -7866,6 +7978,12 @@ Tieoff value uses `verilog-active-low-regexp' and
     (verilog-backward-open-paren)
     (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
   (skip-chars-backward "a-zA-Z0-9'_$")
+  ;; #1 is legal syntax for gate primitives
+  (when (save-excursion
+         (verilog-backward-syntactic-ws-quick)
+         (eq ?# (char-before)))
+    (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil)
+    (skip-chars-backward "a-zA-Z0-9'_$"))
   (looking-at "[a-zA-Z0-9`_\$]+")
   ;; Important: don't use match string, this must work with Emacs 19 font-lock on
   (buffer-substring-no-properties (match-beginning 0) (match-end 0))
@@ -7946,14 +8064,15 @@ Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
 (defun verilog-read-decls ()
   "Compute signal declaration information for the current module at point.
 Return an array of [outputs inouts inputs wire reg assign const]."
-  (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
+  (let ((end-mod-point (or (verilog-get-end-of-defun) (point-max)))
        (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
-       in-modport in-clocking ptype ign-prop
+       in-modport in-clocking in-ign-to-semi ptype ign-prop
        sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
        sigs-gparam sigs-intf sigs-modports
        vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
        modport
        varstack tmp)
+    ;;(if dbg (setq dbg (concat dbg (format "\n\nverilog-read-decls START PT %s END %s\n" (point) end-mod-point))))
     (save-excursion
       (verilog-beg-of-defun-quick)
       (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
@@ -7979,19 +8098,24 @@ Return an array of [outputs inouts inputs wire reg assign const]."
          (or (re-search-forward "[^\\]\"" nil t)       ;; don't forward-char first, since we look for a non backslash first
              (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
         ((eq ?\; (following-char))
-         (when (and in-modport (not (eq in-modport t))) ;; end of a modport declaration
-           (verilog-modport-decls-set
-            in-modport
-            (verilog-decls-new sigs-out sigs-inout sigs-in
-                               nil nil nil nil nil nil))
-           ;; Pop from varstack to restore state to pre-clocking
-           (setq tmp (car varstack)
-                 varstack (cdr varstack)
-                 sigs-out (aref tmp 0)
-                 sigs-inout (aref tmp 1)
-                 sigs-in (aref tmp 2)))
-         (setq vec nil  io nil  expect-signal nil  newsig nil  paren 0  rvalue nil
-               v2kargs-ok nil  in-modport nil  ign-prop nil)
+         (cond (in-ign-to-semi  ;; Such as inside a "import ...;" in a module header
+                (setq in-ign-to-semi nil))
+               ((and in-modport (not (eq in-modport t))) ;; end of a modport declaration
+                (verilog-modport-decls-set
+                 in-modport
+                 (verilog-decls-new sigs-out sigs-inout sigs-in
+                                    nil nil nil nil nil nil))
+                ;; Pop from varstack to restore state to pre-clocking
+                (setq tmp (car varstack)
+                      varstack (cdr varstack)
+                      sigs-out (aref tmp 0)
+                      sigs-inout (aref tmp 1)
+                      sigs-in (aref tmp 2))
+                (setq vec nil  io nil  expect-signal nil  newsig nil  paren 0  rvalue nil
+                      v2kargs-ok nil  in-modport nil  ign-prop nil))
+               (t
+                (setq vec nil  io nil  expect-signal nil  newsig nil  paren 0  rvalue nil
+                      v2kargs-ok nil  in-modport nil  ign-prop nil)))
          (forward-char 1))
         ((eq ?= (following-char))
          (setq rvalue t  newsig nil)
@@ -8008,7 +8132,7 @@ Return an array of [outputs inouts inputs wire reg assign const]."
          (setq paren (1- paren))
          (forward-char 1)
          (when (< paren sig-paren)
-           (setq expect-signal nil)))   ; ) that ends variables inside v2k arg list
+           (setq expect-signal nil rvalue nil)))   ; ) that ends variables inside v2k arg list
         ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
          (goto-char (match-end 0))
          (cond (newsig ; Memory, not just width.  Patch last signal added's memory (nth 3)
@@ -8094,15 +8218,24 @@ Return an array of [outputs inouts inputs wire reg assign const]."
                 (setq in-modport t))
                ((equal keywd "clocking")
                 (setq in-clocking t))
+               ((equal keywd "import")
+                (if v2kargs-ok  ;; import in module header, not a modport import
+                    (setq in-ign-to-semi t  rvalue t)))
                ((equal keywd "type")
                 (setq ptype t))
+               ((equal keywd "var"))
                ;; Ifdef?  Ignore name of define
                ((member keywd '("`ifdef" "`ifndef" "`elsif"))
                 (setq rvalue t))
                ;; Type?
                ((unless ptype
                   (verilog-typedef-name-p keywd))
-                (setq typedefed keywd))
+                (cond (io
+                       (setq typedefed
+                             (if typedefed (concat typedefed " " keywd) keywd)))
+                      (t (setq vec nil  enum nil  rvalue nil  signed nil
+                               typedefed nil  multidim nil  sig-paren paren
+                               expect-signal 'sigs-var  modport nil))))
                ;; Interface with optional modport in v2k arglist?
                ;; Skip over parsing modport, and take the interface name as the type
                ((and v2kargs-ok
@@ -8162,6 +8295,7 @@ Return an array of [outputs inouts inputs wire reg assign const]."
                      (eq functask 0)
                      (not (member keywd verilog-keywords)))
                 ;; Add new signal to expect-signal's variable
+                ;;(if dbg (setq dbg (concat dbg (format "Pt %s  New sig %s'\n" (point) keywd))))
                 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
                 (set expect-signal (cons newsig
                                          (symbol-value expect-signal))))))
@@ -8193,9 +8327,18 @@ Return an array of [outputs inouts inputs wire reg assign const]."
   ;; - we want an error when we are debugging this code if they are refed.
   (defvar sigs-in)
   (defvar sigs-inout)
-  (defvar sigs-out)
   (defvar sigs-intf)
-  (defvar sigs-intfd))
+  (defvar sigs-intfd)
+  (defvar sigs-out)
+  (defvar sigs-out-d)
+  (defvar sigs-out-i)
+  (defvar sigs-out-unk)
+  (defvar sigs-temp)
+  ;; These are known to be from other packages and may not be defined
+  (defvar diff-command nil)
+  (defvar vector-skip-list)
+  ;; There are known to be from newer versions of Emacs
+  (defvar create-lockfiles))
 
 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
   "For `verilog-read-sub-decls-line', add a signal."
@@ -8437,7 +8580,7 @@ Outputs comments above subcell signals, for example:
            // Inputs
            .in  (in));"
   (save-excursion
-    (let ((end-mod-point (verilog-get-end-of-defun t))
+    (let ((end-mod-point (verilog-get-end-of-defun))
          st-point end-inst-point
          ;; below 3 modified by verilog-read-sub-decls-line
          sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
@@ -8452,7 +8595,7 @@ Outputs comments above subcell signals, for example:
                   (subprim (member submod verilog-gate-keywords))
                   (comment (concat inst " of " submod ".v"))
                   submodi submoddecls)
-             (cond
+             (cond
               (subprim
                (setq submodi `primitive
                      submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
@@ -8569,17 +8712,6 @@ Must call `verilog-read-auto-lisp-present' before this function."
               (verilog-in-hooks t))
          (eval-region beg-pt end-pt nil))))))
 
-(eval-when-compile
-  ;; Prevent compile warnings; these are let's, not globals
-  ;; Do not remove the eval-when-compile
-  ;; - we want an error when we are debugging this code if they are refed.
-  (defvar sigs-in)
-  (defvar sigs-out-d)
-  (defvar sigs-out-i)
-  (defvar sigs-out-unk)
-  (defvar sigs-temp)
-  (defvar vector-skip-list))
-
 (defun verilog-read-always-signals-recurse
   (exit-keywd rvalue temp-next)
   "Recursive routine for parentheses/bracket matching.
@@ -8743,7 +8875,7 @@ IGNORE-NEXT is true to ignore next token, fake from inside case statement."
 (defun verilog-read-instants ()
   "Parse module at point and return list of ( ( file instance ) ... )."
   (verilog-beg-of-defun-quick)
-  (let* ((end-mod-point (verilog-get-end-of-defun t))
+  (let* ((end-mod-point (verilog-get-end-of-defun))
         (state nil)
         (instants-list nil))
     (save-excursion
@@ -8890,12 +9022,14 @@ If found returns `verilog-read-auto-template-inside' structure."
   "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
 Optionally associate it with the specified enumeration ENUMNAME."
   (with-current-buffer (or buffer (current-buffer))
+    ;; Namespace intentionally short for AUTOs and compatibility
     (let ((mac (intern (concat "vh-" defname))))
       ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
       ;; Need to define to a constant if no value given
       (set (make-local-variable mac)
           (if (equal defvalue "") "1" defvalue)))
     (if enumname
+       ;; Namespace intentionally short for AUTOs and compatibility
        (let ((enumvar (intern (concat "venum-" enumname))))
          ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
          (unless (boundp enumvar) (set enumvar nil))
@@ -8965,8 +9099,9 @@ warning message, you need to add to your init file:
       (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
        (let ((defname (match-string-no-properties 1))
              (defvalue (match-string-no-properties 2)))
-         (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
-         (verilog-set-define defname defvalue origbuf)))
+         (unless (verilog-inside-comment-or-string-p (match-beginning 0))
+           (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
+           (verilog-set-define defname defvalue origbuf))))
       ;; Hack: Read parameters
       (goto-char (point-min))
       (while (re-search-forward
@@ -8979,8 +9114,9 @@ warning message, you need to add to your init file:
          (forward-comment 99999)
          (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
                                     "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
-           (verilog-set-define (match-string-no-properties 1)
-                               (match-string-no-properties 2) origbuf enumname)
+           (unless (verilog-inside-comment-or-string-p (match-beginning 0))
+             (verilog-set-define (match-string-no-properties 1)
+                                 (match-string-no-properties 2) origbuf enumname))
            (goto-char (match-end 0))
            (forward-comment 99999)))))))
 
@@ -9013,7 +9149,7 @@ foo.v (an include file):
        `define _FOO_V
        ... contents of file
        `endif // _FOO_V"
-;;slow:  (verilog-read-defines nil t))
+  ;;slow:  (verilog-read-defines nil t)
   (save-excursion
     (verilog-getopt-flags)
     (goto-char (point-min))
@@ -9183,7 +9319,7 @@ Used for __FLAGS__ in `verilog-expand-command'."
 ;;
 
 (defvar verilog-dir-cache-preserving nil
-  "If set, the directory cache is enabled, and file system changes are ignored.
+  "If true, the directory cache is enabled, and file system changes are ignored.
 See `verilog-dir-exists-p' and `verilog-dir-files'.")
 
 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
@@ -9278,10 +9414,12 @@ If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
   (while (and symbol (string-match "^`" symbol))
     (setq symbol (substring symbol 1))
     (setq symbol
+         ;; Namespace intentionally short for AUTOs and compatibility
          (if (boundp (intern (concat "vh-" symbol)))
              ;; Emacs has a bug where boundp on a buffer-local
              ;; variable in only one buffer returns t in another.
              ;; This can confuse, so check for nil.
+             ;; Namespace intentionally short for AUTOs and compatibility
              (let ((val (eval (intern (concat "vh-" symbol)))))
                (if (eq val nil)
                    (if wing-it symbol nil)
@@ -9314,10 +9452,12 @@ If the variable vh-{symbol} is defined, substitute that value."
       (setq symbol (match-string 1 text))
       ;;(message symbol)
       (cond ((and
+             ;; Namespace intentionally short for AUTOs and compatibility
              (boundp (intern (concat "vh-" symbol)))
              ;; Emacs has a bug where boundp on a buffer-local
              ;; variable in only one buffer returns t in another.
              ;; This can confuse, so check for nil.
+             ;; Namespace intentionally short for AUTOs and compatibility
              (setq val (eval (intern (concat "vh-" symbol)))))
             (setq text (replace-match val nil nil text)))
            (t (setq ok nil)))))
@@ -9398,7 +9538,7 @@ variables to build the path.  With optional CHECK-EXT also check
                   (setq outlist (cons (expand-file-name
                                        fn (file-name-directory current))
                                       outlist)))
-                (setq chkexts (cdr chkexts)))
+              (setq chkexts (cdr chkexts)))
             (setq chkdirs (cdr chkdirs)))
           (setq outlist (nreverse outlist))
           (setq verilog-dir-cache-lib-filenames
@@ -9661,6 +9801,7 @@ those clocking block's signals."
          (setq out-list (cons (car in-list) out-list)))
       (setq in-list (cdr in-list)))
     ;; New scheme
+    ;; Namespace intentionally short for AUTOs and compatibility
     (let* ((enumvar (intern (concat "venum-" enum)))
           (enumlist (and (boundp enumvar) (eval enumvar))))
       (while enumlist
@@ -9672,7 +9813,8 @@ those clocking block's signals."
   "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
   (if (or (not regexp) (equal regexp ""))
       in-list
-    (let (out-list)
+    (let ((case-fold-search verilog-case-fold)
+         out-list)
       (while in-list
        (if (string-match regexp (verilog-sig-name (car in-list)))
            (setq out-list (cons (car in-list) out-list)))
@@ -9683,7 +9825,8 @@ those clocking block's signals."
   "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
   (if (or (not regexp) (equal regexp ""))
       in-list
-    (let (out-list)
+    (let ((case-fold-search verilog-case-fold)
+         out-list)
       (while in-list
        (if (not (string-match regexp (verilog-sig-name (car in-list))))
            (setq out-list (cons (car in-list) out-list)))
@@ -9885,19 +10028,6 @@ This repairs those mis-inserted by an AUTOARG."
     (when (looking-at ",")
       (delete-char 1))))
 
-(defun verilog-get-list (start end)
-  "Return the elements of a comma separated list between START and END."
-  (interactive)
-  (let ((my-list (list))
-       my-string)
-    (save-excursion
-      (while (< (point) end)
-       (when (re-search-forward "\\([^,{]+\\)" end t)
-         (setq my-string (verilog-string-remove-spaces (match-string 1)))
-         (setq my-list (nconc my-list (list my-string) ))
-         (goto-char (match-end 0))))
-      my-list)))
-
 (defun verilog-make-width-expression (range-exp)
   "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
   ;; strip off the []
@@ -10013,7 +10143,7 @@ This repairs those mis-inserted by an AUTOARG."
 (defun verilog-typedef-name-p (variable-name)
   "Return true if the VARIABLE-NAME is a type definition."
   (when verilog-typedef-regexp
-    (string-match verilog-typedef-regexp variable-name)))
+    (verilog-string-match-fold verilog-typedef-regexp variable-name)))
 \f
 ;;
 ;; Auto deletion
@@ -10382,7 +10512,7 @@ DIFFPT.  This function is called via `verilog-diff-function'."
   (let ((name1 (with-current-buffer b1 (buffer-file-name))))
     (verilog-warn "%s:%d: Difference in AUTO expansion found"
                  name1 (with-current-buffer b1
-                         (1+ (count-lines (point-min) (point)))))
+                         (count-lines (point-min) diffpt)))
     (cond (noninteractive
           (verilog-diff-file-with-buffer name1 b2 t t))
          (t
@@ -10390,8 +10520,8 @@ DIFFPT.  This function is called via `verilog-diff-function'."
 
 (defun verilog-diff-auto ()
   "Expand AUTOs in a temporary buffer and indicate any change.
-Whitespace differences are ignored to determine identicalness, but
-once a difference is detected, whitespace differences may be shown.
+Whitespace is ignored when detecting differences, but once a
+difference is detected, whitespace differences may be shown.
 
 To call this from the command line, see \\[verilog-batch-diff-auto].
 
@@ -10611,7 +10741,6 @@ See the example in `verilog-auto-inout-modport'."
       ;; Note this may raise an error
       (when (setq submodi (verilog-modi-lookup submod t))
        (let* ((indent-pt (current-indentation))
-              (modi (verilog-modi-current))
               (submoddecls (verilog-modi-get-decls submodi))
               (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
               (sig-list-i (verilog-signals-in ;; Decls doesn't have data types, must resolve
@@ -10652,7 +10781,7 @@ See the example in `verilog-auto-inout-modport'."
                (setq sigs (cdr sigs))))
            (verilog-insert-indent "// End of automatics\n")))))))
 
-(defun verilog-auto-inst-port-map (port-st)
+(defun verilog-auto-inst-port-map (_port-st)
   nil)
 
 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
@@ -10688,7 +10817,7 @@ If PAR-VALUES replace final strings with these parameter values."
                    ""))
         (case-fold-search nil)
         (check-values par-values)
-        tpl-net)
+        tpl-net dflt-bits)
     ;; Replace parameters in bit-width
     (when (and check-values
               (not (equal vl-bits "")))
@@ -10706,11 +10835,14 @@ If PAR-VALUES replace final strings with these parameter values."
            vl-mbits (verilog-simplify-range-expression vl-mbits)
            vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
     ;; Default net value if not found
-    (setq tpl-net (concat port
+    (setq dflt-bits (if (and (verilog-sig-bits port-st)
+                            (or (verilog-sig-multidim port-st)
+                                (verilog-sig-memory port-st)))
+                       (concat "/*" vl-mbits vl-bits "*/")
+                     (concat vl-bits))
+         tpl-net (concat port
                          (if vl-modport (concat "." vl-modport) "")
-                         (if (verilog-sig-multidim port-st)
-                             (concat "/*" vl-mbits vl-bits "*/")
-                           (concat vl-bits))))
+                         dflt-bits))
     ;; Find template
     (cond (tpl-ass         ; Template of exact port name
           (setq tpl-net (nth 1 tpl-ass)))
@@ -10737,12 +10869,13 @@ If PAR-VALUES replace final strings with these parameter values."
                             (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
                             (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
                             (prin1 (eval (car (read-from-string expr)))
-                                   (lambda (ch) ())))))
+                                   (lambda (_ch) ())))))
                     (if (numberp value) (setq value (number-to-string value)))
                     value))
                 (substring tpl-net (match-end 0))))))
       ;; Replace @ and [] magic variables in final output
       (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
+      (setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net))
       (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
     ;; Insert it
     (indent-to indent-pt)
@@ -10855,6 +10988,10 @@ Limitations:
   AUTOWIRE declarations, etc.  Gates are the only case when
   position based connections are passed.
 
+  The array part of arrayed instances are ignored; this may
+  result in undesirable default AUTOINST connections; use a
+  template instead.
+
 For example, first take the submodule InstModule.v:
 
        module InstModule (o,i);
@@ -10934,6 +11071,19 @@ Templates:
   words and capitalized.  Only signals that must be different for each
   instantiation need to be listed.
 
+  Inside a template, a [] in a connection name (with nothing else
+  inside the brackets) will be replaced by the same bus subscript
+  as it is being connected to, or the [] will be removed if it is
+  a single bit signal.
+
+  Inside a template, a [][] in a connection name will behave
+  similarly to a [] for scalar or single-dimensional connection;
+  for a multidimensional connection it will print a comment
+  similar to that printed when a template is not used.  Generally
+  it is a good idea to do this for all connections in a template,
+  as then they will work for any width signal, and with AUTOWIRE.
+  See PTL_BUS becoming PTL_BUSNEW below.
+
   Inside a template, a [] in a connection name (with nothing else inside
   the brackets) will be replaced by the same bus subscript as it is being
   connected to, or the [] will be removed if it is a single bit signal.
@@ -11153,7 +11303,7 @@ For more information see the \\[verilog-faq] and forums at URL
        ;; automatic variable instantiation program.
        (let* ((tpl-info (verilog-read-auto-template submod))
               (tpl-regexp (aref tpl-info 0)))
-         (setq tpl-num (if (string-match tpl-regexp inst)
+         (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
                            (match-string 1 inst)
                          "")
                tpl-list (aref tpl-info 1)))
@@ -11296,7 +11446,7 @@ Templates:
        ;; automatic variable instantiation program.
        (let* ((tpl-info (verilog-read-auto-template submod))
               (tpl-regexp (aref tpl-info 0)))
-         (setq tpl-num (if (string-match tpl-regexp inst)
+         (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
                            (match-string 1 inst)
                          "")
                tpl-list (aref tpl-info 1)))
@@ -11587,6 +11737,7 @@ same expansion will result from only extracting outputs starting with ov:
                      (verilog-subdecls-get-outputs modsubdecls)
                      (append (verilog-decls-get-outputs moddecls)
                              (verilog-decls-get-inouts moddecls)
+                             (verilog-decls-get-inputs moddecls)
                              (verilog-subdecls-get-inputs modsubdecls)
                              (verilog-subdecls-get-inouts modsubdecls)))))
       (when regexp
@@ -11713,6 +11864,7 @@ same expansion will result from only extracting inputs starting with i:
                      (verilog-subdecls-get-inputs modsubdecls)
                      (append (verilog-decls-get-inputs moddecls)
                              (verilog-decls-get-inouts moddecls)
+                             (verilog-decls-get-outputs moddecls)
                              (verilog-decls-get-vars moddecls)
                              (verilog-decls-get-consts moddecls)
                              (verilog-decls-get-gparams moddecls)
@@ -11930,7 +12082,7 @@ against the previous example's module:
                             (verilog-signals-matching-regexp sig-list-if regexp)
                             "interface" direction-re))
          (when v2k (verilog-repair-open-comma))
-         (when (or sig-list-i sig-list-o sig-list-io)
+         (when (or sig-list-i sig-list-o sig-list-io sig-list-if)
            (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
            ;; Don't sort them so an upper AUTOINST will match the main module
            (verilog-insert-definition modi sig-list-o  "output" indent-pt v2k t)
@@ -12056,67 +12208,36 @@ Limitations:
   If placed inside the parenthesis of a module declaration, it creates
   Verilog 2001 style, else uses Verilog 1995 style.
 
-  Concatenation and outputting partial buses is not supported.
-
   Module names must be resolvable to filenames.  See `verilog-auto-inst'.
 
-  Signals are not inserted in the same order as in the original module,
-  though they will appear to be in the same order to an AUTOINST
-  instantiating either module.
+  Parameters are inserted in the same order as in the original module.
 
-  Signals declared as \"output reg\" or \"output wire\" etc will
-  lose the wire/reg declaration so that shell modules may
-  generate those outputs differently.  However, \"output logic\"
-  is propagated.
+  Parameters do not have values, which is SystemVerilog 2009 syntax.
 
 An example:
 
-       module ExampShell (/*AUTOARG*/);
-          /*AUTOINOUTMODULE(\"ExampMain\")*/
+       module ExampShell ();
+          /*AUTOINOUTPARAM(\"ExampMain\")*/
        endmodule
 
-       module ExampMain (i,o,io);
-          input i;
-          output o;
-          inout io;
+       module ExampMain ();
+          parameter PARAM = 22;
         endmodule
 
 Typing \\[verilog-auto] will make this into:
 
        module ExampShell (/*AUTOARG*/i,o,io);
-          /*AUTOINOUTMODULE(\"ExampMain\")*/
-           // Beginning of automatic in/out/inouts (from specific module)
-           output o;
-           inout io;
-           input i;
+          /*AUTOINOUTPARAM(\"ExampMain\")*/
+           // Beginning of automatic parameters (from specific module)
+           parameter PARAM;
           // End of automatics
        endmodule
 
 You may also provide an optional regular expression, in which case only
-signals matching the regular expression will be included.  For example the
-same expansion will result from only extracting signals starting with i:
-
-          /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
-
-You may also provide an optional second regular expression, in
-which case only signals which have that pin direction and data
-type will be included.  This matches against everything before
-the signal name in the declaration, for example against
-\"input\" (single bit), \"output logic\" (direction and type) or
-\"output [1:0]\" (direction and implicit type).  You also
-probably want to skip spaces in your regexp.
+parameters matching the regular expression will be included.  For example the
+same expansion will result from only extracting parameters starting with i:
 
-For example, the below will result in matching the output \"o\"
-against the previous example's module:
-
-          /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/
-
-You may also provide an optional third regular expression, in
-which case any parameter names that match the given regexp will
-be included.  Including parameters is off by default.  To include
-all signals and parameters, use:
-
-          /*AUTOINOUTMODULE(\"ExampMain\",\".*\",\".*\",\".*\")*/"
+          /*AUTOINOUTPARAM(\"ExampMain\",\"^i\")*/"
   (save-excursion
     (let* ((params (verilog-read-auto-params 1 2))
           (submod (nth 0 params))
@@ -12164,7 +12285,7 @@ Limitations:
   Interface names must be resolvable to filenames.  See `verilog-auto-inst'.
 
 As with other autos, any inputs/outputs declared in the module
-will suppress the AUTO from redeclaring an input/output by
+will suppress the AUTO from redeclaring an inputs/outputs by
 the same name.
 
 An example:
@@ -12456,12 +12577,20 @@ used on the right hand side of assignments.
 
 By default, AUTORESET will include the width of the signal in the
 autos, SystemVerilog designs may want to change this.  To control
-this behavior, see `verilog-auto-reset-widths'.
+this behavior, see `verilog-auto-reset-widths'.  In some cases
+AUTORESET must use a '0 assignment and it will print NOWIDTH; use
+`verilog-auto-reset-widths' unbased to prevent this.
 
 AUTORESET ties signals to deasserted, which is presumed to be zero.
 Signals that match `verilog-active-low-regexp' will be deasserted by tying
 them to a one.
 
+AUTORESET may try to reset arrays or structures that cannot be
+reset by a simple assignment, resulting in compile errors.  This
+is a feature to be taken as a hint that you need to reset these
+signals manually (or put them into a \"`ifdef NEVER signal<=`0;
+`endif\" so Verilog-Mode ignores them.)
+
 An example:
 
     always @(posedge clk or negedge reset_l) begin
@@ -12882,7 +13011,7 @@ Typing \\[verilog-auto] will make this into:
                      ;; count(enums) == width(sig)
                      (equal (number-to-string (length enum-sigs))
                             (verilog-sig-width undecode-sig)))))
-          (enum-chars 0)
+          (enum-chars 0)
           (ascii-chars 0))
       ;;
       ;; Find number of ascii chars needed
@@ -13005,6 +13134,9 @@ Use \\[verilog-inject-auto] to insert AUTOs for the first time.
 
 Use \\[verilog-faq] for a pointer to frequently asked questions.
 
+For new users, we recommend setting `verilog-case-fold' to nil
+and `verilog-auto-arg-sort' to t.
+
 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
 called before and after this function, respectively.
 
@@ -13030,12 +13162,12 @@ Using \\[describe-function], see also:
     `verilog-auto-arg'          for AUTOARG module instantiations
     `verilog-auto-ascii-enum'   for AUTOASCIIENUM enumeration decoding
     `verilog-auto-assign-modport' for AUTOASSIGNMODPORT assignment to/from modport
+    `verilog-auto-inout'        for AUTOINOUT making hierarchy inouts
     `verilog-auto-inout-comp'   for AUTOINOUTCOMP copy complemented i/o
     `verilog-auto-inout-in'     for AUTOINOUTIN inputs for all i/o
     `verilog-auto-inout-modport'  for AUTOINOUTMODPORT i/o from an interface modport
     `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
     `verilog-auto-inout-param'  for AUTOINOUTPARAM copying params from elsewhere
-    `verilog-auto-inout'        for AUTOINOUT making hierarchy inouts
     `verilog-auto-input'        for AUTOINPUT making hierarchy inputs
     `verilog-auto-insert-lisp'  for AUTOINSERTLISP insert code from lisp function
     `verilog-auto-inst'         for AUTOINST instantiation pins
@@ -13047,7 +13179,7 @@ Using \\[describe-function], see also:
     `verilog-auto-reg'          for AUTOREG registers
     `verilog-auto-reg-input'    for AUTOREGINPUT instantiation registers
     `verilog-auto-reset'        for AUTORESET flop resets
-    `verilog-auto-sense'        for AUTOSENSE always sensitivity lists
+    `verilog-auto-sense'        for AUTOSENSE or AS always sensitivity lists
     `verilog-auto-tieoff'       for AUTOTIEOFF output tieoffs
     `verilog-auto-undef'        for AUTOUNDEF `undef of local `defines
     `verilog-auto-unused'       for AUTOUNUSED unused inputs/inouts
@@ -13066,6 +13198,7 @@ Wilson Snyder (wsnyder@wsnyder.org)."
   (verilog-save-font-mods
    (let ((oldbuf (if (not (buffer-modified-p))
                     (buffer-string)))
+        (case-fold-search verilog-case-fold)
         ;; Cache directories; we don't write new files, so can't change
         (verilog-dir-cache-preserving t)
         ;; Cache current module
@@ -13196,7 +13329,7 @@ Wilson Snyder (wsnyder@wsnyder.org)."
     (define-key map "r" 'verilog-sk-repeat)
     (define-key map "s" 'verilog-sk-specify)
     (define-key map "t" 'verilog-sk-task)
-    (define-key map "u" 'verilog-sk-uvm-class)
+    (define-key map "u" 'verilog-sk-uvm-object)
     (define-key map "w" 'verilog-sk-while)
     (define-key map "x" 'verilog-sk-casex)
     (define-key map "z" 'verilog-sk-casez)
@@ -13209,6 +13342,7 @@ Wilson Snyder (wsnyder@wsnyder.org)."
     (define-key map "O" 'verilog-sk-output)
     (define-key map "S" 'verilog-sk-state-machine)
     (define-key map "=" 'verilog-sk-inout)
+    (define-key map "U" 'verilog-sk-uvm-component)
     (define-key map "W" 'verilog-sk-wire)
     (define-key map "R" 'verilog-sk-reg)
     (define-key map "D" 'verilog-sk-define-signal)
@@ -13325,13 +13459,13 @@ See also `verilog-header' for an alternative format."
   > _ \n
   > "endclass" (progn (electric-verilog-terminate-line) nil))
 
-(define-skeleton verilog-sk-uvm-class
+(define-skeleton verilog-sk-uvm-object
   "Insert a class definition"
   ()
   > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
   > _ \n
   > "`uvm_object_utils_begin(" name ")" \n
-  > (- verilog-indent-level) " `uvm_object_utils_end" \n
+  > (- verilog-indent-level) "`uvm_object_utils_end" \n
   > _ \n
   > "function new(name=\"" name "\");" \n
   > "super.new(name);" \n
@@ -13339,6 +13473,20 @@ See also `verilog-header' for an alternative format."
   > _ \n
   > "endclass" (progn (electric-verilog-terminate-line) nil))
 
+(define-skeleton verilog-sk-uvm-component
+  "Insert a class definition"
+  ()
+  > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
+  > _ \n
+  > "`uvm_component_utils_begin(" name ")" \n
+  > (- verilog-indent-level) "`uvm_component_utils_end" \n
+  > _ \n
+  > "function new(name=\"\", uvm_component parent);" \n
+  > "super.new(name, parent);" \n
+  > (- verilog-indent-level) "endfunction" \n
+  > _ \n
+  > "endclass" (progn (electric-verilog-terminate-line) nil))
+
 (define-skeleton verilog-sk-primitive
   "Insert a task definition."
   ()
@@ -13401,8 +13549,7 @@ for sensitivity list."
   ()
   > "begin" '(verilog-sk-prompt-name) \n
   > _ \n
-  > (- verilog-indent-level-behavioral) "end"
-)
+  > (- verilog-indent-level-behavioral) "end" )
 
 (define-skeleton verilog-sk-fork
   "Insert a fork join block."
@@ -13600,7 +13747,7 @@ and the case items."
   "Map containing mouse bindings for `verilog-mode'.")
 
 
-(defun verilog-highlight-region (beg end old-len)
+(defun verilog-highlight-region (beg end _old-len)
   "Colorize included files and modules in the (changed?) region.
 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
   (when (or verilog-highlight-includes
@@ -13783,6 +13930,7 @@ Files are checked based on `verilog-library-flags'."
        verilog-before-getopt-flags-hook
        verilog-before-save-font-hook
        verilog-cache-enabled
+       verilog-case-fold
        verilog-case-indent
        verilog-cexp-indent
        verilog-compiler
@@ -13809,7 +13957,6 @@ Files are checked based on `verilog-library-flags'."
        verilog-linter
        verilog-minimum-comment-distance
        verilog-mode-hook
-       verilog-mode-release-date
        verilog-mode-release-emacs
        verilog-mode-version
        verilog-preprocessor