-
Notifications
You must be signed in to change notification settings - Fork 0
/
pel-etags.el
92 lines (78 loc) · 3.43 KB
/
pel-etags.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; pel-etags.el --- Etags support for compressed files. -*- lexical-binding: t; -*-
;; Created : Friday, November 6 2020.
;; Author : Pierre Rouleau <prouleau001@gmail.com>
;; Time-stamp: <2024-06-19 06:58:30 EDT, updated by Pierre Rouleau>
;; This file is part of the PEL package.
;; This file is not part of GNU Emacs.
;; Copyright (C) 2020, 2024 Pierre Rouleau
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; --------------------------------------------------------------------------
;;; Commentary:
;;
;; This file is a temporary work-around for the etags implementation of the
;; xref-location-marker method. The original code is not capable of handling
;; references to symbol defined in compressed files (.el.gz files for
;; example).
;; I reported this problem in the following bug report:
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=44494
;; As a work-around I proposed the modification to xref-location-marker which
;; is able to return the name of the .el.gz file.
;; To use this, simply load it after etags has been loaded by using the
;; following code in your Emacs init file (PEL does it inside pel-init):
;;
;; (add-hook 'xref-etags-mode-hook (function
;; (lambda () (load "pel-etags" :no-error))))
;;; --------------------------------------------------------------------------
;;; Dependencies:
;;
;;
(require 'xref)
(require 'etags)
(require 'eieio) ; use: `with-slots'
;;; --------------------------------------------------------------------------
;;; Code:
;;
(defun pel-file-or-compressed-file-for (fname)
"Return the valid file name for FNAME.
Check if FNAME is an existing file name, if not
try FNAME appended with the following compression extensions:
- \".gz\", the extension of compressed files created by gzip
- \".bz2\", the extension for compressed files created by bzip2
- \".xz\", the extension for compressed files created by xz
- \".lzma\", the extension for compressed files created by xz.
Return the file that exists or nil if nothing found."
(let ((fpath nil))
(cl-dolist (ext '(""
".gz"
".bz2"
".xz"
".lzma"))
(setq fpath (concat fname ext))
(when (file-exists-p fpath)
(cl-return fpath)))))
(cl-defmethod xref-location-marker ((l xref-etags-location))
(with-slots (tag-info file) l
(let (buffer
(fname (pel-file-or-compressed-file-for file)))
(if fname
(setq buffer (find-file-noselect fname))
(user-error "file %s (or .gz, .bz2, .xz, .lzma) does not exist" file))
(with-current-buffer buffer
(save-excursion
(etags-goto-tag-location tag-info)
(point-marker))))))
;;; --------------------------------------------------------------------------
(provide 'pel-etags)
;;; pel-etags.el ends here