]> git.eshelyaron.com Git - emacs.git/commitdiff
Events buffer uses eglot-mode, source buffers use eglot-editing-mode
authorJoão Távora <joaotavora@gmail.com>
Wed, 2 May 2018 12:37:35 +0000 (13:37 +0100)
committerJoão Távora <joaotavora@gmail.com>
Wed, 2 May 2018 14:50:17 +0000 (15:50 +0100)
* eglot.el (eglot--special-buffer-process): New var.
(eglot--current-process): Consider eglot--special-buffer-process.
(eglot-events-buffer): Use eglot-mode
(eglot-editing-mode): New minor mode.
(eglot-mode): Turns on eglot-editing-mode maybe.

lisp/progmodes/eglot.el

index 457f3168938f8fa7d1434455a4b47203e2643062..9742f885d9cc73921d10a229fc4866545d07150b 100644 (file)
 
 (defvar eglot--processes-by-project (make-hash-table :test #'equal))
 
+(defvar eglot--special-buffer-process nil
+  "Current buffer's eglot process.")
+
 (defun eglot--current-process ()
   "The current logical EGLOT process."
-  (let ((cur (project-current)))
-    (and cur
-         (gethash cur eglot--processes-by-project))))
+  (or eglot--special-buffer-process
+      (let ((cur (project-current)))
+        (and cur
+             (gethash cur eglot--processes-by-project)))))
 
 (defun eglot--current-process-or-lose ()
   (or (eglot--current-process)
@@ -270,8 +274,9 @@ INTERACTIVE is t if called interactively."
                        (with-current-buffer buffer
                          (buffer-disable-undo)
                          (read-only-mode t)
-                         (setf (eglot--events-buffer process)
-                               buffer))
+                         (setf (eglot--events-buffer process) buffer
+                               eglot--special-buffer-process process)
+                         (eglot-mode))
                        buffer))))
     (when interactive
       (display-buffer buffer))
@@ -610,12 +615,15 @@ running.  INTERACTIVE is t if called interactively."
 
 (defvar eglot-mode-map (make-sparse-keymap))
 
-(define-minor-mode eglot-mode
-  "Minor mode for buffers where EGLOT is possible"
+(defvar eglot-editing-mode-map (make-sparse-keymap))
+
+(define-minor-mode eglot-editing-mode
+  "Minor mode for source buffers where EGLOT helps you edit."
   nil
   nil
   eglot-mode-map
-  (cond (eglot-mode
+  (cond (eglot-editing-mode
+         (eglot-mode 1)
          (add-hook 'after-change-functions 'eglot--after-change nil t)
          (add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t)
          (if (eglot--current-process)
@@ -625,6 +633,17 @@ running.  INTERACTIVE is t if called interactively."
          (remove-hook 'flymake-diagnostic-functions 'eglot-flymake-backend t)
          (remove-hook 'after-change-functions 'eglot--after-change 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)))))
+
 (defvar eglot-menu)
 
 (easy-menu-define eglot-menu eglot-mode-map "EGLOT"