Mercurial > emacs
comparison lisp/progmodes/cc-engine.el @ 45512:17fef404cef1
(c-add-stmt-syntax): Fixed some cases of wrong anchoring, e.g. for
else-if compounds.
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Sat, 25 May 2002 16:17:27 +0000 |
parents | 11c11cb2b8a8 |
children | 07e19a2737a1 |
comparison
equal
deleted
inserted
replaced
45511:e27a1854f55c | 45512:17fef404cef1 |
---|---|
2331 nil) | 2331 nil) |
2332 (/= (point) savepos)) | 2332 (/= (point) savepos)) |
2333 (setq savepos (point) | 2333 (setq savepos (point) |
2334 step-type step-tmp)) | 2334 step-type step-tmp)) |
2335 | 2335 |
2336 ;; Skip over any comments that stands between the statement and | 2336 (catch 'done |
2337 ;; boi. If stop-at-boi-only is nil and we're not at boi after | |
2338 ;; this, then we're done. | |
2339 (while (and (/= (setq savepos (point)) boi) | |
2340 (c-forward-comment -1)) | |
2341 (setq at-comment t | |
2342 boi (c-point 'boi))) | |
2343 (goto-char savepos) | |
2344 | |
2345 (when (or stop-at-boi-only | |
2346 (= (point) boi)) | |
2347 (catch 'done | |
2348 ;; Loop if we have to back out of the containing block. | 2337 ;; Loop if we have to back out of the containing block. |
2349 (while | 2338 (while |
2350 (progn | 2339 (progn |
2351 ;; Loop if we have to back up another statement. | 2340 ;; Loop if we have to back up another statement. |
2352 (while | 2341 (while |
2353 (progn | 2342 (progn |
2343 | |
2354 ;; Always start by skipping over any comments that | 2344 ;; Always start by skipping over any comments that |
2355 ;; stands between the statement and boi. | 2345 ;; stands between the statement and boi. |
2356 (while (and (/= (setq savepos (point)) boi) | 2346 (while (and (/= (setq savepos (point)) boi) |
2357 (c-forward-comment -1)) | 2347 (c-forward-comment -1)) |
2358 (setq at-comment t | 2348 (setq at-comment t |
2359 boi (c-point 'boi))) | 2349 boi (c-point 'boi))) |
2360 (goto-char savepos) | 2350 (goto-char savepos) |
2361 (and (or at-comment | 2351 |
2362 (eq step-type 'label) | 2352 (and |
2363 (/= savepos boi)) | 2353 (or at-comment |
2364 (progn | 2354 (eq step-type 'label) |
2365 ;; Current position not good enough; skip | 2355 (/= savepos boi)) |
2366 ;; backward another statement. | 2356 |
2367 (setq stop-at-boi-only t | 2357 (progn |
2368 step-type (c-beginning-of-statement-1 | 2358 ;; Current position might not be good enough; |
2369 containing-sexp)) | 2359 ;; skip backward another statement. |
2370 ;; Record this a substatement if we skipped | 2360 (setq step-type (c-beginning-of-statement-1 |
2371 ;; up one level, but not if we're still on | 2361 containing-sexp)) |
2372 ;; the same line. This so e.g. a sequence | 2362 |
2373 ;; of "else if" clauses won't indent deeper | 2363 (if (and (not stop-at-boi-only) |
2374 ;; and deeper. | 2364 (/= savepos boi) |
2375 (when (and (eq step-type 'up) | 2365 (memq step-type '(up previous))) |
2376 (< (point) boi)) | 2366 ;; If stop-at-boi-only is nil, we shouldn't |
2377 (setcdr syms-tail (list 'substatement)) | 2367 ;; back up over previous or containing |
2378 (setq syms-tail (cdr syms-tail))) | 2368 ;; statements to try to reach boi, so go |
2379 (setq boi (c-point 'boi)) | 2369 ;; back to the last position and exit. |
2380 (/= (point) savepos)))) | 2370 (progn |
2371 (goto-char savepos) | |
2372 nil) | |
2373 (if (and (not stop-at-boi-only) | |
2374 (memq step-type '(up previous beginning))) | |
2375 ;; If we've moved into another statement | |
2376 ;; then we should no longer try to stop | |
2377 ;; after boi. | |
2378 (setq stop-at-boi-only t)) | |
2379 | |
2380 ;; Record this a substatement if we skipped up | |
2381 ;; one level, but not if we're still on the | |
2382 ;; same line. This so e.g. a sequence of "else | |
2383 ;; if" clauses won't indent deeper and deeper. | |
2384 (when (and (eq step-type 'up) | |
2385 (< (point) boi)) | |
2386 (setcdr syms-tail (list 'substatement)) | |
2387 (setq syms-tail (cdr syms-tail))) | |
2388 | |
2389 (setq boi (c-point 'boi)) | |
2390 (/= (point) savepos))))) | |
2391 | |
2381 (setq savepos (point) | 2392 (setq savepos (point) |
2382 at-comment nil)) | 2393 at-comment nil)) |
2383 (setq at-comment nil) | 2394 (setq at-comment nil) |
2384 | 2395 |
2385 (when (and (eq step-type 'same) | 2396 (when (and (eq step-type 'same) |
2387 (goto-char containing-sexp) | 2398 (goto-char containing-sexp) |
2388 (setq paren-state (c-whack-state-after containing-sexp | 2399 (setq paren-state (c-whack-state-after containing-sexp |
2389 paren-state) | 2400 paren-state) |
2390 containing-sexp (c-most-enclosing-brace paren-state)) | 2401 containing-sexp (c-most-enclosing-brace paren-state)) |
2391 | 2402 |
2392 (when (and (prog1 | 2403 |
2393 (eq prev-paren ?{) | 2404 (when (eq (setq prev-paren (char-after)) ?\() |
2394 (setq prev-paren (char-after))) | |
2395 (eq prev-paren ?\()) | |
2396 (c-backward-syntactic-ws containing-sexp) | 2405 (c-backward-syntactic-ws containing-sexp) |
2397 (when (c-on-identifier) | 2406 (when (c-on-identifier) |
2398 ;; Arrived at a function arglist start. Exit with | 2407 ;; Arrived at a function arglist start. Exit with |
2399 ;; the position of the first argument inside it. | 2408 ;; the position of the first argument inside it. |
2400 (goto-char savepos) | 2409 (goto-char savepos) |
2431 (if (eq step-type 'same) | 2440 (if (eq step-type 'same) |
2432 ;; Avoid backing up another sexp if the point | 2441 ;; Avoid backing up another sexp if the point |
2433 ;; we're at now is found to be good enough in | 2442 ;; we're at now is found to be good enough in |
2434 ;; the loop above. | 2443 ;; the loop above. |
2435 (setq step-type nil)) | 2444 (setq step-type nil)) |
2436 (setq stop-at-boi-only t | 2445 (if (and (not stop-at-boi-only) |
2437 boi (c-point 'boi))))) | 2446 (memq step-type '(up previous beginning))) |
2438 )))) | 2447 (setq stop-at-boi-only t)) |
2448 (setq boi (c-point 'boi))))) | |
2449 ))) | |
2439 | 2450 |
2440 (while syms | 2451 (while syms |
2441 (c-add-syntax (car syms) (point)) | 2452 (c-add-syntax (car syms) (point)) |
2442 (setq syms (cdr syms))) | 2453 (setq syms (cdr syms))) |
2443 (if add-inexpr-stmt | 2454 (if add-inexpr-stmt |