annotate lisp/progmodes/hideif.el @ 4823:ec62e93360d1

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