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