annotate lisp/progmodes/cmacexp.el @ 6487:e1b0356ae3c9

(Fscroll_up, Fscroll_down, Fscroll_other_window): Doc fix.
author Karl Heuer <kwzh@gnu.org>
date Wed, 23 Mar 1994 20:31:08 +0000
parents fc2dc869f5d4
children 3086be8e7683
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>
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
6 ;; Version: $Id: cmacexp.el,v 1.9 1994/02/07 05:40:46 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
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
29 ;; expansion is put in a separate buffer. A user option
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
30 ;; 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
31 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
32 ;; 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
33 ;; 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
34 ;; 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
35 ;; 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
36 ;; 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
37 ;; 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
38 ;; 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
39 ;; 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
40
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
41 ;; 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
42 ;; 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
43 ;; 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
44 ;; 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
45 ;; 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
46 ;; 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
47 ;; 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
48 ;; 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
49 ;; 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
50 ;; 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
51 ;; 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
52
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
53 ;; 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
54 ;; 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
55
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
56 ;; INSTALLATION ======================================================
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
57
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
58 ;; 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
59 ;; 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
60
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
61 ;; 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
62 ;;(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
63 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
64 ;; 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
65 ;;(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
66 ;;(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
67 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
68 ;; 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
69 ;; necessary:
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
70 ;;(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
71 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
72 ;; 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
73 ;; -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
74 ;; strip the comments):
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
75 ;;(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
76 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
77 ;; 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
78 ;; the default:
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
79 ;;(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
80 ;;
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
81 ;; 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
82 ;; 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
83 ;;(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
84 ;;
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
85 ;; 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
86 ;; evaluation feature:
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
87 ;;(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
88 ;; "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
89
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
90 ;; BUG REPORTS =======================================================
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
91
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
92 ;; 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
93 ;; 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
94
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
95 ;; 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
96
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
97 ;; - 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
98 ;; - #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
99 ;; 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
100 ;; 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
101 ;; 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
102 ;; - 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
103 ;; - 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
104 ;; 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
105 ;; 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
106 ;; 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
107
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
108 ;; ACKNOWLEDGEMENTS ==================================================
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
109
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
110 ;; A lot of thanks to Don Maszle who did a great work of testing, bug
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
111 ;; reporting and suggestion of new features and to Dave Gillespie for
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
112 ;; his suggestions about calc. This work has been partially inspired by
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
113 ;; Don Maszle and Jonathan Segal's.
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
114
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
115 ;; BUGS ==============================================================
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 ;; 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
118 ;; 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
119 ;; 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
120 ;; 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
121 ;; 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
122 ;; 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
123 ;; 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
124 ;; 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
125
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
126 ;; 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
127 ;; macro expansion is often inaccurate.
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1831
diff changeset
128
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
129 ;;; Code:
315
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
131 (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
132 "*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
133
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
134 (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
135 "*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
136
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
137 (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
138 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
139
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
140 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
141 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
142
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
143 (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
144 "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
145
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
146 (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
147
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
148 (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
149 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
150 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
151 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
152 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
153 -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
154
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
155 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
156 For non interactive use, see the c-macro-expansion function."
315
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
158 (interactive "r\nP")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
159 (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
160 (inbuf (current-buffer))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
161 (displaybuf (if subst
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
162 (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
163 (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
164 (expansion ""))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
165 ;; Build the command string.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
166 (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
167 (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
168 (read-string "Preprocessor arguments: "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
169 c-macro-default-cppflags)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
170 ;; 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
171 (if (and subst
5817
6229dd3050be (c-macro-expand): Check inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents: 5816
diff changeset
172 (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
173 (not (eq inbuf displaybuf)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
174 (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
175 (message
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
176 "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
177 (sit-for 2)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
178 (setq subst nil)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
179 (or displaybuf
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
180 (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
181 ;; 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
182 (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
183 (setq expansion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
184 (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
185 (concat c-macro-preprocessor " "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
186 c-macro-default-cppflags)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
187 (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
188 (if subst
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
189 (let ((exchange (= (point) start)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
190 (delete-region start end)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
191 (insert expansion)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
192 (if exchange
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
193 (exchange-point-and-mark)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
194 (set-buffer displaybuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
195 (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
196 (buffer-flush-undo displaybuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
197 (erase-buffer)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
198 (insert expansion)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
199 (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
200 (if (string= "" expansion)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
201 (message "Null expansion")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
202 (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
203 (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
204 (bury-buffer displaybuf))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
205
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
206
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
207 ;; 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
208 ;; 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
209 ;; 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
210 ;; 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
211 ;; 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
212 ;;
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
213 ;; 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
214 ;; 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
215 ;; 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
216 ;; 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
217 ;; 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
218 ;; 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
219 ;; 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
220 ;; changed.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
221 (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
222
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
223 (goto-char (point-min))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
224 (c-mode)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
225 (let ((oldwinheight (window-height))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
226 (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
227 (get-buffer-window (current-buffer)))
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
228 (popped nil)) ;the window popped changing the layout
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
229 (or alreadythere
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
230 (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
231 (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
232 (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
233 (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
234 (or alreadythere popped))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
235 ;; 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
236 (let ((oldwin (selected-window))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
237 (minheight 0)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
238 (maxheight 0))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
239 (save-excursion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
240 (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
241 (setq minheight (if alreadythere
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
242 (window-height)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
243 window-min-height))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
244 (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
245 (enlarge-window (- (min maxheight
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
246 (max minheight
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
247 (+ 2 (vertical-motion 1000000))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
248 (window-height)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
249 (goto-char (point-min))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
250 (select-window oldwin))))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
251
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
252
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
253 (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
254 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
255 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
256 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
257 Returns the output as a string."
315
faf70884106b Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
259 ;; 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
260 ;; 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
261 ;; 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
262 ;; 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
263 ;; 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
264 ;; 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
265 ;; #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
266 ;; 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
267 ;; 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
268 ;; 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
269 ;; buffer.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
270 (let ((inbuf (current-buffer))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
271 (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
272 (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
273 (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
274 buffer-file-name))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
275 (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
276 (buffer-name)))
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
277 (start-state)
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
278 (linenum 0)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
279 (linelist ()))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
280 (unwind-protect
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
281 (save-excursion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
282 (save-restriction
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
283 (widen)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
284 (set-buffer outbuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
285 (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
286 (erase-buffer)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
287 (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
288 (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
289
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
290 ;; 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
291 ;; 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
292 ;; 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
293
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
294 (insert " ")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
295
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
296 (save-excursion
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
297 (goto-char start)
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
298 (setq start-state (parse-partial-sexp 1 (point))))
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
299 ;; 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
300 ;; #else following START.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
301 ;(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
302 (while (re-search-backward "\n#\\(endif\\|else\\)\\>" start 'move)
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
303 (if (equal (nthcdr 3 (parse-partial-sexp start (point) start-state))
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
304 '(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
305 ;comment nor after quote
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
306 (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
307 (goto-char (match-end 0))
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
308 ;; (setq linenum (count-lines 1 (point)))
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
309 (setq linelist
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
310 ;; This used to be a #line command
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
311 ;; but it's not guaranteed that the output
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
312 ;; will have properly matching commands.
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
313 ;; Only the *line numbers* have to agree!
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
314 (cons (format "\n???!!!???!!!!\n")
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
315 linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
316 (insert (car linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
317 (skip-chars-backward "^#")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
318 (insert "line")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
319 (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
320
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
321 ;; 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
322 ;; 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
323 ;; quote.
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
324 ;;; (setq linenum (+ (count-lines 1 (point))
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
325 ;;; (if (bolp) 1 0)))
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
326 (setq linelist
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
327 (cons
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
328 (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
329 (startinstring (nth 3 startstat))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
330 (startincomment (nth 4 startstat))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
331 (startafterquote (nth 5 startstat)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
332 (concat (if startafterquote " ")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
333 (cond (startinstring "\"") (startincomment "*/"))
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
334 (format "\n???!!!???!!!!")
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
335 (cond (startinstring "\"") (startincomment "/*"))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
336 (if startafterquote "\\")))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
337 linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
338 (insert (car linelist))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
339 (skip-chars-backward "^#")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
340 (insert "line")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
341
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
342 ;; Call the preprocessor.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
343 (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
344 (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
345
6086
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
346 (while (search-backward "\n???!!!???!!!!" nil t)
fc2dc869f5d4 (c-macro-display-buffer): Delete special view-mode hack.
Richard M. Stallman <rms@gnu.org>
parents: 5817
diff changeset
347 (replace-match ""))
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
348
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
349 ;; 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
350 ;; 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
351 (buffer-substring (point) (max (point) (- (point-max) 1))))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 612
diff changeset
352
5816
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
353 ;; Cleanup.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
354 (kill-buffer outbuf))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
355
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
356
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
357 ;; 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
358 ;; boolean representations.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
359 (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
360 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
361 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
362 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
363 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
364
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
365 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
366 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
367
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
368 (interactive "r\nP")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
369 (or (fboundp 'calc-eval)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
370 (require 'calc))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
371 (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
372 (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
373 (read-string "Preprocessor arguments: "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
374 c-macro-default-cppflags)))
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 ;; Expand the region.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
377 (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
378 (let ((evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
379 (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
380 (concat c-macro-preprocessor " "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
381 c-macro-default-cppflags)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
382 (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
383 (unwind-protect
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
384 (save-excursion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
385 (set-buffer evalbuf)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
386 (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
387 (erase-buffer)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
388 (insert evaluation)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
389
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
390 ;; Evaluate expression(s).
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
391 (if (interactive-p)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
392 (message "Invoking calc..."))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
393 (setq evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
394 (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
395 (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
396 (erase-buffer)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
397 (cond
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
398 (flag
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
399 (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
400 'calc-language 'c
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
401 'calc-simplify-mode 'binary))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
402 "(u)" " == "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
403 (calc-eval (list evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
404 'calc-language 'c
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
405 '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
406 'calc-simplify-mode 'binary))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
407 "(d)" " == "
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
408 (calc-eval (list evaluation
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
409 'calc-language 'c
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
410 'calc-number-radix 16
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
411 'calc-simplify-mode 'binary))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
412 "(x)")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
413 (save-excursion
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
414 (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
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-number-radix 16
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 (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
419 (if (string= "0"
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
420 (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
421 (match-end 1)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
422 (replace-match "FALSE\\2")
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
423 (replace-match "TRUE\\2"))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
424 (t
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
425 (insert evaluation)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
426
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
427 ;; Output the evaluation.
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
428 (if (interactive-p)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
429 (progn
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
430 (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
431 (message (buffer-string)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
432 (buffer-string)))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
433 (kill-buffer evalbuf))))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
434
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
435 (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
436 (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
437 c-macro-preprocessor
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
438 (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
439 c-macro-default-cppflags))
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
440
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
441 (provide 'cmacexp)
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
442
c381f562cffc Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
443 ;;; cmacexp.el ends here.