emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/eglot-inactive-regions 3569bd5dc7 24/66: Properly enable/c


From: ELPA Syncer
Subject: [nongnu] elpa/eglot-inactive-regions 3569bd5dc7 24/66: Properly enable/clean up state on minor mode toggle
Date: Fri, 6 Dec 2024 06:59:53 -0500 (EST)

branch: elpa/eglot-inactive-regions
commit 3569bd5dc7b42bdc9a80fe922aaf91d9765a77b4
Author: Filippo Argiolas <filippo.argiolas@gmail.com>
Commit: Filippo Argiolas <filippo.argiolas@gmail.com>

    Properly enable/clean up state on minor mode toggle
---
 clangd-inactive-regions.el | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/clangd-inactive-regions.el b/clangd-inactive-regions.el
index 52d62bac70..e753e09678 100644
--- a/clangd-inactive-regions.el
+++ b/clangd-inactive-regions.el
@@ -66,17 +66,6 @@ Allowed methods:
   '((t (:extend t)))
   "Face used to inactive code with shade-background method.")
 
-(define-minor-mode clangd-inactive-regions-mode
-  ""
-  :global nil
-  (cond (clangd-inactive-regions-mode
-         (add-function :after (default-value 
'font-lock-fontify-region-function)
-                       #'clangd-inactive-regions--fontify))
-        (t
-         (remove-function (default-value 'font-lock-fontify-region-function)
-                          #'clangd-inactive-regions--fontify)
-         (clangd-inactive-regions-cleanup))))
-
 (defun clangd-inactive-regions-set-method (method)
   (interactive
    (list (let ((completion-ignore-case t)
@@ -242,14 +231,33 @@ foreground colors, if the face doesn't exist yet create 
it."
           (push ov clangd-inactive-regions--overlays)))))))
 
 
-(cl-defmethod eglot-client-capabilities :around (server)
-  (let ((base (cl-call-next-method)))
-    (when (cl-find "clangd" (process-command (jsonrpc--process server))
-                   :test #'string-match)
-      (setf (cl-getf (cl-getf base :textDocument)
-                     :inactiveRegionsCapabilities)
-            '(:inactiveRegions t)))
-    base))
+(define-minor-mode clangd-inactive-regions-mode
+  "Minor mode to enable Eglot support for clangd inactiveRegions extension."
+  :global nil
+  (cond (clangd-inactive-regions-mode
+         (clangd-inactive-regions--enable))
+        (t
+         (clangd-inactive-regions--disable))))
+
+(defun clangd-inactive-regions--enable ()
+  (add-function :after (default-value 'font-lock-fontify-region-function)
+                #'clangd-inactive-regions--fontify)
+
+  (cl-defmethod eglot-client-capabilities :around (server)
+    (let ((base (cl-call-next-method)))
+      (when (cl-find "clangd" (process-command (jsonrpc--process server))
+                     :test #'string-match)
+        (setf (cl-getf (cl-getf base :textDocument)
+                       :inactiveRegionsCapabilities)
+              '(:inactiveRegions t)))
+      base)))
+
+(defun clangd-inactive-regions--disable ()
+  (remove-function (default-value 'font-lock-fontify-region-function)
+                   #'clangd-inactive-regions--fontify)
+  (clangd-inactive-regions-cleanup)
+  (cl-defmethod eglot-client-capabilities :around (server)
+    (cl-call-next-method)))
 
 (cl-defmethod eglot-handle-notification
   (_server (_method (eql textDocument/inactiveRegions))



reply via email to

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