From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74504: 31.0.50; Wrong source directory in *Help* Date: Sun, 08 Dec 2024 08:35:34 +0100 Message-ID: References: <86v7vvisq7.fsf@gnu.org> Reply-To: Eshel Yaron Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26175"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Stefan Monnier , 74504@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 08 08:36:30 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 1tKBq8-0006fx-50 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 08 Dec 2024 08:36:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tKBpm-0005lr-1D; Sun, 08 Dec 2024 02:36:06 -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 1tKBpi-0005lZ-Vo for bug-gnu-emacs@gnu.org; Sun, 08 Dec 2024 02:36:05 -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 1tKBpi-0000rx-MY for bug-gnu-emacs@gnu.org; Sun, 08 Dec 2024 02:36:02 -0500 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=DYhQWvmPYGFUsaGXkpmf4+b2QByvWJNoJc0YF6mwjOY=; b=SCmEujVYW6BFQZWBOscF+gAks/hNZ5ABBeY3PEu+sms+mlj4fFrprnfUQIQiV/VkOBqJHK+VKSlGPwwkgrxZ+6ttDE5ZIBckVuR7wHV7hsG2Wdfe6Htc3rB29R23/q1nzMLUECqfE+Kmalmi49dRdcexcR2GHC7UDvbvMlZ3trBp8jtYtXFavb6lv8isCXMzwhjRkHZ4dyzkHDXCglb6whCQ+g0TfxSZoLU+c4JoDbe47g8u07dBAbrfNSNqX8p7V2ghfVr+s1KFmcIk9S4nvK0SSjInwlwVUpQvtWlwTVncNH0BjUwcnIcmtoxV21rh5xQSikA52lLeBBezPnwqxw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tKBpi-00019q-Gj for bug-gnu-emacs@gnu.org; Sun, 08 Dec 2024 02:36:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eshel Yaron Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Dec 2024 07:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74504 X-GNU-PR-Package: emacs Original-Received: via spool by 74504-submit@debbugs.gnu.org id=B74504.17336433394409 (code B ref 74504); Sun, 08 Dec 2024 07:36:02 +0000 Original-Received: (at 74504) by debbugs.gnu.org; 8 Dec 2024 07:35:39 +0000 Original-Received: from localhost ([127.0.0.1]:49522 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKBpK-000193-Qk for submit@debbugs.gnu.org; Sun, 08 Dec 2024 02:35:39 -0500 Original-Received: from mail.eshelyaron.com ([107.175.124.16]:44704 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tKBpI-00018v-Q7 for 74504@debbugs.gnu.org; Sun, 08 Dec 2024 02:35:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1733643336; bh=hx4gsBGtd4SDifub4iaNoFbpSmfisePLfsWA7GIpzc0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=VJiyFXkCaBCJDXDXfNamCpO3YuWW79D26mDFt3ujO7TEXZSF8CcvN6a1J+AjUHUHB MkYYcbZH+G5XAK5IpmdLHmCM+1JpPAxZVevK9UAHYgPCYOFEpIT7y/12cVuLQqqD/D n9If/oBB84NUNy9FkBC42C1iX/rCv1LnrLQAekxSr6G9M8kslX6honL7A1BF0dhZ4C sqj7e7Z+i4wxHvuMNsrsvXCbmxesfw1kDG1g+1uSxO6bIu6jf6O//VGzrWROb41gX6 +dFCmMbw/lAaGCccPRHtDJYhXA7173AvI5pWj2bKowuc8mE0c0YB+iuIj7oO/2tjjM 0BVcWdXfeqn3Q== In-Reply-To: <86v7vvisq7.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 07 Dec 2024 14:26:56 +0200") 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:296620 Archived-At: Eli Zaretskii writes: >> Cc: 74504@debbugs.gnu.org >> Date: Mon, 25 Nov 2024 18:26:12 -0500 >> From: Stefan Monnier via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" >>=20 >> > 1. Build Emacs >> > 2. Run src/emacs -Q >> > 3. In the *scratch* buffer say M-x cd /tmp >> > (/tmp here is just an arbitrary directory that is not the Emacs >> > sources directory) >> > 4. C-h f make-overlay >> > Now the first line in the *Help* buffer says: >> > "make-overlay is a primitive-function in =E2=80=98C source code=E2= =80=99." >> > So far so good. >> > 5. Switch to the *Help* buffer and type s, this finds buffer.c >> > 6. Switch back to the *Help* buffer and type g >> > The first line in *Help* now says: >> > "make-overlay is a primitive-function in =E2=80=98/tmp/src/buffer.c= =E2=80=99." >> > ^^^^^ <-- Wrong! >>=20 >> Hmm... my code assumed the file was always absolute, but apparently >> that's not always the case. >>=20 >> The patch below seems to give us back the previous behavior, but maybe >> we should change some other part of the code so >> `help-fns-short-filename` is not used at all for the C sources (since >> it's specifically trying to give a name relative to `load-path`, which >> is nonsensical for our C files). >>=20 >>=20 >> Stefan >>=20 >>=20 >> diff --git a/lisp/help-fns.el b/lisp/help-fns.el >> index c87c86bae84..266cf8eb4a9 100644 >> --- a/lisp/help-fns.el >> +++ b/lisp/help-fns.el >> @@ -1052,7 +1052,8 @@ help-fns--radix-trees >> "Cache of radix-tree representation of `load-path'.") >>=20=20 >> (defun help-fns--filename (file) >> - (let ((f (abbreviate-file-name (expand-file-name file)))) >> + (let ((f (abbreviate-file-name >> + (if (file-name-absolute-p file) (expand-file-name file) fil= e)))) >> (if (file-name-case-insensitive-p f) (downcase f) f))) >>=20=20 >> (defun help-fns--radix-tree (dirs) > > Ping! Can we make further progress with this bug? I think that the workaround Stefan suggests makes sense. It doesn't make the code (and the implicit assumptions about when a file name is absolute and when it isn't) any clearer though. Another option may be something like the following, where we explicitly look only for .el files under load-path: diff --git a/lisp/help-fns.el b/lisp/help-fns.el index c87c86bae84..b57201c6100 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -1064,22 +1064,14 @@ help-fns--radix-tree rt))) =20 (defun help-fns-short-filename (filename) - (let* ((short (help-fns--filename filename)) - (prefixes (radix-tree-prefixes (help-fns--radix-tree load-path) - (file-name-directory short)))) - (if (not prefixes) - ;; The file is not inside the `load-path'. - ;; FIXME: Here's the old code (too slow, bug#73766), - ;; which used to try and shorten it with "../" as well. - ;; (dolist (dir load-path) - ;; (let ((rel (file-relative-name filename dir))) - ;; (if (< (length rel) (length short)) - ;; (setq short rel))) - ;; (let ((rel (file-relative-name abbrev dir))) - ;; (if (< (length rel) (length short)) - ;; (setq short rel)))) - short - (file-relative-name short (caar prefixes))))) + (cond + ((eq filename 'C-source) "C source code") + ((equal (file-name-extension filename) "el") + (let* ((short (help-fns--filename filename)) + (prefixes (radix-tree-prefixes (help-fns--radix-tree load-path) + (file-name-directory short)))) + (if prefixes (file-relative-name short (caar prefixes)) short))) + (t filename))) =20 (defun help-fns--analyze-function (function) ;; FIXME: Document/explain the differences between FUNCTION, @@ -1203,10 +1195,7 @@ help-fns-function-description-header (setq help-mode--current-data (list :symbol function))) ;; We used to add .el to the file name, ;; but that's completely wrong when the user used load-file. - (princ (format-message " in `%s'" - (if (eq file-name 'C-source) - "C source code" - (help-fns-short-filename file-name)))) + (princ (format-message " in `%s'" (help-fns-short-filename file-name))) ;; Make a hyperlink to the library. (with-current-buffer standard-output (setq help-mode--current-data (list :symbol function @@ -1399,9 +1388,7 @@ describe-variable (progn (princ (format-message " is a variable defined in `%s'.\n\n" - (if (eq file-name 'C-source) - "C source code" - (help-fns-short-filename file-name)))) + (help-fns-short-filename file-name))) (with-current-buffer standard-output (setq help-mode--current-data (list :symbol variable @@ -2146,9 +2133,7 @@ describe-keymap (princ ".\n\n")) (princ (format-message " defined in `%s'.\n\n" - (if (eq file-name 'C-source) - "C source code" - (help-fns-short-filename file-name)))) + (help-fns-short-filename file-name))) (save-excursion (re-search-backward (substitute-command-keys "`\\([^`']+\\= )'")) (setq help-mode--current-data (list :symbol keymap