[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot 364348d 04/12: Close #25: Improve eglot-ensure an

From: João Távora
Subject: [elpa] externals/eglot 364348d 04/12: Close #25: Improve eglot-ensure and mention it in README.md
Date: Fri, 22 Jun 2018 11:52:15 -0400 (EDT)

branch: externals/eglot
commit 364348d134c1b49e94c6d7916cedd01c91292d76
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Close #25: Improve eglot-ensure and mention it in README.md
    * README.md (Installation and Usage): Mention eglot-ensure.
    * eglot.el (eglot-ensure): No-op for non-file buffers.
    (eglot--connect): Don't fallback to 'eglot-lsp-server here.
    (eglot--guess-contact): Error if something can't be guessed.
 README.md | 11 ++++++++++-
 eglot.el  | 44 ++++++++++++++++++++++++++------------------
 2 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/README.md b/README.md
index 936aaea..c3f4434 100644
--- a/README.md
+++ b/README.md
@@ -35,13 +35,22 @@ I'll add to this list as I test more servers. In the 
meantime you can
 customize `eglot-server-programs`:
-(add-to-list 'eglot-server-programs '(fancy-mode . ("fancy-language-server" 
+(add-to-list 'eglot-server-programs '(foo-mode . ("foo-language-server" 
 Let me know how well it works and we can add it to the list.  You can
 also enter a `server:port` pattern to connect to an LSP server. To
 skip the guess and always be prompted use `C-u M-x eglot`.
+You can also do:
+  (add-hook 'foo-mode-hook 'eglot-ensure)
+To attempt to start an eglot session automatically everytime a
+`foo-mode` buffer is visited.
 # Commands and keybindings
 Here's a summary of available commands:
diff --git a/eglot.el b/eglot.el
index 1aa3661..ecbd509 100644
--- a/eglot.el
+++ b/eglot.el
@@ -299,7 +299,7 @@ class SERVER-CLASS."
          server connect-success)
     (setq server
-           (or server-class 'eglot-lsp-server)
+           server-class
            :process proc :major-mode managed-major-mode
            :project project :contact contact
            :name name :project-nickname nickname
@@ -341,23 +341,28 @@ class SERVER-CLASS."
 (defun eglot--guess-contact (&optional interactive)
   "Helper for `eglot'.
-If INTERACTIVE, maybe prompt user."
+non-nil, maybe prompt user, else error as soon as something can't
+be guessed."
   (let* ((guessed-mode (if buffer-file-name major-mode))
-           ((or (>= (prefix-numeric-value current-prefix-arg) 16)
-                (not guessed-mode))
+           ((and interactive
+                 (or (>= (prefix-numeric-value current-prefix-arg) 16)
+                     (not guessed-mode)))
               "[eglot] Start a server to manage buffers of what major mode? "
               (mapcar #'symbol-name (eglot--all-major-modes)) nil t
               (symbol-name guessed-mode) nil (symbol-name guessed-mode) nil)))
+           ((not guessed-mode)
+            (eglot--error "Can't guess mode to manage for `%s'" 
            (t guessed-mode)))
          (project (or (project-current) `(transient . ,default-directory)))
          (guess (cdr (assoc managed-mode eglot-server-programs)))
-         (class (and (consp guess) (symbolp (car guess))
-                     (prog1 (car guess) (setq guess (cdr guess)))))
+         (class (or (and (consp guess) (symbolp (car guess))
+                         (prog1 (car guess) (setq guess (cdr guess))))
+                    'eglot-lsp-server))
          (program (and (listp guess) (stringp (car guess)) (car guess)))
           (and interactive
@@ -374,16 +379,18 @@ If INTERACTIVE, maybe prompt user."
                               (format ", but I can't find `%s' in PATH!" 
                               "\n" base-prompt)))))
-          (if prompt
-              (let ((s (read-shell-command
-                        prompt
-                        (if program (combine-and-quote-strings guess))
-                        'eglot-command-history)))
-                (if (string-match "^\\([^\s\t]+\\):\\([[:digit:]]+\\)$"
-                                  (string-trim s))
-                    (list (match-string 1 s) (string-to-number (match-string 2 
-                  (split-string-and-unquote s)))
-            guess)))
+          (or (and prompt
+                   (let ((s (read-shell-command
+                             prompt
+                             (if program (combine-and-quote-strings guess))
+                             'eglot-command-history)))
+                     (if (string-match "^\\([^\s\t]+\\):\\([[:digit:]]+\\)$"
+                                       (string-trim s))
+                         (list (match-string 1 s)
+                               (string-to-number (match-string 2 s)))
+                       (split-string-and-unquote s))))
+              guess
+              (eglot--error "Couldn't guess for `%s'!" managed-mode))))
     (list managed-mode project class contact)))
@@ -470,7 +477,8 @@ INTERACTIVE is t if called interactively."
                  (eglot--name server)
                  (eglot--project-nickname server)))))))
-      (add-hook 'post-command-hook #'maybe-connect 'append nil))))
+      (when buffer-file-name
+        (add-hook 'post-command-hook #'maybe-connect 'append nil)))))
 (defun eglot--process-sentinel (proc change)
   "Called when PROC undergoes CHANGE."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]