Skip to content

Commit

Permalink
Add public hook eglot-managed-mode-hook
Browse files Browse the repository at this point in the history
Per #354, fix #182.

* 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.
  • Loading branch information
nemethf committed Jan 12, 2020
1 parent 4b453dc commit 115ea94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ lisp:
- `eglot-server-initialized-hook`: Hook run after server is
successfully initialized;

- `eglot-managed-mode-hook`: Hook run after Eglot starts/stops
managing a buffer. See its documentation for usage tips;

# How does Eglot work?

`M-x eglot` starts a server via a shell-command guessed from
Expand Down
17 changes: 16 additions & 1 deletion eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,19 @@ 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 starts/stops managing a buffer.
Use `eglot-managed-p' in the hook function to determine whether
EGLOT starts or stops managing a buffer, it returns t or nil,
respectively.")

(define-minor-mode eglot--managed-mode
"Mode for source buffers managed by some EGLOT project."
nil nil eglot-mode-map
Expand Down Expand Up @@ -1289,7 +1302,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."
Expand Down

0 comments on commit 115ea94

Please sign in to comment.