Function: verilog-auto-undef
verilog-auto-undef is a byte-compiled function defined in
verilog-mode.el.gz.
Signature
(verilog-auto-undef)
Documentation
Expand AUTOUNDEF statements, as part of M-x verilog-auto (verilog-auto).
Take any `defines since the last AUTOUNDEF in the current file and create `undefs for them. This is used to insure that file-local defines do not pollute the global `define name space.
Limitations:
AUTOUNDEF presumes any identifier following `define is the
name of a define. Any `ifdefs are ignored.
AUTOUNDEF suppresses creating an `undef for any define that was
`undefed before the AUTOUNDEF. This may be used to work around
the ignoring of `ifdefs as shown below.
An example:
`define XX_FOO
`define M_BAR(x)
`define M_BAZ
...
`ifdef NEVER
`undef M_BAZ // Emacs will see this and not `undef M_BAZ
`endif
...
/*AUTOUNDEF*/
Typing M-x verilog-auto (verilog-auto) will make this into:
...
/*AUTOUNDEF*/
// Beginning of automatic undefs
`undef M_BAR
`undef XX_FOO
// End of automatics
You may also provide an optional regular expression, in which case only defines the regular expression will be undefed.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/verilog-mode.el.gz
(defun verilog-auto-undef ()
"Expand AUTOUNDEF statements, as part of \\[verilog-auto].
Take any \\=`defines since the last AUTOUNDEF in the current file
and create \\=`undefs for them. This is used to insure that
file-local defines do not pollute the global \\=`define name space.
Limitations:
AUTOUNDEF presumes any identifier following \\=`define is the
name of a define. Any \\=`ifdefs are ignored.
AUTOUNDEF suppresses creating an \\=`undef for any define that was
\\=`undefed before the AUTOUNDEF. This may be used to work around
the ignoring of \\=`ifdefs as shown below.
An example:
\\=`define XX_FOO
\\=`define M_BAR(x)
\\=`define M_BAZ
...
\\=`ifdef NEVER
\\=`undef M_BAZ // Emacs will see this and not \\=`undef M_BAZ
\\=`endif
...
/*AUTOUNDEF*/
Typing \\[verilog-auto] will make this into:
...
/*AUTOUNDEF*/
// Beginning of automatic undefs
\\=`undef M_BAR
\\=`undef XX_FOO
// End of automatics
You may also provide an optional regular expression, in which case only
defines the regular expression will be undefed."
(save-excursion
(let* ((params (verilog-read-auto-params 0 1))
(regexp (nth 0 params))
(indent-pt (current-indentation))
(end-pt (point))
defs def)
(save-excursion
;; Scan from start of file, or last AUTOUNDEF
(or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
(goto-char (point-min)))
(while (verilog-re-search-forward-quick
"`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
(cond ((equal (match-string-no-properties 1) "define")
(setq def (match-string-no-properties 2))
(when (and (or (not regexp)
(string-match regexp def))
(not (member def defs))) ; delete-dups not in 21.1
(setq defs (cons def defs))))
(t
(setq defs (delete (match-string-no-properties 2) defs))))))
;; Insert
(setq defs (sort defs #'string<))
(when defs
(verilog-forward-or-insert-line)
(verilog-insert-indent "// Beginning of automatic undefs\n")
(while defs
(verilog-insert-indent "`undef " (car defs) "\n")
(setq defs (cdr defs)))
(verilog-insert-indent "// End of automatics\n")))))