[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`:
```lisp
-(add-to-list 'eglot-server-programs '(fancy-mode . ("fancy-language-server"
"--args"")))
+(add-to-list 'eglot-server-programs '(foo-mode . ("foo-language-server"
"--args"")))
```
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:
+
+```lisp
+ (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
(make-instance
- (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'.
-Return (MANAGED-MODE PROJECT CONTACT CLASS).
-If INTERACTIVE, maybe prompt user."
+Return (MANAGED-MODE PROJECT CLASS CONTACT). If INTERACTIVE is
+non-nil, maybe prompt user, else error as soon as something can't
+be guessed."
(let* ((guessed-mode (if buffer-file-name major-mode))
(managed-mode
(cond
- ((or (>= (prefix-numeric-value current-prefix-arg) 16)
- (not guessed-mode))
+ ((and interactive
+ (or (>= (prefix-numeric-value current-prefix-arg) 16)
+ (not guessed-mode)))
(intern
(completing-read
"[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'"
(current-buffer)))
(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)))
(base-prompt
(and interactive
@@ -374,16 +379,18 @@ If INTERACTIVE, maybe prompt user."
(format ", but I can't find `%s' in PATH!"
program)
"\n" base-prompt)))))
(contact
- (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
s)))
- (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)))
;;;###autoload
@@ -470,7 +477,8 @@ INTERACTIVE is t if called interactively."
(eglot--name server)
major-mode
(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."
- [elpa] externals/eglot updated (a1f1dd6 -> 0176264), João Távora, 2018/06/22
- [elpa] externals/eglot 04ef055 11/12: Close #27: empty ranges are valid in LSP, João Távora, 2018/06/22
- [elpa] externals/eglot 0176264 12/12: * eglot.el (Version): Bump to 0.11, João Távora, 2018/06/22
- [elpa] externals/eglot 610d95b 03/12: Use gfm-mode for formatted strings (#20), João Távora, 2018/06/22
- [elpa] externals/eglot 0cde01f 05/12: Close #26: Guess server for js2-mode and rjsx-mode, João Távora, 2018/06/22
- [elpa] externals/eglot 364348d 04/12: Close #25: Improve eglot-ensure and mention it in README.md,
João Távora <=
- [elpa] externals/eglot efc0f45 02/12: Minor cleanup to new textDocument/formatting feature, João Távora, 2018/06/22
- [elpa] externals/eglot a9010f1 01/12: Implement formatting (#19), João Távora, 2018/06/22
- [elpa] externals/eglot 17ef74e 07/12: Defer textDocument/formatting requests, João Távora, 2018/06/22
- [elpa] externals/eglot 0b9cffe 08/12: Per #22: Apply text edits atomically, João Távora, 2018/06/22
- [elpa] externals/eglot 48c3f45 10/12: Close #22: Apply text edits as a single undoable edit, João Távora, 2018/06/22
- [elpa] externals/eglot cbc418c 06/12: Per #22: Simplify eglot-format-buffer, João Távora, 2018/06/22
- [elpa] externals/eglot df5e72e 09/12: Close #23: Report progress when applying edits, João Távora, 2018/06/22