diff options
| author | Alan Mackenzie | 2015-11-11 22:06:12 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2015-11-11 22:22:35 +0000 |
| commit | e0f64e7b4f9c3bbc12c4909ca8c8aa751f1fca4a (patch) | |
| tree | 731d284343f75a48d13bfef9f10e8e73e3d8b35b | |
| parent | 952395d3eb813e1c21b8bace10e54aa67bee9122 (diff) | |
| download | emacs-e0f64e7b4f9c3bbc12c4909ca8c8aa751f1fca4a.tar.gz emacs-e0f64e7b4f9c3bbc12c4909ca8c8aa751f1fca4a.zip | |
CC Mode: Respect users' settings of open-paren-in-column-0-is-defun-start.
lisp/progmodes/cc-engine.el (c-backward-single-comment, c-backward-comments)
(c-invalidate-state-cache-1, c-parse-state-1, c-guess-basic-syntax):
remove bindings of open-paren-in-column-0-is-defun-start to nil.
(c-get-fallback-scan-pos): "New" function (existed several years ago).
(c-parse-state-get-strategy): Reintroduce the 'BOD strategy, using
c-get-fallback-scan-pos.
(c-parse-state-1): Handle 'BOD strategy.
lisp/progmodes/cc-mode.el (c-before-change, c-after-change)
c-font-lock-fontify-region): remove bindings of
open-paren-in-column-0-is-defun-start to nil.
cc-mode.texi (Performance Issues, Limitations and Known Bugs): Fix mix up
between @chapter and @appendix.
| -rw-r--r-- | doc/misc/cc-mode.texi | 4 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 68 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 12 |
3 files changed, 60 insertions, 24 deletions
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi index b93bc8f679f..9b488cb3125 100644 --- a/doc/misc/cc-mode.texi +++ b/doc/misc/cc-mode.texi | |||
| @@ -6860,7 +6860,7 @@ to change some of the actual values. | |||
| 6860 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 6860 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6861 | @node Performance Issues, Limitations and Known Bugs, Sample Init File, Top | 6861 | @node Performance Issues, Limitations and Known Bugs, Sample Init File, Top |
| 6862 | @comment node-name, next, previous, up | 6862 | @comment node-name, next, previous, up |
| 6863 | @chapter Performance Issues | 6863 | @appendix Performance Issues |
| 6864 | @cindex performance | 6864 | @cindex performance |
| 6865 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 6865 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6866 | 6866 | ||
| @@ -6969,7 +6969,7 @@ more info. | |||
| 6969 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 6969 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6970 | @node Limitations and Known Bugs, FAQ, Performance Issues, Top | 6970 | @node Limitations and Known Bugs, FAQ, Performance Issues, Top |
| 6971 | @comment node-name, next, previous, up | 6971 | @comment node-name, next, previous, up |
| 6972 | @chapter Limitations and Known Bugs | 6972 | @appendix Limitations and Known Bugs |
| 6973 | @cindex limitations | 6973 | @cindex limitations |
| 6974 | @cindex bugs | 6974 | @cindex bugs |
| 6975 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 6975 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 6382b145211..6572cee2cc7 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -1449,13 +1449,12 @@ This function does not do any hidden buffer changes." | |||
| 1449 | ;; same line. | 1449 | ;; same line. |
| 1450 | (re-search-forward "\\=\\s *[\n\r]" start t) | 1450 | (re-search-forward "\\=\\s *[\n\r]" start t) |
| 1451 | 1451 | ||
| 1452 | (if (if (let (open-paren-in-column-0-is-defun-start) (forward-comment -1)) | 1452 | (if (if (forward-comment -1) |
| 1453 | (if (eolp) | 1453 | (if (eolp) |
| 1454 | ;; If forward-comment above succeeded and we're at eol | 1454 | ;; If forward-comment above succeeded and we're at eol |
| 1455 | ;; then the newline we moved over above didn't end a | 1455 | ;; then the newline we moved over above didn't end a |
| 1456 | ;; line comment, so we give it another go. | 1456 | ;; line comment, so we give it another go. |
| 1457 | (let (open-paren-in-column-0-is-defun-start) | 1457 | (forward-comment -1) |
| 1458 | (forward-comment -1)) | ||
| 1459 | t)) | 1458 | t)) |
| 1460 | 1459 | ||
| 1461 | ;; Emacs <= 20 and XEmacs move back over the closer of a | 1460 | ;; Emacs <= 20 and XEmacs move back over the closer of a |
| @@ -1482,7 +1481,7 @@ comment at the start of cc-engine.el for more info." | |||
| 1482 | ;; return t when moving backwards at bob. | 1481 | ;; return t when moving backwards at bob. |
| 1483 | (not (bobp)) | 1482 | (not (bobp)) |
| 1484 | 1483 | ||
| 1485 | (if (let (open-paren-in-column-0-is-defun-start moved-comment) | 1484 | (if (let (moved-comment) |
| 1486 | (while | 1485 | (while |
| 1487 | (and (not (setq moved-comment (forward-comment -1))) | 1486 | (and (not (setq moved-comment (forward-comment -1))) |
| 1488 | ;; Cope specifically with ^M^J here - | 1487 | ;; Cope specifically with ^M^J here - |
| @@ -2524,6 +2523,20 @@ comment at the start of cc-engine.el for more info." | |||
| 2524 | 2523 | ||
| 2525 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2524 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2526 | ;; Defuns which analyze the buffer, yet don't change `c-state-cache'. | 2525 | ;; Defuns which analyze the buffer, yet don't change `c-state-cache'. |
| 2526 | (defun c-get-fallback-scan-pos (here) | ||
| 2527 | ;; Return a start position for building `c-state-cache' from | ||
| 2528 | ;; scratch. This will be at the top level, 2 defuns back. | ||
| 2529 | (save-excursion | ||
| 2530 | ;; Go back 2 bods, but ignore any bogus positions returned by | ||
| 2531 | ;; beginning-of-defun (i.e. open paren in column zero). | ||
| 2532 | (goto-char here) | ||
| 2533 | (let ((cnt 2)) | ||
| 2534 | (while (not (or (bobp) (zerop cnt))) | ||
| 2535 | (c-beginning-of-defun-1) ; Pure elisp BOD. | ||
| 2536 | (if (eq (char-after) ?\{) | ||
| 2537 | (setq cnt (1- cnt))))) | ||
| 2538 | (point))) | ||
| 2539 | |||
| 2527 | (defun c-state-balance-parens-backwards (here- here+ top) | 2540 | (defun c-state-balance-parens-backwards (here- here+ top) |
| 2528 | ;; Return the position of the opening paren/brace/bracket before HERE- which | 2541 | ;; Return the position of the opening paren/brace/bracket before HERE- which |
| 2529 | ;; matches the outermost close p/b/b between HERE+ and TOP. Except when | 2542 | ;; matches the outermost close p/b/b between HERE+ and TOP. Except when |
| @@ -2584,22 +2597,46 @@ comment at the start of cc-engine.el for more info." | |||
| 2584 | ;; o - ('backward nil) - scan backwards (from HERE). | 2597 | ;; o - ('backward nil) - scan backwards (from HERE). |
| 2585 | ;; o - ('back-and-forward START-POINT) - like 'forward, but when HERE is earlier | 2598 | ;; o - ('back-and-forward START-POINT) - like 'forward, but when HERE is earlier |
| 2586 | ;; than GOOD-POS. | 2599 | ;; than GOOD-POS. |
| 2600 | ;; o - ('BOD START-POINT) - scan forwards from START-POINT, which is at the | ||
| 2601 | ;; top level. | ||
| 2587 | ;; o - ('IN-LIT nil) - point is inside the literal containing point-min. | 2602 | ;; o - ('IN-LIT nil) - point is inside the literal containing point-min. |
| 2588 | (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position below HERE in cache (or 1) | 2603 | (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position below HERE in cache (or 1) |
| 2589 | strategy ; 'forward, 'backward, or 'IN-LIT. | 2604 | BOD-pos ; position of 2nd BOD before HERE. |
| 2590 | start-point) | 2605 | strategy ; 'forward, 'backward, 'BOD, or 'IN-LIT. |
| 2606 | start-point | ||
| 2607 | how-far) ; putative scanning distance. | ||
| 2591 | (setq good-pos (or good-pos (c-state-get-min-scan-pos))) | 2608 | (setq good-pos (or good-pos (c-state-get-min-scan-pos))) |
| 2592 | (cond | 2609 | (cond |
| 2593 | ((< here (c-state-get-min-scan-pos)) | 2610 | ((< here (c-state-get-min-scan-pos)) |
| 2594 | (setq strategy 'IN-LIT)) | 2611 | (setq strategy 'IN-LIT |
| 2612 | start-point nil | ||
| 2613 | cache-pos nil | ||
| 2614 | how-far 0)) | ||
| 2595 | ((<= good-pos here) | 2615 | ((<= good-pos here) |
| 2596 | (setq strategy 'forward | 2616 | (setq strategy 'forward |
| 2597 | start-point (max good-pos cache-pos))) | 2617 | start-point (max good-pos cache-pos) |
| 2618 | how-far (- here start-point))) | ||
| 2598 | ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of weighting. | 2619 | ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of weighting. |
| 2599 | (setq strategy 'backward)) | 2620 | (setq strategy 'backward |
| 2621 | how-far (- good-pos here))) | ||
| 2600 | (t | 2622 | (t |
| 2601 | (setq strategy 'back-and-forward | 2623 | (setq strategy 'back-and-forward |
| 2602 | start-point cache-pos))) | 2624 | start-point cache-pos |
| 2625 | how-far (- here start-point)))) | ||
| 2626 | |||
| 2627 | ;; Might we be better off starting from the top level, two defuns back, | ||
| 2628 | ;; instead? This heuristic no longer works well in C++, where | ||
| 2629 | ;; declarations inside namespace brace blocks are frequently placed at | ||
| 2630 | ;; column zero. (2015-11-10): Remove the condition on C++ Mode. | ||
| 2631 | (when (and (or (not (memq 'col-0-paren c-emacs-features)) | ||
| 2632 | open-paren-in-column-0-is-defun-start) | ||
| 2633 | ;; (not (c-major-mode-is 'c++-mode)) | ||
| 2634 | (> how-far c-state-cache-too-far)) | ||
| 2635 | (setq BOD-pos (c-get-fallback-scan-pos here)) ; somewhat EXPENSIVE!!! | ||
| 2636 | (if (< (- here BOD-pos) how-far) | ||
| 2637 | (setq strategy 'BOD | ||
| 2638 | start-point BOD-pos))) | ||
| 2639 | |||
| 2603 | (list strategy start-point))) | 2640 | (list strategy start-point))) |
| 2604 | 2641 | ||
| 2605 | 2642 | ||
| @@ -3227,8 +3264,7 @@ comment at the start of cc-engine.el for more info." | |||
| 3227 | ;; Truncate `c-state-cache' and set `c-state-cache-good-pos' to a value | 3264 | ;; Truncate `c-state-cache' and set `c-state-cache-good-pos' to a value |
| 3228 | ;; below `here'. To maintain its consistency, we may need to insert a new | 3265 | ;; below `here'. To maintain its consistency, we may need to insert a new |
| 3229 | ;; brace pair. | 3266 | ;; brace pair. |
| 3230 | (let (open-paren-in-column-0-is-defun-start | 3267 | (let ((here-bol (c-point 'bol here)) |
| 3231 | (here-bol (c-point 'bol here)) | ||
| 3232 | too-high-pa ; recorded {/(/[ next above here, or nil. | 3268 | too-high-pa ; recorded {/(/[ next above here, or nil. |
| 3233 | dropped-cons ; was the last removed element a brace pair? | 3269 | dropped-cons ; was the last removed element a brace pair? |
| 3234 | pa) | 3270 | pa) |
| @@ -3299,7 +3335,6 @@ comment at the start of cc-engine.el for more info." | |||
| 3299 | ;; This function might do hidden buffer changes. | 3335 | ;; This function might do hidden buffer changes. |
| 3300 | (let* ((here (point)) | 3336 | (let* ((here (point)) |
| 3301 | (here-bopl (c-point 'bopl)) | 3337 | (here-bopl (c-point 'bopl)) |
| 3302 | open-paren-in-column-0-is-defun-start | ||
| 3303 | strategy ; 'forward, 'backward etc.. | 3338 | strategy ; 'forward, 'backward etc.. |
| 3304 | ;; Candidate positions to start scanning from: | 3339 | ;; Candidate positions to start scanning from: |
| 3305 | cache-pos ; highest position below HERE already existing in | 3340 | cache-pos ; highest position below HERE already existing in |
| @@ -3320,9 +3355,13 @@ comment at the start of cc-engine.el for more info." | |||
| 3320 | strategy (car res) | 3355 | strategy (car res) |
| 3321 | start-point (cadr res)) | 3356 | start-point (cadr res)) |
| 3322 | 3357 | ||
| 3358 | (when (eq strategy 'BOD) | ||
| 3359 | (setq c-state-cache nil | ||
| 3360 | c-state-cache-good-pos start-point)) | ||
| 3361 | |||
| 3323 | ;; SCAN! | 3362 | ;; SCAN! |
| 3324 | (cond | 3363 | (cond |
| 3325 | ((memq strategy '(forward back-and-forward)) | 3364 | ((memq strategy '(forward back-and-forward BOD)) |
| 3326 | (setq res (c-remove-stale-state-cache start-point here here-bopl)) | 3365 | (setq res (c-remove-stale-state-cache start-point here here-bopl)) |
| 3327 | (setq cache-pos (car res) | 3366 | (setq cache-pos (car res) |
| 3328 | scan-backward-pos (cadr res) | 3367 | scan-backward-pos (cadr res) |
| @@ -9571,7 +9610,6 @@ comment at the start of cc-engine.el for more info." | |||
| 9571 | (c-save-buffer-state | 9610 | (c-save-buffer-state |
| 9572 | ((indent-point (point)) | 9611 | ((indent-point (point)) |
| 9573 | (case-fold-search nil) | 9612 | (case-fold-search nil) |
| 9574 | open-paren-in-column-0-is-defun-start | ||
| 9575 | ;; A whole ugly bunch of various temporary variables. Have | 9613 | ;; A whole ugly bunch of various temporary variables. Have |
| 9576 | ;; to declare them here since it's not possible to declare | 9614 | ;; to declare them here since it's not possible to declare |
| 9577 | ;; a variable with only the scope of a cond test and the | 9615 | ;; a variable with only the scope of a cond test and the |
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 1b6a233067c..a46ee15ed5e 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -1098,10 +1098,9 @@ Note that the style variables are always made local to the buffer." | |||
| 1098 | (buffer-substring-no-properties beg end))))))) | 1098 | (buffer-substring-no-properties beg end))))))) |
| 1099 | 1099 | ||
| 1100 | (if c-get-state-before-change-functions | 1100 | (if c-get-state-before-change-functions |
| 1101 | (let (open-paren-in-column-0-is-defun-start) | 1101 | (mapc (lambda (fn) |
| 1102 | (mapc (lambda (fn) | 1102 | (funcall fn beg end)) |
| 1103 | (funcall fn beg end)) | 1103 | c-get-state-before-change-functions)) |
| 1104 | c-get-state-before-change-functions))) | ||
| 1105 | ))) | 1104 | ))) |
| 1106 | ;; The following must be done here rather than in `c-after-change' because | 1105 | ;; The following must be done here rather than in `c-after-change' because |
| 1107 | ;; newly inserted parens would foul up the invalidation algorithm. | 1106 | ;; newly inserted parens would foul up the invalidation algorithm. |
| @@ -1132,7 +1131,7 @@ Note that the style variables are always made local to the buffer." | |||
| 1132 | 1131 | ||
| 1133 | (unless (c-called-from-text-property-change-p) | 1132 | (unless (c-called-from-text-property-change-p) |
| 1134 | (setq c-just-done-before-change nil) | 1133 | (setq c-just-done-before-change nil) |
| 1135 | (c-save-buffer-state (case-fold-search open-paren-in-column-0-is-defun-start) | 1134 | (c-save-buffer-state (case-fold-search) |
| 1136 | ;; When `combine-after-change-calls' is used we might get calls | 1135 | ;; When `combine-after-change-calls' is used we might get calls |
| 1137 | ;; with regions outside the current narrowing. This has been | 1136 | ;; with regions outside the current narrowing. This has been |
| 1138 | ;; observed in Emacs 20.7. | 1137 | ;; observed in Emacs 20.7. |
| @@ -1268,8 +1267,7 @@ Note that the style variables are always made local to the buffer." | |||
| 1268 | ;; | 1267 | ;; |
| 1269 | ;; Type a space in the first blank line, and the fontification of the next | 1268 | ;; Type a space in the first blank line, and the fontification of the next |
| 1270 | ;; line was fouled up by context fontification. | 1269 | ;; line was fouled up by context fontification. |
| 1271 | (let (new-beg new-end new-region case-fold-search | 1270 | (let (new-beg new-end new-region case-fold-search) |
| 1272 | open-paren-in-column-0-is-defun-start) | ||
| 1273 | (if (and c-in-after-change-fontification | 1271 | (if (and c-in-after-change-fontification |
| 1274 | (< beg c-new-END) (> end c-new-BEG)) | 1272 | (< beg c-new-END) (> end c-new-BEG)) |
| 1275 | ;; Region and the latest after-change fontification region overlap. | 1273 | ;; Region and the latest after-change fontification region overlap. |