annotate lisp/progmodes/cpp.el @ 9114:9853955949cf

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