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