/[emacs]/emacs/lisp/progmodes/cc-engine.el
ViewVC logotype

Diff of /emacs/lisp/progmodes/cc-engine.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.36 by mast, Wed Sep 24 13:55:23 2003 UTC revision 1.37 by mast, Sun Nov 16 16:55:07 2003 UTC
# Line 197  Line 197 
197  (make-variable-buffer-local 'c-type-decl-end-used)  (make-variable-buffer-local 'c-type-decl-end-used)
198    
199    
200    ;; Basic handling of preprocessor directives.
201    
202    ;; This is a dynamically bound cache used together with
203    ;; `c-query-macro-start' and `c-query-and-set-macro-start'.  It only
204    ;; works as long as point doesn't cross a macro boundary.
205    (defvar c-macro-start 'unknown)
206    
207    (defsubst c-query-and-set-macro-start ()
208      ;; This function does not do any hidden buffer changes.
209      (if (symbolp c-macro-start)
210          (setq c-macro-start (save-excursion
211                                (and (c-beginning-of-macro)
212                                     (point))))
213        c-macro-start))
214    
215    (defsubst c-query-macro-start ()
216      ;; This function does not do any hidden buffer changes.
217      (if (symbolp c-macro-start)
218          (save-excursion
219            (and (c-beginning-of-macro)
220                 (point)))
221        c-macro-start))
222    
223    (defun c-beginning-of-macro (&optional lim)
224      "Go to the beginning of a preprocessor directive.
225    Leave point at the beginning of the directive and return t if in one,
226    otherwise return nil and leave point unchanged.
227    
228    This function does not do any hidden buffer changes."
229      (when c-opt-cpp-prefix
230        (let ((here (point)))
231          (save-restriction
232            (if lim (narrow-to-region lim (point-max)))
233            (beginning-of-line)
234            (while (eq (char-before (1- (point))) ?\\)
235              (forward-line -1))
236            (back-to-indentation)
237            (if (and (<= (point) here)
238                     (looking-at c-opt-cpp-start))
239                t
240              (goto-char here)
241              nil)))))
242    
243    (defun c-end-of-macro ()
244      "Go to the end of a preprocessor directive.
245    More accurately, move point to the end of the closest following line
246    that doesn't end with a line continuation backslash.
247    
248    This function does not do any hidden buffer changes."
249      (while (progn
250               (end-of-line)
251               (when (and (eq (char-before) ?\\)
252                          (not (eobp)))
253                 (forward-char)
254                 t))))
255    
256    (defun c-forward-to-cpp-define-body ()
257      ;; Assuming point is at the "#" that introduces a preprocessor
258      ;; directive, it's moved forward to the start of the definition body
259      ;; if it's a "#define".  Non-nil is returned in this case, in all
260      ;; other cases nil is returned and point isn't moved.
261      (when (and (looking-at
262                  (concat "#[ \t]*"
263                          "define[ \t]+\\(\\sw\\|_\\)+\\(\([^\)]*\)\\)?"
264                          "\\([ \t]\\|\\\\\n\\)*"))
265                 (not (= (match-end 0) (c-point 'eol))))
266        (goto-char (match-end 0))))
267    
268    
269  ;;; Basic utility functions.  ;;; Basic utility functions.
270    
271  (defun c-syntactic-content (from to)  (defun c-syntactic-content (from to)
# Line 268  Line 337 
337  (defvar c-literal-faces  (defvar c-literal-faces
338    '(font-lock-comment-face font-lock-string-face))    '(font-lock-comment-face font-lock-string-face))
339    
340    (defun c-shift-line-indentation (shift-amt)
341      ;; This function does not do any hidden buffer changes.
342      (let ((pos (- (point-max) (point)))
343            (c-macro-start c-macro-start)
344            tmp-char-inserted)
345        (if (zerop shift-amt)
346            nil
347          (when (and (c-query-and-set-macro-start)
348                     (looking-at "[ \t]*\\\\$")
349                     (save-excursion
350                       (skip-chars-backward " \t")
351                       (bolp)))
352            (insert ?x)
353            (backward-char)
354            (setq tmp-char-inserted t))
355          (unwind-protect
356              (let ((col (current-indentation)))
357                (delete-region (c-point 'bol) (c-point 'boi))
358                (beginning-of-line)
359                (indent-to (+ col shift-amt)))
360            (when tmp-char-inserted
361              (delete-char 1))))
362        ;; If initial point was within line's indentation and we're not on
363        ;; a line with a line continuation in a macro, position after the
364        ;; indentation.  Else stay at same point in text.
365        (if (and (< (point) (c-point 'boi))
366                 (not tmp-char-inserted))
367            (back-to-indentation)
368          (if (> (- (point-max) pos) (point))
369              (goto-char (- (point-max) pos))))))
370    
371    
372  ;; Some debug tools to visualize various special positions.  This  ;; Some debug tools to visualize various special positions.  This
373  ;; debug code isn't as portable as the rest of CC Mode.  ;; debug code isn't as portable as the rest of CC Mode.
# Line 592  COMMA-DELIM is non-nil then ',' is treat Line 692  COMMA-DELIM is non-nil then ',' is treat
692    
693                  ;; The PDA state handling.                  ;; The PDA state handling.
694                  ;;                  ;;
695                  ;; Refer to the description of the PDA in the openining                  ;; Refer to the description of the PDA in the opening
696                  ;; comments.  In the following OR form, the first leaf                  ;; comments.  In the following OR form, the first leaf
697                  ;; attempts to handles one of the specific actions detailed                  ;; attempts to handles one of the specific actions detailed
698                  ;; (e.g., finding token "if" whilst in state `else-boundary').                  ;; (e.g., finding token "if" whilst in state `else-boundary').
# Line 769  COMMA-DELIM is non-nil then ',' is treat Line 869  COMMA-DELIM is non-nil then ',' is treat
869                          sym 'boundary)                          sym 'boundary)
870                    (throw 'loop t))) ; like a C "continue".  Analyze the next sexp.                    (throw 'loop t))) ; like a C "continue".  Analyze the next sexp.
871    
872                (when (and (numberp c-maybe-labelp) (not ignore-labels))                (when (and (numberp c-maybe-labelp)
873                             (not ignore-labels)
874                             (not (looking-at "\\s\(")))
875                  ;; c-crosses-statement-barrier-p has found a colon, so                  ;; c-crosses-statement-barrier-p has found a colon, so
876                  ;; we might be in a label now.                  ;; we might be in a label now.
877                  (if (not after-labels-pos)                  (if (not after-labels-pos)
# Line 1012  This function does not do any hidden buf Line 1114  This function does not do any hidden buf
1114                  t))))))                  t))))))
1115    
1116    
 ;; Basic handling of preprocessor directives.  
   
 ;; This is a dynamically bound cache used together with  
 ;; `c-query-macro-start' and `c-query-and-set-macro-start'.  It only  
 ;; works as long as point doesn't cross a macro boundary.  
 (defvar c-macro-start 'unknown)  
   
 (defsubst c-query-and-set-macro-start ()  
   ;; This function does not do any hidden buffer changes.  
   (if (symbolp c-macro-start)  
       (setq c-macro-start (save-excursion  
                             (and (c-beginning-of-macro)  
                                  (point))))  
     c-macro-start))  
   
 (defsubst c-query-macro-start ()  
   ;; This function does not do any hidden buffer changes.  
   (if (symbolp c-macro-start)  
       (save-excursion  
         (and (c-beginning-of-macro)  
              (point)))  
     c-macro-start))  
   
 (defun c-beginning-of-macro (&optional lim)  
   "Go to the beginning of a preprocessor directive.  
 Leave point at the beginning of the directive and return t if in one,  
 otherwise return nil and leave point unchanged.  
   
 This function does not do any hidden buffer changes."  
   (when c-opt-cpp-prefix  
     (let ((here (point)))  
       (save-restriction  
         (if lim (narrow-to-region lim (point-max)))  
         (beginning-of-line)  
         (while (eq (char-before (1- (point))) ?\\)  
           (forward-line -1))  
         (back-to-indentation)  
         (if (and (<= (point) here)  
                  (looking-at c-opt-cpp-start))  
             t  
           (goto-char here)  
           nil)))))  
   
 (defun c-end-of-macro ()  
   "Go to the end of a preprocessor directive.  
 More accurately, move point to the end of the closest following line  
 that doesn't end with a line continuation backslash.  
   
 This function does not do any hidden buffer changes."  
   (while (progn  
            (end-of-line)  
            (when (and (eq (char-before) ?\\)  
                       (not (eobp)))  
              (forward-char)  
              t))))  
   
 (defun c-forward-to-cpp-define-body ()  
   ;; Assuming point is at the "#" that introduces a preprocessor  
   ;; directive, it's moved forward to the start of the definition body  
   ;; if it's a "#define".  Non-nil is returned in this case, in all  
   ;; other cases nil is returned and point isn't moved.  
   (when (and (looking-at  
               (concat "#[ \t]*"  
                       "define[ \t]+\\(\\sw\\|_\\)+\\(\([^\)]*\)\\)?"  
                       "\\([ \t]\\|\\\\\n\\)*"))  
              (not (= (match-end 0) (c-point 'eol))))  
     (goto-char (match-end 0))))  
   
   
1117  ;; Tools for skipping over syntactic whitespace.  ;; Tools for skipping over syntactic whitespace.
1118    
1119  ;; The following functions use text properties to cache searches over  ;; The following functions use text properties to cache searches over
# Line 2451  syntactic whitespace." Line 2484  syntactic whitespace."
2484                            (< check-pos                            (< check-pos
2485                               (save-excursion                               (save-excursion
2486                                 (goto-char check-pos)                                 (goto-char check-pos)
2487                                 (c-end-of-current-token last-token-end-pos)                                 (save-match-data
2488                                     (c-end-of-current-token last-token-end-pos))
2489                                 (setq last-token-end-pos (point))))))                                 (setq last-token-end-pos (point))))))
2490                   ;; Match inside a token.                   ;; Match inside a token.
2491                   (cond ((<= (point) bound)                   (cond ((<= (point) bound)
# Line 2516  syntactic whitespace." Line 2550  syntactic whitespace."
2550  i.e. don't stop at positions inside syntactic whitespace or string  i.e. don't stop at positions inside syntactic whitespace or string
2551  literals.  Preprocessor directives are also ignored, with the exception  literals.  Preprocessor directives are also ignored, with the exception
2552  of the one that the point starts within, if any.  If LIMIT is given,  of the one that the point starts within, if any.  If LIMIT is given,
2553  it's assumed to be at a syntactically relevant position.  it's assumed to be at a syntactically relevant position."
   
 This function does not do any hidden buffer changes."  
2554    
2555    (let ((start (point))    (let ((start (point))
2556          ;; A list of syntactically relevant positions in descending          ;; A list of syntactically relevant positions in descending
# Line 3351  This function does not do any hidden buf Line 3383  This function does not do any hidden buf
3383  (defvar c-promote-possible-types nil)  (defvar c-promote-possible-types nil)
3384    
3385  ;; Dynamically bound variable that instructs `c-forward-<>-arglist' to  ;; Dynamically bound variable that instructs `c-forward-<>-arglist' to
3386  ;; not accept arglists that contain more than one argument.  It's used  ;; not accept arglists that contain binary operators.
3387  ;; to handle ambiguous cases like "foo (a < b, c > d)" better.  ;;
3388  (defvar c-disallow-comma-in-<>-arglists nil)  ;; This is primarily used to handle C++ template arglists.  C++
3389    ;; disambiguates them by checking whether the preceding name is a
3390    ;; template or not.  We can't do that, so we assume it is a template
3391    ;; if it can be parsed as one.  That usually works well since
3392    ;; comparison expressions on the forms "a < b > c" or "a < b, c > d"
3393    ;; in almost all cases would be pointless.
3394    ;;
3395    ;; However, in function arglists, e.g. in "foo (a < b, c > d)", we
3396    ;; should let the comma separate the function arguments instead.  And
3397    ;; in a context where the value of the expression is taken, e.g. in
3398    ;; "if (a < b || c > d)", it's probably not a template.
3399    (defvar c-restricted-<>-arglists nil)
3400    
3401  ;; Dynamically bound variables that instructs `c-forward-name',  ;; Dynamically bound variables that instructs `c-forward-name',
3402  ;; `c-forward-type' and `c-forward-<>-arglist' to record the ranges of  ;; `c-forward-type' and `c-forward-<>-arglist' to record the ranges of
# Line 3494  This function does not do any hidden buf Line 3537  This function does not do any hidden buf
3537               (eq (char-after) ?<)               (eq (char-after) ?<)
3538               (c-forward-<>-arglist (c-keyword-member kwd-sym 'c-<>-type-kwds)               (c-forward-<>-arglist (c-keyword-member kwd-sym 'c-<>-type-kwds)
3539                                     (or c-record-type-identifiers                                     (or c-record-type-identifiers
3540                                         c-disallow-comma-in-<>-arglists)))                                         c-restricted-<>-arglists)))
3541          (c-forward-syntactic-ws)          (c-forward-syntactic-ws)
3542          (setq safe-pos (point)))          (setq safe-pos (point)))
3543    
# Line 3543  This function does not do any hidden buf Line 3586  This function does not do any hidden buf
3586    ;; necessary if the various side effects, e.g. recording of type    ;; necessary if the various side effects, e.g. recording of type
3587    ;; ranges, are important.  Setting REPARSE to t only applies    ;; ranges, are important.  Setting REPARSE to t only applies
3588    ;; recursively to nested angle bracket arglists if    ;; recursively to nested angle bracket arglists if
3589    ;; `c-disallow-comma-in-<>-arglists' is set.    ;; `c-restricted-<>-arglists' is set.
   ;;  
   ;; This is primarily used in C++ to mark up template arglists.  C++  
   ;; disambiguates them by checking whether the preceding name is a  
   ;; template or not.  We can't do that, so we assume it is a template  
   ;; if it can be parsed as one.  This usually works well since  
   ;; comparison expressions on the forms "a < b > c" or "a < b, c > d"  
   ;; in almost all cases would be pointless.  Cases like function  
   ;; calls on the form "foo (a < b, c > d)" needs to be handled  
   ;; specially through the `c-disallow-comma-in-<>-arglists' variable.  
3590    
3591    (let ((start (point))    (let ((start (point))
3592          ;; If `c-record-type-identifiers' is set then activate          ;; If `c-record-type-identifiers' is set then activate
# Line 3683  This function does not do any hidden buf Line 3717  This function does not do any hidden buf
3717                          (forward-char)                          (forward-char)
3718                          t)                          t)
3719    
3720                        ;; Note: This regexp exploits the match order in                        ;; Note: These regexps exploit the match order in \| so
3721                        ;; \| so that "<>" is matched by "<" rather than                        ;; that "<>" is matched by "<" rather than "[^>:-]>".
                       ;; "[^>:-]>".  
3722                        (c-syntactic-re-search-forward                        (c-syntactic-re-search-forward
3723                         "[<;{},]\\|\\([^>:-]>\\)" nil 'move t t 1)                         (if c-restricted-<>-arglists
3724                               ;; Stop on ',', '|', '&', '+' and '-' to catch
3725                               ;; common binary operators that could be between
3726                               ;; two comparison expressions "a<b" and "c>d".
3727                               "[<;{},|&+-]\\|\\([^>:-]>\\)"
3728                             ;; Otherwise we still stop on ',' to find the
3729                             ;; argument start positions.
3730                             "[<;{},]\\|\\([^>:-]>\\)")
3731                           nil 'move t t 1)
3732    
3733                        ;; If the arglist starter has lost its open paren                        ;; If the arglist starter has lost its open paren
3734                        ;; syntax but not the closer, we won't find the                        ;; syntax but not the closer, we won't find the
# Line 3776  This function does not do any hidden buf Line 3817  This function does not do any hidden buf
3817                                             (c-keyword-sym (match-string 1))                                             (c-keyword-sym (match-string 1))
3818                                             'c-<>-type-kwds))                                             'c-<>-type-kwds))
3819                                       (and reparse                                       (and reparse
3820                                            c-disallow-comma-in-<>-arglists))))                                            c-restricted-<>-arglists))))
3821                              )))                              )))
3822    
3823                          ;; It was not an angle bracket arglist.                          ;; It was not an angle bracket arglist.
# Line 3812  This function does not do any hidden buf Line 3853  This function does not do any hidden buf
3853                    t)                    t)
3854    
3855                   ((and (eq (char-before) ?,)                   ((and (eq (char-before) ?,)
3856                         (not c-disallow-comma-in-<>-arglists))                         (not c-restricted-<>-arglists))
3857                    ;; Just another argument.  Record the position.  The                    ;; Just another argument.  Record the position.  The
3858                    ;; type check stuff that made us stop at it is at                    ;; type check stuff that made us stop at it is at
3859                    ;; the top of the loop.                    ;; the top of the loop.
# Line 3959  This function does not do any hidden buf Line 4000  This function does not do any hidden buf
4000                 (when (let ((c-record-type-identifiers nil)                 (when (let ((c-record-type-identifiers nil)
4001                             (c-record-found-types nil))                             (c-record-found-types nil))
4002                         (c-forward-<>-arglist                         (c-forward-<>-arglist
4003                          nil c-disallow-comma-in-<>-arglists))                          nil c-restricted-<>-arglists))
4004                   (c-forward-syntactic-ws)                   (c-forward-syntactic-ws)
4005                   (setq pos (point))                   (setq pos (point))
4006                   (if (and c-opt-identifier-concat-key                   (if (and c-opt-identifier-concat-key
# Line 4202  This function does not do any hidden buf Line 4243  This function does not do any hidden buf
4243      (c-with-syntax-table c++-template-syntax-table      (c-with-syntax-table c++-template-syntax-table
4244        (c-backward-token-2 0 t lim)        (c-backward-token-2 0 t lim)
4245        (while (and (or (looking-at c-symbol-start)        (while (and (or (looking-at c-symbol-start)
4246                        (looking-at "[<,]"))                        (looking-at "[<,]\\|::"))
4247                    (zerop (c-backward-token-2 1 t lim))))                    (zerop (c-backward-token-2 1 t lim))))
4248        (skip-chars-forward "^:"))))        (skip-chars-forward "^:"))))
4249    
# Line 4326  brace." Line 4367  brace."
4367    ;; position that bounds the backward search for the argument list.    ;; position that bounds the backward search for the argument list.
4368    ;;    ;;
4369    ;; Note: A declaration level context is assumed; the test can return    ;; Note: A declaration level context is assumed; the test can return
4370    ;; false positives for statements.  This test is even more easily    ;; false positives for statements.
   ;; fooled than `c-just-after-func-arglist-p'.  
4371    
4372    (save-excursion    (save-excursion
4373      (save-restriction      (save-restriction
# Line 4337  brace." Line 4377  brace."
4377        ;; check that it's followed by some symbol before the next ';'        ;; check that it's followed by some symbol before the next ';'
4378        ;; or '{'.  If it does, it's the header of the K&R argdecl we're        ;; or '{'.  If it does, it's the header of the K&R argdecl we're
4379        ;; in.        ;; in.
4380        (if lim (narrow-to-region lim (point)))        (if lim (narrow-to-region lim (c-point 'eol)))
4381        (let ((outside-macro (not (c-query-macro-start)))        (let ((outside-macro (not (c-query-macro-start)))
4382              paren-end)              paren-end)
4383    
4384          (catch 'done          (catch 'done
4385            (while (if (and (c-safe (setq paren-end            (while (if (and (setq paren-end (c-down-list-backward (point)))
                                         (c-down-list-backward (point))))  
4386                            (eq (char-after paren-end) ?\)))                            (eq (char-after paren-end) ?\)))
4387                       (progn                       (progn
4388                         (goto-char (1+ paren-end))                         (goto-char (1+ paren-end))
# Line 4354  brace." Line 4393  brace."
4393          (and (progn          (and (progn
4394                 (c-forward-syntactic-ws)                 (c-forward-syntactic-ws)
4395                 (looking-at "\\w\\|\\s_"))                 (looking-at "\\w\\|\\s_"))
4396               (c-safe (c-up-list-backward paren-end))  
4397                 (save-excursion
4398                   ;; The function header in a K&R declaration should only
4399                   ;; contain identifiers separated by comma.  It should
4400                   ;; also contain at least one identifier since there
4401                   ;; wouldn't be anything to declare in the K&R region
4402                   ;; otherwise.
4403                   (when (c-go-up-list-backward paren-end)
4404                     (forward-char)
4405                     (catch 'knr-ok
4406                       (while t
4407                         (c-forward-syntactic-ws)
4408                         (if (or (looking-at c-known-type-key)
4409                                 (looking-at c-keywords-regexp))
4410                             (throw 'knr-ok nil))
4411                         (c-forward-token-2)
4412                         (if (eq (char-after) ?,)
4413                             (forward-char)
4414                           (throw 'knr-ok (and (eq (char-after) ?\))
4415                                               (= (point) paren-end))))))))
4416    
4417               (save-excursion               (save-excursion
4418                 ;; If it's a K&R declaration then we're now at the                 ;; If it's a K&R declaration then we're now at the
# Line 4405  brace." Line 4463  brace."
4463        (if start        (if start
4464            (goto-char start)))))            (goto-char start)))))
4465    
4466  (defun c-backward-to-decl-anchor (&optional lim)  (defsubst c-backward-to-decl-anchor (&optional lim)
4467    ;; Assuming point is at a brace that opens the block of a top level    ;; Assuming point is at a brace that opens the block of a top level
4468    ;; declaration of some kind, move to the proper anchor point for    ;; declaration of some kind, move to the proper anchor point for
4469    ;; that block.    ;; that block.
4470    (unless (= (point) (c-point 'boi))    (unless (= (point) (c-point 'boi))
4471      ;; What we have below is actually an extremely stripped variant of      (c-beginning-of-statement-1 lim)))
     ;; c-beginning-of-statement-1.  
     (let ((pos (point)) c-maybe-labelp)  
       ;; Switch syntax table to avoid stopping at line continuations.  
       (save-restriction  
         (if lim (narrow-to-region lim (point-max)))  
         (while (and (progn  
                       (c-backward-syntactic-ws)  
                       (c-safe (goto-char (scan-sexps (point) -1)) t))  
                     (not (c-crosses-statement-barrier-p (point) pos))  
                     (not c-maybe-labelp))  
           (setq pos (point)))  
         (goto-char pos)))))  
4472    
4473  (defun c-search-decl-header-end ()  (defun c-search-decl-header-end ()
4474    ;; Search forward for the end of the "header" of the current    ;; Search forward for the end of the "header" of the current
# Line 4619  brace." Line 4665  brace."
4665        nil)))        nil)))
4666    
4667  (defun c-beginning-of-member-init-list (&optional limit)  (defun c-beginning-of-member-init-list (&optional limit)
4668    ;; Goes to the beginning of a member init list (i.e. just after the    ;; Go to the beginning of a member init list (i.e. just after the
4669    ;; ':') if inside one.  Returns t in that case, nil otherwise.    ;; ':') if inside one.  Returns t in that case, nil otherwise.
4670    (or limit    (or limit
4671        (setq limit (point-min)))        (setq limit (point-min)))
# Line 5196  brace." Line 5242  brace."
5242                           (eq step-type 'label)                           (eq step-type 'label)
5243                           (/= savepos boi))                           (/= savepos boi))
5244    
5245                       (progn                       (let ((save-step-type step-type))
5246                         ;; Current position might not be good enough;                         ;; Current position might not be good enough;
5247                         ;; skip backward another statement.                         ;; skip backward another statement.
5248                         (setq step-type (c-beginning-of-statement-1                         (setq step-type (c-beginning-of-statement-1
# Line 5228  brace." Line 5274  brace."
5274                             (c-add-syntax 'substatement nil))                             (c-add-syntax 'substatement nil))
5275    
5276                           (setq boi (c-point 'boi))                           (setq boi (c-point 'boi))
5277                           (/= (point) savepos)))))                           (if (= (point) savepos)
5278                                 (progn
5279                                   (setq step-type save-step-type)
5280                                   nil)
5281                               t)))))
5282    
5283                  (setq savepos (point)                  (setq savepos (point)
5284                        at-comment nil))                        at-comment nil))
5285                (setq at-comment nil)                (setq at-comment nil)
5286    
5287                (when (and (eq step-type 'same)                (when (and containing-sexp
5288                           containing-sexp)                           (if (memq step-type '(nil same))
5289                                 (/= (point) boi)
5290                               (eq step-type 'label)))
5291                  (goto-char containing-sexp)                  (goto-char containing-sexp)
5292    
5293                  ;; Don't stop in the middle of a special brace list opener                  ;; Don't stop in the middle of a special brace list opener
# Line 5395  brace." Line 5447  brace."
5447    
5448         ;; CASE B.3: The body of a function declared inside a normal         ;; CASE B.3: The body of a function declared inside a normal
5449         ;; block.  Can occur e.g. in Pike and when using gcc         ;; block.  Can occur e.g. in Pike and when using gcc
5450         ;; extensions.  Might also trigger it with some macros followed         ;; extensions, but watch out for macros followed by blocks.
        ;; by blocks, and this gives sane indentation then too.  
5451         ;; C.f. cases E, 16F and 17G.         ;; C.f. cases E, 16F and 17G.
5452         ((and (not (c-looking-at-bos))         ((and (not (c-looking-at-bos))
5453               (eq (c-beginning-of-statement-1 containing-sexp nil nil t)               (eq (c-beginning-of-statement-1 containing-sexp nil nil t)
5454                   'same))                   'same)
5455                 (save-excursion
5456                   ;; Look for a type followed by a symbol, i.e. the start of a
5457                   ;; function declaration.  Doesn't work for declarations like
5458                   ;; "int *foo() ..."; we'd need to refactor the more competent
5459                   ;; analysis in `c-font-lock-declarations' for that.
5460                   (and (c-forward-type)
5461                        (progn
5462                          (c-forward-syntactic-ws)
5463                          (looking-at c-symbol-start)))))
5464          (c-add-stmt-syntax 'defun-open nil t nil          (c-add-stmt-syntax 'defun-open nil t nil
5465                             containing-sexp paren-state))                             containing-sexp paren-state))
5466    
5467         ;; CASE B.4: Continued statement with block open.         ;; CASE B.4: Continued statement with block open.  The most
5468           ;; accurate analysis is perhaps `statement-cont' together with
5469           ;; `block-open' but we play DWIM and use `substatement-open'
5470           ;; instead.  The rationaly is that this typically is a macro
5471           ;; followed by a block which makes it very similar to a
5472           ;; statement with a substatement block.
5473         (t         (t
5474          (goto-char beg-of-same-or-containing-stmt)          (c-add-stmt-syntax 'substatement-open nil nil nil
5475          (c-add-stmt-syntax 'statement-cont nil nil nil                             containing-sexp paren-state))
                            containing-sexp paren-state)  
         (c-add-syntax 'block-open))  
5476         ))         ))
5477    
5478       ;; CASE C: iostream insertion or extraction operator       ;; CASE C: iostream insertion or extraction operator
# Line 5428  brace." Line 5491  brace."
5491       ((and (save-excursion       ((and (save-excursion
5492               ;; Check that the next token is a '{'.  This works as               ;; Check that the next token is a '{'.  This works as
5493               ;; long as no language that allows nested function               ;; long as no language that allows nested function
5494               ;; definitions doesn't allow stuff like member init               ;; definitions allows stuff like member init lists, K&R
5495               ;; lists, K&R declarations or throws clauses there.               ;; declarations or throws clauses there.
5496               ;;               ;;
5497               ;; Note that we do a forward search for something ahead               ;; Note that we do a forward search for something ahead
5498               ;; of the indentation line here.  That's not good since               ;; of the indentation line here.  That's not good since
# Line 5440  brace." Line 5503  brace."
5503               (eq (char-after) ?{))               (eq (char-after) ?{))
5504             (not (c-looking-at-bos))             (not (c-looking-at-bos))
5505             (eq (c-beginning-of-statement-1 containing-sexp nil nil t)             (eq (c-beginning-of-statement-1 containing-sexp nil nil t)
5506                 'same))                 'same)
5507               (save-excursion
5508                 ;; Look for a type followed by a symbol, i.e. the start of a
5509                 ;; function declaration.  Doesn't work for declarations like "int
5510                 ;; *foo() ..."; we'd need to refactor the more competent analysis
5511                 ;; in `c-font-lock-declarations' for that.
5512                 (and (c-forward-type)
5513                      (progn
5514                        (c-forward-syntactic-ws)
5515                        (looking-at c-symbol-start)))))
5516        (c-add-stmt-syntax 'func-decl-cont nil t nil        (c-add-stmt-syntax 'func-decl-cont nil t nil
5517                           containing-sexp paren-state))                           containing-sexp paren-state))
5518    
# Line 5852  This function does not do any hidden buf Line 5924  This function does not do any hidden buf
5924                ;; should be relative to the ctor's indentation                ;; should be relative to the ctor's indentation
5925                )                )
5926               ;; CASE 5B.2: K&R arg decl intro               ;; CASE 5B.2: K&R arg decl intro
5927               (c-recognize-knr-p               ((and c-recognize-knr-p
5928                       (c-in-knr-argdecl lim))
5929                (c-beginning-of-statement-1 lim)                (c-beginning-of-statement-1 lim)
5930                (c-add-syntax 'knr-argdecl-intro (c-point 'boi))                (c-add-syntax 'knr-argdecl-intro (c-point 'boi))
5931                (if inclass-p                (if inclass-p
# Line 6493  This function does not do any hidden buf Line 6566  This function does not do any hidden buf
6566                  (c-add-syntax 'inline-close (point))))                  (c-add-syntax 'inline-close (point))))
6567               ;; CASE 16F: Can be a defun-close of a function declared               ;; CASE 16F: Can be a defun-close of a function declared
6568               ;; in a statement block, e.g. in Pike or when using gcc               ;; in a statement block, e.g. in Pike or when using gcc
6569               ;; extensions.  Might also trigger it with some macros               ;; extensions, but watch out for macros followed by
6570               ;; followed by blocks, and this gives sane indentation               ;; blocks.  Let it through to be handled below.
              ;; then too.  Let it through to be handled below.  
6571               ;; C.f. cases B.3 and 17G.               ;; C.f. cases B.3 and 17G.
6572               ((and (not inenclosing-p)               ((and (not inenclosing-p)
6573                     lim                     lim
6574                     (save-excursion                     (save-excursion
6575                       (and (not (c-looking-at-bos))                       (and (not (c-looking-at-bos))
6576                            (eq (c-beginning-of-statement-1 lim nil nil t) 'same)                            (eq (c-beginning-of-statement-1 lim nil nil t) 'same)
6577                            (setq placeholder (point)))))                            (setq placeholder (point))
6578                              ;; Look for a type or identifier followed by a
6579                              ;; symbol, i.e. the start of a function declaration.
6580                              ;; Doesn't work for declarations like "int *foo()
6581                              ;; ..."; we'd need to refactor the more competent
6582                              ;; analysis in `c-font-lock-declarations' for that.
6583                              (c-forward-type)
6584                              (progn
6585                                (c-forward-syntactic-ws)
6586                                (looking-at c-symbol-start)))))
6587                (back-to-indentation)                (back-to-indentation)
6588                (if (/= (point) containing-sexp)                (if (/= (point) containing-sexp)
6589                    (goto-char placeholder))                    (goto-char placeholder))
# Line 6627  This function does not do any hidden buf Line 6708  This function does not do any hidden buf
6708              (c-add-syntax 'defun-block-intro (point)))              (c-add-syntax 'defun-block-intro (point)))
6709             ;; CASE 17G: First statement in a function declared inside             ;; CASE 17G: First statement in a function declared inside
6710             ;; a normal block.  This can occur in Pike and with             ;; a normal block.  This can occur in Pike and with
6711             ;; e.g. the gcc extensions.  Might also trigger it with             ;; e.g. the gcc extensions, but watch out for macros
6712             ;; some macros followed by blocks, and this gives sane             ;; followed by blocks.  C.f. cases B.3 and 16F.
            ;; indentation then too.  C.f. cases B.3 and 16F.  
6713             ((save-excursion             ((save-excursion
6714                (and (not (c-looking-at-bos))                (and (not (c-looking-at-bos))
6715                     (eq (c-beginning-of-statement-1 lim nil nil t) 'same)                     (eq (c-beginning-of-statement-1 lim nil nil t) 'same)
6716                     (setq placeholder (point))))                     (setq placeholder (point))
6717                       ;; Look for a type or identifier followed by a
6718                       ;; symbol, i.e. the start of a function declaration.
6719                       ;; Doesn't work for declarations like "int *foo()
6720                       ;; ..."; we'd need to refactor the more competent
6721                       ;; analysis in `c-font-lock-declarations' for that.
6722                       (c-forward-type)
6723                       (progn
6724                         (c-forward-syntactic-ws)
6725                         (looking-at c-symbol-start))))
6726              (back-to-indentation)              (back-to-indentation)
6727              (if (/= (point) containing-sexp)              (if (/= (point) containing-sexp)
6728                  (goto-char placeholder))                  (goto-char placeholder))

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.37

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26