From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#21466: [PATCH] Avoid defining (temporarily) vars and functions Date: Wed, 23 Mar 2022 21:13:35 +0100 Message-ID: <87y2105swg.fsf@gnus.org> References: <87eeeestgu.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28103"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Stefan Monnier , 21466@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 23 21:14:12 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nX7Mx-0007Ax-JL for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 23 Mar 2022 21:14:11 +0100 Original-Received: from localhost ([::1]:39148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nX7Mw-00052o-40 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 23 Mar 2022 16:14:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:35126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX7Mo-00050E-Ss for bug-gnu-emacs@gnu.org; Wed, 23 Mar 2022 16:14:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nX7Mo-0001sa-9O; Wed, 23 Mar 2022 16:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nX7Mo-0007vC-2G; Wed, 23 Mar 2022 16:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Wed, 23 Mar 2022 20:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21466 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: patch Original-Received: via spool by 21466-submit@debbugs.gnu.org id=B21466.164806644130436 (code B ref 21466); Wed, 23 Mar 2022 20:14:02 +0000 Original-Received: (at 21466) by debbugs.gnu.org; 23 Mar 2022 20:14:01 +0000 Original-Received: from localhost ([127.0.0.1]:46134 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nX7Mm-0007up-BZ for submit@debbugs.gnu.org; Wed, 23 Mar 2022 16:14:00 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:50212) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nX7Mi-0007uZ-PK for 21466@debbugs.gnu.org; Wed, 23 Mar 2022 16:13:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=apqPH2pEVYFqXlmIt59mUW7pTbNU+1pvHiL1Rx5dP0Q=; b=Oax2VhkFTwE0Xq9+Mmid6ERB/F D4AJM6T2KU9nZNAQSxq5fqstA6PyrcLdUIrMFTyEDmTSqMz0BSmCniTFA7cZs2HvqLqqeLGRTocys n55q2rJGf8R5A1MIOMKOqtDxNe1mkMmOt58SHHkgGJNBUS9wJ4SGwaPyECWjjXgasIok=; Original-Received: from 109.179.236.69.tmi.telenormobil.no ([109.179.236.69] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nX7MT-0007qB-Rw; Wed, 23 Mar 2022 21:13:44 +0100 In-Reply-To: (Alan Mackenzie's message of "Tue, 11 May 2021 20:34:30 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:228835 Archived-At: Alan Mackenzie writes: > So, I don't object on principle to the principle of the patch, just > there are these little irritations about it, and it will need me to > study it more closely to check nothing subtle would get lost (I doubt it > would). The patch no longer applied to Emacs 29, so I've respun it. diff --git a/lisp/progmodes/cc-bytecomp.el b/lisp/progmodes/cc-bytecomp.el index 4b8154dafe..277ba29a89 100644 --- a/lisp/progmodes/cc-bytecomp.el +++ b/lisp/progmodes/cc-bytecomp.el @@ -75,12 +75,10 @@ (defvar cc-bytecomp-unbound-variables nil) (defvar cc-bytecomp-original-functions nil) -(defvar cc-bytecomp-original-properties nil) (defvar cc-bytecomp-loaded-files nil) (setq cc-bytecomp-unbound-variables nil) (setq cc-bytecomp-original-functions nil) -(setq cc-bytecomp-original-properties nil) (setq cc-bytecomp-loaded-files nil) (defvar cc-bytecomp-environment-set nil) @@ -177,16 +175,6 @@ cc-bytecomp-setup-environment (cc-bytecomp-debug-msg "cc-bytecomp-setup-environment: Covered function %s" fun)))) (setq p (cdr p))) - (setq p cc-bytecomp-original-properties) - (while p - (let ((sym (car (car (car p)))) - (prop (cdr (car (car p)))) - (tempdef (car (cdr (car p))))) - (put sym prop tempdef) - (cc-bytecomp-debug-msg - "cc-bytecomp-setup-environment: Bound property %s for %s to %s" - prop sym tempdef)) - (setq p (cdr p))) (setq cc-bytecomp-environment-set t) (cc-bytecomp-debug-msg "cc-bytecomp-setup-environment: Done")))) @@ -236,22 +224,6 @@ cc-bytecomp-restore-environment "cc-bytecomp-restore-environment: Not restoring function %s" fun)))) (setq p (cdr p))) - (setq p cc-bytecomp-original-properties) - (while p - (let ((sym (car (car (car p)))) - (prop (cdr (car (car p)))) - (tempdef (car (cdr (car p)))) - (origdef (cdr (cdr (car p))))) - (if (eq (get sym prop) tempdef) - (progn - (put sym prop origdef) - (cc-bytecomp-debug-msg - "cc-bytecomp-restore-environment: Restored property %s for %s to %s" - prop sym origdef)) - (cc-bytecomp-debug-msg - "cc-bytecomp-restore-environment: Not restoring property %s for %s" - prop sym))) - (setq p (cdr p))) (setq cc-bytecomp-environment-set nil) (cc-bytecomp-debug-msg "cc-bytecomp-restore-environment: Done")))) @@ -385,23 +357,26 @@ cc-bytecomp-defvar This can be used to silence the byte compiler. Don't use within `eval-when-compile'." (declare (debug nil)) - `(eval-when-compile - (if (boundp ',var) - (cc-bytecomp-debug-msg - "cc-bytecomp-defvar: %s bound already as variable" ',var) - (if (not (memq ',var cc-bytecomp-unbound-variables)) - (progn - (cc-bytecomp-debug-msg - "cc-bytecomp-defvar: Saving %s (as unbound)" ',var) - (setq cc-bytecomp-unbound-variables - (cons ',var cc-bytecomp-unbound-variables)))) - (if (cc-bytecomp-is-compiling) - (progn - (defvar ,var) - (set ',var (intern (concat "cc-bytecomp-ignore-var:" - (symbol-name ',var)))) - (cc-bytecomp-debug-msg - "cc-bytecomp-defvar: Covered variable %s" ',var)))))) + (if (not (featurep 'xemacs)) + `(defvar ,var) + ;; Not sure if XEmacs's `defvar' works in the same way. + `(eval-when-compile + (if (boundp ',var) + (cc-bytecomp-debug-msg + "cc-bytecomp-defvar: %s bound already as variable" ',var) + (if (not (memq ',var cc-bytecomp-unbound-variables)) + (progn + (cc-bytecomp-debug-msg + "cc-bytecomp-defvar: Saving %s (as unbound)" ',var) + (setq cc-bytecomp-unbound-variables + (cons ',var cc-bytecomp-unbound-variables)))) + (if (cc-bytecomp-is-compiling) + (progn + (defvar ,var) + (set ',var (intern (concat "cc-bytecomp-ignore-var:" + (symbol-name ',var)))) + (cc-bytecomp-debug-msg + "cc-bytecomp-defvar: Covered variable %s" ',var))))))) (defmacro cc-bytecomp-defun (fun) "Bind the symbol FUN as a function during compilation of the file. @@ -414,42 +389,25 @@ cc-bytecomp-defun existing functions since the byte compiler might need the definition at compile time, e.g. for macros and inline functions." (declare (debug nil)) - `(eval-when-compile - (if (fboundp ',fun) - (cc-bytecomp-debug-msg - "cc-bytecomp-defun: %s bound already as function" ',fun) - (if (not (assq ',fun cc-bytecomp-original-functions)) - (progn - (cc-bytecomp-debug-msg - "cc-bytecomp-defun: Saving %s (as unbound)" ',fun) - (setq cc-bytecomp-original-functions - (cons (list ',fun nil 'unbound) - cc-bytecomp-original-functions)))) - (if (cc-bytecomp-is-compiling) - (progn - (fset ',fun (intern (concat "cc-bytecomp-ignore-fun:" - (symbol-name ',fun)))) - (cc-bytecomp-debug-msg - "cc-bytecomp-defun: Covered function %s" ',fun)))))) - -(defmacro cc-bytecomp-put (symbol propname value) - "Set a property on SYMBOL during compilation (and evaluation) of the file. -Don't use outside `eval-when-compile'." - (declare (debug t)) - `(eval-when-compile - (if (not (assoc (cons ,symbol ,propname) cc-bytecomp-original-properties)) - (progn + (if (fboundp 'declare-function) + `(declare-function ,fun nil) + `(eval-when-compile + (if (fboundp ',fun) (cc-bytecomp-debug-msg - "cc-bytecomp-put: Saving property %s for %s with value %s" - ,propname ,symbol (get ,symbol ,propname)) - (setq cc-bytecomp-original-properties - (cons (cons (cons ,symbol ,propname) - (cons ,value (get ,symbol ,propname))) - cc-bytecomp-original-properties)))) - (put ,symbol ,propname ,value) - (cc-bytecomp-debug-msg - "cc-bytecomp-put: Bound property %s for %s to %s" - ,propname ,symbol ,value))) + "cc-bytecomp-defun: %s bound already as function" ',fun) + (if (not (assq ',fun cc-bytecomp-original-functions)) + (progn + (cc-bytecomp-debug-msg + "cc-bytecomp-defun: Saving %s (as unbound)" ',fun) + (setq cc-bytecomp-original-functions + (cons (list ',fun nil 'unbound) + cc-bytecomp-original-functions)))) + (if (cc-bytecomp-is-compiling) + (progn + (fset ',fun (intern (concat "cc-bytecomp-ignore-fun:" + (symbol-name ',fun)))) + (cc-bytecomp-debug-msg + "cc-bytecomp-defun: Covered function %s" ',fun))))))) (defmacro cc-bytecomp-boundp (symbol) "Return non-nil if SYMBOL is bound as a variable outside the compilation. @@ -457,7 +415,8 @@ cc-bytecomp-boundp variables that have been bound during compilation with `cc-bytecomp-defvar'." (declare (debug t)) - (if (and (cc-bytecomp-is-compiling) + (if (and (featurep 'xemacs) + (cc-bytecomp-is-compiling) (memq (car (cdr symbol)) cc-bytecomp-unbound-variables)) nil `(boundp ,symbol))) @@ -469,7 +428,8 @@ cc-bytecomp-fboundp `cc-bytecomp-defun'." (declare (debug t)) (let (fun-elem) - (if (and (cc-bytecomp-is-compiling) + (if (and (not (fboundp 'declare-function)) + (cc-bytecomp-is-compiling) (setq fun-elem (assq (car (cdr symbol)) cc-bytecomp-original-functions)) (eq (elt fun-elem 2) 'unbound)) However, it leads to a number of warnings when compiling, so either my respin is faulty, or something's changed to make it not work any more? In c-fontify-recorded-types-and-refs: progmodes/cc-fonts.el:491:8: Warning: function `c-fontify-recorded-types-and-refs' defined multiple times in this file ELC progmodes/cc-styles.elc In c-font-lock-declarators: progmodes/cc-fonts.el:1063:8: Warning: function `c-font-lock-declarators' defined multiple times in this file progmodes/cc-fonts.el:2300:35: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2300:35: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2496:37: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2496:37: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2501:37: Warning: reference to free variable `c-reference-face-name' In c-font-lock-objc-method: progmodes/cc-fonts.el:2527:8: Warning: function `c-font-lock-objc-method' defined multiple times in this file progmodes/cc-fonts.el:2602:38: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2602:38: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2650:38: Warning: reference to free variable `c-reference-face-name' progmodes/cc-fonts.el:2678:37: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2678:37: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2683:37: Warning: reference to free variable `c-reference-face-name' progmodes/cc-fonts.el:2711:38: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2711:38: Warning: reference to free variable `c-preprocessor-face-name' progmodes/cc-fonts.el:2716:38: Warning: reference to free variable `c-reference-face-name'