diff options
| author | Wilson Snyder | 2022-12-17 15:00:34 -0500 |
|---|---|---|
| committer | Wilson Snyder | 2022-12-17 15:00:34 -0500 |
| commit | 0dddf9849eac699466a33f7ec28dd5290eea29b0 (patch) | |
| tree | 52024bdb2c65a917fea7874c39b49bb128068e0b | |
| parent | 7828ceac1dd0638bccdec95ce4d1ce504e152bd3 (diff) | |
| download | emacs-0dddf9849eac699466a33f7ec28dd5290eea29b0.tar.gz emacs-0dddf9849eac699466a33f7ec28dd5290eea29b0.zip | |
; lisp/progmodes/verilog-mode.el: Collected updates from verilog-mode upstream.
* lisp/progmodes/verilog-mode.el (verilog-beg-block-re-ordered)
(verilog-forward-sexp, verilog-leap-to-head): Support of hideshow
for ifdef/ifndef blocks (#1819).
(verilog-cparenexp-indent-level): Improve multiline indentation
with verilog-indent-lists set to nil. Indent uvm statements and
system tasks and functions according to the argument position in
the parenthesized expression.
(verilog-extended-complete-re): Fix verilog-beg-of-statement on
local methods.
(verilog-beg-of-statement): Fix indentation of properties inside
ifdef (#1817).
(verilog-declaration-varname-matcher, verilog-fontify-variables):
Add option to enable/disable variable fontification.
(verilog-declaration-varname-matcher): Fix bug in highlighting of
vars on func/task arguments.
(verilog-mark-defun): Fix behavior of verilog-mark-defun (#1805).
(verilog-pretty-declarations): Add support to align
declarations/expressions within the region (#1806).
(verilog-align-typedef-regexp, verilog-align-typedef-words): Add
support for alignment of user defined types (#1803).
(verilog-pretty-declarations): Limit alignment of members of a
struct to consecutive valid declarations.
(verilog-typedef-enum-re): Update minor bug in typedef enum regex.
(verilog-indent-declaration): Fix compiler warning on
verilog-indent-declaration.
(verilog-batch-error-wrapper) (verilog-warn-error,
verilog-warn-fatal) (verilog-warn-fatal-internal): Make
`verilog-warn-fatal' safe for local variables (#1799). Reported
by Rich-Cloutier.
(verilog-align-comment-distance, verilog-align-comments)
(verilog-align-decl-expr-comments)
(verilog-align-declaration-comments): Support alignment of
parameter/localparam expressions. Support for expression
alignment in parameter lists. Support declaration/expression
alignment of 'type' parameters. Support alignment of inline
comments after `verilog-pretty-expr'. Alignment of expressions
that do not have blanks before/after operator char Fix on
functions that did not work as expected for this use case. Use
markers in verilog-pretty-expr to avoid bugs while iterating.
(verilog-pretty-expr): Fix bug in alignment of expressions
(#1797).
(verilog-cparenexp-indent-level): Improve indentation of defun
parameters when indent-lists is nil (#1795).
(verilog-align-assign-expr): Add support to align expressions of
continuous assignments (#1793).
(verilog-pretty-expr): Fix bug in boundaries of
verilog-pretty-expr (#1792) and prevent verilog-pretty-expr from
executing on multiline assignments
(verilog-do-indent): Fix indentation of assignments and enums with
indent-lists nil (#1790).
(verilog-do-indent): Fix alignment of structs and enums
(#1789).
(verilog-backward-sexp, verilog-forward-sexp): Add precedence to
paren expressions for sexp funcs navigation (#1788).
(verilog-declaration-varname-matcher): Fix fontifying of variable
names and overriding of keywords (#1787).
(verilog-do-indent): Fix indentation of paren expr if
verilog-indent-lists is nil (#1785).
(verilog-backward-ws&directives): Fix indentation after double
comment (#1784).
(verilog-beg-of-statement-1): Fix indentation of instances and
declarations right after 'begin' (#1782).
(verilog-declaration-comments-distance): Add variable to adjust
aligned comment distance in declarations
(#1779).
(verilog-indent-ignore-multiline-defines): Add indentation ignore
of multiline defines and custom regexps (#1778).
(verilog-align-declaration-comments): Add support to align
comments in declarations (#1775).
(verilog-pretty-declarations): Fix alignment of user types on
ports declarations.
(verilog-do-indent): Fix indentation of virtual, protected and
static class methods when verilog-indent-lists is nil.
(verilog-get-lineup-indent, verilog-pretty-declarations): Fix
alignment of first port declaration (#1167) (#1771).
(verilog-pretty-declarations): Fix alignment of declaration of
interfaces with modports (#636) (#1770).
(verilog-do-indent): Add `verilog-indent-class-inside-pkg' and fix
indentation of classes inside packages (#286) (#1769). Reported
by Gonzalo Larumbe.
(verilog-backward-sexp, verilog-forward-sexp)
(verilog-leap-to-class-head, verilog-leap-to-head): Fix
indentation after interface class (#1047) (#1768). Reported by
Gonzalo Larumbe.
(verilog-do-indent): Fix indentation if verilog-indent-lists is
nil (#1703) (#1767). Reported by Gonzalo Larumbe.
(verilog-do-indent): Fix indentation of coverpoints (#1321)
(#1766).
(verilog-backward-sexp, verilog-forward-sexp)
(verilog-leap-to-head): Fix bug in forward-sexp and backward-sexp
for some constructs (#1765) Reported by Gonzalo Larumbe.
| -rw-r--r-- | lisp/progmodes/verilog-mode.el | 1568 |
1 files changed, 1089 insertions, 479 deletions
diff --git a/lisp/progmodes/verilog-mode.el b/lisp/progmodes/verilog-mode.el index e5458e6a07f..7e107d41e18 100644 --- a/lisp/progmodes/verilog-mode.el +++ b/lisp/progmodes/verilog-mode.el | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | ;; Keywords: languages | 9 | ;; Keywords: languages |
| 10 | ;; The "Version" is the date followed by the decimal rendition of the Git | 10 | ;; The "Version" is the date followed by the decimal rendition of the Git |
| 11 | ;; commit hex. | 11 | ;; commit hex. |
| 12 | ;; Version: 2021.10.14.127365406 | 12 | ;; Version: 2022.12.17.249810658 |
| 13 | 13 | ||
| 14 | ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this | 14 | ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this |
| 15 | ;; file on 19/3/2008, and the maintainer agreed that when a bug is | 15 | ;; file on 19/3/2008, and the maintainer agreed that when a bug is |
| @@ -124,7 +124,7 @@ | |||
| 124 | ;; | 124 | ;; |
| 125 | 125 | ||
| 126 | ;; This variable will always hold the version number of the mode | 126 | ;; This variable will always hold the version number of the mode |
| 127 | (defconst verilog-mode-version "2021-10-14-797711e-vpo-GNU" | 127 | (defconst verilog-mode-version "2022-12-17-ee3cee2-vpo-GNU" |
| 128 | "Version of this Verilog mode.") | 128 | "Version of this Verilog mode.") |
| 129 | (defconst verilog-mode-release-emacs t | 129 | (defconst verilog-mode-release-emacs t |
| 130 | "If non-nil, this version of Verilog mode was released with Emacs itself.") | 130 | "If non-nil, this version of Verilog mode was released with Emacs itself.") |
| @@ -455,11 +455,11 @@ This function may be removed when Emacs 21 is no longer supported." | |||
| 455 | last-command-event))) | 455 | last-command-event))) |
| 456 | 456 | ||
| 457 | (defvar verilog-no-change-functions nil | 457 | (defvar verilog-no-change-functions nil |
| 458 | "True if `after-change-functions' is disabled. | 458 | "Non-nil if `after-change-functions' is disabled. |
| 459 | Use of `syntax-ppss' may break, as ppss's cache may get corrupted.") | 459 | Use of `syntax-ppss' may break, as ppss's cache may get corrupted.") |
| 460 | 460 | ||
| 461 | (defvar verilog-in-hooks nil | 461 | (defvar verilog-in-hooks nil |
| 462 | "True when within a `verilog-run-hooks' block.") | 462 | "Non-nil when within a `verilog-run-hooks' block.") |
| 463 | 463 | ||
| 464 | (defmacro verilog-run-hooks (&rest hooks) | 464 | (defmacro verilog-run-hooks (&rest hooks) |
| 465 | "Run each hook in HOOKS using `run-hooks'. | 465 | "Run each hook in HOOKS using `run-hooks'. |
| @@ -505,8 +505,14 @@ Set `verilog-in-hooks' during this time, to assist AUTO caches." | |||
| 505 | (defvar verilog-debug nil | 505 | (defvar verilog-debug nil |
| 506 | "Non-nil means enable debug messages for `verilog-mode' internals.") | 506 | "Non-nil means enable debug messages for `verilog-mode' internals.") |
| 507 | 507 | ||
| 508 | (defvar verilog-warn-fatal nil | 508 | (defcustom verilog-warn-fatal nil |
| 509 | "Non-nil means `verilog-warn-error' warnings are fatal `error's.") | 509 | "Non-nil means `verilog-warn-error' warnings are fatal `error's." |
| 510 | :group 'verilog-mode-auto | ||
| 511 | :type 'boolean) | ||
| 512 | (put 'verilog-warn-fatal 'safe-local-variable #'verilog-booleanp) | ||
| 513 | |||
| 514 | ;; Internal use similar to `verilog-warn-fatal' | ||
| 515 | (defvar verilog-warn-fatal-internal t) | ||
| 510 | 516 | ||
| 511 | (defcustom verilog-linter | 517 | (defcustom verilog-linter |
| 512 | "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'" | 518 | "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'" |
| @@ -679,6 +685,18 @@ Set to 0 to have all directives start at the left side of the screen." | |||
| 679 | :type 'integer) | 685 | :type 'integer) |
| 680 | (put 'verilog-indent-level-directive 'safe-local-variable #'integerp) | 686 | (put 'verilog-indent-level-directive 'safe-local-variable #'integerp) |
| 681 | 687 | ||
| 688 | (defcustom verilog-indent-ignore-multiline-defines t | ||
| 689 | "Non-nil means ignore indentation on lines that are part of a multiline define." | ||
| 690 | :group 'verilog-mode-indent | ||
| 691 | :type 'boolean) | ||
| 692 | (put 'verilog-indent-ignore-multiline-defines 'safe-local-variable #'verilog-booleanp) | ||
| 693 | |||
| 694 | (defcustom verilog-indent-ignore-regexp nil | ||
| 695 | "Regexp that matches lines that should be ignored for indentation." | ||
| 696 | :group 'verilog-mode-indent | ||
| 697 | :type 'boolean) | ||
| 698 | (put 'verilog-indent-ignore-regexp 'safe-local-variable #'stringp) | ||
| 699 | |||
| 682 | (defcustom verilog-cexp-indent 2 | 700 | (defcustom verilog-cexp-indent 2 |
| 683 | "Indentation of Verilog statements split across lines." | 701 | "Indentation of Verilog statements split across lines." |
| 684 | :group 'verilog-mode-indent | 702 | :group 'verilog-mode-indent |
| @@ -723,6 +741,13 @@ Otherwise, line them up." | |||
| 723 | :type 'boolean) | 741 | :type 'boolean) |
| 724 | (put 'verilog-indent-begin-after-if 'safe-local-variable #'verilog-booleanp) | 742 | (put 'verilog-indent-begin-after-if 'safe-local-variable #'verilog-booleanp) |
| 725 | 743 | ||
| 744 | (defcustom verilog-indent-class-inside-pkg t | ||
| 745 | "Non-nil means indent classes inside packages. | ||
| 746 | Otherwise, classes have zero indentation." | ||
| 747 | :group 'verilog-mode-indent | ||
| 748 | :type 'boolean) | ||
| 749 | (put 'verilog-indent-class-inside-pkg 'safe-local-variable #'verilog-booleanp) | ||
| 750 | |||
| 726 | (defcustom verilog-align-ifelse nil | 751 | (defcustom verilog-align-ifelse nil |
| 727 | "Non-nil means align `else' under matching `if'. | 752 | "Non-nil means align `else' under matching `if'. |
| 728 | Otherwise else is lined up with first character on line holding matching if." | 753 | Otherwise else is lined up with first character on line holding matching if." |
| @@ -730,6 +755,37 @@ Otherwise else is lined up with first character on line holding matching if." | |||
| 730 | :type 'boolean) | 755 | :type 'boolean) |
| 731 | (put 'verilog-align-ifelse 'safe-local-variable #'verilog-booleanp) | 756 | (put 'verilog-align-ifelse 'safe-local-variable #'verilog-booleanp) |
| 732 | 757 | ||
| 758 | (defcustom verilog-align-decl-expr-comments t | ||
| 759 | "Non-nil means align declaration and expressions comments." | ||
| 760 | :group 'verilog-mode-indent | ||
| 761 | :type 'boolean) | ||
| 762 | (put 'verilog-align-decl-expr-comments 'safe-local-variable #'verilog-booleanp) | ||
| 763 | |||
| 764 | (defcustom verilog-align-comment-distance 1 | ||
| 765 | "Distance (in spaces) between longest declaration/expression and comments. | ||
| 766 | Only works if `verilog-align-decl-expr-comments' is non-nil." | ||
| 767 | :group 'verilog-mode-indent | ||
| 768 | :type 'integer) | ||
| 769 | (put 'verilog-align-comment-distance 'safe-local-variable #'integerp) | ||
| 770 | |||
| 771 | (defcustom verilog-align-assign-expr nil | ||
| 772 | "Non-nil means align expressions of continuous assignments." | ||
| 773 | :group 'verilog-mode-indent | ||
| 774 | :type 'boolean) | ||
| 775 | (put 'verilog-align-assign-expr 'safe-local-variable #'verilog-booleanp) | ||
| 776 | |||
| 777 | (defcustom verilog-align-typedef-regexp nil | ||
| 778 | "Regexp that matches user typedefs for declaration alignment." | ||
| 779 | :group 'verilog-mode-indent | ||
| 780 | :type 'string) | ||
| 781 | (put 'verilog-align-typedef-regexp 'safe-local-variable #'stringp) | ||
| 782 | |||
| 783 | (defcustom verilog-align-typedef-words nil | ||
| 784 | "List of words that match user typedefs for declaration alignment." | ||
| 785 | :group 'verilog-mode-indent | ||
| 786 | :type '(repeat string)) | ||
| 787 | (put 'verilog-align-typedef-words 'safe-local-variable #'listp) | ||
| 788 | |||
| 733 | (defcustom verilog-minimum-comment-distance 10 | 789 | (defcustom verilog-minimum-comment-distance 10 |
| 734 | "Minimum distance (in lines) between begin and end required before a comment. | 790 | "Minimum distance (in lines) between begin and end required before a comment. |
| 735 | Setting this variable to zero results in every end acquiring a comment; the | 791 | Setting this variable to zero results in every end acquiring a comment; the |
| @@ -876,6 +932,12 @@ always be saved." | |||
| 876 | :type 'boolean) | 932 | :type 'boolean) |
| 877 | (put 'verilog-auto-star-save 'safe-local-variable #'verilog-booleanp) | 933 | (put 'verilog-auto-star-save 'safe-local-variable #'verilog-booleanp) |
| 878 | 934 | ||
| 935 | (defcustom verilog-fontify-variables t | ||
| 936 | "Non-nil means fontify declaration variables." | ||
| 937 | :group 'verilog-mode-actions | ||
| 938 | :type 'boolean) | ||
| 939 | (put 'verilog-fontify-variables 'safe-local-variable #'verilog-booleanp) | ||
| 940 | |||
| 879 | (defvar verilog-auto-update-tick nil | 941 | (defvar verilog-auto-update-tick nil |
| 880 | "Modification tick at which autos were last performed.") | 942 | "Modification tick at which autos were last performed.") |
| 881 | 943 | ||
| @@ -1052,7 +1114,7 @@ You might want these defined in each file; put at the *END* of your file | |||
| 1052 | something like: | 1114 | something like: |
| 1053 | 1115 | ||
| 1054 | // Local Variables: | 1116 | // Local Variables: |
| 1055 | // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\") | 1117 | // verilog-library-files:(\"/path/technology.v\" \"/path2/tech2.v\") |
| 1056 | // End: | 1118 | // End: |
| 1057 | 1119 | ||
| 1058 | Verilog-mode attempts to detect changes to this local variable, but they | 1120 | Verilog-mode attempts to detect changes to this local variable, but they |
| @@ -1124,7 +1186,7 @@ those temporaries reset. See example in `verilog-auto-reset'." | |||
| 1124 | (put 'verilog-auto-reset-blocking-in-non 'safe-local-variable #'verilog-booleanp) | 1186 | (put 'verilog-auto-reset-blocking-in-non 'safe-local-variable #'verilog-booleanp) |
| 1125 | 1187 | ||
| 1126 | (defcustom verilog-auto-reset-widths t | 1188 | (defcustom verilog-auto-reset-widths t |
| 1127 | "True means AUTORESET should determine the width of signals. | 1189 | "Non-nil means AUTORESET should determine the width of signals. |
| 1128 | This is then used to set the width of the zero (32'h0 for example). This | 1190 | This is then used to set the width of the zero (32'h0 for example). This |
| 1129 | is required by some lint tools that aren't smart enough to ignore widths of | 1191 | is required by some lint tools that aren't smart enough to ignore widths of |
| 1130 | the constant zero. This may result in ugly code when parameters determine | 1192 | the constant zero. This may result in ugly code when parameters determine |
| @@ -1264,7 +1326,7 @@ See `verilog-auto-inst-param-value'." | |||
| 1264 | Also affects AUTOINSTPARAM. Declaration order is the default for | 1326 | Also affects AUTOINSTPARAM. Declaration order is the default for |
| 1265 | backward compatibility, and as some teams prefer signals that are | 1327 | backward compatibility, and as some teams prefer signals that are |
| 1266 | declared together to remain together. Sorted order reduces | 1328 | declared together to remain together. Sorted order reduces |
| 1267 | changes when declarations are moved around in a file. Sorting is | 1329 | changes when declarations are moved around in a file. Sorting is |
| 1268 | within input/output/inout groupings, there is intentionally no | 1330 | within input/output/inout groupings, there is intentionally no |
| 1269 | option to intermix between input/output/inouts. | 1331 | option to intermix between input/output/inouts. |
| 1270 | 1332 | ||
| @@ -1275,7 +1337,7 @@ See also `verilog-auto-arg-sort'." | |||
| 1275 | (put 'verilog-auto-inst-sort 'safe-local-variable #'verilog-booleanp) | 1337 | (put 'verilog-auto-inst-sort 'safe-local-variable #'verilog-booleanp) |
| 1276 | 1338 | ||
| 1277 | (defcustom verilog-auto-inst-vector t | 1339 | (defcustom verilog-auto-inst-vector t |
| 1278 | "True means when creating default ports with AUTOINST, use bus subscripts. | 1340 | "Non-nil means when creating default ports with AUTOINST, use bus subscripts. |
| 1279 | If nil, skip the subscript when it matches the entire bus as declared in | 1341 | If nil, skip the subscript when it matches the entire bus as declared in |
| 1280 | the module (AUTOWIRE signals always are subscripted, you must manually | 1342 | the module (AUTOWIRE signals always are subscripted, you must manually |
| 1281 | declare the wire to have the subscripts removed.) Setting this to nil may | 1343 | declare the wire to have the subscripts removed.) Setting this to nil may |
| @@ -1515,10 +1577,9 @@ If set will become buffer local.") | |||
| 1515 | (define-key map "\C-c/" #'verilog-star-comment) | 1577 | (define-key map "\C-c/" #'verilog-star-comment) |
| 1516 | (define-key map "\C-c\C-c" #'verilog-comment-region) | 1578 | (define-key map "\C-c\C-c" #'verilog-comment-region) |
| 1517 | (define-key map "\C-c\C-u" #'verilog-uncomment-region) | 1579 | (define-key map "\C-c\C-u" #'verilog-uncomment-region) |
| 1518 | (when (featurep 'xemacs) | 1580 | (define-key map "\M-\C-h" #'verilog-mark-defun) |
| 1519 | (define-key map [(meta control h)] #'verilog-mark-defun) | 1581 | (define-key map "\M-\C-a" #'verilog-beg-of-defun) |
| 1520 | (define-key map "\M-\C-a" #'verilog-beg-of-defun) | 1582 | (define-key map "\M-\C-e" #'verilog-end-of-defun) |
| 1521 | (define-key map "\M-\C-e" #'verilog-end-of-defun)) | ||
| 1522 | (define-key map "\C-c\C-d" #'verilog-goto-defun) | 1583 | (define-key map "\C-c\C-d" #'verilog-goto-defun) |
| 1523 | (define-key map "\C-c\C-k" #'verilog-delete-auto) | 1584 | (define-key map "\C-c\C-k" #'verilog-delete-auto) |
| 1524 | (define-key map "\C-c\C-a" #'verilog-auto) | 1585 | (define-key map "\C-c\C-a" #'verilog-auto) |
| @@ -2028,11 +2089,11 @@ Where __FLAGS__ appears in the string `verilog-current-flags' | |||
| 2028 | will be substituted. Where __FILE__ appears in the string, the | 2089 | will be substituted. Where __FILE__ appears in the string, the |
| 2029 | current buffer's file-name, without the directory portion, will | 2090 | current buffer's file-name, without the directory portion, will |
| 2030 | be substituted." | 2091 | be substituted." |
| 2031 | (setq command (verilog-string-replace-matches | 2092 | (setq command (verilog-string-replace-matches |
| 2032 | ;; Note \\b only works if under verilog syntax table | 2093 | ;; Note \\b only works if under verilog syntax table |
| 2033 | "\\b__FLAGS__\\b" (verilog-current-flags) | 2094 | "\\b__FLAGS__\\b" (verilog-current-flags) |
| 2034 | t t command)) | 2095 | t t command)) |
| 2035 | (setq command (verilog-string-replace-matches | 2096 | (setq command (verilog-string-replace-matches |
| 2036 | "\\b__FILE__\\b" (file-name-nondirectory | 2097 | "\\b__FILE__\\b" (file-name-nondirectory |
| 2037 | (or (buffer-file-name) "")) | 2098 | (or (buffer-file-name) "")) |
| 2038 | t t command)) | 2099 | t t command)) |
| @@ -2468,13 +2529,8 @@ find the errors." | |||
| 2468 | ;; | 2529 | ;; |
| 2469 | ;; Regular expressions used to calculate indent, etc. | 2530 | ;; Regular expressions used to calculate indent, etc. |
| 2470 | ;; | 2531 | ;; |
| 2471 | (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>") | 2532 | (defconst verilog-identifier-re "[a-zA-Z_][a-zA-Z_0-9]*") |
| 2472 | ;; Want to match | 2533 | (defconst verilog-identifier-sym-re (concat "\\<" verilog-identifier-re "\\>")) |
| 2473 | ;; aa : | ||
| 2474 | ;; aa,bb : | ||
| 2475 | ;; a[34:32] : | ||
| 2476 | ;; a, | ||
| 2477 | ;; b : | ||
| 2478 | (defconst verilog-assignment-operator-re | 2534 | (defconst verilog-assignment-operator-re |
| 2479 | (eval-when-compile | 2535 | (eval-when-compile |
| 2480 | (verilog-regexp-opt | 2536 | (verilog-regexp-opt |
| @@ -2492,12 +2548,11 @@ find the errors." | |||
| 2492 | ) 't | 2548 | ) 't |
| 2493 | ))) | 2549 | ))) |
| 2494 | (defconst verilog-assignment-operation-re | 2550 | (defconst verilog-assignment-operation-re |
| 2495 | (concat | 2551 | (concat "\\(^.*?\\)" verilog-assignment-operator-re)) |
| 2496 | ;; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)" | 2552 | (defconst verilog-assignment-operation-re-2 |
| 2497 | ;; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)" | 2553 | (concat "\\(.*?\\)" verilog-assignment-operator-re)) |
| 2498 | "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" )) | ||
| 2499 | 2554 | ||
| 2500 | (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*")) | 2555 | (defconst verilog-label-re (concat verilog-identifier-sym-re "\\s-*:\\s-*")) |
| 2501 | (defconst verilog-property-re | 2556 | (defconst verilog-property-re |
| 2502 | (concat "\\(" verilog-label-re "\\)?" | 2557 | (concat "\\(" verilog-label-re "\\)?" |
| 2503 | ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>" | 2558 | ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>" |
| @@ -2732,6 +2787,9 @@ find the errors." | |||
| 2732 | "\\|\\(\\<clocking\\>\\)" ;17 | 2787 | "\\|\\(\\<clocking\\>\\)" ;17 |
| 2733 | "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;18 | 2788 | "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;18 |
| 2734 | "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)" | 2789 | "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)" |
| 2790 | "\\|\\(\\<`ifn?def\\>\\)" ;20, matched end can be: `else `elsif `endif | ||
| 2791 | "\\|\\(\\<`else\\>\\)" ;21, matched end can be: `endif | ||
| 2792 | "\\|\\(\\<`elsif\\>\\)" ;22, matched end can be: `else `endif | ||
| 2735 | ;; | 2793 | ;; |
| 2736 | )) | 2794 | )) |
| 2737 | 2795 | ||
| @@ -2817,40 +2875,54 @@ find the errors." | |||
| 2817 | "localparam" "parameter" "var" | 2875 | "localparam" "parameter" "var" |
| 2818 | ;; misc | 2876 | ;; misc |
| 2819 | "string" "event" "chandle" "virtual" "enum" "genvar" | 2877 | "string" "event" "chandle" "virtual" "enum" "genvar" |
| 2820 | "struct" "union" | 2878 | "struct" "union" "type" |
| 2821 | ;; builtin classes | 2879 | ;; builtin classes |
| 2822 | "mailbox" "semaphore" | 2880 | "mailbox" "semaphore" |
| 2823 | )))) | 2881 | )))) |
| 2824 | (defconst verilog-declaration-re | ||
| 2825 | (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re)) | ||
| 2826 | (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+") | 2882 | (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+") |
| 2827 | (defconst verilog-optional-signed-re "\\s-*\\(\\(un\\)?signed\\)?") | 2883 | (defconst verilog-optional-signed-re "\\s-*\\(\\(un\\)?signed\\)?") |
| 2828 | (defconst verilog-optional-signed-range-re | 2884 | (defconst verilog-optional-signed-range-re |
| 2829 | (concat | 2885 | (concat "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<\\(un\\)?signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?")) |
| 2830 | "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<\\(un\\)?signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?")) | ||
| 2831 | (defconst verilog-macroexp-re "`\\sw+") | 2886 | (defconst verilog-macroexp-re "`\\sw+") |
| 2832 | |||
| 2833 | (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)") | 2887 | (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)") |
| 2834 | (defconst verilog-declaration-re-2-no-macro | 2888 | (defconst verilog-interface-modport-re "\\(\\s-*\\([a-zA-Z0-9`_$]+\\.[a-zA-Z0-9`_$]+\\)[ \t\f]+\\)") |
| 2835 | (concat "\\s-*" verilog-declaration-re | 2889 | (defconst verilog-comment-start-regexp "//\\|/\\*" "Dual comment value for `comment-start-regexp'.") |
| 2836 | "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" | 2890 | (defconst verilog-typedef-enum-re |
| 2837 | "\\)")) | 2891 | (concat "^\\s-*\\(typedef\\s-+\\)?enum\\(\\s-+" verilog-declaration-core-re "\\s-*" verilog-optional-signed-range-re "\\)?")) |
| 2838 | (defconst verilog-declaration-re-2-macro | 2892 | |
| 2839 | (concat "\\s-*" verilog-declaration-re | 2893 | (defconst verilog-declaration-simple-re |
| 2840 | "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" | 2894 | (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re)) |
| 2841 | "\\|\\(" verilog-macroexp-re "\\)" | 2895 | (defconst verilog-declaration-re |
| 2842 | "\\)")) | 2896 | (concat "\\s-*" verilog-declaration-simple-re |
| 2843 | (defconst verilog-declaration-re-1-macro | 2897 | "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)\\)")) |
| 2844 | (concat "^" verilog-declaration-re-2-macro)) | 2898 | (defconst verilog-declaration-re-macro |
| 2845 | 2899 | (concat "\\s-*" verilog-declaration-simple-re | |
| 2846 | (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro)) | 2900 | "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)\\|\\(" verilog-macroexp-re "\\)\\)")) |
| 2901 | (defconst verilog-declaration-or-iface-mp-re | ||
| 2902 | (concat "\\(" verilog-declaration-re "\\)\\|\\(" verilog-interface-modport-re "\\)")) | ||
| 2903 | (defconst verilog-declaration-embedded-comments-re | ||
| 2904 | (concat "\\( " verilog-declaration-re "\\) ""\\s-*" "\\(" verilog-comment-start-regexp "\\)") | ||
| 2905 | "Match expressions such as: input logic [7:0] /* auto enum sm_psm */ sm_psm;.") | ||
| 2847 | 2906 | ||
| 2848 | (defconst verilog-defun-re | 2907 | (defconst verilog-defun-re |
| 2849 | (eval-when-compile (verilog-regexp-words '("macromodule" "connectmodule" "module" "class" "program" "interface" "package" "primitive" "config")))) | 2908 | (eval-when-compile (verilog-regexp-words '("macromodule" "connectmodule" "module" "class" "program" "interface" "package" "primitive" "config")))) |
| 2850 | (defconst verilog-end-defun-re | 2909 | (defconst verilog-end-defun-re |
| 2851 | (eval-when-compile (verilog-regexp-words '("endconnectmodule" "endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) | 2910 | (eval-when-compile (verilog-regexp-words '("endconnectmodule" "endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) |
| 2911 | (defconst verilog-defun-tf-re-beg | ||
| 2912 | (eval-when-compile (verilog-regexp-words '("macromodule" "connectmodule" "module" "class" "program" "interface" "package" "primitive" "config" "function" "task")))) | ||
| 2913 | (defconst verilog-defun-tf-re-end | ||
| 2914 | (eval-when-compile (verilog-regexp-words '("endconnectmodule" "endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig" "endfunction" "endtask")))) | ||
| 2915 | (defconst verilog-defun-tf-re-all | ||
| 2916 | (eval-when-compile (verilog-regexp-words '("macromodule" "connectmodule" "module" "class" "program" "interface" "package" "primitive" "config" "function" "task" | ||
| 2917 | "endconnectmodule" "endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig" "endfunction" "endtask")))) | ||
| 2918 | (defconst verilog-defun-no-class-re | ||
| 2919 | (eval-when-compile (verilog-regexp-words '("macromodule" "connectmodule" "module" "program" "interface" "package" "primitive" "config")))) | ||
| 2920 | (defconst verilog-end-defun-no-class-re | ||
| 2921 | (eval-when-compile (verilog-regexp-words '("endconnectmodule" "endmodule" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) | ||
| 2852 | (defconst verilog-zero-indent-re | 2922 | (defconst verilog-zero-indent-re |
| 2853 | (concat verilog-defun-re "\\|" verilog-end-defun-re)) | 2923 | (concat verilog-defun-re "\\|" verilog-end-defun-re)) |
| 2924 | (defconst verilog-zero-indent-no-class-re | ||
| 2925 | (concat verilog-defun-no-class-re "\\|" verilog-end-defun-no-class-re)) | ||
| 2854 | (defconst verilog-inst-comment-re | 2926 | (defconst verilog-inst-comment-re |
| 2855 | (eval-when-compile (verilog-regexp-words '("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced")))) | 2927 | (eval-when-compile (verilog-regexp-words '("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced")))) |
| 2856 | 2928 | ||
| @@ -2983,19 +3055,38 @@ find the errors." | |||
| 2983 | (defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\|randcase\\)") | 3055 | (defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\|randcase\\)") |
| 2984 | (defconst verilog-extended-complete-re | 3056 | (defconst verilog-extended-complete-re |
| 2985 | ;; verilog-beg-of-statement also looks backward one token to extend this match | 3057 | ;; verilog-beg-of-statement also looks backward one token to extend this match |
| 2986 | (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\|\\<static\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)" | 3058 | (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?virtual\\s-+\\|\\<local\\s-+\\|\\<protected\\s-+\\|\\<static\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)" |
| 2987 | "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)" | 3059 | "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)" |
| 2988 | "\\|\\(\\(\\<\\(import\\|export\\)\\>\\s-+\\)?\\(\"DPI\\(-C\\)?\"\\s-+\\)?\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\(function\\>\\|task\\>\\)\\)" | 3060 | "\\|\\(\\(\\<\\(import\\|export\\)\\>\\s-+\\)?\\(\"DPI\\(-C\\)?\"\\s-+\\)?\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\(function\\>\\|task\\>\\)\\)" |
| 2989 | "\\|" verilog-extended-case-re )) | 3061 | "\\|" verilog-extended-case-re )) |
| 3062 | |||
| 3063 | (eval-and-compile | ||
| 3064 | (defconst verilog-basic-complete-words | ||
| 3065 | '("always" "assign" "always_latch" "always_ff" "always_comb" "analog" "connectmodule" "constraint" | ||
| 3066 | "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while" | ||
| 3067 | "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert" "default" "generate")) | ||
| 3068 | (defconst verilog-basic-complete-words-expr | ||
| 3069 | (let ((words verilog-basic-complete-words)) | ||
| 3070 | (dolist (word '("default" "parameter" "localparam")) | ||
| 3071 | (setq words (remove word words))) | ||
| 3072 | words)) | ||
| 3073 | (defconst verilog-basic-complete-words-expr-no-assign | ||
| 3074 | (remove "assign" verilog-basic-complete-words-expr))) | ||
| 3075 | |||
| 2990 | (defconst verilog-basic-complete-re | 3076 | (defconst verilog-basic-complete-re |
| 2991 | (eval-when-compile | 3077 | (eval-when-compile |
| 2992 | (verilog-regexp-words | 3078 | (verilog-regexp-words verilog-basic-complete-words))) |
| 2993 | '( | 3079 | |
| 2994 | "always" "assign" "always_latch" "always_ff" "always_comb" "analog" "connectmodule" "constraint" | 3080 | (defconst verilog-basic-complete-expr-re |
| 2995 | "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while" | 3081 | (eval-when-compile |
| 2996 | "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert" | 3082 | (verilog-regexp-words verilog-basic-complete-words-expr))) |
| 2997 | )))) | 3083 | |
| 2998 | (defconst verilog-complete-reg | 3084 | (defconst verilog-basic-complete-expr-no-assign-re |
| 3085 | (eval-when-compile | ||
| 3086 | (verilog-regexp-words verilog-basic-complete-words-expr-no-assign))) | ||
| 3087 | |||
| 3088 | |||
| 3089 | (defconst verilog-complete-re | ||
| 2999 | (concat | 3090 | (concat |
| 3000 | verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)")) | 3091 | verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)")) |
| 3001 | 3092 | ||
| @@ -3114,9 +3205,6 @@ find the errors." | |||
| 3114 | )) | 3205 | )) |
| 3115 | "List of Verilog keywords.") | 3206 | "List of Verilog keywords.") |
| 3116 | 3207 | ||
| 3117 | (defconst verilog-comment-start-regexp "//\\|/\\*" | ||
| 3118 | "Dual comment value for `comment-start-regexp'.") | ||
| 3119 | |||
| 3120 | (defvar verilog-mode-syntax-table | 3208 | (defvar verilog-mode-syntax-table |
| 3121 | (let ((table (make-syntax-table))) | 3209 | (let ((table (make-syntax-table))) |
| 3122 | ;; Populate the syntax TABLE. | 3210 | ;; Populate the syntax TABLE. |
| @@ -3338,12 +3426,12 @@ See also `verilog-font-lock-extra-types'.") | |||
| 3338 | (list | 3426 | (list |
| 3339 | "\\<\\(\\(macro\\|connect\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)" | 3427 | "\\<\\(\\(macro\\|connect\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)" |
| 3340 | '(1 font-lock-keyword-face) | 3428 | '(1 font-lock-keyword-face) |
| 3341 | '(3 font-lock-function-name-face prepend)) | 3429 | '(3 font-lock-function-name-face)) |
| 3342 | ;; Fontify function definitions | 3430 | ;; Fontify function definitions |
| 3343 | (list | 3431 | (list |
| 3344 | (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" ) | 3432 | (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" ) |
| 3345 | '(1 font-lock-keyword-face) | 3433 | '(1 font-lock-keyword-face) |
| 3346 | '(3 font-lock-constant-face prepend)) | 3434 | '(3 font-lock-constant-face)) |
| 3347 | '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)" | 3435 | '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)" |
| 3348 | (1 font-lock-keyword-face) | 3436 | (1 font-lock-keyword-face) |
| 3349 | (2 font-lock-constant-face append)) | 3437 | (2 font-lock-constant-face append)) |
| @@ -3358,12 +3446,12 @@ See also `verilog-font-lock-extra-types'.") | |||
| 3358 | ;; Pre-form for this anchored matcher: | 3446 | ;; Pre-form for this anchored matcher: |
| 3359 | ;; First, avoid declaration keywords written in comments, | 3447 | ;; First, avoid declaration keywords written in comments, |
| 3360 | ;; which can also trigger this anchor. | 3448 | ;; which can also trigger this anchor. |
| 3361 | '(if (not (verilog-in-comment-p)) | 3449 | '(if (and (not (verilog-in-comment-p)) |
| 3450 | (not (member (thing-at-point 'symbol) verilog-keywords))) | ||
| 3362 | (verilog-single-declaration-end verilog-highlight-max-lookahead) | 3451 | (verilog-single-declaration-end verilog-highlight-max-lookahead) |
| 3363 | (point)) ;; => current declaration statement is of 0 length | 3452 | (point)) ;; => current declaration statement is of 0 length |
| 3364 | nil ;; Post-form: nothing to be done | 3453 | nil ;; Post-form: nothing to be done |
| 3365 | '(0 font-lock-variable-name-face t t))) | 3454 | '(0 font-lock-variable-name-face)))))) |
| 3366 | ))) | ||
| 3367 | 3455 | ||
| 3368 | 3456 | ||
| 3369 | (setq verilog-font-lock-keywords-2 | 3457 | (setq verilog-font-lock-keywords-2 |
| @@ -3617,7 +3705,7 @@ inserted using a single call to `verilog-insert'." | |||
| 3617 | (defun verilog-single-declaration-end (limit) | 3705 | (defun verilog-single-declaration-end (limit) |
| 3618 | "Return pos where current (single) declaration statement ends. | 3706 | "Return pos where current (single) declaration statement ends. |
| 3619 | Also, this function moves POINT forward to the start of a variable name | 3707 | Also, this function moves POINT forward to the start of a variable name |
| 3620 | (skipping the range-part and whitespace). | 3708 | \(skipping the range-part and whitespace). |
| 3621 | Function expected to be called with POINT just after a declaration keyword. | 3709 | Function expected to be called with POINT just after a declaration keyword. |
| 3622 | LIMIT sets the max POINT for searching and moving to. No such limit if LIMIT | 3710 | LIMIT sets the max POINT for searching and moving to. No such limit if LIMIT |
| 3623 | is 0. | 3711 | is 0. |
| @@ -3629,8 +3717,6 @@ Meaning of *single* declaration: | |||
| 3629 | and `output [1:0] y' is the other single declaration. In the 1st single | 3717 | and `output [1:0] y' is the other single declaration. In the 1st single |
| 3630 | declaration, POINT is moved to start of `clk'. And in the 2nd declaration, | 3718 | declaration, POINT is moved to start of `clk'. And in the 2nd declaration, |
| 3631 | POINT is moved to `y'." | 3719 | POINT is moved to `y'." |
| 3632 | |||
| 3633 | |||
| 3634 | (let (maxpoint old-point) | 3720 | (let (maxpoint old-point) |
| 3635 | ;; maxpoint = min(curr-point + limit, buffer-size) | 3721 | ;; maxpoint = min(curr-point + limit, buffer-size) |
| 3636 | (setq maxpoint (if (eq limit 0) | 3722 | (setq maxpoint (if (eq limit 0) |
| @@ -3651,7 +3737,7 @@ POINT is moved to `y'." | |||
| 3651 | (not (eq old-point (point))) | 3737 | (not (eq old-point (point))) |
| 3652 | (not (eq (char-after) ?\; )) | 3738 | (not (eq (char-after) ?\; )) |
| 3653 | (not (eq (char-after) ?\) )) | 3739 | (not (eq (char-after) ?\) )) |
| 3654 | (not (looking-at verilog-declaration-re))) | 3740 | (not (looking-at (verilog-get-declaration-re)))) |
| 3655 | (setq old-point (point)) | 3741 | (setq old-point (point)) |
| 3656 | (ignore-errors | 3742 | (ignore-errors |
| 3657 | (forward-sexp) | 3743 | (forward-sexp) |
| @@ -3669,31 +3755,28 @@ This function moves POINT to the next variable within the same declaration (if | |||
| 3669 | it exists). | 3755 | it exists). |
| 3670 | LIMIT is expected to be the pos at which current single-declaration ends, | 3756 | LIMIT is expected to be the pos at which current single-declaration ends, |
| 3671 | obtained using `verilog-single-declaration-end'." | 3757 | obtained using `verilog-single-declaration-end'." |
| 3672 | 3758 | (when (and verilog-fontify-variables | |
| 3673 | (let (found-var old-point) | 3759 | (not (member (thing-at-point 'symbol) verilog-keywords))) |
| 3674 | 3760 | (let (found-var old-point) | |
| 3675 | ;; Remove starting whitespace | 3761 | ;; Remove starting whitespace |
| 3676 | (verilog-forward-ws&directives limit) | 3762 | (verilog-forward-ws&directives limit) |
| 3677 | 3763 | (when (< (point) limit) ;; no matching if this is violated | |
| 3678 | (when (< (point) limit) ;; no matching if this is violated | 3764 | ;; Find the variable name (match-data is set here) |
| 3679 | 3765 | (setq found-var (re-search-forward verilog-identifier-sym-re limit t)) | |
| 3680 | ;; Find the variable name (match-data is set here) | 3766 | ;; Walk to this variable's delimiter |
| 3681 | (setq found-var (re-search-forward verilog-symbol-re limit t)) | 3767 | (save-match-data |
| 3682 | |||
| 3683 | ;; Walk to this variable's delimiter | ||
| 3684 | (save-match-data | ||
| 3685 | (verilog-forward-ws&directives limit) | ||
| 3686 | (setq old-point nil) | ||
| 3687 | (while (and (< (point) limit) | ||
| 3688 | (not (member (char-after) '(?, ?\) ?\;))) | ||
| 3689 | (not (eq old-point (point)))) | ||
| 3690 | (setq old-point (point)) | ||
| 3691 | (verilog-forward-ws&directives limit) | 3768 | (verilog-forward-ws&directives limit) |
| 3692 | (forward-sexp) | 3769 | (setq old-point nil) |
| 3693 | (verilog-forward-ws&directives limit)) | 3770 | (while (and (< (point) limit) |
| 3694 | ;; Only a comma or semicolon expected at this point | 3771 | (not (member (char-after) '(?, ?\) ?\] ?\} ?\;))) |
| 3695 | (skip-syntax-forward ".")) | 3772 | (not (eq old-point (point)))) |
| 3696 | found-var))) | 3773 | (setq old-point (point)) |
| 3774 | (verilog-forward-ws&directives limit) | ||
| 3775 | (forward-sexp) | ||
| 3776 | (verilog-forward-ws&directives limit)) | ||
| 3777 | ;; Only a comma or semicolon expected at this point | ||
| 3778 | (skip-syntax-forward ".")) | ||
| 3779 | found-var)))) | ||
| 3697 | 3780 | ||
| 3698 | (defun verilog-point-text (&optional pointnum) | 3781 | (defun verilog-point-text (&optional pointnum) |
| 3699 | "Return text describing where POINTNUM or current point is (for errors). | 3782 | "Return text describing where POINTNUM or current point is (for errors). |
| @@ -3728,9 +3811,14 @@ Use filename, if current buffer being edited shorten to just buffer name." | |||
| 3728 | (elsec 1) | 3811 | (elsec 1) |
| 3729 | (found nil) | 3812 | (found nil) |
| 3730 | (st (point))) | 3813 | (st (point))) |
| 3731 | (if (not (looking-at "\\<")) | 3814 | (unless (looking-at "\\<") |
| 3732 | (forward-word-strictly -1)) | 3815 | (forward-word-strictly -1)) |
| 3733 | (cond | 3816 | (cond |
| 3817 | ((save-excursion | ||
| 3818 | (goto-char st) | ||
| 3819 | (member (preceding-char) '(?\) ?\} ?\]))) | ||
| 3820 | (goto-char st) | ||
| 3821 | (backward-sexp 1)) | ||
| 3734 | ((verilog-skip-backward-comment-or-string)) | 3822 | ((verilog-skip-backward-comment-or-string)) |
| 3735 | ((looking-at "\\<else\\>") | 3823 | ((looking-at "\\<else\\>") |
| 3736 | (setq reg (concat | 3824 | (setq reg (concat |
| @@ -3754,7 +3842,17 @@ Use filename, if current buffer being edited shorten to just buffer name." | |||
| 3754 | (setq found 't)))))) | 3842 | (setq found 't)))))) |
| 3755 | ((looking-at verilog-end-block-re) | 3843 | ((looking-at verilog-end-block-re) |
| 3756 | (verilog-leap-to-head)) | 3844 | (verilog-leap-to-head)) |
| 3757 | ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)\\|\\(\\<endconnectmodule\\>\\)") | 3845 | (;; Fallback, when current word does not match `verilog-end-block-re' |
| 3846 | (looking-at (concat | ||
| 3847 | "\\(\\<endmodule\\>\\)\\|" ; 1 | ||
| 3848 | "\\(\\<endprimitive\\>\\)\\|" ; 2 | ||
| 3849 | "\\(\\<endclass\\>\\)\\|" ; 3 | ||
| 3850 | "\\(\\<endprogram\\>\\)\\|" ; 4 | ||
| 3851 | "\\(\\<endinterface\\>\\)\\|" ; 5 | ||
| 3852 | "\\(\\<endpackage\\>\\)\\|" ; 6 | ||
| 3853 | "\\(\\<endconnectmodule\\>\\)\\|" ; 7 | ||
| 3854 | "\\(\\<endchecker\\>\\)\\|" ; 8 | ||
| 3855 | "\\(\\<endconfig\\>\\)")) ; 9 | ||
| 3758 | (cond | 3856 | (cond |
| 3759 | ((match-end 1) | 3857 | ((match-end 1) |
| 3760 | (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move)) | 3858 | (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move)) |
| @@ -3769,7 +3867,11 @@ Use filename, if current buffer being edited shorten to just buffer name." | |||
| 3769 | ((match-end 6) | 3867 | ((match-end 6) |
| 3770 | (verilog-re-search-backward "\\<package\\>" nil 'move)) | 3868 | (verilog-re-search-backward "\\<package\\>" nil 'move)) |
| 3771 | ((match-end 7) | 3869 | ((match-end 7) |
| 3772 | (verilog-re-search-backward "\\<connectmodule\\>" nil 'move)) | 3870 | (verilog-re-search-backward "\\<connectmodule\\>" nil 'move)) |
| 3871 | ((match-end 8) | ||
| 3872 | (verilog-re-search-backward "\\<checker\\>" nil 'move)) | ||
| 3873 | ((match-end 9) | ||
| 3874 | (verilog-re-search-backward "\\<config\\>" nil 'move)) | ||
| 3773 | (t | 3875 | (t |
| 3774 | (goto-char st) | 3876 | (goto-char st) |
| 3775 | (backward-sexp 1)))) | 3877 | (backward-sexp 1)))) |
| @@ -3782,9 +3884,14 @@ Use filename, if current buffer being edited shorten to just buffer name." | |||
| 3782 | (md 2) | 3884 | (md 2) |
| 3783 | (st (point)) | 3885 | (st (point)) |
| 3784 | (nest 'yes)) | 3886 | (nest 'yes)) |
| 3785 | (if (not (looking-at "\\<")) | 3887 | (unless (looking-at "\\<") |
| 3786 | (forward-word-strictly -1)) | 3888 | (forward-word-strictly -1)) |
| 3787 | (cond | 3889 | (cond |
| 3890 | ((save-excursion | ||
| 3891 | (goto-char st) | ||
| 3892 | (member (following-char) '(?\( ?\{ ?\[))) | ||
| 3893 | (goto-char st) | ||
| 3894 | (forward-sexp 1)) | ||
| 3788 | ((verilog-skip-forward-comment-or-string) | 3895 | ((verilog-skip-forward-comment-or-string) |
| 3789 | (verilog-forward-syntactic-ws)) | 3896 | (verilog-forward-syntactic-ws)) |
| 3790 | ((looking-at verilog-beg-block-re-ordered) | 3897 | ((looking-at verilog-beg-block-re-ordered) |
| @@ -3843,22 +3950,31 @@ Use filename, if current buffer being edited shorten to just buffer name." | |||
| 3843 | ;; Search forward for matching endtask | 3950 | ;; Search forward for matching endtask |
| 3844 | (setq reg "\\<endtask\\>" ) | 3951 | (setq reg "\\<endtask\\>" ) |
| 3845 | (setq nest 'no)) | 3952 | (setq nest 'no)) |
| 3846 | ((match-end 12) | 3953 | ((match-end 13) |
| 3847 | ;; Search forward for matching endgenerate | 3954 | ;; Search forward for matching endgenerate |
| 3848 | (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | 3955 | (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) |
| 3849 | ((match-end 13) | 3956 | ((match-end 14) |
| 3850 | ;; Search forward for matching endgroup | 3957 | ;; Search forward for matching endgroup |
| 3851 | (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) | 3958 | (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) |
| 3852 | ((match-end 14) | 3959 | ((match-end 15) |
| 3853 | ;; Search forward for matching endproperty | 3960 | ;; Search forward for matching endproperty |
| 3854 | (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) | 3961 | (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) |
| 3855 | ((match-end 15) | 3962 | ((match-end 16) |
| 3856 | ;; Search forward for matching endsequence | 3963 | ;; Search forward for matching endsequence |
| 3857 | (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ) | 3964 | (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ) |
| 3858 | (setq md 3)) ; 3 to get to endsequence in the reg above | 3965 | (setq md 3)) ; 3 to get to endsequence in the reg above |
| 3859 | ((match-end 17) | 3966 | ((match-end 17) |
| 3860 | ;; Search forward for matching endclocking | 3967 | ;; Search forward for matching endclocking |
| 3861 | (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" ))) | 3968 | (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )) |
| 3969 | ((match-end 20) | ||
| 3970 | ;; Search forward for matching `ifn?def, can be `else `elseif or `endif | ||
| 3971 | (setq reg "\\(\\<`ifn?def\\>\\)\\|\\(\\<`endif\\>\\|\\<`else\\>\\|\\<`elsif\\>\\)" )) | ||
| 3972 | ((match-end 21) | ||
| 3973 | ;; Search forward for matching `else, can be `endif | ||
| 3974 | (setq reg "\\(\\<`else\\>\\|\\<`ifn?def\\>\\)\\|\\(\\<`endif\\>\\)" )) | ||
| 3975 | ((match-end 22) | ||
| 3976 | ;; Search forward for matching `elsif, can be `else or `endif, DONT support `elsif | ||
| 3977 | (setq reg "\\(\\<`elsif\\>\\|\\<`ifn?def\\>\\)\\|\\(\\<`endif\\>\\|\\<`else\\>\\)" ))) | ||
| 3862 | (if (and reg | 3978 | (if (and reg |
| 3863 | (forward-word-strictly 1)) | 3979 | (forward-word-strictly 1)) |
| 3864 | (catch 'skip | 3980 | (catch 'skip |
| @@ -3867,15 +3983,26 @@ Use filename, if current buffer being edited shorten to just buffer name." | |||
| 3867 | here) | 3983 | here) |
| 3868 | (while (verilog-re-search-forward reg nil 'move) | 3984 | (while (verilog-re-search-forward reg nil 'move) |
| 3869 | (cond | 3985 | (cond |
| 3870 | ((match-end md) ; a closer in regular expression, so we are climbing out | 3986 | ((and (or (match-end md) |
| 3987 | (and (member (match-string-no-properties 1) '("`else" "`elsif")) | ||
| 3988 | (= 1 depth))) | ||
| 3989 | (or (and (member (match-string-no-properties 2) '("`else" "`elsif")) | ||
| 3990 | (= 1 depth)) | ||
| 3991 | ;; stop at `else/`elsif which matching ifn?def (or `elsif with same depth) | ||
| 3992 | ;; a closer in regular expression, so we are climbing out | ||
| 3993 | (not (member (match-string-no-properties 2) '("`else" "`elsif"))))) | ||
| 3871 | (setq depth (1- depth)) | 3994 | (setq depth (1- depth)) |
| 3872 | (if (= 0 depth) ; we are out! | 3995 | (if (= 0 depth) ; we are out! |
| 3873 | (throw 'skip 1))) | 3996 | (throw 'skip 1))) |
| 3874 | ((match-end 1) ; an opener in the r-e, so we are in deeper now | 3997 | ((and (match-end 1) ; an opener in the r-e, so we are in deeper now |
| 3998 | (not (member (match-string-no-properties 1) '("`else" "`elsif")))) | ||
| 3875 | (setq here (point)) ; remember where we started | 3999 | (setq here (point)) ; remember where we started |
| 3876 | (goto-char (match-beginning 1)) | 4000 | (goto-char (match-beginning 1)) |
| 3877 | (cond | 4001 | (cond |
| 3878 | ((if (or | 4002 | ((verilog-looking-back "\\(\\<typedef\\>\\s-+\\)" (point-at-bol)) |
| 4003 | ;; avoid nesting for typedef class defs | ||
| 4004 | (forward-word-strictly 1)) | ||
| 4005 | ((if (or | ||
| 3879 | (looking-at verilog-disable-fork-re) | 4006 | (looking-at verilog-disable-fork-re) |
| 3880 | (and (looking-at "fork") | 4007 | (and (looking-at "fork") |
| 3881 | (progn | 4008 | (progn |
| @@ -3890,28 +4017,37 @@ Use filename, if current buffer being edited shorten to just buffer name." | |||
| 3890 | (throw 'skip 1)))))) | 4017 | (throw 'skip 1)))))) |
| 3891 | 4018 | ||
| 3892 | ((looking-at (concat | 4019 | ((looking-at (concat |
| 3893 | "\\(\\<\\(macro\\)?module\\>\\)\\|" | 4020 | "\\(\\<\\(macro\\)?module\\>\\)\\|" ; 1,2 |
| 3894 | "\\(\\<primitive\\>\\)\\|" | 4021 | "\\(\\<primitive\\>\\)\\|" ; 3 |
| 3895 | "\\(\\<class\\>\\)\\|" | 4022 | "\\(\\(\\(interface\\|virtual\\)\\s-+\\)?\\<class\\>\\)\\|" ; 4,5,6 |
| 3896 | "\\(\\<program\\>\\)\\|" | 4023 | "\\(\\<program\\>\\)\\|" ; 7 |
| 3897 | "\\(\\<interface\\>\\)\\|" | 4024 | "\\(\\<interface\\>\\)\\|" ; 8 |
| 3898 | "\\(\\<package\\>\\)\\|" | 4025 | "\\(\\<package\\>\\)\\|" ; 9 |
| 3899 | "\\(\\<connectmodule\\>\\)")) | 4026 | "\\(\\<connectmodule\\>\\)\\|" ; 10 |
| 4027 | "\\(\\<generate\\>\\)\\|" ; 11 | ||
| 4028 | "\\(\\<checker\\>\\)\\|" ; 12 | ||
| 4029 | "\\(\\<config\\>\\)")) ; 13 | ||
| 3900 | (cond | 4030 | (cond |
| 3901 | ((match-end 1) | 4031 | ((match-end 1) |
| 3902 | (verilog-re-search-forward "\\<endmodule\\>" nil 'move)) | 4032 | (verilog-re-search-forward "\\<endmodule\\>" nil 'move)) |
| 3903 | ((match-end 2) | ||
| 3904 | (verilog-re-search-forward "\\<endprimitive\\>" nil 'move)) | ||
| 3905 | ((match-end 3) | 4033 | ((match-end 3) |
| 3906 | (verilog-re-search-forward "\\<endclass\\>" nil 'move)) | 4034 | (verilog-re-search-forward "\\<endprimitive\\>" nil 'move)) |
| 3907 | ((match-end 4) | 4035 | ((match-end 4) |
| 4036 | (verilog-re-search-forward "\\<endclass\\>" nil 'move)) | ||
| 4037 | ((match-end 7) | ||
| 3908 | (verilog-re-search-forward "\\<endprogram\\>" nil 'move)) | 4038 | (verilog-re-search-forward "\\<endprogram\\>" nil 'move)) |
| 3909 | ((match-end 5) | 4039 | ((match-end 8) |
| 3910 | (verilog-re-search-forward "\\<endinterface\\>" nil 'move)) | 4040 | (verilog-re-search-forward "\\<endinterface\\>" nil 'move)) |
| 3911 | ((match-end 6) | 4041 | ((match-end 9) |
| 3912 | (verilog-re-search-forward "\\<endpackage\\>" nil 'move)) | 4042 | (verilog-re-search-forward "\\<endpackage\\>" nil 'move)) |
| 3913 | ((match-end 7) | 4043 | ((match-end 10) |
| 3914 | (verilog-re-search-forward "\\<endconnectmodule\\>" nil 'move)) | 4044 | (verilog-re-search-forward "\\<endconnectmodule\\>" nil 'move)) |
| 4045 | ((match-end 11) | ||
| 4046 | (verilog-re-search-forward "\\<endgenerate\\>" nil 'move)) | ||
| 4047 | ((match-end 12) | ||
| 4048 | (verilog-re-search-forward "\\<endchecker\\>" nil 'move)) | ||
| 4049 | ((match-end 13) | ||
| 4050 | (verilog-re-search-forward "\\<endconfig\\>" nil 'move)) | ||
| 3915 | (t | 4051 | (t |
| 3916 | (goto-char st) | 4052 | (goto-char st) |
| 3917 | (if (= (following-char) ?\) ) | 4053 | (if (= (following-char) ?\) ) |
| @@ -3924,11 +4060,69 @@ Use filename, if current buffer being edited shorten to just buffer name." | |||
| 3924 | (forward-sexp 1)))))) | 4060 | (forward-sexp 1)))))) |
| 3925 | 4061 | ||
| 3926 | (defun verilog-declaration-beg () | 4062 | (defun verilog-declaration-beg () |
| 3927 | (verilog-re-search-backward verilog-declaration-re (bobp) t)) | 4063 | (verilog-re-search-backward (verilog-get-declaration-re) (bobp) t)) |
| 3928 | 4064 | ||
| 3929 | ;; | 4065 | (defun verilog-align-typedef-enabled-p () |
| 3930 | ;; | 4066 | "Return non-nil if alignment of user typedefs is enabled. |
| 3931 | ;; Mode | 4067 | This will be automatically set when either `verilog-align-typedef-regexp' |
| 4068 | or `verilog-align-typedef-words' are non-nil." | ||
| 4069 | (when (or verilog-align-typedef-regexp | ||
| 4070 | verilog-align-typedef-words) | ||
| 4071 | t)) | ||
| 4072 | |||
| 4073 | (defun verilog-get-declaration-typedef-re () | ||
| 4074 | "Return regexp of a user defined typedef. | ||
| 4075 | See `verilog-align-typedef-regexp' and `verilog-align-typedef-words'." | ||
| 4076 | (let (typedef-re words words-re re) | ||
| 4077 | (when (verilog-align-typedef-enabled-p) | ||
| 4078 | (setq typedef-re verilog-align-typedef-regexp) | ||
| 4079 | (setq words verilog-align-typedef-words) | ||
| 4080 | (setq words-re (verilog-regexp-words verilog-align-typedef-words)) | ||
| 4081 | (cond ((and typedef-re (not words)) | ||
| 4082 | (setq re typedef-re)) | ||
| 4083 | ((and (not typedef-re) words) | ||
| 4084 | (setq re words-re)) | ||
| 4085 | ((and typedef-re words) | ||
| 4086 | (setq re (concat verilog-align-typedef-regexp "\\|" words-re)))) | ||
| 4087 | (concat "\\s-*" "\\(" verilog-declaration-prefix-re "\\s-*\\(" verilog-range-re "\\)?" "\\s-*\\)?" | ||
| 4088 | (concat "\\(" re "\\)") | ||
| 4089 | "\\(\\s-*" verilog-range-re "\\)?\\s-+")))) | ||
| 4090 | |||
| 4091 | (defun verilog-get-declaration-re (&optional type) | ||
| 4092 | "Return declaration regexp depending on customizable variables and TYPE." | ||
| 4093 | (let ((re (cond ((equal type 'iface-mp) | ||
| 4094 | verilog-declaration-or-iface-mp-re) | ||
| 4095 | ((equal type 'embedded-comments) | ||
| 4096 | verilog-declaration-embedded-comments-re) | ||
| 4097 | (verilog-indent-declaration-macros | ||
| 4098 | verilog-declaration-re-macro) | ||
| 4099 | (t | ||
| 4100 | verilog-declaration-re)))) | ||
| 4101 | (when (and (verilog-align-typedef-enabled-p) | ||
| 4102 | (or (string= re verilog-declaration-or-iface-mp-re) | ||
| 4103 | (string= re verilog-declaration-re))) | ||
| 4104 | (setq re (concat "\\(" (verilog-get-declaration-typedef-re) "\\)\\|\\(" re "\\)"))) | ||
| 4105 | re)) | ||
| 4106 | |||
| 4107 | (defun verilog-looking-at-decl-to-align () | ||
| 4108 | "Return non-nil if pointing at a Verilog variable declaration that must be aligned." | ||
| 4109 | (let* ((re (verilog-get-declaration-re)) | ||
| 4110 | (valid-re (looking-at re)) | ||
| 4111 | (id-pos (match-end 0))) | ||
| 4112 | (and valid-re | ||
| 4113 | (not (verilog-at-struct-decl-p)) | ||
| 4114 | (not (verilog-at-enum-decl-p)) | ||
| 4115 | (save-excursion | ||
| 4116 | (goto-char id-pos) | ||
| 4117 | (verilog-forward-syntactic-ws) | ||
| 4118 | (and (not (looking-at ";")) | ||
| 4119 | (not (member (thing-at-point 'symbol) verilog-keywords)) | ||
| 4120 | (progn ; Avoid alignment of instances whose name match user defined types | ||
| 4121 | (forward-word) | ||
| 4122 | (verilog-forward-syntactic-ws) | ||
| 4123 | (not (looking-at "(")))))))) | ||
| 4124 | |||
| 4125 | ;;; Mode: | ||
| 3932 | ;; | 4126 | ;; |
| 3933 | (defvar verilog-which-tool 1) | 4127 | (defvar verilog-which-tool 1) |
| 3934 | ;;;###autoload | 4128 | ;;;###autoload |
| @@ -3965,6 +4159,10 @@ Variables controlling indentation/edit style: | |||
| 3965 | function keyword. | 4159 | function keyword. |
| 3966 | `verilog-indent-level-directive' (default 1) | 4160 | `verilog-indent-level-directive' (default 1) |
| 3967 | Indentation of \\=`ifdef/\\=`endif blocks. | 4161 | Indentation of \\=`ifdef/\\=`endif blocks. |
| 4162 | `verilog-indent-ignore-multiline-defines' (default t) | ||
| 4163 | Non-nil means ignore indentation on lines that are part of a multiline define. | ||
| 4164 | `verilog-indent-ignore-regexp' (default nil | ||
| 4165 | Regexp that matches lines that should be ignored for indentation. | ||
| 3968 | `verilog-cexp-indent' (default 1) | 4166 | `verilog-cexp-indent' (default 1) |
| 3969 | Indentation of Verilog statements broken across lines i.e.: | 4167 | Indentation of Verilog statements broken across lines i.e.: |
| 3970 | if (a) | 4168 | if (a) |
| @@ -3988,6 +4186,9 @@ Variables controlling indentation/edit style: | |||
| 3988 | otherwise you get: | 4186 | otherwise you get: |
| 3989 | if (a) | 4187 | if (a) |
| 3990 | begin | 4188 | begin |
| 4189 | `verilog-indent-class-inside-pkg' (default t) | ||
| 4190 | Non-nil means indent classes inside packages. | ||
| 4191 | Otherwise, classes have zero indentation. | ||
| 3991 | `verilog-auto-endcomments' (default t) | 4192 | `verilog-auto-endcomments' (default t) |
| 3992 | Non-nil means a comment /* ... */ is set after the ends which ends | 4193 | Non-nil means a comment /* ... */ is set after the ends which ends |
| 3993 | cases, tasks, functions and modules. | 4194 | cases, tasks, functions and modules. |
| @@ -3997,6 +4198,17 @@ Variables controlling indentation/edit style: | |||
| 3997 | will be inserted. Setting this variable to zero results in every | 4198 | will be inserted. Setting this variable to zero results in every |
| 3998 | end acquiring a comment; the default avoids too many redundant | 4199 | end acquiring a comment; the default avoids too many redundant |
| 3999 | comments in tight quarters. | 4200 | comments in tight quarters. |
| 4201 | `verilog-align-decl-expr-comments' (default t) | ||
| 4202 | Non-nil means align declaration and expressions comments. | ||
| 4203 | `verilog-align-comment-distance' (default 1) | ||
| 4204 | Distance (in spaces) between longest declaration and comments. | ||
| 4205 | Only works if `verilog-align-decl-expr-comments' is non-nil. | ||
| 4206 | `verilog-align-assign-expr' (default nil) | ||
| 4207 | Non-nil means align expressions of continuous assignments. | ||
| 4208 | `verilog-align-typedef-regexp' (default nil) | ||
| 4209 | Regexp that matches user typedefs for declaration alignment. | ||
| 4210 | `verilog-align-typedef-words' (default nil) | ||
| 4211 | List of words that match user typedefs for declaration alignment. | ||
| 4000 | `verilog-auto-lineup' (default `declarations') | 4212 | `verilog-auto-lineup' (default `declarations') |
| 4001 | List of contexts where auto lineup of code should be done. | 4213 | List of contexts where auto lineup of code should be done. |
| 4002 | 4214 | ||
| @@ -4147,7 +4359,7 @@ Key bindings specific to `verilog-mode-map' are: | |||
| 4147 | ;; verilog-mode-hook call added by define-derived-mode | 4359 | ;; verilog-mode-hook call added by define-derived-mode |
| 4148 | ) | 4360 | ) |
| 4149 | 4361 | ||
| 4150 | ;;; Integration with the speedbar | 4362 | ;;; Integration with the speedbar: |
| 4151 | ;; | 4363 | ;; |
| 4152 | 4364 | ||
| 4153 | ;; Avoid problems with XEmacs byte-compiles. | 4365 | ;; Avoid problems with XEmacs byte-compiles. |
| @@ -4427,15 +4639,24 @@ following code fragment: | |||
| 4427 | "Mark the current Verilog function (or procedure). | 4639 | "Mark the current Verilog function (or procedure). |
| 4428 | This puts the mark at the end, and point at the beginning." | 4640 | This puts the mark at the end, and point at the beginning." |
| 4429 | (interactive) | 4641 | (interactive) |
| 4430 | (if (featurep 'xemacs) | 4642 | (let (found) |
| 4431 | (progn | 4643 | (if (featurep 'xemacs) |
| 4432 | (push-mark) | 4644 | (progn |
| 4433 | (verilog-end-of-defun) | 4645 | (push-mark) |
| 4434 | (push-mark) | 4646 | (verilog-end-of-defun) |
| 4435 | (verilog-beg-of-defun) | 4647 | (push-mark) |
| 4436 | (if (fboundp 'zmacs-activate-region) | 4648 | (verilog-beg-of-defun) |
| 4437 | (zmacs-activate-region))) | 4649 | (if (fboundp 'zmacs-activate-region) |
| 4438 | (mark-defun))) | 4650 | (zmacs-activate-region))) |
| 4651 | ;; GNU Emacs | ||
| 4652 | (when (verilog-beg-of-defun) | ||
| 4653 | (setq found (point)) | ||
| 4654 | (verilog-end-of-defun) | ||
| 4655 | (end-of-line) | ||
| 4656 | (push-mark) | ||
| 4657 | (goto-char found) | ||
| 4658 | (beginning-of-line) | ||
| 4659 | (setq mark-active t))))) | ||
| 4439 | 4660 | ||
| 4440 | (defun verilog-comment-region (start end) | 4661 | (defun verilog-comment-region (start end) |
| 4441 | ;; checkdoc-params: (start end) | 4662 | ;; checkdoc-params: (start end) |
| @@ -4514,7 +4735,21 @@ area. See also `verilog-comment-region'." | |||
| 4514 | (defun verilog-beg-of-defun () | 4735 | (defun verilog-beg-of-defun () |
| 4515 | "Move backward to the beginning of the current function or procedure." | 4736 | "Move backward to the beginning of the current function or procedure." |
| 4516 | (interactive) | 4737 | (interactive) |
| 4517 | (verilog-re-search-backward verilog-defun-re nil 'move)) | 4738 | (let (found) |
| 4739 | (save-excursion | ||
| 4740 | (when (verilog-looking-back verilog-defun-tf-re-end (point-at-bol)) | ||
| 4741 | (verilog-backward-sexp) | ||
| 4742 | (setq found (point))) | ||
| 4743 | (while (and (not found) | ||
| 4744 | (verilog-re-search-backward verilog-defun-tf-re-all nil t)) | ||
| 4745 | (cond ((verilog-looking-back "\\(\\<typedef\\>\\s-+\\)" (point-at-bol)) ; corner case, e.g. 'typedef class <id>;' | ||
| 4746 | (backward-word)) | ||
| 4747 | ((looking-at verilog-defun-tf-re-end) | ||
| 4748 | (verilog-backward-sexp)) | ||
| 4749 | ((looking-at verilog-defun-tf-re-beg) | ||
| 4750 | (setq found (point)))))) | ||
| 4751 | (when found | ||
| 4752 | (goto-char found)))) | ||
| 4518 | 4753 | ||
| 4519 | (defun verilog-beg-of-defun-quick () | 4754 | (defun verilog-beg-of-defun-quick () |
| 4520 | "Move backward to the beginning of the current function or procedure. | 4755 | "Move backward to the beginning of the current function or procedure. |
| @@ -4525,7 +4760,10 @@ Uses `verilog-scan' cache." | |||
| 4525 | (defun verilog-end-of-defun () | 4760 | (defun verilog-end-of-defun () |
| 4526 | "Move forward to the end of the current function or procedure." | 4761 | "Move forward to the end of the current function or procedure." |
| 4527 | (interactive) | 4762 | (interactive) |
| 4528 | (verilog-re-search-forward verilog-end-defun-re nil 'move)) | 4763 | (when (or (looking-at verilog-defun-tf-re-beg) |
| 4764 | (verilog-beg-of-defun)) | ||
| 4765 | (verilog-forward-sexp) | ||
| 4766 | (point))) | ||
| 4529 | 4767 | ||
| 4530 | (defun verilog-get-end-of-defun () | 4768 | (defun verilog-get-end-of-defun () |
| 4531 | (save-excursion | 4769 | (save-excursion |
| @@ -4542,10 +4780,10 @@ Uses `verilog-scan' cache." | |||
| 4542 | (case-fold-search nil) | 4780 | (case-fold-search nil) |
| 4543 | (oldpos (point)) | 4781 | (oldpos (point)) |
| 4544 | (b (progn | 4782 | (b (progn |
| 4545 | (verilog-beg-of-defun) | 4783 | (verilog-re-search-backward verilog-defun-re nil 'move) |
| 4546 | (point-marker))) | 4784 | (point-marker))) |
| 4547 | (e (progn | 4785 | (e (progn |
| 4548 | (verilog-end-of-defun) | 4786 | (verilog-re-search-forward verilog-end-defun-re nil 'move) |
| 4549 | (point-marker)))) | 4787 | (point-marker)))) |
| 4550 | (goto-char (marker-position b)) | 4788 | (goto-char (marker-position b)) |
| 4551 | (if (> (- e b) 200) | 4789 | (if (> (- e b) 200) |
| @@ -4605,19 +4843,18 @@ Uses `verilog-scan' cache." | |||
| 4605 | (goto-char h))) | 4843 | (goto-char h))) |
| 4606 | ;; stop if we see an extended complete reg, perhaps a complete one | 4844 | ;; stop if we see an extended complete reg, perhaps a complete one |
| 4607 | (and | 4845 | (and |
| 4608 | (looking-at verilog-complete-reg) | 4846 | (looking-at verilog-complete-re) |
| 4609 | (let* ((p (point))) | 4847 | (let* ((p (point))) |
| 4610 | (while (and (looking-at verilog-extended-complete-re) | 4848 | (while (and (looking-at verilog-extended-complete-re) |
| 4611 | (progn (setq p (point)) | 4849 | (progn (setq p (point)) |
| 4612 | (verilog-backward-token) | 4850 | (verilog-backward-token) |
| 4613 | (/= p (point))))) | 4851 | (/= p (point))))) |
| 4614 | (goto-char p))) | 4852 | (goto-char p))) |
| 4615 | ;; stop if we see a complete reg (previous found extended ones) | ||
| 4616 | (looking-at verilog-basic-complete-re) | ||
| 4617 | ;; stop if previous token is an ender | 4853 | ;; stop if previous token is an ender |
| 4618 | (save-excursion | 4854 | (save-excursion |
| 4619 | (verilog-backward-token) | 4855 | (verilog-backward-token) |
| 4620 | (looking-at verilog-end-block-re)))) | 4856 | (or (looking-at verilog-end-block-re) |
| 4857 | (verilog-in-directive-p))))) | ||
| 4621 | (verilog-backward-syntactic-ws) | 4858 | (verilog-backward-syntactic-ws) |
| 4622 | (verilog-backward-token)) | 4859 | (verilog-backward-token)) |
| 4623 | ;; Now point is where the previous line ended. | 4860 | ;; Now point is where the previous line ended. |
| @@ -4634,28 +4871,23 @@ Uses `verilog-scan' cache." | |||
| 4634 | (verilog-backward-syntactic-ws)) | 4871 | (verilog-backward-syntactic-ws)) |
| 4635 | (let ((pt (point))) | 4872 | (let ((pt (point))) |
| 4636 | (catch 'done | 4873 | (catch 'done |
| 4637 | (while (not (looking-at verilog-complete-reg)) | 4874 | (while (not (looking-at verilog-complete-re)) |
| 4638 | (setq pt (point)) | 4875 | (setq pt (point)) |
| 4639 | (verilog-backward-syntactic-ws) | 4876 | (verilog-backward-syntactic-ws) |
| 4640 | (if (or (bolp) | 4877 | (if (or (bolp) |
| 4641 | (= (preceding-char) ?\;) | 4878 | (= (preceding-char) ?\;) |
| 4879 | (and (= (preceding-char) ?\{) | ||
| 4880 | (save-excursion | ||
| 4881 | (backward-char) | ||
| 4882 | (verilog-at-struct-p))) | ||
| 4642 | (progn | 4883 | (progn |
| 4643 | (verilog-backward-token) | 4884 | (verilog-backward-token) |
| 4644 | (looking-at verilog-ends-re))) | 4885 | (or (looking-at verilog-ends-re) |
| 4886 | (looking-at "begin")))) | ||
| 4645 | (progn | 4887 | (progn |
| 4646 | (goto-char pt) | 4888 | (goto-char pt) |
| 4647 | (throw 'done t))))) | 4889 | (throw 'done t))))) |
| 4648 | (verilog-forward-syntactic-ws))) | 4890 | (verilog-forward-syntactic-ws))) |
| 4649 | ;; | ||
| 4650 | ;; (while (and | ||
| 4651 | ;; (not (looking-at verilog-complete-reg)) | ||
| 4652 | ;; (not (bolp)) | ||
| 4653 | ;; (not (= (preceding-char) ?\;))) | ||
| 4654 | ;; (verilog-backward-token) | ||
| 4655 | ;; (verilog-backward-syntactic-ws) | ||
| 4656 | ;; (setq pt (point))) | ||
| 4657 | ;; (goto-char pt) | ||
| 4658 | ;; ;(verilog-forward-syntactic-ws) | ||
| 4659 | 4891 | ||
| 4660 | (defun verilog-end-of-statement () | 4892 | (defun verilog-end-of-statement () |
| 4661 | "Move forward to end of current statement." | 4893 | "Move forward to end of current statement." |
| @@ -4713,7 +4945,7 @@ Uses `verilog-scan' cache." | |||
| 4713 | pos))))) | 4945 | pos))))) |
| 4714 | 4946 | ||
| 4715 | (defun verilog-in-case-region-p () | 4947 | (defun verilog-in-case-region-p () |
| 4716 | "Return true if in a case region. | 4948 | "Return non-nil if in a case region. |
| 4717 | More specifically, point @ in the line foo : @ begin" | 4949 | More specifically, point @ in the line foo : @ begin" |
| 4718 | (interactive) | 4950 | (interactive) |
| 4719 | (save-excursion | 4951 | (save-excursion |
| @@ -4758,37 +4990,29 @@ More specifically, point @ in the line foo : @ begin" | |||
| 4758 | (forward-sexp arg))) | 4990 | (forward-sexp arg))) |
| 4759 | 4991 | ||
| 4760 | (defun verilog-in-generate-region-p () | 4992 | (defun verilog-in-generate-region-p () |
| 4761 | "Return true if in a generate region. | 4993 | "Return non-nil if in a generate region. |
| 4762 | More specifically, after a generate and before an endgenerate." | 4994 | More specifically, after a generate and before an endgenerate." |
| 4763 | (interactive) | 4995 | (interactive) |
| 4764 | (let ((nest 1)) | 4996 | (let ((pos (point)) |
| 4765 | (save-excursion | 4997 | gen-beg-point gen-end-point) |
| 4766 | (catch 'done | 4998 | (save-match-data |
| 4767 | (while (and | 4999 | (save-excursion |
| 4768 | (/= nest 0) | 5000 | (and (verilog-re-search-backward "\\<\\(generate\\)\\>" nil t) |
| 4769 | (verilog-re-search-backward | 5001 | (forward-word) |
| 4770 | "\\<\\(module\\)\\|\\(connectmodule\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\|\\(if\\)\\|\\(case\\)\\|\\(for\\)\\>" nil 'move) | 5002 | (setq gen-beg-point (point)) |
| 4771 | (cond | 5003 | (verilog-forward-sexp) |
| 4772 | ((match-end 1) ; module - we have crawled out | 5004 | (backward-word) |
| 4773 | (throw 'done 1)) | 5005 | (setq gen-end-point (point))))) |
| 4774 | ((match-end 2) ; connectmodule - we have crawled out | 5006 | (if (and gen-beg-point gen-end-point |
| 4775 | (throw 'done 1)) | 5007 | (>= pos gen-beg-point) |
| 4776 | ((match-end 3) ; generate | 5008 | (<= pos gen-end-point)) |
| 4777 | (setq nest (1- nest))) | 5009 | t |
| 4778 | ((match-end 4) ; endgenerate | 5010 | nil))) |
| 4779 | (setq nest (1+ nest))) | ||
| 4780 | ((match-end 5) ; if | ||
| 4781 | (setq nest (1- nest))) | ||
| 4782 | ((match-end 6) ; case | ||
| 4783 | (setq nest (1- nest))) | ||
| 4784 | ((match-end 7) ; for | ||
| 4785 | (setq nest (1- nest)))))))) | ||
| 4786 | (= nest 0) )) ; return nest | ||
| 4787 | 5011 | ||
| 4788 | (defun verilog-in-fork-region-p () | 5012 | (defun verilog-in-fork-region-p () |
| 4789 | "Return true if between a fork and join." | 5013 | "Return non-nil if between a fork and join." |
| 4790 | (interactive) | 5014 | (interactive) |
| 4791 | (let ((lim (save-excursion (verilog-beg-of-defun) (point))) | 5015 | (let ((lim (save-excursion (verilog-re-search-backward verilog-defun-re nil 'move) (point))) |
| 4792 | (nest 1)) | 5016 | (nest 1)) |
| 4793 | (save-excursion | 5017 | (save-excursion |
| 4794 | (while (and | 5018 | (while (and |
| @@ -4802,7 +5026,7 @@ More specifically, after a generate and before an endgenerate." | |||
| 4802 | (= nest 0) )) ; return nest | 5026 | (= nest 0) )) ; return nest |
| 4803 | 5027 | ||
| 4804 | (defun verilog-in-deferred-immediate-final-p () | 5028 | (defun verilog-in-deferred-immediate-final-p () |
| 4805 | "Return true if inside an `assert/assume/cover final' statement." | 5029 | "Return non-nil if inside an `assert/assume/cover final' statement." |
| 4806 | (interactive) | 5030 | (interactive) |
| 4807 | (and (looking-at "final") | 5031 | (and (looking-at "final") |
| 4808 | (verilog-looking-back "\\<\\(?:assert\\|assume\\|cover\\)\\>\\s-+" nil)) | 5032 | (verilog-looking-back "\\<\\(?:assert\\|assume\\|cover\\)\\>\\s-+" nil)) |
| @@ -5013,7 +5237,7 @@ primitive or interface named NAME." | |||
| 5013 | (insert str) | 5237 | (insert str) |
| 5014 | (ding 't)) | 5238 | (ding 't)) |
| 5015 | (let ((lim | 5239 | (let ((lim |
| 5016 | (save-excursion (verilog-beg-of-defun) (point))) | 5240 | (save-excursion (verilog-re-search-backward verilog-defun-re nil 'move) (point))) |
| 5017 | (here (point))) | 5241 | (here (point))) |
| 5018 | (cond | 5242 | (cond |
| 5019 | (;-- handle named block differently | 5243 | (;-- handle named block differently |
| @@ -5461,7 +5685,7 @@ For example: | |||
| 5461 | becomes: | 5685 | becomes: |
| 5462 | // surefire lint_line_off UDDONX" | 5686 | // surefire lint_line_off UDDONX" |
| 5463 | (interactive) | 5687 | (interactive) |
| 5464 | (let ((buff (if (boundp 'next-error-last-buffer) ;Added to Emacs-22.1 | 5688 | (let ((buff (if (boundp 'next-error-last-buffer) ; Added to Emacs-22.1 |
| 5465 | next-error-last-buffer | 5689 | next-error-last-buffer |
| 5466 | (verilog--suppressed-warnings | 5690 | (verilog--suppressed-warnings |
| 5467 | ((obsolete compilation-last-buffer)) | 5691 | ((obsolete compilation-last-buffer)) |
| @@ -5585,13 +5809,14 @@ FILENAME to find directory to run in, or defaults to `buffer-file-name'." | |||
| 5585 | (defun verilog-warn-error (string &rest args) | 5809 | (defun verilog-warn-error (string &rest args) |
| 5586 | "Call `error' using STRING and optional ARGS. | 5810 | "Call `error' using STRING and optional ARGS. |
| 5587 | If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead." | 5811 | If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead." |
| 5588 | (apply (if verilog-warn-fatal #'error #'verilog-warn) | 5812 | (apply (if (and verilog-warn-fatal verilog-warn-fatal-internal) |
| 5813 | #'error #'verilog-warn) | ||
| 5589 | string args)) | 5814 | string args)) |
| 5590 | 5815 | ||
| 5591 | (defmacro verilog-batch-error-wrapper (&rest body) | 5816 | (defmacro verilog-batch-error-wrapper (&rest body) |
| 5592 | "Execute BODY and add error prefix to any errors found. | 5817 | "Execute BODY and add error prefix to any errors found. |
| 5593 | This lets programs calling batch mode to easily extract error messages." | 5818 | This lets programs calling batch mode to easily extract error messages." |
| 5594 | `(let ((verilog-warn-fatal nil)) | 5819 | `(let ((verilog-warn-fatal-internal nil)) |
| 5595 | (condition-case err | 5820 | (condition-case err |
| 5596 | (progn ,@body) | 5821 | (progn ,@body) |
| 5597 | (error | 5822 | (error |
| @@ -5721,7 +5946,7 @@ This sets up the appropriate Verilog mode environment, calls | |||
| 5721 | (string . 0))) | 5946 | (string . 0))) |
| 5722 | 5947 | ||
| 5723 | (defun verilog-continued-line-1 (lim) | 5948 | (defun verilog-continued-line-1 (lim) |
| 5724 | "Return true if this is a continued line. | 5949 | "Return non-nil if this is a continued line. |
| 5725 | Set point to where line starts. Limit search to point LIM." | 5950 | Set point to where line starts. Limit search to point LIM." |
| 5726 | (let ((continued 't)) | 5951 | (let ((continued 't)) |
| 5727 | (if (eq 0 (forward-line -1)) | 5952 | (if (eq 0 (forward-line -1)) |
| @@ -5774,7 +5999,6 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)." | |||
| 5774 | ;; if we are in a parenthesized list, and the user likes to indent these, return. | 5999 | ;; if we are in a parenthesized list, and the user likes to indent these, return. |
| 5775 | ;; unless we are in the newfangled coverpoint or constraint blocks | 6000 | ;; unless we are in the newfangled coverpoint or constraint blocks |
| 5776 | (if (and | 6001 | (if (and |
| 5777 | verilog-indent-lists | ||
| 5778 | (verilog-in-paren) | 6002 | (verilog-in-paren) |
| 5779 | (not (verilog-in-coverage-p)) | 6003 | (not (verilog-in-coverage-p)) |
| 5780 | ) | 6004 | ) |
| @@ -5791,7 +6015,7 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)." | |||
| 5791 | (looking-at verilog-in-constraint-re) )) ; may still get hosed if concat in constraint | 6015 | (looking-at verilog-in-constraint-re) )) ; may still get hosed if concat in constraint |
| 5792 | (let ((sp (point))) | 6016 | (let ((sp (point))) |
| 5793 | (if (and | 6017 | (if (and |
| 5794 | (not (looking-at verilog-complete-reg)) | 6018 | (not (looking-at verilog-complete-re)) |
| 5795 | (verilog-continued-line-1 lim)) | 6019 | (verilog-continued-line-1 lim)) |
| 5796 | (progn (goto-char sp) | 6020 | (progn (goto-char sp) |
| 5797 | (throw 'nesting 'cexp)) | 6021 | (throw 'nesting 'cexp)) |
| @@ -5996,6 +6220,12 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)." | |||
| 5996 | (goto-char here) ; or is clocking, starts a new block | 6220 | (goto-char here) ; or is clocking, starts a new block |
| 5997 | (throw 'nesting 'block))))) | 6221 | (throw 'nesting 'block))))) |
| 5998 | 6222 | ||
| 6223 | ;; if find `ifn?def `else `elsif | ||
| 6224 | ((or (match-end 20) | ||
| 6225 | (match-end 21) | ||
| 6226 | (match-end 22)) | ||
| 6227 | (throw 'continue 'foo)) | ||
| 6228 | |||
| 5999 | ((looking-at "\\<class\\|struct\\|function\\|task\\>") | 6229 | ((looking-at "\\<class\\|struct\\|function\\|task\\>") |
| 6000 | ;; *sigh* These words have an optional prefix: | 6230 | ;; *sigh* These words have an optional prefix: |
| 6001 | ;; extern {virtual|protected}? function a(); | 6231 | ;; extern {virtual|protected}? function a(); |
| @@ -6025,7 +6255,7 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)." | |||
| 6025 | ;; {assert|assume|cover} property (); are complete | 6255 | ;; {assert|assume|cover} property (); are complete |
| 6026 | ;; and could also be labeled: - foo: assert property | 6256 | ;; and could also be labeled: - foo: assert property |
| 6027 | ;; but | 6257 | ;; but |
| 6028 | ;; property ID () ... needs end_property | 6258 | ;; property ID () ... needs endproperty |
| 6029 | (verilog-beg-of-statement) | 6259 | (verilog-beg-of-statement) |
| 6030 | (if (looking-at verilog-property-re) | 6260 | (if (looking-at verilog-property-re) |
| 6031 | (throw 'continue 'statement) ; We don't need an endproperty for these | 6261 | (throw 'continue 'statement) ; We don't need an endproperty for these |
| @@ -6110,6 +6340,23 @@ of the appropriate enclosing block." | |||
| 6110 | (ding 't) | 6340 | (ding 't) |
| 6111 | (setq nest 0)))))) | 6341 | (setq nest 0)))))) |
| 6112 | 6342 | ||
| 6343 | (defun verilog-leap-to-class-head () | ||
| 6344 | (let ((nest 1) | ||
| 6345 | (class-re (concat "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"))) | ||
| 6346 | (catch 'skip | ||
| 6347 | (while (verilog-re-search-backward class-re nil 'move) | ||
| 6348 | (cond | ||
| 6349 | ((match-end 1) ; begin | ||
| 6350 | (when (verilog-looking-back "\\(\\<interface\\>\\s-+\\)\\|\\(\\<virtual\\>\\s-+\\)" (point-at-bol)) | ||
| 6351 | (goto-char (match-beginning 0))) | ||
| 6352 | (unless (verilog-looking-back "\\<typedef\\>\\s-+" (point-at-bol)) | ||
| 6353 | (setq nest (1- nest)) | ||
| 6354 | (if (= 0 nest) | ||
| 6355 | ;; Now previous line describes syntax | ||
| 6356 | (throw 'skip 1)))) | ||
| 6357 | ((match-end 2) ; end | ||
| 6358 | (setq nest (1+ nest)))))))) | ||
| 6359 | |||
| 6113 | (defun verilog-leap-to-head () | 6360 | (defun verilog-leap-to-head () |
| 6114 | "Move point to the head of this block. | 6361 | "Move point to the head of this block. |
| 6115 | Jump from end to matching begin, from endcase to matching case, and so on." | 6362 | Jump from end to matching begin, from endcase to matching case, and so on." |
| @@ -6137,7 +6384,9 @@ Jump from end to matching begin, from endcase to matching case, and so on." | |||
| 6137 | (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | 6384 | (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) |
| 6138 | ((looking-at "\\<endclass\\>") | 6385 | ((looking-at "\\<endclass\\>") |
| 6139 | ;; 5: Search back for matching class | 6386 | ;; 5: Search back for matching class |
| 6140 | (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | 6387 | (catch 'nesting |
| 6388 | (verilog-leap-to-class-head) | ||
| 6389 | (setq reg nil))) | ||
| 6141 | ((looking-at "\\<endtable\\>") | 6390 | ((looking-at "\\<endtable\\>") |
| 6142 | ;; 6: Search back for matching table | 6391 | ;; 6: Search back for matching table |
| 6143 | (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | 6392 | (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) |
| @@ -6175,7 +6424,19 @@ Jump from end to matching begin, from endcase to matching case, and so on." | |||
| 6175 | (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )) | 6424 | (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )) |
| 6176 | ((looking-at "\\<endclocking\\>") | 6425 | ((looking-at "\\<endclocking\\>") |
| 6177 | ;; 12: Search back for matching clocking | 6426 | ;; 12: Search back for matching clocking |
| 6178 | (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" ))) | 6427 | (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )) |
| 6428 | ;; Search back for matching package | ||
| 6429 | ((looking-at "\\<endpackage\\>") | ||
| 6430 | (setq reg "\\(\\<package\\>\\)" )) | ||
| 6431 | ;; Search back for matching program | ||
| 6432 | ((looking-at "\\<endprogram\\>") | ||
| 6433 | (setq reg "\\(\\<program\\>\\)" )) | ||
| 6434 | ((looking-at "\\<`endif\\>") | ||
| 6435 | ;; Search back for matching `endif `else `elsif | ||
| 6436 | (setq reg "\\(\\<`ifn?def\\>\\)\\|\\(\\<`endif\\>\\)" )) | ||
| 6437 | ((looking-at "\\<`else\\>") | ||
| 6438 | ;; Search back for matching `else `else `elsif | ||
| 6439 | (setq reg "\\(\\<`ifn?def\\>\\|\\<`elsif\\>\\)\\|\\(\\<`else\\>\\)" ))) | ||
| 6179 | (if reg | 6440 | (if reg |
| 6180 | (catch 'skip | 6441 | (catch 'skip |
| 6181 | (if (eq nesting 'yes) | 6442 | (if (eq nesting 'yes) |
| @@ -6221,7 +6482,7 @@ Jump from end to matching begin, from endcase to matching case, and so on." | |||
| 6221 | (throw 'skip 1))))))) | 6482 | (throw 'skip 1))))))) |
| 6222 | 6483 | ||
| 6223 | (defun verilog-continued-line () | 6484 | (defun verilog-continued-line () |
| 6224 | "Return true if this is a continued line. | 6485 | "Return non-nil if this is a continued line. |
| 6225 | Set point to where line starts." | 6486 | Set point to where line starts." |
| 6226 | (let ((continued 't)) | 6487 | (let ((continued 't)) |
| 6227 | (if (eq 0 (forward-line -1)) | 6488 | (if (eq 0 (forward-line -1)) |
| @@ -6394,10 +6655,10 @@ Optional BOUND limits search." | |||
| 6394 | (let ((state (save-excursion (verilog-syntax-ppss)))) | 6655 | (let ((state (save-excursion (verilog-syntax-ppss)))) |
| 6395 | (cond | 6656 | (cond |
| 6396 | ((nth 7 state) ; in // comment | 6657 | ((nth 7 state) ; in // comment |
| 6397 | (verilog-re-search-backward "//" nil 'move) | 6658 | (re-search-backward "//" nil 'move) |
| 6398 | (skip-chars-backward "/")) | 6659 | (skip-chars-backward "/")) |
| 6399 | ((nth 4 state) ; in /* */ comment | 6660 | ((nth 4 state) ; in /* */ comment |
| 6400 | (verilog-re-search-backward "/\\*" nil 'move)))) | 6661 | (re-search-backward "/\\*" nil 'move)))) |
| 6401 | (narrow-to-region bound (point)) | 6662 | (narrow-to-region bound (point)) |
| 6402 | (while (/= here (point)) | 6663 | (while (/= here (point)) |
| 6403 | (setq here (point)) | 6664 | (setq here (point)) |
| @@ -6450,13 +6711,60 @@ Optional BOUND limits search." | |||
| 6450 | (if jump | 6711 | (if jump |
| 6451 | (beginning-of-line 2)))))))) | 6712 | (beginning-of-line 2)))))))) |
| 6452 | 6713 | ||
| 6714 | (defun verilog-pos-at-beg-of-statement () | ||
| 6715 | "Return point position at the beginning of current statement." | ||
| 6716 | (save-excursion | ||
| 6717 | (verilog-beg-of-statement) | ||
| 6718 | (point))) | ||
| 6719 | |||
| 6720 | (defun verilog-col-at-beg-of-statement () | ||
| 6721 | "Return current column at the beginning of current statement." | ||
| 6722 | (save-excursion | ||
| 6723 | (verilog-beg-of-statement) | ||
| 6724 | (current-column))) | ||
| 6725 | |||
| 6726 | (defun verilog-pos-at-end-of-statement () | ||
| 6727 | "Return point position at the end of current statement." | ||
| 6728 | (save-excursion | ||
| 6729 | (verilog-end-of-statement))) | ||
| 6730 | |||
| 6731 | (defun verilog-col-at-end-of-statement () | ||
| 6732 | "Return current column at the end of current statement." | ||
| 6733 | (save-excursion | ||
| 6734 | (verilog-end-of-statement) | ||
| 6735 | (current-column))) | ||
| 6736 | |||
| 6737 | (defun verilog-pos-at-forward-syntactic-ws () | ||
| 6738 | "Return point position at next non whitespace/comment token." | ||
| 6739 | (save-excursion | ||
| 6740 | (verilog-forward-syntactic-ws) | ||
| 6741 | (point))) | ||
| 6742 | |||
| 6743 | (defun verilog-col-at-forward-syntactic-ws () | ||
| 6744 | "Return current column at next non whitespace/comment token." | ||
| 6745 | (save-excursion | ||
| 6746 | (verilog-forward-syntactic-ws) | ||
| 6747 | (current-column))) | ||
| 6748 | |||
| 6749 | (defun verilog-pos-at-backward-syntactic-ws () | ||
| 6750 | "Return point position at previous non whitespace/comment token." | ||
| 6751 | (save-excursion | ||
| 6752 | (verilog-backward-syntactic-ws) | ||
| 6753 | (point))) | ||
| 6754 | |||
| 6755 | (defun verilog-col-at-backward-syntactic-ws () | ||
| 6756 | "Return current column at previous non whitespace/comment token." | ||
| 6757 | (save-excursion | ||
| 6758 | (verilog-backward-syntactic-ws) | ||
| 6759 | (current-column))) | ||
| 6760 | |||
| 6453 | (defun verilog-in-comment-p () | 6761 | (defun verilog-in-comment-p () |
| 6454 | "Return true if in a star or // comment." | 6762 | "Return non-nil if in a star or // comment." |
| 6455 | (let ((state (save-excursion (verilog-syntax-ppss)))) | 6763 | (let ((state (save-excursion (verilog-syntax-ppss)))) |
| 6456 | (or (nth 4 state) (nth 7 state)))) | 6764 | (or (nth 4 state) (nth 7 state)))) |
| 6457 | 6765 | ||
| 6458 | (defun verilog-in-star-comment-p () | 6766 | (defun verilog-in-star-comment-p () |
| 6459 | "Return true if in a star comment." | 6767 | "Return non-nil if in a star comment." |
| 6460 | (let ((state (save-excursion (verilog-syntax-ppss)))) | 6768 | (let ((state (save-excursion (verilog-syntax-ppss)))) |
| 6461 | (and | 6769 | (and |
| 6462 | (nth 4 state) ; t if in a comment of style a // or b /**/ | 6770 | (nth 4 state) ; t if in a comment of style a // or b /**/ |
| @@ -6465,40 +6773,39 @@ Optional BOUND limits search." | |||
| 6465 | )))) | 6773 | )))) |
| 6466 | 6774 | ||
| 6467 | (defun verilog-in-slash-comment-p () | 6775 | (defun verilog-in-slash-comment-p () |
| 6468 | "Return true if in a slash comment." | 6776 | "Return non-nil if in a slash comment." |
| 6469 | (let ((state (save-excursion (verilog-syntax-ppss)))) | 6777 | (let ((state (save-excursion (verilog-syntax-ppss)))) |
| 6470 | (nth 7 state))) | 6778 | (nth 7 state))) |
| 6471 | 6779 | ||
| 6472 | (defun verilog-in-comment-or-string-p () | 6780 | (defun verilog-in-comment-or-string-p () |
| 6473 | "Return true if in a string or comment." | 6781 | "Return non-nil if in a string or comment." |
| 6474 | (let ((state (save-excursion (verilog-syntax-ppss)))) | 6782 | (let ((state (save-excursion (verilog-syntax-ppss)))) |
| 6475 | (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment) | 6783 | (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment) |
| 6476 | 6784 | ||
| 6477 | (defun verilog-in-attribute-p () | 6785 | (defun verilog-in-attribute-p () |
| 6478 | "Return true if point is in an attribute (* [] attribute *)." | 6786 | "Return non-nil if point is in an attribute (* [] attribute *)." |
| 6479 | (save-match-data | 6787 | (let ((pos (point))) |
| 6480 | (save-excursion | 6788 | (save-match-data |
| 6481 | (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move) | 6789 | (save-excursion |
| 6482 | (cond | 6790 | (and (verilog-re-search-backward "(\\*" nil 'move) |
| 6483 | ((match-end 1) | 6791 | (progn (forward-sexp) |
| 6484 | (progn (goto-char (match-end 1)) | 6792 | (skip-chars-backward "*)")) |
| 6485 | (not (looking-at "\\s-*)"))) | 6793 | (< pos (point))))))) |
| 6486 | nil) | ||
| 6487 | ((match-end 2) | ||
| 6488 | (progn (goto-char (match-beginning 2)) | ||
| 6489 | (not (looking-at "(\\s-*"))) | ||
| 6490 | nil) | ||
| 6491 | (t nil))))) | ||
| 6492 | 6794 | ||
| 6493 | (defun verilog-in-parameter-p () | 6795 | (defun verilog-in-parameter-p () |
| 6494 | "Return true if point is in a parameter assignment #( p1=1, p2=5)." | 6796 | "Return non-nil if point is in a parameter assignment #( p1=1, p2=5)." |
| 6495 | (save-match-data | 6797 | (save-match-data |
| 6496 | (save-excursion | 6798 | (save-excursion |
| 6497 | (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move) | 6799 | (and (progn |
| 6498 | (numberp (match-beginning 1))))) | 6800 | (verilog-backward-up-list 1) |
| 6801 | (verilog-backward-syntactic-ws) | ||
| 6802 | (= (preceding-char) ?\#)) | ||
| 6803 | (progn | ||
| 6804 | (verilog-beg-of-statement-1) | ||
| 6805 | (looking-at verilog-defun-re)))))) | ||
| 6499 | 6806 | ||
| 6500 | (defun verilog-in-escaped-name-p () | 6807 | (defun verilog-in-escaped-name-p () |
| 6501 | "Return true if in an escaped name." | 6808 | "Return non-nil if in an escaped name." |
| 6502 | (save-excursion | 6809 | (save-excursion |
| 6503 | (backward-char) | 6810 | (backward-char) |
| 6504 | (skip-chars-backward "^ \t\n\f") | 6811 | (skip-chars-backward "^ \t\n\f") |
| @@ -6507,20 +6814,20 @@ Optional BOUND limits search." | |||
| 6507 | nil))) | 6814 | nil))) |
| 6508 | 6815 | ||
| 6509 | (defun verilog-in-directive-p () | 6816 | (defun verilog-in-directive-p () |
| 6510 | "Return true if in a directive." | 6817 | "Return non-nil if in a directive." |
| 6511 | (save-excursion | 6818 | (save-excursion |
| 6512 | (beginning-of-line) | 6819 | (beginning-of-line) |
| 6513 | (looking-at verilog-directive-re-1))) | 6820 | (looking-at verilog-directive-re-1))) |
| 6514 | 6821 | ||
| 6515 | (defun verilog-in-parenthesis-p () | 6822 | (defun verilog-in-parenthesis-p () |
| 6516 | "Return true if in a ( ) expression (but not { } or [ ])." | 6823 | "Return non-nil if in a ( ) expression (but not { } or [ ])." |
| 6517 | (save-match-data | 6824 | (save-match-data |
| 6518 | (save-excursion | 6825 | (save-excursion |
| 6519 | (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move) | 6826 | (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move) |
| 6520 | (numberp (match-beginning 1))))) | 6827 | (numberp (match-beginning 1))))) |
| 6521 | 6828 | ||
| 6522 | (defun verilog-in-paren () | 6829 | (defun verilog-in-paren () |
| 6523 | "Return true if in a parenthetical expression. | 6830 | "Return non-nil if in a parenthetical expression. |
| 6524 | May cache result using `verilog-syntax-ppss'." | 6831 | May cache result using `verilog-syntax-ppss'." |
| 6525 | (let ((state (save-excursion (verilog-syntax-ppss)))) | 6832 | (let ((state (save-excursion (verilog-syntax-ppss)))) |
| 6526 | (> (nth 0 state) 0 ))) | 6833 | (> (nth 0 state) 0 ))) |
| @@ -6534,7 +6841,7 @@ May cache result using `verilog-syntax-ppss'." | |||
| 6534 | 0 ))) | 6841 | 0 ))) |
| 6535 | 6842 | ||
| 6536 | (defun verilog-in-paren-quick () | 6843 | (defun verilog-in-paren-quick () |
| 6537 | "Return true if in a parenthetical expression. | 6844 | "Return non-nil if in a parenthetical expression. |
| 6538 | Always starts from `point-min', to allow inserts with hooks disabled." | 6845 | Always starts from `point-min', to allow inserts with hooks disabled." |
| 6539 | ;; The -quick refers to its use alongside the other -quick functions, | 6846 | ;; The -quick refers to its use alongside the other -quick functions, |
| 6540 | ;; not that it's likely to be faster than verilog-in-paren. | 6847 | ;; not that it's likely to be faster than verilog-in-paren. |
| @@ -6542,7 +6849,7 @@ Always starts from `point-min', to allow inserts with hooks disabled." | |||
| 6542 | (> (nth 0 state) 0 ))) | 6849 | (> (nth 0 state) 0 ))) |
| 6543 | 6850 | ||
| 6544 | (defun verilog-in-struct-p () | 6851 | (defun verilog-in-struct-p () |
| 6545 | "Return true if in a struct declaration." | 6852 | "Return non-nil if in a struct declaration." |
| 6546 | (interactive) | 6853 | (interactive) |
| 6547 | (save-excursion | 6854 | (save-excursion |
| 6548 | (if (verilog-in-paren) | 6855 | (if (verilog-in-paren) |
| @@ -6568,7 +6875,7 @@ Return >0 for nested struct." | |||
| 6568 | nil)))) | 6875 | nil)))) |
| 6569 | 6876 | ||
| 6570 | (defun verilog-in-coverage-p () | 6877 | (defun verilog-in-coverage-p () |
| 6571 | "Return true if in a constraint or coverpoint expression." | 6878 | "Return non-nil if in a constraint or coverpoint expression." |
| 6572 | (interactive) | 6879 | (interactive) |
| 6573 | (save-excursion | 6880 | (save-excursion |
| 6574 | (if (verilog-in-paren) | 6881 | (if (verilog-in-paren) |
| @@ -6608,7 +6915,7 @@ Also move point to constraint." | |||
| 6608 | (equal (char-before) ?\;) | 6915 | (equal (char-before) ?\;) |
| 6609 | (equal (char-before) ?\})) | 6916 | (equal (char-before) ?\})) |
| 6610 | ;; skip what looks like bus repetition operator {#{ | 6917 | ;; skip what looks like bus repetition operator {#{ |
| 6611 | (not (string-match "^{\\s-*[()0-9a-zA-Z_\\]*\\s-*{" | 6918 | (not (string-match "^{\\s-*[][()0-9a-zA-Z_,:\\]*\\s-*{" |
| 6612 | (buffer-substring p (point))))))))) | 6919 | (buffer-substring p (point))))))))) |
| 6613 | (progn | 6920 | (progn |
| 6614 | (let ( (pt (point)) (pass 0)) | 6921 | (let ( (pt (point)) (pass 0)) |
| @@ -6625,7 +6932,7 @@ Also move point to constraint." | |||
| 6625 | )) | 6932 | )) |
| 6626 | ;; if first word token not keyword, it maybe the instance name | 6933 | ;; if first word token not keyword, it maybe the instance name |
| 6627 | ;; check next word token | 6934 | ;; check next word token |
| 6628 | (if (looking-at "\\<\\w+\\>\\|\\s-*(\\s-*\\S-+") | 6935 | (if (looking-at "\\<\\w+\\>\\|\\s-*[\[(}]\\s-*\\S-+") |
| 6629 | (progn (verilog-beg-of-statement) | 6936 | (progn (verilog-beg-of-statement) |
| 6630 | (if (and | 6937 | (if (and |
| 6631 | (not (string-match verilog-named-block-re (buffer-substring pt (point)))) ;; Abort if 'begin' keyword is found | 6938 | (not (string-match verilog-named-block-re (buffer-substring pt (point)))) ;; Abort if 'begin' keyword is found |
| @@ -6674,13 +6981,39 @@ Also move point to constraint." | |||
| 6674 | (verilog-in-struct-p) | 6981 | (verilog-in-struct-p) |
| 6675 | (looking-at "}\\(?:\\s-*\\w+\\s-*\\(?:,\\s-*\\w+\\s-*\\)*\\)?;"))) | 6982 | (looking-at "}\\(?:\\s-*\\w+\\s-*\\(?:,\\s-*\\w+\\s-*\\)*\\)?;"))) |
| 6676 | 6983 | ||
| 6984 | (defun verilog-at-struct-decl-p () | ||
| 6985 | "Return non-nil if at a struct declaration." | ||
| 6986 | (interactive) | ||
| 6987 | (save-excursion | ||
| 6988 | (verilog-re-search-forward "{" (point-at-eol) t) | ||
| 6989 | (unless (bobp) | ||
| 6990 | (backward-char)) | ||
| 6991 | (verilog-at-struct-p))) | ||
| 6992 | |||
| 6993 | (defun verilog-at-enum-p () | ||
| 6994 | "If at the { of a enum, return true, not moving point." | ||
| 6995 | (save-excursion | ||
| 6996 | (when (equal (char-after) ?\{) | ||
| 6997 | (verilog-beg-of-statement) | ||
| 6998 | (beginning-of-line) | ||
| 6999 | (when (verilog-re-search-forward verilog-typedef-enum-re (verilog-pos-at-end-of-statement) t) | ||
| 7000 | t)))) | ||
| 7001 | |||
| 7002 | (defun verilog-at-enum-decl-p () | ||
| 7003 | "Return non-nil if at a enum declaration." | ||
| 7004 | (interactive) | ||
| 7005 | (save-excursion | ||
| 7006 | (verilog-re-search-forward "{" (verilog-pos-at-end-of-statement) t) | ||
| 7007 | (unless (bobp) | ||
| 7008 | (backward-char)) | ||
| 7009 | (verilog-at-enum-p))) | ||
| 7010 | |||
| 6677 | (defun verilog-parenthesis-depth () | 7011 | (defun verilog-parenthesis-depth () |
| 6678 | "Return non zero if in parenthetical-expression." | 7012 | "Return non zero if in parenthetical-expression." |
| 6679 | (save-excursion (nth 1 (verilog-syntax-ppss)))) | 7013 | (save-excursion (nth 1 (verilog-syntax-ppss)))) |
| 6680 | 7014 | ||
| 6681 | |||
| 6682 | (defun verilog-skip-forward-comment-or-string () | 7015 | (defun verilog-skip-forward-comment-or-string () |
| 6683 | "Return true if in a string or comment." | 7016 | "Return non-nil if in a string or comment." |
| 6684 | (let ((state (save-excursion (verilog-syntax-ppss)))) | 7017 | (let ((state (save-excursion (verilog-syntax-ppss)))) |
| 6685 | (cond | 7018 | (cond |
| 6686 | ((nth 3 state) ;Inside string | 7019 | ((nth 3 state) ;Inside string |
| @@ -6695,7 +7028,7 @@ Also move point to constraint." | |||
| 6695 | nil)))) | 7028 | nil)))) |
| 6696 | 7029 | ||
| 6697 | (defun verilog-skip-backward-comment-or-string () | 7030 | (defun verilog-skip-backward-comment-or-string () |
| 6698 | "Return true if in a string or comment." | 7031 | "Return non-nil if in a string or comment." |
| 6699 | (let ((state (save-excursion (verilog-syntax-ppss)))) | 7032 | (let ((state (save-excursion (verilog-syntax-ppss)))) |
| 6700 | (cond | 7033 | (cond |
| 6701 | ((nth 3 state) ;Inside string | 7034 | ((nth 3 state) ;Inside string |
| @@ -6712,7 +7045,7 @@ Also move point to constraint." | |||
| 6712 | nil)))) | 7045 | nil)))) |
| 6713 | 7046 | ||
| 6714 | (defun verilog-skip-backward-comments () | 7047 | (defun verilog-skip-backward-comments () |
| 6715 | "Return true if a comment was skipped." | 7048 | "Return non-nil if a comment was skipped." |
| 6716 | (let ((more t)) | 7049 | (let ((more t)) |
| 6717 | (while more | 7050 | (while more |
| 6718 | (setq more | 7051 | (setq more |
| @@ -6831,6 +7164,9 @@ Only look at a few lines to determine indent level." | |||
| 6831 | (let ((type (car indent-str)) | 7164 | (let ((type (car indent-str)) |
| 6832 | (ind (car (cdr indent-str)))) | 7165 | (ind (car (cdr indent-str)))) |
| 6833 | (cond | 7166 | (cond |
| 7167 | (; handle indentation ignoring | ||
| 7168 | (verilog-indent-ignore-p) | ||
| 7169 | nil) | ||
| 6834 | (; handle continued exp | 7170 | (; handle continued exp |
| 6835 | (eq type 'cexp) | 7171 | (eq type 'cexp) |
| 6836 | (let ((here (point))) | 7172 | (let ((here (point))) |
| @@ -6840,14 +7176,14 @@ Only look at a few lines to determine indent level." | |||
| 6840 | (= (preceding-char) ?\,) | 7176 | (= (preceding-char) ?\,) |
| 6841 | (save-excursion | 7177 | (save-excursion |
| 6842 | (verilog-beg-of-statement-1) | 7178 | (verilog-beg-of-statement-1) |
| 6843 | (looking-at verilog-declaration-re))) | 7179 | (verilog-looking-at-decl-to-align))) |
| 6844 | (let* ( fst | 7180 | (let* ( fst |
| 6845 | (val | 7181 | (val |
| 6846 | (save-excursion | 7182 | (save-excursion |
| 6847 | (backward-char 1) | 7183 | (backward-char 1) |
| 6848 | (verilog-beg-of-statement-1) | 7184 | (verilog-beg-of-statement-1) |
| 6849 | (setq fst (point)) | 7185 | (setq fst (point)) |
| 6850 | (if (looking-at verilog-declaration-re) | 7186 | (if (looking-at (verilog-get-declaration-re)) |
| 6851 | (progn ; we have multiple words | 7187 | (progn ; we have multiple words |
| 6852 | (goto-char (match-end 0)) | 7188 | (goto-char (match-end 0)) |
| 6853 | (skip-chars-forward " \t") | 7189 | (skip-chars-forward " \t") |
| @@ -6869,9 +7205,9 @@ Only look at a few lines to determine indent level." | |||
| 6869 | (+ (current-column) verilog-cexp-indent)))))) | 7205 | (+ (current-column) verilog-cexp-indent)))))) |
| 6870 | (goto-char here) | 7206 | (goto-char here) |
| 6871 | (indent-line-to val) | 7207 | (indent-line-to val) |
| 6872 | (if (and (not verilog-indent-lists) | 7208 | (when (and (not verilog-indent-lists) |
| 6873 | (verilog-in-paren)) | 7209 | (verilog-in-paren)) |
| 6874 | (verilog-pretty-declarations-auto)) | 7210 | (verilog-pretty-declarations-auto)) |
| 6875 | )) | 7211 | )) |
| 6876 | ((= (preceding-char) ?\) ) | 7212 | ((= (preceding-char) ?\) ) |
| 6877 | (goto-char here) | 7213 | (goto-char here) |
| @@ -6897,21 +7233,17 @@ Only look at a few lines to determine indent level." | |||
| 6897 | 7233 | ||
| 6898 | (; handle inside parenthetical expressions | 7234 | (; handle inside parenthetical expressions |
| 6899 | (eq type 'cparenexp) | 7235 | (eq type 'cparenexp) |
| 6900 | (let* ( here | 7236 | (let* ((val (verilog-cparenexp-indent-level)) |
| 6901 | (val (save-excursion | 7237 | (here (save-excursion |
| 6902 | (verilog-backward-up-list 1) | 7238 | (verilog-backward-up-list 1) |
| 6903 | (forward-char 1) | 7239 | (forward-char 1) |
| 6904 | (if verilog-indent-lists | 7240 | (skip-chars-forward " \t") |
| 6905 | (skip-chars-forward " \t") | 7241 | (point))) |
| 6906 | (verilog-forward-syntactic-ws)) | 7242 | (decl (save-excursion |
| 7243 | (goto-char here) | ||
| 7244 | (verilog-forward-syntactic-ws) | ||
| 6907 | (setq here (point)) | 7245 | (setq here (point)) |
| 6908 | (current-column))) | 7246 | (looking-at (verilog-get-declaration-re))))) |
| 6909 | |||
| 6910 | (decl (save-excursion | ||
| 6911 | (goto-char here) | ||
| 6912 | (verilog-forward-syntactic-ws) | ||
| 6913 | (setq here (point)) | ||
| 6914 | (looking-at verilog-declaration-re)))) | ||
| 6915 | (indent-line-to val) | 7247 | (indent-line-to val) |
| 6916 | (if decl | 7248 | (if decl |
| 6917 | (verilog-pretty-declarations-auto)))) | 7249 | (verilog-pretty-declarations-auto)))) |
| @@ -6938,17 +7270,20 @@ Only look at a few lines to determine indent level." | |||
| 6938 | 7270 | ||
| 6939 | (;-- defun | 7271 | (;-- defun |
| 6940 | (and (eq type 'defun) | 7272 | (and (eq type 'defun) |
| 6941 | (looking-at verilog-zero-indent-re)) | 7273 | (or (and verilog-indent-class-inside-pkg |
| 7274 | (looking-at verilog-zero-indent-no-class-re)) | ||
| 7275 | (and (not verilog-indent-class-inside-pkg) | ||
| 7276 | (looking-at verilog-zero-indent-re)))) | ||
| 6942 | (indent-line-to 0)) | 7277 | (indent-line-to 0)) |
| 6943 | 7278 | ||
| 6944 | (;-- declaration | 7279 | (;-- declaration |
| 6945 | (and (or | 7280 | (and (or |
| 6946 | (eq type 'defun) | 7281 | (eq type 'defun) |
| 6947 | (eq type 'block)) | 7282 | (eq type 'block)) |
| 6948 | (looking-at verilog-declaration-re) | 7283 | (verilog-looking-at-decl-to-align) |
| 6949 | ;; Do not consider "virtual function", "virtual task", "virtual class" | 7284 | ;; Do not consider "virtual function", "virtual task", "virtual class" |
| 6950 | ;; as declarations | 7285 | ;; as declarations |
| 6951 | (not (looking-at (concat verilog-declaration-re | 7286 | (not (looking-at (concat (verilog-get-declaration-re) |
| 6952 | "\\s-+\\(function\\|task\\|class\\)\\b")))) | 7287 | "\\s-+\\(function\\|task\\|class\\)\\b")))) |
| 6953 | (verilog-indent-declaration ind)) | 7288 | (verilog-indent-declaration ind)) |
| 6954 | 7289 | ||
| @@ -6994,6 +7329,81 @@ Do not count named blocks or case-statements." | |||
| 6994 | (t | 7329 | (t |
| 6995 | (current-column))))) | 7330 | (current-column))))) |
| 6996 | 7331 | ||
| 7332 | (defun verilog-cparenexp-indent-level () | ||
| 7333 | "Return indent level for current line inside a parenthetical expression." | ||
| 7334 | (let ((start-pos (point)) | ||
| 7335 | (close-par (looking-at "[)}]")) | ||
| 7336 | pos pos-arg-paren) | ||
| 7337 | (save-excursion | ||
| 7338 | (verilog-backward-up-list 1) | ||
| 7339 | (if verilog-indent-lists | ||
| 7340 | (progn | ||
| 7341 | (forward-char 1) | ||
| 7342 | (skip-chars-forward " \t") | ||
| 7343 | (current-column)) | ||
| 7344 | ;; Indentation with `verilog-indent-lists' set to nil | ||
| 7345 | (verilog-beg-of-statement-1) | ||
| 7346 | (when (looking-at "\\<\\(function\\|task\\)\\>") | ||
| 7347 | (verilog-beg-of-statement)) ; find virtual/protected/static | ||
| 7348 | (cond (;; 1) Closing ); of a module/function/task | ||
| 7349 | (and close-par | ||
| 7350 | (save-excursion | ||
| 7351 | (verilog-beg-of-statement-1) | ||
| 7352 | (or (looking-at verilog-complete-re) | ||
| 7353 | (progn (beginning-of-line) | ||
| 7354 | (not (looking-at verilog-assignment-operation-re)))))) | ||
| 7355 | (current-column)) | ||
| 7356 | (;; 2) if (condition) | ||
| 7357 | (looking-at "(") | ||
| 7358 | (forward-char 1) | ||
| 7359 | (skip-chars-forward " \t\f" (point-at-eol)) | ||
| 7360 | (current-column)) | ||
| 7361 | (;; 3) Inside a module/defun param list or function/task argument list | ||
| 7362 | (or (looking-at verilog-defun-level-re) | ||
| 7363 | (looking-at "\\(\\<\\(virtual\\|protected\\|static\\)\\>\\s-+\\)?\\(\\<task\\>\\|\\<function\\>\\)")) | ||
| 7364 | (setq pos-arg-paren (save-excursion | ||
| 7365 | (goto-char start-pos) | ||
| 7366 | (verilog-backward-up-list 1) | ||
| 7367 | (forward-char) | ||
| 7368 | (skip-chars-forward " \t") | ||
| 7369 | (when (not (eolp)) | ||
| 7370 | (current-column)))) | ||
| 7371 | (or pos-arg-paren | ||
| 7372 | ;; arg in next line after ( | ||
| 7373 | (+ (current-column) verilog-indent-level))) | ||
| 7374 | (;; 4) Assignment operation | ||
| 7375 | (save-excursion | ||
| 7376 | (beginning-of-line) | ||
| 7377 | (and (looking-at verilog-assignment-operation-re) | ||
| 7378 | (save-excursion | ||
| 7379 | (goto-char (match-beginning 2)) | ||
| 7380 | (not (verilog-within-string))) | ||
| 7381 | (progn (verilog-forward-syntactic-ws) | ||
| 7382 | (not (looking-at verilog-complete-re))))) | ||
| 7383 | (goto-char (match-end 2)) | ||
| 7384 | (skip-chars-forward " \t\f" (point-at-eol)) | ||
| 7385 | (skip-chars-forward "{(" (1+ (point))) | ||
| 7386 | (skip-chars-forward " \t\f" (point-at-eol)) | ||
| 7387 | (current-column)) | ||
| 7388 | (;; 5) Typedef enum declaration | ||
| 7389 | (verilog-at-enum-decl-p) | ||
| 7390 | (verilog-re-search-forward "{" (verilog-pos-at-end-of-statement) t) | ||
| 7391 | (if (> (verilog-pos-at-forward-syntactic-ws) (point-at-eol)) | ||
| 7392 | (+ (verilog-col-at-beg-of-statement) verilog-indent-level) | ||
| 7393 | (verilog-col-at-forward-syntactic-ws))) | ||
| 7394 | (;; 6) Long reporting strings (e.g. $display or $sformatf inside `uvm_info) | ||
| 7395 | (save-excursion | ||
| 7396 | (goto-char start-pos) | ||
| 7397 | (verilog-backward-up-list 1) | ||
| 7398 | (setq pos (1+ (point))) | ||
| 7399 | (backward-word) | ||
| 7400 | (or (looking-at (concat "$" verilog-identifier-re)) ; System function/task | ||
| 7401 | (looking-at verilog-uvm-statement-re))) ; `uvm_* macros | ||
| 7402 | (goto-char pos) | ||
| 7403 | (current-column)) | ||
| 7404 | (t ;; 7) Default | ||
| 7405 | (+ (current-column) verilog-indent-level))))))) | ||
| 7406 | |||
| 6997 | (defun verilog-indent-comment () | 7407 | (defun verilog-indent-comment () |
| 6998 | "Indent current line as comment." | 7408 | "Indent current line as comment." |
| 6999 | (let* ((stcol | 7409 | (let* ((stcol |
| @@ -7053,90 +7463,137 @@ _ARG is ignored, for `comment-indent-function' compatibility." | |||
| 7053 | 7463 | ||
| 7054 | ;; | 7464 | ;; |
| 7055 | 7465 | ||
| 7466 | (defun verilog-align-comments (startpos endpos) | ||
| 7467 | "Align inline comments between STARTPOS and ENDPOS." | ||
| 7468 | (let (comm-ind e) | ||
| 7469 | (when verilog-align-decl-expr-comments | ||
| 7470 | (setq comm-ind (verilog-get-comment-align-indent (marker-position startpos) endpos)) | ||
| 7471 | (save-excursion | ||
| 7472 | (goto-char (marker-position startpos)) | ||
| 7473 | (while (progn (setq e (marker-position endpos)) | ||
| 7474 | (< (point) e)) | ||
| 7475 | (when (verilog-search-comment-in-declaration e) | ||
| 7476 | (goto-char (match-beginning 0)) | ||
| 7477 | (delete-horizontal-space) | ||
| 7478 | (indent-to (1- (+ comm-ind verilog-align-comment-distance))))))))) | ||
| 7479 | |||
| 7056 | (defun verilog-pretty-declarations-auto (&optional quiet) | 7480 | (defun verilog-pretty-declarations-auto (&optional quiet) |
| 7057 | "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'." | 7481 | "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'." |
| 7058 | (when (or (eq 'all verilog-auto-lineup) | 7482 | (when (or (eq 'all verilog-auto-lineup) |
| 7059 | (eq 'declarations verilog-auto-lineup)) | 7483 | (eq 'declarations verilog-auto-lineup)) |
| 7060 | (verilog-pretty-declarations quiet))) | 7484 | (verilog-pretty-declarations quiet))) |
| 7061 | 7485 | ||
| 7486 | (defun verilog--pretty-declarations-find-end (&optional reg-end) | ||
| 7487 | "Find end position for current alignment of declarations. | ||
| 7488 | If region is active, use arg REG-END to set a limit on the alignment." | ||
| 7489 | (let (e) | ||
| 7490 | (if (and (verilog-parenthesis-depth) | ||
| 7491 | (not (verilog-in-struct-p))) | ||
| 7492 | ;; In an argument list or parameter block | ||
| 7493 | (progn | ||
| 7494 | (verilog-backward-up-list -1) | ||
| 7495 | (forward-char -1) | ||
| 7496 | (verilog-backward-syntactic-ws) | ||
| 7497 | (if (region-active-p) | ||
| 7498 | (min reg-end (point)) | ||
| 7499 | (point))) | ||
| 7500 | ;; In a declaration block (not in argument list) | ||
| 7501 | (verilog-end-of-statement) | ||
| 7502 | (setq e (point)) ; Might be on last line | ||
| 7503 | (verilog-forward-syntactic-ws) | ||
| 7504 | (while (verilog-looking-at-decl-to-align) | ||
| 7505 | (verilog-end-of-statement) | ||
| 7506 | (setq e (point)) | ||
| 7507 | (verilog-forward-syntactic-ws)) | ||
| 7508 | (if (region-active-p) | ||
| 7509 | (min reg-end e) | ||
| 7510 | e)))) | ||
| 7511 | |||
| 7512 | (defun verilog--pretty-declarations-find-base-ind () | ||
| 7513 | "Find base indentation for current alignment of declarations." | ||
| 7514 | (if (and (verilog-parenthesis-depth) | ||
| 7515 | (not (verilog-in-struct-p))) | ||
| 7516 | ;; In an argument list or parameter block | ||
| 7517 | (progn | ||
| 7518 | (unless (or (verilog-looking-back "(" (point-at-bol)) | ||
| 7519 | (bolp)) | ||
| 7520 | (forward-char 1)) | ||
| 7521 | (skip-chars-forward " \t") | ||
| 7522 | (current-column)) | ||
| 7523 | ;; In a declaration block (not in argument list) | ||
| 7524 | (progn | ||
| 7525 | (verilog-do-indent (verilog-calculate-indent)) | ||
| 7526 | (verilog-forward-ws&directives) | ||
| 7527 | (current-column)))) | ||
| 7528 | |||
| 7062 | (defun verilog-pretty-declarations (&optional quiet) | 7529 | (defun verilog-pretty-declarations (&optional quiet) |
| 7063 | "Line up declarations around point. | 7530 | "Line up declarations around point. |
| 7064 | Be verbose about progress unless optional QUIET set." | 7531 | Be verbose about progress unless optional QUIET set." |
| 7065 | (interactive) | 7532 | (interactive) |
| 7066 | (let* ((m1 (make-marker)) | 7533 | (let ((m1 (make-marker)) |
| 7067 | (e (point)) | 7534 | (e (point)) |
| 7068 | el | 7535 | (here (point)) |
| 7069 | r | 7536 | el r ind start startpos end endpos base-ind rstart rend) |
| 7070 | (here (point)) | ||
| 7071 | ind | ||
| 7072 | start | ||
| 7073 | startpos | ||
| 7074 | end | ||
| 7075 | endpos | ||
| 7076 | base-ind | ||
| 7077 | ) | ||
| 7078 | (save-excursion | 7537 | (save-excursion |
| 7538 | (when (region-active-p) | ||
| 7539 | (setq rstart (region-beginning)) | ||
| 7540 | (setq rend (region-end)) | ||
| 7541 | (goto-char rstart)) ; Shrinks the region but ensures that start is a valid declaration | ||
| 7079 | (if (progn | 7542 | (if (progn |
| 7080 | ;; (verilog-beg-of-statement-1) | 7543 | ;; Check if alignment can be performed |
| 7081 | (beginning-of-line) | 7544 | (beginning-of-line) |
| 7082 | (verilog-forward-syntactic-ws) | 7545 | (verilog-forward-syntactic-ws) |
| 7083 | (and (not (verilog-in-directive-p)) ; could have `define input foo | 7546 | (or (and (not (verilog-in-directive-p)) ; could have `define input foo |
| 7084 | (looking-at verilog-declaration-re))) | 7547 | (verilog-looking-at-decl-to-align)) |
| 7085 | (progn | 7548 | (and (verilog-parenthesis-depth) |
| 7086 | (if (verilog-parenthesis-depth) | 7549 | (looking-at verilog-interface-modport-re)))) |
| 7087 | ;; in an argument list or parameter block | 7550 | ;; Find boundaries of alignment |
| 7088 | (setq el (verilog-backward-up-list -1) | 7551 | (progn |
| 7089 | start (progn | 7552 | (cond (;; Using region |
| 7090 | (goto-char e) | 7553 | (region-active-p) |
| 7091 | (verilog-backward-up-list 1) | 7554 | (setq start rstart |
| 7092 | (forward-line) ; ignore ( input foo, | 7555 | startpos (set-marker (make-marker) start) |
| 7093 | (verilog-re-search-forward verilog-declaration-re el 'move) | 7556 | end (progn (goto-char start) |
| 7094 | (goto-char (match-beginning 0)) | 7557 | (verilog--pretty-declarations-find-end rend)) |
| 7558 | endpos (set-marker (make-marker) end) | ||
| 7559 | base-ind (progn (goto-char start) | ||
| 7560 | (verilog--pretty-declarations-find-base-ind)))) | ||
| 7561 | (;; In an argument list or parameter block | ||
| 7562 | (and (verilog-parenthesis-depth) | ||
| 7563 | (not (verilog-in-struct-p))) | ||
| 7564 | (setq el (verilog-backward-up-list -1) | ||
| 7565 | start (progn | ||
| 7566 | (goto-char e) | ||
| 7567 | (verilog-backward-up-list 1) | ||
| 7568 | (verilog-re-search-forward (verilog-get-declaration-re 'iface-mp) el 'move) | ||
| 7569 | (goto-char (match-beginning 0)) | ||
| 7570 | (skip-chars-backward " \t") | ||
| 7571 | (point)) | ||
| 7572 | startpos (set-marker (make-marker) start) | ||
| 7573 | end (progn (goto-char start) | ||
| 7574 | (verilog--pretty-declarations-find-end)) | ||
| 7575 | endpos (set-marker (make-marker) end) | ||
| 7576 | base-ind (progn (goto-char start) | ||
| 7577 | (verilog--pretty-declarations-find-base-ind)))) | ||
| 7578 | (;; In a declaration block (not in argument list) | ||
| 7579 | t | ||
| 7580 | (setq | ||
| 7581 | start (progn | ||
| 7582 | (verilog-beg-of-statement-1) | ||
| 7583 | (while (and (verilog-looking-at-decl-to-align) | ||
| 7584 | (not (bobp))) | ||
| 7095 | (skip-chars-backward " \t") | 7585 | (skip-chars-backward " \t") |
| 7096 | (point)) | 7586 | (setq e (point)) |
| 7097 | startpos (set-marker (make-marker) start) | 7587 | (verilog-backward-syntactic-ws) |
| 7098 | end (progn | 7588 | (backward-char) |
| 7099 | (goto-char start) | 7589 | (verilog-beg-of-statement-1)) |
| 7100 | (verilog-backward-up-list -1) | 7590 | e) |
| 7101 | (forward-char -1) | 7591 | startpos (set-marker (make-marker) start) |
| 7102 | (verilog-backward-syntactic-ws) | 7592 | end (progn (goto-char here) |
| 7103 | (point)) | 7593 | (verilog--pretty-declarations-find-end)) |
| 7104 | endpos (set-marker (make-marker) end) | 7594 | endpos (set-marker (make-marker) end) |
| 7105 | base-ind (progn | 7595 | base-ind (progn (goto-char start) |
| 7106 | (goto-char start) | 7596 | (verilog--pretty-declarations-find-base-ind))))) |
| 7107 | (forward-char 1) | ||
| 7108 | (skip-chars-forward " \t") | ||
| 7109 | (current-column))) | ||
| 7110 | ;; in a declaration block (not in argument list) | ||
| 7111 | (setq | ||
| 7112 | start (progn | ||
| 7113 | (verilog-beg-of-statement-1) | ||
| 7114 | (while (and (looking-at verilog-declaration-re) | ||
| 7115 | (not (bobp))) | ||
| 7116 | (skip-chars-backward " \t") | ||
| 7117 | (setq e (point)) | ||
| 7118 | (beginning-of-line) | ||
| 7119 | (verilog-backward-syntactic-ws) | ||
| 7120 | (backward-char) | ||
| 7121 | (verilog-beg-of-statement-1)) | ||
| 7122 | e) | ||
| 7123 | startpos (set-marker (make-marker) start) | ||
| 7124 | end (progn | ||
| 7125 | (goto-char here) | ||
| 7126 | (verilog-end-of-statement) | ||
| 7127 | (setq e (point)) ;Might be on last line | ||
| 7128 | (verilog-forward-syntactic-ws) | ||
| 7129 | (while (looking-at verilog-declaration-re) | ||
| 7130 | (verilog-end-of-statement) | ||
| 7131 | (setq e (point)) | ||
| 7132 | (verilog-forward-syntactic-ws)) | ||
| 7133 | e) | ||
| 7134 | endpos (set-marker (make-marker) end) | ||
| 7135 | base-ind (progn | ||
| 7136 | (goto-char start) | ||
| 7137 | (verilog-do-indent (verilog-calculate-indent)) | ||
| 7138 | (verilog-forward-ws&directives) | ||
| 7139 | (current-column)))) | ||
| 7140 | ;; OK, start and end are set | 7597 | ;; OK, start and end are set |
| 7141 | (goto-char (marker-position startpos)) | 7598 | (goto-char (marker-position startpos)) |
| 7142 | (if (and (not quiet) | 7599 | (if (and (not quiet) |
| @@ -7152,12 +7609,13 @@ Be verbose about progress unless optional QUIET set." | |||
| 7152 | (indent-line-to base-ind) | 7609 | (indent-line-to base-ind) |
| 7153 | (verilog-forward-ws&directives) | 7610 | (verilog-forward-ws&directives) |
| 7154 | (if (< (point) e) | 7611 | (if (< (point) e) |
| 7155 | (verilog-re-search-forward "[ \t\n\f]" e 'move))) | 7612 | (verilog-re-search-forward "[ \t\n\f]" (marker-position endpos) 'move))) |
| 7156 | (t | 7613 | (t |
| 7157 | (just-one-space) | 7614 | (unless (verilog-looking-back "(" (point-at-bol)) |
| 7158 | (verilog-re-search-forward "[ \t\n\f]" e 'move))) | 7615 | (just-one-space)) |
| 7159 | ;;(forward-line) | 7616 | (if (looking-at verilog-comment-start-regexp) |
| 7160 | ) | 7617 | (verilog-forward-syntactic-ws) |
| 7618 | (verilog-re-search-forward "[ \t\n\f]" e 'move))))) | ||
| 7161 | ;; Now find biggest prefix | 7619 | ;; Now find biggest prefix |
| 7162 | (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos)) | 7620 | (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos)) |
| 7163 | ;; Now indent each line. | 7621 | ;; Now indent each line. |
| @@ -7167,27 +7625,27 @@ Be verbose about progress unless optional QUIET set." | |||
| 7167 | (> r 0)) | 7625 | (> r 0)) |
| 7168 | (setq e (point)) | 7626 | (setq e (point)) |
| 7169 | (unless quiet (message "%d" r)) | 7627 | (unless quiet (message "%d" r)) |
| 7170 | ;; (verilog-do-indent (verilog-calculate-indent))) | ||
| 7171 | (verilog-forward-ws&directives) | 7628 | (verilog-forward-ws&directives) |
| 7172 | (cond | 7629 | (cond |
| 7173 | ((or (and verilog-indent-declaration-macros | 7630 | ((looking-at (verilog-get-declaration-re 'iface-mp)) |
| 7174 | (looking-at verilog-declaration-re-2-macro)) | 7631 | (unless (looking-at (verilog-get-declaration-re 'embedded-comments)) |
| 7175 | (looking-at verilog-declaration-re-2-no-macro)) | 7632 | (let ((p (match-end 0))) |
| 7176 | (let ((p (match-end 0))) | 7633 | (set-marker m1 p) |
| 7177 | (set-marker m1 p) | 7634 | (if (verilog-re-search-forward "[[#`]" p 'move) |
| 7178 | (if (verilog-re-search-forward "[[#`]" p 'move) | 7635 | (progn |
| 7179 | (progn | 7636 | (forward-char -1) |
| 7180 | (forward-char -1) | 7637 | (just-one-space) |
| 7181 | (just-one-space) | 7638 | (goto-char (marker-position m1)) |
| 7182 | (goto-char (marker-position m1)) | 7639 | (delete-horizontal-space) |
| 7640 | (indent-to ind 1)) | ||
| 7641 | (progn | ||
| 7183 | (delete-horizontal-space) | 7642 | (delete-horizontal-space) |
| 7184 | (indent-to ind 1)) | 7643 | (indent-to ind 1)))))) |
| 7185 | (progn | ||
| 7186 | (delete-horizontal-space) | ||
| 7187 | (indent-to ind 1))))) | ||
| 7188 | ((verilog-continued-line-1 (marker-position startpos)) | 7644 | ((verilog-continued-line-1 (marker-position startpos)) |
| 7189 | (goto-char e) | 7645 | (goto-char e) |
| 7190 | (indent-line-to ind)) | 7646 | (unless (and (verilog-in-parenthesis-p) |
| 7647 | (looking-at (concat "\\s-*" verilog-identifier-sym-re "\\s-+" verilog-identifier-sym-re "\\s-*"))) | ||
| 7648 | (indent-line-to ind))) | ||
| 7191 | ((verilog-in-struct-p) | 7649 | ((verilog-in-struct-p) |
| 7192 | ;; could have a declaration of a user defined item | 7650 | ;; could have a declaration of a user defined item |
| 7193 | (goto-char e) | 7651 | (goto-char e) |
| @@ -7197,104 +7655,202 @@ Be verbose about progress unless optional QUIET set." | |||
| 7197 | (verilog-forward-ws&directives) | 7655 | (verilog-forward-ws&directives) |
| 7198 | (forward-line -1))) | 7656 | (forward-line -1))) |
| 7199 | (forward-line 1)) | 7657 | (forward-line 1)) |
| 7200 | (unless quiet (message ""))))))) | 7658 | ;; Align comments if enabled |
| 7659 | (when verilog-align-decl-expr-comments | ||
| 7660 | (verilog-align-comments startpos endpos))) | ||
| 7661 | ;; Exit | ||
| 7662 | (unless quiet (message "")))))) | ||
| 7663 | |||
| 7664 | (defun verilog--pretty-expr-assignment-found (&optional discard-re) | ||
| 7665 | "Return non-nil if point is at a valid assignment operation to be aligned. | ||
| 7666 | Ensure cursor is not over DISCARD-RE (e.g. Verilog keywords). | ||
| 7667 | If returned non-nil, update match data according to `verilog-assignment-operation-re'." | ||
| 7668 | ;; Not looking at a verilog keyword sentence (i.e looking at a potential assignment) | ||
| 7669 | (and (if discard-re | ||
| 7670 | (not (looking-at discard-re)) | ||
| 7671 | t) | ||
| 7672 | ;; Corner case to filter first parameter on param lists | ||
| 7673 | (save-excursion | ||
| 7674 | (if (and (verilog-re-search-forward verilog-assignment-operation-re (point-at-eol) 'move) | ||
| 7675 | (verilog-in-parenthesis-p)) | ||
| 7676 | (progn (verilog-backward-up-list 1) | ||
| 7677 | (forward-char 1) | ||
| 7678 | (not (eq 0 (string-match discard-re (buffer-substring-no-properties (point) (point-at-eol)))))) | ||
| 7679 | t)) | ||
| 7680 | ;; Don't work on multiline assignments unless they are continued lines | ||
| 7681 | ;; e.g, multiple parameters or variable declarations in the same statement | ||
| 7682 | (if (save-excursion | ||
| 7683 | (and (not (verilog-in-parameter-p)) | ||
| 7684 | (verilog-continued-line) | ||
| 7685 | (not (looking-at verilog-basic-complete-re)))) | ||
| 7686 | (save-excursion | ||
| 7687 | (verilog-beg-of-statement-1) | ||
| 7688 | (looking-at (verilog-get-declaration-re))) | ||
| 7689 | t) | ||
| 7690 | ;; Ensure it's not any kind of logical comparison | ||
| 7691 | (save-excursion | ||
| 7692 | (unless (and (not (verilog-in-parameter-p)) | ||
| 7693 | (verilog-re-search-forward (verilog-regexp-words '("if" "for" "assert" "with")) (point-at-eol) 'move)) | ||
| 7694 | t)) | ||
| 7695 | ;; Looking at an assignment (last check, provides match data) | ||
| 7696 | (looking-at verilog-assignment-operation-re))) | ||
| 7697 | |||
| 7698 | (defun verilog--pretty-expr-find-end (&optional discard-re reg-end) | ||
| 7699 | "Find end position for current alignment of expressions. | ||
| 7700 | Use optional arg DISCARD-RE when aligning expressions outside of an | ||
| 7701 | argument list and REG-END to set a limit on the alignment when the | ||
| 7702 | region is active." | ||
| 7703 | (if (verilog-in-parenthesis-p) | ||
| 7704 | ;; Limit end in argument list | ||
| 7705 | (progn | ||
| 7706 | (verilog-backward-up-list -1) | ||
| 7707 | (forward-char -1) | ||
| 7708 | (verilog-backward-syntactic-ws) | ||
| 7709 | (if (region-active-p) | ||
| 7710 | (min reg-end (point)) | ||
| 7711 | (point))) | ||
| 7712 | ;; Limit end in non-argument list | ||
| 7713 | (save-excursion ; EOL of the last line of the assignment block | ||
| 7714 | (end-of-line) | ||
| 7715 | (let ((pt (point))) ; Might be on last line | ||
| 7716 | (verilog-forward-syntactic-ws) | ||
| 7717 | (beginning-of-line) | ||
| 7718 | (while (and (verilog--pretty-expr-assignment-found discard-re) | ||
| 7719 | (progn | ||
| 7720 | (end-of-line) | ||
| 7721 | (not (eq pt (point))))) | ||
| 7722 | (setq pt (point)) | ||
| 7723 | (verilog-forward-syntactic-ws) | ||
| 7724 | (beginning-of-line)) | ||
| 7725 | (if (region-active-p) | ||
| 7726 | (min reg-end pt) | ||
| 7727 | pt))))) | ||
| 7201 | 7728 | ||
| 7202 | (defun verilog-pretty-expr (&optional quiet) | 7729 | (defun verilog-pretty-expr (&optional quiet) |
| 7203 | "Line up expressions around point. | 7730 | "Line up expressions around point. |
| 7204 | If QUIET is non-nil, do not print messages showing the progress of line-up." | 7731 | If QUIET is non-nil, do not print messages showing the progress of line-up." |
| 7205 | (interactive) | 7732 | (interactive) |
| 7206 | (unless (verilog-in-comment-or-string-p) | 7733 | (let* ((basic-complete-pretty-expr-re (if verilog-align-assign-expr |
| 7734 | verilog-basic-complete-expr-no-assign-re | ||
| 7735 | verilog-basic-complete-expr-re)) | ||
| 7736 | (complete-pretty-expr-re (concat verilog-extended-complete-re "\\|\\(" basic-complete-pretty-expr-re "\\)")) | ||
| 7737 | (discard-re (concat "^\\s-*\\(" complete-pretty-expr-re "\\)")) | ||
| 7738 | rstart rend) | ||
| 7207 | (save-excursion | 7739 | (save-excursion |
| 7208 | (let ((regexp (concat "^\\s-*" verilog-complete-reg)) | 7740 | (when (region-active-p) |
| 7209 | (regexp1 (concat "^\\s-*" verilog-basic-complete-re))) | 7741 | (setq rstart (region-beginning)) |
| 7742 | (setq rend (region-end)) | ||
| 7743 | (goto-char rstart)) | ||
| 7744 | (unless (verilog-in-comment-or-string-p) | ||
| 7210 | (beginning-of-line) | 7745 | (beginning-of-line) |
| 7211 | (when (and (not (looking-at regexp)) | 7746 | (when (and (verilog--pretty-expr-assignment-found discard-re) |
| 7212 | (looking-at verilog-assignment-operation-re) | ||
| 7213 | (save-excursion | 7747 | (save-excursion |
| 7214 | (goto-char (match-end 2)) | 7748 | (goto-char (match-end 2)) |
| 7215 | (and (not (verilog-in-attribute-p)) | 7749 | (and (not (verilog-in-attribute-p)) |
| 7216 | (not (verilog-in-parameter-p)) | ||
| 7217 | (not (verilog-in-comment-or-string-p))))) | 7750 | (not (verilog-in-comment-or-string-p))))) |
| 7218 | (let* ((start (save-excursion ; BOL of the first line of the assignment block | 7751 | (let* ((start (cond (;; Using region |
| 7219 | (beginning-of-line) | 7752 | (region-active-p) |
| 7220 | (let ((pt (point))) | 7753 | rstart) |
| 7221 | (verilog-backward-syntactic-ws) | 7754 | (;; Parameter list |
| 7222 | (beginning-of-line) | 7755 | (verilog-in-parenthesis-p) |
| 7223 | (while (and (not (looking-at regexp1)) | 7756 | (progn |
| 7224 | (looking-at verilog-assignment-operation-re) | 7757 | (verilog-backward-up-list 1) |
| 7225 | (not (bobp))) | 7758 | (forward-char) |
| 7226 | (setq pt (point)) | 7759 | (verilog-re-search-forward verilog-assignment-operation-re-2 nil 'move) |
| 7227 | (verilog-backward-syntactic-ws) | 7760 | (goto-char (match-beginning 0)) |
| 7228 | (beginning-of-line)) ; Ack, need to grok `define | 7761 | (point))) |
| 7229 | pt))) | 7762 | (t ;; Declarations |
| 7230 | (end (save-excursion ; EOL of the last line of the assignment block | 7763 | (save-excursion ; BOL of the first line of the assignment block |
| 7231 | (end-of-line) | 7764 | (beginning-of-line) |
| 7232 | (let ((pt (point))) ; Might be on last line | 7765 | (let ((pt (point))) |
| 7233 | (verilog-forward-syntactic-ws) | 7766 | (verilog-backward-syntactic-ws) |
| 7234 | (beginning-of-line) | 7767 | (beginning-of-line) |
| 7235 | (while (and | 7768 | (while (and (verilog--pretty-expr-assignment-found discard-re) |
| 7236 | (not (looking-at regexp1)) | 7769 | (not (bobp))) |
| 7237 | (looking-at verilog-assignment-operation-re) | 7770 | (setq pt (point)) |
| 7238 | (progn | 7771 | (verilog-backward-syntactic-ws) |
| 7239 | (end-of-line) | 7772 | (beginning-of-line)) ; Ack, need to grok `define |
| 7240 | (not (eq pt (point))))) | 7773 | pt))))) |
| 7241 | (setq pt (point)) | 7774 | (startpos (set-marker (make-marker) start)) |
| 7242 | (verilog-forward-syntactic-ws) | 7775 | (end (cond (;; Using region |
| 7243 | (beginning-of-line)) | 7776 | (region-active-p) |
| 7244 | pt))) | 7777 | (verilog--pretty-expr-find-end discard-re rend)) |
| 7245 | (contains-2-char-operator (string-match "<=" (buffer-substring-no-properties start end))) | 7778 | (;; Parameter list |
| 7246 | (endmark (set-marker (make-marker) end))) | 7779 | (verilog-in-parenthesis-p) |
| 7247 | (goto-char start) | 7780 | (verilog--pretty-expr-find-end)) |
| 7248 | (verilog-do-indent (verilog-calculate-indent)) | 7781 | (t ;; Declarations |
| 7782 | (verilog--pretty-expr-find-end discard-re)))) | ||
| 7783 | (endpos (set-marker (make-marker) end)) | ||
| 7784 | (contains-2-char-operator (string-match "<=" (buffer-substring-no-properties start end)))) | ||
| 7785 | ;; Start with alignment | ||
| 7786 | (goto-char startpos) | ||
| 7787 | (unless (save-excursion | ||
| 7788 | (beginning-of-line) | ||
| 7789 | (looking-at discard-re)) | ||
| 7790 | (verilog-do-indent (verilog-calculate-indent))) | ||
| 7249 | (when (and (not quiet) | 7791 | (when (and (not quiet) |
| 7250 | (> (- end start) 100)) | 7792 | (> (- (marker-position endpos) (marker-position startpos)) 100)) |
| 7251 | (message "Lining up expressions.. (please stand by)")) | 7793 | (message "Lining up expressions.. (please stand by)")) |
| 7252 | |||
| 7253 | ;; Set indent to minimum throughout region | 7794 | ;; Set indent to minimum throughout region |
| 7254 | ;; Rely on mark rather than on point as the indentation changes can | 7795 | ;; Rely on mark rather than on point as the indentation changes can |
| 7255 | ;; make the older point reference obsolete | 7796 | ;; make the older point reference obsolete |
| 7256 | (while (< (point) (marker-position endmark)) | 7797 | (while (< (point) (marker-position endpos)) |
| 7257 | (beginning-of-line) | 7798 | (beginning-of-line) |
| 7258 | (save-excursion | 7799 | (save-excursion |
| 7259 | (verilog-just-one-space verilog-assignment-operation-re)) | 7800 | (if (looking-at verilog-complete-re) |
| 7801 | (progn (goto-char (marker-position startpos)) | ||
| 7802 | (verilog-just-one-space verilog-assignment-operation-re-2)) | ||
| 7803 | (verilog-just-one-space verilog-assignment-operation-re))) | ||
| 7260 | (verilog-do-indent (verilog-calculate-indent)) | 7804 | (verilog-do-indent (verilog-calculate-indent)) |
| 7261 | (end-of-line) | 7805 | (end-of-line) |
| 7262 | (verilog-forward-syntactic-ws)) | 7806 | (verilog-forward-syntactic-ws)) |
| 7263 | 7807 | ||
| 7264 | (let ((ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start (marker-position endmark))) ; Find the biggest prefix | 7808 | (let ((ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re (marker-position startpos) (marker-position endpos))) ; Find the biggest prefix |
| 7265 | e) | 7809 | e) |
| 7266 | ;; Now indent each line. | 7810 | ;; Now indent each line. |
| 7267 | (goto-char start) | 7811 | (goto-char (marker-position startpos)) |
| 7268 | (while (progn | 7812 | (while (progn |
| 7269 | (setq e (marker-position endmark)) | 7813 | (setq e (marker-position endpos)) |
| 7270 | (> e (point))) | 7814 | (> e (point))) |
| 7271 | (unless quiet | 7815 | (unless quiet |
| 7272 | (message " verilog-pretty-expr: %d" (- e (point)))) | 7816 | (message " verilog-pretty-expr: %d" (- e (point)))) |
| 7273 | (setq e (point)) | 7817 | (setq e (point)) |
| 7274 | (cond | 7818 | (cond |
| 7275 | ((looking-at verilog-assignment-operation-re) | 7819 | ((or (looking-at verilog-assignment-operation-re) |
| 7820 | (and (verilog-in-parenthesis-p) | ||
| 7821 | (looking-at verilog-assignment-operation-re-2))) | ||
| 7276 | (goto-char (match-beginning 2)) | 7822 | (goto-char (match-beginning 2)) |
| 7277 | (unless (or (verilog-in-parenthesis-p) ; Leave attributes and comparisons alone | 7823 | (unless (or (and (verilog-in-parenthesis-p) ; Leave attributes and comparisons alone |
| 7824 | (save-excursion ; Allow alignment of some expressions inside param/port list | ||
| 7825 | (verilog-backward-up-list 1) | ||
| 7826 | (verilog-beg-of-statement-1) | ||
| 7827 | (not (looking-at verilog-defun-level-re)))) | ||
| 7278 | (verilog-in-coverage-p)) | 7828 | (verilog-in-coverage-p)) |
| 7279 | (if (and contains-2-char-operator | 7829 | (if (and contains-2-char-operator |
| 7280 | (eq (char-after) ?=)) | 7830 | (eq (char-after) ?=)) |
| 7281 | (indent-to (1+ ind)) ; Line up the = of the <= with surrounding = | 7831 | (indent-to (1+ ind)) ; Line up the = of the <= with surrounding = |
| 7282 | (indent-to ind)))) | 7832 | (indent-to ind))) |
| 7283 | ((verilog-continued-line-1 start) | 7833 | (forward-line 1)) |
| 7834 | ((and (save-excursion | ||
| 7835 | (verilog-forward-syntactic-ws) | ||
| 7836 | (not (looking-at verilog-complete-re))) | ||
| 7837 | (verilog-continued-line-1 (marker-position startpos))) | ||
| 7284 | (goto-char e) | 7838 | (goto-char e) |
| 7285 | (indent-line-to ind)) | 7839 | (indent-line-to ind) |
| 7286 | (t ; Must be comment or white space | 7840 | (forward-line 1)) |
| 7841 | (t ; Must be comment, white space or syntax error | ||
| 7287 | (goto-char e) | 7842 | (goto-char e) |
| 7288 | (verilog-forward-ws&directives) | 7843 | (forward-line 1)))) |
| 7289 | (forward-line -1))) | 7844 | ;; Align comments if enabled |
| 7290 | (forward-line 1)) | 7845 | (when verilog-align-decl-expr-comments |
| 7846 | (verilog-align-comments startpos endpos)) | ||
| 7291 | (unless quiet | 7847 | (unless quiet |
| 7292 | (message ""))))))))) | 7848 | (message ""))))))))) |
| 7293 | 7849 | ||
| 7294 | (defun verilog-just-one-space (myre) | 7850 | (defun verilog-just-one-space (myre) |
| 7295 | "Remove extra spaces around regular expression MYRE." | 7851 | "Remove extra spaces around regular expression MYRE." |
| 7296 | (interactive) | 7852 | (interactive) |
| 7297 | (if (and (not(looking-at verilog-complete-reg)) | 7853 | (if (and (not(looking-at verilog-complete-re)) |
| 7298 | (looking-at myre)) | 7854 | (looking-at myre)) |
| 7299 | (let ((p1 (match-end 1)) | 7855 | (let ((p1 (match-end 1)) |
| 7300 | (p2 (match-end 2))) | 7856 | (p2 (match-end 2))) |
| @@ -7312,59 +7868,63 @@ BASEIND is the base indent to offset everything." | |||
| 7312 | ;; `ind' is used in expressions stored in `verilog-indent-alist'. | 7868 | ;; `ind' is used in expressions stored in `verilog-indent-alist'. |
| 7313 | (verilog--suppressed-warnings ((lexical ind)) (defvar ind)) | 7869 | (verilog--suppressed-warnings ((lexical ind)) (defvar ind)) |
| 7314 | (let ((pos (point-marker)) | 7870 | (let ((pos (point-marker)) |
| 7315 | (lim (save-excursion | 7871 | (m1 (make-marker)) |
| 7316 | ;; (verilog-re-search-backward verilog-declaration-opener nil 'move) | 7872 | (in-paren (verilog-parenthesis-depth)) |
| 7317 | (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<\\(connect\\)?module\\>\\)\\|\\(\\<task\\>\\)" nil 'move) | 7873 | (val (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist))))) |
| 7318 | (point))) | 7874 | ind) |
| 7319 | (ind) | ||
| 7320 | (val) | ||
| 7321 | (m1 (make-marker))) | ||
| 7322 | (setq val | ||
| 7323 | (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist))))) | ||
| 7324 | (indent-line-to val) | 7875 | (indent-line-to val) |
| 7325 | |||
| 7326 | ;; Use previous declaration (in this module) as template. | 7876 | ;; Use previous declaration (in this module) as template. |
| 7327 | (if (or (eq 'all verilog-auto-lineup) | 7877 | (when (and (or (eq 'all verilog-auto-lineup) |
| 7328 | (eq 'declarations verilog-auto-lineup)) | 7878 | (eq 'declarations verilog-auto-lineup)) |
| 7329 | (if (verilog-re-search-backward | 7879 | ;; Limit alignment to consecutive statements |
| 7330 | (or (and verilog-indent-declaration-macros | 7880 | (progn |
| 7331 | verilog-declaration-re-1-macro) | 7881 | (verilog-backward-syntactic-ws) |
| 7332 | verilog-declaration-re-1-no-macro) | 7882 | (backward-char) |
| 7333 | lim t) | 7883 | (looking-at ";")) |
| 7334 | (progn | 7884 | (progn |
| 7335 | (goto-char (match-end 0)) | 7885 | (verilog-beg-of-statement) |
| 7336 | (skip-chars-forward " \t") | 7886 | (looking-at (verilog-get-declaration-re))) |
| 7337 | (setq ind (current-column)) | 7887 | ;; Make sure that we don't jump to an argument list or parameter block if |
| 7338 | (goto-char pos) | 7888 | ;; we were in a declaration block (not in argument list) |
| 7339 | (setq val | 7889 | (or (and in-paren |
| 7340 | (+ baseind | 7890 | (verilog-parenthesis-depth)) |
| 7341 | (eval (cdr (assoc 'declaration verilog-indent-alist))))) | 7891 | (and (not in-paren) |
| 7342 | (indent-line-to val) | 7892 | (not (verilog-parenthesis-depth)))) |
| 7343 | (if (and verilog-indent-declaration-macros | 7893 | ;; Skip variable declarations inside functions/tasks |
| 7344 | (looking-at verilog-declaration-re-2-macro)) | 7894 | (skip-chars-backward " \t\f") |
| 7345 | (let ((p (match-end 0))) | 7895 | (bolp)) |
| 7346 | (set-marker m1 p) | 7896 | (goto-char (match-end 0)) |
| 7347 | (if (verilog-re-search-forward "[[#`]" p 'move) | 7897 | (skip-chars-forward " \t") |
| 7348 | (progn | 7898 | (setq ind (current-column)) |
| 7349 | (forward-char -1) | 7899 | (goto-char pos) |
| 7350 | (just-one-space) | 7900 | (setq val |
| 7351 | (goto-char (marker-position m1)) | 7901 | (+ baseind |
| 7352 | (delete-horizontal-space) | 7902 | (eval (cdr (assoc 'declaration verilog-indent-alist))))) |
| 7353 | (indent-to ind 1)) | 7903 | (indent-line-to val) |
| 7354 | (delete-horizontal-space) | 7904 | (if (looking-at (verilog-get-declaration-re)) |
| 7355 | (indent-to ind 1))) | 7905 | (let ((p (match-end 0))) |
| 7356 | (if (looking-at verilog-declaration-re-2-no-macro) | 7906 | (set-marker m1 p) |
| 7357 | (let ((p (match-end 0))) | 7907 | (if (verilog-re-search-forward "[[#`]" p 'move) |
| 7358 | (set-marker m1 p) | 7908 | (progn |
| 7359 | (if (verilog-re-search-forward "[[`#]" p 'move) | 7909 | (forward-char -1) |
| 7360 | (progn | 7910 | (just-one-space) |
| 7361 | (forward-char -1) | 7911 | (goto-char (marker-position m1)) |
| 7362 | (just-one-space) | 7912 | (delete-horizontal-space) |
| 7363 | (goto-char (marker-position m1)) | 7913 | (indent-to ind 1)) |
| 7364 | (delete-horizontal-space) | 7914 | (delete-horizontal-space) |
| 7365 | (indent-to ind 1)) | 7915 | (indent-to ind 1))) |
| 7366 | (delete-horizontal-space) | 7916 | (when (looking-at (verilog-get-declaration-re)) |
| 7367 | (indent-to ind 1)))))))) | 7917 | (let ((p (match-end 0))) |
| 7918 | (set-marker m1 p) | ||
| 7919 | (if (verilog-re-search-forward "[[`#]" p 'move) | ||
| 7920 | (progn | ||
| 7921 | (forward-char -1) | ||
| 7922 | (just-one-space) | ||
| 7923 | (goto-char (marker-position m1)) | ||
| 7924 | (delete-horizontal-space) | ||
| 7925 | (indent-to ind 1)) | ||
| 7926 | (delete-horizontal-space) | ||
| 7927 | (indent-to ind 1)))))) | ||
| 7368 | (goto-char pos))) | 7928 | (goto-char pos))) |
| 7369 | 7929 | ||
| 7370 | (defun verilog-get-lineup-indent (b edpos) | 7930 | (defun verilog-get-lineup-indent (b edpos) |
| @@ -7376,16 +7936,13 @@ Region is defined by B and EDPOS." | |||
| 7376 | ;; Get rightmost position | 7936 | ;; Get rightmost position |
| 7377 | (while (progn (setq e (marker-position edpos)) | 7937 | (while (progn (setq e (marker-position edpos)) |
| 7378 | (< (point) e)) | 7938 | (< (point) e)) |
| 7379 | (if (verilog-re-search-forward | 7939 | (when (verilog-re-search-forward (verilog-get-declaration-re 'iface-mp) e 'move) |
| 7380 | (or (and verilog-indent-declaration-macros | 7940 | (goto-char (match-end 0)) |
| 7381 | verilog-declaration-re-1-macro) | 7941 | (verilog-backward-syntactic-ws) |
| 7382 | verilog-declaration-re-1-no-macro) e 'move) | 7942 | (if (> (current-column) ind) |
| 7383 | (progn | 7943 | (setq ind (current-column))) |
| 7384 | (goto-char (match-end 0)) | 7944 | (goto-char (match-end 0)) |
| 7385 | (verilog-backward-syntactic-ws) | 7945 | (forward-line 1))) |
| 7386 | (if (> (current-column) ind) | ||
| 7387 | (setq ind (current-column))) | ||
| 7388 | (goto-char (match-end 0))))) | ||
| 7389 | (if (> ind 0) | 7946 | (if (> ind 0) |
| 7390 | (1+ ind) | 7947 | (1+ ind) |
| 7391 | ;; No lineup-string found | 7948 | ;; No lineup-string found |
| @@ -7402,12 +7959,13 @@ BEG and END." | |||
| 7402 | (save-excursion | 7959 | (save-excursion |
| 7403 | (let ((ind 0)) | 7960 | (let ((ind 0)) |
| 7404 | (goto-char beg) | 7961 | (goto-char beg) |
| 7962 | (beginning-of-line) | ||
| 7405 | ;; Get rightmost position | 7963 | ;; Get rightmost position |
| 7406 | (while (< (point) end) | 7964 | (while (< (point) end) |
| 7407 | (when (and (verilog-re-search-forward regexp end 'move) | 7965 | (when (and (verilog-re-search-forward regexp end 'move) |
| 7408 | (not (verilog-in-attribute-p))) ; skip attribute exprs | 7966 | (not (verilog-in-attribute-p))) ; skip attribute exprs |
| 7409 | (goto-char (match-beginning 2)) | 7967 | (goto-char (match-beginning 2)) |
| 7410 | (verilog-backward-syntactic-ws) | 7968 | (skip-chars-backward " \t") |
| 7411 | (if (> (current-column) ind) | 7969 | (if (> (current-column) ind) |
| 7412 | (setq ind (current-column))) | 7970 | (setq ind (current-column))) |
| 7413 | (goto-char (match-end 0)))) | 7971 | (goto-char (match-end 0)))) |
| @@ -7420,6 +7978,32 @@ BEG and END." | |||
| 7420 | (1+ (current-column)))) | 7978 | (1+ (current-column)))) |
| 7421 | ind))) | 7979 | ind))) |
| 7422 | 7980 | ||
| 7981 | (defun verilog-search-comment-in-declaration (bound) | ||
| 7982 | "Move cursor to position of comment in declaration and return point. | ||
| 7983 | BOUND is a buffer position that bounds the search." | ||
| 7984 | (and (verilog-re-search-forward (verilog-get-declaration-re 'iface-mp) bound 'move) | ||
| 7985 | (not (looking-at (concat "\\s-*" verilog-comment-start-regexp))) | ||
| 7986 | (re-search-forward verilog-comment-start-regexp (point-at-eol) :noerror))) | ||
| 7987 | |||
| 7988 | (defun verilog-get-comment-align-indent (b endpos) | ||
| 7989 | "Return the indent level that will line up comments within the region. | ||
| 7990 | Region is defined by B and ENDPOS." | ||
| 7991 | (save-excursion | ||
| 7992 | (let ((ind 0) | ||
| 7993 | e comm-ind) | ||
| 7994 | (goto-char b) | ||
| 7995 | ;; Get rightmost position | ||
| 7996 | (while (progn (setq e (marker-position endpos)) | ||
| 7997 | (< (point) e)) | ||
| 7998 | (when (verilog-search-comment-in-declaration e) | ||
| 7999 | (end-of-line) | ||
| 8000 | (verilog-backward-syntactic-ws) | ||
| 8001 | (setq comm-ind (1+ (current-column))) | ||
| 8002 | (when (> comm-ind ind) | ||
| 8003 | (setq ind comm-ind))) | ||
| 8004 | (forward-line 1)) | ||
| 8005 | ind))) | ||
| 8006 | |||
| 7423 | (defun verilog-comment-depth (type val) | 8007 | (defun verilog-comment-depth (type val) |
| 7424 | "A useful mode debugging aide. TYPE and VAL are comments for insertion." | 8008 | "A useful mode debugging aide. TYPE and VAL are comments for insertion." |
| 7425 | (save-excursion | 8009 | (save-excursion |
| @@ -7439,6 +8023,19 @@ BEG and END." | |||
| 7439 | (insert | 8023 | (insert |
| 7440 | (format "%s %d" type val)))) | 8024 | (format "%s %d" type val)))) |
| 7441 | 8025 | ||
| 8026 | (defun verilog-indent-ignore-p () | ||
| 8027 | "Return non-nil if current line should ignore indentation." | ||
| 8028 | (or (and verilog-indent-ignore-multiline-defines | ||
| 8029 | ;; Line with multiline define, ends with "\" or "\" plus trailing whitespace | ||
| 8030 | (or (looking-at ".*\\\\\\s-*$") | ||
| 8031 | (save-excursion ; Last line after multiline define | ||
| 8032 | (verilog-backward-syntactic-ws) | ||
| 8033 | (unless (bobp) | ||
| 8034 | (backward-char)) | ||
| 8035 | (looking-at "\\\\")))) | ||
| 8036 | (and verilog-indent-ignore-regexp ; Ignore lines according to specified regexp | ||
| 8037 | (looking-at verilog-indent-ignore-regexp)))) | ||
| 8038 | |||
| 7442 | 8039 | ||
| 7443 | ;;; Completion: | 8040 | ;;; Completion: |
| 7444 | ;; | 8041 | ;; |
| @@ -7446,7 +8043,7 @@ BEG and END." | |||
| 7446 | (defvar verilog-all nil) | 8043 | (defvar verilog-all nil) |
| 7447 | (defvar verilog-buffer-to-use nil) | 8044 | (defvar verilog-buffer-to-use nil) |
| 7448 | (defvar verilog-toggle-completions nil | 8045 | (defvar verilog-toggle-completions nil |
| 7449 | "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one. | 8046 | "Non-nil means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one. |
| 7450 | Repeated use of \\[verilog-complete-word] will show you all of them. | 8047 | Repeated use of \\[verilog-complete-word] will show you all of them. |
| 7451 | Normally, when there is more than one possible completion, | 8048 | Normally, when there is more than one possible completion, |
| 7452 | it displays a list of all possible completions.") | 8049 | it displays a list of all possible completions.") |
| @@ -7598,16 +8195,14 @@ TYPE is `module', `tf' for task or function, or t if unknown." | |||
| 7598 | (defun verilog-get-completion-decl (end) | 8195 | (defun verilog-get-completion-decl (end) |
| 7599 | "Macro for searching through current declaration (var, type or const) | 8196 | "Macro for searching through current declaration (var, type or const) |
| 7600 | for matches of `str' and adding the occurrence tp `all' through point END." | 8197 | for matches of `str' and adding the occurrence tp `all' through point END." |
| 7601 | (let ((re (or (and verilog-indent-declaration-macros | 8198 | (let ((re (verilog-get-declaration-re)) |
| 7602 | verilog-declaration-re-2-macro) | ||
| 7603 | verilog-declaration-re-2-no-macro)) | ||
| 7604 | decl-end match) | 8199 | decl-end match) |
| 7605 | ;; Traverse lines | 8200 | ;; Traverse lines |
| 7606 | (while (and (< (point) end) | 8201 | (while (and (< (point) end) |
| 7607 | (verilog-re-search-forward re end t)) | 8202 | (verilog-re-search-forward re end t)) |
| 7608 | ;; Traverse current line | 8203 | ;; Traverse current line |
| 7609 | (setq decl-end (save-excursion (verilog-declaration-end))) | 8204 | (setq decl-end (save-excursion (verilog-declaration-end))) |
| 7610 | (while (and (verilog-re-search-forward verilog-symbol-re decl-end t) | 8205 | (while (and (verilog-re-search-forward verilog-identifier-sym-re decl-end t) |
| 7611 | (not (match-end 1))) | 8206 | (not (match-end 1))) |
| 7612 | (setq match (buffer-substring (match-beginning 0) (match-end 0))) | 8207 | (setq match (buffer-substring (match-beginning 0) (match-end 0))) |
| 7613 | (if (string-match (concat "\\<" verilog-str) match) | 8208 | (if (string-match (concat "\\<" verilog-str) match) |
| @@ -7619,7 +8214,7 @@ for matches of `str' and adding the occurrence tp `all' through point END." | |||
| 7619 | "Calculate all possible completions for variables (or constants)." | 8214 | "Calculate all possible completions for variables (or constants)." |
| 7620 | (let ((start (point))) | 8215 | (let ((start (point))) |
| 7621 | ;; Search for all reachable var declarations | 8216 | ;; Search for all reachable var declarations |
| 7622 | (verilog-beg-of-defun) | 8217 | (verilog-re-search-backward verilog-defun-re nil 'move) |
| 7623 | (save-excursion | 8218 | (save-excursion |
| 7624 | ;; Check var declarations | 8219 | ;; Check var declarations |
| 7625 | (verilog-get-completion-decl start)))) | 8220 | (verilog-get-completion-decl start)))) |
| @@ -8765,6 +9360,11 @@ Return an array of [outputs inouts inputs wire reg assign const gparam intf]." | |||
| 8765 | (t ; Bit width | 9360 | (t ; Bit width |
| 8766 | (setq vec (verilog-string-replace-matches | 9361 | (setq vec (verilog-string-replace-matches |
| 8767 | "\\s-+" "" nil nil keywd))))) | 9362 | "\\s-+" "" nil nil keywd))))) |
| 9363 | ;; int'(a) is cast, not declaration of a | ||
| 9364 | ((and (looking-at "'") | ||
| 9365 | (not rvalue)) | ||
| 9366 | (forward-char 1) | ||
| 9367 | (setq expect-signal nil rvalue nil)) | ||
| 8768 | ;; Normal or escaped identifier -- note we remember the \ if escaped | 9368 | ;; Normal or escaped identifier -- note we remember the \ if escaped |
| 8769 | ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)") | 9369 | ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)") |
| 8770 | (goto-char (match-end 0)) | 9370 | (goto-char (match-end 0)) |
| @@ -9702,9 +10302,9 @@ resolve it. If optional RECURSE is non-nil, recurse through \\=`includes. | |||
| 9702 | Localparams must be simple assignments to constants, or have their own | 10302 | Localparams must be simple assignments to constants, or have their own |
| 9703 | \"localparam\" label rather than a list of localparams. Thus: | 10303 | \"localparam\" label rather than a list of localparams. Thus: |
| 9704 | 10304 | ||
| 9705 | localparam X = 5, Y = 10; // Ok | 10305 | localparam X = 5, Y = 10; // Ok |
| 9706 | localparam X = {1\\='b1, 2\\='h2}; // Ok | 10306 | localparam X = {1\\='b1, 2\\='h2}; // Ok |
| 9707 | localparam X = {1\\='b1, 2\\='h2}, Y = 10; // Bad, make into 2 localparam lines | 10307 | localparam X = {1\\='b1, 2\\='h2}, Y = 10; // Bad, make into 2 localparam lines |
| 9708 | 10308 | ||
| 9709 | Defines must be simple text substitutions, one on a line, starting | 10309 | Defines must be simple text substitutions, one on a line, starting |
| 9710 | at the beginning of the line. Any ifdefs or multiline comments around the | 10310 | at the beginning of the line. Any ifdefs or multiline comments around the |
| @@ -9827,8 +10427,7 @@ variable over and over when many modules are compiled together, put a test | |||
| 9827 | around the inside each include file: | 10427 | around the inside each include file: |
| 9828 | 10428 | ||
| 9829 | foo.v (an include file): | 10429 | foo.v (an include file): |
| 9830 | \\=`ifdef _FOO_V // include if not already included | 10430 | \\=`ifndef _FOO_V // include if not already included |
| 9831 | \\=`else | ||
| 9832 | \\=`define _FOO_V | 10431 | \\=`define _FOO_V |
| 9833 | ... contents of file | 10432 | ... contents of file |
| 9834 | \\=`endif // _FOO_V" | 10433 | \\=`endif // _FOO_V" |
| @@ -10066,7 +10665,7 @@ Results are cached if inside `verilog-preserve-dir-cache'." | |||
| 10066 | ;; (prin1 (verilog-dir-files ".")) nil) | 10665 | ;; (prin1 (verilog-dir-files ".")) nil) |
| 10067 | 10666 | ||
| 10068 | (defun verilog-dir-file-exists-p (filename) | 10667 | (defun verilog-dir-file-exists-p (filename) |
| 10069 | "Return true if FILENAME exists. | 10668 | "Return non-nil if FILENAME exists. |
| 10070 | Like `file-exists-p' but results are cached if inside | 10669 | Like `file-exists-p' but results are cached if inside |
| 10071 | `verilog-preserve-dir-cache'." | 10670 | `verilog-preserve-dir-cache'." |
| 10072 | (let* ((dirname (file-name-directory filename)) | 10671 | (let* ((dirname (file-name-directory filename)) |
| @@ -10105,7 +10704,7 @@ Allows version control to check out the file if need be." | |||
| 10105 | modi))))) | 10704 | modi))))) |
| 10106 | 10705 | ||
| 10107 | (defun verilog-is-number (symbol) | 10706 | (defun verilog-is-number (symbol) |
| 10108 | "Return true if SYMBOL is number-like." | 10707 | "Return non-nil if SYMBOL is number-like." |
| 10109 | (or (string-match "^[0-9 \t:]+$" symbol) | 10708 | (or (string-match "^[0-9 \t:]+$" symbol) |
| 10110 | (string-match "^[---]*[0-9]+$" symbol) | 10709 | (string-match "^[---]*[0-9]+$" symbol) |
| 10111 | (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol))) | 10710 | (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol))) |
| @@ -10177,7 +10776,7 @@ Or, just the existing dirnames themselves if there are no wildcards." | |||
| 10177 | (unless dirnames | 10776 | (unless dirnames |
| 10178 | (error "`verilog-library-directories' should include at least `.'")) | 10777 | (error "`verilog-library-directories' should include at least `.'")) |
| 10179 | (save-match-data | 10778 | (save-match-data |
| 10180 | (setq dirnames (reverse dirnames)) ; not nreverse | 10779 | (setq dirnames (reverse dirnames)) ; not nreverse |
| 10181 | (let ((dirlist nil) | 10780 | (let ((dirlist nil) |
| 10182 | pattern dirfile dirfiles dirname root filename rest basefile) | 10781 | pattern dirfile dirfiles dirname root filename rest basefile) |
| 10183 | (setq dirnames (mapcar #'substitute-in-file-name dirnames)) | 10782 | (setq dirnames (mapcar #'substitute-in-file-name dirnames)) |
| @@ -10885,12 +11484,12 @@ This repairs those mis-inserted by an AUTOARG." | |||
| 10885 | (if (equal (match-string 3 out) ">>") | 11484 | (if (equal (match-string 3 out) ">>") |
| 10886 | (int-to-string (ash (string-to-number (match-string 2 out)) | 11485 | (int-to-string (ash (string-to-number (match-string 2 out)) |
| 10887 | (* -1 (string-to-number (match-string 4 out)))))) | 11486 | (* -1 (string-to-number (match-string 4 out)))))) |
| 10888 | (if (equal (match-string 3 out) "<<") | ||
| 10889 | (int-to-string (ash (string-to-number (match-string 2 out)) | ||
| 10890 | (string-to-number (match-string 4 out))))) | ||
| 10891 | (if (equal (match-string 3 out) ">>>") | 11487 | (if (equal (match-string 3 out) ">>>") |
| 10892 | (int-to-string (ash (string-to-number (match-string 2 out)) | 11488 | (int-to-string (ash (string-to-number (match-string 2 out)) |
| 10893 | (* -1 (string-to-number (match-string 4 out)))))) | 11489 | (* -1 (string-to-number (match-string 4 out)))))) |
| 11490 | (if (equal (match-string 3 out) "<<") | ||
| 11491 | (int-to-string (ash (string-to-number (match-string 2 out)) | ||
| 11492 | (string-to-number (match-string 4 out))))) | ||
| 10894 | (if (equal (match-string 3 out) "<<<") | 11493 | (if (equal (match-string 3 out) "<<<") |
| 10895 | (int-to-string (ash (string-to-number (match-string 2 out)) | 11494 | (int-to-string (ash (string-to-number (match-string 2 out)) |
| 10896 | (string-to-number (match-string 4 out))))) | 11495 | (string-to-number (match-string 4 out))))) |
| @@ -10920,7 +11519,7 @@ This repairs those mis-inserted by an AUTOARG." | |||
| 10920 | (ceiling (/ (log value) (log 2))))) | 11519 | (ceiling (/ (log value) (log 2))))) |
| 10921 | 11520 | ||
| 10922 | (defun verilog-typedef-name-p (variable-name) | 11521 | (defun verilog-typedef-name-p (variable-name) |
| 10923 | "Return true if the VARIABLE-NAME is a type definition." | 11522 | "Return non-nil if the VARIABLE-NAME is a type definition." |
| 10924 | (when verilog-typedef-regexp | 11523 | (when verilog-typedef-regexp |
| 10925 | (verilog-string-match-fold verilog-typedef-regexp variable-name))) | 11524 | (verilog-string-match-fold verilog-typedef-regexp variable-name))) |
| 10926 | 11525 | ||
| @@ -11678,7 +12277,7 @@ If PAR-VALUES replace final strings with these parameter values." | |||
| 11678 | (concat "." vl-modport) "") | 12277 | (concat "." vl-modport) "") |
| 11679 | dflt-bits)) | 12278 | dflt-bits)) |
| 11680 | ;; Find template | 12279 | ;; Find template |
| 11681 | (cond (tpl-ass ; Template of exact port name | 12280 | (cond (tpl-ass ; Template of exact port name |
| 11682 | (setq tpl-net (nth 1 tpl-ass))) | 12281 | (setq tpl-net (nth 1 tpl-ass))) |
| 11683 | ((nth 1 tpl-list) ; Wildcards in template, search them | 12282 | ((nth 1 tpl-list) ; Wildcards in template, search them |
| 11684 | (let ((wildcards (nth 1 tpl-list))) | 12283 | (let ((wildcards (nth 1 tpl-list))) |
| @@ -12240,7 +12839,9 @@ For more information see the \\[verilog-faq] and forums at URL | |||
| 12240 | (cond ((not verilog-auto-inst-first-any) | 12839 | (cond ((not verilog-auto-inst-first-any) |
| 12241 | (re-search-backward "," pt t) | 12840 | (re-search-backward "," pt t) |
| 12242 | (delete-char 1) | 12841 | (delete-char 1) |
| 12243 | (insert ");") | 12842 | (when (looking-at " ") |
| 12843 | (delete-char 1)) ; so we can align // Templated comments | ||
| 12844 | (insert ");") | ||
| 12244 | (search-forward "\n") ; Added by inst-port | 12845 | (search-forward "\n") ; Added by inst-port |
| 12245 | (delete-char -1) | 12846 | (delete-char -1) |
| 12246 | (if (search-forward ")" nil t) ; From user, moved up a line | 12847 | (if (search-forward ")" nil t) ; From user, moved up a line |
| @@ -14645,7 +15246,7 @@ and the case items." | |||
| 14645 | (if (not (member v1 verilog-keywords)) | 15246 | (if (not (member v1 verilog-keywords)) |
| 14646 | (save-excursion | 15247 | (save-excursion |
| 14647 | (setq verilog-sk-signal v1) | 15248 | (setq verilog-sk-signal v1) |
| 14648 | (verilog-beg-of-defun) | 15249 | (verilog-re-search-backward verilog-defun-re nil 'move) |
| 14649 | (verilog-end-of-statement) | 15250 | (verilog-end-of-statement) |
| 14650 | (verilog-forward-syntactic-ws) | 15251 | (verilog-forward-syntactic-ws) |
| 14651 | (verilog-sk-def-reg) | 15252 | (verilog-sk-def-reg) |
| @@ -14897,7 +15498,12 @@ Files are checked based on `verilog-library-flags'." | |||
| 14897 | '( | 15498 | '( |
| 14898 | verilog-active-low-regexp | 15499 | verilog-active-low-regexp |
| 14899 | verilog-after-save-font-hook | 15500 | verilog-after-save-font-hook |
| 15501 | verilog-align-assign-expr | ||
| 15502 | verilog-align-comment-distance | ||
| 15503 | verilog-align-decl-expr-comments | ||
| 14900 | verilog-align-ifelse | 15504 | verilog-align-ifelse |
| 15505 | verilog-align-typedef-regexp | ||
| 15506 | verilog-align-typedef-words | ||
| 14901 | verilog-assignment-delay | 15507 | verilog-assignment-delay |
| 14902 | verilog-auto-arg-sort | 15508 | verilog-auto-arg-sort |
| 14903 | verilog-auto-declare-nettype | 15509 | verilog-auto-declare-nettype |
| @@ -14942,13 +15548,17 @@ Files are checked based on `verilog-library-flags'." | |||
| 14942 | verilog-compiler | 15548 | verilog-compiler |
| 14943 | verilog-coverage | 15549 | verilog-coverage |
| 14944 | verilog-delete-auto-hook | 15550 | verilog-delete-auto-hook |
| 15551 | verilog-fontify-variables | ||
| 14945 | verilog-getopt-flags-hook | 15552 | verilog-getopt-flags-hook |
| 14946 | verilog-highlight-grouping-keywords | 15553 | verilog-highlight-grouping-keywords |
| 14947 | verilog-highlight-includes | 15554 | verilog-highlight-includes |
| 14948 | verilog-highlight-modules | 15555 | verilog-highlight-modules |
| 14949 | verilog-highlight-translate-off | 15556 | verilog-highlight-translate-off |
| 14950 | verilog-indent-begin-after-if | 15557 | verilog-indent-begin-after-if |
| 15558 | verilog-indent-class-inside-pkg | ||
| 14951 | verilog-indent-declaration-macros | 15559 | verilog-indent-declaration-macros |
| 15560 | verilog-indent-ignore-multiline-defines | ||
| 15561 | verilog-indent-ignore-regexp | ||
| 14952 | verilog-indent-level | 15562 | verilog-indent-level |
| 14953 | verilog-indent-level-behavioral | 15563 | verilog-indent-level-behavioral |
| 14954 | verilog-indent-level-declaration | 15564 | verilog-indent-level-declaration |