]> git.eshelyaron.com Git - emacs.git/commitdiff
Add public hook eglot-managed-mode-hook
authorFelicián Németh <felician.nemeth@gmail.com>
Fri, 22 Nov 2019 15:55:04 +0000 (16:55 +0100)
committerFelicián Németh <felician.nemeth@gmail.com>
Mon, 13 Jan 2020 17:22:06 +0000 (18:22 +0100)
Per https://github.com/joaotavora/eglot/issues/354.

* eglot.el (eglot-managed-p): New function.
(eglot--managed-mode-hook): Obsolete it.
(eglot-managed-mode-hook): New hook variable.
(eglot--managed-mode): Run the new hook.

* README.md (Customization): Mention the new hook.

GitHub-reference: fix https://github.com/joaotavora/eglot/issues/182

lisp/progmodes/eglot.el

index 7f506c8c9ffdcef9fdfe0dc85e35c03a95257c55..4c65af0a24c467a29c28d8dff919c690c7969458 100644 (file)
@@ -1234,6 +1234,17 @@ For example, to keep your Company customization use
 (defvar-local eglot--cached-server nil
   "A cached reference to the current EGLOT server.")
 
+(defun eglot-managed-p ()
+  "Tell if current buffer is managed by EGLOT."
+  eglot--managed-mode)
+
+(make-obsolete-variable
+ 'eglot--managed-mode-hook 'eglot-managed-mode-hook "1.6")
+
+(defvar eglot-managed-mode-hook nil
+  "A hook run by EGLOT after it started/stopped managing a buffer.
+Use `eglot-managed-p' to determine if current buffer is managed.")
+
 (define-minor-mode eglot--managed-mode
   "Mode for source buffers managed by some EGLOT project."
   nil nil eglot-mode-map
@@ -1289,7 +1300,9 @@ For example, to keep your Company customization use
               (delq (current-buffer) (eglot--managed-buffers server)))
         (when (and eglot-autoshutdown
                    (null (eglot--managed-buffers server)))
-          (eglot-shutdown server)))))))
+          (eglot-shutdown server))))))
+  ;; Note: the public hook runs before the internal eglot--managed-mode-hook.
+  (run-hooks 'eglot-managed-mode-hook))
 
 (defun eglot--managed-mode-off ()
   "Turn off `eglot--managed-mode' unconditionally."