annotate lisp/progmodes/hideif.el @ 109734:650ab6e37354

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