Mercurial > emacs
annotate lisp/progmodes/cmacexp.el @ 885:9ba823ecb3df
*** empty log message ***
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Mon, 27 Jul 1992 19:54:35 +0000 |
parents | 213978acbc1e |
children | 1c7d06764d0d |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
1 ;;; cmacexp.el --- C macro expansion |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1988 Free Software Foundation, Inc. |
4 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Maintainer: FSF |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
6 ;; Keywords: c |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
7 |
315 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
315 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
24 ;;; Code: |
315 | 25 |
26 (defvar c-macro-preprocessor "/lib/cpp" | |
27 "*Command to be used for C preprocessing.") | |
28 | |
29 (defvar c-macro-options nil | |
30 "*List of options to use in C preprocessing. | |
31 Each string in the list becomes a separate argument to the preprocessor. | |
32 These arguments precede the filename. | |
33 Use the `-I' option here to specify directories for header files.") | |
34 | |
35 (defun c-macro-expand (beg end) | |
36 "Display the result of expanding all C macros occurring in the region. | |
37 The expansion is entirely correct because it uses the C preprocessor. | |
38 You can use the variables `c-macro-preprocessor' and `c-macro-options' | |
612
68ef62058595
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
315
diff
changeset
|
39 to customize how preprocessing is done, or specify header file directories |
68ef62058595
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
315
diff
changeset
|
40 and macros to predefine." |
315 | 41 (interactive "r") |
42 (let ((outbuf (get-buffer-create "*Macroexpansion*")) | |
43 (tempfile "%%macroexpand%%") | |
44 process | |
45 last-needed) | |
46 (save-excursion | |
47 (set-buffer outbuf) | |
48 (erase-buffer)) | |
49 (setq process (apply 'start-process "macros" outbuf c-macro-preprocessor | |
50 c-macro-options)) | |
51 (set-process-sentinel process '(lambda (&rest x))) | |
52 (save-restriction | |
53 (widen) | |
54 (save-excursion | |
55 (goto-char beg) | |
56 (beginning-of-line) | |
57 (setq last-needed (point)) | |
58 (if (re-search-backward "^[ \t]*#" nil t) | |
59 (progn | |
60 ;; Skip continued lines. | |
61 (while (progn (end-of-line) (= (preceding-char) ?\\)) | |
62 (forward-line 1)) | |
63 ;; Skip the last line of the macro definition we found. | |
64 (forward-line 1) | |
65 (setq last-needed (point))))) | |
66 (write-region (point-min) last-needed tempfile nil 'nomsg) | |
67 ;; Output comment ender in case last #-directive is inside a comment. | |
68 ;; Also, terminate any string that we are in. | |
69 (write-region "*//*\"*/\n" nil tempfile t 'nomsg) | |
70 (write-region beg end (concat tempfile "x") nil 'nomsg) | |
71 (process-send-string process (concat "#include \"" tempfile "\"\n")) | |
72 (process-send-string process "\n") | |
73 (process-send-string process (concat "#include \"" tempfile "x\"\n")) | |
74 (process-send-eof process)) | |
75 (while (eq (process-status process) 'run) | |
76 (accept-process-output)) | |
77 (delete-file tempfile) | |
78 (delete-file (concat tempfile "x")) | |
79 (display-buffer outbuf) | |
80 (save-excursion | |
81 (set-buffer outbuf) | |
82 (goto-char (point-max)) | |
83 (forward-line -1) | |
84 (delete-region (point) (point-max)) | |
85 (re-search-backward "\n# 1 ") | |
86 (forward-line 2) | |
87 (while (eolp) (delete-char 1)) | |
88 (delete-region (point-min) (point))) | |
89 (display-buffer outbuf))) | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
90 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
91 ;;; cmacexp.el ends here |