aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/cpp.el
diff options
context:
space:
mode:
authorRichard M. Stallman1995-04-18 07:21:52 +0000
committerRichard M. Stallman1995-04-18 07:21:52 +0000
commit2e922f0b7a6e26c380269bc8a44d0eff913b5439 (patch)
tree53e12c7bd01469c7513e15fbeb2f364aea267570 /lisp/progmodes/cpp.el
parent2596511d21a1388c88e0c4993a963679853b4116 (diff)
downloademacs-2e922f0b7a6e26c380269bc8a44d0eff913b5439.tar.gz
emacs-2e922f0b7a6e26c380269bc8a44d0eff913b5439.zip
(cpp-edit-list): Move definition toward start of file.
(cpp-face-type-list, cpp-writable-list, cpp-button-event) (cpp-edit-buffer, cpp-branch-list, cpp-face-default-list) (cpp-face-light-name-list, cpp-face-dark-name-list) (cpp-face-light-list, cpp-face-dark-list, cpp-face-mono-list) (cpp-face-none-list, cpp-face-all-list, cpp-overlay-list): Likewise. (cpp-highlight-buffer): Rename stack to cpp-state-stack. (cpp-parse-open, cpp-parse-close): Likewise. (cpp-push-button, cpp-choose-symbol): Rename data to cpp-callback-data. (cpp-state-stack, cpp-callback-data): Add defvars.
Diffstat (limited to 'lisp/progmodes/cpp.el')
-rw-r--r--lisp/progmodes/cpp.el199
1 files changed, 102 insertions, 97 deletions
diff --git a/lisp/progmodes/cpp.el b/lisp/progmodes/cpp.el
index fecb15193dc..2320a775462 100644
--- a/lisp/progmodes/cpp.el
+++ b/lisp/progmodes/cpp.el
@@ -1,6 +1,6 @@
1;;; cpp.el --- Highlight or hide text according to cpp conditionals. 1;;; cpp.el --- Highlight or hide text according to cpp conditionals.
2 2
3;; Copyright (C) 1994 Free Software Foundation 3;; Copyright (C) 1994, 1995 Free Software Foundation
4 4
5;; Author: Per Abrahamsen <abraham@iesd.auc.dk> 5;; Author: Per Abrahamsen <abraham@iesd.auc.dk>
6;; Keywords: c, faces, tools 6;; Keywords: c, faces, tools
@@ -64,6 +64,86 @@ screens, and none if you don't use a window system.")
64(defvar cpp-unknown-writable t 64(defvar cpp-unknown-writable t
65 "*Non-nil means you are allowed to modify the unknown conditionals.") 65 "*Non-nil means you are allowed to modify the unknown conditionals.")
66 66
67(defvar cpp-edit-list nil
68 "Alist of cpp macros and information about how they should be displayed.
69Each entry is a list with the following elements:
700. The name of the macro (a string).
711. Face used for text that is `ifdef' the macro.
722. Face used for text that is `ifndef' the macro.
733. `t', `nil', or `both' depending on what text may be edited.")
74
75(defvar cpp-overlay-list nil)
76;; List of cpp overlays active in the current buffer.
77(make-variable-buffer-local 'cpp-overlay-list)
78
79(defvar cpp-callback-data)
80(defvar cpp-state-stack)
81
82(defconst cpp-face-type-list
83 '(("light color background" . light)
84 ("dark color background" . dark)
85 ("monochrome" . mono)
86 ("tty" . none))
87 "Alist of strings and names of the defined face collections.")
88
89(defconst cpp-writable-list
90 ;; Names used for the writable property.
91 '(("writable" . t)
92 ("read-only" . nil)))
93
94(defvar cpp-button-event nil)
95;; This will be t in the callback for `cpp-make-button'.
96
97(defvar cpp-edit-buffer nil)
98;; Real buffer whose cpp display information we are editing.
99(make-variable-buffer-local 'cpp-edit-buffer)
100
101(defconst cpp-branch-list
102 ;; Alist of branches.
103 '(("false" . nil)
104 ("true" . t)
105 ("both" . both)))
106
107(defvar cpp-face-default-list nil
108 "List of faces you can choose from for cpp conditionals.")
109
110(defvar cpp-face-light-name-list
111 '("light gray" "light blue" "light cyan" "light yellow" "light pink"
112 "pale green" "beige" "orange" "magenta" "violet" "medium purple"
113 "turquoise")
114 "Background colours useful with dark foreground colors.")
115
116(defvar cpp-face-dark-name-list
117 '("dim gray" "blue" "cyan" "yellow" "red"
118 "dark green" "brown" "dark orange" "dark khaki" "dark violet" "purple"
119 "dark turquoise")
120 "Background colours useful with light foreground colors.")
121
122(defvar cpp-face-light-list nil
123 "Alist of names and faces to be used for light backgrounds.")
124
125(defvar cpp-face-dark-list nil
126 "Alist of names and faces to be used for dark backgrounds.")
127
128(defvar cpp-face-mono-list
129 '(("bold" . 'bold)
130 ("bold-italic" . 'bold-italic)
131 ("italic" . 'italic)
132 ("underline" . 'underline))
133 "Alist of names and faces to be used for monocrome screens.")
134
135(defvar cpp-face-none-list
136 '(("default" . default)
137 ("invisible" . invisible))
138 "Alist of names and faces available even if you don't use a window system.")
139
140(defvar cpp-face-all-list
141 (append cpp-face-light-list
142 cpp-face-dark-list
143 cpp-face-mono-list
144 cpp-face-none-list)
145 "All faces used for highligting text inside cpp conditionals.")
146
67;;; Parse Buffer: 147;;; Parse Buffer:
68 148
69(defvar cpp-parse-symbols nil 149(defvar cpp-parse-symbols nil
@@ -88,7 +168,7 @@ A prefix arg suppresses display of that buffer."
88 (cpp-parse-reset) 168 (cpp-parse-reset)
89 (if (null cpp-edit-list) 169 (if (null cpp-edit-list)
90 (cpp-edit-load)) 170 (cpp-edit-load))
91 (let (stack) 171 (let (cpp-state-stack)
92 (save-excursion 172 (save-excursion
93 (goto-char (point-min)) 173 (goto-char (point-min))
94 (cpp-progress-message "Parsing...") 174 (cpp-progress-message "Parsing...")
@@ -126,27 +206,28 @@ A prefix arg suppresses display of that buffer."
126 (cpp-parse-close from to)) 206 (cpp-parse-close from to))
127 (cpp-parse-open t expr from to)) 207 (cpp-parse-open t expr from to))
128 ((string-equal type "else") 208 ((string-equal type "else")
129 (or stack (cpp-parse-error "Top level #else")) 209 (or cpp-state-stack
130 (let ((entry (list (not (nth 0 (car stack))) 210 (cpp-parse-error "Top level #else"))
131 (nth 1 (car stack)) 211 (let ((entry (list (not (nth 0 (car cpp-state-stack)))
212 (nth 1 (car cpp-state-stack))
132 from to))) 213 from to)))
133 (cpp-parse-close from to) 214 (cpp-parse-close from to)
134 (setq stack (cons entry stack)))) 215 (setq cpp-state-stack (cons entry cpp-state-stack))))
135 ((string-equal type "endif") 216 ((string-equal type "endif")
136 (cpp-parse-close from to)) 217 (cpp-parse-close from to))
137 (t 218 (t
138 (cpp-parse-error "Parser error")))))))) 219 (cpp-parse-error "Parser error"))))))))
139 (message "Parsing...done")) 220 (message "Parsing...done"))
140 (if stack 221 (if cpp-state-stack
141 (save-excursion 222 (save-excursion
142 (goto-char (nth 3 (car stack))) 223 (goto-char (nth 3 (car cpp-state-stack)))
143 (cpp-parse-error "Unclosed conditional")))) 224 (cpp-parse-error "Unclosed conditional"))))
144 (or arg 225 (or arg
145 (null cpp-parse-symbols) 226 (null cpp-parse-symbols)
146 (cpp-parse-edit))) 227 (cpp-parse-edit)))
147 228
148(defun cpp-parse-open (branch expr begin end) 229(defun cpp-parse-open (branch expr begin end)
149 "Push information about conditional-beginning onto stack." 230 "Push information about conditional-beginning onto `cpp-state-stack'."
150 ;; Discard comments within this line. 231 ;; Discard comments within this line.
151 (while (string-match "\\b[ \t]*/\\*.*\\*/[ \t]*\\b" expr) 232 (while (string-match "\\b[ \t]*/\\*.*\\*/[ \t]*\\b" expr)
152 (setq expr (concat (substring expr 0 (match-beginning 0)) 233 (setq expr (concat (substring expr 0 (match-beginning 0))
@@ -160,7 +241,7 @@ A prefix arg suppresses display of that buffer."
160 (while (string-match "[ \t]+" expr) 241 (while (string-match "[ \t]+" expr)
161 (setq expr (concat (substring expr 0 (match-beginning 0)) 242 (setq expr (concat (substring expr 0 (match-beginning 0))
162 (substring expr (match-end 0))))) 243 (substring expr (match-end 0)))))
163 (setq stack (cons (list branch expr begin end) stack)) 244 (setq cpp-state-stack (cons (list branch expr begin end) cpp-state-stack))
164 (or (member expr cpp-parse-symbols) 245 (or (member expr cpp-parse-symbols)
165 (setq cpp-parse-symbols 246 (setq cpp-parse-symbols
166 (cons expr cpp-parse-symbols))) 247 (cons expr cpp-parse-symbols)))
@@ -169,16 +250,16 @@ A prefix arg suppresses display of that buffer."
169 (cpp-make-unknown-overlay begin end))) 250 (cpp-make-unknown-overlay begin end)))
170 251
171(defun cpp-parse-close (from to) 252(defun cpp-parse-close (from to)
172 ;; Pop top of stack and create overlay. 253 ;; Pop top of cpp-state-stack and create overlay.
173 (let ((entry (assoc (nth 1 (car stack)) cpp-edit-list)) 254 (let ((entry (assoc (nth 1 (car cpp-state-stack)) cpp-edit-list))
174 (branch (nth 0 (car stack))) 255 (branch (nth 0 (car cpp-state-stack)))
175 (begin (nth 2 (car stack))) 256 (begin (nth 2 (car cpp-state-stack)))
176 (end (nth 3 (car stack)))) 257 (end (nth 3 (car cpp-state-stack))))
177 (setq stack (cdr stack)) 258 (setq cpp-state-stack (cdr cpp-state-stack))
178 (if entry 259 (if entry
179 (let ((face (nth (if branch 1 2) entry)) 260 (let ((face (nth (if branch 1 2) entry))
180 (read-only (eq (not branch) (nth 3 entry))) 261 (read-only (eq (not branch) (nth 3 entry)))
181 (priority (length stack)) 262 (priority (length cpp-state-stack))
182 (overlay (make-overlay end from))) 263 (overlay (make-overlay end from)))
183 (cpp-make-known-overlay from to) 264 (cpp-make-known-overlay from to)
184 (setq cpp-overlay-list (cons overlay cpp-overlay-list)) 265 (setq cpp-overlay-list (cons overlay cpp-overlay-list))
@@ -218,10 +299,6 @@ A prefix arg suppresses display of that buffer."
218 299
219;;; Overlays: 300;;; Overlays:
220 301
221(defvar cpp-overlay-list nil)
222;; List of cpp overlays active in the current buffer.
223(make-variable-buffer-local 'cpp-overlay-list)
224
225(defun cpp-make-known-overlay (start end) 302(defun cpp-make-known-overlay (start end)
226 ;; Create an overlay for a known cpp command from START to END. 303 ;; Create an overlay for a known cpp command from START to END.
227 (let ((overlay (make-overlay start end))) 304 (let ((overlay (make-overlay start end)))
@@ -283,14 +360,6 @@ A prefix arg suppresses display of that buffer."
283 360
284;;; Edit Buffer: 361;;; Edit Buffer:
285 362
286(defvar cpp-edit-list nil
287 "Alist of cpp macros and information about how they should be displayed.
288Each entry is a list with the following elements:
2890. The name of the macro (a string).
2901. Face used for text that is `ifdef' the macro.
2912. Face used for text that is `ifndef' the macro.
2923. `t', `nil', or `both' depending on what text may be edited.")
293
294(defvar cpp-edit-map nil) 363(defvar cpp-edit-map nil)
295;; Keymap for `cpp-edit-mode'. 364;; Keymap for `cpp-edit-mode'.
296 365
@@ -333,10 +402,6 @@ Each entry is a list with the following elements:
333 (define-key cpp-edit-map "q" 'bury-buffer) 402 (define-key cpp-edit-map "q" 'bury-buffer)
334 (define-key cpp-edit-map "Q" 'bury-buffer)) 403 (define-key cpp-edit-map "Q" 'bury-buffer))
335 404
336(defvar cpp-edit-buffer nil)
337;; Real buffer whose cpp display information we are editing.
338(make-variable-buffer-local 'cpp-edit-buffer)
339
340(defvar cpp-edit-symbols nil) 405(defvar cpp-edit-symbols nil)
341;; Symbols defined in the edit buffer. 406;; Symbols defined in the edit buffer.
342(make-variable-buffer-local 'cpp-edit-symbols) 407(make-variable-buffer-local 'cpp-edit-symbols)
@@ -493,11 +558,6 @@ You can also use the keyboard accelerators indicated like this: [K]ey."
493 (setq cpp-unknown-face (cpp-choose-face "Unknown face" cpp-unknown-face)) 558 (setq cpp-unknown-face (cpp-choose-face "Unknown face" cpp-unknown-face))
494 (cpp-edit-reset)) 559 (cpp-edit-reset))
495 560
496(defconst cpp-writable-list
497 ;; Names used for the writable property.
498 '(("writable" . t)
499 ("read-only" . nil)))
500
501(defun cpp-edit-toggle-known (arg) 561(defun cpp-edit-toggle-known (arg)
502 "Toggle writable status for known conditionals. 562 "Toggle writable status for known conditionals.
503With optional argument ARG, make them writable iff ARG is positive." 563With optional argument ARG, make them writable iff ARG is positive."
@@ -559,15 +619,9 @@ BRANCH should be either nil (false branch), t (true branch) or 'both."
559(defun cpp-choose-symbol () 619(defun cpp-choose-symbol ()
560 ;; Choose a symbol if called from keyboard, otherwise use the one clicked on. 620 ;; Choose a symbol if called from keyboard, otherwise use the one clicked on.
561 (if cpp-button-event 621 (if cpp-button-event
562 data 622 cpp-callback-data
563 (completing-read "Symbol: " (mapcar 'list cpp-edit-symbols) nil t))) 623 (completing-read "Symbol: " (mapcar 'list cpp-edit-symbols) nil t)))
564 624
565(defconst cpp-branch-list
566 ;; Alist of branches.
567 '(("false" . nil)
568 ("true" . t)
569 ("both" . both)))
570
571(defun cpp-choose-branch () 625(defun cpp-choose-branch ()
572 ;; Choose a branch, either nil, t, or both. 626 ;; Choose a branch, either nil, t, or both.
573 (if cpp-button-event 627 (if cpp-button-event
@@ -592,13 +646,6 @@ BRANCH should be either nil (false branch), t (true branch) or 'both."
592 cpp-face-all-list)))) 646 cpp-face-all-list))))
593 default)) 647 default))
594 648
595(defconst cpp-face-type-list
596 '(("light color background" . light)
597 ("dark color background" . dark)
598 ("monochrome" . mono)
599 ("tty" . none))
600 "Alist of strings and names of the defined face collections.")
601
602(defun cpp-choose-default-face (type) 649(defun cpp-choose-default-face (type)
603 ;; Choose default face list for screen of TYPE. 650 ;; Choose default face list for screen of TYPE.
604 ;; Type must be one of the types defined in `cpp-face-type-list'. 651 ;; Type must be one of the types defined in `cpp-face-type-list'.
@@ -642,14 +689,12 @@ BRANCH should be either nil (false branch), t (true branch) or 'both."
642 689
643;;; Buttons: 690;;; Buttons:
644 691
645(defvar cpp-button-event nil)
646;; This will be t in the callback for `cpp-make-button'.
647
648(defun cpp-make-button (name callback &optional data face padding) 692(defun cpp-make-button (name callback &optional data face padding)
649 ;; Create a button at point. 693 ;; Create a button at point.
650 ;; NAME is the name of the button. 694 ;; NAME is the name of the button.
651 ;; CALLBACK is the function to call when the button is pushed. 695 ;; CALLBACK is the function to call when the button is pushed.
652 ;; DATA will be available to CALLBACK as a free variable. 696 ;; DATA will be made available to CALLBACK
697 ;;in the free variable cpp-callback-data.
653 ;; FACE means that NAME is the name of a face in `cpp-face-all-list'. 698 ;; FACE means that NAME is the name of a face in `cpp-face-all-list'.
654 ;; PADDING means NAME will be right justified at that length. 699 ;; PADDING means NAME will be right justified at that length.
655 (let ((name (format "%s" name)) 700 (let ((name (format "%s" name))
@@ -683,7 +728,7 @@ BRANCH should be either nil (false branch), t (true branch) or 'both."
683 (interactive "@e") 728 (interactive "@e")
684 (set-buffer (window-buffer (posn-window (event-start event)))) 729 (set-buffer (window-buffer (posn-window (event-start event))))
685 (let ((pos (posn-point (event-start event)))) 730 (let ((pos (posn-point (event-start event))))
686 (let ((data (get-text-property pos 'cpp-data)) 731 (let ((cpp-callback-data (get-text-property pos 'cpp-data))
687 (fun (get-text-property pos 'cpp-callback)) 732 (fun (get-text-property pos 'cpp-callback))
688 (cpp-button-event event)) 733 (cpp-button-event event))
689 (cond (fun 734 (cond (fun
@@ -693,46 +738,6 @@ BRANCH should be either nil (false branch), t (true branch) or 'both."
693 738
694;;; Faces: 739;;; Faces:
695 740
696(defvar cpp-face-light-name-list
697 '("light gray" "light blue" "light cyan" "light yellow" "light pink"
698 "pale green" "beige" "orange" "magenta" "violet" "medium purple"
699 "turquoise")
700 "Background colours useful with dark foreground colors.")
701
702(defvar cpp-face-dark-name-list
703 '("dim gray" "blue" "cyan" "yellow" "red"
704 "dark green" "brown" "dark orange" "dark khaki" "dark violet" "purple"
705 "dark turquoise")
706 "Background colours useful with light foreground colors.")
707
708(defvar cpp-face-light-list nil
709 "Alist of names and faces to be used for light backgrounds.")
710
711(defvar cpp-face-dark-list nil
712 "Alist of names and faces to be used for dark backgrounds.")
713
714(defvar cpp-face-mono-list
715 '(("bold" . 'bold)
716 ("bold-italic" . 'bold-italic)
717 ("italic" . 'italic)
718 ("underline" . 'underline))
719 "Alist of names and faces to be used for monocrome screens.")
720
721(defvar cpp-face-none-list
722 '(("default" . default)
723 ("invisible" . invisible))
724 "Alist of names and faces available even if you don't use a window system.")
725
726(defvar cpp-face-all-list
727 (append cpp-face-light-list
728 cpp-face-dark-list
729 cpp-face-mono-list
730 cpp-face-none-list)
731 "All faces used for highligting text inside cpp conditionals.")
732
733(defvar cpp-face-default-list nil
734 "List of faces you can choose from for cpp conditionals.")
735
736(defun cpp-create-bg-face (color) 741(defun cpp-create-bg-face (color)
737 ;; Create entry for face with background COLOR. 742 ;; Create entry for face with background COLOR.
738 (let ((name (intern (concat "cpp " color)))) 743 (let ((name (intern (concat "cpp " color))))