annotate lisp/modes/hideif.el @ 0:376386a54a3c r19-14

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