Subject: bug#44494: bug#2807: Subject: 23.0.90; etags can't access .el.gz files

From: Mauro Aranda <[email-masked]>
Date: Thu, 12 Oct 2023 12:04:47 -0300

On 12/10/23 11:28, Stefan Monnier via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
 >> +(defun etags--ensure-file (file)
 >> +  "Ensure FILE can be visited.
 >> +
 >> +FILE should be an expanded file name.
 >> +This function tries to locate FILE, possibly adding it a suffix
 >> +present in `tags-compression-info-list'.  If the file can't be found,
 >> +signals an error.
 >> +Else, returns the filename that can be visited for sure."
 >> +  (let ((f (locate-file file nil tags-compression-info-list)))
 >> +    (unless f
 >> +      (signal 'file-missing (list "Cannot locate file in TAGS" file)))
 >> +    f))
 >
 > The patch looks pretty good, but other parts of the code use
 > check `auto-compression-mode` before using `tags-compression-info-list`,
 > so we should probably do the same here.

Thank you!  Yes, I should've added that check.  I attach a patch that
incorporates the check.

 > As other comments mention in the file, this arrangement is suboptimal
 > because the search for compressed filenames should probably be moved to
 > jka-compr's code (e.g. using `jka-compr-compression-info-list` rather
 > than `tags-compression-info-list`).

Yes, but I opted to go with this simpler patch for a 24 year-old bug
report.

 > Historical side note: jka-compr used to have the ability to do what we
 > want here "transparently" (it changed things like `find-file-noselect`
 > to look for compressed versions of the file, among other things).
 > IIRC it was removed when it got integrated into Emacs (don't know why
 > but I assumed it was too hackish/ugly/costly/brittle).
 >
 > We should arguably re-add this feature, tho maybe not transparent,
 > i.e. let packages who need that request that feature explicitly (like
 > here).
 >

That's good to know, thank you.  And I agree that the feature would be
good to have, but I hope that in the meantime we can go with the updated
patch.
From bfed523e3ae8007e959e7801a3cbcd0a4c7b83d8 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Thu, 12 Oct 2023 09:41:58 -0300
Subject: [PATCH] Fix searching for tags in compressed files

* lisp/progmodes/etags.el (etags--ensure-file): New function.
(etags--all-files): Make sure files in TAGS can be visited, even if
the files are compressed.  (Bug#2807)
(etags--xref-find-definitions): Report to xref a file that we are sure
it exists.  (Bug#44494)
---
 lisp/progmodes/etags.el | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index cb95f29b5fe..d48dcc6659d 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -1729,6 +1729,21 @@ tags-next-file
   (fileloop-next-file novisit)
   (switch-to-buffer (current-buffer)))
 
+(defun etags--ensure-file (file)
+  "Ensure FILE can be visited.
+
+FILE should be an expanded file name.
+This function tries to locate FILE, possibly adding it a suffix
+present in `tags-compression-info-list'.  If the file can't be found,
+signals an error.
+Else, returns the filename that can be visited for sure."
+  (let ((f (locate-file file nil (if auto-compression-mode
+				     tags-compression-info-list
+				   '("")))))
+    (unless f
+      (signal 'file-missing (list "Cannot locate file in TAGS" file)))
+    f))
+
 (defun tags--all-files ()
   (save-excursion
     (let ((cbuf (current-buffer))
@@ -1750,7 +1765,7 @@ tags--all-files
           ;; list later returned by (tags-table-files).
           (setf (if tail (cdr tail) files)
                 (mapcar #'expand-file-name (tags-table-files)))))
-      files)))
+      (mapcar #'etags--ensure-file files))))
 
 (make-obsolete-variable 'tags-loop-operate 'fileloop-initialize "27.1")
 (defvar tags-loop-operate nil
@@ -2137,7 +2152,7 @@ etags--xref-find-definitions
               (beginning-of-line)
               (pcase-let* ((tag-info (etags-snarf-tag))
                            (`(,hint ,line . _) tag-info))
-                (let* ((file (file-of-tag))
+                (let* ((file (etags--ensure-file (file-of-tag)))
                        (mark-key (cons file line)))
                   (unless (gethash mark-key marks)
                     (let ((loc (xref-make-etags-location
-- 
2.34.1