Function: c-macro-expand
c-macro-expand is an autoloaded, interactive and byte-compiled
function defined in cmacexp.el.gz.
Signature
(c-macro-expand START END SUBST)
Documentation
Expand C macros in the region, using the C preprocessor.
Normally display output in temp buffer, but prefix arg means replace the region with it.
c-macro-preprocessor specifies the preprocessor to use.
If the user option c-macro-prompt-flag is non-nil
prompt for arguments to the preprocessor (e.g. -DDEBUG -I ./include),
otherwise use c-macro-cppflags.
Noninteractive args are START, END, SUBST.
For use inside Lisp programs, see also c-macro-expansion.
Probably introduced at or before Emacs version 18.52.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cmacexp.el.gz
;;;###autoload
(defun c-macro-expand (start end subst)
"Expand C macros in the region, using the C preprocessor.
Normally display output in temp buffer, but
prefix arg means replace the region with it.
`c-macro-preprocessor' specifies the preprocessor to use.
If the user option `c-macro-prompt-flag' is non-nil
prompt for arguments to the preprocessor \(e.g. `-DDEBUG -I ./include'),
otherwise use `c-macro-cppflags'.
Noninteractive args are START, END, SUBST.
For use inside Lisp programs, see also `c-macro-expansion'."
(interactive "r\nP")
(let ((inbuf (current-buffer))
(displaybuf (if subst
(get-buffer c-macro-buffer-name)
(get-buffer-create c-macro-buffer-name)))
(expansion ""))
;; Build the command string.
(if c-macro-prompt-flag
(setq c-macro-cppflags
(read-string "Preprocessor arguments: "
c-macro-cppflags)))
;; Decide where to display output.
(if (and subst
(and buffer-read-only (not inhibit-read-only))
(not (eq inbuf displaybuf)))
(progn
(message
"Buffer is read only: displaying expansion in alternate window")
(sit-for 2)
(setq subst nil)
(or displaybuf
(setq displaybuf (get-buffer-create c-macro-buffer-name)))))
;; Expand the macro and output it.
(setq expansion (c-macro-expansion start end
(concat c-macro-preprocessor " "
c-macro-cppflags) t))
(if subst
(let ((exchange (= (point) start)))
(delete-region start end)
(insert expansion)
(if exchange
(exchange-point-and-mark)))
(set-buffer displaybuf)
(setq buffer-read-only nil)
(buffer-disable-undo displaybuf)
(erase-buffer)
(insert expansion)
(set-buffer-modified-p nil)
(if (string= "" expansion)
(message "Null expansion")
(c-macro-display-buffer))
(setq buffer-read-only t)
(setq buffer-auto-save-file-name nil)
(bury-buffer displaybuf))))