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

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

[nongnu] elpa/eglot-inactive-regions 52d2f80ccb 28/66: Tentatively limit


From: ELPA Syncer
Subject: [nongnu] elpa/eglot-inactive-regions 52d2f80ccb 28/66: Tentatively limit global fontification hook to classic c modes
Date: Fri, 6 Dec 2024 06:59:54 -0500 (EST)

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

    Tentatively limit global fontification hook to classic c modes
    
    Advice default fontify-region hook only with c/c++ major modes, keep
    it local otherwise. As far as I know only classic c modes extend
    fontification region chaining the new region into the default
    function.
    
    Keep it buffer local for other modes (notably c/c++ ts modes).
    
    Only disable the global advice if our minor mode is not active in any
    classic c mode buffer.
    
    Still way to hacky for my taste...
---
 clangd-inactive-regions.el | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/clangd-inactive-regions.el b/clangd-inactive-regions.el
index 1a99ce010f..134caf7a38 100644
--- a/clangd-inactive-regions.el
+++ b/clangd-inactive-regions.el
@@ -241,8 +241,11 @@ foreground colors, if the face doesn't exist yet create 
it."
          (clangd-inactive-regions--disable))))
 
 (defun clangd-inactive-regions--enable ()
-  (add-function :after (default-value 'font-lock-fontify-region-function)
-                #'clangd-inactive-regions--fontify)
+  (if (memq major-mode '(c-mode c++-mode))
+      (add-function :after (default-value 'font-lock-fontify-region-function)
+                    #'clangd-inactive-regions--fontify)
+    (add-function :after (local 'font-lock-fontify-region-function)
+                  #'clangd-inactive-regions--fontify))
 
   (cl-defmethod eglot-client-capabilities :around (server)
     (let ((base (cl-call-next-method)))
@@ -253,9 +256,22 @@ foreground colors, if the face doesn't exist yet create 
it."
               '(:inactiveRegions t)))
       base)))
 
+(defun clangd-inactive-regions--enabled-anywhere ()
+  (let ((enabled nil))
+    (dolist (buffer (buffer-list))
+      (with-current-buffer buffer
+        (and (memq major-mode '(c-mode c++-mode))
+             (clangd-inactive-regions-mode)
+             (setq enabled t))))
+    enabled))
+
 (defun clangd-inactive-regions--disable ()
-  (remove-function (default-value 'font-lock-fontify-region-function)
-                   #'clangd-inactive-regions--fontify)
+  (if (memq major-mode '(c-mode c++-mode))
+      (unless (clangd-inactive-regions--enabled-anywhere)
+        (remove-function (default-value 'font-lock-fontify-region-function)
+                         #'clangd-inactive-regions--fontify))
+    (remove-function (local 'font-lock-fontify-region-function)
+                     #'clangd-inactive-regions--fontify))
   (clangd-inactive-regions-cleanup)
   (cl-defmethod eglot-client-capabilities :around (server)
     (cl-call-next-method)))



reply via email to

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