annotate lisp/progmodes/cpp.el @ 14975:7b91ceb19771

[DJGPP v2]: Include fcntl.h. (copy_text_and_data) [DJGPP v2]: Call __djgpp_exception_toggle.
author Richard M. Stallman <rms@gnu.org>
date Wed, 10 Apr 1996 04:15:13 +0000
parents 2b2e0cef30d5
children 58b38425b463
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; cpp.el --- Highlight or hide text according to cpp conditionals.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
3 ;; Copyright (C) 1994, 1995 Free Software Foundation
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@iesd.auc.dk>
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: c, faces, tools
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
8736
fe48762e68de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
8 ;; This file is part of GNU Emacs.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
8736
fe48762e68de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
8736
fe48762e68de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
14
fe48762e68de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
8736
fe48762e68de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
19
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13974
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13974
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13974
diff changeset
23 ;; Boston, MA 02111-1307, USA.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
8736
fe48762e68de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
25 ;;; Commentary:
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; Parse a text for C preprocessor conditionals, and highlight or hide
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; the text inside the conditionals as you wish.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
8740
714588372e06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8736
diff changeset
30 ;; This package is inspired by Jim Coplien's delta editor for SCCS.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; Todo:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Should parse "#if" and "#elif" expressions and merge the faces
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; somehow.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Somehow it is sometimes possible to make changes near a read only
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; area which you can't undo. Their are other strange effects in that
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; area.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; The Edit buffer should -- optionally -- appear in its own frame.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; Conditionals seem to be rear-sticky. They shouldn't be.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; Restore window configurations when exiting CPP Edit buffer.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; Code:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; Customization:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
13911
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
51 (defvar cpp-config-file (convert-standard-filename ".cpp.el")
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
52 "*File name to save cpp configuration.")
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
53
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (defvar cpp-known-face 'invisible
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 "*Face used for known cpp symbols.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (defvar cpp-unknown-face 'highlight
13974
37cfc82fe02d (cpp-unknown-face, cpp-face-mono-list, cpp-face-all-list):
Karl Heuer <kwzh@gnu.org>
parents: 13911
diff changeset
58 "*Face used for unknown cpp symbols.")
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (defvar cpp-face-type 'light
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 "*Indicate what background face type you prefer.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 Can be either light or dark for color screens, mono for monochrome
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 screens, and none if you don't use a window system.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (defvar cpp-known-writable t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 "*Non-nil means you are allowed to modify the known conditionals.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (defvar cpp-unknown-writable t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 "*Non-nil means you are allowed to modify the unknown conditionals.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
71 (defvar cpp-edit-list nil
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
72 "Alist of cpp macros and information about how they should be displayed.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
73 Each entry is a list with the following elements:
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
74 0. The name of the macro (a string).
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
75 1. Face used for text that is `ifdef' the macro.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
76 2. Face used for text that is `ifndef' the macro.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
77 3. `t', `nil', or `both' depending on what text may be edited.")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
78
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
79 (defvar cpp-overlay-list nil)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
80 ;; List of cpp overlays active in the current buffer.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
81 (make-variable-buffer-local 'cpp-overlay-list)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
82
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
83 (defvar cpp-callback-data)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
84 (defvar cpp-state-stack)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
85
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
86 (defconst cpp-face-type-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
87 '(("light color background" . light)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
88 ("dark color background" . dark)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
89 ("monochrome" . mono)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
90 ("tty" . none))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
91 "Alist of strings and names of the defined face collections.")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
92
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
93 (defconst cpp-writable-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
94 ;; Names used for the writable property.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
95 '(("writable" . t)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
96 ("read-only" . nil)))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
97
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
98 (defvar cpp-button-event nil)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
99 ;; This will be t in the callback for `cpp-make-button'.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
100
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
101 (defvar cpp-edit-buffer nil)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
102 ;; Real buffer whose cpp display information we are editing.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
103 (make-variable-buffer-local 'cpp-edit-buffer)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
104
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
105 (defconst cpp-branch-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
106 ;; Alist of branches.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
107 '(("false" . nil)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
108 ("true" . t)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
109 ("both" . both)))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
110
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
111 (defvar cpp-face-default-list nil
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
112 "List of faces you can choose from for cpp conditionals.")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
113
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
114 (defvar cpp-face-light-name-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
115 '("light gray" "light blue" "light cyan" "light yellow" "light pink"
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
116 "pale green" "beige" "orange" "magenta" "violet" "medium purple"
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
117 "turquoise")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
118 "Background colours useful with dark foreground colors.")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
119
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
120 (defvar cpp-face-dark-name-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
121 '("dim gray" "blue" "cyan" "yellow" "red"
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
122 "dark green" "brown" "dark orange" "dark khaki" "dark violet" "purple"
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
123 "dark turquoise")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
124 "Background colours useful with light foreground colors.")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
125
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
126 (defvar cpp-face-light-list nil
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
127 "Alist of names and faces to be used for light backgrounds.")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
128
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
129 (defvar cpp-face-dark-list nil
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
130 "Alist of names and faces to be used for dark backgrounds.")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
131
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
132 (defvar cpp-face-mono-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
133 '(("bold" . 'bold)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
134 ("bold-italic" . 'bold-italic)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
135 ("italic" . 'italic)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
136 ("underline" . 'underline))
13974
37cfc82fe02d (cpp-unknown-face, cpp-face-mono-list, cpp-face-all-list):
Karl Heuer <kwzh@gnu.org>
parents: 13911
diff changeset
137 "Alist of names and faces to be used for monochrome screens.")
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
138
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
139 (defvar cpp-face-none-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
140 '(("default" . default)
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
141 ("invisible" . invisible))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
142 "Alist of names and faces available even if you don't use a window system.")
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
143
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
144 (defvar cpp-face-all-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
145 (append cpp-face-light-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
146 cpp-face-dark-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
147 cpp-face-mono-list
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
148 cpp-face-none-list)
13974
37cfc82fe02d (cpp-unknown-face, cpp-face-mono-list, cpp-face-all-list):
Karl Heuer <kwzh@gnu.org>
parents: 13911
diff changeset
149 "All faces used for highlighting text inside cpp conditionals.")
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
150
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;;; Parse Buffer:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (defvar cpp-parse-symbols nil
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 "List of cpp macros used in the local buffer.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (make-variable-buffer-local 'cpp-parse-symbols)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (defconst cpp-parse-regexp
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;; Regexp matching all tokens needed to find conditionals.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (concat
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 "'\\|\"\\|/\\*\\|//\\|"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 "\\(^[ \t]*#[ \t]*\\(ifdef\\|ifndef\\|if\\|"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 "elif\\|else\\|endif\\)\\b\\)"))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;;;###autoload
8741
9728aab0cab3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 8740
diff changeset
165 (defun cpp-highlight-buffer (arg)
9728aab0cab3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 8740
diff changeset
166 "Highlight C code according to preprocessor conditionals.
9728aab0cab3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 8740
diff changeset
167 This command pops up a buffer which you should edit to specify
9728aab0cab3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 8740
diff changeset
168 what kind of highlighting to use, and the criteria for highlighting.
11456
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
169 A prefix arg suppresses display of that buffer."
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (interactive "P")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (setq cpp-parse-symbols nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (cpp-parse-reset)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (if (null cpp-edit-list)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (cpp-edit-load))
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
175 (let (cpp-state-stack)
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (save-excursion
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (goto-char (point-min))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (cpp-progress-message "Parsing...")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (while (re-search-forward cpp-parse-regexp nil t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (cpp-progress-message "Parsing...%d%%"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (/ (* 100 (- (point) (point-min))) (buffer-size)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (let ((match (buffer-substring (match-beginning 0) (match-end 0))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (cond ((or (string-equal match "'")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (string-equal match "\""))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (goto-char (match-beginning 0))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (condition-case nil
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (forward-sexp)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (error (cpp-parse-error
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "Unterminated string or character"))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ((string-equal match "/*")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (or (search-forward "*/" nil t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (error "Unterminated comment")))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ((string-equal match "//")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (skip-chars-forward "^\n\r"))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (end-of-line 1)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (let ((from (match-beginning 1))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (to (1+ (point)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (type (buffer-substring (match-beginning 2)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (match-end 2)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (expr (buffer-substring (match-end 1) (point))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (cond ((string-equal type "ifdef")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (cpp-parse-open t expr from to))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ((string-equal type "ifndef")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (cpp-parse-open nil expr from to))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ((string-equal type "if")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (cpp-parse-open t expr from to))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ((string-equal type "elif")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (let (cpp-known-face cpp-unknown-face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (cpp-parse-close from to))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (cpp-parse-open t expr from to))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ((string-equal type "else")
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
213 (or cpp-state-stack
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
214 (cpp-parse-error "Top level #else"))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
215 (let ((entry (list (not (nth 0 (car cpp-state-stack)))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
216 (nth 1 (car cpp-state-stack))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 from to)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (cpp-parse-close from to)
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
219 (setq cpp-state-stack (cons entry cpp-state-stack))))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ((string-equal type "endif")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (cpp-parse-close from to))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (cpp-parse-error "Parser error"))))))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (message "Parsing...done"))
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
225 (if cpp-state-stack
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (save-excursion
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
227 (goto-char (nth 3 (car cpp-state-stack)))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (cpp-parse-error "Unclosed conditional"))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (or arg
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (null cpp-parse-symbols)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (cpp-parse-edit)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (defun cpp-parse-open (branch expr begin end)
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
234 "Push information about conditional-beginning onto `cpp-state-stack'."
11456
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
235 ;; Discard comments within this line.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (while (string-match "\\b[ \t]*/\\*.*\\*/[ \t]*\\b" expr)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (setq expr (concat (substring expr 0 (match-beginning 0))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (substring expr (match-end 0)))))
11456
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
239 ;; If a comment starts on this line and continues past, discard it.
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
240 (if (string-match "\\b[ \t]*/\\*" expr)
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
241 (setq expr (substring expr 0 (match-beginning 0))))
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
242 ;; Delete any C++ comment from the line.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (if (string-match "\\b[ \t]*\\(//.*\\)?$" expr)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (setq expr (substring expr 0 (match-beginning 0))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (while (string-match "[ \t]+" expr)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (setq expr (concat (substring expr 0 (match-beginning 0))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (substring expr (match-end 0)))))
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
248 (setq cpp-state-stack (cons (list branch expr begin end) cpp-state-stack))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (or (member expr cpp-parse-symbols)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (setq cpp-parse-symbols
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (cons expr cpp-parse-symbols)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (if (assoc expr cpp-edit-list)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (cpp-make-known-overlay begin end)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (cpp-make-unknown-overlay begin end)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (defun cpp-parse-close (from to)
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
257 ;; Pop top of cpp-state-stack and create overlay.
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
258 (let ((entry (assoc (nth 1 (car cpp-state-stack)) cpp-edit-list))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
259 (branch (nth 0 (car cpp-state-stack)))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
260 (begin (nth 2 (car cpp-state-stack)))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
261 (end (nth 3 (car cpp-state-stack))))
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
262 (setq cpp-state-stack (cdr cpp-state-stack))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (if entry
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (let ((face (nth (if branch 1 2) entry))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (read-only (eq (not branch) (nth 3 entry)))
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
266 (priority (length cpp-state-stack))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (overlay (make-overlay end from)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (cpp-make-known-overlay from to)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (setq cpp-overlay-list (cons overlay cpp-overlay-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (if priority (overlay-put overlay 'priority priority))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (cond ((eq face 'invisible)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (cpp-make-overlay-hidden overlay))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 ((eq face 'default))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (overlay-put overlay 'face face)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (if read-only
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (cpp-make-overlay-read-only overlay)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (cpp-make-overlay-sticky overlay)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (cpp-make-unknown-overlay from to))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (defun cpp-parse-error (error)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 ;; Error message issued by the cpp parser.
14417
2b2e0cef30d5 (cpp-parse-error): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
283 (error "%s at line %d" error (count-lines (point-min) (point))))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (defun cpp-parse-reset ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 "Reset display of cpp conditionals to normal."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (while cpp-overlay-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (delete-overlay (car cpp-overlay-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (setq cpp-overlay-list (cdr cpp-overlay-list))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 ;;;###autoload
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (defun cpp-parse-edit ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 "Edit display information for cpp conditionals."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (or cpp-parse-symbols
11456
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
297 (cpp-highlight-buffer t))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (let ((buffer (current-buffer)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (pop-to-buffer "*CPP Edit*")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (cpp-edit-mode)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (setq cpp-edit-buffer buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (cpp-edit-reset)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 ;;; Overlays:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (defun cpp-make-known-overlay (start end)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ;; Create an overlay for a known cpp command from START to END.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (let ((overlay (make-overlay start end)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (if (eq cpp-known-face 'invisible)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (cpp-make-overlay-hidden overlay)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (or (eq cpp-known-face 'default)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (overlay-put overlay 'face cpp-known-face))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (if cpp-known-writable
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (overlay-put overlay 'modification-hooks '(cpp-signal-read-only))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (overlay-put overlay 'insert-in-front-hooks '(cpp-signal-read-only))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (setq cpp-overlay-list (cons overlay cpp-overlay-list))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (defun cpp-make-unknown-overlay (start end)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 ;; Create an overlay for an unknown cpp command from START to END.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (let ((overlay (make-overlay start end)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (cond ((eq cpp-unknown-face 'invisible)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (cpp-make-overlay-hidden overlay))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 ((eq cpp-unknown-face 'default))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (overlay-put overlay 'face cpp-unknown-face)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (if cpp-unknown-writable
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (overlay-put overlay 'modification-hooks '(cpp-signal-read-only))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (overlay-put overlay 'insert-in-front-hooks '(cpp-signal-read-only)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (setq cpp-overlay-list (cons overlay cpp-overlay-list))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (defun cpp-make-overlay-hidden (overlay)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 ;; Make overlay hidden and intangible.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (overlay-put overlay 'invisible t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (overlay-put overlay 'intangible t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 ;; Unfortunately `intangible' is not implemented for overlays yet,
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 ;; so we make is read-only instead.
11492
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
339 (overlay-put overlay 'modification-hooks '(cpp-signal-read-only))
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
340 (overlay-put overlay 'insert-in-front-hooks '(cpp-signal-read-only)))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (defun cpp-make-overlay-read-only (overlay)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 ;; Make overlay read only.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (overlay-put overlay 'modification-hooks '(cpp-signal-read-only))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (overlay-put overlay 'insert-in-front-hooks '(cpp-signal-read-only))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (overlay-put overlay 'insert-behind-hooks '(cpp-signal-read-only)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (defun cpp-make-overlay-sticky (overlay)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 ;; Make OVERLAY grow when you insert text at either end.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (overlay-put overlay 'insert-in-front-hooks '(cpp-grow-overlay))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (overlay-put overlay 'insert-behind-hooks '(cpp-grow-overlay)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352
11492
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
353 (defun cpp-signal-read-only (overlay after start end &optional len)
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 ;; Only allow deleting the whole overlay.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 ;; Trying to change a read-only overlay.
11492
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
356 (if (and (not after)
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
357 (or (< (overlay-start overlay) start)
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
358 (> (overlay-end overlay) end)))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (error "This text is read only")))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
11492
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
361 (defun cpp-grow-overlay (overlay after start end &optional len)
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 ;; Make OVERLAY grow to contain range START to END.
11492
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
363 (if after
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
364 (move-overlay overlay
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
365 (min start (overlay-start overlay))
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
366 (max end (overlay-end overlay)))))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 ;;; Edit Buffer:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (defvar cpp-edit-map nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 ;; Keymap for `cpp-edit-mode'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (if cpp-edit-map
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (setq cpp-edit-map (make-keymap))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (suppress-keymap cpp-edit-map)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (define-key cpp-edit-map [ down-mouse-2 ] 'cpp-push-button)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (define-key cpp-edit-map [ mouse-2 ] 'ignore)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (define-key cpp-edit-map " " 'scroll-up)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (define-key cpp-edit-map "\C-?" 'scroll-down)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (define-key cpp-edit-map [ delete ] 'scroll-down)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (define-key cpp-edit-map "\C-c\C-c" 'cpp-edit-apply)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (define-key cpp-edit-map "a" 'cpp-edit-apply)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (define-key cpp-edit-map "A" 'cpp-edit-apply)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (define-key cpp-edit-map "r" 'cpp-edit-reset)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (define-key cpp-edit-map "R" 'cpp-edit-reset)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (define-key cpp-edit-map "s" 'cpp-edit-save)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (define-key cpp-edit-map "S" 'cpp-edit-save)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (define-key cpp-edit-map "l" 'cpp-edit-load)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (define-key cpp-edit-map "L" 'cpp-edit-load)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (define-key cpp-edit-map "h" 'cpp-edit-home)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (define-key cpp-edit-map "H" 'cpp-edit-home)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (define-key cpp-edit-map "b" 'cpp-edit-background)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (define-key cpp-edit-map "B" 'cpp-edit-background)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (define-key cpp-edit-map "k" 'cpp-edit-known)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (define-key cpp-edit-map "K" 'cpp-edit-known)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (define-key cpp-edit-map "u" 'cpp-edit-unknown)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (define-key cpp-edit-map "u" 'cpp-edit-unknown)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (define-key cpp-edit-map "t" 'cpp-edit-true)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (define-key cpp-edit-map "T" 'cpp-edit-true)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (define-key cpp-edit-map "f" 'cpp-edit-false)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (define-key cpp-edit-map "F" 'cpp-edit-false)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (define-key cpp-edit-map "w" 'cpp-edit-write)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (define-key cpp-edit-map "W" 'cpp-edit-write)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (define-key cpp-edit-map "X" 'cpp-edit-toggle-known)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (define-key cpp-edit-map "x" 'cpp-edit-toggle-known)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (define-key cpp-edit-map "Y" 'cpp-edit-toggle-unknown)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (define-key cpp-edit-map "y" 'cpp-edit-toggle-unknown)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (define-key cpp-edit-map "q" 'bury-buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (define-key cpp-edit-map "Q" 'bury-buffer))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (defvar cpp-edit-symbols nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 ;; Symbols defined in the edit buffer.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (make-variable-buffer-local 'cpp-edit-symbols)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (defun cpp-edit-mode ()
8741
9728aab0cab3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 8740
diff changeset
417 "Major mode for editing the criteria for highlighting cpp conditionals.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 Click on objects to change them.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 You can also use the keyboard accelerators indicated like this: [K]ey."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (kill-all-local-variables)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (buffer-disable-undo)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (auto-save-mode -1)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (setq buffer-read-only t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (setq major-mode 'cpp-edit-mode)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (setq mode-name "CPP Edit")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (use-local-map cpp-edit-map))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (defun cpp-edit-apply ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 "Apply edited display information to original buffer."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (cpp-edit-home)
11456
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
432 (cpp-highlight-buffer t))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (defun cpp-edit-reset ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 "Reset display information from original buffer."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (let ((buffer (current-buffer))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (buffer-read-only nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (start (window-start))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (pos (point))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 symbols)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (set-buffer cpp-edit-buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (setq symbols cpp-parse-symbols)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (set-buffer buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (setq cpp-edit-symbols symbols)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (erase-buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (insert "CPP Display Information for `")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (cpp-make-button (buffer-name cpp-edit-buffer) 'cpp-edit-home)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (insert "\n\nClick mouse-2 on item you want to change or use\n"
11456
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
450 "or switch to this buffer and type the keyboard equivalents.\n"
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
451 "Keyboard equivalents are indicated with brackets like [T]his.\n\n")
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
452 (cpp-make-button "[H]ome (display the C file)" 'cpp-edit-home)
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
453 (insert " ")
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
454 (cpp-make-button "[A]pply new settings" 'cpp-edit-apply)
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
455 (insert "\n")
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
456 (cpp-make-button "[S]ave settings" 'cpp-edit-save)
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
457 (insert " ")
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
458 (cpp-make-button "[L]oad settings" 'cpp-edit-load)
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
459 (insert "\n\n")
0950bf9c8d06 (cpp-parse-open): Delete comments that go past end of line.
Richard M. Stallman <rms@gnu.org>
parents: 8741
diff changeset
460
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (insert "[B]ackground: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (cpp-make-button (car (rassq cpp-face-type cpp-face-type-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 'cpp-edit-background)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (insert "\n[K]nown conditionals: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (cpp-make-button (cpp-face-name cpp-known-face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 'cpp-edit-known nil t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (insert " [X] ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (cpp-make-button (car (rassq cpp-known-writable cpp-writable-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 'cpp-edit-toggle-known)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (insert "\n[U]nknown conditionals: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (cpp-make-button (cpp-face-name cpp-unknown-face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 'cpp-edit-unknown nil t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (insert " [Y] ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (cpp-make-button (car (rassq cpp-unknown-writable cpp-writable-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 'cpp-edit-toggle-unknown)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (insert (format "\n\n\n%39s: %14s %14s %7s\n\n" "Expression"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 "[T]rue Face" "[F]alse Face" "[W]rite"))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (while symbols
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (let* ((symbol (car symbols))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (entry (assoc symbol cpp-edit-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (true (nth 1 entry))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (false (nth 2 entry))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (write (if entry (nth 3 entry) 'both)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (setq symbols (cdr symbols))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (if (and entry ; Make default entries unknown.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (or (null true) (eq true 'default))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (or (null false) (eq false 'default))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (eq write 'both))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (setq cpp-edit-list (delq entry cpp-edit-list)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 entry nil))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492
11492
2e09c796bf70 (cpp-edit-reset): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 11480
diff changeset
493 (if (> (length symbol) 39)
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (insert (substring symbol 0 39) ": ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (insert (format "%39s: " symbol)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (cpp-make-button (cpp-face-name true)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 'cpp-edit-true symbol t 14)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (insert " ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (cpp-make-button (cpp-face-name false)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 'cpp-edit-false symbol t 14)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (insert " ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (cpp-make-button (car (rassq write cpp-branch-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 'cpp-edit-write symbol nil 6)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (insert "\n")))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (insert "\n\n")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (set-window-start nil start)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (goto-char pos)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (defun cpp-edit-load ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 "Load cpp configuration."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (interactive)
13911
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
513 (cond ((file-readable-p cpp-config-file)
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
514 (load-file cpp-config-file))
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
515 ((file-readable-p (concat "~/" cpp-config-file))
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
516 (load-file cpp-config-file)))
8740
714588372e06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8736
diff changeset
517 (if (eq major-mode 'cpp-edit-mode)
714588372e06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 8736
diff changeset
518 (cpp-edit-reset)))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (defun cpp-edit-save ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 "Load cpp configuration."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (require 'pp)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (save-excursion
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (set-buffer cpp-edit-buffer)
13911
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
526 (let ((buffer (find-file-noselect cpp-config-file)))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (set-buffer buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (erase-buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (pp (list 'setq 'cpp-known-face
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (list 'quote cpp-known-face)) buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (pp (list 'setq 'cpp-unknown-face
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (list 'quote cpp-unknown-face)) buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (pp (list 'setq 'cpp-face-type
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (list 'quote cpp-face-type)) buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (pp (list 'setq 'cpp-known-writable
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (list 'quote cpp-known-writable)) buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (pp (list 'setq 'cpp-unknown-writable
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (list 'quote cpp-unknown-writable)) buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (pp (list 'setq 'cpp-edit-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (list 'quote cpp-edit-list)) buffer)
13911
3e9e8b468bc1 (cpp-config-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 11492
diff changeset
541 (write-file cpp-config-file))))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (defun cpp-edit-home ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 "Switch back to original buffer."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (if cpp-button-event
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (read-event))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (pop-to-buffer cpp-edit-buffer))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (defun cpp-edit-background ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 "Change default face collection."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (call-interactively 'cpp-choose-default-face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (cpp-edit-reset))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (defun cpp-edit-known ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 "Select default for known conditionals."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (setq cpp-known-face (cpp-choose-face "Known face" cpp-known-face))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (cpp-edit-reset))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (defun cpp-edit-unknown ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 "Select default for unknown conditionals."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (setq cpp-unknown-face (cpp-choose-face "Unknown face" cpp-unknown-face))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (cpp-edit-reset))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (defun cpp-edit-toggle-known (arg)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 "Toggle writable status for known conditionals.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 With optional argument ARG, make them writable iff ARG is positive."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (interactive "@P")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (if (or (and (null arg) cpp-known-writable)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (<= (prefix-numeric-value arg) 0))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (setq cpp-known-writable nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (setq cpp-known-writable t))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (cpp-edit-reset))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (defun cpp-edit-toggle-unknown (arg)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 "Toggle writable status for unknown conditionals.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 With optional argument ARG, make them writable iff ARG is positive."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (interactive "@P")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (if (or (and (null arg) cpp-unknown-writable)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 (<= (prefix-numeric-value arg) 0))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (setq cpp-unknown-writable nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 (setq cpp-unknown-writable t))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (cpp-edit-reset))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (defun cpp-edit-true (symbol face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 "Select SYMBOL's true FACE used for highlighting taken conditionals."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (interactive
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (let ((symbol (cpp-choose-symbol)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 (list symbol
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 (cpp-choose-face "True face"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (nth 1 (assoc symbol cpp-edit-list))))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (setcar (nthcdr 1 (cpp-edit-list-entry-get-or-create symbol)) face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (cpp-edit-reset))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (defun cpp-edit-false (symbol face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 "Select SYMBOL's false FACE used for highlighting untaken conditionals."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (interactive
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (let ((symbol (cpp-choose-symbol)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (list symbol
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (cpp-choose-face "False face"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (nth 2 (assoc symbol cpp-edit-list))))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (setcar (nthcdr 2 (cpp-edit-list-entry-get-or-create symbol)) face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (cpp-edit-reset))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (defun cpp-edit-write (symbol branch)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 "Set which branches of SYMBOL should be writable to BRANCH.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 BRANCH should be either nil (false branch), t (true branch) or 'both."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (interactive (list (cpp-choose-symbol) (cpp-choose-branch)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (setcar (nthcdr 3 (cpp-edit-list-entry-get-or-create symbol)) branch)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (cpp-edit-reset))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 (defun cpp-edit-list-entry-get-or-create (symbol)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 ;; Return the entry for SYMBOL in `cpp-edit-list'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 ;; If it does not exist, create it.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (let ((entry (assoc symbol cpp-edit-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (or entry
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 (setq entry (list symbol nil nil 'both nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 cpp-edit-list (cons entry cpp-edit-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 entry))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 ;;; Prompts:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 (defun cpp-choose-symbol ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 ;; Choose a symbol if called from keyboard, otherwise use the one clicked on.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (if cpp-button-event
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
629 cpp-callback-data
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (completing-read "Symbol: " (mapcar 'list cpp-edit-symbols) nil t)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (defun cpp-choose-branch ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 ;; Choose a branch, either nil, t, or both.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 (if cpp-button-event
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 (x-popup-menu cpp-button-event
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (list "Branch" (cons "Branch" cpp-branch-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 (cdr (assoc (completing-read "Branch: " cpp-branch-list nil t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 cpp-branch-list))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (defun cpp-choose-face (prompt default)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 ;; Choose a face from cpp-face-defalt-list.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 ;; PROMPT is what to say to the user.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 ;; DEFAULT is the default face.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (or (if cpp-button-event
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 (x-popup-menu cpp-button-event
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 (list prompt (cons prompt cpp-face-default-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 (let ((name (car (rassq default cpp-face-default-list))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 (cdr (assoc (completing-read (if name
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 (concat prompt
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 " (default " name "): ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 (concat prompt ": "))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 cpp-face-default-list nil t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 cpp-face-all-list))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 default))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (defun cpp-choose-default-face (type)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 ;; Choose default face list for screen of TYPE.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 ;; Type must be one of the types defined in `cpp-face-type-list'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (interactive (list (if cpp-button-event
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (x-popup-menu cpp-button-event
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (list "Screen type"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (cons "Screen type"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 cpp-face-type-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (cdr (assoc (completing-read "Screen type: "
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 cpp-face-type-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 nil t)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 cpp-face-type-list)))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 (cond ((null type))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 ((eq type 'light)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (if cpp-face-light-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 (setq cpp-face-light-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (mapcar 'cpp-create-bg-face cpp-face-light-name-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (setq cpp-face-all-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (append cpp-face-all-list cpp-face-light-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (setq cpp-face-type 'light)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (setq cpp-face-default-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 (append cpp-face-light-list cpp-face-none-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 ((eq type 'dark)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 (if cpp-face-dark-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (setq cpp-face-dark-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 (mapcar 'cpp-create-bg-face cpp-face-dark-name-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 (setq cpp-face-all-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 (append cpp-face-all-list cpp-face-dark-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (setq cpp-face-type 'dark)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 (setq cpp-face-default-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (append cpp-face-dark-list cpp-face-none-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 ((eq type 'mono)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (setq cpp-face-type 'mono)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 (setq cpp-face-default-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 (append cpp-face-mono-list cpp-face-none-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 (t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 (setq cpp-face-type 'none)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 (setq cpp-face-default-list cpp-face-none-list))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 ;;; Buttons:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (defun cpp-make-button (name callback &optional data face padding)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 ;; Create a button at point.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 ;; NAME is the name of the button.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 ;; CALLBACK is the function to call when the button is pushed.
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
703 ;; DATA will be made available to CALLBACK
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
704 ;;in the free variable cpp-callback-data.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 ;; FACE means that NAME is the name of a face in `cpp-face-all-list'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 ;; PADDING means NAME will be right justified at that length.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (let ((name (format "%s" name))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 from to)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (cond ((null padding)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (setq from (point))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (insert name))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 ((> (length name) padding)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (setq from (point))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (insert (substring name 0 padding)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (insert (make-string (- padding (length name)) ? ))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (setq from (point))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 (insert name)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (setq to (point))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 (setq face
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (if face
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 (let ((check (cdr (assoc name cpp-face-all-list))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (if (memq check '(default invisible))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 'bold
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 check))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 'bold))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 (add-text-properties from to
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (append (list 'face face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 '(mouse-face highlight)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 (list 'cpp-callback callback)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (if data (list 'cpp-data data))))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 (defun cpp-push-button (event)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 ;; Pushed a CPP button.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 (interactive "@e")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 (set-buffer (window-buffer (posn-window (event-start event))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (let ((pos (posn-point (event-start event))))
11480
5865f4bc9521 (cpp-edit-list): Move definition toward start of file.
Richard M. Stallman <rms@gnu.org>
parents: 11456
diff changeset
738 (let ((cpp-callback-data (get-text-property pos 'cpp-data))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 (fun (get-text-property pos 'cpp-callback))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 (cpp-button-event event))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 (cond (fun
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 (call-interactively (get-text-property pos 'cpp-callback)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 ((lookup-key global-map [ down-mouse-2])
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 (call-interactively (lookup-key global-map [ down-mouse-2])))))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 ;;; Faces:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 (defun cpp-create-bg-face (color)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 ;; Create entry for face with background COLOR.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 (let ((name (intern (concat "cpp " color))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 (make-face name)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 (set-face-background name color)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 (cons color name)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (cpp-choose-default-face (if window-system cpp-face-type 'none))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 (defun cpp-face-name (face)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 ;; Return the name of FACE from `cpp-face-all-list'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 (let ((entry (rassq (if face face 'default) cpp-face-all-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (if entry
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 (car entry)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (format "<%s>" face))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 ;;; Utilities:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 (defvar cpp-progress-time 0)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 ;; Last time we issued a progress message.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 (defun cpp-progress-message (&rest args)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770 ;; Report progress at most once a second. Take same ARGS as `message'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (let ((time (nth 1 (current-time))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (if (= time cpp-progress-time)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (setq cpp-progress-time time)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 (apply 'message args))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 (provide 'cpp)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 ;;; cpp.el ends here