48 |
|
|
49 |
;; Silence the compiler. |
;; Silence the compiler. |
50 |
(cc-bytecomp-defvar c-enable-xemacs-performance-kludge-p) ; In cc-vars.el |
(cc-bytecomp-defvar c-enable-xemacs-performance-kludge-p) ; In cc-vars.el |
|
(cc-bytecomp-defvar c-emacs-features) ; In cc-vars.el |
|
51 |
(cc-bytecomp-defun buffer-syntactic-context-depth) ; XEmacs |
(cc-bytecomp-defun buffer-syntactic-context-depth) ; XEmacs |
52 |
(cc-bytecomp-defun region-active-p) ; XEmacs |
(cc-bytecomp-defun region-active-p) ; XEmacs |
53 |
(cc-bytecomp-defvar zmacs-region-stays) ; XEmacs |
(cc-bytecomp-defvar zmacs-region-stays) ; XEmacs |
104 |
|
|
105 |
;;; Variables also used at compile time. |
;;; Variables also used at compile time. |
106 |
|
|
107 |
(defconst c-version "5.30.8" |
(defconst c-version "5.30.9" |
108 |
"CC Mode version number.") |
"CC Mode version number.") |
109 |
|
|
110 |
(defconst c-version-sym (intern c-version)) |
(defconst c-version-sym (intern c-version)) |
619 |
(eq (char-before) ?\\))) |
(eq (char-before) ?\\))) |
620 |
(backward-char)))) |
(backward-char)))) |
621 |
|
|
622 |
|
(eval-and-compile |
623 |
|
(defvar c-langs-are-parametric nil)) |
624 |
|
|
625 |
(defmacro c-major-mode-is (mode) |
(defmacro c-major-mode-is (mode) |
626 |
"Return non-nil if the current CC Mode major mode is MODE. |
"Return non-nil if the current CC Mode major mode is MODE. |
627 |
MODE is either a mode symbol or a list of mode symbols. |
MODE is either a mode symbol or a list of mode symbols. |
628 |
|
|
629 |
This function does not do any hidden buffer changes." |
This function does not do any hidden buffer changes." |
630 |
(if (eq (car-safe mode) 'quote) |
|
631 |
(let ((mode (eval mode))) |
(if c-langs-are-parametric |
632 |
(if (listp mode) |
;; Inside a `c-lang-defconst'. |
633 |
`(memq c-buffer-is-cc-mode ',mode) |
`(c-lang-major-mode-is ,mode) |
634 |
`(eq c-buffer-is-cc-mode ',mode))) |
|
635 |
`(let ((mode ,mode)) |
(if (eq (car-safe mode) 'quote) |
636 |
(if (listp mode) |
(let ((mode (eval mode))) |
637 |
(memq c-buffer-is-cc-mode mode) |
(if (listp mode) |
638 |
(eq c-buffer-is-cc-mode mode))))) |
`(memq c-buffer-is-cc-mode ',mode) |
639 |
|
`(eq c-buffer-is-cc-mode ',mode))) |
640 |
|
|
641 |
|
`(let ((mode ,mode)) |
642 |
|
(if (listp mode) |
643 |
|
(memq c-buffer-is-cc-mode mode) |
644 |
|
(eq c-buffer-is-cc-mode mode)))))) |
645 |
|
|
646 |
|
(defmacro c-mode-is-new-awk-p () |
647 |
|
;; Is the current mode the "new" awk mode? It is important for |
648 |
|
;; (e.g.) the cc-engine functions do distinguish between the old and |
649 |
|
;; new awk-modes. |
650 |
|
'(and (c-major-mode-is 'awk-mode) |
651 |
|
(memq 'syntax-properties c-emacs-features))) |
652 |
|
|
653 |
(defmacro c-parse-sexp-lookup-properties () |
(defmacro c-parse-sexp-lookup-properties () |
654 |
;; Return the value of the variable that says whether the |
;; Return the value of the variable that says whether the |
983 |
This function does not do any hidden buffer changes." |
This function does not do any hidden buffer changes." |
984 |
(symbol-value (c-mode-symbol suffix))) |
(symbol-value (c-mode-symbol suffix))) |
985 |
|
|
|
(defsubst c-mode-is-new-awk-p () |
|
|
;; Is the current mode the "new" awk mode? It is important for |
|
|
;; (e.g.) the cc-engine functions do distinguish between the old and |
|
|
;; new awk-modes. |
|
|
(and (c-major-mode-is 'awk-mode) |
|
|
(memq 'syntax-properties c-emacs-features))) |
|
|
|
|
986 |
(defsubst c-got-face-at (pos faces) |
(defsubst c-got-face-at (pos faces) |
987 |
"Return non-nil if position POS in the current buffer has any of the |
"Return non-nil if position POS in the current buffer has any of the |
988 |
faces in the list FACES. |
faces in the list FACES. |
1065 |
(put 'c-make-keywords-re 'lisp-indent-function 1) |
(put 'c-make-keywords-re 'lisp-indent-function 1) |
1066 |
|
|
1067 |
|
|
1068 |
|
;; Figure out what features this Emacs has |
1069 |
|
|
1070 |
|
(cc-bytecomp-defvar open-paren-in-column-0-is-defun-start) |
1071 |
|
|
1072 |
|
(defconst c-emacs-features |
1073 |
|
(let (list) |
1074 |
|
|
1075 |
|
(if (boundp 'infodock-version) |
1076 |
|
;; I've no idea what this actually is, but it's legacy. /mast |
1077 |
|
(setq list (cons 'infodock list))) |
1078 |
|
|
1079 |
|
;; XEmacs 19 and beyond use 8-bit modify-syntax-entry flags. |
1080 |
|
;; Emacs 19 uses a 1-bit flag. We will have to set up our |
1081 |
|
;; syntax tables differently to handle this. |
1082 |
|
(let ((table (copy-syntax-table)) |
1083 |
|
entry) |
1084 |
|
(modify-syntax-entry ?a ". 12345678" table) |
1085 |
|
(cond |
1086 |
|
;; XEmacs 19, and beyond Emacs 19.34 |
1087 |
|
((arrayp table) |
1088 |
|
(setq entry (aref table ?a)) |
1089 |
|
;; In Emacs, table entries are cons cells |
1090 |
|
(if (consp entry) (setq entry (car entry)))) |
1091 |
|
;; XEmacs 20 |
1092 |
|
((fboundp 'get-char-table) (setq entry (get-char-table ?a table))) |
1093 |
|
;; before and including Emacs 19.34 |
1094 |
|
((and (fboundp 'char-table-p) |
1095 |
|
(char-table-p table)) |
1096 |
|
(setq entry (car (char-table-range table [?a])))) |
1097 |
|
;; incompatible |
1098 |
|
(t (error "CC Mode is incompatible with this version of Emacs"))) |
1099 |
|
(setq list (cons (if (= (logand (lsh entry -16) 255) 255) |
1100 |
|
'8-bit |
1101 |
|
'1-bit) |
1102 |
|
list))) |
1103 |
|
|
1104 |
|
(let ((buf (generate-new-buffer " test")) |
1105 |
|
parse-sexp-lookup-properties |
1106 |
|
parse-sexp-ignore-comments |
1107 |
|
lookup-syntax-properties) |
1108 |
|
(save-excursion |
1109 |
|
(set-buffer buf) |
1110 |
|
(set-syntax-table (make-syntax-table)) |
1111 |
|
|
1112 |
|
;; For some reason we have to set some of these after the |
1113 |
|
;; buffer has been made current. (Specifically, |
1114 |
|
;; `parse-sexp-ignore-comments' in Emacs 21.) |
1115 |
|
(setq parse-sexp-lookup-properties t |
1116 |
|
parse-sexp-ignore-comments t |
1117 |
|
lookup-syntax-properties t) |
1118 |
|
|
1119 |
|
;; Find out if the `syntax-table' text property works. |
1120 |
|
(modify-syntax-entry ?< ".") |
1121 |
|
(modify-syntax-entry ?> ".") |
1122 |
|
(insert "<()>") |
1123 |
|
(c-mark-<-as-paren 1) |
1124 |
|
(c-mark->-as-paren 4) |
1125 |
|
(goto-char 1) |
1126 |
|
(c-forward-sexp) |
1127 |
|
(if (= (point) 5) |
1128 |
|
(setq list (cons 'syntax-properties list))) |
1129 |
|
|
1130 |
|
;; Find out if generic comment delimiters work. |
1131 |
|
(c-safe |
1132 |
|
(modify-syntax-entry ?x "!") |
1133 |
|
(if (string-match "\\s!" "x") |
1134 |
|
(setq list (cons 'gen-comment-delim list)))) |
1135 |
|
|
1136 |
|
;; Find out if generic string delimiters work. |
1137 |
|
(c-safe |
1138 |
|
(modify-syntax-entry ?x "|") |
1139 |
|
(if (string-match "\\s|" "x") |
1140 |
|
(setq list (cons 'gen-string-delim list)))) |
1141 |
|
|
1142 |
|
;; See if POSIX char classes work. |
1143 |
|
(when (and (string-match "[[:alpha:]]" "a") |
1144 |
|
;; All versions of Emacs 21 so far haven't fixed |
1145 |
|
;; char classes in `skip-chars-forward' and |
1146 |
|
;; `skip-chars-backward'. |
1147 |
|
(progn |
1148 |
|
(delete-region (point-min) (point-max)) |
1149 |
|
(insert "foo123") |
1150 |
|
(skip-chars-backward "[:alnum:]") |
1151 |
|
(bobp)) |
1152 |
|
(= (skip-chars-forward "[:alpha:]") 3)) |
1153 |
|
(setq list (cons 'posix-char-classes list))) |
1154 |
|
|
1155 |
|
;; See if `open-paren-in-column-0-is-defun-start' exists and |
1156 |
|
;; isn't buggy. |
1157 |
|
(when (boundp 'open-paren-in-column-0-is-defun-start) |
1158 |
|
(let ((open-paren-in-column-0-is-defun-start nil) |
1159 |
|
(parse-sexp-ignore-comments t)) |
1160 |
|
(delete-region (point-min) (point-max)) |
1161 |
|
(set-syntax-table (make-syntax-table)) |
1162 |
|
(modify-syntax-entry ?\' "\"") |
1163 |
|
(cond |
1164 |
|
;; XEmacs. Afaik this is currently an Emacs-only |
1165 |
|
;; feature, but it's good to be prepared. |
1166 |
|
((memq '8-bit list) |
1167 |
|
(modify-syntax-entry ?/ ". 1456") |
1168 |
|
(modify-syntax-entry ?* ". 23")) |
1169 |
|
;; Emacs |
1170 |
|
((memq '1-bit list) |
1171 |
|
(modify-syntax-entry ?/ ". 124b") |
1172 |
|
(modify-syntax-entry ?* ". 23"))) |
1173 |
|
(modify-syntax-entry ?\n "> b") |
1174 |
|
(insert "/* '\n () */") |
1175 |
|
(backward-sexp) |
1176 |
|
(if (bobp) |
1177 |
|
(setq list (cons 'col-0-paren list))))) |
1178 |
|
|
1179 |
|
(set-buffer-modified-p nil)) |
1180 |
|
(kill-buffer buf)) |
1181 |
|
|
1182 |
|
;; See if `parse-partial-sexp' returns the eighth element. |
1183 |
|
(when (c-safe (>= (length (save-excursion (parse-partial-sexp 1 1))) 10)) |
1184 |
|
(setq list (cons 'pps-extended-state list))) |
1185 |
|
|
1186 |
|
;;(message "c-emacs-features: %S" list) |
1187 |
|
list) |
1188 |
|
"A list of certain features in the (X)Emacs you are using. |
1189 |
|
There are many flavors of Emacs out there, each with different |
1190 |
|
features supporting those needed by CC Mode. The following values |
1191 |
|
might be present: |
1192 |
|
|
1193 |
|
'8-bit 8 bit syntax entry flags (XEmacs style). |
1194 |
|
'1-bit 1 bit syntax entry flags (Emacs style). |
1195 |
|
'syntax-properties It works to override the syntax for specific characters |
1196 |
|
in the buffer with the 'syntax-table property. |
1197 |
|
'gen-comment-delim Generic comment delimiters work |
1198 |
|
(i.e. the syntax class `!'). |
1199 |
|
'gen-string-delim Generic string delimiters work |
1200 |
|
(i.e. the syntax class `|'). |
1201 |
|
'pps-extended-state `parse-partial-sexp' returns a list with at least 10 |
1202 |
|
elements, i.e. it contains the position of the |
1203 |
|
start of the last comment or string. |
1204 |
|
'posix-char-classes The regexp engine understands POSIX character classes. |
1205 |
|
'col-0-paren It's possible to turn off the ad-hoc rule that a paren |
1206 |
|
in column zero is the start of a defun. |
1207 |
|
'infodock This is Infodock (based on XEmacs). |
1208 |
|
|
1209 |
|
'8-bit and '1-bit are mutually exclusive.") |
1210 |
|
|
1211 |
|
|
1212 |
;;; Some helper constants. |
;;; Some helper constants. |
1213 |
|
|
1214 |
;; If the regexp engine supports POSIX char classes (e.g. Emacs 21) |
;; If the regexp engine supports POSIX char classes then we can use |
1215 |
;; then we can use them to handle extended charsets correctly. |
;; them to handle extended charsets correctly. |
1216 |
(if (string-match "[[:alpha:]]" "a") ; Can't use c-emacs-features here. |
(if (memq 'posix-char-classes c-emacs-features) |
1217 |
(progn |
(progn |
1218 |
(defconst c-alpha "[:alpha:]") |
(defconst c-alpha "[:alpha:]") |
1219 |
(defconst c-alnum "[:alnum:]") |
(defconst c-alnum "[:alnum:]") |
1279 |
(error "The mode name symbol `%s' must end with \"-mode\"" mode)) |
(error "The mode name symbol `%s' must end with \"-mode\"" mode)) |
1280 |
(put mode 'c-mode-prefix (match-string 1 (symbol-name mode))) |
(put mode 'c-mode-prefix (match-string 1 (symbol-name mode))) |
1281 |
(unless (get base-mode 'c-mode-prefix) |
(unless (get base-mode 'c-mode-prefix) |
1282 |
(error "Unknown base mode `%s'" base-mode) |
(error "Unknown base mode `%s'" base-mode)) |
1283 |
(put mode 'c-fallback-mode base-mode))) |
(put mode 'c-fallback-mode base-mode)) |
1284 |
|
|
1285 |
(defvar c-lang-constants (make-vector 151 0)) |
(defvar c-lang-constants (make-vector 151 0)) |
1286 |
;; This obarray is a cache to keep track of the language constants |
;; This obarray is a cache to keep track of the language constants |
1296 |
;; various other symbols, but those don't have any variable bindings. |
;; various other symbols, but those don't have any variable bindings. |
1297 |
|
|
1298 |
(defvar c-lang-const-expansion nil) |
(defvar c-lang-const-expansion nil) |
|
(defvar c-langs-are-parametric nil) |
|
1299 |
|
|
1300 |
(defsubst c-get-current-file () |
(defsubst c-get-current-file () |
1301 |
;; Return the base name of the current file. |
;; Return the base name of the current file. |
1736 |
|
|
1737 |
c-lang-constants))) |
c-lang-constants))) |
1738 |
|
|
1739 |
|
(defun c-lang-major-mode-is (mode) |
1740 |
|
;; `c-major-mode-is' expands to a call to this function inside |
1741 |
|
;; `c-lang-defconst'. Here we also match the mode(s) against any |
1742 |
|
;; fallback modes for the one in `c-buffer-is-cc-mode', so that |
1743 |
|
;; e.g. (c-major-mode-is 'c++-mode) is true in a derived language |
1744 |
|
;; that has c++-mode as base mode. |
1745 |
|
(unless (listp mode) |
1746 |
|
(setq mode (list mode))) |
1747 |
|
(let (match (buf-mode c-buffer-is-cc-mode)) |
1748 |
|
(while (if (memq buf-mode mode) |
1749 |
|
(progn |
1750 |
|
(setq match t) |
1751 |
|
nil) |
1752 |
|
(setq buf-mode (get buf-mode 'c-fallback-mode)))) |
1753 |
|
match)) |
1754 |
|
|
1755 |
|
|
1756 |
(cc-provide 'cc-defs) |
(cc-provide 'cc-defs) |
1757 |
|
|