(defun verilog-forward-sexp ()
(let ((reg)
(st (point)))
(if (not (looking-at "\\<"))
(forward-word -1))
(cond
((verilog-skip-forward-comment-or-string)
(verilog-forward-syntactic-ws)
)
((looking-at verilog-beg-block-re-1);; begin|fork|case|table|specify
(cond
((match-end 1) ; end
;; Search forward for matching begin
(setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )
)
((match-end 2) ; endcase
;; Search forward for matching case
(setq reg "\\(\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
)
((match-end 3) ; join
;; Search forward for matching fork
(setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\>\\)" )
)
((match-end 4) ; endtable
;; Search forward for matching table
(setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )
)
((match-end 5) ; endspecify
;; Search forward for matching specify
(setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )
)
((match-end 6) ; endfunction
;; Search forward for matching function
(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )
)
((match-end 7) ; endspecify
;; Search forward for matching task
(setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )
)
)
(if (forward-word 1)
(catch 'skip
(let ((nest 1))
(while (verilog-re-search-forward reg nil 'move)
(cond
((match-end 2) ; end
(setq nest (1- nest))
(if (= 0 nest)
(throw 'skip 1)))
((match-end 1) ; begin
(setq nest (1+ nest)))))
)
)
)
)
((looking-at
"\\(\\<\\(macro\\)?module\\>\\)\\|\\(\\<primitive\\>\\)")
(cond
((match-end 1)
(verilog-re-search-forward "\\<endmodule\\>" nil 'move))
((match-end 2)
(verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
(t
(goto-char st)
(if (= (following-char) ?\) )
(forward-char 1)
(forward-sexp 1)))))
(t
(goto-char st)
(if (= (following-char) ?\) )
(forward-char 1)
(forward-sexp 1)))
) ;; cond
)
)
(defun verilog-declaration-beg ()
(verilog-re-search-backward verilog-declaration-re (bobp) t))
(defsubst verilog-within-string ()
(save-excursion
(nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point)))))
(put 'verilog-mode 'font-lock-defaults
'((verilog-font-lock-keywords-after-1930 )
nil ;; nil means highlight strings & comments as well as keywords
nil ;; nil means keywords must match case
nil ;; syntax table handled elsewhere
verilog-beg-of-defun ;; function to move to beginning of reasonable region to
highlight
))
;;;
;;; Mode
;;;
;;;###autoload
(defun verilog-mode ()
"Major mode for editing Verilog code. \\<verilog-mode-map>
NEWLINE, TAB indents for Verilog code.
Delete converts tabs to spaces as it moves back.
Supports highlighting.
Variables controlling indentation/edit style:
verilog-indent-level (default 3)
Indentation of Verilog statements with respect to containing block.
verilog-indent-level-module (default 3)
Absolute indentation of Module level Verilog statements.
Set to 0 to get initial and always statements lined up
on the left side of your screen.
verilog-indent-level-declaration (default 3)
Indentation of declarations with respect to containing block.
Set to 0 to get them list right under containing block.
verilog-indent-level-behavioral (default 3)
Indentation of first begin in a task or function block
Set to 0 to get such code to linedup underneath the task or function keyword
verilog-cexp-indent (default 1)
Indentation of Verilog statements broken across lines IE:
if (a)
begin
verilog-case-indent (default 2)
Indentation for case statements.
verilog-auto-newline (default nil)
Non-nil means automatically newline after semicolons and the punctation
mark after an end.
verilog-auto-indent-on-newline (default t)
Non-nil means automatically indent line after newline
verilog-tab-always-indent (default t)
Non-nil means TAB in Verilog mode should always reindent the current line,
regardless of where in the line point is when the TAB command is used.
verilog-indent-begin-after-if (default t)
Non-nil means to indent begin statements following a preceding
if, else, while, for and repeat statements, if any. otherwise,
the begin is lined up with the preceding token. If t, you get:
if (a)
begin // amount of indent based on verilog-cexp-indent
otherwise you get:
if (a)
begin
verilog-auto-endcomments (default t)
Non-nil means a comment /* ... */ is set after the ends which ends
cases, tasks, functions and modules.
The type and name of the object will be set between the braces.
verilog-minimum-comment-distance (default 10)
Minimum distance (in lines) between begin and end required before a comment
will be inserted. Setting this variable to zero results in every
end aquiring a comment; the default avoids too many redundanet
comments in tight quarters.
verilog-auto-lineup (default `(all))
List of contexts where auto lineup of :'s or ='s should be done.
Turning on Verilog mode calls the value of the variable verilog-mode-hook with
no args, if that value is non-nil.
Other useful functions are:
\\[verilog-complete-word]\t-complete word with appropriate possibilities
(functions, verilog keywords...)
\\[verilog-comment-region]\t- Put marked area in a comment, fixing
nested comments.
\\[verilog-uncomment-region]\t- Uncomment an area commented with \
\\[verilog-comment-region].
\\[verilog-insert-block]\t- insert begin ... end;
\\[verilog-star-comment]\t- insert /* ... */
\\[verilog-mark-defun]\t- Mark function.
\\[verilog-beg-of-defun]\t- Move to beginning of current function.
\\[verilog-end-of-defun]\t- Move to end of current function.
\\[verilog-label-be]\t- Label matching begin ... end, fork ... join
and case ... endcase statements;
"
(interactive)
(kill-all-local-variables)
(use-local-map verilog-mode-map)
(setq major-mode 'verilog-mode)
(setq mode-name "Verilog")
(setq local-abbrev-table verilog-mode-abbrev-table)
(setq verilog-mode-syntax-table (make-syntax-table))
(verilog-populate-syntax-table verilog-mode-syntax-table)
;; add extra comment syntax
(verilog-setup-dual-comments verilog-mode-syntax-table)
(set-syntax-table verilog-mode-syntax-table)
(make-local-variable 'indent-line-function)
(setq indent-line-function 'verilog-indent-line-relative)
(setq comment-indent-function 'verilog-comment-indent)
(make-local-variable 'parse-sexp-ignore-comments)
(setq parse-sexp-ignore-comments nil)
(make-local-variable 'comment-start)
(make-local-variable 'comment-end)
(make-local-variable 'comment-multi-line)
(make-local-variable 'comment-start-skip)
(setq comment-start "// "
comment-end ""
comment-start-skip "/\\*+ *\\|// *"
comment-multi-line nil)
;; Setting up things for font-lock
(if (string-match "XEmacs" emacs-version)
(progn
(if (and current-menubar
(not (assoc "Verilog" current-menubar)))
(progn
(set-buffer-menubar (copy-sequence current-menubar))
(add-submenu nil verilog-xemacs-menu))) ))
;; Stuff for GNU emacs
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
'((verilog-font-lock-keywords verilog-font-lock-keywords-1
verilog-font-lock-keywords-2
verilog-font-lock-keywords-3
verilog-font-lock-keywords-4)
nil t))
;; Tell imenu how to handle verilog.
(make-local-variable 'imenu-generic-expression)
(setq imenu-generic-expression verilog-imenu-generic-expression)
;; End GNU emacs stuff
(run-hooks 'verilog-mode-hook))
;;;
;;; Electric functions
;;;
(defun electric-verilog-terminate-line (&optional arg)
"Terminate line and indent next line."
(interactive)
;; before that see if we are in a comment
(let ((state
(save-excursion
(parse-partial-sexp (point-min) (point)))))
(cond
((nth 7 state) ; Inside // comment
(if (eolp)
(progn
(delete-horizontal-space)
(newline))
(progn
(newline)
(insert-string "// ")
(beginning-of-line)
))
(verilog-indent-line)
)
((nth 4 state) ; Inside any comment (hence /**/)
(newline)
(verilog-more-comment)
)
((eolp)
;; First, check if current line should be indented
(if (save-excursion
(delete-horizontal-space)
(beginning-of-line)
(skip-chars-forward " \t")
(if (looking-at verilog-autoindent-lines-re)
(let ((indent-str (verilog-indent-line)))
;; Maybe we should set some endcomments
(if verilog-auto-endcomments
(verilog-set-auto-endcomments indent-str arg))
(end-of-line)
(delete-horizontal-space)
(if arg
()
(newline))
nil)
(progn
(end-of-line)
(delete-horizontal-space)
't
)))
(newline)
(forward-line 1)
)
;; Indent next line
(if verilog-auto-indent-on-newline
(verilog-indent-line))
)
(t
(newline)
)
)
)
)
(defun electric-verilog-semi ()
"Insert `;' character and reindent the line."
(interactive)
(insert last-command-char)
(if (or (verilog-in-comment-or-string-p)
(verilog-in-escaped-name-p))
()
(save-excursion
(beginning-of-line)
(verilog-forward-ws&directives)
(verilog-indent-line))
(if (and verilog-auto-newline
(not (verilog-parenthesis-depth)))
(electric-verilog-terminate-line))))
(defun electric-verilog-semi-with-comment ()
"Insert `;' character, reindent the line and indent for comment."
(interactive)
(insert "\;")
(save-excursion
(beginning-of-line)
(verilog-indent-line))
(indent-for-comment))
(defun electric-verilog-colon ()
"Insert `:' and do all indentions except line indent on this line."
(interactive)
(insert last-command-char)
;; Do nothing if within string.
(if (or
(verilog-within-string)
(not (verilog-in-case-region-p)))
()
(save-excursion
(let ((p (point))
(lim (progn (verilog-beg-of-statement) (point))))
(goto-char p)
(verilog-backward-case-item lim)
(verilog-indent-line)))
;; (let ((verilog-tab-always-indent nil))
;; (verilog-indent-line))
)
)
(defun electric-verilog-equal ()
"Insert `=', and do indention if within block."
(interactive)
(insert last-command-char)
;; Could auto line up expressions, but not yet
;; (if (eq (car (verilog-calculate-indent)) 'block)
;; (let ((verilog-tab-always-indent nil))
;; (verilog-indent-command)))
)
(defun electric-verilog-tick ()
"Insert back-tick, and indent to coulmn 0 if this is a CPP directive."
(interactive)
(insert last-command-char)
(if (save-excursion
(beginning-of-line)
(looking-at verilog-directive-re-1))
(save-excursion (beginning-of-line)
(delete-horizontal-space))))
(defun electric-verilog-tab ()
"Function called when TAB is pressed in Verilog mode."
(interactive)
;; If verilog-tab-always-indent, indent the beginning of the line.
(if (or verilog-tab-always-indent
(save-excursion
(skip-chars-backward " \t")
(bolp)))
(let* (
(oldpnt (point))
(boi-point
(save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
(let (type state )
(setq type (verilog-indent-line))
(setq state (car type))
(cond
((eq state 'block)
(if (looking-at verilog-behavioral-block-beg-re )
(error
(concat
"The reserved word \""
(buffer-substring (match-beginning 0) (match-end 0))
"\" must be at the behavioral level!"))))
))
(back-to-indentation)
(point))))
(if (< (point) boi-point)
(back-to-indentation)
(cond ((not verilog-tab-to-comment))
((not (eolp))
(end-of-line))
(t
(indent-for-comment)
(when (and (eolp) (= oldpnt (point)))
; kill existing comment
(beginning-of-line)
(re-search-forward comment-start-skip oldpnt 'move)
(goto-char (match-beginning 0))
(skip-chars-backward " \t")
(kill-region (point) oldpnt)
))))
)
(progn (insert "\t"))
)
)
;;;
;;; Interactive functions
;;;
(defun verilog-insert-block ()
"Insert Verilog begin ... end; block in the code with right indentation."
(interactive)
(verilog-indent-line)
(insert "begin")
(electric-verilog-terminate-line)
(save-excursion
(electric-verilog-terminate-line)
(insert "end")
(beginning-of-line)
(verilog-indent-line)))
(defun verilog-star-comment ()
"Insert Verilog star comment at point."
(interactive)
(verilog-indent-line)
(insert "/*")
(save-excursion
(newline)
(insert " */"))
(newline)
(insert " * "))
(defun verilog-mark-defun ()
"Mark the current verilog function (or procedure).
This puts the mark at the end, and point at the beginning."
(interactive)
(push-mark (point))
(verilog-end-of-defun)
(push-mark (point))
(verilog-beg-of-defun)
(zmacs-activate-region))
(defun verilog-comment-region (start end)
"Put the region into a Verilog comment.
The comments that are in this area are \"deformed\":
`*)' becomes `!(*' and `}' becomes `!{'.
These deformed comments are returned to normal if you use
\\[verilog-uncomment-region] to undo the commenting.
The commented area starts with `verilog-exclude-str-start', and ends with
`verilog-include-str-end'. But if you change these variables,
\\[verilog-uncomment-region] won't recognize the comments."
(interactive "r")
(save-excursion
;; Insert start and endcomments
(goto-char end)
(if (and (save-excursion (skip-chars-forward " \t") (eolp))
(not (save-excursion (skip-chars-backward " \t") (bolp))))
(forward-line 1)
(beginning-of-line))
(insert verilog-exclude-str-end)
(setq end (point))
(newline)
(goto-char start)
(beginning-of-line)
(insert verilog-exclude-str-start)
(newline)
;; Replace end-comments within commented area
(goto-char end)
(save-excursion
(while (re-search-backward "\\*/" start t)
(replace-match "*-/" t t)))
(save-excursion
(let ((s+1 (1+ start)))
(while (re-search-backward "/\\*" s+1 t)
(replace-match "/-*" t t))))
)
)
(defun verilog-uncomment-region ()
"Uncomment a commented area; change deformed comments back to normal.
This command does nothing if the pointer is not in a commented
area. See also `verilog-comment-region'."
(interactive)
(save-excursion
(let ((start (point))
(end (point)))
;; Find the boundaries of the comment
(save-excursion
(setq start (progn (search-backward verilog-exclude-str-start nil t)
(point)))
(setq end (progn (search-forward verilog-exclude-str-end nil t)
(point))))
;; Check if we're really inside a comment
(if (or (equal start (point)) (<= end (point)))
(message "Not standing within commented area.")
(progn
;; Remove endcomment
(goto-char end)
(beginning-of-line)
(let ((pos (point)))
(end-of-line)
(delete-region pos (1+ (point))))
;; Change comments back to normal
(save-excursion
(while (re-search-backward "\\*-/" start t)
(replace-match "*/" t t)))
(save-excursion
(while (re-search-backward "/-\\*" start t)
(replace-match "/*" t t)))
;; Remove startcomment
(goto-char start)
(beginning-of-line)
(let ((pos (point)))
(end-of-line)
(delete-region pos (1+ (point)))))))))
(defun verilog-beg-of-defun ()
"Move backward to the beginning of the current function or procedure."
(interactive)
(verilog-re-search-backward verilog-defun-re nil 'move)
)
(defun verilog-end-of-defun ()
(interactive)
(verilog-re-search-forward verilog-end-defun-re nil 'move)
)
(defun verilog-get-beg-of-defun (&optional warn)
(save-excursion
(cond ((verilog-re-search-forward-quick verilog-defun-re nil t)
(point))
(warn (error "Can't find module beginning in %s" (or buffer-file-name
(buffer-name)))
(point-max)))))
(defun verilog-get-end-of-defun (&optional warn)
(save-excursion
(cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
(point))
(warn (error "Can't find endmodule in %s" (or buffer-file-name
(buffer-name)))
(point-max)))))
(defun verilog-label-be (&optional arg)
"Label matching begin ... end, fork ... join and case ... endcase
statements in this module; With argument, first kill any existing
labels."
(interactive)
(let ((cnt 0)
(oldpos (point))
(b (progn
(verilog-beg-of-defun)
(point-marker)))
(e (progn
(verilog-end-of-defun)
(point-marker)))
)
(goto-char (marker-position b))
(if (> (- e b) 200)
(message "Relabeling module..."))
(while (and
(> (marker-position e) (point))
(verilog-re-search-forward
(concat
"\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|"
"\\(primitive\\)\\|\\(case\\)\\)?\\>"
"\\|\\(`endif\\)\\|\\(`else\\)")
nil 'move))
(goto-char (match-beginning 0))
(let ((indent-str (verilog-indent-line)))
(verilog-set-auto-endcomments indent-str 't)
(end-of-line)
(delete-horizontal-space)
)
(setq cnt (1+ cnt))
(if (= 9 (% cnt 10))
(message "%d..." cnt))
)
(goto-char oldpos)
(if (or
(> (- e b) 200)
(> cnt 20))
(message "%d lines autocommented" cnt))
)
)
(defun verilog-beg-of-statement ()
"Move backward to beginning of statement"
(interactive)
(while (save-excursion
(and
(not (looking-at verilog-complete-reg))
(verilog-backward-syntactic-ws)
(not (or (bolp) (= (preceding-char) ?\;)))
)
)
(skip-chars-backward " \t")
(verilog-backward-token))
(let ((last (point)))
(while (progn
(setq last (point))
(and (not (looking-at verilog-complete-reg))
(verilog-continued-line))))
(goto-char last)
(verilog-forward-syntactic-ws)
)
)
(defun verilog-beg-of-statement-1 ()
"Move backward to beginning of statement"
(interactive)
(let ((pt (point)))
(while (and (not (looking-at verilog-complete-reg))
(setq pt (point))
(verilog-backward-token)
(verilog-backward-syntactic-ws)
(setq pt (point))
(not (bolp))
(not (= (preceding-char) ?\;)))
)
(while (progn
(setq pt (point))
(and (not (looking-at verilog-complete-reg))
(not (= (preceding-char) ?\;))
(verilog-continued-line))))
(goto-char pt)
(verilog-forward-syntactic-ws)
)
)
(defun verilog-end-of-statement ()
"Move forward to end of current statement."
(interactive)
(let ((nest 0) pos)
(or (looking-at verilog-beg-block-re)
;; Skip to end of statement
(setq pos (catch 'found
(while t
(forward-sexp 1)
(verilog-skip-forward-comment-or-string)
(cond ((looking-at "[ \t]*;")
(skip-chars-forward "^;")
(forward-char 1)
(throw 'found (point)))
((save-excursion
(forward-sexp -1)
(looking-at verilog-beg-block-re))
(goto-char (match-beginning 0))
(throw 'found nil))
((eobp)
(throw 'found (point))))))))
(if (not pos)
;; Skip a whole block
(catch 'found
(while t
(verilog-re-search-forward verilog-end-statement-re nil 'move)
(setq nest (if (match-end 1)
(1+ nest)
(1- nest)))
(cond ((eobp)
(throw 'found (point)))
((= 0 nest)
(throw 'found (verilog-end-of-statement))))))
pos)))
(defun verilog-in-case-region-p ()
"Return TRUE if in a case region: more specifically, point @ in the
line foo : @ begin"
(interactive)
(save-excursion
(if (and
(progn (verilog-forward-syntactic-ws)
(looking-at "\\<begin\\>"))
(progn (verilog-backward-syntactic-ws)
(= (preceding-char) ?\:)))
(catch 'found
(let ((nest 1))
(while t
(verilog-re-search-backward
(concat "\\(\\<module\\>\\)\\|\\(\\<case[xz]?\\>[^:]\\)\\|"
"\\(\\<endcase\\>\\)\\>")
nil 'move)
(cond
((match-end 3)
(setq nest (1+ nest)))
((match-end 2)
(if (= nest 1)
(throw 'found 1))
(setq nest (1- nest))
)
( t
(throw 'found (= nest 0)))
)
)
)
)
nil)
)
)
(defun verilog-in-fork-region-p ()
"Return true if between a fork and join"
(interactive)
(let
( (lim (save-excursion (verilog-beg-of-defun) (point)))
(nest 1)
)
(save-excursion
(while (and
(/= nest 0)
(verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\)\\>" lim
'move)
(cond
((match-end 1) ; fork
(setq nest (1- nest)))
((match-end 2) ; join
(setq nest (1+ nest)))
)
)
)
)
(= nest 0) ) ; return nest
)
(defun verilog-backward-case-item (lim)
"Skip backward to nearest enclosing case item"
(interactive)
(let (
(str 'nil)
(lim1
(progn
(save-excursion
(verilog-re-search-backward verilog-endcomment-reason-re
lim 'move)
(point)))))
;; Try to find the real :
(if (save-excursion (search-backward ":" lim1 t))
(let ((colon 0)
b e )
(while
(and
(< colon 1)
(verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
lim1 'move))
(cond
((match-end 1) ;; [
(setq colon (1+ colon))
(if (>= colon 0)
(error "unbalanced [")))
((match-end 2) ;; ]
(setq colon (1- colon)))
((match-end 3) ;; :
(setq colon (1+ colon)))
)
)
;; Skip back to begining of case item
(skip-chars-backward "\t ")
(verilog-skip-backward-comment-or-string)
(setq e (point))
(setq b
(progn
(if
(verilog-re-search-backward
"\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
(progn
(cond
((match-end 1)
(goto-char (match-end 1))
(verilog-forward-ws&directives)
(if (looking-at "(")
(progn
(forward-sexp)
(verilog-forward-ws&directives)
))
(point))
(t
(goto-char (match-end 0))
(verilog-forward-ws&directives)
(point))
))
(error "Malformed case item")
)
)
)
(setq str (buffer-substring b e))
(if
(setq e
(string-match
"[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
(setq str (concat (substring str 0 e) "...")))
str)
'nil)
)
)
;;;
;;; Other functions
;;;
(defun kill-existing-comment ()
"kill autocomment on this line"
(save-excursion
(let* (
(e (progn
(end-of-line)
(point)))
(b (progn
(beginning-of-line)
(search-forward "//" e t))))
(if b
(delete-region (- b 2) e))
)
)
)
(defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
"Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
Insert `// case expr ' if this line ends a case block.
Insert `// ifdef FOO ' if this line ends code conditional on FOO.
Insert `// NAME ' if this line ends a module or primitive named NAME."
(save-excursion
(cond
(; Comment close preprocessor directives
(and
(looking-at "\\(`endif\\)\\|\\(`else\\)")
(or kill-existing-comment
(not (save-excursion
(end-of-line)
(search-backward "//" (verilog-get-beg-of-line) t)))))
(let ( (reg
"\\(`else\\>\\)\\|\\(`ifdef\\>\\)\\|\\(`endif\\>\\)")
(nest 1)
b e
(else (if (match-end 2)
1
0))
)
(end-of-line)
(if kill-existing-comment
(kill-existing-comment))
(delete-horizontal-space)
(save-excursion
(backward-sexp 1)
(while (and (/= nest 0)
(verilog-re-search-backward reg nil 'move))
(cond
((match-end 1) ; `else
(if (= nest 1)
(setq else 1)))
((match-end 2) ; `ifdef
(setq nest (1- nest)))
((match-end 3) ; `endif
(setq nest (1+ nest)))
))
(if (match-end 0)
(setq b (progn
(skip-chars-forward "^ \t")
(verilog-forward-syntactic-ws)
(point))
e (progn
(skip-chars-forward "a-zA-Z0-9_")
(point)
))))
(if b
(if (> (count-lines (point) b) verilog-minimum-comment-distance)
(insert (concat (if
(= else 0)
" // ifdef "
" // !ifdef ")
(buffer-substring b e))))
(progn
(insert " // unmatched `endif")
(ding 't))
)))
(; Comment close case/function/task/module and named block
(and (looking-at "\\<end")
(or kill-existing-comment
(not (save-excursion
(end-of-line)
(search-backward "//" (verilog-get-beg-of-line) t)))))
(let ((type (car indent-str)))
(if (eq type 'declaration)
()
(if
(looking-at verilog-enders-re)
(cond
(;- This is a case block; search back for the start of this case
(match-end 1)
(let ((err 't)
(str "UNMATCHED!!"))
(save-excursion
(verilog-leap-to-head)
(if (match-end 0)
(progn
(goto-char (match-end 1))
(setq str (concat (buffer-substring (match-beginning 1) (match-end 1))
(verilog-get-expr)))
(setq err nil))))
(end-of-line)
(if kill-existing-comment
(kill-existing-comment))
(delete-horizontal-space)
(insert (concat " // " str ))
(if err (ding 't))
))
(;- This is a begin..end block
(match-end 2)
(let ((str " // UNMATCHED !!")
(err 't)
(here (point))
there
cntx
)
(save-excursion
(verilog-leap-to-head)
(setq there (point))
(if (not (match-end 0))
(progn
(goto-char here)
(end-of-line)
(if kill-existing-comment
(kill-existing-comment))
(delete-horizontal-space)
(insert str)
(ding 't)
)
(let ( sp
(lim (save-excursion (verilog-beg-of-defun) (point)))
(here (point))
)
(cond
(;-- handle named block differently
(looking-at verilog-named-block-re)
(search-forward ":")
(setq there (point))
(setq str (verilog-get-expr))
(setq err nil)
(setq str (concat " // block: " str )))
((verilog-in-case-region-p) ;-- handle case item differently
(goto-char here)
(setq str (verilog-backward-case-item lim))
(setq there (point))
(setq err nil)
(setq str (concat " // case: " str ))
)
(;- try to find "reason" for this begin
(cond
(;
(eq here (progn
(verilog-backward-token)
(verilog-beg-of-statement)
(point)))
(setq err nil)
(setq str ""))
((looking-at verilog-endcomment-reason-re)
(setq there (match-end 0))
(setq cntx (concat
(buffer-substring (match-beginning 0) (match-end 0)) " "))
(cond
(;
(match-end 2)
(setq err nil)
(save-excursion