annotate lisp/progmodes/hideif.el @ 69362:29fe34ec2296

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