aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorPaul Eggert2016-01-30 11:28:37 -0800
committerPaul Eggert2016-01-30 11:28:37 -0800
commit2b41d6a979b0ea361e078891b8763b4ae7be8092 (patch)
treeaef17169e9bf8e59baa82ec7df5c1b64139d9c9f /lisp
parentfe9c8b687c5121a413342024b62824a86d2de2be (diff)
parent71468e00735a44e19814a73e8f9013c0f272c342 (diff)
downloademacs-2b41d6a979b0ea361e078891b8763b4ae7be8092.tar.gz
emacs-2b41d6a979b0ea361e078891b8763b4ae7be8092.zip
-
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/cc-engine.el171
-rw-r--r--lisp/progmodes/cc-fonts.el93
-rw-r--r--lisp/textmodes/reftex-ref.el2
3 files changed, 169 insertions, 97 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index b08c555e34f..7d3f5282214 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -6802,6 +6802,110 @@ comment at the start of cc-engine.el for more info."
6802 ;; This identifier is bound only in the inner let. 6802 ;; This identifier is bound only in the inner let.
6803 '(setq start id-start)))) 6803 '(setq start id-start))))
6804 6804
6805(defun c-forward-declarator (&optional limit)
6806 ;; Assuming point is at the start of a declarator, move forward over it,
6807 ;; leaving point at the next token after it (e.g. a ) or a ; or a ,).
6808 ;;
6809 ;; Return a list (ID-START ID-END BRACKETS-AFTER-ID GOT-INIT), where ID-START and
6810 ;; ID-END are the bounds of the declarator's identifier, and
6811 ;; BRACKETS-AFTER-ID is non-nil if a [...] pair is present after the id.
6812 ;; GOT-INIT is non-nil when the declarator is followed by "=" or "(".
6813 ;;
6814 ;; If no declarator is found, leave point unmoved and return nil. LIMIT is
6815 ;; an optional limit for forward searching.
6816 ;;
6817 ;; Note that the global variable `c-last-identifier-range' is written to, so
6818 ;; the caller should bind it if necessary.
6819
6820 ;; Inside the following "condition form", we move forward over the
6821 ;; declarator's identifier up as far as any opening bracket (for array
6822 ;; size) or paren (for parameters of function-type) or brace (for
6823 ;; array/struct initialization) or "=" or terminating delimiter
6824 ;; (e.g. "," or ";" or "}").
6825 (let ((here (point))
6826 id-start id-end brackets-after-id paren-depth)
6827 (or limit (setq limit (point-max)))
6828 (if (and
6829 (< (point) limit)
6830
6831 ;; The following form moves forward over the declarator's
6832 ;; identifier (and what precedes it), returning t. If there
6833 ;; wasn't one, it returns nil.
6834 (let (got-identifier)
6835 (setq paren-depth 0)
6836 ;; Skip over type decl prefix operators, one for each iteration
6837 ;; of the while. These are, e.g. "*" in "int *foo" or "(" and
6838 ;; "*" in "int (*foo) (void)" (Note similar code in
6839 ;; `c-forward-decl-or-cast-1'.)
6840 (while (and (looking-at c-type-decl-prefix-key)
6841 (if (and (c-major-mode-is 'c++-mode)
6842 (match-beginning 3))
6843 ;; If the third submatch matches in C++ then
6844 ;; we're looking at an identifier that's a
6845 ;; prefix only if it specifies a member pointer.
6846 (progn
6847 (setq id-start (point))
6848 (c-forward-name)
6849 (if (looking-at "\\(::\\)")
6850 ;; We only check for a trailing "::" and
6851 ;; let the "*" that should follow be
6852 ;; matched in the next round.
6853 t
6854 ;; It turned out to be the real identifier,
6855 ;; so flag that and stop.
6856 (setq got-identifier t)
6857 nil))
6858 t))
6859 (if (eq (char-after) ?\()
6860 (progn
6861 (setq paren-depth (1+ paren-depth))
6862 (forward-char))
6863 (goto-char (match-end 1)))
6864 (c-forward-syntactic-ws))
6865
6866 ;; If we haven't passed the identifier already, do it now.
6867 (unless got-identifier
6868 (setq id-start (point))
6869 (c-forward-name))
6870 (prog1
6871 (/= (point) here)
6872 (save-excursion
6873 (c-backward-syntactic-ws)
6874 (setq id-end (point)))))
6875
6876 ;; Skip out of the parens surrounding the identifier. If closing
6877 ;; parens are missing, this form returns nil.
6878 (or (= paren-depth 0)
6879 (c-safe (goto-char (scan-lists (point) 1 paren-depth))))
6880
6881 (<= (point) limit)
6882
6883 ;; Skip over any trailing bit, such as "__attribute__".
6884 (progn
6885 (when (looking-at c-decl-hangon-key)
6886 (c-forward-keyword-clause 1))
6887 (<= (point) limit))
6888
6889 ;; Search syntactically to the end of the declarator (";",
6890 ;; ",", a closing paren, eob etc) or to the beginning of an
6891 ;; initializer or function prototype ("=" or "\\s\(").
6892 ;; Note that square brackets are now not also treated as
6893 ;; initializers, since this broke when there were also
6894 ;; initializing brace lists.
6895 (let (found)
6896 (while
6897 (and (setq found (c-syntactic-re-search-forward
6898 "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t))
6899 (eq (char-before) ?\[)
6900 (c-go-up-list-forward))
6901 (setq brackets-after-id t))
6902 (backward-char)
6903 found))
6904 (list id-start id-end brackets-after-id (match-beginning 1))
6905
6906 (goto-char here)
6907 nil)))
6908
6805(defun c-forward-decl-or-cast-1 (preceding-token-end context last-cast-end) 6909(defun c-forward-decl-or-cast-1 (preceding-token-end context last-cast-end)
6806 ;; Move forward over a declaration or a cast if at the start of one. 6910 ;; Move forward over a declaration or a cast if at the start of one.
6807 ;; The point is assumed to be at the start of some token. Nil is 6911 ;; The point is assumed to be at the start of some token. Nil is
@@ -8156,14 +8260,14 @@ comment at the start of cc-engine.el for more info."
8156 ;; Return the position of the first argument declaration if point is 8260 ;; Return the position of the first argument declaration if point is
8157 ;; inside a K&R style argument declaration list, nil otherwise. 8261 ;; inside a K&R style argument declaration list, nil otherwise.
8158 ;; `c-recognize-knr-p' is not checked. If LIM is non-nil, it's a 8262 ;; `c-recognize-knr-p' is not checked. If LIM is non-nil, it's a
8159 ;; position that bounds the backward search for the argument list. 8263 ;; position that bounds the backward search for the argument list. This
8264 ;; function doesn't move point.
8160 ;; 8265 ;;
8161 ;; Point must be within a possible K&R region, e.g. just before a top-level 8266 ;; Point must be within a possible K&R region, e.g. just before a top-level
8162 ;; "{". It must be outside of parens and brackets. The test can return 8267 ;; "{". It must be outside of parens and brackets. The test can return
8163 ;; false positives otherwise. 8268 ;; false positives otherwise.
8164 ;; 8269 ;;
8165 ;; This function might do hidden buffer changes. 8270 ;; This function might do hidden buffer changes.
8166
8167 (save-excursion 8271 (save-excursion
8168 (save-restriction 8272 (save-restriction
8169 ;; If we're in a macro, our search range is restricted to it. Narrow to 8273 ;; If we're in a macro, our search range is restricted to it. Narrow to
@@ -8172,8 +8276,12 @@ comment at the start of cc-engine.el for more info."
8172 (macro-end (save-excursion (and macro-start (c-end-of-macro) (point)))) 8276 (macro-end (save-excursion (and macro-start (c-end-of-macro) (point))))
8173 (low-lim (max (or lim (point-min)) (or macro-start (point-min)))) 8277 (low-lim (max (or lim (point-min)) (or macro-start (point-min))))
8174 before-lparen after-rparen 8278 before-lparen after-rparen
8175 (pp-count-out 20)) ; Max number of paren/brace constructs before 8279 (here (point))
8280 (pp-count-out 20) ; Max number of paren/brace constructs before
8176 ; we give up 8281 ; we give up
8282 ids ; List of identifiers in the parenthesised list.
8283 id-start after-prec-token decl-or-cast decl-res
8284 c-last-identifier-range identifier-ok)
8177 (narrow-to-region low-lim (or macro-end (point-max))) 8285 (narrow-to-region low-lim (or macro-end (point-max)))
8178 8286
8179 ;; Search backwards for the defun's argument list. We give up if we 8287 ;; Search backwards for the defun's argument list. We give up if we
@@ -8192,8 +8300,12 @@ comment at the start of cc-engine.el for more info."
8192 ;; int foo (bar, baz, yuk) 8300 ;; int foo (bar, baz, yuk)
8193 ;; int bar [] ; 8301 ;; int bar [] ;
8194 ;; int (*baz) (my_type) ; 8302 ;; int (*baz) (my_type) ;
8195 ;; int (*) (void) (*yuk) (void) ; 8303 ;; int (*(* yuk) (void)) (void) ;
8196 ;; { 8304 ;; {
8305 ;;
8306 ;; Additionally, for a knr list to be recognized:
8307 ;; o - The identifier of each deeclarator up to and including the
8308 ;; one "near" point must be contained in the arg list.
8197 8309
8198 (catch 'knr 8310 (catch 'knr
8199 (while (> pp-count-out 0) ; go back one paren/bracket pair each time. 8311 (while (> pp-count-out 0) ; go back one paren/bracket pair each time.
@@ -8239,21 +8351,58 @@ comment at the start of cc-engine.el for more info."
8239 (goto-char before-lparen) 8351 (goto-char before-lparen)
8240 (c-forward-token-2) ; to first token inside parens 8352 (c-forward-token-2) ; to first token inside parens
8241 (and 8353 (and
8242 (c-on-identifier) 8354 (setq id-start (c-on-identifier)) ; Must be at least one.
8243 (c-forward-token-2)
8244 (catch 'id-list 8355 (catch 'id-list
8245 (while (eq (char-after) ?\,) 8356 (while
8357 (progn
8358 (forward-char)
8359 (c-end-of-current-token)
8360 (push (buffer-substring-no-properties id-start
8361 (point))
8362 ids)
8363 (c-forward-syntactic-ws)
8364 (eq (char-after) ?\,))
8246 (c-forward-token-2) 8365 (c-forward-token-2)
8247 (unless (c-on-identifier) (throw 'id-list nil)) 8366 (unless (setq id-start (c-on-identifier))
8248 (c-forward-token-2)) 8367 (throw 'id-list nil)))
8249 (eq (char-after) ?\)))))) 8368 (eq (char-after) ?\)))))
8250 8369
8370 ;; Are all the identifiers in the k&r list up to the
8371 ;; current one also in the argument list?
8372 (progn
8373 (forward-char) ; over the )
8374 (setq after-prec-token after-rparen)
8375 (c-forward-syntactic-ws)
8376 (while (and
8377 (or (consp (setq decl-or-cast
8378 (c-forward-decl-or-cast-1
8379 after-prec-token
8380 nil ; Or 'arglist ???
8381 nil)))
8382 (progn
8383 (goto-char after-prec-token)
8384 (c-forward-syntactic-ws)
8385 (setq identifier-ok (eq (char-after) ?{))
8386 nil))
8387 (eq (char-after) ?\;)
8388 (setq after-prec-token (1+ (point)))
8389 (goto-char (car decl-or-cast))
8390 (setq decl-res (c-forward-declarator))
8391 (setq identifier-ok
8392 (member (buffer-substring-no-properties
8393 (car decl-res) (cadr decl-res))
8394 ids))
8395 (progn
8396 (goto-char after-prec-token)
8397 (prog1 (< (point) here)
8398 (c-forward-syntactic-ws))))
8399 (setq identifier-ok nil))
8400 identifier-ok))
8251 ;; ...Yes. We've identified the function's argument list. 8401 ;; ...Yes. We've identified the function's argument list.
8252 (throw 'knr 8402 (throw 'knr
8253 (progn (goto-char after-rparen) 8403 (progn (goto-char after-rparen)
8254 (c-forward-syntactic-ws) 8404 (c-forward-syntactic-ws)
8255 (point))) 8405 (point)))
8256
8257 ;; ...No. The current parens aren't the function's arg list. 8406 ;; ...No. The current parens aren't the function's arg list.
8258 (goto-char before-lparen)) 8407 (goto-char before-lparen))
8259 8408
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 03e67a99515..1e101d12aac 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1006,6 +1006,7 @@ casts and declarations are fontified. Used on level 2 and higher."
1006 ;;(message "c-font-lock-declarators from %s to %s" (point) limit) 1006 ;;(message "c-font-lock-declarators from %s to %s" (point) limit)
1007 (c-fontify-types-and-refs 1007 (c-fontify-types-and-refs
1008 ((pos (point)) next-pos id-start id-end 1008 ((pos (point)) next-pos id-start id-end
1009 decl-res
1009 paren-depth 1010 paren-depth
1010 id-face got-init 1011 id-face got-init
1011 c-last-identifier-range 1012 c-last-identifier-range
@@ -1015,93 +1016,15 @@ casts and declarations are fontified. Used on level 2 and higher."
1015 ;; The following `while' fontifies a single declarator id each time round. 1016 ;; The following `while' fontifies a single declarator id each time round.
1016 ;; It loops only when LIST is non-nil. 1017 ;; It loops only when LIST is non-nil.
1017 (while 1018 (while
1018 ;; Inside the following "condition form", we move forward over the 1019 (and pos (setq decl-res (c-forward-declarator limit)))
1019 ;; declarator's identifier up as far as any opening bracket (for array 1020 (setq next-pos (point)
1020 ;; size) or paren (for parameters of function-type) or brace (for 1021 id-start (car decl-res)
1021 ;; array/struct initialization) or "=" or terminating delimiter 1022 id-face (if (and (eq (char-after) ?\()
1022 ;; (e.g. "," or ";" or "}"). 1023 (not (car (cddr decl-res)))) ; brackets-after-id
1023 (and
1024 pos
1025 (< (point) limit)
1026
1027 ;; The following form moves forward over the declarator's
1028 ;; identifier (and what precedes it), returning t. If there
1029 ;; wasn't one, it returns nil, terminating the `while'.
1030 (let (got-identifier)
1031 (setq paren-depth 0)
1032 ;; Skip over type decl prefix operators, one for each iteration
1033 ;; of the while. These are, e.g. "*" in "int *foo" or "(" and
1034 ;; "*" in "int (*foo) (void)" (Note similar code in
1035 ;; `c-forward-decl-or-cast-1'.)
1036 (while (and (looking-at c-type-decl-prefix-key)
1037 (if (and (c-major-mode-is 'c++-mode)
1038 (match-beginning 3))
1039 ;; If the third submatch matches in C++ then
1040 ;; we're looking at an identifier that's a
1041 ;; prefix only if it specifies a member pointer.
1042 (progn
1043 (setq id-start (point))
1044 (c-forward-name)
1045 (if (looking-at "\\(::\\)")
1046 ;; We only check for a trailing "::" and
1047 ;; let the "*" that should follow be
1048 ;; matched in the next round.
1049 t
1050 ;; It turned out to be the real identifier,
1051 ;; so flag that and stop.
1052 (setq got-identifier t)
1053 nil))
1054 t))
1055 (if (eq (char-after) ?\()
1056 (progn
1057 (setq paren-depth (1+ paren-depth))
1058 (forward-char))
1059 (goto-char (match-end 1)))
1060 (c-forward-syntactic-ws))
1061
1062 ;; If we haven't passed the identifier already, do it now.
1063 (unless got-identifier
1064 (setq id-start (point))
1065 (c-forward-name))
1066 (setq id-end (point))
1067
1068 (/= id-end pos))
1069
1070 ;; Skip out of the parens surrounding the identifier. If closing
1071 ;; parens are missing, this form returns nil.
1072 (or (= paren-depth 0)
1073 (c-safe (goto-char (scan-lists (point) 1 paren-depth))))
1074
1075 (<= (point) limit)
1076
1077 ;; Skip over any trailing bit, such as "__attribute__".
1078 (progn
1079 (when (looking-at c-decl-hangon-key)
1080 (c-forward-keyword-clause 1))
1081 (<= (point) limit))
1082
1083 ;; Search syntactically to the end of the declarator (";",
1084 ;; ",", a closing paren, eob etc) or to the beginning of an
1085 ;; initializer or function prototype ("=" or "\\s(").
1086 ;; Note that square brackets are now not also treated as
1087 ;; initializers, since this broke when there were also
1088 ;; initializing brace lists.
1089 (let (found)
1090 (while
1091 (and (setq found (c-syntactic-re-search-forward
1092 "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t))
1093 (eq (char-before) ?\[)
1094 (c-go-up-list-forward))
1095 (setq brackets-after-id t))
1096 found))
1097
1098 (setq next-pos (match-beginning 0)
1099 id-face (if (and (eq (char-after next-pos) ?\()
1100 (not brackets-after-id))
1101 'font-lock-function-name-face 1024 'font-lock-function-name-face
1102 'font-lock-variable-name-face) 1025 'font-lock-variable-name-face)
1103 got-init (and (match-beginning 1) 1026 got-init (and (cadr (cddr decl-res)) ; got-init
1104 (char-after (match-beginning 1)))) 1027 (char-after)))
1105 1028
1106 (if types 1029 (if types
1107 ;; Register and fontify the identifier as a type. 1030 ;; Register and fontify the identifier as a type.
diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el
index 7f13ed5b06d..f5a784bf63d 100644
--- a/lisp/textmodes/reftex-ref.el
+++ b/lisp/textmodes/reftex-ref.el
@@ -228,7 +228,7 @@ This function is controlled by the settings of reftex-insert-label-flags."
228 (symbol-value reftex-docstruct-symbol))) 228 (symbol-value reftex-docstruct-symbol)))
229 (ding) 229 (ding)
230 (if (y-or-n-p 230 (if (y-or-n-p
231` (format-message "Label `%s' exists. Use anyway? " label)) 231 (format-message "Label `%s' exists. Use anyway? " label))
232 (setq valid t))) 232 (setq valid t)))
233 233
234 ;; Label is ok 234 ;; Label is ok