annotate lisp/progmodes/hideif.el @ 14502:37107ad125f0

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