diff options
| author | Alan Mackenzie | 2007-03-08 21:52:30 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2007-03-08 21:52:30 +0000 |
| commit | 580fba94862977a430e4212de49adc28b9cda4dc (patch) | |
| tree | a311a13bedbba11586b46b5dbc342191d295d4a8 | |
| parent | 9c184ed25c8db6d68268c06dbba1736eb4f003e5 (diff) | |
| download | emacs-580fba94862977a430e4212de49adc28b9cda4dc.tar.gz emacs-580fba94862977a430e4212de49adc28b9cda4dc.zip | |
(c-partial-ws-p, c-unfind-type, c-trim-found-types): new functions.
An ad hoc attempt to remove stale tokens from the cache `c-found-types'.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 100 |
1 files changed, 85 insertions, 15 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index f69382c9d70..a901ee07454 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -1912,6 +1912,26 @@ comment at the start of cc-engine.el for more info." | |||
| 1912 | ))) | 1912 | ))) |
| 1913 | 1913 | ||
| 1914 | 1914 | ||
| 1915 | ;; Other whitespace tools | ||
| 1916 | (defun c-partial-ws-p (beg end) | ||
| 1917 | ;; Is the region (beg end) WS, and is there WS (or BOB/EOB) next to the | ||
| 1918 | ;; region? This is a "heuristic" function. ..... | ||
| 1919 | ;; | ||
| 1920 | ;; The motivation for the second bit is to check whether the removal of this | ||
| 1921 | ;; space is to check whether removing this region would coalesce two | ||
| 1922 | ;; symbols. | ||
| 1923 | ;; | ||
| 1924 | ;; FIXME!!! This function doesn't check virtual semicolons in any way. Be | ||
| 1925 | ;; careful about using this function for, e.g. AWK. (2007/3/7) | ||
| 1926 | (save-excursion | ||
| 1927 | (let ((end+1 (min (1+ end) (point-max)))) | ||
| 1928 | (or (progn (goto-char (max (point-min) (1- beg))) | ||
| 1929 | (c-skip-ws-forward end) | ||
| 1930 | (eq (point) end)) | ||
| 1931 | (progn (goto-char beg) | ||
| 1932 | (c-skip-ws-forward end+1) | ||
| 1933 | (eq (point) end+1)))))) | ||
| 1934 | |||
| 1915 | ;; A system for finding noteworthy parens before the point. | 1935 | ;; A system for finding noteworthy parens before the point. |
| 1916 | 1936 | ||
| 1917 | (defvar c-state-cache nil) | 1937 | (defvar c-state-cache nil) |
| @@ -2491,24 +2511,25 @@ comment at the start of cc-engine.el for more info." | |||
| 2491 | ;; Move to the beginning of the current token. Do not move if not | 2511 | ;; Move to the beginning of the current token. Do not move if not |
| 2492 | ;; in the middle of one. BACK-LIMIT may be used to bound the | 2512 | ;; in the middle of one. BACK-LIMIT may be used to bound the |
| 2493 | ;; backward search; if given it's assumed to be at the boundary | 2513 | ;; backward search; if given it's assumed to be at the boundary |
| 2494 | ;; between two tokens. | 2514 | ;; between two tokens. Return non-nil if the point is move, nil |
| 2515 | ;; otherwise. | ||
| 2495 | ;; | 2516 | ;; |
| 2496 | ;; This function might do hidden buffer changes. | 2517 | ;; This function might do hidden buffer changes. |
| 2497 | (if (looking-at "\\w\\|\\s_") | ||
| 2498 | (skip-syntax-backward "w_" back-limit) | ||
| 2499 | (let ((start (point))) | 2518 | (let ((start (point))) |
| 2500 | (when (< (skip-syntax-backward ".()" back-limit) 0) | 2519 | (if (looking-at "\\w\\|\\s_") |
| 2501 | (while (let ((pos (or (and (looking-at c-nonsymbol-token-regexp) | 2520 | (skip-syntax-backward "w_" back-limit) |
| 2502 | (match-end 0)) | 2521 | (when (< (skip-syntax-backward ".()" back-limit) 0) |
| 2503 | ;; `c-nonsymbol-token-regexp' should always match | 2522 | (while (let ((pos (or (and (looking-at c-nonsymbol-token-regexp) |
| 2504 | ;; since we've skipped backward over punctuator | 2523 | (match-end 0)) |
| 2505 | ;; or paren syntax, but consume one char in case | 2524 | ;; `c-nonsymbol-token-regexp' should always match |
| 2506 | ;; it doesn't so that we don't leave point before | 2525 | ;; since we've skipped backward over punctuator |
| 2507 | ;; some earlier incorrect token. | 2526 | ;; or paren syntax, but consume one char in case |
| 2508 | (1+ (point))))) | 2527 | ;; it doesn't so that we don't leave point before |
| 2509 | (if (<= pos start) | 2528 | ;; some earlier incorrect token. |
| 2510 | (goto-char pos)) | 2529 | (1+ (point))))) |
| 2511 | (< pos start))))))) | 2530 | (if (<= pos start) |
| 2531 | (goto-char pos)))))) | ||
| 2532 | (< (point) start))) | ||
| 2512 | 2533 | ||
| 2513 | (defun c-end-of-current-token (&optional back-limit) | 2534 | (defun c-end-of-current-token (&optional back-limit) |
| 2514 | ;; Move to the end of the current token. Do not move if not in the | 2535 | ;; Move to the end of the current token. Do not move if not in the |
| @@ -3957,6 +3978,9 @@ comment at the start of cc-engine.el for more info." | |||
| 3957 | ;; file, and we only use this as a last resort in ambiguous cases (see | 3978 | ;; file, and we only use this as a last resort in ambiguous cases (see |
| 3958 | ;; `c-forward-decl-or-cast-1'). | 3979 | ;; `c-forward-decl-or-cast-1'). |
| 3959 | ;; | 3980 | ;; |
| 3981 | ;; Not every type need be in this cache. However, things which have | ||
| 3982 | ;; ceased to be types must be removed from it. | ||
| 3983 | ;; | ||
| 3960 | ;; Template types in C++ are added here too but with the template | 3984 | ;; Template types in C++ are added here too but with the template |
| 3961 | ;; arglist replaced with "<>" in references or "<" for the one in the | 3985 | ;; arglist replaced with "<>" in references or "<" for the one in the |
| 3962 | ;; primary type. E.g. the type "Foo<A,B>::Bar<C>" is stored as | 3986 | ;; primary type. E.g. the type "Foo<A,B>::Bar<C>" is stored as |
| @@ -3990,6 +4014,10 @@ comment at the start of cc-engine.el for more info." | |||
| 3990 | (unintern (substring type 0 -1) c-found-types) | 4014 | (unintern (substring type 0 -1) c-found-types) |
| 3991 | (intern type c-found-types)))) | 4015 | (intern type c-found-types)))) |
| 3992 | 4016 | ||
| 4017 | (defun c-unfind-type (name) | ||
| 4018 | ;; Remove the "NAME" from c-found-types, if present. | ||
| 4019 | (unintern name c-found-types)) | ||
| 4020 | |||
| 3993 | (defsubst c-check-type (from to) | 4021 | (defsubst c-check-type (from to) |
| 3994 | ;; Return non-nil if the given region contains a type in | 4022 | ;; Return non-nil if the given region contains a type in |
| 3995 | ;; `c-found-types'. | 4023 | ;; `c-found-types'. |
| @@ -4008,6 +4036,48 @@ comment at the start of cc-engine.el for more info." | |||
| 4008 | c-found-types) | 4036 | c-found-types) |
| 4009 | (sort type-list 'string-lessp))) | 4037 | (sort type-list 'string-lessp))) |
| 4010 | 4038 | ||
| 4039 | (defun c-trim-found-types (beg end old-len) | ||
| 4040 | ;; An after change function which, in conjunction with the info in | ||
| 4041 | ;; c-maybe-stale-found-type (set in c-before-change), removes a type | ||
| 4042 | ;; from `c-found-types', should this type have become stale. For | ||
| 4043 | ;; example, this happens to "foo" when "foo \n bar();" becomes | ||
| 4044 | ;; "foo(); \n bar();". Such stale types, if not removed, foul up | ||
| 4045 | ;; the fontification. | ||
| 4046 | ;; | ||
| 4047 | ;; Have we, perhaps, added non-ws characters to the front/back of a found | ||
| 4048 | ;; type? | ||
| 4049 | (when (> end beg) | ||
| 4050 | (save-excursion | ||
| 4051 | (when (< end (point-max)) | ||
| 4052 | (goto-char end) | ||
| 4053 | (if (and (c-beginning-of-current-token) ; only moves when we started in the middle | ||
| 4054 | (progn (goto-char end) | ||
| 4055 | (c-end-of-current-token))) | ||
| 4056 | (c-unfind-type (buffer-substring-no-properties | ||
| 4057 | end (point))))) | ||
| 4058 | (when (> beg (point-min)) | ||
| 4059 | (goto-char beg) | ||
| 4060 | (if (and (c-end-of-current-token) ; only moves when we started in the middle | ||
| 4061 | (progn (goto-char beg) | ||
| 4062 | (c-beginning-of-current-token))) | ||
| 4063 | (c-unfind-type (buffer-substring-no-properties | ||
| 4064 | (point) beg)))))) | ||
| 4065 | |||
| 4066 | (if c-maybe-stale-found-type ; e.g. (c-decl-id-start "foo" 97 107 " (* ooka) " "o") | ||
| 4067 | (cond | ||
| 4068 | ;; Changing the amount of (already existing) whitespace - don't do anything. | ||
| 4069 | ((and (c-partial-ws-p beg end) | ||
| 4070 | (or (= beg end) ; removal of WS | ||
| 4071 | ; (string-match "\\s *\\'" (nth 5 c-maybe-stale-found-type)) | ||
| 4072 | (string-match "^[ \t\n\r\f\v]*$" (nth 5 c-maybe-stale-found-type))))) | ||
| 4073 | |||
| 4074 | ;; The syntactic relationship which defined a "found type" has been | ||
| 4075 | ;; destroyed. | ||
| 4076 | ((eq (car c-maybe-stale-found-type) 'c-decl-id-start) | ||
| 4077 | (c-unfind-type (cadr c-maybe-stale-found-type))) | ||
| 4078 | ;; ((eq (car c-maybe-stale-found-type) 'c-decl-type-start) FIXME!!! | ||
| 4079 | ))) | ||
| 4080 | |||
| 4011 | 4081 | ||
| 4012 | ;; Handling of small scale constructs like types and names. | 4082 | ;; Handling of small scale constructs like types and names. |
| 4013 | 4083 | ||