annotate lisp/progmodes/cmacexp.el @ 1440:8c27b145955a

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