Mercurial > emacs
annotate lisp/progmodes/cmacexp.el @ 5020:94de08fd8a7c
(Fnext_single_property_change): Fix missing \n\.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Mon, 15 Nov 1993 06:41:45 +0000 |
| parents | 10e417efb12a |
| children | c381f562cffc |
| rev | line source |
|---|---|
|
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
1 ;;; cmacexp.el --- C preprocessor macro expansion |
|
662
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 | |
|
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
24 ;;; Commentary: |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
25 |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
26 ;; This package gives you the ability to run the C macro preprocessor |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
27 ;; on the current region, expanding macros within it. This can be useful |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
28 ;; when you're not sure of the value or expansion of such macros and want |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
29 ;; to make sure they're doing what you think they're doing. |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
30 ;; |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
31 ;; This package supports the following option variables: |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
32 ;; |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
33 ;; c-macro-preprocessor --- program to be used for macro expansion. |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
34 ;; c-macro-options --- command-line options to pass it. |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
35 |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
36 ;;; Code: |
| 315 | 37 |
| 38 (defvar c-macro-preprocessor "/lib/cpp" | |
| 39 "*Command to be used for C preprocessing.") | |
| 40 | |
| 41 (defvar c-macro-options nil | |
| 42 "*List of options to use in C preprocessing. | |
| 43 Each string in the list becomes a separate argument to the preprocessor. | |
| 44 These arguments precede the filename. | |
| 45 Use the `-I' option here to specify directories for header files.") | |
| 46 | |
| 47 (defun c-macro-expand (beg end) | |
| 48 "Display the result of expanding all C macros occurring in the region. | |
| 49 The expansion is entirely correct because it uses the C preprocessor. | |
| 50 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
|
51 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
|
52 and macros to predefine." |
| 315 | 53 (interactive "r") |
| 54 (let ((outbuf (get-buffer-create "*Macroexpansion*")) | |
| 55 (tempfile "%%macroexpand%%") | |
|
1831
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
56 expanded |
| 315 | 57 process |
| 58 last-needed) | |
|
1831
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
59 (setq expanded (expand-file-name tempfile)) |
| 315 | 60 (save-excursion |
| 61 (set-buffer outbuf) | |
| 62 (erase-buffer)) | |
| 63 (setq process (apply 'start-process "macros" outbuf c-macro-preprocessor | |
| 64 c-macro-options)) | |
| 65 (set-process-sentinel process '(lambda (&rest x))) | |
| 66 (save-restriction | |
| 67 (widen) | |
| 68 (save-excursion | |
| 69 (goto-char beg) | |
| 70 (beginning-of-line) | |
| 71 (setq last-needed (point)) | |
| 72 (if (re-search-backward "^[ \t]*#" nil t) | |
| 73 (progn | |
| 74 ;; Skip continued lines. | |
| 75 (while (progn (end-of-line) (= (preceding-char) ?\\)) | |
| 76 (forward-line 1)) | |
| 77 ;; Skip the last line of the macro definition we found. | |
| 78 (forward-line 1) | |
| 79 (setq last-needed (point))))) | |
|
1831
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
80 (write-region (point-min) last-needed expanded nil 'nomsg) |
| 315 | 81 ;; Output comment ender in case last #-directive is inside a comment. |
| 82 ;; Also, terminate any string that we are in. | |
|
1831
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
83 (write-region "*//*\"*/\n" nil expanded t 'nomsg) |
|
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
84 (write-region beg end (concat expanded "x") nil 'nomsg) |
| 315 | 85 (process-send-string process (concat "#include \"" tempfile "\"\n")) |
| 86 (process-send-string process "\n") | |
| 87 (process-send-string process (concat "#include \"" tempfile "x\"\n")) | |
|
1831
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
88 (process-send-eof process) |
|
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
89 ;; HPUX seems to want two eofs. |
| 315 | 90 (process-send-eof process)) |
| 91 (while (eq (process-status process) 'run) | |
| 92 (accept-process-output)) | |
|
1831
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
93 (delete-file expanded) |
|
1c7d06764d0d
(c-macro-expand): Use expanded name to write or delete.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
94 (delete-file (concat expanded "x")) |
| 315 | 95 (display-buffer outbuf) |
| 96 (save-excursion | |
| 97 (set-buffer outbuf) | |
| 98 (goto-char (point-max)) | |
| 99 (forward-line -1) | |
| 100 (delete-region (point) (point-max)) | |
| 101 (re-search-backward "\n# 1 ") | |
| 102 (forward-line 2) | |
| 103 (while (eolp) (delete-char 1)) | |
| 104 (delete-region (point-min) (point))) | |
| 105 (display-buffer outbuf))) | |
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
106 |
|
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
107 ;;; cmacexp.el ends here |
