annotate lisp/progmodes/cmacexp.el @ 5928:0a2c25c9400c

(super-apropos-check-doc-file): Don't attempt to retrieve function documentation from a symbol with no function binding.
author Karl Heuer <kwzh@gnu.org>
date Sat, 12 Feb 1994 04:21:06 +0000
parents 6229dd3050be
children fc2dc869f5d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
1 ;;; cmacexp.el --- expand C macros in a region
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
2
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 612
diff changeset
4
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
5 ;; Author: Francesco Potorti` <pot@cnuce.cnr.it>
5817
6229dd3050be (c-macro-expand): Check inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents: 5816
diff changeset
6 ;; Version: $Id: cmacexp.el,v 1.8 1994/02/07 05:39:56 rms Exp rms $
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
7 ;; Adapted-By: ESR
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
8 ;; Keywords: c
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
9
315
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; 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
14 ;; the Free Software Foundation; either version 2, or (at your option)
315
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; any later version.
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1831
diff changeset
26 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1831
diff changeset
27
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
28 ;; In C mode C-M-x is bound to c-macro-expand. The result of the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
29 ;; expansion is put in a separate buffer. The buffer is put in
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
30 ;; view-mode if the Inge Frick's view.el is installed. A user option
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
31 ;; allows the window displaying the buffer to be optimally sized.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
32 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
33 ;; When called with a C-u prefix, c-macro-expand replaces the selected
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
34 ;; region with the expansion. With two C-u's the user is offered to
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
35 ;; change the flags to the preprocessor (while the results of the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
36 ;; expansion go to a separate buffer). Preprocessor arguments default
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
37 ;; to the last ones entered. Both the preprocessor name and the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
38 ;; initial flag defaults can be set by the user. Setting
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
39 ;; c-macro-always-prompt to a non-nil value allows one to be always
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
40 ;; prompted for the flags, regardless of the prefix used.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
41
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
42 ;; A c-macro-expansion function is provided for non-interactive use.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
43 ;; A still experimental function c-macro-eval is provided. It aims at
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
44 ;; evaluating the contents of a region by using calc (by Dave
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
45 ;; Gillespie). Select a region and type C-x C-e (if you followed the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
46 ;; suggestions in the INSTALLATION section) or type M-x c-ma RET v
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
47 ;; RET. If you have calc installed, the computed value of the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
48 ;; expression will appear in the message area. If you give an
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
49 ;; interactive C-u prefix the computed value will be shown in signed,
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
50 ;; unsigned, hex and boolean representations. Two C-u's allow to
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
51 ;; change the preprocessor flags via prompt. c-macro-eval works well
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
52 ;; for constant expressions, but see the BUG section.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
53
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
54 ;; A patch to calc 2.02 has been written by Dave Gillespie. It can
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
55 ;; be downloaded via anonymous ftp at fly.cnuce.cnr.it:pub/calc.diff.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
56
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
57 ;; INSTALLATION ======================================================
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
58
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
59 ;; Put this file on your load-path, byte compile it for increased
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
60 ;; speed and put part or all of the following in your ~/.emacs file.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
61
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
62 ;; To make a directory ~/emacs be in front of your load-path:
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
63 ;;(setq load-path (cons (expand-file-name "~/emacs") load-path))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
64 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
65 ;; Suggested keybindings (work only in c-mode):
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
66 ;;(define-key c-mode-map "\C-\M-x" 'c-macro-expand)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
67 ;;(define-key c-mode-map "\C-x\C-e" 'c-macro-eval)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
68 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
69 ;; If you want the *Macroexpansion* window to be not higher than
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
70 ;; necessary:
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
71 ;;(setq c-macro-shrink-window-p t)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
72 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
73 ;; If you use a preprocessor other than /lib/cpp (be careful to set a
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
74 ;; -C option or equivalent in order to make the preprocessor not to
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
75 ;; strip the comments):
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
76 ;;(setq c-macro-preprocessor "gpp -C")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
77 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
78 ;; If you often use a particular set of flags, and want them to be
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
79 ;; the default:
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
80 ;;(setq c-macro-default-cppflags "-I /usr/include/local -DDEBUG"
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1831
diff changeset
81 ;;
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
82 ;; If you always want the "Preprocessor arguments: " prompt,
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
83 ;; regardless of the arguments provided:
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
84 ;;(setq c-macro-always-prompt-p t)
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1831
diff changeset
85 ;;
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
86 ;; If you want to experiment with the C constant expressions
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
87 ;; evaluation feature:
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
88 ;;(autoload 'c-macro-eval "cmacexp"
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
89 ;; "C constant expressions evaluation. Requires calc. Experimental." t)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
90
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
91 ;; BUG REPORTS =======================================================
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
92
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
93 ;; Please report bugs, suggestions, complaints and so on to
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
94 ;; pot@cnuce.cnr.it (Francesco Potorti`).
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
95
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
96 ;; IMPROVEMENTS OVER emacs 18.xx cmacexp.el ==========================
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
97
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
98 ;; - A lot of user visible changes. See above.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
99 ;; - #line directives are inserted, so __LINE__ and __FILE__ are
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
100 ;; correctly expanded. Works even with START inside a string, a
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
101 ;; comment or a region #ifdef'd away by cpp. cpp is invoked with -C,
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
102 ;; making comments visible in the expansion.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
103 ;; - All work is done in core memory, no need for temporary files.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
104 ;; - The /lib/cpp process is run synchronously. This fixes an
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
105 ;; infinite loop bug on Motorola Delta (cpp waiting forever for
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
106 ;; end-of-file, don't know why). Fixes a similar intermittent
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
107 ;; problem on SunOS 4.1.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
108
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
109 ;; ACKNOWLEDGEMENTS ==================================================
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
110
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
111 ;; A lot of thanks to Don Maszle who did a great work of testing, bug
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
112 ;; reporting and suggestion of new features, to Inge Fricks for her
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
113 ;; help with view.el and to Dave Gillespie for his suggestions on
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
114 ;; calc's use. This work has been partially inspired by Don Maszle
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
115 ;; and Jonathan Segal's.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
116
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
117 ;; By the way, I recommend you Inge Frick's view.el. It works like
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
118 ;; the standard view, but *it is not recursive* and has some more
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
119 ;; commands. Moreover it is a minor mode, so you preserve all your
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
120 ;; major mode keybindings (well, not always :). Mail me to obtain a
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
121 ;; copy, or get it by anonymous ftp in fly.cnuce.cnr.it:pub/view.el.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
122
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
123 ;; BUGS ==============================================================
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
124
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
125 ;; calc 2.02 does not handle the C operators "->", ".", "*" (as a
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
126 ;; prefix), the composite assignement operators "+=" etc. It cannot
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
127 ;; handle the "," operator and will be confused by ";". Almost all
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
128 ;; these can be defined as no-ops using the Calc's Syntax Tables
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
129 ;; feature. The built-in calc functions will cause problems in
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
130 ;; certain circumstances. c-macro-eval behaves correctly only on
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
131 ;; expressions not containing such operators. Does not distinguish
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
132 ;; among integer and real division.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
133
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
134 ;; If the start point of the region is inside a macro definition the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
135 ;; macro expansion is often inaccurate.
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1831
diff changeset
136
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
137 ;;; Code:
315
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
139 (defvar c-macro-shrink-window-p nil
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
140 "*Non-nil means shrink the *Macroexpansion* window to fit its contents.")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
141
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
142 (defvar c-macro-always-prompt-p nil
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
143 "*Non-nil means always prompt for preprocessor arguments.")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
144
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
145 (defvar c-macro-preprocessor "/lib/cpp -C" "\
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
146 The preprocessor used by the cmacexp package.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
147
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
148 If you change this, be sure to preserve the -C (don't strip comments)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
149 option, or to set an equivalent one.")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
150
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
151 (defvar c-macro-default-cppflags ""
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
152 "Default cpp flags used by c-macro-expand.")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
153
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
154 (defconst c-macro-buffer-name "*Macroexpansion*")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
155
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
156 (defun c-macro-expand (start end &optional flag) "\
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
157 Expand all C macros occurring in the region using c-macro-preprocessor.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
158 Normally display output in temp buffer.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
159 Prefix arg means replace the region with it.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
160 Prompt for a string of arguments to the preprocessor, (e.g.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
161 -DDEBUG -I ./include) when prefixed with two C-u's.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
162
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
163 It is intended for interactive use only.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
164 For non interactive use, see the c-macro-expansion function."
315
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
166 (interactive "r\nP")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
167 (let* ((subst (and flag (not (equal flag '(16)))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
168 (inbuf (current-buffer))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
169 (displaybuf (if subst
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
170 (get-buffer c-macro-buffer-name)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
171 (get-buffer-create c-macro-buffer-name)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
172 (expansion ""))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
173 ;; Build the command string.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
174 (if (or c-macro-always-prompt-p (equal flag '(16)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
175 (setq c-macro-default-cppflags
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
176 (read-string "Preprocessor arguments: "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
177 c-macro-default-cppflags)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
178 ;; Decide where to display output.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
179 (if (and subst
5817
6229dd3050be (c-macro-expand): Check inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents: 5816
diff changeset
180 (and buffer-read-only (not inhibit-read-only))
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
181 (not (eq inbuf displaybuf)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
182 (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
183 (message
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
184 "Buffer is read only: displaying expansion in alternate window")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
185 (sit-for 2)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
186 (setq subst nil)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
187 (or displaybuf
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
188 (setq displaybuf (get-buffer-create c-macro-buffer-name)))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
189 ;; Expand the macro and output it.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
190 (if (interactive-p) (message (c-macro-default-message)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
191 (setq expansion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
192 (c-macro-expansion start end
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
193 (concat c-macro-preprocessor " "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
194 c-macro-default-cppflags)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
195 (message (concat (c-macro-default-message) "done"))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
196 (if subst
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
197 (let ((exchange (= (point) start)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
198 (delete-region start end)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
199 (insert expansion)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
200 (if exchange
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
201 (exchange-point-and-mark)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
202 (set-buffer displaybuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
203 (setq buffer-read-only nil)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
204 (buffer-flush-undo displaybuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
205 (erase-buffer)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
206 (insert expansion)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
207 (set-buffer-modified-p nil)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
208 (if (string= "" expansion)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
209 (message "Null expansion")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
210 (c-macro-display-buffer inbuf))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
211 (setq buffer-read-only t)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
212 (bury-buffer displaybuf))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
213
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
214
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
215 ;; Display the current buffer in a window which is either just large
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
216 ;; enough to contain the entire buffer, or half the size of the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
217 ;; screen, whichever is smaller. Put the current buffer in view-mode
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
218 ;; if the Inge Frick's view-mode is installed, with buffer to return
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
219 ;; to set to RETBUF (if sensible). Do not select the new window.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
220 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
221 ;; Several factors influence window resizing so that the window is
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
222 ;; sized optimally if it is created anew, and so that it is messed
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
223 ;; with minimally if it has been created by the user. If the window
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
224 ;; chosen for display exists already but contains something else, the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
225 ;; window is not re-sized. If the window already contains the current
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
226 ;; buffer, it is never shrunk, but possibly expanded. Finally, if the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
227 ;; variable c-macro-shrink-window-p is nil the window size is *never*
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
228 ;; changed.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
229 (defun c-macro-display-buffer (retbuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
230
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
231 (goto-char (point-min))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
232 (c-mode)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
233 (require 'view) ;load view.el
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
234 (let ((oldwinheight (window-height))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
235 (alreadythere ;the window was already there
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
236 (get-buffer-window (current-buffer)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
237 (popped nil) ;the window popped changing the layout
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
238 (niceview ;is this Inge Fricks's view.el?
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
239 (boundp 'view-kill-when-finished)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
240
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
241 (or alreadythere
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
242 (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
243 (display-buffer (current-buffer) t)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
244 (setq popped (/= oldwinheight (window-height)))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
245 (if niceview
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
246 (view-mode 1)) ;set view mode
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
247 (if (and c-macro-shrink-window-p ;user wants fancy shrinking :\)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
248 (or alreadythere popped))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
249 ;; Enlarge up to half screen, or shrink properly.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
250 (let ((oldwin (selected-window))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
251 (minheight 0)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
252 (maxheight 0))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
253 (save-excursion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
254 (select-window (get-buffer-window (current-buffer)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
255 (setq minheight (if alreadythere
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
256 (window-height)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
257 window-min-height))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
258 (setq maxheight (/ (screen-height) 2))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
259 (enlarge-window (- (min maxheight
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
260 (max minheight
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
261 (+ 2 (vertical-motion 1000000))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
262 (window-height)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
263 (goto-char (point-min))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
264 (select-window oldwin))))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
265
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
266
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
267 (defun c-macro-expansion (start end cppcommand) "\
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
268 Expands the region between START and END in the current buffer using
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
269 the shell command CPPCOMMAND (e.g. \"/lib/cpp -C -DDEBUG\"). Be sure
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
270 to use a -C (don't strip comments) or equivalent option.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
271 Returns the output as a string."
315
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
273 ;; Copy the current buffer's contents to a temporary hidden buffer.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
274 ;; Delete from END to end of buffer. Insert a preprocessor #line
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
275 ;; directive at START and after each #endif following START that are
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
276 ;; not inside a comment or a string. Put all the strings thus
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
277 ;; inserted (without the "line" substring) in a list named linelist.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
278 ;; If START is inside a comment, prepend "*/" and append "/*" to the
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
279 ;; #line directive. If inside a string, prepend and append "\"".
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
280 ;; Preprocess the buffer contents, then look for all the lines stored
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
281 ;; in linelist starting from end of buffer. The last line so found is
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
282 ;; where START was, so return the substring from point to end of
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
283 ;; buffer.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
284 (let ((inbuf (current-buffer))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
285 (outbuf (get-buffer-create " *C Macro Expansion*"))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
286 (filename (if (and buffer-file-name
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
287 (string-match (regexp-quote default-directory)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
288 buffer-file-name))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
289 (substring buffer-file-name (match-end 0))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
290 (buffer-name)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
291 (linenum 0)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
292 (linelist ()))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
293 (unwind-protect
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
294 (save-excursion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
295 (save-restriction
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
296 (widen)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
297 (set-buffer outbuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
298 (setq buffer-read-only nil)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
299 (erase-buffer)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
300 (set-syntax-table c-mode-syntax-table)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
301 (insert-buffer-substring inbuf 1 end))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
302
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
303 ;; We have copied inbuf to outbuf. Point is at end of
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
304 ;; outbuf. Insert a space at the end, so cpp can correctly
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
305 ;; parse a token ending at END.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
306
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
307 (insert " ")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
308
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
309 ;; Now we insert the #line directives after all #endif or
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
310 ;; #else following START.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
311 ;(switch-to-buffer outbuf) (debug) ;debugging instructions
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
312 (while (re-search-backward "\n#\\(endif\\|else\\)\\>" start 'move)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
313 (if (equal (nthcdr 3 (parse-partial-sexp 1 (point)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
314 '(nil nil nil 0)) ;neither in string nor in
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
315 ;comment nor after quote
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
316 (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
317 (goto-char (match-end 0))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
318 (setq linenum (count-lines 1 (point)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
319 (setq linelist
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
320 (cons (format "\n# %d \"%s\"\n" linenum filename)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
321 linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
322 (insert (car linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
323 (skip-chars-backward "^#")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
324 (insert "line")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
325 (goto-char (match-beginning 0)))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
326
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
327 ;; We are at START. Insert the first #line directive. This
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
328 ;; must work even inside a string or comment, or after a
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
329 ;; quote.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
330 (setq linenum (+ (count-lines 1 (point))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
331 (if (bolp) 1 0)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
332 (setq linelist
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
333 (cons
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
334 (let* ((startstat (parse-partial-sexp 1 start))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
335 (startinstring (nth 3 startstat))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
336 (startincomment (nth 4 startstat))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
337 (startafterquote (nth 5 startstat)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
338 (concat (if startafterquote " ")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
339 (cond (startinstring "\"") (startincomment "*/"))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
340 (format "\n# %d \"%s\"\n" linenum filename)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
341 (cond (startinstring "\"") (startincomment "/*"))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
342 (if startafterquote "\\")))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
343 linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
344 (insert (car linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
345 (skip-chars-backward "^#")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
346 (insert "line")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
347
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
348 ;; Call the preprocessor.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
349 (call-process-region 1 (point-max) "sh" t t nil "-c"
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
350 (concat cppcommand " 2>/dev/null"))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
351
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
352 ;; Look for the `# nn "file.c"' lines from the last to the first
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
353 ;; and delete them.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
354 (setq linelist (reverse linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
355 (while (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
356 (if (search-backward (car linelist) nil t)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
357 (replace-match ""))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
358 (setq linelist (cdr linelist))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
359
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
360 ;; Compute the return value, keeping in account the space
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
361 ;; inserted at the end of the buffer.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
362 (buffer-substring (point) (max (point) (- (point-max) 1))))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 612
diff changeset
363
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
364 ;; Cleanup.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
365 (kill-buffer outbuf))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
366
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
367
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
368 ;; Experimental. With an argument, print signed, unsigned, hex and
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
369 ;; boolean representations.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
370 (defun c-macro-eval (start end &optional flag) "\
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
371 Expand region using cpp and evaluate it using calc.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
372 Interactively print value in minibuffer and push it on the kill ring.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
373 With a C-u argument shows the evaluation in a variety of formats.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
374 With two C-u's prompts the user for a string of flags to the preprocessor.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
375
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
376 Non interactively returns value of region between START and END
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
377 as a string. Several formats are used if optional FLAG is non-nil."
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
378
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
379 (interactive "r\nP")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
380 (or (fboundp 'calc-eval)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
381 (require 'calc))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
382 (if (or c-macro-always-prompt-p (equal flag '(16)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
383 (setq c-macro-default-cppflags
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
384 (read-string "Preprocessor arguments: "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
385 c-macro-default-cppflags)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
386
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
387 ;; Expand the region.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
388 (if (interactive-p) (message (c-macro-default-message)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
389 (let ((evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
390 (c-macro-expansion start end
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
391 (concat c-macro-preprocessor " "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
392 c-macro-default-cppflags)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
393 (evalbuf (get-buffer-create " *Macro Evaluation*")))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
394 (unwind-protect
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
395 (save-excursion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
396 (set-buffer evalbuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
397 (setq buffer-read-only nil)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
398 (erase-buffer)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
399 (insert evaluation)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
400
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
401 ;; Evaluate expression(s).
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
402 (if (interactive-p)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
403 (message "Invoking calc..."))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
404 (setq evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
405 (let ((calc-eval-error t))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
406 (calc-eval (list (buffer-string) 'calc-language 'c))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
407 (erase-buffer)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
408 (cond
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
409 (flag
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
410 (insert (calc-eval (list evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
411 'calc-language 'c
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
412 'calc-simplify-mode 'binary))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
413 "(u)" " == "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
414 (calc-eval (list evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
415 'calc-language 'c
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
416 'calc-word-size (- calc-word-size)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
417 'calc-simplify-mode 'binary))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
418 "(d)" " == "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
419 (calc-eval (list evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
420 'calc-language 'c
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
421 'calc-number-radix 16
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
422 'calc-simplify-mode 'binary))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
423 "(x)")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
424 (save-excursion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
425 (insert " == " (calc-eval (list evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
426 'calc-language 'c
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
427 'calc-number-radix 16
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
428 'calc-simplify-mode 'binary))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
429 (while (re-search-forward "0x\\([^,]+\\)\\(, \\|\\'\\)" nil t)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
430 (if (string= "0"
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
431 (buffer-substring (match-beginning 1)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
432 (match-end 1)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
433 (replace-match "FALSE\\2")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
434 (replace-match "TRUE\\2"))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
435 (t
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
436 (insert evaluation)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
437
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
438 ;; Output the evaluation.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
439 (if (interactive-p)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
440 (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
441 (copy-region-as-kill 1 (point-max))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
442 (message (buffer-string)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
443 (buffer-string)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
444 (kill-buffer evalbuf))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
445
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
446 (defun c-macro-default-message ()
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
447 (format "Invoking %s%s%s on region..."
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
448 c-macro-preprocessor
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
449 (if (string= "" c-macro-default-cppflags) "" " ")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
450 c-macro-default-cppflags))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
451
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
452 (provide 'cmacexp)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
453
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
454 ;;; cmacexp.el ends here.