]> git.eshelyaron.com Git - emacs.git/commitdiff
Eglot: abandon compat.el
authorJoão Távora <joaotavora@gmail.com>
Wed, 22 Jan 2025 21:43:10 +0000 (21:43 +0000)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 Jan 2025 10:28:32 +0000 (11:28 +0100)
After period of months using this to help compatibility to older Emacs
versions.  It's not really buying us that much and complicates
maintenance, so it gets the axe.

A common problem is the compatibility alias for require-with-check,
which often errors with some "Feature X loaded from Y is now provided by
Z".  The tests for Emacs 26.3 were all failing in the Github tracker
ever since this (and track-changes.el) were added to Eglot.

* lisp/progmodes/eglot.el (compat): No longer require.
(eglot-alternatives): Reword comment.
(eglot-alternatives): Call eglot--executable-find.
(eglot--guess-contact): Call eglot--executable-find.
(eglot--connect): Check if package-get-version exists.
(eglot--format): Check if substitute-quotes exists.
(eglot--format-markup): Check if text-property-search exists.

(cherry picked from commit a60249b098d22093ec79b6cbc27a759b7b4f8883)

lisp/progmodes/eglot.el

index 19412dc61581e0a1840b75dace53deadbd1d2582..4b022ca0ebdb66788882aea1bd248525c29ab909 100644 (file)
@@ -7,7 +7,7 @@
 ;; Maintainer: João Távora <joaotavora@gmail.com>
 ;; URL: https://github.com/joaotavora/eglot
 ;; Keywords: convenience, languages
-;; Package-Requires: ((emacs "26.3") (compat "27.1") (eldoc "1.14.0") (external-completion "0.1") (flymake "1.2.1") (jsonrpc "1.0.24") (project "0.9.8") (seq "2.23") (xref "1.6.2"))
+;; Package-Requires: ((emacs "26.3") (eldoc "1.14.0") (external-completion "0.1") (flymake "1.2.1") (jsonrpc "1.0.24") (project "0.9.8") (seq "2.23") (xref "1.6.2"))
 
 ;; This is a GNU ELPA :core package.  Avoid adding functionality
 ;; that is not available in the version of Emacs recorded above or any
 (require 'text-property-search nil t)
 (require 'diff-mode)
 (require 'diff)
-(require 'compat)
 
 ;; These dependencies are also GNU ELPA core packages.  Because of
 ;; bug#62576, since there is a risk that M-x package-install, despite
@@ -197,8 +196,8 @@ path of the PROGRAM that was chosen (interactively or
 automatically)."
   (lambda (&optional interactive _project)
     ;; JT@2021-06-13: This function is way more complicated than it
-    ;; could be because it accounts for the fact that Compat's
-    ;; `executable-find' may take much longer to execute on
+    ;; could be because it accounts for the fact that
+    ;; `eglot--executable-find' may take much longer to execute on
     ;; remote files.
     (let* ((listified (cl-loop for a in alternatives
                                collect (if (listp a) a (list a))))
@@ -210,7 +209,7 @@ automatically)."
              nil)
             (interactive
              (let* ((augmented (mapcar (lambda (a)
-                                         (let ((found (compat-call executable-find
+                                         (let ((found (eglot--executable-find
                                                        (car a) t)))
                                            (and found
                                                 (cons (car a) (cons found (cdr a))))))
@@ -230,7 +229,7 @@ automatically)."
                       nil))))
             (t
              (cl-loop for (p . args) in listified
-                      for probe = (compat-call executable-find p t)
+                      for probe = (eglot--executable-find p t)
                       when probe return (cons probe args)
                       finally (funcall err)))))))
 
@@ -606,6 +605,11 @@ This can be useful when using docker to run a language server.")
 
 (defconst eglot--{} (make-hash-table :size 0) "The empty JSON object.")
 
+(defun eglot--executable-find (command &optional remote)
+  "Like Emacs 27's `executable-find', ignore REMOTE on Emacs 26."
+  (if (>= emacs-major-version 27) (executable-find command remote)
+    (executable-find command)))
+
 (defun eglot--accepted-formats ()
   (if (and (not eglot-prefer-plaintext) (fboundp 'gfm-view-mode))
       ["markdown" "plaintext"] ["plaintext"]))
@@ -1330,7 +1334,7 @@ be guessed."
                        main-mode base-prompt))
                      ((and program
                            (not (file-name-absolute-p program))
-                           (not (compat-call executable-find program t)))
+                           (not (eglot--executable-find program t)))
                       (if full-program-invocation
                           (concat (eglot--format
                                    "[eglot] I guess you want to run `%s'"
@@ -1628,7 +1632,8 @@ This docstring appeases checkdoc, that's all."
                             :clientInfo
                             (append
                              '(:name "Eglot")
-                             (let ((v "1.17"))
+                             (let ((v (and (featurep 'package)
+                                           (package-get-version))))
                                (and v (list :version v))))
                             ;; Maybe turn trampy `/ssh:foo@bar:/path/to/baz.py'
                             ;; into `/path/to/baz.py', so LSP groks it.
@@ -1708,7 +1713,10 @@ in project `%s'."
 ;;;
 (defun eglot--format (format &rest args)
   "Like `format`, but substitutes quotes."
-  (apply #'format (substitute-quotes format) args))
+  (apply #'format (if (functionp 'substitute-quotes)
+                      (substitute-quotes format)
+                    format)
+         args))
 
 (defun eglot--error (format &rest args)
   "Error out with FORMAT with ARGS."
@@ -1896,9 +1904,10 @@ MARKUP is either an LSP MarkedString or MarkupContent object."
         (font-lock-ensure)
         (goto-char (point-min))
         (let ((inhibit-read-only t))
-          (while (setq match (text-property-search-forward 'invisible))
-            (delete-region (prop-match-beginning match)
-                           (prop-match-end match))))
+          (when (fboundp 'text-property-search-forward)
+            (while (setq match (text-property-search-forward 'invisible))
+              (delete-region (prop-match-beginning match)
+                             (prop-match-end match)))))
         (string-trim (buffer-string))))))
 
 (defun eglot--read-server (prompt &optional dont-if-just-the-one)