Commit 3f5fe0cd authored by Alan Mackenzie's avatar Alan Mackenzie
Browse files

Convert CC Mode to lexical binding in Emacs

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 _.
parent 1060289f
;;; 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)
;; Standard line-up functions
;;
......
;;; 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.
......
;;; 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)
)
......
;;; 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.
......@@ -49,12 +49,11 @@
; 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)
;; 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)
......
;;; 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.
......
;;; 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.
 
......@@ -163,6 +163,8 @@
(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)
......
;;; 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
)
......
;;; 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.
......
;;; 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)
......
;;; 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.
......
;;; 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.
......
;;; 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
......
;;; 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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment