Mercurial > emacs
annotate lisp/progmodes/hideif.el @ 20665:5d82beffb498
Initial revision
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Sun, 18 Jan 1998 03:39:09 +0000 |
parents | 8fc9b5fc7633 |
children | 6f55b3849106 |
rev | line source |
---|---|
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
1 ;;; hide-ifdef-mode.el --- hides selected code within ifdef. |
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
2 |
14169 | 3 ;; Copyright (C) 1988, 1994 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
5 ;; Author: Dan LaLiberte <liberte@a.cs.uiuc.edu> |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
6 ;; Maintainer: FSF |
11455 | 7 ;; Keywords: c, outlines |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
8 |
895
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
10 |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
14 ;; any later version. |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
15 |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
19 ;; GNU General Public License for more details. |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
20 |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
895
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
25 |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
26 ;;; Commentary: |
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
27 |
14169 | 28 ;; To initialize, toggle the hide-ifdef minor mode with |
29 ;; | |
30 ;; M-x hide-ifdef-mode | |
31 ;; | |
32 ;; This will set up key bindings and call hide-ifdef-mode-hook if it | |
33 ;; has a value. To explicitly hide ifdefs using a buffer-local | |
34 ;; define list (default empty), type | |
35 ;; | |
36 ;; M-x hide-ifdefs or C-c @ h | |
37 ;; | |
38 ;; Hide-ifdef suppresses the display of code that the preprocessor wouldn't | |
39 ;; pass through. The support of constant expressions in #if lines is | |
40 ;; limited to identifiers, parens, and the operators: &&, ||, !, and | |
41 ;; "defined". Please extend this. | |
42 ;; | |
43 ;; The hidden code is marked by ellipses (...). Be | |
44 ;; cautious when editing near ellipses, since the hidden text is | |
45 ;; still in the buffer, and you can move the point into it and modify | |
46 ;; text unawares. If you don't want to see the ellipses, set | |
47 ;; selective-display-ellipses to nil. But this can be dangerous. | |
48 ;; You can make your buffer read-only while hide-ifdef-hiding by setting | |
49 ;; hide-ifdef-read-only to a non-nil value. You can toggle this | |
50 ;; variable with hide-ifdef-toggle-read-only (C-c @ C-q). | |
51 ;; | |
52 ;; You can undo the effect of hide-ifdefs by typing | |
53 ;; | |
54 ;; M-x show-ifdefs or C-c @ s | |
55 ;; | |
56 ;; Use M-x hide-ifdef-define (C-c @ d) to define a symbol. | |
57 ;; Use M-x hide-ifdef-undef (C-c @ u) to undefine a symbol. | |
58 ;; | |
59 ;; If you define or undefine a symbol while hide-ifdef-mode is in effect, | |
60 ;; the display will be updated. Only the define list for the current | |
61 ;; buffer will be affected. You can save changes to the local define | |
62 ;; list with hide-ifdef-set-define-alist. This adds entries | |
63 ;; to hide-ifdef-define-alist. | |
64 ;; | |
65 ;; If you have defined a hide-ifdef-mode-hook, you can set | |
66 ;; up a list of symbols that may be used by hide-ifdefs as in the | |
67 ;; following example: | |
68 ;; | |
69 ;; (setq hide-ifdef-mode-hook | |
70 ;; '(lambda () | |
71 ;; (if (not hide-ifdef-define-alist) | |
72 ;; (setq hide-ifdef-define-alist | |
73 ;; '((list1 ONE TWO) | |
74 ;; (list2 TWO THREE) | |
75 ;; ))) | |
76 ;; (hide-ifdef-use-define-alist 'list2) ; use list2 by default | |
77 ;; )) | |
78 ;; | |
79 ;; You can call hide-ifdef-use-define-alist (C-c @ u) at any time to specify | |
80 ;; another list to use. | |
81 ;; | |
82 ;; To cause ifdefs to be hidden as soon as hide-ifdef-mode is called, | |
83 ;; set hide-ifdef-initially to non-nil. | |
84 ;; | |
85 ;; If you set hide-ifdef-lines to t, hide-ifdefs hides all the #ifdef lines. | |
86 ;; In the absence of highlighting, that might be a bad idea. If you set | |
87 ;; hide-ifdef-lines to nil (the default), the surrounding preprocessor | |
88 ;; lines will be displayed. That can be confusing in its own | |
89 ;; right. Other variations on display are possible, but not much | |
90 ;; better. | |
91 ;; | |
92 ;; You can explicitly hide or show individual ifdef blocks irrespective | |
93 ;; of the define list by using hide-ifdef-block and show-ifdef-block. | |
94 ;; | |
95 ;; You can move the point between ifdefs with forward-ifdef, backward-ifdef, | |
96 ;; up-ifdef, down-ifdef, next-ifdef, and previous-ifdef. | |
97 ;; | |
98 ;; If you have minor-mode-alist in your mode line (the default) two labels | |
99 ;; may appear. "Ifdef" will appear when hide-ifdef-mode is active. "Hiding" | |
100 ;; will appear when text may be hidden ("hide-ifdef-hiding" is non-nil). | |
101 ;; | |
102 ;; Written by Brian Marick, at Gould, Computer Systems Division, Urbana IL. | |
103 ;; Extensively modified by Daniel LaLiberte (while at Gould). | |
104 ;; | |
105 ;; You may freely modify and distribute this, but keep a record | |
106 ;; of modifications and send comments to: | |
107 ;; liberte@a.cs.uiuc.edu or ihnp4!uiucdcs!liberte | |
108 ;; I will continue to upgrade hide-ifdef-mode | |
109 ;; with your contributions. | |
31 | 110 |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
111 ;;; Code: |
31 | 112 |
13297
9699410bf8bf
Provide hideif; require cc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
12954
diff
changeset
|
113 (require 'cc-mode) |
9699410bf8bf
Provide hideif; require cc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
12954
diff
changeset
|
114 |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
115 (defvar hide-ifdef-mode-submap nil |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
116 "Keymap used with Hide-Ifdef mode.") |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
117 |
31 | 118 (defvar hide-ifdef-mode-map nil |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
119 "Keymap used with Hide-Ifdef mode.") |
31 | 120 |
11652
1162093d885c
(hide-ifdef-mode-prefix-key): Change to C-c @.
Richard M. Stallman <rms@gnu.org>
parents:
11581
diff
changeset
|
121 (defconst hide-ifdef-mode-prefix-key "\C-c@" |
210 | 122 "Prefix key for all Hide-Ifdef mode commands.") |
31 | 123 |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
124 ;; Set up the submap that goes after the prefix key. |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
125 (if hide-ifdef-mode-submap |
14017 | 126 () ; Don't redefine it. |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
127 (setq hide-ifdef-mode-submap (make-sparse-keymap)) |
11652
1162093d885c
(hide-ifdef-mode-prefix-key): Change to C-c @.
Richard M. Stallman <rms@gnu.org>
parents:
11581
diff
changeset
|
128 (define-key hide-ifdef-mode-submap "d" 'hide-ifdef-define) |
1162093d885c
(hide-ifdef-mode-prefix-key): Change to C-c @.
Richard M. Stallman <rms@gnu.org>
parents:
11581
diff
changeset
|
129 (define-key hide-ifdef-mode-submap "u" 'hide-ifdef-undef) |
1162093d885c
(hide-ifdef-mode-prefix-key): Change to C-c @.
Richard M. Stallman <rms@gnu.org>
parents:
11581
diff
changeset
|
130 (define-key hide-ifdef-mode-submap "D" 'hide-ifdef-set-define-alist) |
1162093d885c
(hide-ifdef-mode-prefix-key): Change to C-c @.
Richard M. Stallman <rms@gnu.org>
parents:
11581
diff
changeset
|
131 (define-key hide-ifdef-mode-submap "U" 'hide-ifdef-use-define-alist) |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
132 |
11652
1162093d885c
(hide-ifdef-mode-prefix-key): Change to C-c @.
Richard M. Stallman <rms@gnu.org>
parents:
11581
diff
changeset
|
133 (define-key hide-ifdef-mode-submap "h" 'hide-ifdefs) |
1162093d885c
(hide-ifdef-mode-prefix-key): Change to C-c @.
Richard M. Stallman <rms@gnu.org>
parents:
11581
diff
changeset
|
134 (define-key hide-ifdef-mode-submap "s" 'show-ifdefs) |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
135 (define-key hide-ifdef-mode-submap "\C-d" 'hide-ifdef-block) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
136 (define-key hide-ifdef-mode-submap "\C-s" 'show-ifdef-block) |
31 | 137 |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
138 (define-key hide-ifdef-mode-submap "\C-q" 'hide-ifdef-toggle-read-only) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
139 (let ((where (where-is-internal 'toggle-read-only '(keymap) t))) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
140 (if where |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
141 (define-key hide-ifdef-mode-submap |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
142 where |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
143 'hide-ifdef-toggle-outside-read-only))) |
31 | 144 ) |
145 | |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
146 ;; Set up the mode's main map, which leads via the prefix key to the submap. |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
147 (if hide-ifdef-mode-map |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
148 () |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
149 (setq hide-ifdef-mode-map (make-sparse-keymap)) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
150 (define-key hide-ifdef-mode-map hide-ifdef-mode-prefix-key |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
151 hide-ifdef-mode-submap)) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
152 |
31 | 153 (defvar hide-ifdef-mode nil |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
154 "Non-nil when hide-ifdef-mode is activated.") |
31 | 155 |
156 (defvar hide-ifdef-hiding nil | |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
157 "Non-nil when text may be hidden.") |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
158 |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
159 ;; Arrange to use the mode's map when the mode is enabled. |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
160 (or (assq 'hide-ifdef-mode minor-mode-map-alist) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
161 (setq minor-mode-map-alist |
8095
8d24be305959
(minor-mode-map-alist): Add missing quote.
Richard M. Stallman <rms@gnu.org>
parents:
7379
diff
changeset
|
162 (cons (cons 'hide-ifdef-mode hide-ifdef-mode-map) |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
163 minor-mode-map-alist))) |
31 | 164 |
165 (or (assq 'hide-ifdef-hiding minor-mode-alist) | |
166 (setq minor-mode-alist | |
167 (cons '(hide-ifdef-hiding " Hiding") | |
168 minor-mode-alist))) | |
169 | |
170 (or (assq 'hide-ifdef-mode minor-mode-alist) | |
171 (setq minor-mode-alist | |
172 (cons '(hide-ifdef-mode " Ifdef") | |
173 minor-mode-alist))) | |
174 | |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
175 ;; fix c-mode syntax table so we can recognize whole symbols. |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
176 (defvar hide-ifdef-syntax-table |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
177 (copy-syntax-table c-mode-syntax-table) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
178 "Syntax table used for tokenizing #if expressions.") |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
179 |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
180 (modify-syntax-entry ?_ "w" hide-ifdef-syntax-table) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
181 (modify-syntax-entry ?& "." hide-ifdef-syntax-table) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
182 (modify-syntax-entry ?\| "." hide-ifdef-syntax-table) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
183 |
998 | 184 ;;;###autoload |
31 | 185 (defun hide-ifdef-mode (arg) |
210 | 186 "Toggle Hide-Ifdef mode. This is a minor mode, albeit a large one. |
15166
83258eb2ede5
(hide-ifdef-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
187 With ARG, turn Hide-Ifdef mode on if arg is positive, off otherwise. |
210 | 188 In Hide-Ifdef mode, code within #ifdef constructs that the C preprocessor |
31 | 189 would eliminate may be hidden from view. Several variables affect |
190 how the hiding is done: | |
191 | |
192 hide-ifdef-env | |
193 An association list of defined and undefined symbols for the | |
210 | 194 current buffer. Initially, the global value of `hide-ifdef-env' |
195 is used. | |
31 | 196 |
197 hide-ifdef-define-alist | |
198 An association list of defined symbol lists. | |
210 | 199 Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env' |
200 and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env' | |
201 from one of the lists in `hide-ifdef-define-alist'. | |
31 | 202 |
203 hide-ifdef-lines | |
204 Set to non-nil to not show #if, #ifdef, #ifndef, #else, and | |
205 #endif lines when hiding. | |
206 | |
207 hide-ifdef-initially | |
210 | 208 Indicates whether `hide-ifdefs' should be called when Hide-Ifdef mode |
31 | 209 is activated. |
210 | |
211 hide-ifdef-read-only | |
212 Set to non-nil if you want to make buffers read only while hiding. | |
210 | 213 After `show-ifdefs', read-only status is restored to previous value. |
31 | 214 |
215 \\{hide-ifdef-mode-map}" | |
216 | |
217 (interactive "P") | |
218 (make-local-variable 'hide-ifdef-mode) | |
219 (setq hide-ifdef-mode | |
220 (if (null arg) | |
221 (not hide-ifdef-mode) | |
222 (> (prefix-numeric-value arg) 0))) | |
223 | |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
224 (force-mode-line-update) |
31 | 225 |
226 (if hide-ifdef-mode | |
227 (progn | |
228 ; inherit global values | |
229 (make-local-variable 'hide-ifdef-env) | |
230 (setq hide-ifdef-env (default-value 'hide-ifdef-env)) | |
231 | |
232 (make-local-variable 'hide-ifdef-hiding) | |
233 (setq hide-ifdef-hiding (default-value 'hide-ifdef-hiding)) | |
234 | |
235 (make-local-variable 'hif-outside-read-only) | |
236 (setq hif-outside-read-only buffer-read-only) | |
237 | |
238 (run-hooks 'hide-ifdef-mode-hook) | |
239 | |
240 (if hide-ifdef-initially | |
241 (hide-ifdefs) | |
242 (show-ifdefs)) | |
13855 | 243 (message "Enter Hide-Ifdef mode") |
31 | 244 ) |
245 ; else end hide-ifdef-mode | |
246 (if hide-ifdef-hiding | |
247 (show-ifdefs)) | |
13855 | 248 (message "Exit Hide-Ifdef mode") |
31 | 249 )) |
250 | |
251 | |
252 ;; from outline.el with docstring fixed. | |
253 (defun hif-outline-flag-region (from to flag) | |
13855 | 254 "Hides or shows lines from FROM to TO, according to FLAG. |
255 If FLAG is \\n (newline character) then text is shown, while if FLAG is \\^M | |
31 | 256 \(control-M) the text is hidden." |
257 (let ((modp (buffer-modified-p))) | |
258 (unwind-protect (progn | |
259 (subst-char-in-region from to | |
260 (if (= flag ?\n) ?\^M ?\n) | |
261 flag t) ) | |
262 (set-buffer-modified-p modp)) | |
263 )) | |
264 | |
265 (defun hif-show-all () | |
266 "Show all of the text in the current buffer." | |
267 (interactive) | |
268 (hif-outline-flag-region (point-min) (point-max) ?\n)) | |
269 | |
13855 | 270 ;; By putting this on after-revert-hook, we arrange that it only |
271 ;; does anything when revert-buffer avoids turning off the mode. | |
272 ;; (That can happen in VC.) | |
273 (defun hif-before-revert-function () | |
274 (and hide-ifdef-mode hide-ifdef-hiding | |
275 (hide-ifdefs t))) | |
276 (add-hook 'after-revert-hook 'hif-before-revert-function) | |
277 | |
31 | 278 (defun hide-ifdef-region (start end) |
279 "START is the start of a #if or #else form. END is the ending part. | |
280 Everything including these lines is made invisible." | |
281 (hif-outline-flag-region start end ?\^M) | |
282 ) | |
283 | |
284 (defun hif-show-ifdef-region (start end) | |
285 "Everything between START and END is made visible." | |
286 (hif-outline-flag-region start end ?\n) | |
287 ) | |
288 | |
289 | |
290 | |
291 ;===%%SF%% evaluation (Start) === | |
292 | |
13855 | 293 ;; It is not useful to set this to anything but `eval'. |
294 ;; In fact, the variable might as well be eliminated. | |
31 | 295 (defvar hide-ifdef-evaluator 'eval |
13855 | 296 "The function to use to evaluate a form. |
297 The evaluator is given a canonical form and returns t if text under | |
31 | 298 that form should be displayed.") |
299 | |
300 (defvar hif-undefined-symbol nil | |
301 "...is by default considered to be false.") | |
302 | |
303 (defvar hide-ifdef-env nil | |
304 "An alist of defined symbols and their values.") | |
305 | |
306 | |
307 (defun hif-set-var (var value) | |
308 "Prepend (var value) pair to hide-ifdef-env." | |
309 (setq hide-ifdef-env (cons (cons var value) hide-ifdef-env))) | |
310 | |
311 | |
312 (defun hif-lookup (var) | |
313 ; (message "hif-lookup %s" var) | |
314 (let ((val (assoc var hide-ifdef-env))) | |
315 (if val | |
316 (cdr val) | |
317 hif-undefined-symbol))) | |
318 | |
319 (defun hif-defined (var) | |
320 (hif-lookup var) | |
321 ; when #if expressions are fully supported, defined result should be 1 | |
322 ; (if (assoc var hide-ifdef-env) | |
323 ; 1 | |
324 ; nil) | |
325 ) | |
326 | |
327 | |
328 ;===%%SF%% evaluation (End) === | |
329 | |
330 | |
331 | |
332 ;===%%SF%% parsing (Start) === | |
333 ;;; The code that understands what ifs and ifdef in files look like. | |
334 | |
335 (defconst hif-cpp-prefix "\\(^\\|\r\\)[ \t]*#[ \t]*") | |
336 (defconst hif-ifndef-regexp (concat hif-cpp-prefix "ifndef")) | |
337 (defconst hif-ifx-regexp (concat hif-cpp-prefix "if\\(n?def\\)?[ \t]+")) | |
338 (defconst hif-else-regexp (concat hif-cpp-prefix "else")) | |
339 (defconst hif-endif-regexp (concat hif-cpp-prefix "endif")) | |
340 (defconst hif-ifx-else-endif-regexp | |
341 (concat hif-ifx-regexp "\\|" hif-else-regexp "\\|" hif-endif-regexp)) | |
342 | |
343 | |
344 (defun hif-infix-to-prefix (token-list) | |
345 "Convert list of tokens in infix into prefix list" | |
346 ; (message "hif-infix-to-prefix: %s" token-list) | |
347 (if (= 1 (length token-list)) | |
348 (` (hif-lookup (quote (, (car token-list))))) | |
349 (hif-parse-if-exp token-list)) | |
350 ) | |
351 | |
352 ; pattern to match initial identifier, !, &&, ||, (, or ). | |
8914 | 353 ; Added ==, + and -: garyo@avs.com 8/9/94 |
19528
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
354 (defconst hif-token-regexp "^\\(&&\\|||\\|[!=]=\\|!\\|[()+-]\\|[<>]=?\\|\\w+\\)") |
31 | 355 (defconst hif-end-of-comment "\\*/") |
356 | |
357 | |
358 (defun hif-tokenize (expr-string) | |
359 "Separate string into a list of tokens" | |
360 (let ((token-list nil) | |
361 (expr-start 0) | |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
362 (expr-length (length expr-string)) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
363 (current-syntax-table (syntax-table))) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
364 (unwind-protect |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
365 (progn |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
366 (set-syntax-table hide-ifdef-syntax-table) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
367 (while (< expr-start expr-length) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
368 ; (message "expr-start = %d" expr-start) (sit-for 1) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
369 (cond |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
370 ((string-match "^[ \t]+" expr-string expr-start) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
371 ;; skip whitespace |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
372 (setq expr-start (match-end 0)) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
373 ;; stick newline in string so ^ matches on the next string-match |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
374 (aset expr-string (1- expr-start) ?\n)) |
31 | 375 |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
376 ((string-match "^/\\*" expr-string expr-start) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
377 (setq expr-start (match-end 0)) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
378 (aset expr-string (1- expr-start) ?\n) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
379 (or |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
380 (string-match hif-end-of-comment |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
381 expr-string expr-start) ; eat comment |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
382 (string-match "$" expr-string expr-start)) ; multi-line comment |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
383 (setq expr-start (match-end 0)) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
384 (aset expr-string (1- expr-start) ?\n)) |
31 | 385 |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
386 ((string-match "^//" expr-string expr-start) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
387 (string-match "$" expr-string expr-start) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
388 (setq expr-start (match-end 0))) |
5560
a9924c6db247
(hif-tokenize): Handle // comments after #if.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
389 |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
390 ((string-match hif-token-regexp expr-string expr-start) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
391 (let ((token (substring expr-string expr-start (match-end 0)))) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
392 (setq expr-start (match-end 0)) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
393 (aset expr-string (1- expr-start) ?\n) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
394 ; (message "token: %s" token) (sit-for 1) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
395 (setq token-list |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
396 (cons |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
397 (cond |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
398 ((string-equal token "||") 'or) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
399 ((string-equal token "&&") 'and) |
8914 | 400 ((string-equal token "==") 'equal) |
401 ((string-equal token "!=") 'hif-notequal) | |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
402 ((string-equal token "!") 'not) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
403 ((string-equal token "defined") 'hif-defined) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
404 ((string-equal token "(") 'lparen) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
405 ((string-equal token ")") 'rparen) |
19528
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
406 ((string-equal token ">") 'hif-greater) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
407 ((string-equal token "<") 'hif-less) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
408 ((string-equal token ">=") 'hif-greater-equal) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
409 ((string-equal token "<=") 'hif-less-equal) |
8914 | 410 ((string-equal token "+") 'hif-plus) |
411 ((string-equal token "-") 'hif-minus) | |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
412 (t (intern token))) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
413 token-list)))) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
414 (t (error "Bad #if expression: %s" expr-string))))) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
415 (set-syntax-table current-syntax-table)) |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
416 (nreverse token-list))) |
31 | 417 |
418 ;;;----------------------------------------------------------------- | |
419 ;;; Translate C preprocessor #if expressions using recursive descent. | |
420 ;;; This parser is limited to the operators &&, ||, !, and "defined". | |
8914 | 421 ;;; Added ==, !=, +, and -. Gary Oberbrunner, garyo@avs.com, 8/9/94 |
31 | 422 |
423 (defun hif-parse-if-exp (token-list) | |
424 "Parse the TOKEN-LIST. Return translated list in prefix form." | |
425 (hif-nexttoken) | |
426 (prog1 | |
427 (hif-expr) | |
428 (if token ; is there still a token? | |
210 | 429 (error "Error: unexpected token: %s" token)))) |
31 | 430 |
431 (defun hif-nexttoken () | |
432 "Pop the next token from token-list into the let variable \"token\"." | |
433 (setq token (car token-list)) | |
434 (setq token-list (cdr token-list)) | |
210 | 435 token) |
31 | 436 |
437 (defun hif-expr () | |
13855 | 438 "Parse an expression as found in #if. |
31 | 439 expr : term | expr '||' term." |
440 (let ((result (hif-term))) | |
441 (while (eq token 'or) | |
442 (hif-nexttoken) | |
443 (setq result (list 'or result (hif-term)))) | |
210 | 444 result)) |
31 | 445 |
446 (defun hif-term () | |
13855 | 447 "Parse a term : eq-expr | term '&&' eq-expr." |
8914 | 448 (let ((result (hif-eq-expr))) |
31 | 449 (while (eq token 'and) |
450 (hif-nexttoken) | |
8914 | 451 (setq result (list 'and result (hif-eq-expr)))) |
210 | 452 result)) |
31 | 453 |
8914 | 454 (defun hif-eq-expr () |
19528
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
455 "Parse an eq-expr : math | eq-expr `=='|`!='|`<'|`>'|`>='|`<=' math." |
8914 | 456 (let ((result (hif-math)) |
457 (eq-token nil)) | |
19528
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
458 (while (memq token '(equal hif-notequal hif-greater hif-less |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
459 hif-greater-equal hif-less-equal)) |
8914 | 460 (setq eq-token token) |
461 (hif-nexttoken) | |
462 (setq result (list eq-token result (hif-math)))) | |
463 result)) | |
464 | |
465 (defun hif-math () | |
13855 | 466 "Parse an expression with + or - and simpler things. |
8914 | 467 math : factor | math '+|-' factor." |
468 (let ((result (hif-factor)) | |
469 (math-op nil)) | |
470 (while (or (eq token 'hif-plus) (eq token 'hif-minus)) | |
471 (setq math-op token) | |
472 (hif-nexttoken) | |
473 (setq result (list math-op result (hif-factor)))) | |
474 result)) | |
475 | |
31 | 476 (defun hif-factor () |
13855 | 477 "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id." |
31 | 478 (cond |
479 ((eq token 'not) | |
480 (hif-nexttoken) | |
481 (list 'not (hif-factor))) | |
482 | |
483 ((eq token 'lparen) | |
484 (hif-nexttoken) | |
485 (let ((result (hif-expr))) | |
486 (if (not (eq token 'rparen)) | |
487 (error "Bad token in parenthesized expression: %s" token) | |
488 (hif-nexttoken) | |
489 result))) | |
490 | |
491 ((eq token 'hif-defined) | |
492 (hif-nexttoken) | |
493 (if (not (eq token 'lparen)) | |
494 (error "Error: expected \"(\" after \"defined\"")) | |
495 (hif-nexttoken) | |
496 (let ((ident token)) | |
497 (if (memq token '(or and not hif-defined lparen rparen)) | |
498 (error "Error: unexpected token: %s" token)) | |
499 (hif-nexttoken) | |
500 (if (not (eq token 'rparen)) | |
501 (error "Error: expected \")\" after identifier")) | |
502 (hif-nexttoken) | |
503 (` (hif-defined (quote (, ident)))) | |
504 )) | |
505 | |
506 (t ; identifier | |
507 (let ((ident token)) | |
508 (if (memq ident '(or and)) | |
509 (error "Error: missing identifier")) | |
510 (hif-nexttoken) | |
511 (` (hif-lookup (quote (, ident)))) | |
512 )) | |
513 )) | |
514 | |
8914 | 515 (defun hif-mathify (val) |
516 "Treat VAL as a number: if it's t or nil, use 1 or 0." | |
517 (cond ((eq val t) | |
518 1) | |
519 ((null val) | |
520 0) | |
521 (t val))) | |
522 | |
523 (defun hif-plus (a b) | |
524 "Like ordinary plus but treat t and nil as 1 and 0." | |
525 (+ (hif-mathify a) (hif-mathify b))) | |
526 (defun hif-minus (a b) | |
527 "Like ordinary minus but treat t and nil as 1 and 0." | |
528 (- (hif-mathify a) (hif-mathify b))) | |
529 (defun hif-notequal (a b) | |
530 "Like (not (equal A B)) but as one symbol." | |
531 (not (equal a b))) | |
19528
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
532 (defun hif-greater (a b) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
533 "Simple comparison." |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
534 (> (hif-mathify a) (hif-mathify b))) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
535 (defun hif-less (a b) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
536 "Simple comparison." |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
537 (< (hif-mathify a) (hif-mathify b))) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
538 (defun hif-greater-equal (a b) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
539 "Simple comparison." |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
540 (>= (hif-mathify a) (hif-mathify b))) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
541 (defun hif-less-equal (a b) |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
542 "Simple comparison." |
8fc9b5fc7633
(hif-greater, hif-less, hif-greater-equal)
Richard M. Stallman <rms@gnu.org>
parents:
16182
diff
changeset
|
543 (<= (hif-mathify a) (hif-mathify b))) |
31 | 544 ;;;----------- end of parser ----------------------- |
545 | |
546 | |
547 (defun hif-canonicalize () | |
13855 | 548 "When at beginning of #ifX, returns a Lisp expression for its condition." |
31 | 549 (save-excursion |
550 (let ((negate (looking-at hif-ifndef-regexp))) | |
551 (re-search-forward hif-ifx-regexp) | |
552 (let* ((expr-string | |
553 (buffer-substring (point) | |
554 (progn (skip-chars-forward "^\n\r") (point)))) | |
555 (expr (hif-infix-to-prefix (hif-tokenize expr-string)))) | |
556 ; (message "hif-canonicalized: %s" expr) | |
557 (if negate | |
558 (list 'not expr) | |
559 expr))))) | |
560 | |
561 | |
562 (defun hif-find-any-ifX () | |
13855 | 563 "Move to next #if..., or #ifndef, at point or after." |
31 | 564 ; (message "find ifX at %d" (point)) |
565 (prog1 | |
566 (re-search-forward hif-ifx-regexp (point-max) t) | |
567 (beginning-of-line))) | |
568 | |
569 | |
570 (defun hif-find-next-relevant () | |
13855 | 571 "Move to next #if..., #else, or #endif, after the current line." |
31 | 572 ; (message "hif-find-next-relevant at %d" (point)) |
573 (end-of-line) | |
574 ; avoid infinite recursion by only going to beginning of line if match found | |
575 (if (re-search-forward hif-ifx-else-endif-regexp (point-max) t) | |
210 | 576 (beginning-of-line))) |
31 | 577 |
578 (defun hif-find-previous-relevant () | |
13855 | 579 "Move to previous #if..., #else, or #endif, before the current line." |
31 | 580 ; (message "hif-find-previous-relevant at %d" (point)) |
581 (beginning-of-line) | |
582 ; avoid infinite recursion by only going to beginning of line if match found | |
583 (if (re-search-backward hif-ifx-else-endif-regexp (point-min) t) | |
210 | 584 (beginning-of-line))) |
31 | 585 |
586 | |
587 (defun hif-looking-at-ifX () ;; Should eventually see #if | |
588 (looking-at hif-ifx-regexp)) | |
589 (defun hif-looking-at-endif () | |
590 (looking-at hif-endif-regexp)) | |
591 (defun hif-looking-at-else () | |
592 (looking-at hif-else-regexp)) | |
593 | |
594 | |
595 | |
596 (defun hif-ifdef-to-endif () | |
597 "If positioned at #ifX or #else form, skip to corresponding #endif." | |
598 ; (message "hif-ifdef-to-endif at %d" (point)) (sit-for 1) | |
599 (hif-find-next-relevant) | |
600 (cond ((hif-looking-at-ifX) | |
601 (hif-ifdef-to-endif) ; find endif of nested if | |
602 (hif-ifdef-to-endif)) ; find outer endif or else | |
603 ((hif-looking-at-else) | |
604 (hif-ifdef-to-endif)) ; find endif following else | |
605 ((hif-looking-at-endif) | |
606 'done) | |
607 (t | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3457
diff
changeset
|
608 (error "Mismatched #ifdef #endif pair")))) |
31 | 609 |
610 | |
611 (defun hif-endif-to-ifdef () | |
612 "If positioned at #endif form, skip backward to corresponding #ifX." | |
613 ; (message "hif-endif-to-ifdef at %d" (point)) | |
614 (let ((start (point))) | |
615 (hif-find-previous-relevant) | |
616 (if (= start (point)) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3457
diff
changeset
|
617 (error "Mismatched #ifdef #endif pair"))) |
31 | 618 (cond ((hif-looking-at-endif) |
619 (hif-endif-to-ifdef) ; find beginning of nested if | |
620 (hif-endif-to-ifdef)) ; find beginning of outer if or else | |
621 ((hif-looking-at-else) | |
622 (hif-endif-to-ifdef)) | |
623 ((hif-looking-at-ifX) | |
624 'done) | |
922 | 625 (t))) ; never gets here |
31 | 626 |
627 | |
628 (defun forward-ifdef (&optional arg) | |
629 "Move point to beginning of line of the next ifdef-endif. | |
210 | 630 With argument, do this that many times." |
31 | 631 (interactive "p") |
632 (or arg (setq arg 1)) | |
633 (if (< arg 0) | |
634 (backward-ifdef (- arg))) | |
635 (while (< 0 arg) | |
636 (setq arg (- arg)) | |
637 (let ((start (point))) | |
638 (if (not (hif-looking-at-ifX)) | |
639 (hif-find-next-relevant)) | |
640 (if (hif-looking-at-ifX) | |
641 (hif-ifdef-to-endif) | |
642 (goto-char start) | |
643 (error "No following #ifdef") | |
644 )))) | |
645 | |
646 | |
647 (defun backward-ifdef (&optional arg) | |
648 "Move point to beginning of the previous ifdef-endif. | |
210 | 649 With argument, do this that many times." |
31 | 650 (interactive "p") |
651 (or arg (setq arg 1)) | |
652 (if (< arg 0) | |
653 (forward-ifdef (- arg))) | |
654 (while (< 0 arg) | |
655 (setq arg (1- arg)) | |
656 (beginning-of-line) | |
657 (let ((start (point))) | |
658 (if (not (hif-looking-at-endif)) | |
659 (hif-find-previous-relevant)) | |
660 (if (hif-looking-at-endif) | |
661 (hif-endif-to-ifdef) | |
662 (goto-char start) | |
210 | 663 (error "No previous #ifdef"))))) |
31 | 664 |
665 | |
666 (defun down-ifdef () | |
667 "Move point to beginning of nested ifdef or else-part." | |
668 (interactive) | |
669 (let ((start (point))) | |
670 (hif-find-next-relevant) | |
671 (if (or (hif-looking-at-ifX) (hif-looking-at-else)) | |
672 () | |
673 (goto-char start) | |
210 | 674 (error "No following #ifdef")))) |
31 | 675 |
676 | |
677 (defun up-ifdef () | |
678 "Move point to beginning of enclosing ifdef or else-part." | |
679 (interactive) | |
680 (beginning-of-line) | |
681 (let ((start (point))) | |
682 (if (not (hif-looking-at-endif)) | |
683 (hif-find-previous-relevant)) | |
684 (if (hif-looking-at-endif) | |
685 (hif-endif-to-ifdef)) | |
686 (if (= start (point)) | |
210 | 687 (error "No previous #ifdef")))) |
31 | 688 |
689 (defun next-ifdef (&optional arg) | |
690 "Move to the beginning of the next #ifX, #else, or #endif. | |
210 | 691 With argument, do this that many times." |
31 | 692 (interactive "p") |
693 (or arg (setq arg 1)) | |
694 (if (< arg 0) | |
695 (previous-ifdef (- arg))) | |
696 (while (< 0 arg) | |
697 (setq arg (1- arg)) | |
698 (hif-find-next-relevant) | |
699 (if (eolp) | |
700 (progn | |
701 (beginning-of-line) | |
210 | 702 (error "No following #ifdefs, #elses, or #endifs"))))) |
31 | 703 |
704 (defun previous-ifdef (&optional arg) | |
705 "Move to the beginning of the previous #ifX, #else, or #endif. | |
210 | 706 With argument, do this that many times." |
31 | 707 (interactive "p") |
708 (or arg (setq arg 1)) | |
709 (if (< arg 0) | |
710 (next-ifdef (- arg))) | |
711 (while (< 0 arg) | |
712 (setq arg (1- arg)) | |
713 (let ((start (point))) | |
714 (hif-find-previous-relevant) | |
715 (if (= start (point)) | |
716 (error "No previous #ifdefs, #elses, or #endifs") | |
717 )))) | |
718 | |
719 | |
720 ;===%%SF%% parsing (End) === | |
721 | |
722 | |
723 ;===%%SF%% hide-ifdef-hiding (Start) === | |
724 | |
725 | |
726 ;;; A range is a structure with four components: | |
727 ;;; ELSE-P True if there was an else clause for the ifdef. | |
728 ;;; START The start of the range. (beginning of line) | |
729 ;;; ELSE The else marker (beginning of line) | |
730 ;;; Only valid if ELSE-P is true. | |
731 ;;; END The end of the range. (beginning of line) | |
732 | |
733 (defun hif-make-range (else-p start end &optional else) | |
734 (list else-p start else end)) | |
735 | |
736 (defun hif-range-else-p (range) (elt range 0)) | |
737 (defun hif-range-start (range) (elt range 1)) | |
738 (defun hif-range-else (range) (elt range 2)) | |
739 (defun hif-range-end (range) (elt range 3)) | |
740 | |
741 | |
742 | |
743 ;;; Find-Range | |
744 ;;; The workhorse, it delimits the #if region. Reasonably simple: | |
745 ;;; Skip until an #else or #endif is found, remembering positions. If | |
746 ;;; an #else was found, skip some more, looking for the true #endif. | |
747 | |
748 (defun hif-find-range () | |
749 "Returns a Range structure describing the current #if region. | |
750 Point is left unchanged." | |
751 ; (message "hif-find-range at %d" (point)) | |
752 (save-excursion | |
753 (beginning-of-line) | |
754 (let ((start (point)) | |
755 (else-p nil) | |
756 (else nil) | |
757 (end nil)) | |
758 ;; Part one. Look for either #endif or #else. | |
759 ;; This loop-and-a-half dedicated to E. Dijkstra. | |
760 (hif-find-next-relevant) | |
761 (while (hif-looking-at-ifX) ; Skip nested ifdef | |
762 (hif-ifdef-to-endif) | |
763 (hif-find-next-relevant)) | |
764 ;; Found either a #else or an #endif. | |
765 (cond ((hif-looking-at-else) | |
766 (setq else-p t) | |
767 (setq else (point))) | |
768 (t | |
769 (setq end (point)) ; (save-excursion (end-of-line) (point)) | |
770 )) | |
771 ;; If found #else, look for #endif. | |
772 (if else-p | |
773 (progn | |
774 (hif-find-next-relevant) | |
775 (while (hif-looking-at-ifX) ; Skip nested ifdef | |
776 (hif-ifdef-to-endif) | |
777 (hif-find-next-relevant)) | |
778 (if (hif-looking-at-else) | |
779 (error "Found two elses in a row? Broken!")) | |
780 (setq end (point)) ; (save-excursion (end-of-line) (point)) | |
781 )) | |
782 (hif-make-range else-p start end else)))) | |
783 | |
784 | |
785 ;;; A bit slimy. | |
786 ;;; NOTE: If there's an #ifdef at the beginning of the file, we can't | |
787 ;;; hide it. There's no previous newline to replace. If we added | |
788 ;;; one, we'd throw off all the counts. Feh. | |
789 | |
790 (defun hif-hide-line (point) | |
210 | 791 "Hide the line containing point. Does nothing if `hide-ifdef-lines' is nil." |
31 | 792 (if hide-ifdef-lines |
793 (save-excursion | |
794 (goto-char point) | |
795 (let ((modp (buffer-modified-p))) | |
796 (unwind-protect | |
797 (progn | |
798 (beginning-of-line) | |
799 (if (not (= (point) 1)) | |
800 (hide-ifdef-region (1- (point)) (point)))) | |
801 (set-buffer-modified-p modp)) | |
802 )) | |
803 )) | |
804 | |
805 | |
806 ;;; Hif-Possibly-Hide | |
807 ;;; There are four cases. The #ifX expression is "taken" if it | |
808 ;;; the hide-ifdef-evaluator returns T. Presumably, this means the code | |
809 ;;; inside the #ifdef would be included when the program was | |
810 ;;; compiled. | |
811 ;;; | |
812 ;;; Case 1: #ifX taken, and there's an #else. | |
813 ;;; The #else part must be hidden. The #if (then) part must be | |
814 ;;; processed for nested #ifX's. | |
815 ;;; Case 2: #ifX taken, and there's no #else. | |
816 ;;; The #if part must be processed for nested #ifX's. | |
817 ;;; Case 3: #ifX not taken, and there's an #else. | |
818 ;;; The #if part must be hidden. The #else part must be processed | |
819 ;;; for nested #ifs. | |
820 ;;; Case 4: #ifX not taken, and there's no #else. | |
821 ;;; The #ifX part must be hidden. | |
822 ;;; | |
823 ;;; Further processing is done by narrowing to the relevant region | |
824 ;;; and just recursively calling hide-ifdef-guts. | |
825 ;;; | |
826 ;;; When hif-possibly-hide returns, point is at the end of the | |
827 ;;; possibly-hidden range. | |
828 | |
829 (defun hif-recurse-on (start end) | |
210 | 830 "Call `hide-ifdef-guts' after narrowing to end of START line and END line." |
31 | 831 (save-excursion |
832 (save-restriction | |
833 (goto-char start) | |
834 (end-of-line) | |
835 (narrow-to-region (point) end) | |
836 (hide-ifdef-guts)))) | |
837 | |
838 (defun hif-possibly-hide () | |
13855 | 839 "Called at #ifX expression, this hides those parts that should be hidden. |
840 It uses the judgement of `hide-ifdef-evaluator'." | |
31 | 841 ; (message "hif-possibly-hide") (sit-for 1) |
842 (let ((test (hif-canonicalize)) | |
843 (range (hif-find-range))) | |
844 ; (message "test = %s" test) (sit-for 1) | |
845 | |
846 (hif-hide-line (hif-range-end range)) | |
847 (if (funcall hide-ifdef-evaluator test) | |
848 (cond ((hif-range-else-p range) ; case 1 | |
849 (hif-hide-line (hif-range-else range)) | |
850 (hide-ifdef-region (hif-range-else range) | |
851 (1- (hif-range-end range))) | |
852 (hif-recurse-on (hif-range-start range) | |
853 (hif-range-else range))) | |
854 (t ; case 2 | |
855 (hif-recurse-on (hif-range-start range) | |
856 (hif-range-end range)))) | |
857 (cond ((hif-range-else-p range) ; case 3 | |
858 (hif-hide-line (hif-range-else range)) | |
859 (hide-ifdef-region (hif-range-start range) | |
860 (1- (hif-range-else range))) | |
861 (hif-recurse-on (hif-range-else range) | |
862 (hif-range-end range))) | |
863 (t ; case 4 | |
864 (hide-ifdef-region (point) | |
865 (1- (hif-range-end range)))) | |
866 )) | |
867 (hif-hide-line (hif-range-start range)) ; Always hide start. | |
868 (goto-char (hif-range-end range)) | |
869 (end-of-line) | |
870 )) | |
871 | |
872 | |
873 | |
874 (defun hide-ifdef-guts () | |
13855 | 875 "Does most of the work of `hide-ifdefs'. |
876 It does not do the work that's pointless to redo on a recursive entry." | |
31 | 877 ; (message "hide-ifdef-guts") |
878 (save-excursion | |
879 (goto-char (point-min)) | |
880 (while (hif-find-any-ifX) | |
881 (hif-possibly-hide)))) | |
882 | |
883 ;===%%SF%% hide-ifdef-hiding (End) === | |
884 | |
885 | |
886 ;===%%SF%% exports (Start) === | |
887 | |
998 | 888 ;;;###autoload |
31 | 889 (defvar hide-ifdef-initially nil |
13855 | 890 "*Non-nil means call `hide-ifdefs' when Hide-Ifdef mode is first activated.") |
31 | 891 |
998 | 892 ;;;###autoload |
31 | 893 (defvar hide-ifdef-read-only nil |
894 "*Set to non-nil if you want buffer to be read-only while hiding text.") | |
895 | |
896 (defvar hif-outside-read-only nil | |
210 | 897 "Internal variable. Saves the value of `buffer-read-only' while hiding.") |
31 | 898 |
998 | 899 ;;;###autoload |
31 | 900 (defvar hide-ifdef-lines nil |
13855 | 901 "*Non-nil means hide the #ifX, #else, and #endif lines.") |
31 | 902 |
903 (defun hide-ifdef-toggle-read-only () | |
904 "Toggle hide-ifdef-read-only." | |
905 (interactive) | |
906 (setq hide-ifdef-read-only (not hide-ifdef-read-only)) | |
907 (message "Hide-Read-Only %s" | |
908 (if hide-ifdef-read-only "ON" "OFF")) | |
909 (if hide-ifdef-hiding | |
910 (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only))) | |
11581
e21661a78292
(hide-ifdef-toggle-read-only): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
11455
diff
changeset
|
911 (force-mode-line-update)) |
31 | 912 |
913 (defun hide-ifdef-toggle-outside-read-only () | |
13855 | 914 "Replacement for `toggle-read-only' within Hide-Ifdef mode." |
31 | 915 (interactive) |
916 (setq hif-outside-read-only (not hif-outside-read-only)) | |
917 (message "Read only %s" | |
918 (if hif-outside-read-only "ON" "OFF")) | |
919 (setq buffer-read-only | |
920 (or (and hide-ifdef-hiding hide-ifdef-read-only) | |
921 hif-outside-read-only) | |
922 ) | |
11581
e21661a78292
(hide-ifdef-toggle-read-only): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
11455
diff
changeset
|
923 (force-mode-line-update)) |
31 | 924 |
925 | |
926 (defun hide-ifdef-define (var) | |
927 "Define a VAR so that #ifdef VAR would be included." | |
928 (interactive "SDefine what? ") | |
8914 | 929 (hif-set-var var 1) |
31 | 930 (if hide-ifdef-hiding (hide-ifdefs))) |
931 | |
932 (defun hide-ifdef-undef (var) | |
933 "Undefine a VAR so that #ifdef VAR would not be included." | |
934 (interactive "SUndefine what? ") | |
935 (hif-set-var var nil) | |
936 (if hide-ifdef-hiding (hide-ifdefs))) | |
937 | |
938 | |
13855 | 939 (defun hide-ifdefs (&optional nomsg) |
1476 | 940 "Hide the contents of some #ifdefs. |
941 Assume that defined symbols have been added to `hide-ifdef-env'. | |
942 The text hidden is the text that would not be included by the C | |
943 preprocessor if it were given the file with those symbols defined. | |
31 | 944 |
8375 | 945 Turn off hiding by calling `show-ifdefs'." |
31 | 946 |
947 (interactive) | |
948 (message "Hiding...") | |
13856
8046a1616264
(hide-ifdefs): Set hif-outside-read-only here.
Richard M. Stallman <rms@gnu.org>
parents:
13855
diff
changeset
|
949 (setq hif-outside-read-only buffer-read-only) |
31 | 950 (if (not hide-ifdef-mode) |
951 (hide-ifdef-mode 1)) ; turn on hide-ifdef-mode | |
952 (if hide-ifdef-hiding | |
953 (show-ifdefs)) ; Otherwise, deep confusion. | |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
954 (let ((inhibit-read-only t)) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
955 (setq selective-display t) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
956 (setq hide-ifdef-hiding t) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
957 (hide-ifdef-guts)) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
958 (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only)) |
13855 | 959 (or nomsg |
960 (message "Hiding done"))) | |
31 | 961 |
962 | |
963 (defun show-ifdefs () | |
13855 | 964 "Cancel the effects of `hide-ifdef': show the contents of all #ifdefs." |
31 | 965 (interactive) |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
966 (setq buffer-read-only hif-outside-read-only) |
31 | 967 (setq selective-display nil) ; defaults |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
968 (let ((inhibit-read-only t)) |
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
969 (hif-show-all)) |
210 | 970 (setq hide-ifdef-hiding nil)) |
31 | 971 |
972 | |
973 (defun hif-find-ifdef-block () | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3457
diff
changeset
|
974 "Utility for hide and show `ifdef-block'. |
1476 | 975 Set top and bottom of ifdef block." |
31 | 976 (let (max-bottom) |
977 (save-excursion | |
978 (beginning-of-line) | |
979 (if (not (or (hif-looking-at-else) (hif-looking-at-ifX))) | |
980 (up-ifdef)) | |
981 (setq top (point)) | |
982 (hif-ifdef-to-endif) | |
210 | 983 (setq max-bottom (1- (point)))) |
31 | 984 (save-excursion |
985 (beginning-of-line) | |
986 (if (not (hif-looking-at-endif)) | |
987 (hif-find-next-relevant)) | |
988 (while (hif-looking-at-ifX) | |
989 (hif-ifdef-to-endif) | |
210 | 990 (hif-find-next-relevant)) |
991 (setq bottom (min max-bottom (1- (point)))))) | |
31 | 992 ) |
993 | |
994 | |
995 (defun hide-ifdef-block () | |
996 "Hide the ifdef block (true or false part) enclosing or before the cursor." | |
997 (interactive) | |
998 (if (not hide-ifdef-mode) | |
999 (hide-ifdef-mode 1)) | |
1000 (setq selective-display t) | |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
1001 (let (top bottom (inhibit-read-only t)) |
31 | 1002 (hif-find-ifdef-block) ; set top and bottom - dynamic scoping |
1003 (hide-ifdef-region top bottom) | |
1004 (if hide-ifdef-lines | |
1005 (progn | |
1006 (hif-hide-line top) | |
1007 (hif-hide-line (1+ bottom)))) | |
210 | 1008 (setq hide-ifdef-hiding t)) |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
1009 (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only))) |
31 | 1010 |
1011 | |
1012 (defun show-ifdef-block () | |
1013 "Show the ifdef block (true or false part) enclosing or before the cursor." | |
1014 (interactive) | |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
1015 (let ((inhibit-read-only t)) |
31 | 1016 (if hide-ifdef-lines |
1017 (save-excursion | |
1018 (beginning-of-line) | |
1019 (hif-show-ifdef-region (1- (point)) (progn (end-of-line) (point)))) | |
1020 | |
1021 (let (top bottom) | |
1022 (hif-find-ifdef-block) | |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
1023 (hif-show-ifdef-region (1- top) bottom))))) |
31 | 1024 |
1025 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3457
diff
changeset
|
1026 ;;; definition alist support |
31 | 1027 |
1028 (defvar hide-ifdef-define-alist nil | |
1029 "A global assoc list of pre-defined symbol lists") | |
1030 | |
1031 (defun hif-compress-define-list (env) | |
1032 "Compress the define list ENV into a list of defined symbols only." | |
1033 (let ((defs (mapcar '(lambda (arg) | |
1034 (if (hif-lookup (car arg)) (car arg))) | |
1035 env)) | |
1036 (new-defs nil)) | |
1037 (while defs | |
1038 (if (car defs) | |
1039 (setq new-defs (cons (car defs) new-defs))) | |
1040 (setq defs (cdr defs))) | |
210 | 1041 new-defs)) |
31 | 1042 |
1043 (defun hide-ifdef-set-define-alist (name) | |
1476 | 1044 "Set the association for NAME to `hide-ifdef-env'." |
31 | 1045 (interactive "SSet define list: ") |
1046 (setq hide-ifdef-define-alist | |
1047 (cons (cons name (hif-compress-define-list hide-ifdef-env)) | |
210 | 1048 hide-ifdef-define-alist))) |
31 | 1049 |
1050 (defun hide-ifdef-use-define-alist (name) | |
1476 | 1051 "Set `hide-ifdef-env' to the define list specified by NAME." |
31 | 1052 (interactive "SUse define list: ") |
1053 (let ((define-list (assoc name hide-ifdef-define-alist))) | |
1054 (if define-list | |
1055 (setq hide-ifdef-env | |
1056 (mapcar '(lambda (arg) (cons arg t)) | |
1057 (cdr define-list))) | |
1058 (error "No define list for %s" name)) | |
210 | 1059 (if hide-ifdef-hiding (hide-ifdefs)))) |
31 | 1060 |
13297
9699410bf8bf
Provide hideif; require cc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
12954
diff
changeset
|
1061 (provide 'hideif) |
9699410bf8bf
Provide hideif; require cc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
12954
diff
changeset
|
1062 |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
210
diff
changeset
|
1063 ;;; hideif.el ends here |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
210
diff
changeset
|
1064 |