From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67696: 30.0.50; Help deal with multiple versions in load-path Date: Thu, 07 Dec 2023 11:42:12 -0500 Message-ID: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35495"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca To: 67696@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 07 17:43:17 2023 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 1rBHT3-00094O-Ad for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Dec 2023 17:43:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rBHSe-00058A-JT; Thu, 07 Dec 2023 11:42:52 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rBHSc-00057k-H2 for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 11:42:50 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rBHSc-0006uB-99 for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 11:42:50 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rBHSo-0005gx-Df; Thu, 07 Dec 2023 11:43:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Dec 2023 16:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 67696 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: monnier@iro.umontreal.ca Original-Received: via spool by submit@debbugs.gnu.org id=B.170196737121859 (code B ref -1); Thu, 07 Dec 2023 16:43:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Dec 2023 16:42:51 +0000 Original-Received: from localhost ([127.0.0.1]:42872 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rBHSc-0005gU-L9 for submit@debbugs.gnu.org; Thu, 07 Dec 2023 11:42:51 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:48468) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rBHSb-0005gE-8A for submit@debbugs.gnu.org; Thu, 07 Dec 2023 11:42:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rBHSD-00051n-HP for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 11:42:27 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rBHSB-0006rL-3c for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 11:42:25 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 39E16443043 for ; Thu, 7 Dec 2023 11:42:21 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1701967339; bh=4ncMWEuiPUhtHWBDDwgrBn7lQWguI1SGF6EFG5yBHj8=; h=From:To:Subject:Date:From; b=Vn7+2193tA5DOpBQMq7+64MhZbXJtM4iIn9NKDQciHe4WilYwwasbeW7QqW3AoEXn iYXWFMCIbMdMMjeq1caa2FD/O9dHTXu5oiyBPCPsPQXg4tPZjKHns/5dm5sECfESM0 AcnZm6TcU2QTgTQzEp0hqnW3ze6814EK5ZWdbMzfsxM/+I66zW62GsBBa2smOd/RcO WESLzg5rB0QudlMQXagwF7hmfSPWO3ObBtIWGWzVKtwXXd3Dv5abrT1OUYcifGV9JI 6hEue9Y2pOdiNEndCtsePY6Yd0sQf2eXXJ5Ty734Kx0aU82d5uieCpTu9JKwm6lGxc 7v6Ol9qwMB++g== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 97DD9442FF9 for ; Thu, 7 Dec 2023 11:42:19 -0500 (EST) Original-Received: from pastel (unknown [45.72.194.97]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 704F0120301 for ; Thu, 7 Dec 2023 11:42:19 -0500 (EST) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275682 Archived-At: --=-=-= Content-Type: text/plain Package: Emacs Version: 30.0.50 With packages being available both as bundled with Emacs and as ELPA packages, it has become a lot more common place to have two versions of a package in the `load-path` and to have to deal with situations where the "incorrect" version has been loaded before `load-path` was changed. These kinds of problems manifest in various ways and we try to circumvent them in `package.el` in some cases but that can't cover all cases. I suggest we introduce a new function to help packages susceptible to those problems. The patch below introduces a new function which I tentatively called `require-with-check` and shows how it could be used in the case of `eglot.el` (which relies on several core packages also distributed via GNU ELPA and currently uses a hack which slows it down unnecessarily in the normal case). As mentioned in a FIXME in there, maybe we should also consider adding to `seq` (and `eldoc`) something like ;;;###autoload (if (featurep 'seq) (require-with-check 'seq 'reload)) -- Stefan --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=require-with-check.patch Content-Transfer-Encoding: quoted-printable diff --git a/lisp/files.el b/lisp/files.el index 1cdcec23b11..e1e885462ce 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1246,6 +1246,29 @@ load-library (interactive (list (read-library-name))) (load library)) =20 +(defun require-with-check (feature &optional filename noerror) + "If FEATURE is not already loaded, load it from FILENAME. +This is like `require' except if FEATURE is already a member of the list +`features=E2=80=99, then we check if this was provided by a different file= than the +one that we would load now (presumably because `load-path' has been +changed since the file was loaded). +If it's the case, we either signal an error (the default), or forcibly rel= oad +the new file (if NOERROR is equal to `reload'), or otherwise emit a warnin= g." + (let ((lh load-history) + (res (require feature filename (if (eq noerror 'reload) nil noerro= r)))) + ;; If the `feature' was not yet provided, `require' just loaded the ri= ght + ;; file, so we're done. + (when (eq lh load-history) + ;; If `require' did nothing, we need to make sure that was warranted. + (let ((fn (locate-file (or filename (symbol-name feature)) + load-path (get-load-suffixes)))) + (cond + ((assoc fn load-history) nil) ;We loaded the right file. + ((eq noerror 'reload) (load fn nil 'nomessage)) + (t (funcall (if noerror #'warn #'error) + "Feature provided by other file: %S" feature))))) + res)) + (defun file-remote-p (file &optional identification connected) "Test whether FILE specifies a location on a remote system. A file is considered remote if accessing it is likely to diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index d410367f902..8124a3f52e0 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -116,13 +116,16 @@ ;; having installed them, didn't correctly re-load them over the ;; built-in versions. (eval-and-compile - (load "project") - (load "eldoc") - (load "seq") - (load "flymake") - (load "xref") - (load "jsonrpc") - (load "external-completion")) + ;; For those packages that are preloaded, reload them if needed, + ;; since that's the best we can do anyway. + ;; FIXME: Maybe the ELPA packages for those preloaded packages should + ;; force-reload themselves eagerly when the package is activated! + (require-with-check 'eldoc nil 'reload) + (require-with-check 'seq nil 'reload) + ;; For those packages which are not preloaded OTOH, signal an error if + ;; the loaded file is not the one that should have been loaded. + (mapc #'require-with-check + '(project flymake xref jsonrpc external-completion))) =20 ;; forward-declare, but don't require (Emacs 28 doesn't seem to care) (defvar markdown-fontify-code-blocks-natively) @@ -138,11 +141,12 @@ tramp-use-ssh-controlmaster-options 'eglot-managed-mode-hook "1.6") (define-obsolete-variable-alias 'eglot-confirm-server-initiated-edits 'eglot-confirm-server-edits "1.16") -(define-obsolete-function-alias 'eglot--uri-to-path 'eglot-uri-to-path "1.= 16") -(define-obsolete-function-alias 'eglot--path-to-uri 'eglot-path-to-uri "1.= 16") -(define-obsolete-function-alias 'eglot--range-region 'eglot-range-region "= 1.16") -(define-obsolete-function-alias 'eglot--server-capable 'eglot-server-capab= le "1.16") -(define-obsolete-function-alias 'eglot--server-capable-or-lose 'eglot-serv= er-capable-or-lose "1.16") +(define-obsolete-function-alias 'eglot--uri-to-path #'eglot-uri-to-path "1= .16") +(define-obsolete-function-alias 'eglot--path-to-uri #'eglot-path-to-uri "1= .16") +(define-obsolete-function-alias 'eglot--range-region #'eglot-range-region = "1.16") +(define-obsolete-function-alias 'eglot--server-capable #'eglot-server-capa= ble "1.16") +(define-obsolete-function-alias 'eglot--server-capable-or-lose + #'eglot-server-capable-or-lose "1.16") (define-obsolete-function-alias 'eglot-lsp-abiding-column 'eglot-utf-16-linepos "1.12") (define-obsolete-function-alias --=-=-=--