comparison lisp/progmodes/verilog-mode.el @ 92148:f991f10f15ec

Merge from emacs--rel--22 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1074
author Miles Bader <miles@gnu.org>
date Sun, 24 Feb 2008 10:09:07 +0000
parents 46c8bcf2455c 7d8f87158250
children d999f30304bc
comparison
equal deleted inserted replaced
92147:773ae07da318 92148:f991f10f15ec
113 ;; (This section is required to appease checkdoc.) 113 ;; (This section is required to appease checkdoc.)
114 114
115 ;;; Code: 115 ;;; Code:
116 116
117 ;; This variable will always hold the version number of the mode 117 ;; This variable will always hold the version number of the mode
118 (defconst verilog-mode-version "383" 118 (defconst verilog-mode-version "399"
119 "Version of this Verilog mode.") 119 "Version of this Verilog mode.")
120 (defconst verilog-mode-release-date "2008-01-07-GNU" 120 (defconst verilog-mode-release-date "2008-02-19-GNU"
121 "Release date of this Verilog mode.") 121 "Release date of this Verilog mode.")
122 (defconst verilog-mode-release-emacs t 122 (defconst verilog-mode-release-emacs t
123 "If non-nil, this version of Verilog mode was released with Emacs itself.") 123 "If non-nil, this version of Verilog mode was released with Emacs itself.")
124 124
125 (defun verilog-version () 125 (defun verilog-version ()
157 (error nil)) 157 (error nil))
158 (condition-case nil 158 (condition-case nil
159 (if (fboundp 'store-match-data) 159 (if (fboundp 'store-match-data)
160 nil ;; fab 160 nil ;; fab
161 (defmacro store-match-data (&rest args) nil)) 161 (defmacro store-match-data (&rest args) nil))
162 (error nil))
163 (condition-case nil
164 (if (boundp 'current-menubar)
165 nil ;; great
166 (progn
167 (defmacro add-submenu (&rest args) nil))
168 )
169 (error nil)) 162 (error nil))
170 (condition-case nil 163 (condition-case nil
171 (if (fboundp 'char-before) 164 (if (fboundp 'char-before)
172 nil ;; great 165 nil ;; great
173 (defmacro char-before (&rest body) 166 (defmacro char-before (&rest body)
955 (define-key map "\C-c\C-h" 'verilog-header) 948 (define-key map "\C-c\C-h" 'verilog-header)
956 map) 949 map)
957 "Keymap used in Verilog mode.") 950 "Keymap used in Verilog mode.")
958 951
959 ;; menus 952 ;; menus
960 (defvar verilog-xemacs-menu 953 (easy-menu-define
954 verilog-menu verilog-mode-map "Menu for Verilog mode"
961 `("Verilog" 955 `("Verilog"
962 ("Choose Compilation Action" 956 ("Choose Compilation Action"
963 ["None" 957 ["None"
964 (progn 958 (progn
965 (setq verilog-tool nil) 959 (setq verilog-tool nil)
990 (verilog-set-compile-command)) 984 (verilog-set-compile-command))
991 :style radio 985 :style radio
992 :selected (equal verilog-tool `verilog-compiler)] 986 :selected (equal verilog-tool `verilog-compiler)]
993 ) 987 )
994 ("Move" 988 ("Move"
995 ,(if (featurep 'xemacs) 989 ["Beginning of function" verilog-beg-of-defun
996 (progn 990 :keys "C-M-a"]
997 ["Beginning of function" verilog-beg-of-defun t] 991 ["End of function" verilog-end-of-defun
998 ["End of function" verilog-end-of-defun t] 992 :keys "C-M-e"]
999 ["Mark function" verilog-mark-defun t]) 993 ["Mark function" verilog-mark-defun
1000 ["Beginning of function" beginning-of-defun t] 994 :keys "C-M-h"]
1001 ["End of function" end-of-defun t]
1002 ["Mark function" mark-defun t])
1003
1004 ["Goto function/module" verilog-goto-defun t] 995 ["Goto function/module" verilog-goto-defun t]
1005 ["Move to beginning of block" electric-verilog-backward-sexp t] 996 ["Move to beginning of block" electric-verilog-backward-sexp t]
1006 ["Move to end of block" electric-verilog-forward-sexp t] 997 ["Move to end of block" electric-verilog-forward-sexp t]
1007 ) 998 )
1008 ("Comments" 999 ("Comments"
1055 ) 1046 )
1056 "----" 1047 "----"
1057 ["Submit bug report" verilog-submit-bug-report t] 1048 ["Submit bug report" verilog-submit-bug-report t]
1058 ["Version and FAQ" verilog-faq t] 1049 ["Version and FAQ" verilog-faq t]
1059 ["Customize Verilog Mode..." verilog-customize t] 1050 ["Customize Verilog Mode..." verilog-customize t]
1060 ["Customize Verilog Fonts & Colors" verilog-font-customize t] 1051 ["Customize Verilog Fonts & Colors" verilog-font-customize t]))
1061 ) 1052
1062 "Emacs menu for Verilog mode." 1053 (easy-menu-define
1063 ) 1054 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1064 (defvar verilog-statement-menu
1065 '("Statements" 1055 '("Statements"
1066 ["Header" verilog-sk-header t] 1056 ["Header" verilog-sk-header t]
1067 ["Comment" verilog-sk-comment t] 1057 ["Comment" verilog-sk-comment t]
1068 "----" 1058 "----"
1069 ["Module" verilog-sk-module t] 1059 ["Module" verilog-sk-module t]
1090 ["While" verilog-sk-while t] 1080 ["While" verilog-sk-while t]
1091 ["Fork" verilog-sk-fork t] 1081 ["Fork" verilog-sk-fork t]
1092 ["Repeat" verilog-sk-repeat t] 1082 ["Repeat" verilog-sk-repeat t]
1093 ["Case" verilog-sk-case t] 1083 ["Case" verilog-sk-case t]
1094 ["Casex" verilog-sk-casex t] 1084 ["Casex" verilog-sk-casex t]
1095 ["Casez" verilog-sk-casez t] 1085 ["Casez" verilog-sk-casez t]))
1096 )
1097 "Menu for statement templates in Verilog.")
1098
1099 (easy-menu-define verilog-menu verilog-mode-map "Menu for Verilog mode"
1100 verilog-xemacs-menu)
1101 (easy-menu-define verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1102 verilog-statement-menu)
1103 1086
1104 (defvar verilog-mode-abbrev-table nil 1087 (defvar verilog-mode-abbrev-table nil
1105 "Abbrev table in use in Verilog-mode buffers.") 1088 "Abbrev table in use in Verilog-mode buffers.")
1106 1089
1107 (define-abbrev-table 'verilog-mode-abbrev-table ()) 1090 (define-abbrev-table 'verilog-mode-abbrev-table ())
1449 ;; verilog-forward-sexp and verilog-calc-indent 1432 ;; verilog-forward-sexp and verilog-calc-indent
1450 1433
1451 (defconst verilog-beg-block-re-ordered 1434 (defconst verilog-beg-block-re-ordered
1452 ( concat "\\<" 1435 ( concat "\\<"
1453 "\\(begin\\)" ;1 1436 "\\(begin\\)" ;1
1454 "\\|\\(randcase\\|\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)" ; 2 1437 "\\|\\(randcase\\|\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)" ; 2,3
1455 ;; "\\|\\(randcase\\|case[xz]?\\)" ; 2 1438 "\\|\\(\\(disable\\s-+\\)?fork\\)" ;4
1456 "\\|\\(fork\\)" ;3 1439 "\\|\\(class\\)" ;5
1457 "\\|\\(class\\)" ;4 1440 "\\|\\(table\\)" ;6
1458 "\\|\\(table\\)" ;5 1441 "\\|\\(specify\\)" ;7
1459 "\\|\\(specify\\)" ;6 1442 "\\|\\(function\\)" ;8
1460 "\\|\\(function\\)" ;7 1443 "\\|\\(task\\)" ;9
1461 "\\|\\(task\\)" ;8 1444 "\\|\\(generate\\)" ;10
1462 "\\|\\(generate\\)" ;9 1445 "\\|\\(covergroup\\)" ;11
1463 "\\|\\(covergroup\\)" ;10 1446 "\\|\\(property\\)" ;12
1464 "\\|\\(property\\)" ;11 1447 "\\|\\(\\(rand\\)?sequence\\)" ;13
1465 "\\|\\(\\(rand\\)?sequence\\)" ;12 1448 "\\|\\(clocking\\)" ;14
1466 "\\|\\(clocking\\)" ;13
1467 "\\>")) 1449 "\\>"))
1468 1450
1469 (defconst verilog-end-block-ordered-rry 1451 (defconst verilog-end-block-ordered-rry
1470 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" 1452 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
1471 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" 1453 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
1524 )))) 1506 ))))
1525 (defconst verilog-declaration-core-re 1507 (defconst verilog-declaration-core-re
1526 (eval-when-compile 1508 (eval-when-compile
1527 (verilog-regexp-words 1509 (verilog-regexp-words
1528 `( 1510 `(
1511 ;; port direction (by themselves)
1512 "inout" "input" "output"
1529 ;; integer_atom_type 1513 ;; integer_atom_type
1530 "byte" "shortint" "int" "longint" "integer" "time" 1514 "byte" "shortint" "int" "longint" "integer" "time"
1531 ;; integer_vector_type 1515 ;; integer_vector_type
1532 "bit" "logic" "reg" 1516 "bit" "logic" "reg"
1533 ;; non_integer_type 1517 ;; non_integer_type
1570 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) 1554 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
1571 (defconst verilog-zero-indent-re 1555 (defconst verilog-zero-indent-re
1572 (concat verilog-defun-re "\\|" verilog-end-defun-re)) 1556 (concat verilog-defun-re "\\|" verilog-end-defun-re))
1573 1557
1574 (defconst verilog-behavioral-block-beg-re 1558 (defconst verilog-behavioral-block-beg-re
1575 (concat "\\(\\<initial\\>\\|\\<final\\>\\|\\<always\\>\\|\\<always_comb\\>\\|\\<always_ff\\>\\|" 1559 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
1576 "\\<always_latch\\>\\|\\<function\\>\\|\\<task\\>\\)")) 1560 "function" "task"))))
1577 1561
1578 (defconst verilog-indent-re 1562 (defconst verilog-indent-re
1579 (eval-when-compile 1563 (eval-when-compile
1580 (verilog-regexp-words 1564 (verilog-regexp-words
1581 `( 1565 `(
1636 (eval-when-compile 1620 (eval-when-compile
1637 (verilog-regexp-words 1621 (verilog-regexp-words
1638 `( 1622 `(
1639 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass" 1623 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
1640 )))) 1624 ))))
1625 (defconst verilog-disable-fork-re "disable\\s-+fork")
1641 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") 1626 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?")
1642 (defconst verilog-extended-complete-re 1627 (defconst verilog-extended-complete-re
1643 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)" 1628 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)"
1644 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)" 1629 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)"
1645 "\\|" verilog-extended-case-re )) 1630 "\\|" verilog-extended-case-re ))
1811 (:foreground "orange1" :bold t )) 1796 (:foreground "orange1" :bold t ))
1812 (t (:italic t))) 1797 (t (:italic t)))
1813 "Font lock mode face used to highlight AMS keywords." 1798 "Font lock mode face used to highlight AMS keywords."
1814 :group 'font-lock-highlighting-faces) 1799 :group 'font-lock-highlighting-faces)
1815 1800
1801 (defvar verilog-font-grouping-keywords-face
1802 'verilog-font-lock-grouping-keywords-face
1803 "Font to use for Verilog Grouping Keywords (such as begin..end).")
1804 (defface verilog-font-lock-grouping-keywords-face
1805 '((((class color)
1806 (background light))
1807 (:foreground "red4" :bold t ))
1808 (((class color)
1809 (background dark))
1810 (:foreground "red4" :bold t ))
1811 (t (:italic t)))
1812 "Font lock mode face used to highlight verilog grouping keywords."
1813 :group 'font-lock-highlighting-faces)
1814
1816 (let* ((verilog-type-font-keywords 1815 (let* ((verilog-type-font-keywords
1817 (eval-when-compile 1816 (eval-when-compile
1818 (verilog-regexp-opt 1817 (verilog-regexp-opt
1819 '( 1818 '(
1820 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam" 1819 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
1875 1874
1876 (verilog-font-keywords 1875 (verilog-font-keywords
1877 (eval-when-compile 1876 (eval-when-compile
1878 (verilog-regexp-opt 1877 (verilog-regexp-opt
1879 '( 1878 '(
1880 "assign" "begin" "case" "casex" "casez" "randcase" "deassign" 1879 "assign" "case" "casex" "casez" "randcase" "deassign"
1881 "default" "disable" "else" "end" "endcase" "endfunction" 1880 "default" "disable" "else" "endcase" "endfunction"
1882 "endgenerate" "endinterface" "endmodule" "endprimitive" 1881 "endgenerate" "endinterface" "endmodule" "endprimitive"
1883 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break" 1882 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
1884 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial" 1883 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
1885 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge" 1884 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
1886 "package" "endpackage" "always" "always_comb" "always_ff" 1885 "package" "endpackage" "always" "always_comb" "always_ff"
1887 "always_latch" "posedge" "primitive" "priority" "release" 1886 "always_latch" "posedge" "primitive" "priority" "release"
1888 "repeat" "specify" "table" "task" "unique" "wait" "while" 1887 "repeat" "specify" "table" "task" "unique" "wait" "while"
1889 "class" "program" "endclass" "endprogram" 1888 "class" "program" "endclass" "endprogram"
1890 ) nil )))) 1889 ) nil )))
1890
1891 (verilog-font-grouping-keywords
1892 (eval-when-compile
1893 (verilog-regexp-opt
1894 '( "begin" "end" ) nil ))))
1891 1895
1892 (setq verilog-font-lock-keywords 1896 (setq verilog-font-lock-keywords
1893 (list 1897 (list
1894 ;; Fontify all builtin keywords 1898 ;; Fontify all builtin keywords
1895 (concat "\\<\\(" verilog-font-keywords "\\|" 1899 (concat "\\<\\(" verilog-font-keywords "\\|"
1896 ;; And user/system tasks and functions 1900 ;; And user/system tasks and functions
1897 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*" 1901 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
1898 "\\)\\>") 1902 "\\)\\>")
1899 ;; Fontify all types 1903 ;; Fontify all types
1900 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>") 1904 (cons (concat "\\(\\<" verilog-font-grouping-keywords "\\)\\>")
1905 'verilog-font-lock-ams-face)
1906 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
1901 'font-lock-type-face) 1907 'font-lock-type-face)
1902 ;; Fontify IEEE-P1800 keywords appropriately 1908 ;; Fontify IEEE-P1800 keywords appropriately
1903 (if verilog-highlight-p1800-keywords 1909 (if verilog-highlight-p1800-keywords
1904 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") 1910 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>")
1905 'verilog-font-lock-p1800-face) 1911 'verilog-font-lock-p1800-face)
2062 (if (not (looking-at "\\<")) 2068 (if (not (looking-at "\\<"))
2063 (forward-word -1)) 2069 (forward-word -1))
2064 (cond 2070 (cond
2065 ((verilog-skip-forward-comment-or-string) 2071 ((verilog-skip-forward-comment-or-string)
2066 (verilog-forward-syntactic-ws)) 2072 (verilog-forward-syntactic-ws))
2067 ((looking-at verilog-beg-block-re-ordered);; begin|case|fork|class|table|specify|function|task|generate|covergroup|property|sequence|clocking 2073 ((looking-at verilog-beg-block-re-ordered) ;; begin|(case)|xx|(fork)|class|table|specify|function|task|generate|covergroup|property|sequence|clocking
2068 (cond 2074 (cond
2069 ((match-end 1) ; end 2075 ((match-end 1) ; end
2070 ;; Search forward for matching begin 2076 ;; Search forward for matching begin
2071 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )) 2077 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
2072 ((match-end 2) ; endcase 2078 ((match-end 2) ; endcase
2073 ;; Search forward for matching case 2079 ;; Search forward for matching case
2074 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) 2080 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
2075 ((match-end 3) ; join 2081 (setq md 3) ;; ender is third item in regexp
2076 ;; Search forward for matching fork 2082 )
2077 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) 2083 ((match-end 4) ; join
2078 ((match-end 4) ; endclass 2084 ;; might be "disable fork"
2085 (if (or
2086 (looking-at verilog-disable-fork-re)
2087 (and (looking-at "fork")
2088 (progn
2089 (forward-word -1)
2090 (looking-at verilog-disable-fork-re))))
2091 (progn
2092 (goto-char (match-end 0))
2093 (forward-word)
2094 (setq reg nil))
2095 (progn
2096 ;; Search forward for matching fork
2097 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))))
2098 ((match-end 5) ; endclass
2079 ;; Search forward for matching class 2099 ;; Search forward for matching class
2080 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) 2100 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
2081 ((match-end 5) ; endtable 2101 ((match-end 6) ; endtable
2082 ;; Search forward for matching table 2102 ;; Search forward for matching table
2083 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) 2103 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
2084 ((match-end 6) ; endspecify 2104 ((match-end 7) ; endspecify
2085 ;; Search forward for matching specify 2105 ;; Search forward for matching specify
2086 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) 2106 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
2087 ((match-end 7) ; endfunction 2107 ((match-end 8) ; endfunction
2088 ;; Search forward for matching function 2108 ;; Search forward for matching function
2089 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) 2109 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
2090 ((match-end 8) ; endtask 2110 ((match-end 9) ; endtask
2091 ;; Search forward for matching task 2111 ;; Search forward for matching task
2092 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) 2112 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
2093 ((match-end 9) ; endgenerate 2113 ((match-end 10) ; endgenerate
2094 ;; Search forward for matching generate 2114 ;; Search forward for matching generate
2095 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) 2115 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
2096 ((match-end 10) ; endgroup 2116 ((match-end 11) ; endgroup
2097 ;; Search forward for matching covergroup 2117 ;; Search forward for matching covergroup
2098 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) 2118 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
2099 ((match-end 11) ; endproperty 2119 ((match-end 12) ; endproperty
2100 ;; Search forward for matching property 2120 ;; Search forward for matching property
2101 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) 2121 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
2102 ((match-end 12) ; endsequence 2122 ((match-end 13) ; endsequence
2103 ;; Search forward for matching sequence 2123 ;; Search forward for matching sequence
2104 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ) 2124 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
2105 (setq md 3)) ; 3 to get to endsequence in the reg above 2125 (setq md 3)) ; 3 to get to endsequence in the reg above
2106 ((match-end 13) ; endclocking 2126 ((match-end 14) ; endclocking
2107 ;; Search forward for matching clocking 2127 ;; Search forward for matching clocking
2108 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" ))) 2128 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
2109 (if (forward-word 1) 2129 (if (and reg
2130 (forward-word 1))
2110 (catch 'skip 2131 (catch 'skip
2111 (let ((nest 1)) 2132 (let ((nest 1))
2112 (while (verilog-re-search-forward reg nil 'move) 2133 (while (verilog-re-search-forward reg nil 'move)
2113 (cond 2134 (cond
2114 ((match-end md) ; the closer in reg, so we are climbing out 2135 ((match-end md) ; the closer in reg, so we are climbing out
2341 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables 2362 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
2342 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t)) 2363 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
2343 2364
2344 ;; Setting up menus 2365 ;; Setting up menus
2345 (when (featurep 'xemacs) 2366 (when (featurep 'xemacs)
2346 (when (and current-menubar 2367 (easy-menu-add verilog-stmt-menu)
2347 (not (assoc "Verilog" current-menubar))) 2368 (easy-menu-add verilog-menu)
2348 ;; (set-buffer-menubar (copy-sequence current-menubar)) 2369 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
2349 (add-submenu nil verilog-xemacs-menu)
2350 (add-submenu nil verilog-stmt-menu)))
2351 2370
2352 ;; Stuff for GNU emacs 2371 ;; Stuff for GNU emacs
2353 (set (make-local-variable 'font-lock-defaults) 2372 (set (make-local-variable 'font-lock-defaults)
2354 '((verilog-font-lock-keywords verilog-font-lock-keywords-1 2373 '((verilog-font-lock-keywords verilog-font-lock-keywords-1
2355 verilog-font-lock-keywords-2 2374 verilog-font-lock-keywords-2
2639 2658
2640 (defun verilog-mark-defun () 2659 (defun verilog-mark-defun ()
2641 "Mark the current Verilog function (or procedure). 2660 "Mark the current Verilog function (or procedure).
2642 This puts the mark at the end, and point at the beginning." 2661 This puts the mark at the end, and point at the beginning."
2643 (interactive) 2662 (interactive)
2644 (when (featurep 'xemacs) 2663 (if (featurep 'xemacs)
2645 (push-mark (point)) 2664 (progn
2646 (verilog-end-of-defun) 2665 (push-mark (point))
2647 (push-mark (point)) 2666 (verilog-end-of-defun)
2648 (verilog-beg-of-defun) 2667 (push-mark (point))
2649 (if (fboundp 'zmacs-activate-region) 2668 (verilog-beg-of-defun)
2650 (zmacs-activate-region)))) 2669 (if (fboundp 'zmacs-activate-region)
2670 (zmacs-activate-region)))
2671 (mark-defun)))
2651 2672
2652 (defun verilog-comment-region (start end) 2673 (defun verilog-comment-region (start end)
2653 ; checkdoc-params: (start end) 2674 ; checkdoc-params: (start end)
2654 "Put the region into a Verilog comment. 2675 "Put the region into a Verilog comment.
2655 The comments that are in this area are \"deformed\": 2676 The comments that are in this area are \"deformed\":
3930 (verilog-beg-of-statement) 3951 (verilog-beg-of-statement)
3931 (if (looking-at verilog-extended-case-re) 3952 (if (looking-at verilog-extended-case-re)
3932 (throw 'nesting 'case) 3953 (throw 'nesting 'case)
3933 (goto-char here))) 3954 (goto-char here)))
3934 (throw 'nesting 'case)) 3955 (throw 'nesting 'case))
3956
3957 ((match-end 4) ; *sigh* could be "disable fork"
3958 (let ((here (point)))
3959 (verilog-beg-of-statement)
3960 (if (looking-at verilog-disable-fork-re)
3961 t ; is disable fork, this is a normal statement
3962 (progn ; or is fork, starts a new block
3963 (goto-char here)
3964 (throw 'nesting 'block)))))
3965
3935 3966
3936 ;; need to consider typedef struct here... 3967 ;; need to consider typedef struct here...
3937 ((looking-at "\\<class\\|struct\\|function\\|task\\|property\\>") 3968 ((looking-at "\\<class\\|struct\\|function\\|task\\|property\\>")
3938 ; *sigh* These words have an optional prefix: 3969 ; *sigh* These words have an optional prefix:
3939 ; extern {virtual|protected}? function a(); 3970 ; extern {virtual|protected}? function a();
4165 t 4196 t
4166 (forward-word -1) 4197 (forward-word -1)
4167 (cond 4198 (cond
4168 ((looking-at "\\<else\\>") 4199 ((looking-at "\\<else\\>")
4169 t) 4200 t)
4201 ((looking-at verilog-behavioral-block-beg-re)
4202 t)
4170 ((looking-at verilog-indent-re) 4203 ((looking-at verilog-indent-re)
4171 nil) 4204 nil)
4172 (t 4205 (t
4173 (let 4206 (let
4174 ((back (point))) 4207 ((back (point)))
4680 (re-search-backward "//" nil t) 4713 (re-search-backward "//" nil t)
4681 (current-column))))) 4714 (current-column)))))
4682 4715
4683 ;; 4716 ;;
4684 4717
4685 (defun verilog-pretty-declarations () 4718 (defun verilog-pretty-declarations (&optional quiet)
4686 "Line up declarations around point." 4719 "Line up declarations around point."
4687 (interactive) 4720 (interactive)
4688 (save-excursion 4721 (save-excursion
4689 (if (progn 4722 (if (progn
4690 (verilog-beg-of-statement-1) 4723 (verilog-beg-of-statement-1)
4724 (verilog-do-indent (verilog-calculate-indent)) 4757 (verilog-do-indent (verilog-calculate-indent))
4725 (verilog-forward-ws&directives) 4758 (verilog-forward-ws&directives)
4726 (current-column)))) 4759 (current-column))))
4727 (goto-char end) 4760 (goto-char end)
4728 (goto-char start) 4761 (goto-char start)
4729 (if (> (- end start) 100) 4762 (if (and (not quiet)
4763 (> (- end start) 100))
4730 (message "Lining up declarations..(please stand by)")) 4764 (message "Lining up declarations..(please stand by)"))
4731 ;; Get the beginning of line indent first 4765 ;; Get the beginning of line indent first
4732 (while (progn (setq e (marker-position edpos)) 4766 (while (progn (setq e (marker-position edpos))
4733 (< (point) e)) 4767 (< (point) e))
4734 (cond 4768 (cond
4749 (goto-char start) 4783 (goto-char start)
4750 (while (progn (setq e (marker-position edpos)) 4784 (while (progn (setq e (marker-position edpos))
4751 (setq r (- e (point))) 4785 (setq r (- e (point)))
4752 (> r 0)) 4786 (> r 0))
4753 (setq e (point)) 4787 (setq e (point))
4754 (message "%d" r) 4788 (unless quiet (message "%d" r))
4755 (cond 4789 (cond
4756 ((or (and verilog-indent-declaration-macros 4790 ((or (and verilog-indent-declaration-macros
4757 (looking-at verilog-declaration-re-1-macro)) 4791 (looking-at verilog-declaration-re-1-macro))
4758 (looking-at verilog-declaration-re-1-no-macro)) 4792 (looking-at verilog-declaration-re-1-no-macro))
4759 (let ((p (match-end 0))) 4793 (let ((p (match-end 0)))
4774 (t ; Must be comment or white space 4808 (t ; Must be comment or white space
4775 (goto-char e) 4809 (goto-char e)
4776 (verilog-forward-ws&directives) 4810 (verilog-forward-ws&directives)
4777 (forward-line -1))) 4811 (forward-line -1)))
4778 (forward-line 1)) 4812 (forward-line 1))
4779 (message ""))))) 4813 (unless quiet (message ""))))))
4780 4814
4781 (defun verilog-pretty-expr (&optional myre) 4815 (defun verilog-pretty-expr (&optional quiet myre)
4782 "Line up expressions around point, or optional regexp MYRE." 4816 "Line up expressions around point, or optional regexp MYRE."
4783 (interactive "sRegular Expression: ((<|:)?=) ") 4817 (interactive "sRegular Expression: ((<|:)?=) ")
4784 (save-excursion 4818 (save-excursion
4785 (if (or (eq myre nil) 4819 (if (or (eq myre nil)
4786 (string-equal myre "")) 4820 (string-equal myre ""))
4787 (setq myre "\\(<\\|:\\)?=")) 4821 (setq myre "\\(<\\|:\\)?="))
4788 ; (setq myre (concat "\\(^[^;" myre "]*\\)\\([" myre "]\\)")) 4822 (setq myre (concat "\\(^[^;#:<=>]*\\)\\(" myre "\\)"))
4789 (setq myre (concat "\\(^[^;#:?=]*\\)\\([" myre "]\\)")) 4823 (let ((rexp(concat "^\\s-*" verilog-complete-reg)))
4790 (beginning-of-line) 4824 (beginning-of-line)
4791 (if (and (not (looking-at (concat "^\\s-*" verilog-complete-reg))) 4825 (if (and (not (looking-at rexp ))
4792 (looking-at myre)) 4826 (looking-at myre))
4793 (let* ((here (point)) 4827 (let* ((here (point))
4794 (e) (r) 4828 (e) (r)
4795 (start 4829 (start
4796 (progn 4830 (progn
4797 (beginning-of-line) 4831 (beginning-of-line)
4798 (setq e (point))
4799 (verilog-backward-syntactic-ws)
4800 (beginning-of-line)
4801 (while (and (not (looking-at (concat "^\\s-*" verilog-complete-reg)))
4802 (looking-at myre)
4803 (not (bobp)))
4804 (setq e (point)) 4832 (setq e (point))
4805 (verilog-backward-syntactic-ws) 4833 (verilog-backward-syntactic-ws)
4806 (beginning-of-line) 4834 (beginning-of-line)
4807 ) ;Ack, need to grok `define 4835 (while (and (not (looking-at rexp ))
4808 e)) 4836 (looking-at myre)
4809 (end 4837 (not (bobp))
4810 (progn 4838 )
4811 (goto-char here) 4839 (setq e (point))
4812 (end-of-line) 4840 (verilog-backward-syntactic-ws)
4813 (setq e (point)) ;Might be on last line 4841 (beginning-of-line)
4814 (verilog-forward-syntactic-ws) 4842 ) ;Ack, need to grok `define
4815 (beginning-of-line) 4843 e))
4816 (while (and (not (looking-at 4844 (end
4817 (concat "^\\s-*" verilog-complete-reg))) 4845 (progn
4818 (looking-at myre)) 4846 (goto-char here)
4819 (end-of-line) 4847 (end-of-line)
4820 (setq e (point)) 4848 (setq e (point)) ;Might be on last line
4821 (verilog-forward-syntactic-ws) 4849 (verilog-forward-syntactic-ws)
4822 (beginning-of-line)) 4850 (beginning-of-line)
4823 e)) 4851 (while (and (not (looking-at rexp ))
4824 (edpos (set-marker (make-marker) end)) 4852 (looking-at myre))
4825 (ind)) 4853 (end-of-line)
4826 (goto-char start) 4854 (setq e (point))
4827 (verilog-do-indent (verilog-calculate-indent)) 4855 (verilog-forward-syntactic-ws)
4828 (if (> (- end start) 100) 4856 (beginning-of-line)
4829 (message "Lining up expressions..(please stand by)")) 4857 )
4830 4858 e))
4831 ;; Set indent to minimum throughout region 4859 (edpos (set-marker (make-marker) end))
4832 (while (< (point) (marker-position edpos)) 4860 (ind)
4833 (beginning-of-line) 4861 )
4834 (verilog-just-one-space myre) 4862 (goto-char start)
4835 (end-of-line) 4863 (verilog-do-indent (verilog-calculate-indent))
4836 (verilog-forward-syntactic-ws)) 4864 (if (and (not quiet)
4837 4865 (> (- end start) 100))
4838 ;; Now find biggest prefix 4866 (message "Lining up expressions..(please stand by)"))
4839 (setq ind (verilog-get-lineup-indent-2 myre start edpos)) 4867
4840 4868 ;; Set indent to minimum throughout region
4841 ;; Now indent each line. 4869 (while (< (point) (marker-position edpos))
4842 (goto-char start) 4870 (beginning-of-line)
4843 (while (progn (setq e (marker-position edpos)) 4871 (verilog-just-one-space myre)
4844 (setq r (- e (point))) 4872 (end-of-line)
4845 (> r 0)) 4873 (verilog-forward-syntactic-ws)
4846 (setq e (point)) 4874 )
4847 (message "%d" r) 4875
4848 (cond 4876 ;; Now find biggest prefix
4849 ((looking-at myre) 4877 (setq ind (verilog-get-lineup-indent-2 myre start edpos))
4850 (goto-char (match-end 1)) 4878
4851 (if (eq (char-after) ?=) 4879 ;; Now indent each line.
4852 (indent-to (1+ ind)) ; line up the = of the <= with surrounding = 4880 (goto-char start)
4853 (indent-to ind))) 4881 (while (progn (setq e (marker-position edpos))
4854 ((verilog-continued-line-1 start) 4882 (setq r (- e (point)))
4855 (goto-char e) 4883 (> r 0))
4856 (indent-line-to ind)) 4884 (setq e (point))
4857 (t ; Must be comment or white space 4885 (if (not quiet) (message "%d" r))
4858 (goto-char e) 4886 (cond
4859 (verilog-forward-ws&directives) 4887 ((looking-at myre)
4860 (forward-line -1))) 4888 (goto-char (match-end 1))
4861 (forward-line 1)) 4889 (if (not (verilog-parenthesis-depth)) ;; ignore parenthsized exprs
4862 (message ""))))) 4890 (if (eq (char-after) ?=)
4891 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
4892 (indent-to ind)
4893 )))
4894 ((verilog-continued-line-1 start)
4895 (goto-char e)
4896 (indent-line-to ind))
4897 (t ; Must be comment or white space
4898 (goto-char e)
4899 (verilog-forward-ws&directives)
4900 (forward-line -1))
4901 )
4902 (forward-line 1))
4903 (unless quiet (message ""))
4904 )))))
4863 4905
4864 (defun verilog-just-one-space (myre) 4906 (defun verilog-just-one-space (myre)
4865 "Remove extra spaces around regular expression MYRE." 4907 "Remove extra spaces around regular expression MYRE."
4866 (interactive) 4908 (interactive)
4867 (if (and (not(looking-at verilog-complete-reg)) 4909 (if (and (not(looking-at verilog-complete-reg))
4871 (progn 4913 (progn
4872 (goto-char p2) 4914 (goto-char p2)
4873 (if (looking-at "\\s-") (just-one-space)) 4915 (if (looking-at "\\s-") (just-one-space))
4874 (goto-char p1) 4916 (goto-char p1)
4875 (forward-char -1) 4917 (forward-char -1)
4876 (if (looking-at "\\s-") (just-one-space))))) 4918 (if (looking-at "\\s-") (just-one-space))
4877 (message "")) 4919 ))))
4878 4920
4879 (defun verilog-indent-declaration (baseind) 4921 (defun verilog-indent-declaration (baseind)
4880 "Indent current lines as declaration. 4922 "Indent current lines as declaration.
4881 Line up the variable names based on previous declaration's indentation. 4923 Line up the variable names based on previous declaration's indentation.
4882 BASEIND is the base indent to offset everything." 4924 BASEIND is the base indent to offset everything."
4973 (let ((ind 0) e) 5015 (let ((ind 0) e)
4974 (goto-char b) 5016 (goto-char b)
4975 ;; Get rightmost position 5017 ;; Get rightmost position
4976 (while (progn (setq e (marker-position edpos)) 5018 (while (progn (setq e (marker-position edpos))
4977 (< (point) e)) 5019 (< (point) e))
4978 (if (verilog-re-search-forward myre e 'move) 5020 (if (and (verilog-re-search-forward myre e 'move)
5021 (not (verilog-parenthesis-depth))) ;; skip parenthsized exprs
4979 (progn 5022 (progn
4980 (goto-char (match-end 0)) 5023 (goto-char (match-beginning 2))
4981 (verilog-backward-syntactic-ws) 5024 (verilog-backward-syntactic-ws)
4982 (if (> (current-column) ind) 5025 (if (> (current-column) ind)
4983 (setq ind (current-column))) 5026 (setq ind (current-column)))
4984 (goto-char (match-end 0))))) 5027 (goto-char (match-end 0)))
5028 ))
4985 (if (> ind 0) 5029 (if (> ind 0)
4986 (1+ ind) 5030 (1+ ind)
4987 ;; No lineup-string found 5031 ;; No lineup-string found
4988 (goto-char b) 5032 (goto-char b)
4989 (end-of-line) 5033 (end-of-line)
5453 (beginning-of-line)) 5497 (beginning-of-line))
5454 pt) 5498 pt)
5455 (verilog-goto-defun-file label)))) 5499 (verilog-goto-defun-file label))))
5456 5500
5457 ;; Eliminate compile warning 5501 ;; Eliminate compile warning
5458 (eval-when-compile 5502 (defvar occur-pos-list)
5459 (if (not (boundp 'occur-pos-list))
5460 (defvar occur-pos-list nil "Backward compatibility occur positions.")))
5461 5503
5462 (defun verilog-showscopes () 5504 (defun verilog-showscopes ()
5463 "List all scopes in this module." 5505 "List all scopes in this module."
5464 (interactive) 5506 (interactive)
5465 (let ((buffer (current-buffer)) 5507 (let ((buffer (current-buffer))
8497 (verilog-modi-cache-add-wires modi sig-list) 8539 (verilog-modi-cache-add-wires modi sig-list)
8498 (verilog-insert-indent "// End of automatics\n") 8540 (verilog-insert-indent "// End of automatics\n")
8499 (when nil ;; Too slow on huge modules, plus makes everyone's module change 8541 (when nil ;; Too slow on huge modules, plus makes everyone's module change
8500 (beginning-of-line) 8542 (beginning-of-line)
8501 (setq pnt (point)) 8543 (setq pnt (point))
8502 (verilog-pretty-declarations) 8544 (verilog-pretty-declarations quiet)
8503 (goto-char pnt) 8545 (goto-char pnt)
8504 (verilog-pretty-expr "//")))))) 8546 (verilog-pretty-expr "//"))))))
8505 8547
8506 (defun verilog-auto-output () 8548 (defun verilog-auto-output ()
8507 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto]. 8549 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
9812 > "always @ ( /*AUTOSENSE*/ ) begin\n" 9854 > "always @ ( /*AUTOSENSE*/ ) begin\n"
9813 > "case (" '(verilog-sk-prompt-state-selector) ") " \n 9855 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
9814 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n ) 9856 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
9815 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil) 9857 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
9816 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)) 9858 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
9817
9818 ;; Eliminate compile warning
9819 (eval-when-compile
9820 (if (not (boundp 'mode-popup-menu))
9821 (defvar mode-popup-menu nil "Compatibility with XEmacs.")))
9822
9823 ;; ---- add menu 'Statements' in Verilog mode (MH)
9824 (defun verilog-add-statement-menu ()
9825 "Add the menu 'Statements' to the menu bar in Verilog mode."
9826 (if (featurep 'xemacs)
9827 (progn
9828 (easy-menu-add verilog-stmt-menu)
9829 (easy-menu-add verilog-menu)
9830 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))))
9831
9832 (add-hook 'verilog-mode-hook 'verilog-add-statement-menu)
9833
9834 9859
9835 9860
9836 ;; 9861 ;;
9837 ;; Include file loading with mouse/return event 9862 ;; Include file loading with mouse/return event
9838 ;; 9863 ;;