]> git.eshelyaron.com Git - emacs.git/commitdiff
Convert CC Mode to lexical binding in Emacs
authorAlan Mackenzie <acm@muc.de>
Sat, 10 Apr 2021 19:18:28 +0000 (19:18 +0000)
committerAlan Mackenzie <acm@muc.de>
Sat, 10 Apr 2021 19:20:14 +0000 (19:20 +0000)
lisp/progmodes/cc-align.el, lisp/progmodes/cc-awk.el,
lisp/progmodes/cc-bytecomp.el, lisp/progmodes/cc-cmds.el,
lisp/progmodes/cc-defs.el, lisp/progmodes/cc-engine.el,
lisp/progmodes/cc-fonts.el, lisp/progmodes/cc-guess.el,
lisp/progmodes/cc-langs.el, lisp/progmodes/cc-menus.el,
lisp/progmodes/cc-mode.el, lisp/progmodes/cc-styles.el,
lisp/progmodes/cc-subword.el, lisp/progmodes/cc-vars.el: Mark these files with
a `lexical-binding' setting in line 1.

lisp/progmodes/cc-align.el, lisp/progmodes/cc-engine.el,
lisp/progmodes/cc-vars.el (c-syntactic-context, c-syntactic-element): Declare
these as special variables.

lisp/progmodes/cc-bytecomp.el (cc-bytecomp-debug-msg): prefix the parameter
ARGS with a _, and remove an `ignore' call.

lisp/progmodes/cc-cmds.el (c-where-wrt-brace-construct): Remove `kluge-start',
an unused variable.
(c-while-widening-to-decl-block): Add an extra parameter, which suppresses
the generation of a setting of variable `where'.
(c-defun-name-and-limits): Remove variable `where' from the function and use
the new argument to the previous macro.

lisp/progmodes/cc-engine.el (c-cache-to-parse-ps-state): Remove two unneeded
variables, `last' and `intermediate'.

lisp/progmodes/cc-fonts.el (c-font-lock-c++-using): Remove unused variable.

lisp/progmodes/cc-langs.el (c-vsemi-status-unknown-p-fn): Replace the doc
string with the more precise one from stand-alone CC Mode.

lisp/progmodes/cc-styles.el (c-set-offset): Give the `ignored' parameter a
leading _.

13 files changed:
lisp/progmodes/cc-align.el
lisp/progmodes/cc-awk.el
lisp/progmodes/cc-bytecomp.el
lisp/progmodes/cc-cmds.el
lisp/progmodes/cc-defs.el
lisp/progmodes/cc-engine.el
lisp/progmodes/cc-fonts.el
lisp/progmodes/cc-guess.el
lisp/progmodes/cc-langs.el
lisp/progmodes/cc-menus.el
lisp/progmodes/cc-mode.el
lisp/progmodes/cc-styles.el
lisp/progmodes/cc-vars.el

index 51d51deef714e2f5535e423e2abc3bdcac00d1b9..9234d0b19b95d60e93f66565c7e8bacb818fff62 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-align.el --- custom indentation functions for CC Mode
+;;; cc-align.el --- custom indentation functions for CC Mode -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
@@ -44,6 +44,9 @@
 (cc-require 'cc-vars)
 (cc-require 'cc-engine)
 
+(defvar c-syntactic-context)
+(defvar c-syntactic-element)
+
 \f
 ;; Standard line-up functions
 ;;
index 322894437256e9e7e99f05633875a9c442470b65..84cc5b115e79325dbd3787baaaf1db7ffe585cb7 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-awk.el --- AWK specific code within cc-mode.
+;;; cc-awk.el --- AWK specific code within cc-mode. -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1988, 1994, 1996, 2000-2021 Free Software Foundation,
 ;; Inc.
index 3f7caf3c2e9601ae130529f9db57654874c3d39e..29f4b81637db4c1221d751300f9527db0aadedb0 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-bytecomp.el --- compile time setup for proper compilation
+;;; cc-bytecomp.el --- compile time setup for proper compilation -*- lexical-binding: t -*-
 
 ;; Copyright (C) 2000-2021 Free Software Foundation, Inc.
 
@@ -85,8 +85,7 @@
 
 (defvar cc-bytecomp-environment-set nil)
 
-(defmacro cc-bytecomp-debug-msg (&rest args)
-  (ignore args)
+(defmacro cc-bytecomp-debug-msg (&rest _args) ; Change to ARGS when needed.
   ;;`(message ,@args)
   )
 
