From 3f22bfba9b15f52137ad2f3e19b5e9e154ade0f8 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 5 Apr 2021 13:43:09 -0400 Subject: [PATCH 2/4] * lisp/progmodes/cc-*.el: Use `declare` in macros This converts most uses of `def-edebug-spec` and (put..list-indent-function..) to use `declare` instead. I left those in `cc-defs.el` because there were too many, and I left those applied to functions since Emacs-21 only supports `declare` in `defmacro` and not in `defun`. * lisp/progmodes/cc-langs.el (c-lang-defvar, c-lang-setvar): * lisp/progmodes/cc-fonts.el (c-put-font-lock-face) (c-remove-font-lock-face, c-put-font-lock-string-face) (c-fontify-types-and-refs, c-font-lock-doc-comments): * lisp/progmodes/cc-defs.el (cc-eval-when-compile, c-safe) (c-tentative-buffer-changes, c-with-syntax-table, c-lang-defconst): * lisp/progmodes/cc-cmds.el (c-while-widening-to-decl-block): * lisp/progmodes/cc-engine.el (c-bos-pop-state) (c-bos-save-error-info, c-put-is-sws, c-put-in-sws, c-remove-is-sws) (c-remove-in-sws, c-remove-is-and-in-sws, c-state-cache-top-lparen) (c-state-cache-top-paren, c-state-cache-after-top-paren) (c-state-maybe-marker, c-record-type-id, c-record-ref-id) (c-forward-keyword-prefixed-id, c-forward-id-comma-list) (c-pull-open-brace): Use `declare` for indent and debug specs. --- lisp/progmodes/cc-cmds.el | 3 +-- lisp/progmodes/cc-defs.el | 21 +++++++-------------- lisp/progmodes/cc-engine.el | 33 ++++++++++++++++----------------- lisp/progmodes/cc-fonts.el | 15 +++++---------- lisp/progmodes/cc-langs.el | 12 ++++-------- 5 files changed, 33 insertions(+), 51 deletions(-) diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index f7f2b10b7c..87ac076ee4 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el @@ -1819,6 +1819,7 @@ c-widen-to-enclosing-decl-scope ;; 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. + (declare (debug t)) `(while (and ,condition (eq c-defun-tactic 'go-outward) @@ -1828,8 +1829,6 @@ c-widen-to-enclosing-decl-scope paren-state orig-point-min orig-point-max)) (setq where 'in-block)))) -(def-edebug-spec c-while-widening-to-decl-block t) - (defun c-beginning-of-defun (&optional arg) "Move backward to the beginning of a defun. Every top level declaration that contains a brace paren block is diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el index bfad72b7f2..3072733d4d 100644 --- a/lisp/progmodes/cc-defs.el +++ b/lisp/progmodes/cc-defs.el @@ -125,7 +125,7 @@ c-syntax-table-hwm This variant works around bugs in `eval-when-compile' in various \(X)Emacs versions. See cc-defs.el for details." - + (declare (indent 0) (debug t)) (if c-inside-eval-when-compile ;; XEmacs 21.4.6 has a bug in `eval-when-compile' in that it ;; evaluates its body at macro expansion time if it's nested @@ -170,9 +170,7 @@ c-syntax-table-hwm ;; constant that we eval. That otoh introduce a problem in ;; that a returned lambda expression doesn't get byte ;; compiled (even if `function' is used). - (eval '(let ((c-inside-eval-when-compile t)) ,@body))))) - - (put 'cc-eval-when-compile 'lisp-indent-hook 0)) + (eval '(let ((c-inside-eval-when-compile t)) ,@body)))))) ;;; Macros. @@ -505,10 +503,10 @@ c-delete-and-extract-region (defmacro c-safe (&rest body) ;; safely execute BODY, return nil if an error occurred + (declare (indent 0) (debug t)) `(condition-case nil (progn ,@body) (error nil))) -(put 'c-safe 'lisp-indent-function 0) (defmacro c-int-to-char (integer) ;; In Emacs, a character is an integer. In XEmacs, a character is a @@ -628,6 +626,7 @@ c-tentative-buffer-changes macro inside `c-save-buffer-state'. That way the change can be done even when the buffer is read-only, and without interference from various buffer change hooks." + (declare (indent 0) (debug t)) `(let (-tnt-chng-keep -tnt-chng-state) (unwind-protect @@ -638,7 +637,6 @@ c-tentative-buffer-changes -tnt-chng-state (c-tnt-chng-record-state) -tnt-chng-keep (progn ,@body)) (c-tnt-chng-cleanup -tnt-chng-keep -tnt-chng-state)))) -(put 'c-tentative-buffer-changes 'lisp-indent-function 0) (defun c-tnt-chng-record-state () ;; Used internally in `c-tentative-buffer-changes'. @@ -993,6 +991,7 @@ c-with-syntax-table ;; way to execute code. ;; Maintainers' note: If TABLE is `c++-template-syntax-table', DON'T call ;; any forms inside this that call `c-parse-state'. !!!! + (declare (indent 1) (debug t)) ;; FIXME: Use `with-syntax-table' (introduced in Emacs-21.1)? `(let ((c-with-syntax-table-orig-table (syntax-table))) (unwind-protect @@ -1000,7 +999,6 @@ c-with-syntax-table (set-syntax-table ,table) ,@code) (set-syntax-table c-with-syntax-table-orig-table)))) -(put 'c-with-syntax-table 'lisp-indent-function 1) (defmacro c-skip-ws-forward (&optional limit) "Skip over any whitespace following point. @@ -2397,7 +2395,8 @@ c-lang-defconst already is one it will be completely replaced; the value in the earlier definition will not affect `c-lang-const' on the same constant. A file is identified by its base name." - + (declare (indent 1) + (debug (&define name [&optional stringp] [&rest sexp def-form]))) (let* ((sym (intern (symbol-name name) c-lang-constants)) ;; Make `c-lang-const' expand to a straightforward call to ;; `c-get-lang-constant' in `c--macroexpand-all' below. @@ -2488,12 +2487,6 @@ c-lang-defconst (c-define-lang-constant ',name ,bindings ,@(and pre-files `(',pre-files)))))) -(put 'c-lang-defconst 'lisp-indent-function 1) -;(eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el. -; ' -(def-edebug-spec c-lang-defconst - (&define name [&optional stringp] [&rest sexp def-form])) - (defun c-define-lang-constant (name bindings &optional pre-files) ;; Used by `c-lang-defconst'. diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 8634f7c63f..56d33ac117 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -735,6 +735,7 @@ c-bos-push-state '(setq stack (cons (cons state saved-pos) stack))) (defmacro c-bos-pop-state (&optional do-if-done) + (declare (debug t)) `(if (setq state (car (car stack)) saved-pos (cdr (car stack)) stack (cdr stack)) @@ -759,6 +760,7 @@ c-bos-restore-pos (goto-char pos) (setq sym nil))) (defmacro c-bos-save-error-info (missing got) + (declare (debug t)) `(setq saved-pos (vector pos ,missing ,got))) (defmacro c-bos-report-error () '(unless noerror @@ -1876,44 +1878,44 @@ c-debug-sws-msg (defmacro c-put-is-sws (beg end) ;; This macro does a hidden buffer change. + (declare (debug t)) `(let ((beg ,beg) (end ,end)) (put-text-property beg end 'c-is-sws t) ,@(when (facep 'c-debug-is-sws-face) '((c-debug-add-face beg end 'c-debug-is-sws-face))))) -(def-edebug-spec c-put-is-sws t) (defmacro c-put-in-sws (beg end) ;; This macro does a hidden buffer change. + (declare (debug t)) `(let ((beg ,beg) (end ,end)) (put-text-property beg end 'c-in-sws t) ,@(when (facep 'c-debug-is-sws-face) '((c-debug-add-face beg end 'c-debug-in-sws-face))))) -(def-edebug-spec c-put-in-sws t) (defmacro c-remove-is-sws (beg end) ;; This macro does a hidden buffer change. + (declare (debug t)) `(let ((beg ,beg) (end ,end)) (remove-text-properties beg end '(c-is-sws nil)) ,@(when (facep 'c-debug-is-sws-face) '((c-debug-remove-face beg end 'c-debug-is-sws-face))))) -(def-edebug-spec c-remove-is-sws t) (defmacro c-remove-in-sws (beg end) ;; This macro does a hidden buffer change. + (declare (debug t)) `(let ((beg ,beg) (end ,end)) (remove-text-properties beg end '(c-in-sws nil)) ,@(when (facep 'c-debug-is-sws-face) '((c-debug-remove-face beg end 'c-debug-in-sws-face))))) -(def-edebug-spec c-remove-in-sws t) (defmacro c-remove-is-and-in-sws (beg end) ;; This macro does a hidden buffer change. + (declare (debug t)) `(let ((beg ,beg) (end ,end)) (remove-text-properties beg end '(c-is-sws nil c-in-sws nil)) ,@(when (facep 'c-debug-is-sws-face) '((c-debug-remove-face beg end 'c-debug-is-sws-face) (c-debug-remove-face beg end 'c-debug-in-sws-face))))) -(def-edebug-spec c-remove-is-and-in-sws t) ;; The type of literal position `end' is in a `before-change-functions' ;; function - one of `c', `c++', `pound', `noise', `attribute' or nil (but NOT @@ -3516,6 +3518,7 @@ c-state-brace-pair-desert (defmacro c-state-cache-top-lparen (&optional cache) ;; Return the address of the top left brace/bracket/paren recorded in CACHE ;; (default `c-state-cache') (or nil). + (declare (debug t)) (let ((cash (or cache 'c-state-cache))) `(if (consp (car ,cash)) (caar ,cash) @@ -3524,6 +3527,7 @@ c-state-cache-top-lparen (defmacro c-state-cache-top-paren (&optional cache) ;; Return the address of the latest brace/bracket/paren (whether left or ;; right) recorded in CACHE (default `c-state-cache') or nil. + (declare (debug t)) (let ((cash (or cache 'c-state-cache))) `(if (consp (car ,cash)) (cdar ,cash) @@ -3532,6 +3536,7 @@ c-state-cache-top-paren (defmacro c-state-cache-after-top-paren (&optional cache) ;; Return the position just after the latest brace/bracket/paren (whether ;; left or right) recorded in CACHE (default `c-state-cache') or nil. + (declare (debug t)) (let ((cash (or cache 'c-state-cache))) `(if (consp (car ,cash)) (cdar ,cash) @@ -4486,6 +4491,7 @@ c-invalidate-state-cache (defmacro c-state-maybe-marker (place marker) ;; If PLACE is non-nil, return a marker marking it, otherwise nil. ;; We (re)use MARKER. + (declare (debug (form symbolp))) `(let ((-place- ,place)) (and -place- (or ,marker (setq ,marker (make-marker))) @@ -7773,6 +7779,7 @@ c-record-ref-identifiers (defvar c-last-identifier-range nil) (defmacro c-record-type-id (range) + (declare (debug t)) (if (eq (car-safe range) 'cons) ;; Always true. `(setq c-record-type-identifiers @@ -7783,6 +7790,7 @@ c-record-type-id (cons range c-record-type-identifiers)))))) (defmacro c-record-ref-id (range) + (declare (debug t)) (if (eq (car-safe range) 'cons) ;; Always true. `(setq c-record-ref-identifiers @@ -7808,6 +7816,7 @@ c-forward-keyword-prefixed-id ;; if TYPE is 'type or as a reference if TYPE is 'ref. ;; ;; This macro might do hidden buffer changes. + (declare (debug t)) `(let (res) (setq c-last-identifier-range nil) (while (if (setq res ,(if (eq type 'type) @@ -7832,6 +7841,7 @@ c-forward-id-comma-list ;; `c-forward-keyword-prefixed-id'. ;; ;; This macro might do hidden buffer changes. + (declare (debug t)) `(while (and (progn ,(when update-safe-pos '(setq safe-pos (point))) @@ -8775,6 +8785,7 @@ c-forward-annotation (defmacro c-pull-open-brace (ps) ;; Pull the next open brace from PS (which has the form of paren-state), ;; skipping over any brace pairs. Returns NIL when PS is exhausted. + (declare (debug (symbolp))) `(progn (while (consp (car ,ps)) (setq ,ps (cdr ,ps))) @@ -14685,18 +14696,6 @@ c-get-syntactic-indentation (current-column))) indent))) - -(def-edebug-spec c-bos-pop-state t) -(def-edebug-spec c-bos-save-error-info t) -(def-edebug-spec c-state-cache-top-lparen t) -(def-edebug-spec c-state-cache-top-paren t) -(def-edebug-spec c-state-cache-after-top-paren t) -(def-edebug-spec c-state-maybe-marker (form symbolp)) -(def-edebug-spec c-record-type-id t) -(def-edebug-spec c-record-ref-id t) -(def-edebug-spec c-forward-keyword-prefixed-id t) -(def-edebug-spec c-forward-id-comma-list t) -(def-edebug-spec c-pull-open-brace (symbolp)) (cc-provide 'cc-engine) diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 57e5dccfd7..3567f5e76e 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -218,6 +218,7 @@ c-annotation-face ;; incorrectly. ;; ;; This function does a hidden buffer change. + (declare (debug t)) (if (fboundp 'font-lock-set-face) ;; Note: This function has no docstring in XEmacs so it might be ;; considered internal. @@ -228,6 +229,7 @@ c-annotation-face ;; This is the inverse of `c-put-font-lock-face'. ;; ;; This function does a hidden buffer change. + (declare (debug t)) (if (fboundp 'font-lock-remove-face) `(font-lock-remove-face ,from ,to) `(remove-text-properties ,from ,to '(face nil)))) @@ -238,11 +240,13 @@ c-annotation-face ;; region should include them. ;; ;; This function does a hidden buffer change. + (declare (debug t)) (if (featurep 'xemacs) `(c-put-font-lock-face (1+ ,from) (1- ,to) 'font-lock-string-face) `(c-put-font-lock-face ,from ,to 'font-lock-string-face))) (defmacro c-fontify-types-and-refs (varlist &rest body) + (declare (indent 1) (debug let*)) ;; Like `let', but additionally activates `c-record-type-identifiers' ;; and `c-record-ref-identifiers', and fontifies the recorded ranges ;; accordingly on exit. @@ -253,7 +257,6 @@ c-annotation-face ,@varlist) (prog1 (progn ,@body) (c-fontify-recorded-types-and-refs)))) - (put 'c-fontify-types-and-refs 'lisp-indent-function 1) (defun c-skip-comments-and-strings (limit) ;; If the point is within a region fontified as a comment or @@ -486,13 +489,6 @@ c-annotation-face ,(c-make-font-lock-search-form (car normal) (cdr normal) t) nil)))) -; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el. -; '(progn -(def-edebug-spec c-put-font-lock-face t) -(def-edebug-spec c-remove-font-lock-face t) -(def-edebug-spec c-put-font-lock-string-face t) - (def-edebug-spec c-fontify-types-and-refs let*) - (def-edebug-spec c-make-syntactic-matcher t) ;; If there are literal quoted or backquoted highlight specs in ;; the call to `c-make-font-lock-search-function' then let's ;; instrument the forms in them. @@ -2788,7 +2784,7 @@ c-font-lock-doc-comments ;; is used as a flag in other code to skip comments. ;; ;; This function might do hidden buffer changes. - + (declare (indent 2)) (let (comment-beg region-beg) (if (memq (get-text-property (point) 'face) '(font-lock-comment-face font-lock-comment-delimiter-face)) @@ -2871,7 +2867,6 @@ c-font-lock-doc-comments (goto-char region-end))))) nil) -(put 'c-font-lock-doc-comments 'lisp-indent-function 2) (defun c-find-invalid-doc-markup (regexp limit) ;; Used to fontify invalid markup in doc comments after the correct diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index fa4e73087e..9edef527d8 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -159,7 +159,9 @@ c-lang-defvar `c-lang-const' is typically used in VAL to get the right value for the language being initialized, and such calls will be macro expanded to the evaluated constant value at compile time." - + (declare (indent defun) + (debug (&define name def-form + &optional &or ("quote" symbolp) stringp))) (when (and (not doc) (eq (car-safe val) 'c-lang-const) (eq (nth 1 val) var) @@ -191,6 +193,7 @@ c-lang-setvar `c-lang-const' is typically used in VAL to get the right value for the language being initialized, and such calls will be macro expanded to the evaluated constant value at compile time." + (declare (debug (&define name def-form))) (let ((elem (assq var (cdr c-emacs-variable-inits)))) (if elem (setcdr elem (list val)) ; Maybe remove "list", sometime. 2006-07-19 @@ -200,13 +203,6 @@ c-lang-setvar ;; Return the symbol, like the other def* forms. `',var) -(put 'c-lang-defvar 'lisp-indent-function 'defun) -; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el. -; ' -(def-edebug-spec c-lang-defvar - (&define name def-form &optional &or ("quote" symbolp) stringp)) -(def-edebug-spec c-lang-setvar (&define name def-form)) - ;; Suppress "might not be defined at runtime" warning. ;; This file is only used when compiling other cc files. (declare-function cl-delete-duplicates "cl-seq" (cl-seq &rest cl-keys)) -- 2.30.2