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