[Top][All Lists]

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

[elpa] externals/eglot 4d4b85d 061/139: eglot-editing-mode becomes eglot

From: João Távora
Subject: [elpa] externals/eglot 4d4b85d 061/139: eglot-editing-mode becomes eglot--managed-mode
Date: Mon, 14 May 2018 09:54:54 -0400 (EDT)

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

    eglot-editing-mode becomes eglot--managed-mode
    * eglot.el (eglot--sentinel): Use eglot--managed-mode.
    (eglot--managed-mode-map): Renamed from eglot-editing-mode-map.
    (eglot--managed-mode): Renamed from eglot-editing-mode.
    (eglot-mode): Simplify.
    (eglot--buffer-managed-p): New function.
    (eglot--maybe-activate-editing-mode): Simplify.
 eglot.el | 63 +++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 33 insertions(+), 30 deletions(-)

diff --git a/eglot.el b/eglot.el
index ec7f3e6..0300ad3 100644
--- a/eglot.el
+++ b/eglot.el
@@ -341,12 +341,20 @@ INTERACTIVE is t if called interactively."
                   "(sentinel) Cancelling timer for continuation %s" id)
                  (cancel-timer timeout)))
              (eglot--pending-continuations process))
+    ;; Turn off `eglot--managed-mode' where appropriate.
+    ;;
+    (dolist (buffer (buffer-list))
+      (with-current-buffer buffer
+        (when (eglot--buffer-managed-p process)
+          (eglot--managed-mode -1))))
+    ;; Forget about the process-project relationship
+    ;;
+    (setf (gethash (eglot--project process) eglot--processes-by-project)
+          (delq process
+                (gethash (eglot--project process) 
     (cond ((eglot--moribund process)
            (eglot--message "(sentinel) Moribund process exited with status %s"
-                           (process-exit-status process))
-           (setf (gethash (eglot--project process) eglot--processes-by-project)
-                 (delq process
-                       (gethash (eglot--project process) 
+                           (process-exit-status process)))
             "(sentinel) Reconnecting after process unexpectedly changed to %s."
@@ -641,60 +649,55 @@ identifier.  ERROR is non-nil if this is an error."
 (defvar eglot-mode-map (make-sparse-keymap))
-(defvar eglot-editing-mode-map (make-sparse-keymap))
+(defvar eglot--managed-mode-map (make-sparse-keymap))
-(define-minor-mode eglot-editing-mode
-  "Minor mode for source buffers where EGLOT helps you edit."
+(define-minor-mode eglot--managed-mode
+  "Mode for source buffers managed by some EGLOT project."
-   (eglot-editing-mode
+   (eglot--managed-mode
     (eglot-mode 1)
     (add-hook 'after-change-functions 'eglot--after-change nil t)
     (add-hook 'before-change-functions 'eglot--before-change nil t)
     (add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t)
     (add-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose nil t)
     (add-hook 'before-revert-hook 'eglot--signal-textDocument/didClose nil t)
-    (add-hook 'after-revert-hook 'eglot--signal-textDocument/didOpen nil t)
+    ;; (add-hook 'after-revert-hook 'eglot--signal-textDocument/didOpen nil t)
     (add-hook 'before-save-hook 'eglot--signal-textDocument/willSave nil t)
     (add-hook 'after-save-hook 'eglot--signal-textDocument/didSave nil t)
-    (flymake-mode 1)
-    (unless (eglot--current-process)
-      (eglot--warn "No process, start one with `M-x eglot'")))
+    (flymake-mode 1))
     (remove-hook 'flymake-diagnostic-functions 'eglot-flymake-backend t)
     (remove-hook 'after-change-functions 'eglot--after-change t)
     (remove-hook 'before-change-functions 'eglot--before-change t)
     (remove-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose t)
     (remove-hook 'before-revert-hook 'eglot--signal-textDocument/didClose t)
-    (remove-hook 'after-revert-hook 'eglot--signal-textDocument/didOpen t)
+    ;; (remove-hook 'after-revert-hook 'eglot--signal-textDocument/didOpen t)
     (remove-hook 'before-save-hook 'eglot--signal-textDocument/willSave t)
     (remove-hook 'after-save-hook 'eglot--signal-textDocument/didSave t))))
 (define-minor-mode eglot-mode
   "Minor mode for all buffers managed by EGLOT in some way."  nil
-  nil eglot-mode-map
-  (cond (eglot-mode
-         (when (and buffer-file-name
-                    (not eglot-editing-mode))
-           (eglot-editing-mode 1)))
-        (t
-         (when eglot-editing-mode
-           (eglot-editing-mode -1)))))
+  nil eglot-mode-map)
+(defun eglot--buffer-managed-p (&optional proc)
+  "Tell if current buffer is managed by PROC."
+  (and buffer-file-name
+       (let ((cur (eglot--current-process)))
+         (or (and (null proc) cur)
+             (and proc (eq proc cur))))))
 (defun eglot--maybe-activate-editing-mode (&optional proc)
-  "Maybe activate mode function `eglot-editing-mode'.
+  "Maybe activate mode function `eglot--managed-mode'.
 If PROC is supplied, do it only if BUFFER is managed by it.  In
 that case, also signal textDocument/didOpen."
-  (when buffer-file-name
-    (let ((cur (eglot--current-process)))
-      (when (or (and (null proc) cur)
-                (and proc (eq proc cur)))
-        (unless eglot-editing-mode
-          (eglot-editing-mode 1))
-        (eglot--signal-textDocument/didOpen)
-        (flymake-start)))))
+  ;; Called even when revert-buffer-in-progress-p
+  (when (eglot--buffer-managed-p proc)
+    (eglot--managed-mode 1)
+    (eglot--signal-textDocument/didOpen)
+    (flymake-start)))
 (add-hook 'find-file-hook 'eglot--maybe-activate-editing-mode)

reply via email to

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