index c89494482716d1541e6b9386b4bccb8abb7e7c16..bee87b6849958ae4bc76a49901605535bd21ae9f 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-cmds.el --- user level commands for CC Mode
+;;; cc-cmds.el --- user level commands for CC Mode -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
                                        ; which looks at this.
 (cc-bytecomp-defun electric-pair-post-self-insert-function)
 (cc-bytecomp-defvar c-indent-to-body-directives)
+(defvar c-syntactic-context)
 \f
 ;; Indentation / Display syntax functions
 (defvar c-fix-backslashes t)
 
-(defvar c-syntactic-context)
-
 (defun c-indent-line (&optional syntax quiet ignore-point-pos)
   "Indent the current line according to the syntactic context,
 if `c-syntactic-indentation' is non-nil.  Optional SYNTAX is the
@@ -1220,9 +1219,9 @@ numeric argument is supplied, or the point is inside a literal."
       (self-insert-command (prefix-numeric-value arg)))
     (setq final-pos (point))
 
-;;;; 2010-01-31: There used to be code here to put a syntax-table text
-;;;; property on the new < or > and its mate (if any) when they are template
-;;;; parens.  This is now done in an after-change function.
+;;;;  2010-01-31: There used to be code here to put a syntax-table text
+;;;;  property on the new < or > and its mate (if any) when they are template
+;;;;  parens.  This is now done in an after-change function.
 
     (when (and (not arg) (not literal))
       ;; Have we got a delimiter on a #include directive?
@@ -1639,9 +1638,8 @@ No indentation or other \"electric\" behavior is performed."
   ;;
   ;; This function might do hidden buffer changes.
   (save-excursion
-    (let* (kluge-start
-          knr-start knr-res
-          decl-result brace-decl-p
+    (let* (knr-start knr-res
+          decl-result
           (start (point))
           (paren-state (c-parse-state))
           (least-enclosing (c-least-enclosing-brace paren-state)))
@@ -1676,7 +1674,6 @@ No indentation or other \"electric\" behavior is performed."
        (if (or (and (eolp) (not (eobp))) ; EOL is matched by "\\s>"
                (not (c-looking-at-non-alphnumspace)))
            (forward-char))
-       (setq kluge-start (point))
 
        (if (and least-enclosing
                 (eq (char-after least-enclosing) ?\())
@@ -1827,12 +1824,14 @@ No indentation or other \"electric\" behavior is performed."
       nil)))
 
 (eval-and-compile
-  (defmacro c-while-widening-to-decl-block (condition)
+  (defmacro c-while-widening-to-decl-block (condition &optional no-where)
     ;; Repeatedly evaluate CONDITION until it returns nil.  After each
     ;; evaluation, if `c-defun-tactic' is set appropriately, widen to innards
     ;; of the next enclosing declaration block (e.g. namespace, class), or the
     ;; buffer's original restriction.
     ;;
+    ;; If NO-WHERE is non-nil, don't compile in a `(setq where ....)'.
+    ;;
     ;; This is a very special purpose macro, which assumes the existence of
     ;; several variables.  It is for use only in c-beginning-of-defun and
     ;; c-end-of-defun.
@@ -1843,7 +1842,8 @@ No indentation or other \"electric\" behavior is performed."
        (setq paren-state (c-whack-state-after lim paren-state))
        (setq lim (c-widen-to-enclosing-decl-scope
                  paren-state orig-point-min orig-point-max))
-       (setq where 'in-block))))
+       ,@(if (not no-where)
+            `((setq where 'in-block))))))
 
 (def-edebug-spec c-while-widening-to-decl-block t)
 
@@ -2324,11 +2324,11 @@ with a brace block, at the outermost level of nesting."
        (c-save-buffer-state ((paren-state (c-parse-state))
                              (orig-point-min (point-min))
                              (orig-point-max (point-max))
-                             lim name limits where)
+                             lim name limits)
          (setq lim (c-widen-to-enclosing-decl-scope
                     paren-state orig-point-min orig-point-max))
          (and lim (setq lim (1- lim)))
-         (c-while-widening-to-decl-block (not (setq name (c-defun-name-1))))
+         (c-while-widening-to-decl-block (not (setq name (c-defun-name-1))) t)
          (when name
            (setq limits (c-declaration-limits-1 near))
            (cons name limits)))
@@ -2944,10 +2944,13 @@ function does not require the declaration to contain a brace block."
                         (c-looking-at-special-brace-list)))
               (or allow-early-stop (/= here last))
               (save-excursion  ; Is this a check that we're NOT at top level?
-;;;; NO!  This seems to check that (i) EITHER we're at the top level; OR (ii) The next enclosing
-;;;; level of bracketing is a '{'.  HMM.  Doesn't seem to make sense.
-;;;; 2003/8/8 This might have something to do with the GCC extension "Statement Expressions", e.g.
-;;;; while ({stmt1 ; stmt2 ; exp ;}).  This form excludes such Statement Expressions.
+;;;;  NO!  This seems to check that (i) EITHER we're at the top level;
+;;;;  OR (ii) The next enclosing  level of bracketing is a '{'.  HMM.
+;;;;  Doesn't seem to make sense.
+;;;;  2003/8/8 This might have something to do with the GCC extension
+;;;;  "Statement Expressions", e.g.
+;;;;  while ({stmt1 ; stmt2 ; exp ;}).
+;;;;  This form excludes such Statement Expressions.
                 (or (not (c-safe (up-list -1) t))
                     (= (char-after) ?{))))
          (goto-char last)
index 536e676626116d89dbe6119ea3943d8c3244c7cd..20dc97db5d7f2a5811d11ccc16942bab243f6120 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-defs.el --- compile time definitions for CC Mode
+;;; cc-defs.el --- compile time definitions for CC Mode -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
index cc9833a434eab80040ad958a544645808e47ee75..747a6fd4eda8b527ff4084463509ccb86c2632aa 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-engine.el --- core syntax guessing engine for CC mode -*- coding: utf-8 -*-
+;;; cc-engine.el --- core syntax guessing engine for CC mode -*- lexical-binding:t; coding: utf-8 -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
 (defvar c-doc-line-join-re)
 (defvar c-doc-bright-comment-start-re)
 (defvar c-doc-line-join-end-ch)
+(defvar c-syntactic-context)
+(defvar c-syntactic-element)
 (cc-bytecomp-defvar c-min-syn-tab-mkr)
 (cc-bytecomp-defvar c-max-syn-tab-mkr)
 (cc-bytecomp-defun c-clear-syn-tab)
@@ -2717,9 +2719,9 @@ comment at the start of cc-engine.el for more info."
   ;; two char construct (such as a comment opener or an escaped character).)
   (if (and (consp elt) (>= (length elt) 3))
       ;; Inside a string or comment
-      (let ((depth 0) (containing nil) (last nil)
+      (let ((depth 0) (containing nil)
            in-string in-comment
-           (min-depth 0) com-style com-str-start (intermediate nil)
+           (min-depth 0) com-style com-str-start
            (char-1 (nth 3 elt))        ; first char of poss. 2-char construct
            (pos (car elt))
            (type (cadr elt)))
@@ -2736,14 +2738,13 @@ comment at the start of cc-engine.el for more info."
                       (1- pos)
                     pos))
        (if (memq 'pps-extended-state c-emacs-features)
-           (list depth containing last
+           (list depth containing nil
                  in-string in-comment nil
                  min-depth com-style com-str-start
-                 intermediate nil)
-         (list depth containing last
+                 nil nil)
+         (list depth containing nil
                in-string in-comment nil
-               min-depth com-style com-str-start
-               intermediate)))
+               min-depth com-style com-str-start nil)))
 
     ;; Not in a string or comment.
     (if (memq 'pps-extended-state c-emacs-features)
index 4e283764ceb9fd29c00ec7193a81b1693cdc8b44..433b4dcf4a8240effa99daccae89638f4a54e736 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-fonts.el --- font lock support for CC Mode
+;;; cc-fonts.el --- font lock support for CC Mode -*- lexical-binding: t -*-
 
 ;; Copyright (C) 2002-2021 Free Software Foundation, Inc.
 
@@ -2287,7 +2287,7 @@ need for `c-font-lock-extra-types'.")
   ;; font-lock-keyword-face.  It always returns NIL to inhibit this and
   ;; prevent a repeat invocation.  See elisp/lispref page "Search-based
   ;; fontification".
-  (let (pos after-name)
+  (let (pos)
     (while (c-syntactic-re-search-forward c-using-key limit 'end)
       (while  ; Do one declarator of a comma separated list, each time around.
          (progn
@@ -2295,7 +2295,6 @@ need for `c-font-lock-extra-types'.")
            (setq pos (point))          ; token after "using".
            (when (and (c-on-identifier)
                       (c-forward-name))
-             (setq after-name (point))
              (cond
               ((eq (char-after) ?=)            ; using foo = <type-id>;
                (goto-char pos)
@@ -2305,7 +2304,8 @@ need for `c-font-lock-extra-types'.")
                       (c-go-up-list-backward)
                       (eq (char-after) ?{)
                       (eq (car (c-beginning-of-decl-1
-                                (c-determine-limit 1000))) 'same)
+                                (c-determine-limit 1000)))
+                          'same)
                       (looking-at c-colon-type-list-re)))
                ;; Inherited protected member: leave unfontified
                )
index 1b852ec49106a60799fc3747e4e280c91eaba9be..0824af66b4356cb30a4d00bddda31f16ec899ac6 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-guess.el --- guess indentation values by scanning existing code
+;;; cc-guess.el --- guess indentation values by scanning existing code -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2006, 2011-2021 Free Software
 ;; Foundation, Inc.
index fa4e73087efb61858be4932926f21683dbd1c486..28a1565427772940a7c80e375c61ed1fa3a7f929 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-langs.el --- language specific settings for CC Mode -*- coding: utf-8 -*-
+;;; cc-langs.el --- language specific settings for CC Mode -*- lexical-binding: t; coding: utf-8 -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
@@ -579,14 +579,12 @@ don't have EOL terminated statements. "
 (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
 
 (c-lang-defconst c-vsemi-status-unknown-p-fn
-  "Contains a predicate regarding the presence of virtual semicolons.
-More precisely, the function answers the question, \"are we unsure whether a
-virtual semicolon exists on this line?\".  The (admittedly kludgy) purpose of
-such a function is to prevent an infinite recursion in
-`c-beginning-of-statement-1' when point starts at a `while' token.  The function
-MUST NOT UNDER ANY CIRCUMSTANCES call `c-beginning-of-statement-1', even
-indirectly.  This variable contains nil for languages which don't have EOL
-terminated statements."
+  "A function \"are we unsure whether there is a virtual semicolon on this line?\".
+The (admittedly kludgy) purpose of such a function is to prevent an infinite
+recursion in c-beginning-of-statement-1 when point starts at a `while' token.
+The function MUST NOT UNDER ANY CIRCUMSTANCES call `c-beginning-of-statement-1',
+even indirectly.  This variable contains nil for languages which don't have
+EOL terminated statements."
   t nil
   (c c++ objc) 'c-macro-vsemi-status-unknown-p
   awk 'c-awk-vsemi-status-unknown-p)
index 0ff6efb7d373bd93a505ce40e2f87bd3bdbf79be..a099ec1de95a4b2c999970eb6d8d486e422ec206 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-menus.el --- imenu support for CC Mode
+;;; cc-menus.el --- imenu support for CC Mode -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
index cfb23d0d45eab62af43ce171096d1e0d7513ef03..dae0062efb5eaf22391245cb06434f6a8a60f09e 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-mode.el --- major mode for editing C and similar languages
+;;; cc-mode.el --- major mode for editing C and similar languages -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
index 29cbe54c3bdcd8c8f89bcc2e743a8f65c7fb2d1e..77cad77711a9e6d65a67aa928536d8c6091058b0 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-styles.el --- support for styles in CC Mode
+;;; cc-styles.el --- support for styles in CC Mode -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
@@ -464,7 +464,7 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
     offset))
 
 ;;;###autoload
-(defun c-set-offset (symbol offset &optional ignored)
+(defun c-set-offset (symbol offset &optional _ignored)
   "Change the value of a syntactic element symbol in `c-offsets-alist'.
 SYMBOL is the syntactic element symbol to change and OFFSET is the new
 offset for that syntactic element.  The optional argument is not used
index 88ee092da791b5928483baea441bfcf713e9b03b..b33fea0b48c5ac184f9aa416c234ea1073310e5d 100644 (file)
@@ -1,4 +1,4 @@
-;;; cc-vars.el --- user customization variables for CC Mode
+;;; cc-vars.el --- user customization variables for CC Mode -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1987, 1992-2021 Free Software Foundation, Inc.
 
@@ -42,6 +42,9 @@
 
 (cc-require 'cc-defs)
 
+(defvar c-syntactic-context)
+(defvar c-syntactic-element)
+
 (cc-eval-when-compile
   (require 'custom)
   (require 'widget))