From: Alan Mackenzie Date: Sun, 19 Dec 2021 14:26:06 +0000 (+0000) Subject: CC Mode: Remove annoying background fontification. Should fix bug #52298 X-Git-Tag: emacs-29.0.90~3575 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=22b8d6813217187e3121338b93deabe62add99c1;p=emacs.git CC Mode: Remove annoying background fontification. Should fix bug #52298 Partially revert the commits from 2021-10-24 - 2021-10-26, "CC Mode: Fontify "found types" which are recognized after being first scanned". This removes the background fontification which ran off of a 0.1s timer, but leaves the facility of normal fontification causing the fontification throughout the buffer of newly found types. * lisp/progmodes/cc-fonts.el (c-find-types-background) (c-type-finder-timer-func): Remove. * lisp/progmodes/cc-mode.el (c-type-finder-timer, c-inhibit-type-finder) (c-type-finder-pos, c-post-gc-hook): Remove. (c-leave-cc-mode-mode): Remove the manipulations of c-type-finder-timer and c-post-gc-hook. (c-basic-common-init): Remove the manipulations of c-type-finder-pos, c-type-finder-timer, and c-post-gc-hook. * lisp/progmodes/cc-vars.el (c-type-finder-time-slot) (c-type-finder-repeat-time, c-type-finder-chunk-size): Remove. * doc/misc/cc-mode.texi (Found Types): Remove. Amend some menu entries. --- diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi index a2ff572a3f4..a388846fbfe 100644 --- a/doc/misc/cc-mode.texi +++ b/doc/misc/cc-mode.texi @@ -284,7 +284,6 @@ Font Locking * Faces:: * Doc Comments:: * Wrong Comment Style:: -* Found Types:: * Misc Font Locking:: * AWK Mode Font Locking:: @@ -1857,7 +1856,6 @@ sections apply to the other languages. * Faces:: * Doc Comments:: * Wrong Comment Style:: -* Found Types:: * Misc Font Locking:: * AWK Mode Font Locking:: @end menu @@ -2164,60 +2162,6 @@ which aren't of the default style will be fontified with @code{font-lock-warning-face}. @end defvar -@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -@node Found Types -@comment node-name, next, previous, up -@section ``Found Type'' handling. -@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -In most languages handled by CC Mode, @dfn{found types} are recognized -as types by their context in the source code. These contrast with -types which are basic to a language or are declared as types (e.g. by -@code{typedef} in C). - -In earlier versions of @ccmode{}, when @code{jit-lock-mode} was -enabled in Emacs (which it is by default), found types would -frequently fail to get fontified properly. This happened when the -fontification functions scanned a use of the found type before -scanning the code which caused it to be recognized. - -From @ccmode{} version 5.36, a timer mechanism scans the entire buffer -for found types in the seconds immediately after starting the major -mode. When a found type gets recognized, all its occurrences in the -buffer get marked for (re)fontification. This scanning happens in -short time slices interleaved with other processing, such as keyboard -handling, so that the responsiveness of Emacs should be barely -affected. This mechanism can be disabled (see below). It is only -active when @code{jit-lock-mode} is also active. - -@defvar c-type-finder-time-slot -@vindex type-finder-time-slot (c-) -The approximate time in seconds that CC Mode spends in scanning source -code before relinquishing control to other Emacs activities. The -default value is 0.05. To disable the scanning mechanism, set this -variable to @code{nil}. -@end defvar - -@defvar c-type-finder-repeat-time -@vindex type-finder-repeat-time (c-) -The approximate frequency (in seconds) with which the scanning -mechanism is triggered. This time must be greater than -@code{c-type-finder-time-slot}. Its default value is 0.1. If a less -powerful machine becomes sluggish due to the scanning, increase the -value of @code{c-type-finder-repeat-time} to compensate. -@end defvar - -@defvar c-type-finder-chunk-size -@vindex type-finder-chunk-size (c-) -The approximate size (in characters) of the buffer chunk processed as -a unit before the scanning mechanism checks whether -@code{c-type-finder-time-slot} seconds have passed. The default value -is 1000. A too small value here will cause inefficiencies due to the -initialization which happens for each chunk, whereas a too large value -will cause the processing to consume an excessive proportion of the -@code{c-type-finder-repeat-time}. -@end defvar - @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @node Misc Font Locking @comment node-name, next, previous, up diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 967464ac14d..846c25f45a6 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -93,14 +93,10 @@ (cc-bytecomp-defvar c-preprocessor-face-name) (cc-bytecomp-defvar c-reference-face-name) (cc-bytecomp-defvar c-block-comment-flag) -(cc-bytecomp-defvar c-type-finder-pos) -(cc-bytecomp-defvar c-inhibit-type-finder) -(cc-bytecomp-defvar c-type-finder-timer) (cc-bytecomp-defun c-fontify-recorded-types-and-refs) (cc-bytecomp-defun c-font-lock-declarators) (cc-bytecomp-defun c-font-lock-objc-method) (cc-bytecomp-defun c-font-lock-invalid-string) -(cc-bytecomp-defun c-before-context-fl-expand-region) (cc-bytecomp-defun c-font-lock-fontify-region) @@ -1603,175 +1599,6 @@ casts and declarations are fontified. Used on level 2 and higher." nil)))) -(defun c-find-types-background (start limit) - ;; Find any "found types" between START and LIMIT. Allow any such types to - ;; be entered into `c-found-types' by the action of `c-forward-name' or - ;; `c-forward-type' called from this function. This process also causes - ;; occurrences of the type to be prepared for fontification throughout the - ;; buffer. - ;; - ;; Return POINT at the end of the function. This should be at or after - ;; LIMIT, and not later than the next decl-spot after LIMIT. - ;; - ;; This function is called from the timer `c-type-finder-timer'. It may do - ;; hidden buffer changes. - (save-excursion - (save-restriction - (widen) - (goto-char start) - ;; If we're in a (possibly large) literal, skip over it. - (let ((lit-bounds (nth 2 (c-full-pp-to-literal (point))))) - (if lit-bounds - (goto-char (cdr lit-bounds)))) - (when (< (point) limit) - (let (;; o - 'decl if we're in an arglist containing declarations - ;; (but if `c-recognize-paren-inits' is set it might also be - ;; an initializer arglist); - ;; o - '<> if the arglist is of angle bracket type; - ;; o - 'arglist if it's some other arglist; - ;; o - nil, if not in an arglist at all. This includes the - ;; parenthesized condition which follows "if", "while", etc. - context - ;; A list of starting positions of possible type declarations, or of - ;; the typedef preceding one, if any. - last-cast-end - ;; The result from `c-forward-decl-or-cast-1'. - decl-or-cast - ;; The maximum of the end positions of all the checked type - ;; decl expressions in the successfully identified - ;; declarations. The position might be either before or - ;; after the syntactic whitespace following the last token - ;; in the type decl expression. - (max-type-decl-end 0) - ;; Same as `max-type-decl-*', but used when we're before - ;; `token-pos'. - (max-type-decl-end-before-token 0) - ) - (goto-char start) - (c-find-decl-spots - limit - c-decl-start-re - nil ; (eval c-maybe-decl-faces) - - (lambda (match-pos inside-macro &optional toplev) - ;; Note to maintainers: don't use `limit' inside this lambda form; - ;; c-find-decl-spots sometimes narrows to less than `limit'. - (if (and c-macro-with-semi-re - (looking-at c-macro-with-semi-re)) - ;; Don't do anything more if we're looking at something that - ;; can't start a declaration. - t - - ;; Set `context' and `c-restricted-<>-arglists'. Look for - ;; "<" for the sake of C++-style template arglists. - ;; "Ignore "(" when it's part of a control flow construct - ;; (e.g. "for ("). - (let ((got-context - (c-get-fontification-context - match-pos - (< match-pos (if inside-macro - max-type-decl-end-before-token - max-type-decl-end)) - toplev))) - (setq context (car got-context) - c-restricted-<>-arglists (cdr got-context))) - - ;; In QT, "more" is an irritating keyword that expands to nothing. - ;; We skip over it to prevent recognition of "more slots: " - ;; as a bitfield declaration. - (when (and (c-major-mode-is 'c++-mode) - (looking-at - (concat "\\(more\\)\\([^" c-symbol-chars "]\\|$\\)"))) - (goto-char (match-end 1)) - (c-forward-syntactic-ws)) - - ;; Now analyze the construct. This analysis will cause - ;; `c-forward-name' and `c-forward-type' to call `c-add-type', - ;; triggering the desired recognition and fontification of - ;; these found types. - (when (not (eq context 'not-decl)) - (setq decl-or-cast - (c-forward-decl-or-cast-1 - match-pos context last-cast-end)) - - (cond - ((eq decl-or-cast 'cast) - ;; Save the position after the previous cast so we can feed - ;; it to `c-forward-decl-or-cast-1' in the next round. That - ;; helps it discover cast chains like "(a) (b) c". - (setq last-cast-end (point)) - nil) - (decl-or-cast - ;; We've found a declaration. - - ;; Set `max-type-decl-end' or `max-type-decl-end-before-token' - ;; under the assumption that we're after the first type decl - ;; expression in the declaration now. That's not really true; - ;; we could also be after a parenthesized initializer - ;; expression in C++, but this is only used as a last resort - ;; to slant ambiguous expression/declarations, and overall - ;; it's worth the risk to occasionally fontify an expression - ;; as a declaration in an initializer expression compared to - ;; getting ambiguous things in normal function prototypes - ;; fontified as expressions. - (if inside-macro - (when (> (point) max-type-decl-end-before-token) - (setq max-type-decl-end-before-token (point))) - (when (> (point) max-type-decl-end) - (setq max-type-decl-end (point))))) - (t t)))))))) - (point)))) - -(defun c-type-finder-timer-func () - ;; A CC Mode idle timer function for finding "found types". It triggers - ;; every `c-type-finder-repeat-time' seconds and processes buffer chunks of - ;; size around `c-type-finder-chunk-size' characters, and runs for (a little - ;; over) `c-type-finder-time-slot' seconds. The types it finds are inserted - ;; into `c-found-types', and their occurrences throughout the buffer are - ;; prepared for fontification. - (when (and c-type-finder-time-slot - (boundp 'font-lock-support-mode) - (eq font-lock-support-mode 'jit-lock-mode)) - (if c-inhibit-type-finder ; No processing immediately after a GC operation. - (setq c-inhibit-type-finder nil) - (let* ((stop-time (+ (float-time) c-type-finder-time-slot)) - (buf-list (buffer-list))) - ;; One CC Mode buffer needing processing each time around this loop. - (while (and buf-list - (< (float-time) stop-time)) - ;; Cdr through BUF-LIST to find the next buffer needing processing. - (while (and buf-list - (not (with-current-buffer (car buf-list) c-type-finder-pos))) - (setq buf-list (cdr buf-list))) - (when buf-list - (with-current-buffer (car buf-list) - ;; (message "%s" (current-buffer)) ; Useful diagnostic. - (save-restriction - (widen) - ;; Process one `c-type-finder-chunk-size' chunk each time - ;; around this loop. - (while (and c-type-finder-pos - (< (float-time) stop-time)) - ;; Process one chunk per iteration. - (save-match-data - (c-save-buffer-state - (case-fold-search - (beg (marker-position c-type-finder-pos)) - (end (min (+ beg c-type-finder-chunk-size) (point-max))) - (region (c-before-context-fl-expand-region beg end))) - (setq beg (car region) - end (cdr region)) - (setq beg (max (c-find-types-background beg end) end)) - (move-marker c-type-finder-pos - (if (save-excursion (goto-char beg) (eobp)) - nil - beg)) - (when (not (marker-position c-type-finder-pos)) - (setq c-type-finder-pos nil)))))))))))) - ;; Set the timer to run again. - (setq c-type-finder-timer - (run-at-time c-type-finder-repeat-time nil #'c-type-finder-timer-func))) - (defun c-font-lock-enum-body (limit) ;; Fontify the identifiers of each enum we find by searching forward. ;; diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index f9435c9ceee..ae2ca397661 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -129,16 +129,6 @@ ; ' (require 'cc-fonts) ;) -(defvar c-type-finder-timer nil) -;; The variable which holds the repeating idle timer which triggers off the -;; background type finding search. - -(defvar c-inhibit-type-finder nil) -;; When non-nil (set by `c-post-gc-hook') don't perform the type finding -;; activities the next time `c-type-finder-timer' triggers. This ensures -;; keyboard/mouse input will be dealt with when garbage collection is taking a -;; large portion of CPU time. - ;; The following three really belong to cc-fonts.el, but they are required ;; even when cc-fonts.el hasn't been loaded (this happens in XEmacs when ;; font-lock-mode is nil). @@ -197,10 +187,7 @@ c-buffer-is-cc-mode)) (throw 'found nil))) (remove-hook 'post-command-hook 'c-post-command) - (remove-hook 'post-gc-hook 'c-post-gc-hook) - (and c-type-finder-timer - (progn (cancel-timer c-type-finder-timer) - (setq c-type-finder-timer nil))))) + (remove-hook 'post-gc-hook 'c-post-gc-hook))) (c-save-buffer-state () (c-clear-char-properties (point-min) (point-max) 'category) (c-clear-char-properties (point-min) (point-max) 'syntax-table) @@ -596,12 +583,6 @@ preferably use the `c-mode-menu' language constant directly." ;; currently no such text property. (make-variable-buffer-local 'c-max-syn-tab-mkr) -;; `c-type-finder-pos' is a marker marking the current place in a CC Mode -;; buffer which is due to be searched next for "found types", or nil if the -;; searching is complete. -(defvar c-type-finder-pos nil) -(make-variable-buffer-local 'c-type-finder-pos) - (defun c-basic-common-init (mode default-style) "Initialize the syntax handling routines and the line breaking/filling code. Intended to be used by other packages that embed CC Mode. @@ -774,17 +755,6 @@ that requires a literal mode spec at compile time." ;; c-after-font-lock-init. (add-hook 'after-change-functions 'c-after-change nil t) (add-hook 'post-command-hook 'c-post-command) - (setq c-type-finder-pos - (save-restriction - (widen) - (move-marker (make-marker) (point-min)))) - - ;; Install the functionality for seeking "found types" at mode startup: - (or c-type-finder-timer - (setq c-type-finder-timer - (run-at-time - c-type-finder-repeat-time nil #'c-type-finder-timer-func))) - (add-hook 'post-gc-hook #'c-post-gc-hook) (when (boundp 'font-lock-extend-after-change-region-function) (set (make-local-variable 'font-lock-extend-after-change-region-function) @@ -2028,9 +1998,6 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") c-new-id-end nil c-new-id-is-type nil))) -(defun c-post-gc-hook (&optional _stats) ; For XEmacs. - (setq c-inhibit-type-finder t)) - (defun c-before-change (beg end) ;; Function to be put on `before-change-functions'. Primarily, this calls ;; the language dependent `c-get-state-before-change-functions'. It is diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el index 40a43c32ed9..83fd3da7c1d 100644 --- a/lisp/progmodes/cc-vars.el +++ b/lisp/progmodes/cc-vars.el @@ -1524,39 +1524,6 @@ working due to this change." :type 'boolean :group 'c) -(defcustom c-type-finder-time-slot 0.05 - "The length in seconds of a background type search time slot. - -In CC Mode modes, \"found types\" wouldn't always get cleanly -fontified without the background searching for them which happens -in the seconds after starting Emacs or initializing the major -mode. - -This background searching can be disabled by setting this option -to nil." - :type '(choice (const :tag "disabled" nil) - number) - :group 'c) - -(defcustom c-type-finder-repeat-time 0.1 - "The interval, in seconds, at which background type searches occur. - -This interval must be greater than `c-type-finder-time-slot'." - :type 'number - :group 'c) - -(defcustom c-type-finder-chunk-size 1000 - "The size, in characters, of a chunk for background type search. - -Chunks of this size are searched atomically for \"found types\" -just after starting Emacs or initializing the major mode. - -This chunk size is a balance between efficiency (with larger -values) and responsiveness of the keyboard (with smaller values). -See also `c-type-finder-time-slot'." - :type 'integer - :group 'c) - (define-widget 'c-extra-types-widget 'radio "Internal CC Mode widget for the `*-font-lock-extra-types' variables." :args '((const :tag "none" nil)