comparison lisp/progmodes/cc-mode.el @ 76424:2233da85ba88

(c-before-change): insert call of `save-match-data'.
author Alan Mackenzie <acm@muc.de>
date Fri, 09 Mar 2007 23:11:15 +0000
parents ec0b1fedc030
children 20327b8e8725 91bf6e05918b
comparison
equal deleted inserted replaced
76423:51f9ca8269f0 76424:2233da85ba88
488 ;; it/them from the cache. Don't worry about being inside a string 488 ;; it/them from the cache. Don't worry about being inside a string
489 ;; or a comment - "wrongly" removing a symbol from `c-found-types' 489 ;; or a comment - "wrongly" removing a symbol from `c-found-types'
490 ;; isn't critical. 490 ;; isn't critical.
491 (setq c-maybe-stale-found-type nil) 491 (setq c-maybe-stale-found-type nil)
492 (save-restriction 492 (save-restriction
493 (widen) 493 (save-match-data
494 (save-excursion 494 (widen)
495 ;; Are we inserting/deleting stuff in the middle of an identifier? 495 (save-excursion
496 (c-unfind-enclosing-token beg) 496 ;; Are we inserting/deleting stuff in the middle of an identifier?
497 (c-unfind-enclosing-token end) 497 (c-unfind-enclosing-token beg)
498 ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"? 498 (c-unfind-enclosing-token end)
499 (when (< beg end) 499 ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
500 (c-unfind-coalesced-tokens beg end)) 500 (when (< beg end)
501 ;; Are we (potentially) disrupting the syntactic context which 501 (c-unfind-coalesced-tokens beg end))
502 ;; makes a type a type? E.g. by inserting stuff after "foo" in 502 ;; Are we (potentially) disrupting the syntactic context which
503 ;; "foo bar;", or before "foo" in "typedef foo *bar;"? 503 ;; makes a type a type? E.g. by inserting stuff after "foo" in
504 ;; 504 ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
505 ;; We search for appropriate c-type properties "near" the change. 505 ;;
506 ;; First, find an appropriate boundary for this property search. 506 ;; We search for appropriate c-type properties "near" the change.
507 (let (lim 507 ;; First, find an appropriate boundary for this property search.
508 type type-pos 508 (let (lim
509 marked-id term-pos 509 type type-pos
510 (end1 510 marked-id term-pos
511 (if (eq (get-text-property end 'face) 'font-lock-comment-face) 511 (end1
512 (previous-single-property-change end 'face) 512 (if (eq (get-text-property end 'face) 'font-lock-comment-face)
513 end))) 513 (previous-single-property-change end 'face)
514 (when (>= end1 beg) ; Don't hassle about changes entirely in comments. 514 end)))
515 ;; Find a limit for the search for a `c-type' property 515 (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
516 (while 516 ;; Find a limit for the search for a `c-type' property
517 (and (/= (skip-chars-backward "^;{}") 0) 517 (while
518 (> (point) (point-min)) 518 (and (/= (skip-chars-backward "^;{}") 0)
519 (memq (c-get-char-property (1- (point)) 'face) 519 (> (point) (point-min))
520 '(font-lock-comment-face font-lock-string-face)))) 520 (memq (c-get-char-property (1- (point)) 'face)
521 (setq lim (max (point-min) (1- (point)))) 521 '(font-lock-comment-face font-lock-string-face))))
522 522 (setq lim (max (point-min) (1- (point))))
523 ;; Look for the latest `c-type' property before end1 523
524 (when (and (> end1 1) 524 ;; Look for the latest `c-type' property before end1
525 (setq type-pos 525 (when (and (> end1 1)
526 (if (get-text-property (1- end1) 'c-type) 526 (setq type-pos
527 end1 527 (if (get-text-property (1- end1) 'c-type)
528 (previous-single-property-change end1 'c-type nil lim)))) 528 end1
529 (setq type (get-text-property (max (1- type-pos) lim) 'c-type)) 529 (previous-single-property-change end1 'c-type nil lim))))
530 530 (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
531 (when (memq type '(c-decl-id-start c-decl-type-start)) 531
532 ;; Get the identifier, if any, that the property is on. 532 (when (memq type '(c-decl-id-start c-decl-type-start))
533 (goto-char (1- type-pos)) 533 ;; Get the identifier, if any, that the property is on.
534 (setq marked-id 534 (goto-char (1- type-pos))
535 (when (looking-at "\\(\\sw\\|\\s_\\)") 535 (setq marked-id
536 (c-beginning-of-current-token) 536 (when (looking-at "\\(\\sw\\|\\s_\\)")
537 (buffer-substring-no-properties (point) type-pos))) 537 (c-beginning-of-current-token)
538 538 (buffer-substring-no-properties (point) type-pos)))
539 (goto-char end1) 539
540 (skip-chars-forward "^;{}") ; FIXME!!! loop for comment, maybe 540 (goto-char end1)
541 (setq lim (point)) 541 (skip-chars-forward "^;{}") ; FIXME!!! loop for comment, maybe
542 (setq term-pos 542 (setq lim (point))
543 (or (next-single-property-change end 'c-type nil lim) lim)) 543 (setq term-pos
544 (setq c-maybe-stale-found-type 544 (or (next-single-property-change end 'c-type nil lim) lim))
545 (list type marked-id 545 (setq c-maybe-stale-found-type
546 type-pos term-pos 546 (list type marked-id
547 (buffer-substring-no-properties type-pos term-pos) 547 type-pos term-pos
548 (buffer-substring-no-properties beg end)))))))))) 548 (buffer-substring-no-properties type-pos term-pos)
549 (buffer-substring-no-properties beg end)))))))))))
549 550
550 (defun c-after-change (beg end old-len) 551 (defun c-after-change (beg end old-len)
551 ;; Function put on `after-change-functions' to adjust various caches 552 ;; Function put on `after-change-functions' to adjust various caches
552 ;; etc. Prefer speed to finesse here, since there will be an order 553 ;; etc. Prefer speed to finesse here, since there will be an order
553 ;; of magnitude more calls to this function than any of the 554 ;; of magnitude more calls to this function than any of the