Mercurial > emacs
annotate lisp/progmodes/hideif.el @ 100111:70331b8d068a
(c-tab-always-indent, c-insert-tab-function): Doc fix. (Bug#1368)
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 02 Dec 2008 03:32:05 +0000 |
parents | 52b7a8c22af5 |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
30805
diff
changeset
|
1 ;;; hideif.el --- hides selected code within ifdef |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
2 |
87873
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
3 ;; Copyright (C) 1988, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
4 ;; 2008 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
5 |
30805
3cfd3dc474b8
Change authors' mail address.
Gerd Moellmann <gerd@gnu.org>
parents:
30327
diff
changeset
|
6 ;; Author: Daniel LaLiberte <liberte@holonexus.org> |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
7 ;; Maintainer: FSF |
11455 | 8 ;; Keywords: c, outlines |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
9 |
895
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
11 |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94206
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
895
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94206
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94206
diff
changeset
|
15 ;; (at your option) any later version. |
895
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
16 |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
17 ;; 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
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
20 ;; GNU General Public License for more details. |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
21 |
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94206
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
895
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
24 |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
25 ;;; Commentary: |
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
26 |
14169 | 27 ;; To initialize, toggle the hide-ifdef minor mode with |
28 ;; | |
29 ;; M-x hide-ifdef-mode | |
30 ;; | |
31 ;; This will set up key bindings and call hide-ifdef-mode-hook if it | |
32 ;; has a value. To explicitly hide ifdefs using a buffer-local | |
33 ;; define list (default empty), type | |
34 ;; | |
35 ;; M-x hide-ifdefs or C-c @ h | |
36 ;; | |
37 ;; Hide-ifdef suppresses the display of code that the preprocessor wouldn't | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
38 ;; pass through. The support of constant expressions in #if lines is |
14169 | 39 ;; limited to identifiers, parens, and the operators: &&, ||, !, and |
40 ;; "defined". Please extend this. | |
41 ;; | |
42 ;; The hidden code is marked by ellipses (...). Be | |
43 ;; cautious when editing near ellipses, since the hidden text is | |
44 ;; still in the buffer, and you can move the point into it and modify | |
41619 | 45 ;; text unawares. |
14169 | 46 ;; You can make your buffer read-only while hide-ifdef-hiding by setting |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
47 ;; hide-ifdef-read-only to a non-nil value. You can toggle this |
14169 | 48 ;; variable with hide-ifdef-toggle-read-only (C-c @ C-q). |
49 ;; | |
50 ;; You can undo the effect of hide-ifdefs by typing | |
51 ;; | |
52 ;; M-x show-ifdefs or C-c @ s | |
53 ;; | |
54 ;; Use M-x hide-ifdef-define (C-c @ d) to define a symbol. | |
55 ;; Use M-x hide-ifdef-undef (C-c @ u) to undefine a symbol. | |
56 ;; | |
57 ;; If you define or undefine a symbol while hide-ifdef-mode is in effect, | |
58 ;; the display will be updated. Only the define list for the current | |
59 ;; buffer will be affected. You can save changes to the local define | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
60 ;; list with hide-ifdef-set-define-alist. This adds entries |
14169 | 61 ;; to hide-ifdef-define-alist. |
62 ;; | |
63 ;; If you have defined a hide-ifdef-mode-hook, you can set | |
64 ;; up a list of symbols that may be used by hide-ifdefs as in the | |
65 ;; following example: | |
66 ;; | |
41619 | 67 ;; (add-hook 'hide-ifdef-mode-hook |
29588
0cf06902af64
(hif-compress-define-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26519
diff
changeset
|
68 ;; (lambda () |
41619 | 69 ;; (unless hide-ifdef-define-alist |
70 ;; (setq hide-ifdef-define-alist | |
71 ;; '((list1 ONE TWO) | |
72 ;; (list2 TWO THREE)))) | |
73 ;; (hide-ifdef-use-define-alist 'list2))) ; use list2 by default | |
14169 | 74 ;; |
30327
09b01c9914a6
Correct author's email address. Fix typo in comment.
Gerd Moellmann <gerd@gnu.org>
parents:
29588
diff
changeset
|
75 ;; You can call hide-ifdef-use-define-alist (C-c @ U) at any time to specify |
14169 | 76 ;; another list to use. |
77 ;; | |
78 ;; To cause ifdefs to be hidden as soon as hide-ifdef-mode is called, | |
79 ;; set hide-ifdef-initially to non-nil. | |
80 ;; | |
81 ;; If you set hide-ifdef-lines to t, hide-ifdefs hides all the #ifdef lines. | |
82 ;; In the absence of highlighting, that might be a bad idea. If you set | |
83 ;; hide-ifdef-lines to nil (the default), the surrounding preprocessor | |
84 ;; lines will be displayed. That can be confusing in its own | |
85 ;; right. Other variations on display are possible, but not much | |
86 ;; better. | |
87 ;; | |
88 ;; You can explicitly hide or show individual ifdef blocks irrespective | |
89 ;; of the define list by using hide-ifdef-block and show-ifdef-block. | |
90 ;; | |
91 ;; You can move the point between ifdefs with forward-ifdef, backward-ifdef, | |
92 ;; up-ifdef, down-ifdef, next-ifdef, and previous-ifdef. | |
93 ;; | |
94 ;; If you have minor-mode-alist in your mode line (the default) two labels | |
95 ;; may appear. "Ifdef" will appear when hide-ifdef-mode is active. "Hiding" | |
96 ;; will appear when text may be hidden ("hide-ifdef-hiding" is non-nil). | |
97 ;; | |
98 ;; Written by Brian Marick, at Gould, Computer Systems Division, Urbana IL. | |
99 ;; Extensively modified by Daniel LaLiberte (while at Gould). | |
31 | 100 |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
101 ;;; Code: |
31 | 102 |
13297
9699410bf8bf
Provide hideif; require cc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
12954
diff
changeset
|
103 (require 'cc-mode) |
9699410bf8bf
Provide hideif; require cc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
12954
diff
changeset
|
104 |
20781 | 105 (defgroup hide-ifdef nil |
106 "Hide selected code within `ifdef'." | |
107 :group 'c) | |
108 | |
87873
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
109 (defcustom hide-ifdef-initially nil |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
110 "Non-nil means call `hide-ifdefs' when Hide-Ifdef mode is first activated." |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
111 :type 'boolean |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
112 :group 'hide-ifdef) |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
113 |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
114 (defcustom hide-ifdef-read-only nil |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
115 "Set to non-nil if you want buffer to be read-only while hiding text." |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
116 :type 'boolean |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
117 :group 'hide-ifdef) |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
118 |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
119 (defcustom hide-ifdef-lines nil |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
120 "Non-nil means hide the #ifX, #else, and #endif lines." |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
121 :type 'boolean |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
122 :group 'hide-ifdef) |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
123 |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
124 (defcustom hide-ifdef-shadow nil |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
125 "Non-nil means shadow text instead of hiding it." |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
126 :type 'boolean |
87916
0ed1c2a3adc0
(hide-ifdef-shadow): Add version number for defcustom.
Martin Rudalics <rudalics@gmx.at>
parents:
87895
diff
changeset
|
127 :group 'hide-ifdef |
0ed1c2a3adc0
(hide-ifdef-shadow): Add version number for defcustom.
Martin Rudalics <rudalics@gmx.at>
parents:
87895
diff
changeset
|
128 :version "23.1") |
87873
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
129 |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
130 (defface hide-ifdef-shadow '((t (:inherit shadow))) |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
131 "Face for shadowing ifdef blocks." |
87916
0ed1c2a3adc0
(hide-ifdef-shadow): Add version number for defcustom.
Martin Rudalics <rudalics@gmx.at>
parents:
87895
diff
changeset
|
132 :group 'hide-ifdef |
0ed1c2a3adc0
(hide-ifdef-shadow): Add version number for defcustom.
Martin Rudalics <rudalics@gmx.at>
parents:
87895
diff
changeset
|
133 :version "23.1") |
87873
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
134 |
adc70c059607
Move defcustoms and defface to start of file.
Glenn Morris <rgm@gnu.org>
parents:
87851
diff
changeset
|
135 |
41619 | 136 (defvar hide-ifdef-mode-submap |
137 ;; Set up the submap that goes after the prefix key. | |
138 (let ((map (make-sparse-keymap))) | |
139 (define-key map "d" 'hide-ifdef-define) | |
140 (define-key map "u" 'hide-ifdef-undef) | |
141 (define-key map "D" 'hide-ifdef-set-define-alist) | |
142 (define-key map "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
|
143 |
41619 | 144 (define-key map "h" 'hide-ifdefs) |
145 (define-key map "s" 'show-ifdefs) | |
146 (define-key map "\C-d" 'hide-ifdef-block) | |
147 (define-key map "\C-s" 'show-ifdef-block) | |
148 | |
149 (define-key map "\C-q" 'hide-ifdef-toggle-read-only) | |
87851
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
150 (define-key map "\C-w" 'hide-ifdef-toggle-shadowing) |
41619 | 151 (substitute-key-definition |
152 'toggle-read-only 'hide-ifdef-toggle-outside-read-only map) | |
153 map) | |
154 "Keymap used by `hide-ifdef-mode' under `hide-ifdef-mode-prefix-key'.") | |
31 | 155 |
11652
1162093d885c
(hide-ifdef-mode-prefix-key): Change to C-c @.
Richard M. Stallman <rms@gnu.org>
parents:
11581
diff
changeset
|
156 (defconst hide-ifdef-mode-prefix-key "\C-c@" |
210 | 157 "Prefix key for all Hide-Ifdef mode commands.") |
31 | 158 |
41619 | 159 (defvar hide-ifdef-mode-map |
160 ;; Set up the mode's main map, which leads via the prefix key to the submap. | |
161 (let ((map (make-sparse-keymap))) | |
162 (define-key map hide-ifdef-mode-prefix-key hide-ifdef-mode-submap) | |
163 map) | |
164 "Keymap used with `hide-ifdef-mode'.") | |
31 | 165 |
79699
1ad384d8d37a
(hide-ifdef-mode-menu): Put hide-ifdef commands
Nick Roberts <nickrob@snap.net.nz>
parents:
78234
diff
changeset
|
166 (easy-menu-define hide-ifdef-mode-menu hide-ifdef-mode-map |
1ad384d8d37a
(hide-ifdef-mode-menu): Put hide-ifdef commands
Nick Roberts <nickrob@snap.net.nz>
parents:
78234
diff
changeset
|
167 "Menu for `hide-ifdef-mode'." |
1ad384d8d37a
(hide-ifdef-mode-menu): Put hide-ifdef commands
Nick Roberts <nickrob@snap.net.nz>
parents:
78234
diff
changeset
|
168 '("Hide-Ifdef" |
94206
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
169 ["Hide some ifdefs" hide-ifdefs |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
170 :help "Hide the contents of some #ifdefs"] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
171 ["Show all ifdefs" show-ifdefs |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
172 :help "Cancel the effects of `hide-ifdef': show the contents of all #ifdefs"] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
173 ["Hide ifdef block" hide-ifdef-block |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
174 :help "Hide the ifdef block (true or false part) enclosing or before the cursor"] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
175 ["Show ifdef block" show-ifdef-block |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
176 :help "Show the ifdef block (true or false part) enclosing or before the cursor"] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
177 ["Define a variable..." hide-ifdef-define |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
178 :help "Define a VAR so that #ifdef VAR would be included"] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
179 ["Undefine a variable..." hide-ifdef-undef |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
180 :help "Undefine a VAR so that #ifdef VAR would not be included"] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
181 ["Define an alist..." hide-ifdef-set-define-alist |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
182 :help "Set the association for NAME to `hide-ifdef-env'"] |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
183 ["Use an alist..." hide-ifdef-use-define-alist |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
184 :help "Set `hide-ifdef-env' to the define list specified by NAME"] |
79699
1ad384d8d37a
(hide-ifdef-mode-menu): Put hide-ifdef commands
Nick Roberts <nickrob@snap.net.nz>
parents:
78234
diff
changeset
|
185 ["Toggle read only" hide-ifdef-toggle-read-only |
94206
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
186 :style toggle :selected hide-ifdef-read-only |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
187 :help "Buffer should be read-only while hiding text"] |
87851
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
188 ["Toggle shadowing" hide-ifdef-toggle-shadowing |
94206
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
189 :style toggle :selected hide-ifdef-shadow |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
190 :help "Text should be shadowed instead of hidden"])) |
79699
1ad384d8d37a
(hide-ifdef-mode-menu): Put hide-ifdef commands
Nick Roberts <nickrob@snap.net.nz>
parents:
78234
diff
changeset
|
191 |
31 | 192 (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
|
193 "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
|
194 |
31 | 195 (or (assq 'hide-ifdef-hiding minor-mode-alist) |
196 (setq minor-mode-alist | |
197 (cons '(hide-ifdef-hiding " Hiding") | |
198 minor-mode-alist))) | |
199 | |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
200 ;; 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
|
201 (defvar hide-ifdef-syntax-table |
41619 | 202 (let ((st (copy-syntax-table c-mode-syntax-table))) |
203 (modify-syntax-entry ?_ "w" st) | |
204 (modify-syntax-entry ?& "." st) | |
205 (modify-syntax-entry ?\| "." st) | |
206 st) | |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
207 "Syntax table used for tokenizing #if expressions.") |
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
208 |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
209 (defvar hide-ifdef-env nil |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
210 "An alist of defined symbols and their values.") |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
211 |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
212 (defvar hif-outside-read-only nil |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
213 "Internal variable. Saves the value of `buffer-read-only' while hiding.") |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
214 |
998 | 215 ;;;###autoload |
41619 | 216 (define-minor-mode hide-ifdef-mode |
210 | 217 "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
|
218 With ARG, turn Hide-Ifdef mode on if arg is positive, off otherwise. |
210 | 219 In Hide-Ifdef mode, code within #ifdef constructs that the C preprocessor |
31 | 220 would eliminate may be hidden from view. Several variables affect |
221 how the hiding is done: | |
222 | |
41619 | 223 `hide-ifdef-env' |
31 | 224 An association list of defined and undefined symbols for the |
210 | 225 current buffer. Initially, the global value of `hide-ifdef-env' |
226 is used. | |
31 | 227 |
41619 | 228 `hide-ifdef-define-alist' |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
229 An association list of defined symbol lists. |
210 | 230 Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env' |
231 and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env' | |
232 from one of the lists in `hide-ifdef-define-alist'. | |
31 | 233 |
41619 | 234 `hide-ifdef-lines' |
31 | 235 Set to non-nil to not show #if, #ifdef, #ifndef, #else, and |
236 #endif lines when hiding. | |
237 | |
41619 | 238 `hide-ifdef-initially' |
210 | 239 Indicates whether `hide-ifdefs' should be called when Hide-Ifdef mode |
31 | 240 is activated. |
241 | |
41619 | 242 `hide-ifdef-read-only' |
31 | 243 Set to non-nil if you want to make buffers read only while hiding. |
210 | 244 After `show-ifdefs', read-only status is restored to previous value. |
31 | 245 |
246 \\{hide-ifdef-mode-map}" | |
61286
e85dd7fe4004
(hide-ifdef-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents:
60213
diff
changeset
|
247 :group 'hide-ifdef :lighter " Ifdef" |
31 | 248 (if hide-ifdef-mode |
249 (progn | |
41619 | 250 ;; inherit global values |
251 (set (make-local-variable 'hide-ifdef-env) | |
252 (default-value 'hide-ifdef-env)) | |
253 (set (make-local-variable 'hide-ifdef-hiding) | |
254 (default-value 'hide-ifdef-hiding)) | |
255 (set (make-local-variable 'hif-outside-read-only) buffer-read-only) | |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
256 (set (make-local-variable 'line-move-ignore-invisible) t) |
41712
c2b7b74ef973
(hide-ifdef-mode): Only modify
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41645
diff
changeset
|
257 (add-hook 'change-major-mode-hook |
c2b7b74ef973
(hide-ifdef-mode): Only modify
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41645
diff
changeset
|
258 (lambda () (hide-ifdef-mode -1)) nil t) |
31 | 259 |
41619 | 260 (add-to-invisibility-spec '(hide-ifdef . t)) |
31 | 261 |
262 (if hide-ifdef-initially | |
263 (hide-ifdefs) | |
41619 | 264 (show-ifdefs))) |
265 ;; else end hide-ifdef-mode | |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
266 (kill-local-variable 'line-move-ignore-invisible) |
41712
c2b7b74ef973
(hide-ifdef-mode): Only modify
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41645
diff
changeset
|
267 (remove-from-invisibility-spec '(hide-ifdef . t)) |
94206
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
268 (when hide-ifdef-hiding |
10db3330138c
* progmodes/asm-mode.el (asm-mode-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94036
diff
changeset
|
269 (show-ifdefs)))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
270 |
31 | 271 |
272 (defun hif-show-all () | |
273 "Show all of the text in the current buffer." | |
274 (interactive) | |
41619 | 275 (hif-show-ifdef-region (point-min) (point-max))) |
31 | 276 |
13855 | 277 ;; By putting this on after-revert-hook, we arrange that it only |
278 ;; does anything when revert-buffer avoids turning off the mode. | |
279 ;; (That can happen in VC.) | |
41619 | 280 (defun hif-after-revert-function () |
13855 | 281 (and hide-ifdef-mode hide-ifdef-hiding |
282 (hide-ifdefs t))) | |
41619 | 283 (add-hook 'after-revert-hook 'hif-after-revert-function) |
13855 | 284 |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
285 (defun hif-end-of-line () |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
286 (end-of-line) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
287 (while (= (logand 1 (skip-chars-backward "\\\\")) 1) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
288 (end-of-line 2))) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
289 |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
290 (defun hide-ifdef-region-internal (start end) |
87851
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
291 (remove-overlays start end 'hide-ifdef t) |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
292 (let ((o (make-overlay start end))) |
87851
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
293 (overlay-put o 'hide-ifdef t) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
294 (if hide-ifdef-shadow |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
295 (overlay-put o 'face 'hide-ifdef-shadow) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
296 (overlay-put o 'invisible 'hide-ifdef)))) |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
297 |
31 | 298 (defun hide-ifdef-region (start end) |
299 "START is the start of a #if or #else form. END is the ending part. | |
300 Everything including these lines is made invisible." | |
41619 | 301 (save-excursion |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
302 (goto-char start) (hif-end-of-line) (setq start (point)) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
303 (goto-char end) (hif-end-of-line) (setq end (point)) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
304 (hide-ifdef-region-internal start end))) |
31 | 305 |
306 (defun hif-show-ifdef-region (start end) | |
307 "Everything between START and END is made visible." | |
87851
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
308 (remove-overlays start end 'hide-ifdef t)) |
31 | 309 |
310 | |
41619 | 311 ;;===%%SF%% evaluation (Start) === |
31 | 312 |
13855 | 313 ;; It is not useful to set this to anything but `eval'. |
314 ;; In fact, the variable might as well be eliminated. | |
31 | 315 (defvar hide-ifdef-evaluator 'eval |
13855 | 316 "The function to use to evaluate a form. |
317 The evaluator is given a canonical form and returns t if text under | |
31 | 318 that form should be displayed.") |
319 | |
320 (defvar hif-undefined-symbol nil | |
321 "...is by default considered to be false.") | |
322 | |
323 | |
324 (defun hif-set-var (var value) | |
325 "Prepend (var value) pair to hide-ifdef-env." | |
326 (setq hide-ifdef-env (cons (cons var value) hide-ifdef-env))) | |
327 | |
328 | |
329 (defun hif-lookup (var) | |
41619 | 330 ;; (message "hif-lookup %s" var) |
31 | 331 (let ((val (assoc var hide-ifdef-env))) |
332 (if val | |
333 (cdr val) | |
334 hif-undefined-symbol))) | |
335 | |
336 (defun hif-defined (var) | |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
337 (if (assoc var hide-ifdef-env) 1 0)) |
31 | 338 |
41619 | 339 ;;===%%SF%% evaluation (End) === |
31 | 340 |
341 | |
342 | |
41619 | 343 ;;===%%SF%% parsing (Start) === |
31 | 344 ;;; The code that understands what ifs and ifdef in files look like. |
345 | |
346 (defconst hif-cpp-prefix "\\(^\\|\r\\)[ \t]*#[ \t]*") | |
347 (defconst hif-ifndef-regexp (concat hif-cpp-prefix "ifndef")) | |
348 (defconst hif-ifx-regexp (concat hif-cpp-prefix "if\\(n?def\\)?[ \t]+")) | |
349 (defconst hif-else-regexp (concat hif-cpp-prefix "else")) | |
350 (defconst hif-endif-regexp (concat hif-cpp-prefix "endif")) | |
351 (defconst hif-ifx-else-endif-regexp | |
352 (concat hif-ifx-regexp "\\|" hif-else-regexp "\\|" hif-endif-regexp)) | |
353 | |
41619 | 354 ;; Used to store the current token and the whole token list during parsing. |
355 ;; Only bound dynamically. | |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
356 (defvar hif-token) |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
357 (defvar hif-token-list) |
31 | 358 |
93681
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
359 (defconst hif-token-alist |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
360 '(("||" . or) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
361 ("&&" . and) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
362 ("|" . hif-logior) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
363 ("&" . hif-logand) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
364 ("==" . equal) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
365 ("!=" . hif-notequal) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
366 ("!" . not) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
367 ("(" . lparen) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
368 (")" . rparen) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
369 (">" . hif-greater) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
370 ("<" . hif-less) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
371 (">=" . hif-greater-equal) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
372 ("<=" . hif-less-equal) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
373 ("+" . hif-plus) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
374 ("-" . hif-minus) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
375 ("?" . hif-conditional) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
376 (":" . hif-colon))) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
377 |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
378 (defconst hif-token-regexp |
93681
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
379 (concat (regexp-opt (mapcar 'car hif-token-alist)) "\\|\\w+")) |
31 | 380 |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
381 (defun hif-tokenize (start end) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
382 "Separate string between START and END into a list of tokens." |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
383 (let ((token-list nil)) |
41619 | 384 (with-syntax-table hide-ifdef-syntax-table |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
385 (save-excursion |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
386 (goto-char start) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
387 (while (progn (forward-comment (point-max)) (< (point) end)) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
388 ;; (message "expr-start = %d" expr-start) (sit-for 1) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
389 (cond |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
390 ((looking-at "\\\\\n") |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
391 (forward-char 2)) |
31 | 392 |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
393 ((looking-at hif-token-regexp) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
394 (let ((token (buffer-substring (point) (match-end 0)))) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
395 (goto-char (match-end 0)) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
396 ;; (message "token: %s" token) (sit-for 1) |
93681
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
397 (push (or (cdr (assoc token hif-token-alist)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
398 (if (string-equal token "defined") 'hif-defined) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
399 (if (string-match "\\`[0-9]*\\'" token) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
400 (string-to-number token)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
401 (intern token)) |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
402 token-list))) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
403 (t (error "Bad #if expression: %s" (buffer-string))))))) |
7379
822429149720
(hide-ifdef-syntax-table): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
7324
diff
changeset
|
404 (nreverse token-list))) |
31 | 405 |
406 ;;;----------------------------------------------------------------- | |
407 ;;; Translate C preprocessor #if expressions using recursive descent. | |
408 ;;; This parser is limited to the operators &&, ||, !, and "defined". | |
8914 | 409 ;;; Added ==, !=, +, and -. Gary Oberbrunner, garyo@avs.com, 8/9/94 |
31 | 410 |
41753
bf8b35f0db41
(hif-nexttoken): Move to before first def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41712
diff
changeset
|
411 (defsubst hif-nexttoken () |
bf8b35f0db41
(hif-nexttoken): Move to before first def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41712
diff
changeset
|
412 "Pop the next token from token-list into the let variable \"hif-token\"." |
bf8b35f0db41
(hif-nexttoken): Move to before first def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41712
diff
changeset
|
413 (setq hif-token (pop hif-token-list))) |
bf8b35f0db41
(hif-nexttoken): Move to before first def.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41712
diff
changeset
|
414 |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
415 (defun hif-parse-if-exp (hif-token-list) |
31 | 416 "Parse the TOKEN-LIST. Return translated list in prefix form." |
417 (hif-nexttoken) | |
418 (prog1 | |
419 (hif-expr) | |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
420 (if hif-token ; is there still a token? |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
421 (error "Error: unexpected token: %s" hif-token)))) |
31 | 422 |
423 (defun hif-expr () | |
13855 | 424 "Parse an expression as found in #if. |
43747
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
425 expr : or-expr | or-expr '?' expr ':' expr." |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
426 (let ((result (hif-or-expr)) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
427 middle) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
428 (while (eq hif-token 'hif-conditional) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
429 (hif-nexttoken) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
430 (setq middle (hif-expr)) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
431 (if (eq hif-token 'hif-colon) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
432 (progn |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
433 (hif-nexttoken) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
434 (setq result (list 'hif-conditional result middle (hif-expr)))) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
435 (error "Error: unexpected token: %s" hif-token))) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
436 result)) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
437 |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
438 (defun hif-or-expr () |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
439 "Parse n or-expr : and-expr | or-expr '||' and-expr." |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
440 (let ((result (hif-and-expr))) |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
441 (while (eq hif-token 'or) |
31 | 442 (hif-nexttoken) |
43747
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
443 (setq result (list 'hif-or result (hif-and-expr)))) |
210 | 444 result)) |
31 | 445 |
43747
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
446 (defun hif-and-expr () |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
447 "Parse an and-expr : eq-expr | and-expr '&&' eq-expr." |
8914 | 448 (let ((result (hif-eq-expr))) |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
449 (while (eq hif-token 'and) |
31 | 450 (hif-nexttoken) |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
451 (setq result (list 'hif-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)) | |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
458 (while (memq hif-token '(equal hif-notequal hif-greater hif-less |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
459 hif-greater-equal hif-less-equal)) |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
460 (setq eq-token hif-token) |
8914 | 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)) | |
93681
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
470 (while (memq hif-token '(hif-plus hif-minus hif-logior hif-logand)) |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
471 (setq math-op hif-token) |
8914 | 472 (hif-nexttoken) |
473 (setq result (list math-op result (hif-factor)))) | |
474 result)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
475 |
31 | 476 (defun hif-factor () |
13855 | 477 "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id." |
31 | 478 (cond |
26519 | 479 ((eq hif-token 'not) |
480 (hif-nexttoken) | |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
481 (list 'hif-not (hif-factor))) |
31 | 482 |
26519 | 483 ((eq hif-token 'lparen) |
484 (hif-nexttoken) | |
485 (let ((result (hif-expr))) | |
486 (if (not (eq hif-token 'rparen)) | |
487 (error "Bad token in parenthesized expression: %s" hif-token) | |
488 (hif-nexttoken) | |
489 result))) | |
31 | 490 |
26519 | 491 ((eq hif-token 'hif-defined) |
492 (hif-nexttoken) | |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
493 (let ((paren (when (eq hif-token 'lparen) (hif-nexttoken) t)) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
494 (ident hif-token)) |
26519 | 495 (if (memq hif-token '(or and not hif-defined lparen rparen)) |
496 (error "Error: unexpected token: %s" hif-token)) | |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
497 (when paren |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
498 (hif-nexttoken) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
499 (unless (eq hif-token 'rparen) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
500 (error "Error: expected \")\" after identifier"))) |
26519 | 501 (hif-nexttoken) |
41619 | 502 `(hif-defined (quote ,ident)))) |
31 | 503 |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
504 ((numberp hif-token) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
505 (prog1 hif-token (hif-nexttoken))) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
506 |
94036
d669760bc2f0
(hif-factor): Handle unary minus.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93681
diff
changeset
|
507 ;; Unary plus/minus. |
d669760bc2f0
(hif-factor): Handle unary minus.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93681
diff
changeset
|
508 ((memq hif-token '(hif-minus hif-plus)) |
d669760bc2f0
(hif-factor): Handle unary minus.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93681
diff
changeset
|
509 (list (prog1 hif-token (hif-nexttoken)) 0 (hif-factor))) |
d669760bc2f0
(hif-factor): Handle unary minus.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93681
diff
changeset
|
510 |
26519 | 511 (t ; identifier |
512 (let ((ident hif-token)) | |
513 (if (memq ident '(or and)) | |
514 (error "Error: missing identifier")) | |
515 (hif-nexttoken) | |
41619 | 516 `(hif-lookup (quote ,ident)))))) |
31 | 517 |
8914 | 518 (defun hif-mathify (val) |
519 "Treat VAL as a number: if it's t or nil, use 1 or 0." | |
41619 | 520 (cond ((eq val t) 1) |
521 ((null val) 0) | |
8914 | 522 (t val))) |
523 | |
43747
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
524 (defun hif-conditional (a b c) |
91939e9a62ec
Augment expression parser to handle conditional expressions.
Andreas Schwab <schwab@suse.de>
parents:
41753
diff
changeset
|
525 (if (not (zerop (hif-mathify a))) (hif-mathify b) (hif-mathify c))) |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
526 (defun hif-and (a b) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
527 (and (not (zerop (hif-mathify a))) (not (zerop (hif-mathify b))))) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
528 (defun hif-or (a b) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
529 (or (not (zerop (hif-mathify a))) (not (zerop (hif-mathify b))))) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
530 (defun hif-not (a) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
531 (zerop (hif-mathify a))) |
93681
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
532 |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
533 (defmacro hif-mathify-binop (fun) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
534 `(lambda (a b) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
535 ,(format "Like `%s' but treat t and nil as 1 and 0." fun) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
536 (,fun (hif-mathify a) (hif-mathify b)))) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
537 |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
538 (defalias 'hif-plus (hif-mathify-binop +)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
539 (defalias 'hif-minus (hif-mathify-binop -)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
540 (defalias 'hif-notequal (hif-mathify-binop /=)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
541 (defalias 'hif-greater (hif-mathify-binop >)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
542 (defalias 'hif-less (hif-mathify-binop <)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
543 (defalias 'hif-greater-equal (hif-mathify-binop >=)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
544 (defalias 'hif-less-equal (hif-mathify-binop <=)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
545 (defalias 'hif-logior (hif-mathify-binop logior)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
546 (defalias 'hif-logand (hif-mathify-binop logand)) |
c9b42189e94f
(hif-token-alist): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87923
diff
changeset
|
547 |
31 | 548 ;;;----------- end of parser ----------------------- |
549 | |
550 | |
551 (defun hif-canonicalize () | |
41619 | 552 "When at beginning of #ifX, return 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) | |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
556 (let* ((tokens (hif-tokenize (point) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
557 (progn (hif-end-of-line) (point)))) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
558 (expr (hif-parse-if-exp tokens))) |
41619 | 559 ;; (message "hif-canonicalized: %s" expr) |
31 | 560 (if negate |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
561 (list 'hif-not expr) |
31 | 562 expr))))) |
563 | |
564 | |
565 (defun hif-find-any-ifX () | |
13855 | 566 "Move to next #if..., or #ifndef, at point or after." |
41619 | 567 ;; (message "find ifX at %d" (point)) |
31 | 568 (prog1 |
569 (re-search-forward hif-ifx-regexp (point-max) t) | |
570 (beginning-of-line))) | |
571 | |
572 | |
573 (defun hif-find-next-relevant () | |
13855 | 574 "Move to next #if..., #else, or #endif, after the current line." |
41619 | 575 ;; (message "hif-find-next-relevant at %d" (point)) |
31 | 576 (end-of-line) |
41619 | 577 ;; avoid infinite recursion by only going to beginning of line if match found |
31 | 578 (if (re-search-forward hif-ifx-else-endif-regexp (point-max) t) |
210 | 579 (beginning-of-line))) |
31 | 580 |
581 (defun hif-find-previous-relevant () | |
13855 | 582 "Move to previous #if..., #else, or #endif, before the current line." |
41619 | 583 ;; (message "hif-find-previous-relevant at %d" (point)) |
31 | 584 (beginning-of-line) |
41619 | 585 ;; avoid infinite recursion by only going to beginning of line if match found |
31 | 586 (if (re-search-backward hif-ifx-else-endif-regexp (point-min) t) |
210 | 587 (beginning-of-line))) |
31 | 588 |
589 | |
590 (defun hif-looking-at-ifX () ;; Should eventually see #if | |
591 (looking-at hif-ifx-regexp)) | |
592 (defun hif-looking-at-endif () | |
593 (looking-at hif-endif-regexp)) | |
594 (defun hif-looking-at-else () | |
595 (looking-at hif-else-regexp)) | |
596 | |
597 | |
598 | |
599 (defun hif-ifdef-to-endif () | |
600 "If positioned at #ifX or #else form, skip to corresponding #endif." | |
41619 | 601 ;; (message "hif-ifdef-to-endif at %d" (point)) (sit-for 1) |
31 | 602 (hif-find-next-relevant) |
603 (cond ((hif-looking-at-ifX) | |
604 (hif-ifdef-to-endif) ; find endif of nested if | |
605 (hif-ifdef-to-endif)) ; find outer endif or else | |
606 ((hif-looking-at-else) | |
607 (hif-ifdef-to-endif)) ; find endif following else | |
608 ((hif-looking-at-endif) | |
609 'done) | |
610 (t | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3457
diff
changeset
|
611 (error "Mismatched #ifdef #endif pair")))) |
31 | 612 |
613 | |
614 (defun hif-endif-to-ifdef () | |
615 "If positioned at #endif form, skip backward to corresponding #ifX." | |
41619 | 616 ;; (message "hif-endif-to-ifdef at %d" (point)) |
31 | 617 (let ((start (point))) |
618 (hif-find-previous-relevant) | |
619 (if (= start (point)) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3457
diff
changeset
|
620 (error "Mismatched #ifdef #endif pair"))) |
31 | 621 (cond ((hif-looking-at-endif) |
622 (hif-endif-to-ifdef) ; find beginning of nested if | |
623 (hif-endif-to-ifdef)) ; find beginning of outer if or else | |
624 ((hif-looking-at-else) | |
625 (hif-endif-to-ifdef)) | |
626 ((hif-looking-at-ifX) | |
627 'done) | |
922 | 628 (t))) ; never gets here |
31 | 629 |
630 | |
631 (defun forward-ifdef (&optional arg) | |
632 "Move point to beginning of line of the next ifdef-endif. | |
210 | 633 With argument, do this that many times." |
31 | 634 (interactive "p") |
635 (or arg (setq arg 1)) | |
41619 | 636 (if (< arg 0) (backward-ifdef (- arg)) |
637 (while (< 0 arg) | |
638 (setq arg (- arg)) | |
639 (let ((start (point))) | |
640 (unless (hif-looking-at-ifX) | |
31 | 641 (hif-find-next-relevant)) |
41619 | 642 (if (hif-looking-at-ifX) |
643 (hif-ifdef-to-endif) | |
644 (goto-char start) | |
645 (error "No following #ifdef")))))) | |
31 | 646 |
647 | |
648 (defun backward-ifdef (&optional arg) | |
649 "Move point to beginning of the previous ifdef-endif. | |
210 | 650 With argument, do this that many times." |
31 | 651 (interactive "p") |
652 (or arg (setq arg 1)) | |
41619 | 653 (if (< arg 0) (forward-ifdef (- arg)) |
654 (while (< 0 arg) | |
655 (setq arg (1- arg)) | |
656 (beginning-of-line) | |
657 (let ((start (point))) | |
658 (unless (hif-looking-at-endif) | |
31 | 659 (hif-find-previous-relevant)) |
41619 | 660 (if (hif-looking-at-endif) |
661 (hif-endif-to-ifdef) | |
662 (goto-char start) | |
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))) | |
41619 | 682 (unless (hif-looking-at-endif) |
683 (hif-find-previous-relevant)) | |
31 | 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)) | |
41619 | 694 (if (< arg 0) (previous-ifdef (- arg)) |
695 (while (< 0 arg) | |
696 (setq arg (1- arg)) | |
697 (hif-find-next-relevant) | |
698 (when (eolp) | |
699 (beginning-of-line) | |
700 (error "No following #ifdefs, #elses, or #endifs"))))) | |
31 | 701 |
702 (defun previous-ifdef (&optional arg) | |
703 "Move to the beginning of the previous #ifX, #else, or #endif. | |
210 | 704 With argument, do this that many times." |
31 | 705 (interactive "p") |
706 (or arg (setq arg 1)) | |
41619 | 707 (if (< arg 0) (next-ifdef (- arg)) |
708 (while (< 0 arg) | |
709 (setq arg (1- arg)) | |
710 (let ((start (point))) | |
711 (hif-find-previous-relevant) | |
712 (if (= start (point)) | |
713 (error "No previous #ifdefs, #elses, or #endifs")))))) | |
31 | 714 |
715 | |
41619 | 716 ;;===%%SF%% parsing (End) === |
31 | 717 |
718 | |
41619 | 719 ;;===%%SF%% hide-ifdef-hiding (Start) === |
31 | 720 |
721 | |
722 ;;; A range is a structure with four components: | |
723 ;;; ELSE-P True if there was an else clause for the ifdef. | |
724 ;;; START The start of the range. (beginning of line) | |
725 ;;; ELSE The else marker (beginning of line) | |
726 ;;; Only valid if ELSE-P is true. | |
727 ;;; END The end of the range. (beginning of line) | |
728 | |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
729 (defsubst hif-make-range (start end &optional else) |
41619 | 730 (list start else end)) |
31 | 731 |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
732 (defsubst hif-range-start (range) (elt range 0)) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
733 (defsubst hif-range-else (range) (elt range 1)) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
734 (defsubst hif-range-end (range) (elt range 2)) |
31 | 735 |
736 | |
737 | |
738 ;;; Find-Range | |
739 ;;; The workhorse, it delimits the #if region. Reasonably simple: | |
740 ;;; Skip until an #else or #endif is found, remembering positions. If | |
741 ;;; an #else was found, skip some more, looking for the true #endif. | |
742 | |
743 (defun hif-find-range () | |
41619 | 744 "Return a Range structure describing the current #if region. |
31 | 745 Point is left unchanged." |
41619 | 746 ;; (message "hif-find-range at %d" (point)) |
31 | 747 (save-excursion |
748 (beginning-of-line) | |
749 (let ((start (point)) | |
750 (else nil) | |
751 (end nil)) | |
752 ;; Part one. Look for either #endif or #else. | |
753 ;; This loop-and-a-half dedicated to E. Dijkstra. | |
41619 | 754 (while (progn |
755 (hif-find-next-relevant) | |
756 (hif-looking-at-ifX)) ; Skip nested ifdef | |
757 (hif-ifdef-to-endif)) | |
31 | 758 ;; Found either a #else or an #endif. |
759 (cond ((hif-looking-at-else) | |
760 (setq else (point))) | |
761 (t | |
41619 | 762 (setq end (point)))) ; (save-excursion (end-of-line) (point)) |
31 | 763 ;; If found #else, look for #endif. |
41619 | 764 (when else |
765 (while (progn | |
766 (hif-find-next-relevant) | |
767 (hif-looking-at-ifX)) ; Skip nested ifdef | |
768 (hif-ifdef-to-endif)) | |
769 (if (hif-looking-at-else) | |
770 (error "Found two elses in a row? Broken!")) | |
771 (setq end (point))) ; (save-excursion (end-of-line) (point)) | |
772 (hif-make-range start end else)))) | |
31 | 773 |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
774 |
31 | 775 ;;; A bit slimy. |
776 | |
777 (defun hif-hide-line (point) | |
210 | 778 "Hide the line containing point. Does nothing if `hide-ifdef-lines' is nil." |
87851
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
779 (when hide-ifdef-lines |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
780 (save-excursion |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
781 (goto-char point) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
782 (hide-ifdef-region-internal |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
783 (line-beginning-position) (progn (hif-end-of-line) (point)))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
784 |
31 | 785 |
786 ;;; Hif-Possibly-Hide | |
787 ;;; There are four cases. The #ifX expression is "taken" if it | |
788 ;;; the hide-ifdef-evaluator returns T. Presumably, this means the code | |
789 ;;; inside the #ifdef would be included when the program was | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
790 ;;; compiled. |
31 | 791 ;;; |
792 ;;; Case 1: #ifX taken, and there's an #else. | |
793 ;;; The #else part must be hidden. The #if (then) part must be | |
794 ;;; processed for nested #ifX's. | |
795 ;;; Case 2: #ifX taken, and there's no #else. | |
796 ;;; The #if part must be processed for nested #ifX's. | |
797 ;;; Case 3: #ifX not taken, and there's an #else. | |
798 ;;; The #if part must be hidden. The #else part must be processed | |
799 ;;; for nested #ifs. | |
800 ;;; Case 4: #ifX not taken, and there's no #else. | |
801 ;;; The #ifX part must be hidden. | |
802 ;;; | |
803 ;;; Further processing is done by narrowing to the relevant region | |
804 ;;; and just recursively calling hide-ifdef-guts. | |
805 ;;; | |
806 ;;; When hif-possibly-hide returns, point is at the end of the | |
807 ;;; possibly-hidden range. | |
808 | |
809 (defun hif-recurse-on (start end) | |
210 | 810 "Call `hide-ifdef-guts' after narrowing to end of START line and END line." |
31 | 811 (save-excursion |
812 (save-restriction | |
813 (goto-char start) | |
814 (end-of-line) | |
815 (narrow-to-region (point) end) | |
816 (hide-ifdef-guts)))) | |
817 | |
818 (defun hif-possibly-hide () | |
13855 | 819 "Called at #ifX expression, this hides those parts that should be hidden. |
820 It uses the judgement of `hide-ifdef-evaluator'." | |
41619 | 821 ;; (message "hif-possibly-hide") (sit-for 1) |
822 (let ((test (hif-canonicalize)) | |
823 (range (hif-find-range))) | |
824 ;; (message "test = %s" test) (sit-for 1) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
825 |
41619 | 826 (hif-hide-line (hif-range-end range)) |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
827 (if (not (hif-not (funcall hide-ifdef-evaluator test))) |
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
828 (cond ((hif-range-else range) ; case 1 |
31 | 829 (hif-hide-line (hif-range-else range)) |
41644
6546efdc0288
(hif-end-of-line): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41619
diff
changeset
|
830 (hide-ifdef-region (hif-range-else range) |
41619 | 831 (1- (hif-range-end range))) |
832 (hif-recurse-on (hif-range-start range) | |
833 (hif-range-else range))) | |
834 (t ; case 2 | |
835 (hif-recurse-on (hif-range-start range) | |
836 (hif-range-end range)))) | |
837 (cond ((hif-range-else range) ; case 3 | |
838 (hif-hide-line (hif-range-else range)) | |
839 (hide-ifdef-region (hif-range-start range) | |
840 (1- (hif-range-else range))) | |
841 (hif-recurse-on (hif-range-else range) | |
842 (hif-range-end range))) | |
843 (t ; case 4 | |
844 (hide-ifdef-region (point) | |
845 (1- (hif-range-end range)))))) | |
846 (hif-hide-line (hif-range-start range)) ; Always hide start. | |
847 (goto-char (hif-range-end range)) | |
848 (end-of-line))) | |
31 | 849 |
850 | |
851 | |
852 (defun hide-ifdef-guts () | |
13855 | 853 "Does most of the work of `hide-ifdefs'. |
854 It does not do the work that's pointless to redo on a recursive entry." | |
41619 | 855 ;; (message "hide-ifdef-guts") |
31 | 856 (save-excursion |
857 (goto-char (point-min)) | |
858 (while (hif-find-any-ifX) | |
859 (hif-possibly-hide)))) | |
860 | |
41619 | 861 ;;===%%SF%% hide-ifdef-hiding (End) === |
31 | 862 |
863 | |
41619 | 864 ;;===%%SF%% exports (Start) === |
31 | 865 |
866 (defun hide-ifdef-toggle-read-only () | |
41619 | 867 "Toggle `hide-ifdef-read-only'." |
31 | 868 (interactive) |
869 (setq hide-ifdef-read-only (not hide-ifdef-read-only)) | |
870 (message "Hide-Read-Only %s" | |
871 (if hide-ifdef-read-only "ON" "OFF")) | |
872 (if hide-ifdef-hiding | |
873 (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
|
874 (force-mode-line-update)) |
31 | 875 |
876 (defun hide-ifdef-toggle-outside-read-only () | |
13855 | 877 "Replacement for `toggle-read-only' within Hide-Ifdef mode." |
31 | 878 (interactive) |
879 (setq hif-outside-read-only (not hif-outside-read-only)) | |
880 (message "Read only %s" | |
881 (if hif-outside-read-only "ON" "OFF")) | |
882 (setq buffer-read-only | |
883 (or (and hide-ifdef-hiding hide-ifdef-read-only) | |
41619 | 884 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
|
885 (force-mode-line-update)) |
31 | 886 |
87851
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
887 (defun hide-ifdef-toggle-shadowing () |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
888 "Toggle shadowing." |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
889 (interactive) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
890 (set (make-local-variable 'hide-ifdef-shadow) (not hide-ifdef-shadow)) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
891 (message "Shadowing %s" (if hide-ifdef-shadow "ON" "OFF")) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
892 (save-restriction |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
893 (widen) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
894 (dolist (overlay (overlays-in (point-min) (point-max))) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
895 (when (overlay-get overlay 'hide-ifdef) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
896 (if hide-ifdef-shadow |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
897 (progn |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
898 (overlay-put overlay 'invisible nil) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
899 (overlay-put overlay 'face 'hide-ifdef-shadow)) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
900 (overlay-put overlay 'face nil) |
6e4b2a69d875
(hide-ifdef-shadow): New option.
Martin Rudalics <rudalics@gmx.at>
parents:
79717
diff
changeset
|
901 (overlay-put overlay 'invisible 'hide-ifdef)))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
902 |
31 | 903 (defun hide-ifdef-define (var) |
904 "Define a VAR so that #ifdef VAR would be included." | |
905 (interactive "SDefine what? ") | |
8914 | 906 (hif-set-var var 1) |
31 | 907 (if hide-ifdef-hiding (hide-ifdefs))) |
908 | |
909 (defun hide-ifdef-undef (var) | |
910 "Undefine a VAR so that #ifdef VAR would not be included." | |
911 (interactive "SUndefine what? ") | |
912 (hif-set-var var nil) | |
913 (if hide-ifdef-hiding (hide-ifdefs))) | |
914 | |
915 | |
13855 | 916 (defun hide-ifdefs (&optional nomsg) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
917 "Hide the contents of some #ifdefs. |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43747
diff
changeset
|
918 Assume that defined symbols have been added to `hide-ifdef-env'. |
1476 | 919 The text hidden is the text that would not be included by the C |
920 preprocessor if it were given the file with those symbols defined. | |
31 | 921 |
8375 | 922 Turn off hiding by calling `show-ifdefs'." |
31 | 923 |
924 (interactive) | |
925 (message "Hiding...") | |
13856
8046a1616264
(hide-ifdefs): Set hif-outside-read-only here.
Richard M. Stallman <rms@gnu.org>
parents:
13855
diff
changeset
|
926 (setq hif-outside-read-only buffer-read-only) |
41619 | 927 (unless hide-ifdef-mode (hide-ifdef-mode 1)) ; turn on hide-ifdef-mode |
31 | 928 (if hide-ifdef-hiding |
929 (show-ifdefs)) ; Otherwise, deep confusion. | |
41619 | 930 (setq hide-ifdef-hiding t) |
931 (hide-ifdef-guts) | |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
932 (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only)) |
13855 | 933 (or nomsg |
934 (message "Hiding done"))) | |
31 | 935 |
936 | |
937 (defun show-ifdefs () | |
13855 | 938 "Cancel the effects of `hide-ifdef': show the contents of all #ifdefs." |
31 | 939 (interactive) |
7324
7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
5560
diff
changeset
|
940 (setq buffer-read-only hif-outside-read-only) |
41619 | 941 (hif-show-all) |
210 | 942 (setq hide-ifdef-hiding nil)) |
31 | 943 |
944 | |
945 (defun hif-find-ifdef-block () | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3457
diff
changeset
|
946 "Utility for hide and show `ifdef-block'. |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
947 Return as (TOP . BOTTOM) the extent of ifdef block." |
31 | 948 (let (max-bottom) |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
949 (cons (save-excursion |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
950 (beginning-of-line) |
41619 | 951 (unless (or (hif-looking-at-else) (hif-looking-at-ifX)) |
952 (up-ifdef)) | |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
953 (prog1 (point) |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
954 (hif-ifdef-to-endif) |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
955 (setq max-bottom (1- (point))))) |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
956 (save-excursion |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
957 (beginning-of-line) |
41619 | 958 (unless (hif-looking-at-endif) |
959 (hif-find-next-relevant)) | |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
960 (while (hif-looking-at-ifX) |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
961 (hif-ifdef-to-endif) |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
962 (hif-find-next-relevant)) |
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
963 (min max-bottom (1- (point))))))) |
31 | 964 |
965 | |
966 (defun hide-ifdef-block () | |
967 "Hide the ifdef block (true or false part) enclosing or before the cursor." | |
968 (interactive) | |
41619 | 969 (unless hide-ifdef-mode (hide-ifdef-mode 1)) |
970 (let ((top-bottom (hif-find-ifdef-block))) | |
23440
21dd0dd62240
(hide-ifdef-env, hif-outside-read-only):
Andreas Schwab <schwab@suse.de>
parents:
20781
diff
changeset
|
971 (hide-ifdef-region (car top-bottom) (cdr top-bottom)) |
41619 | 972 (when hide-ifdef-lines |
973 (hif-hide-line (car top-bottom)) | |
974 (hif-hide-line (1+ (cdr top-bottom)))) | |
210 | 975 (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
|
976 (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only))) |
31 | 977 |
978 (defun show-ifdef-block () | |
979 "Show the ifdef block (true or false part) enclosing or before the cursor." | |
980 (interactive) | |
70769
c1396ff7810f
(show-ifdef-block): Fix bug where parts of a hidden block remained hidden if
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
981 (let ((top-bottom (hif-find-ifdef-block))) |
c1396ff7810f
(show-ifdef-block): Fix bug where parts of a hidden block remained hidden if
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
982 (if hide-ifdef-lines |
c1396ff7810f
(show-ifdef-block): Fix bug where parts of a hidden block remained hidden if
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
983 (hif-show-ifdef-region |
c1396ff7810f
(show-ifdef-block): Fix bug where parts of a hidden block remained hidden if
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
984 (save-excursion |
c1396ff7810f
(show-ifdef-block): Fix bug where parts of a hidden block remained hidden if
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
985 (goto-char (car top-bottom)) (line-beginning-position)) |
c1396ff7810f
(show-ifdef-block): Fix bug where parts of a hidden block remained hidden if
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
986 (save-excursion |
c1396ff7810f
(show-ifdef-block): Fix bug where parts of a hidden block remained hidden if
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
987 (goto-char (1+ (cdr top-bottom))) |
c1396ff7810f
(show-ifdef-block): Fix bug where parts of a hidden block remained hidden if
Eli Zaretskii <eliz@gnu.org>
parents:
68773
diff
changeset
|
988 (hif-end-of-line) (point))) |
41619 | 989 (hif-show-ifdef-region (1- (car top-bottom)) (cdr top-bottom))))) |
31 | 990 |
991 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3457
diff
changeset
|
992 ;;; definition alist support |
31 | 993 |
994 (defvar hide-ifdef-define-alist nil | |
41619 | 995 "A global assoc list of pre-defined symbol lists.") |
31 | 996 |
997 (defun hif-compress-define-list (env) | |
998 "Compress the define list ENV into a list of defined symbols only." | |
41619 | 999 (let ((new-defs nil)) |
1000 (dolist (def env new-defs) | |
1001 (if (hif-lookup (car def)) (push (car env) new-defs))))) | |
31 | 1002 |
1003 (defun hide-ifdef-set-define-alist (name) | |
1476 | 1004 "Set the association for NAME to `hide-ifdef-env'." |
31 | 1005 (interactive "SSet define list: ") |
41619 | 1006 (push (cons name (hif-compress-define-list hide-ifdef-env)) |
1007 hide-ifdef-define-alist)) | |
31 | 1008 |
1009 (defun hide-ifdef-use-define-alist (name) | |
1476 | 1010 "Set `hide-ifdef-env' to the define list specified by NAME." |
60213
de939ef4dd88
(hide-ifdef-use-define-alist): Use
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
1011 (interactive |
de939ef4dd88
(hide-ifdef-use-define-alist): Use
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
1012 (list (completing-read "Use define list: " |
64119
b83cb76e940c
(hide-ifdef-use-define-alist): Pass a list of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1013 (mapcar (lambda (x) (symbol-name (car x))) |
b83cb76e940c
(hide-ifdef-use-define-alist): Pass a list of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1014 hide-ifdef-define-alist) |
b83cb76e940c
(hide-ifdef-use-define-alist): Pass a list of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1015 nil t))) |
60213
de939ef4dd88
(hide-ifdef-use-define-alist): Use
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
1016 (if (stringp name) (setq name (intern name))) |
31 | 1017 (let ((define-list (assoc name hide-ifdef-define-alist))) |
1018 (if define-list | |
1019 (setq hide-ifdef-env | |
29588
0cf06902af64
(hif-compress-define-list)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26519
diff
changeset
|
1020 (mapcar (lambda (arg) (cons arg t)) |
31 | 1021 (cdr define-list))) |
1022 (error "No define list for %s" name)) | |
210 | 1023 (if hide-ifdef-hiding (hide-ifdefs)))) |
31 | 1024 |
13297
9699410bf8bf
Provide hideif; require cc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
12954
diff
changeset
|
1025 (provide 'hideif) |
9699410bf8bf
Provide hideif; require cc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
12954
diff
changeset
|
1026 |
64119
b83cb76e940c
(hide-ifdef-use-define-alist): Pass a list of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1027 ;; arch-tag: c6381d17-a59a-483a-b945-658f22277981 |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
210
diff
changeset
|
1028 ;;; hideif.el ends here |