Mercurial > emacs
annotate lisp/progmodes/cmacexp.el @ 14171:e8e99446ef2c
Comment fixes.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Sun, 14 Jan 1996 14:30:11 +0000 |
parents | 83f275dcd93a |
children | 9defc34879ad |
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 |
7298 | 3 ;; Copyright (C) 1992, 1994 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> |
14169 | 6 ;; Version: $Id: cmacexp.el,v 1.20 1995/10/26 03:14:40 rms Exp erik $ |
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 | 10 ;; This file is part of GNU Emacs. |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
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 | 15 ;; any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
315 | 26 |
6979 | 27 ;; USAGE ============================================================= |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
28 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
29 ;; In C mode C-C C-e is bound to c-macro-expand. The result of the |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
30 ;; expansion is put in a separate buffer. A user option allows the |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
31 ;; window displaying the buffer to be optimally sized. |
5816
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 |
6979 | 34 ;; region with the expansion. Both the preprocessor name and the |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
35 ;; initial flag can be set by the user. If c-macro-prompt-flag is set |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
36 ;; to a non-nil value the user is offered to change the options to the |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
37 ;; preprocessor each time c-macro-expand is invoked. Preprocessor |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
38 ;; arguments default to the last ones entered. If c-macro-prompt-flag |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
39 ;; is nil, one must use M-x set-variable to set a different value for |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
40 ;; c-macro-cppflags. |
5816
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 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
44 ;; INSTALLATION ====================================================== |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
45 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
46 ;; Put the following in your ~/.emacs file. |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
47 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
48 ;; 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
|
49 ;; necessary: |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
50 ;;(setq c-macro-shrink-window-flag t) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
51 ;; |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
52 ;; 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
|
53 ;; -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
|
54 ;; strip the comments): |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
55 ;;(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
|
56 ;; |
6979 | 57 ;; If you often use a particular set of flags: |
58 ;;(setq c-macro-cppflags "-I /usr/include/local -DDEBUG" | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
59 ;; |
6979 | 60 ;; If you want the "Preprocessor arguments: " prompt: |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
61 ;;(setq c-macro-prompt-flag t) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
62 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
63 ;; BUG REPORTS ======================================================= |
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 ;; 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
|
66 ;; 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
|
67 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
68 ;; 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
|
69 |
8679
ccfc2ca24a90
* cmacexp.el (c-macro-prompt-flag): set default to t.
Francesco Potortì <pot@gnu.org>
parents:
8537
diff
changeset
|
70 ;; - A lot of user and programmer visible changes. See above. |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
71 ;; - #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
|
72 ;; 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
|
73 ;; 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
|
74 ;; 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
|
75 ;; - 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
|
76 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
77 ;; ACKNOWLEDGEMENTS ================================================== |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
78 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
79 ;; A lot of thanks to Don Maszle who did a great work of testing, bug |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
80 ;; reporting and suggestion of new features. This work has been |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
81 ;; partially inspired by 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
|
82 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
83 ;; BUGS ============================================================== |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
84 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
85 ;; 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
|
86 ;; macro expansion is often inaccurate. |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
87 |
6979 | 88 |
13298 | 89 (require 'cc-mode) |
90 | |
6979 | 91 (provide 'cmacexp) |
315 | 92 |
6981 | 93 (defvar c-macro-shrink-window-flag nil |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
94 "*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
|
95 |
8705
addaa3f01955
(c-macro-prompt-flag): Set default back to nil.
Richard M. Stallman <rms@gnu.org>
parents:
8679
diff
changeset
|
96 (defvar c-macro-prompt-flag nil |
6981 | 97 "*Non-nil makes `c-macro-expand' prompt for preprocessor arguments.") |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
98 |
6981 | 99 (defvar c-macro-preprocessor "/lib/cpp -C" |
100 "The preprocessor used by the cmacexp package. | |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
101 |
8476 | 102 If you change this, be sure to preserve the `-C' (don't strip comments) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
103 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
|
104 |
6979 | 105 (defvar c-macro-cppflags "" |
8476 | 106 "*Preprocessor flags used by `c-macro-expand'.") |
5816
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 (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
|
109 |
6981 | 110 (defun c-macro-expand (start end subst) |
111 "Expand C macros in the region, using the C preprocessor. | |
112 Normally display output in temp buffer, but | |
113 prefix arg means replace the region with it. | |
114 | |
115 `c-macro-preprocessor' specifies the preprocessor to use. | |
116 Prompt for arguments to the preprocessor \(e.g. `-DDEBUG -I ./include') | |
117 if the user option `c-macro-prompt-flag' is non-nil. | |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
118 |
6979 | 119 Noninteractive args are START, END, SUBST. |
6981 | 120 For use inside Lisp programs, see also `c-macro-expansion'." |
315 | 121 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
122 (interactive "r\nP") |
6979 | 123 (let ((inbuf (current-buffer)) |
124 (displaybuf (if subst | |
125 (get-buffer c-macro-buffer-name) | |
126 (get-buffer-create c-macro-buffer-name))) | |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
127 (expansion "")) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
128 ;; Build the command string. |
6981 | 129 (if c-macro-prompt-flag |
6979 | 130 (setq c-macro-cppflags |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
131 (read-string "Preprocessor arguments: " |
6979 | 132 c-macro-cppflags))) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
133 ;; 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
|
134 (if (and subst |
5817
6229dd3050be
(c-macro-expand): Check inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5816
diff
changeset
|
135 (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
|
136 (not (eq inbuf displaybuf))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
137 (progn |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
138 (message |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
139 "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
|
140 (sit-for 2) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
141 (setq subst nil) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
142 (or displaybuf |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
143 (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
|
144 ;; Expand the macro and output it. |
6979 | 145 (setq expansion (c-macro-expansion start end |
146 (concat c-macro-preprocessor " " | |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
147 c-macro-cppflags) t)) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
148 (if subst |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
149 (let ((exchange (= (point) start))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
150 (delete-region start end) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
151 (insert expansion) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
152 (if exchange |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
153 (exchange-point-and-mark))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
154 (set-buffer displaybuf) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
155 (setq buffer-read-only nil) |
8679
ccfc2ca24a90
* cmacexp.el (c-macro-prompt-flag): set default to t.
Francesco Potortì <pot@gnu.org>
parents:
8537
diff
changeset
|
156 (buffer-disable-undo displaybuf) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
157 (erase-buffer) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
158 (insert expansion) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
159 (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
|
160 (if (string= "" expansion) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
161 (message "Null expansion") |
6979 | 162 (c-macro-display-buffer)) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
163 (setq buffer-read-only t) |
6979 | 164 (setq buffer-auto-save-file-name nil) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
165 (bury-buffer displaybuf)))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
166 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
167 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
168 ;; 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
|
169 ;; enough to contain the entire buffer, or half the size of the |
6979 | 170 ;; screen, whichever is smaller. Do not select the new |
171 ;; window. | |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
172 ;; |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
173 ;; 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
|
174 ;; 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
|
175 ;; 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
|
176 ;; 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
|
177 ;; 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
|
178 ;; buffer, it is never shrunk, but possibly expanded. Finally, if the |
6981 | 179 ;; variable c-macro-shrink-window-flag is nil the window size is *never* |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
180 ;; changed. |
6979 | 181 (defun c-macro-display-buffer () |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
182 (goto-char (point-min)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
183 (c-mode) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
184 (let ((oldwinheight (window-height)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
185 (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
|
186 (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
|
187 (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
|
188 (or alreadythere |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
189 (progn |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
190 (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
|
191 (setq popped (/= oldwinheight (window-height))))) |
6981 | 192 (if (and c-macro-shrink-window-flag ;user wants fancy shrinking :\) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
193 (or alreadythere popped)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
194 ;; 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
|
195 (let ((oldwin (selected-window)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
196 (minheight 0) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
197 (maxheight 0)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
198 (save-excursion |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
199 (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
|
200 (setq minheight (if alreadythere |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
201 (window-height) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
202 window-min-height)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
203 (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
|
204 (enlarge-window (- (min maxheight |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
205 (max minheight |
6979 | 206 (+ 2 (vertical-motion (point-max))))) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
207 (window-height))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
208 (goto-char (point-min)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
209 (select-window oldwin)))))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
210 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
211 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
212 (defun c-macro-expansion (start end cppcommand &optional display) |
6981 | 213 "Run a preprocessor on region and return the output as a string. |
6979 | 214 Expand the region between START and END in the current buffer using |
215 the shell command CPPCOMMAND (e.g. \"/lib/cpp -C -DDEBUG\"). | |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
216 Be sure to use a -C (don't strip comments) or equivalent option. |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
217 Optional arg DISPLAY non-nil means show messages in the echo area." |
315 | 218 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
219 ;; 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
|
220 ;; 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
|
221 ;; 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
|
222 ;; 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
|
223 ;; 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
|
224 ;; 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
|
225 ;; #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
|
226 ;; 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
|
227 ;; 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
|
228 ;; 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
|
229 ;; buffer. |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
230 (let ((inbuf (current-buffer)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
231 (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
|
232 (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
|
233 (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
|
234 buffer-file-name)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
235 (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
|
236 (buffer-name))) |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
237 (mymsg (format "Invoking %s%s%s on region..." |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
238 c-macro-preprocessor |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
239 (if (string= "" c-macro-cppflags) "" " ") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
240 c-macro-cppflags)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
241 (uniquestring "???!!!???!!! start of c-macro expansion ???!!!???!!!") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
242 (startlinenum 0) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
243 (linenum 0) |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
244 (startstat ()) |
8476 | 245 (startmarker "") |
8679
ccfc2ca24a90
* cmacexp.el (c-macro-prompt-flag): set default to t.
Francesco Potortì <pot@gnu.org>
parents:
8537
diff
changeset
|
246 (exit-status 0) |
8476 | 247 (tempname (make-temp-name "/tmp/"))) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
248 (unwind-protect |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
249 (save-excursion |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
250 (save-restriction |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
251 (widen) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
252 (set-buffer outbuf) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
253 (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
|
254 (erase-buffer) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
255 (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
|
256 (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
|
257 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
258 ;; 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
|
259 ;; 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
|
260 ;; 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
|
261 (insert " ") |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
262 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
263 ;; Save sexp status and line number at START. |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
264 (setq startstat (parse-partial-sexp 1 start)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
265 (setq startlinenum (+ (count-lines 1 (point)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
266 (if (bolp) 1 0))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
267 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
268 ;; Now we insert the #line directives after all #endif or |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
269 ;; #else following START going backward, so the lines we |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
270 ;; insert don't change the line numbers. |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
271 ;(switch-to-buffer outbuf) (debug) ;debugging instructions |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
272 (goto-char (point-max)) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
273 (while (re-search-backward "\n#\\(endif\\|else\\)\\>" start 'move) |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
274 (if (equal (nthcdr 3 (parse-partial-sexp start (point) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
275 nil nil startstat)) |
6981 | 276 '(nil nil nil 0 nil)) ;neither in string nor in |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
277 ;comment nor after quote |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
278 (progn |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
279 (goto-char (match-end 0)) |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
280 (setq linenum (+ startlinenum |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
281 (count-lines start (point)))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
282 (insert (format "\n#line %d \"%s\"\n" linenum filename)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
283 (goto-char (match-beginning 0))))) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
284 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
285 ;; Now we are at START. Insert the first #line directive. |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
286 ;; This must work even inside a string or comment, or after a |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
287 ;; quote. |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
288 (let* ((startinstring (nth 3 startstat)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
289 (startincomment (nth 4 startstat)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
290 (startafterquote (nth 5 startstat)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
291 (startinbcomment (nth 7 startstat))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
292 (insert (if startafterquote " " "") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
293 (cond (startinstring |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
294 (char-to-string startinstring)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
295 (startincomment "*/") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
296 ("")) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
297 (setq startmarker |
10931
933a04abe0ac
* cmacexp.el (c-macro-expansion): put the unique string before the
Francesco Potortì <pot@gnu.org>
parents:
8705
diff
changeset
|
298 (concat "\n" uniquestring |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
299 (cond (startinstring |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
300 (char-to-string startinstring)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
301 (startincomment "/*") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
302 (startinbcomment "//")) |
10931
933a04abe0ac
* cmacexp.el (c-macro-expansion): put the unique string before the
Francesco Potortì <pot@gnu.org>
parents:
8705
diff
changeset
|
303 (if startafterquote "\\"))) |
933a04abe0ac
* cmacexp.el (c-macro-expansion): put the unique string before the
Francesco Potortì <pot@gnu.org>
parents:
8705
diff
changeset
|
304 (format "\n#line %d \"%s\"\n" startlinenum filename))) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
305 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
306 ;; Call the preprocessor. |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
307 (if display (message mymsg)) |
8476 | 308 (setq exit-status |
309 (call-process-region 1 (point-max) "sh" t t nil "-c" | |
310 (concat cppcommand " 2>" tempname))) | |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
311 (if display (message (concat mymsg "done"))) |
8537
fcddf3261917
(c-macro-expansion): If the CPP output is empty, just show error messages.
Richard M. Stallman <rms@gnu.org>
parents:
8476
diff
changeset
|
312 (if (= (buffer-size) 0) |
fcddf3261917
(c-macro-expansion): If the CPP output is empty, just show error messages.
Richard M. Stallman <rms@gnu.org>
parents:
8476
diff
changeset
|
313 ;; Empty output is normal after a fatal error. |
fcddf3261917
(c-macro-expansion): If the CPP output is empty, just show error messages.
Richard M. Stallman <rms@gnu.org>
parents:
8476
diff
changeset
|
314 (insert "\nPreprocessor produced no output\n") |
fcddf3261917
(c-macro-expansion): If the CPP output is empty, just show error messages.
Richard M. Stallman <rms@gnu.org>
parents:
8476
diff
changeset
|
315 ;; Find and delete the mark of the start of the expansion. |
fcddf3261917
(c-macro-expansion): If the CPP output is empty, just show error messages.
Richard M. Stallman <rms@gnu.org>
parents:
8476
diff
changeset
|
316 ;; Look for `# nn "file.c"' lines and delete them. |
fcddf3261917
(c-macro-expansion): If the CPP output is empty, just show error messages.
Richard M. Stallman <rms@gnu.org>
parents:
8476
diff
changeset
|
317 (goto-char (point-min)) |
fcddf3261917
(c-macro-expansion): If the CPP output is empty, just show error messages.
Richard M. Stallman <rms@gnu.org>
parents:
8476
diff
changeset
|
318 (search-forward startmarker) |
fcddf3261917
(c-macro-expansion): If the CPP output is empty, just show error messages.
Richard M. Stallman <rms@gnu.org>
parents:
8476
diff
changeset
|
319 (delete-region 1 (point))) |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
320 (while (re-search-forward (concat "^# [0-9]+ \"" |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
321 (regexp-quote filename) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
322 "\"") nil t) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
323 (beginning-of-line) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
324 (let ((beg (point))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
325 (forward-line 1) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
326 (delete-region beg (point)))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
327 |
8476 | 328 ;; If CPP got errors, show them at the beginning. |
329 (or (eq exit-status 0) | |
330 (progn | |
331 (goto-char (point-min)) | |
332 (insert (format "Preprocessor terminated with status %s\n" | |
333 exit-status)) | |
334 (insert-file-contents tempname) | |
335 (insert "\n"))) | |
336 (delete-file tempname) | |
337 | |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
338 ;; 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
|
339 ;; inserted at the end of the buffer. |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
340 (buffer-substring 1 (max 1 (- (point-max) 1)))) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
341 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
342 ;; Cleanup. |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
343 (kill-buffer outbuf)))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
344 |
6979 | 345 ;;; cmacexp.el ends here |