diff options
| author | Alan Mackenzie | 2007-03-09 23:11:15 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2007-03-09 23:11:15 +0000 |
| commit | d4e5bf0f80adfbe9bc5896b289474a235e4360a2 (patch) | |
| tree | c67f8ebe4a91eade1e7d7a06e0ec9eb0e3aac618 | |
| parent | fec4d2663f1eb0e04556f59347500cd866c6a811 (diff) | |
| download | emacs-d4e5bf0f80adfbe9bc5896b289474a235e4360a2.tar.gz emacs-d4e5bf0f80adfbe9bc5896b289474a235e4360a2.zip | |
(c-before-change): insert call of `save-match-data'.
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 113 |
1 files changed, 57 insertions, 56 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index a79ca3cac6e..1407b497305 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -490,62 +490,63 @@ preferably use the `c-mode-menu' language constant directly." | |||
| 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 |