Mercurial > emacs
annotate lisp/progmodes/cmacexp.el @ 110561:93141d34a175
Fix typos.
* lisp/finder.el (finder-unknown-keywords):
* lisp/progmodes/gdb-mi.el (gdb-jsonify-buffer, gdb-running-threads-count):
* lisp/progmodes/etags.el (tags-table-including): Fix typos in docstrings.
* lisp/cedet/semantic/lex.el (semantic-ignore-comments): Doc fix.
* lisp/cedet/semantic/symref/list.el (semantic-symref-list-rename-open-hits):
Fix typo in error message.
(semantic-symref-list-map-open-hits): Fix typo in docstring.
* lisp/org/org-agenda.el (org-agenda-hide-tags-regexp):
* lisp/org/org.el (org-refile-targets): Fix typos in docstrings.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Sat, 25 Sep 2010 14:04:35 +0200 |
parents | 1d1d5d9bd884 |
children | 376148b31b5e |
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 |
100908 | 3 ;; Copyright (C) 1992, 1994, 1996, 2000, 2001, 2002, 2003, 2004, 2005, |
106815 | 4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
5 |
32807
7d91ceb03536
Update author's email address.
Eli Zaretskii <eliz@gnu.org>
parents:
26318
diff
changeset
|
6 ;; Author: Francesco Potorti` <pot@gnu.org> |
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 |
94116
842d446b22d9
Cleanup the bug-report email addresses and make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
10 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this |
842d446b22d9
Cleanup the bug-report email addresses and make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
11 ;; file, and the maintainer agreed that when a bug is filed in the |
842d446b22d9
Cleanup the bug-report email addresses and make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
12 ;; Emacs bug reporting system against this file, a copy of the bug |
842d446b22d9
Cleanup the bug-report email addresses and make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
13 ;; report be sent to the maintainer's email address. However, the |
842d446b22d9
Cleanup the bug-report email addresses and make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
14 ;; maintainer prefers not to be the only person maintaining this file |
842d446b22d9
Cleanup the bug-report email addresses and make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
15 ;; in future. |
842d446b22d9
Cleanup the bug-report email addresses and make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
16 |
315 | 17 ;; This file is part of GNU Emacs. |
18 | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94116
diff
changeset
|
19 ;; GNU Emacs is free software: you can redistribute it and/or modify |
315 | 20 ;; it under the terms of the GNU General Public License as published by |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94116
diff
changeset
|
21 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94116
diff
changeset
|
22 ;; (at your option) any later version. |
315 | 23 |
24 ;; GNU Emacs is distributed in the hope that it will be useful, | |
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27 ;; GNU General Public License for more details. | |
28 | |
29 ;; You should have received a copy of the GNU General Public License | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94116
diff
changeset
|
30 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
315 | 31 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32807
diff
changeset
|
32 ;;; Commentary: |
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32807
diff
changeset
|
33 |
6979 | 34 ;; USAGE ============================================================= |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
35 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
36 ;; 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
|
37 ;; 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
|
38 ;; 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
|
39 ;; |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
40 ;; When called with a C-u prefix, c-macro-expand replaces the selected |
6979 | 41 ;; 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
|
42 ;; 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
|
43 ;; 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
|
44 ;; 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
|
45 ;; 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
|
46 ;; 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
|
47 ;; c-macro-cppflags. |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
48 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
49 ;; 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
|
50 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
51 ;; INSTALLATION ====================================================== |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
52 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
53 ;; 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
|
54 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
55 ;; If you want the *Macroexpansion* window to be not higher than |
26318
94efc4f944a4
progmodes/cmacexp.el (c-macro-preprocessor): Find the Solaris cpp.
Sam Steingold <sds@gnu.org>
parents:
26039
diff
changeset
|
56 ;; necessary: |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
57 ;;(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
|
58 ;; |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
59 ;; 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
|
60 ;; -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
|
61 ;; strip the comments): |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
62 ;;(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
|
63 ;; |
6979 | 64 ;; If you often use a particular set of flags: |
65 ;;(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
|
66 ;; |
6979 | 67 ;; 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
|
68 ;;(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
|
69 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
70 ;; BUG REPORTS ======================================================= |
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 ;; Please report bugs, suggestions, complaints and so on to |
32807
7d91ceb03536
Update author's email address.
Eli Zaretskii <eliz@gnu.org>
parents:
26318
diff
changeset
|
73 ;; pot@gnu.org (Francesco Potorti`). |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
74 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
75 ;; 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
|
76 |
8679
ccfc2ca24a90
* cmacexp.el (c-macro-prompt-flag): set default to t.
Francesco Potortì <pot@gnu.org>
parents:
8537
diff
changeset
|
77 ;; - 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
|
78 ;; - #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
|
79 ;; 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
|
80 ;; 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
|
81 ;; 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
|
82 ;; - 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
|
83 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
84 ;; ACKNOWLEDGEMENTS ================================================== |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
85 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
86 ;; 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
|
87 ;; 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
|
88 ;; 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
|
89 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
90 ;; BUGS ============================================================== |
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 ;; 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
|
93 ;; macro expansion is often inaccurate. |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1831
diff
changeset
|
94 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32807
diff
changeset
|
95 ;;; Code: |
6979 | 96 |
13298 | 97 (require 'cc-mode) |
98 | |
6979 | 99 (provide 'cmacexp) |
315 | 100 |
65227
35c9b3d1f7df
(msdos-shells): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64699
diff
changeset
|
101 (defvar msdos-shells) |
35c9b3d1f7df
(msdos-shells): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64699
diff
changeset
|
102 |
35c9b3d1f7df
(msdos-shells): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64699
diff
changeset
|
103 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
104 (defgroup c-macro nil |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
105 "Expand C macros in a region." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
106 :group 'c) |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
107 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
108 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
109 (defcustom c-macro-shrink-window-flag nil |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
110 "*Non-nil means shrink the *Macroexpansion* window to fit its contents." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
111 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
112 :group 'c-macro) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
113 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
114 (defcustom c-macro-prompt-flag nil |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
115 "*Non-nil makes `c-macro-expand' prompt for preprocessor arguments." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
116 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
117 :group 'c-macro) |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
118 |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
119 (defcustom c-macro-preprocessor |
62112
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
120 (cond ;; Solaris has it in an unusual place. |
15353
26a5accd904d
(c-macro-preprocessor): New clause for Solaris.
Richard M. Stallman <rms@gnu.org>
parents:
15268
diff
changeset
|
121 ((and (string-match "^[^-]*-[^-]*-\\(solaris\\|sunos5\\)" |
26a5accd904d
(c-macro-preprocessor): New clause for Solaris.
Richard M. Stallman <rms@gnu.org>
parents:
15268
diff
changeset
|
122 system-configuration) |
26a5accd904d
(c-macro-preprocessor): New clause for Solaris.
Richard M. Stallman <rms@gnu.org>
parents:
15268
diff
changeset
|
123 (file-exists-p "/opt/SUNWspro/SC3.0.1/bin/acomp")) |
26a5accd904d
(c-macro-preprocessor): New clause for Solaris.
Richard M. Stallman <rms@gnu.org>
parents:
15268
diff
changeset
|
124 "/opt/SUNWspro/SC3.0.1/bin/acomp -C -E") |
62112
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
125 ((locate-file "/usr/ccs/lib/cpp" |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
126 '("/") exec-suffixes 'file-executable-p) |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
127 "/usr/ccs/lib/cpp -C") |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
128 ((locate-file "/lib/cpp" |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
129 '("/") exec-suffixes 'file-executable-p) |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
130 "/lib/cpp -C") |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
131 ;; On some systems, we cannot rely on standard directories to |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
132 ;; find CPP. In fact, we cannot rely on having cpp, either, |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
133 ;; in some GCC versions. |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
134 ((locate-file "cpp" exec-path exec-suffixes 'file-executable-p) |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
135 "cpp -C") |
e1aa7e2ac9e5
(c-macro-preprocessor): Use locate-file to look for the preprocessor
Eli Zaretskii <eliz@gnu.org>
parents:
62066
diff
changeset
|
136 (t "gcc -E -C -o - -")) |
6981 | 137 "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
|
138 |
8476 | 139 If you change this, be sure to preserve the `-C' (don't strip comments) |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
140 option, or to set an equivalent one." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
141 :type 'string |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
142 :group 'c-macro) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
143 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
144 (defcustom c-macro-cppflags "" |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
145 "*Preprocessor flags used by `c-macro-expand'." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
146 :type 'string |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
15353
diff
changeset
|
147 :group 'c-macro) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
148 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
149 (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
|
150 |
19529
5ccd55d16f8c
(c-macro-expand): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
18402
diff
changeset
|
151 ;;;###autoload |
6981 | 152 (defun c-macro-expand (start end subst) |
153 "Expand C macros in the region, using the C preprocessor. | |
154 Normally display output in temp buffer, but | |
155 prefix arg means replace the region with it. | |
156 | |
157 `c-macro-preprocessor' specifies the preprocessor to use. | |
64699
629afbe74e61
Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents:
64085
diff
changeset
|
158 Tf the user option `c-macro-prompt-flag' is non-nil |
629afbe74e61
Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents:
64085
diff
changeset
|
159 prompt for arguments to the preprocessor \(e.g. `-DDEBUG -I ./include'), |
629afbe74e61
Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents:
64085
diff
changeset
|
160 otherwise use `c-macro-cppflags'. |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
161 |
6979 | 162 Noninteractive args are START, END, SUBST. |
6981 | 163 For use inside Lisp programs, see also `c-macro-expansion'." |
315 | 164 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
165 (interactive "r\nP") |
6979 | 166 (let ((inbuf (current-buffer)) |
167 (displaybuf (if subst | |
168 (get-buffer c-macro-buffer-name) | |
169 (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
|
170 (expansion "")) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
171 ;; Build the command string. |
6981 | 172 (if c-macro-prompt-flag |
6979 | 173 (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
|
174 (read-string "Preprocessor arguments: " |
6979 | 175 c-macro-cppflags))) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
176 ;; 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
|
177 (if (and subst |
5817
6229dd3050be
(c-macro-expand): Check inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5816
diff
changeset
|
178 (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
|
179 (not (eq inbuf displaybuf))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
180 (progn |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
181 (message |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
182 "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
|
183 (sit-for 2) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
184 (setq subst nil) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
185 (or displaybuf |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
186 (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
|
187 ;; Expand the macro and output it. |
6979 | 188 (setq expansion (c-macro-expansion start end |
189 (concat c-macro-preprocessor " " | |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
190 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
|
191 (if subst |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
192 (let ((exchange (= (point) start))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
193 (delete-region start end) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
194 (insert expansion) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
195 (if exchange |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
196 (exchange-point-and-mark))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
197 (set-buffer displaybuf) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
198 (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
|
199 (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
|
200 (erase-buffer) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
201 (insert expansion) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
202 (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
|
203 (if (string= "" expansion) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
204 (message "Null expansion") |
6979 | 205 (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
|
206 (setq buffer-read-only t) |
6979 | 207 (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
|
208 (bury-buffer displaybuf)))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
209 |
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 ;; 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
|
212 ;; enough to contain the entire buffer, or half the size of the |
6979 | 213 ;; screen, whichever is smaller. Do not select the new |
214 ;; window. | |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
215 ;; |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
216 ;; 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
|
217 ;; 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
|
218 ;; 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
|
219 ;; 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
|
220 ;; 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
|
221 ;; buffer, it is never shrunk, but possibly expanded. Finally, if the |
6981 | 222 ;; 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
|
223 ;; changed. |
6979 | 224 (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
|
225 (goto-char (point-min)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
226 (c-mode) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
227 (let ((oldwinheight (window-height)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
228 (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
|
229 (get-buffer-window (current-buffer))) |
26318
94efc4f944a4
progmodes/cmacexp.el (c-macro-preprocessor): Find the Solaris cpp.
Sam Steingold <sds@gnu.org>
parents:
26039
diff
changeset
|
230 (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
|
231 (or alreadythere |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
232 (progn |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
233 (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
|
234 (setq popped (/= oldwinheight (window-height))))) |
6981 | 235 (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
|
236 (or alreadythere popped)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
237 ;; 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
|
238 (let ((oldwin (selected-window)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
239 (minheight 0) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
240 (maxheight 0)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
241 (save-excursion |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
242 (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
|
243 (setq minheight (if alreadythere |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
244 (window-height) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
245 window-min-height)) |
15268
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
246 (setq maxheight (/ (frame-height) 2)) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
247 (enlarge-window (- (min maxheight |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
248 (max minheight |
6979 | 249 (+ 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
|
250 (window-height))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
251 (goto-char (point-min)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
252 (select-window oldwin)))))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
253 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
254 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
255 (defun c-macro-expansion (start end cppcommand &optional display) |
6981 | 256 "Run a preprocessor on region and return the output as a string. |
6979 | 257 Expand the region between START and END in the current buffer using |
258 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
|
259 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
|
260 Optional arg DISPLAY non-nil means show messages in the echo area." |
315 | 261 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
262 ;; 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
|
263 ;; 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
|
264 ;; 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
|
265 ;; 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
|
266 ;; 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
|
267 ;; 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
|
268 ;; #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
|
269 ;; 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
|
270 ;; 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
|
271 ;; where START was, so return the substring from point to end of |
26318
94efc4f944a4
progmodes/cmacexp.el (c-macro-preprocessor): Find the Solaris cpp.
Sam Steingold <sds@gnu.org>
parents:
26039
diff
changeset
|
272 ;; buffer. |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
273 (let ((inbuf (current-buffer)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
274 (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
|
275 (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
|
276 (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
|
277 buffer-file-name)) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
278 (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
|
279 (buffer-name))) |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
280 (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
|
281 c-macro-preprocessor |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
282 (if (string= "" c-macro-cppflags) "" " ") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
283 c-macro-cppflags)) |
15268
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
284 (uniquestring "??? !!! ??? start of c-macro expansion ??? !!! ???") |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
285 (startlinenum 0) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
286 (linenum 0) |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
287 (startstat ()) |
8476 | 288 (startmarker "") |
8679
ccfc2ca24a90
* cmacexp.el (c-macro-prompt-flag): set default to t.
Francesco Potortì <pot@gnu.org>
parents:
8537
diff
changeset
|
289 (exit-status 0) |
26039
fb6b9c37cdc4
Use make-temp-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25487
diff
changeset
|
290 (tempname (make-temp-file |
22101 | 291 (expand-file-name "cmacexp" |
25487
c2deb54d4d33
(c-macro-expansion): Use small-temporary-file-directory when non-nil.
Eli Zaretskii <eliz@gnu.org>
parents:
22101
diff
changeset
|
292 (or small-temporary-file-directory |
c2deb54d4d33
(c-macro-expansion): Use small-temporary-file-directory when non-nil.
Eli Zaretskii <eliz@gnu.org>
parents:
22101
diff
changeset
|
293 temporary-file-directory))))) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
294 (unwind-protect |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
295 (save-excursion |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
296 (save-restriction |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
297 (widen) |
15268
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
298 (let ((in-syntax-table (syntax-table))) |
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
299 (set-buffer outbuf) |
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
300 (setq buffer-read-only nil) |
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
301 (erase-buffer) |
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
302 (set-syntax-table in-syntax-table)) |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
303 (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
|
304 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
305 ;; We have copied inbuf to outbuf. Point is at end of |
15268
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
306 ;; outbuf. Inset a newline at the end, so cpp can correctly |
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
307 ;; parse a token ending at END. |
18af2c80d4a1
(c-macro-expansion): Delete ??! trigraph in uniquestring.
Karl Heuer <kwzh@gnu.org>
parents:
15267
diff
changeset
|
308 (insert "\n") |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
309 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
310 ;; 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
|
311 (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
|
312 (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
|
313 (if (bolp) 1 0))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
314 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
315 ;; 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
|
316 ;; #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
|
317 ;; 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
|
318 ;(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
|
319 (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
|
320 (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
|
321 (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
|
322 nil nil startstat)) |
6981 | 323 '(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
|
324 ;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
|
325 (progn |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
326 (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
|
327 (setq linenum (+ startlinenum |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
328 (count-lines start (point)))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
329 (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
|
330 (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
|
331 |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
332 ;; 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
|
333 ;; 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
|
334 ;; quote. |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
335 (let* ((startinstring (nth 3 startstat)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
336 (startincomment (nth 4 startstat)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
337 (startafterquote (nth 5 startstat)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
338 (startinbcomment (nth 7 startstat))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
339 (insert (if startafterquote " " "") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
340 (cond (startinstring |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
341 (char-to-string startinstring)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
342 (startincomment "*/") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
343 ("")) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
344 (setq startmarker |
10931
933a04abe0ac
* cmacexp.el (c-macro-expansion): put the unique string before the
Francesco Potortì <pot@gnu.org>
parents:
8705
diff
changeset
|
345 (concat "\n" uniquestring |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
346 (cond (startinstring |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
347 (char-to-string startinstring)) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
348 (startincomment "/*") |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
349 (startinbcomment "//")) |
10931
933a04abe0ac
* cmacexp.el (c-macro-expansion): put the unique string before the
Francesco Potortì <pot@gnu.org>
parents:
8705
diff
changeset
|
350 (if startafterquote "\\"))) |
933a04abe0ac
* cmacexp.el (c-macro-expansion): put the unique string before the
Francesco Potortì <pot@gnu.org>
parents:
8705
diff
changeset
|
351 (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
|
352 |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
353 ;; Call the preprocessor. |
65584
6dbba0bd58df
Message format fixes, commit no. 3
Deepak Goel <deego@gnufans.org>
parents:
65227
diff
changeset
|
354 (if display (message "%s" mymsg)) |
8476 | 355 (setq exit-status |
14408
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
356 (call-process-region 1 (point-max) |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
357 shell-file-name |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
358 t (list t tempname) nil "-c" |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
359 cppcommand)) |
65584
6dbba0bd58df
Message format fixes, commit no. 3
Deepak Goel <deego@gnufans.org>
parents:
65227
diff
changeset
|
360 (if display (message "%s" (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
|
361 (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
|
362 ;; 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
|
363 (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
|
364 ;; 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
|
365 ;; 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
|
366 (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
|
367 (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
|
368 (delete-region 1 (point))) |
7008
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
369 (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
|
370 (regexp-quote filename) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
371 "\"") nil t) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
372 (beginning-of-line) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
373 (let ((beg (point))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
374 (forward-line 1) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
375 (delete-region beg (point)))) |
fd080d04dfe2
(c-macro-expansion): changed the algorithm to allow
Richard M. Stallman <rms@gnu.org>
parents:
6981
diff
changeset
|
376 |
8476 | 377 ;; If CPP got errors, show them at the beginning. |
14408
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
378 ;; MS-DOS shells don't return the exit code of their children. |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
379 ;; Look at the size of the error message file instead, but |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
380 ;; don't punish those MS-DOS users who have a shell that does |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
381 ;; return an error code. |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
382 (or (and (or (not (boundp 'msdos-shells)) |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
383 (not (member (file-name-nondirectory shell-file-name) |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
384 msdos-shells))) |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
385 (eq exit-status 0)) |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
386 (zerop (nth 7 (file-attributes (expand-file-name tempname)))) |
8476 | 387 (progn |
388 (goto-char (point-min)) | |
14408
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
389 ;; Put the messages inside a comment, so they won't get in |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
390 ;; the way of font-lock, highlighting etc. |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
391 (insert |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
392 (format "/* Preprocessor terminated with status %s\n\n Messages from `%s\':\n\n" |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
393 exit-status cppcommand)) |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
394 (goto-char (+ (point) |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
395 (nth 1 (insert-file-contents tempname)))) |
9defc34879ad
(c-macro-preprocessor): Define a preprocessor name
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
396 (insert "\n\n*/\n"))) |
8476 | 397 (delete-file tempname) |
398 | |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
399 ;; 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
|
400 ;; 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
|
401 (buffer-substring 1 (max 1 (- (point-max) 1)))) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
612
diff
changeset
|
402 |
5816
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
403 ;; Cleanup. |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
404 (kill-buffer outbuf)))) |
c381f562cffc
Properly check in the total rewrite installed months ago.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
405 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79717
diff
changeset
|
406 ;; arch-tag: 4f20253c-71ef-4e6d-a774-19087060910e |
6979 | 407 ;;; cmacexp.el ends here |