;;; c-macro-expand-and-clean.el ;;; ;;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, ;;; 2000, 2004, 2007, 2008 Thien-Thi Nguyen ;;; ;;; This file is part of ttn's personal elisp library, released under ;;; the terms of the GNU General Public License as published by the ;;; Free Software Foundation; either version 3, or (at your option) any ;;; later version. There is NO WARRANTY. See file COPYING for details. ;;; Description: Expand a region of C code into another buffer, then clean it. ;;;###autoload (defvar c-macro-expand-and-clean-substitutions '("/\\*\\([^*]\\|\\(\\*[^/]\\)\\)*\\*/" "" "^\\s-+" "" "\\`\n+" "" "[ \t]*[ \t]" " " "(\\s-+" "(" "\\s-+)" ")" "{\\|}" "\n\\&\n" "\\s-*;" ";\n" "\n\\s-*\n" "\n" "\\s-*," "," ",\\([^\n]\\)" ",\n\\1" " \\?" "\n?" " :" "\n:" ")\\s-+do\\s-" ")\ndo " "\\s-+$" "" "\n\n+\\(\\s-*}\\)" "\n\\1" "\n\n\n*" "\n\n" ;; Add regexp / string pairs here. ) "*List of alternating strings for `c-macro-expand-and-clean'. In *Macroexpansion*, each CAR (regexp) is substituted with the CADR.") ;;;###autoload (defun c-macro-expand-and-clean (beg end) "Call `c-macro-expand', then do additional cleaning. See variable `c-macro-expand-and-clean-substitutions'." (interactive "r") (message "Calling c-macro-expand ...") (let (c-mode-common-hook) (c-macro-expand beg end nil)) (let* ((cb (current-buffer)) (mb (get-buffer "*Macroexpansion*")) (buffer-read-only nil)) (set-buffer mb) (map-table-2col (lambda (from to) (message "Cleaning...") (goto-char (point-min)) (unless (input-pending-p) (sit-for 0.02)) (while (re-search-forward from nil t) (replace-match to nil nil))) c-macro-expand-and-clean-substitutions) (setq indent-tabs-mode nil truncate-lines t) (indent-region 1 (point-max) nil) (message "Cleaning...done") (set-buffer cb))) (provide 'c-macro-expand-and-clean) ;;; c-macro-expand-and-clean.el ends here