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#74040: `require-with-check` signals error for `project` Date: Sun, 27 Oct 2024 12:25:53 -0400 Message-ID: References: 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="27424"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 74040@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 27 17:26:41 2024 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 1t566C-0006x9-0n for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 27 Oct 2024 17:26:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5660-0000ln-Us; Sun, 27 Oct 2024 12:26:29 -0400 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 1t565z-0000le-CF for bug-gnu-emacs@gnu.org; Sun, 27 Oct 2024 12:26:27 -0400 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 1t565z-0006Sg-2v for bug-gnu-emacs@gnu.org; Sun, 27 Oct 2024 12:26:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=clJgfrcdAadRPrOg7MXMrD2zUoAbsrp1HEzp7ia6XHc=; b=dcCrG3OLnfbWaLfG1Guy+yI1pTfWjv4C8GnARMGr1rl74/hcsznPTh2oaqE8ZGa4whkNZbTvPZdsIh32j3HVgozAjqQtk7IG9eIlP24brJuuYTUoLWMeG17D+DQu2cXkW5KH8s+p8qxE/XDcolt1TsAFGPas7v44sfbd2rNzHKuYt/tDJDc0d6BoUjNxMJBRHsajgg93NGJdSQodiCaWLFex+ku+fT5b0TN206jqYq4DucrQPNrbjx8tQ0GsJmiUspv0h7R9i3++GMjojqvXd6rVjMpao1kC1k7ZGi7PsmpEHIUKt0x+PAEijgKfl43U70GyZ/8ya6TvaOnaMJzXfQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t566X-0006Wn-V2 for bug-gnu-emacs@gnu.org; Sun, 27 Oct 2024 12:27:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 27 Oct 2024 16:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74040 X-GNU-PR-Package: emacs Original-Received: via spool by 74040-submit@debbugs.gnu.org id=B74040.173004640425063 (code B ref 74040); Sun, 27 Oct 2024 16:27:01 +0000 Original-Received: (at 74040) by debbugs.gnu.org; 27 Oct 2024 16:26:44 +0000 Original-Received: from localhost ([127.0.0.1]:46011 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t566G-0006WA-5L for submit@debbugs.gnu.org; Sun, 27 Oct 2024 12:26:44 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:33255) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t566A-0006Vk-QC for 74040@debbugs.gnu.org; Sun, 27 Oct 2024 12:26:42 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id E712980932; Sun, 27 Oct 2024 12:25:55 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1730046354; bh=vNts9pgU11MhfacLwgXz7xRaa3eiHmxOtnny2/ZgRGE=; h=From:To:Subject:In-Reply-To:References:Date:From; b=ZX6MA8Ml5GLgtKRcgOaGUbbEd7sVMqETW9GncG1TIppobjjfhbXmFJ0420LBsqPKr yvrFsv2NahT+2S6RkYWSFAFa8wVruLODtroKeJgAIt76I2KYI2P3mVz3dMnxQPDu3P aJD7zT07TNq8u9h1gPiXctW9N1zWZ9qmtNzXNx7WWSG6NZ1/j+NEYWp8EPhZoVtKV/ +jTM2OJRrKy9Bhm+RnwobaT54Ojm+caWMlxwku8UvpAhJkpfoRkXxpyzH9GiyvaXd+ ay3RsV81g269M8iTWQUxlJ5YHxtoNQFnSl56tmYLxXciUiDstDo0Ma7LEB0dG74o9Z JrsB94t9OVybg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 52D5D80762; Sun, 27 Oct 2024 12:25:54 -0400 (EDT) Original-Received: from pastel (69-196-161-60.dsl.teksavvy.com [69.196.161.60]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 327C51201F9; Sun, 27 Oct 2024 12:25:54 -0400 (EDT) In-Reply-To: (Stefan Monnier's message of "Sat, 26 Oct 2024 23:15:01 -0400") 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:294370 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > 1. Customize `load-prefer-newer` to t. > 2. Edit project.el in-tree, save it, don't recompile Emacs. > 3. Restart Emacs. > 4. Visit some code file and try to launch `M-x eglot` there. > > You should get an error along the lines of: > > require-with-check: Feature =E2=80=98project=E2=80=99 loaded from > ".../lisp/progmodes/project.el" is now provided by > ".../lisp/progmodes/project.elc" > > This error is spurious. AFAICT, it is due to the fact that > `require-with-check` uses `locate-file` to "guess" which file `load` > would use, but `locate-file` doesn't obey `load-prefer-newer`, so it > guesses wrong. One approach is to expose the `prefer` option of `openp` to `locate-file` so we can use it in `require-with-check`, as in the patch below. Stefan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=require-with-check.patch diff --git a/lisp/files.el b/lisp/files.el index a81f742bbb4..a67d34f81b2 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1039,7 +1039,7 @@ load-file (defvar comp-eln-to-el-h) -(defun locate-file (filename path &optional suffixes predicate) +(defun locate-file (filename path &optional suffixes predicate prefer-newer) "Search for FILENAME through PATH. If found, return the absolute file name of FILENAME; otherwise return nil. @@ -1057,7 +1057,10 @@ locate-file in which case file name handlers are ignored. This usage is deprecated. For compatibility, PREDICATE can also be one of the symbols `executable', `readable', `writable', or `exists', or a list of -one or more of those symbols." +one or more of those symbols. + +PREFER-NEWER, if non-nil, means to disregard the order of SUFFIXES and +return the most recently modified file instead." (if (and predicate (symbolp predicate) (not (functionp predicate))) (setq predicate (list predicate))) (when (and (consp predicate) (not (functionp predicate))) @@ -1065,7 +1068,7 @@ locate-file (logior (if (memq 'executable predicate) 1 0) (if (memq 'writable predicate) 2 0) (if (memq 'readable predicate) 4 0)))) - (locate-file-internal filename path suffixes predicate)) + (locate-file-internal filename path suffixes predicate prefer-newer)) (defun locate-file-completion-table (dirs suffixes string pred action) "Do completion for file names passed to `locate-file'." @@ -1278,7 +1281,8 @@ require-with-check (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)))) + load-path (get-load-suffixes) nil + load-prefer-newer))) (cond ((assoc fn load-history) nil) ;We loaded the right file. ((eq noerror 'reload) (load fn nil 'nomessage)) diff --git a/src/lread.c b/src/lread.c index 854aaa784ad..6cc2e8b6349 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1793,7 +1793,7 @@ complete_filename_p (Lisp_Object pathname) && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))); } -DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0, +DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 5, 0, doc: /* Search for FILENAME through PATH. Returns the file's name in absolute form, or nil if not found. If SUFFIXES is non-nil, it should be a list of suffixes to append to @@ -1802,12 +1802,15 @@ DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, PREDICATE can also be an integer to pass to the faccessat(2) function, in which case file-name-handlers are ignored. This function will normally skip directories, so if you want it to find -directories, make sure the PREDICATE function returns `dir-ok' for them. */) - (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Object predicate) +directories, make sure the PREDICATE function returns `dir-ok' for them. +PREFER-NEWER, if non-nil, means to disregard the order of SUFFIXES and +return the most recently modified file instead. */) + (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, + Lisp_Object predicate, Lisp_Object prefer_newer) { Lisp_Object file; - int fd = openp (path, filename, suffixes, &file, predicate, false, true, - NULL); + int fd = openp (path, filename, suffixes, &file, predicate, + !NILP (prefer_newer), true, NULL); if (NILP (predicate) && fd >= 0) emacs_close (fd); return file; @@ -1886,7 +1889,7 @@ maybe_swap_for_eln (bool no_native, Lisp_Object *filename, int *fd, can't find even central .el files. */ if (NILP (Flocate_file_internal (build_string ("simple.el"), Vload_path, - Qnil, Qnil))) + Qnil, Qnil, Qnil))) return; Vdelayed_warnings_list = Fcons (list2 --=-=-=--