[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/eglot-inactive-regions 3d3280c415 48/66: rename to eglot-i
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/eglot-inactive-regions 3d3280c415 48/66: rename to eglot-inactive-regions.el |
Date: |
Fri, 6 Dec 2024 06:59:57 -0500 (EST) |
branch: elpa/eglot-inactive-regions
commit 3d3280c4150bf9f8bfd7905c5db9deaf92a2317b
Author: Filippo Argiolas <filippo.argiolas@gmail.com>
Commit: Filippo Argiolas <filippo.argiolas@gmail.com>
rename to eglot-inactive-regions.el
with the CCLS support we are no longer clangd specific, rename to a more
generig eglot extension
---
clangd-inactive-regions.el | 245 ++++++++++++++++++++++++---------------------
1 file changed, 131 insertions(+), 114 deletions(-)
diff --git a/clangd-inactive-regions.el b/clangd-inactive-regions.el
index 42972afc12..2d09cfcaef 100644
--- a/clangd-inactive-regions.el
+++ b/clangd-inactive-regions.el
@@ -1,4 +1,4 @@
-;;; clangd-inactive-regions.el --- Highlight inactive code regions with clangd
power -*- lexical-binding: t; -*-
+;;; eglot-inactive-regions.el --- Highlight inactive code regions with eglot
power -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Filippo Argiolas <filippo.argiolas@gmail.com>
;; Based on an example implementation from João Távora
@@ -9,26 +9,38 @@
;; URL: https://github.com/fargiolas/clangd-inactive-regions.el
;; Package-Requires: ((emacs "29.1"))
-;; clangd-inactive-regions.el is free software: you can redistribute
+;; eglot-inactive-regions.el is free software: you can redistribute
;; it and/or modify it under the terms of the GNU General Public
;; License as published by the Free Software Foundation, either
;; version 3 of the License, or (at your option) any later version.
-;; clangd-inactive-regions.el is distributed in the hope that it will
+;; eglot-inactive-regions.el is distributed in the hope that it will
;; be useful, but WITHOUT ANY WARRANTY; without even the implied
;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;; See the GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with clangd-inactive-regions.el. If not, see
+;; along with eglot-inactive-regions.el. If not, see
;; <https://www.gnu.org/licenses/>.
;;; Commentary:
-;; This package extends Eglot to enable clangd inactiveRegions LSP
-;; protocol extension (introduced in clangd-17)
-;; It listens to inactiveRegions server notifications and use them to
-;; darken inactive code
+;; This package extends Eglot to enable inactive code regions
+;; detection and shading.
+;;
+;; LSP servers provide information about currently disabled
+;; preprocessor branches with knowledge about build-time options and
+;; defines.
+;;
+;; This mode provides visual feedback to quickly identify these disabled
+;; code regions. Supports three visualization styles:
+;; - `shadow' applies shadow face from current theme
+;; - `shade-background' makes the background slightly lighter or darker
+;; - `darken-foreground' dims foreground colors
+;;
+;; Currently supported servers:
+;; - `clangd' with inactiveRegions extension (needs clangd-17+)
+;; - `ccls' with skippedRegions extension
;;; Code:
@@ -37,82 +49,82 @@
(require 'color)
(require 'font-lock)
-(defvar clangd-inactive-regions-opacity 0.55
+(defvar eglot-inactive-regions-opacity 0.55
"Blending factor for the `darken-foreground' method.
Used to mix foreground and background colors and apply to the foreground
face of the inactive region. The lower the blending factor the more
text will look dim.")
-(defvar clangd-inactive-regions-shading 0.08
+(defvar eglot-inactive-regions-shading 0.08
"Blending factor for the `shade-background' method.
Used to mix background and foreground colors and shade inactive region
background face. The higher the less visible the shading will be.")
-(defvar clangd-inactive-regions-method "darken-foreground"
+(defvar eglot-inactive-regions-method "darken-foreground"
"Shading method to apply to the inactive code regions.
Allowed methods:
- darken-foreground: dim foreground color
- shade-background: shade background color
- shadow: apply shadow face.")
-(defvar-local clangd-inactive-regions--overlays '())
-(setq-default clangd-inactive-regions--overlays '())
-(defvar-local clangd-inactive-regions--ranges '())
-(setq-default clangd-inactive-regions--ranges '())
-(defvar-local clangd-inactive-regions--active nil)
-(setq-default clangd-inactive-regions--active nil)
+(defvar-local eglot-inactive-regions--overlays '())
+(setq-default eglot-inactive-regions--overlays '())
+(defvar-local eglot-inactive-regions--ranges '())
+(setq-default eglot-inactive-regions--ranges '())
+(defvar-local eglot-inactive-regions--active nil)
+(setq-default eglot-inactive-regions--active nil)
-(defvar clangd-inactive-regions--methods '("darken-foreground"
"shade-background" "shadow"))
+(defvar eglot-inactive-regions--methods '("darken-foreground"
"shade-background" "shadow"))
-(defface clangd-inactive-regions-shadow-face
+(defface eglot-inactive-regions-shadow-face
'((t (:inherit shadow)))
"Base face used to fontify inactive code with `shadow' method.")
-(defface clangd-inactive-regions-shade-face
+(defface eglot-inactive-regions-shade-face
'((t (:extend t)))
"Base face used to fontify inactive code with `shade-background' method.")
-(define-minor-mode clangd-inactive-regions-mode
+(define-minor-mode eglot-inactive-regions-mode
"Minor mode to enable Eglot support for clangd inactiveRegions extension."
:global t
- (cond (clangd-inactive-regions-mode
- (clangd-inactive-regions--enable))
+ (cond (eglot-inactive-regions-mode
+ (eglot-inactive-regions--enable))
(t
- (clangd-inactive-regions--disable))))
+ (eglot-inactive-regions--disable))))
-(defun clangd-inactive-regions-set-method (method)
+(defun eglot-inactive-regions-set-method (method)
"Interactively select a shading METHOD to render inactive code regions."
(interactive
(list (let ((completion-ignore-case t)
(prompt "Set inactive regions shading method: "))
- (completing-read prompt clangd-inactive-regions--methods nil t
nil))))
- (unless (member method clangd-inactive-regions--methods)
+ (completing-read prompt eglot-inactive-regions--methods nil t nil))))
+ (unless (member method eglot-inactive-regions--methods)
(error "Unknown shading method: %s" method))
- (setq clangd-inactive-regions-method method)
- (when clangd-inactive-regions-mode
- (clangd-inactive-regions-refresh-all)))
+ (setq eglot-inactive-regions-method method)
+ (when eglot-inactive-regions-mode
+ (eglot-inactive-regions-refresh-all)))
-(defun clangd-inactive-regions-set-opacity (opacity)
+(defun eglot-inactive-regions-set-opacity (opacity)
"Interactively set a new OPACITY value for inactive regions.
Only applies to `darken-foreground' method."
(interactive "nNew inactive region foreground color opacity [0-1.0]: ")
(unless (and (>= opacity 0.0) (<= opacity 1.0))
(error "Opacity should be between 0.0 and 1.0"))
- (setq clangd-inactive-regions-opacity opacity)
- (when clangd-inactive-regions-mode
- (clangd-inactive-regions-refresh-all)))
+ (setq eglot-inactive-regions-opacity opacity)
+ (when eglot-inactive-regions-mode
+ (eglot-inactive-regions-refresh-all)))
-(defun clangd-inactive-regions-set-shading (shading)
+(defun eglot-inactive-regions-set-shading (shading)
"Interactively set a new SHADING value for inactive regions.
Only applies to `shade-background' method."
(interactive "nNew inactive region background color shading [0-1.0]: ")
(unless (and (>= shading 0.0) (<= shading 1.0))
(error "Shading factor should be between 0.0 and 1.0"))
- (setq clangd-inactive-regions-shading shading)
- (when clangd-inactive-regions-mode
- (clangd-inactive-regions-refresh-all)))
+ (setq eglot-inactive-regions-shading shading)
+ (when eglot-inactive-regions-mode
+ (eglot-inactive-regions-refresh-all)))
-(defun clangd-inactive-regions--color-blend (from-color to-color alpha)
+(defun eglot-inactive-regions--color-blend (from-color to-color alpha)
"Linearly interpolate between two colors.
Blend colors FROM-COLOR and TO-COLOR with ALPHA interpolation
factor."
@@ -125,16 +137,16 @@ factor."
from-rgb to-rgb))
'unspecified)))
-(defun clangd-inactive-regions-cleanup ()
+(defun eglot-inactive-regions-cleanup ()
"Clean up inactive regions."
- (when clangd-inactive-regions--active
- (mapc #'delete-overlay clangd-inactive-regions--overlays)
- (setq clangd-inactive-regions--overlays '())
+ (when eglot-inactive-regions--active
+ (mapc #'delete-overlay eglot-inactive-regions--overlays)
+ (setq eglot-inactive-regions--overlays '())
(with-silent-modifications
- (remove-text-properties (point-min) (point-max) '(clangd-inactive-region
nil)))
+ (remove-text-properties (point-min) (point-max) '(eglot-inactive-region
nil)))
(font-lock-flush)))
-(defun clangd-inactive-regions--get-face (pos)
+(defun eglot-inactive-regions--get-face (pos)
"Get face at POS.
If no face is present return `default', if multiple faces are
present return the higher priority one."
@@ -144,24 +156,24 @@ present return the higher priority one."
(car face-prop)
face-prop)))
-(defun clangd-inactive-regions--make-darken-face (parent-face)
+(defun eglot-inactive-regions--make-darken-face (parent-face)
"New face from PARENT-FACE with dimmed foreground.
If the correspondend \"clangd-inactive\" face doesn't not exist yet create it."
(let* ((fg (face-foreground parent-face nil 'default))
(bg (face-background parent-face nil 'default))
- (clangd-inactive-fg (clangd-inactive-regions--color-blend fg bg
clangd-inactive-regions-opacity))
- (clangd-inactive-face-name (concat (face-name parent-face)
"-clangd-inactive"))
- (clangd-inactive-face (intern clangd-inactive-face-name))
- (clangd-inactive-doc (concat (face-documentation parent-face) "
(clangd inactive region darkened face)")))
+ (eglot-inactive-fg (eglot-inactive-regions--color-blend fg bg
eglot-inactive-regions-opacity))
+ (eglot-inactive-face-name (concat (face-name parent-face)
"-clangd-inactive"))
+ (eglot-inactive-face (intern eglot-inactive-face-name))
+ (eglot-inactive-doc (concat (face-documentation parent-face) "
(clangd inactive region darkened face)")))
- (unless (facep clangd-inactive-face)
- (eval `(defface ,clangd-inactive-face '((t nil)) ,clangd-inactive-doc)))
+ (unless (facep eglot-inactive-face)
+ (eval `(defface ,eglot-inactive-face '((t nil)) ,eglot-inactive-doc)))
- (set-face-foreground clangd-inactive-face clangd-inactive-fg)
+ (set-face-foreground eglot-inactive-face eglot-inactive-fg)
- clangd-inactive-face))
+ eglot-inactive-face))
-(defun clangd-inactive-regions--forward-face-or-whitespace ()
+(defun eglot-inactive-regions--forward-face-or-whitespace ()
"Forward to the next face change.
Some mode use `default' face for both generic keywords and
whitespace while some other uses nil for whitespace. Either way
@@ -175,16 +187,16 @@ we don't want to include whitespace in fontification."
(forward-char)
(setq next-face (get-text-property (point) 'face)))))
-(defun clangd-inactive-regions--fontify (start end &optional verbose)
+(defun eglot-inactive-regions--fontify (start end &optional verbose)
"Fontify inactive region (START END) with semitransparent faces."
;; sometimes font lock fontifies in chunks and each fontification
;; functions takes care of extending the region to something
;; syntactically relevant... guess we need to do the same, extend to
;; cover whole lines seems to work with c modes
(ignore verbose)
- (when (and clangd-inactive-regions-mode
- clangd-inactive-regions--active
- (string= clangd-inactive-regions-method "darken-foreground"))
+ (when (and eglot-inactive-regions-mode
+ eglot-inactive-regions--active
+ (string= eglot-inactive-regions-method "darken-foreground"))
(save-excursion
(save-restriction
(widen)
@@ -200,8 +212,8 @@ we don't want to include whitespace in fontification."
;; find the inactive region inside the region to fontify
(while (and start (< start end))
- (let* ((from (or (text-property-any start end 'clangd-inactive-region t)
end))
- (to (or (text-property-any from end 'clangd-inactive-region nil)
end))
+ (let* ((from (or (text-property-any start end 'eglot-inactive-region t)
end))
+ (to (or (text-property-any from end 'eglot-inactive-region nil)
end))
(beg from))
;; the idea here is to iterate through the region by syntax
;; blocks, derive a new face from current one with dimmed
@@ -217,67 +229,86 @@ we don't want to include whitespace in fontification."
(widen)
(goto-char from)
(while (<= (point) to)
- (clangd-inactive-regions--forward-face-or-whitespace)
+ (eglot-inactive-regions--forward-face-or-whitespace)
;; no need to dim whitespace
(unless (string-match-p "[[:blank:]\n]" (string (char-before)))
- (let* ((cur-face (clangd-inactive-regions--get-face (1-
(point))))
- (clangd-inactive-face
(clangd-inactive-regions--make-darken-face cur-face)))
+ (let* ((cur-face (eglot-inactive-regions--get-face (1-
(point))))
+ (eglot-inactive-face
(eglot-inactive-regions--make-darken-face cur-face)))
(let* ((ov (make-overlay beg (point))))
- (overlay-put ov 'face clangd-inactive-face)
- (push ov clangd-inactive-regions--overlays))))
+ (overlay-put ov 'face eglot-inactive-face)
+ (push ov eglot-inactive-regions--overlays))))
(setq beg (point))))))
(setq start to)))))
-(defun clangd-inactive-regions-refresh ()
+(defun eglot-inactive-regions-refresh ()
"Force a refresh of known inactive regions.
Useful to update colors after a face or theme change."
- (clangd-inactive-regions-cleanup)
- (when clangd-inactive-regions--active
- (when (string= clangd-inactive-regions-method "shade-background")
- (set-face-background 'clangd-inactive-regions-shade-face
- (clangd-inactive-regions--color-blend
+ (eglot-inactive-regions-cleanup)
+ (when eglot-inactive-regions--active
+ (when (string= eglot-inactive-regions-method "shade-background")
+ (set-face-background 'eglot-inactive-regions-shade-face
+ (eglot-inactive-regions--color-blend
(face-foreground 'default)
(face-background 'default)
- clangd-inactive-regions-shading)))
- (dolist (range clangd-inactive-regions--ranges)
+ eglot-inactive-regions-shading)))
+ (dolist (range eglot-inactive-regions--ranges)
(let ((beg (car range))
(end (cdr range)))
(cond
- ((string= clangd-inactive-regions-method "darken-foreground")
+ ((string= eglot-inactive-regions-method "darken-foreground")
(with-silent-modifications
- (put-text-property beg end 'clangd-inactive-region t))
+ (put-text-property beg end 'eglot-inactive-region t))
(font-lock-flush))
- ((string= clangd-inactive-regions-method "shadow")
+ ((string= eglot-inactive-regions-method "shadow")
(let ((ov (make-overlay beg end)))
- (overlay-put ov 'face 'clangd-inactive-regions-shadow-face)
- (push ov clangd-inactive-regions--overlays)))
- ((string= clangd-inactive-regions-method "shade-background")
+ (overlay-put ov 'face 'eglot-inactive-regions-shadow-face)
+ (push ov eglot-inactive-regions--overlays)))
+ ((string= eglot-inactive-regions-method "shade-background")
(let ((ov (make-overlay beg (1+ end))))
- (overlay-put ov 'face 'clangd-inactive-regions-shade-face)
- (push ov clangd-inactive-regions--overlays))))))))
+ (overlay-put ov 'face 'eglot-inactive-regions-shade-face)
+ (push ov eglot-inactive-regions--overlays))))))))
-(defun clangd-inactive-regions-refresh-all ()
+(defun eglot-inactive-regions-refresh-all ()
+ "Refresh all buffers where this mode is enabled."
(dolist (buffer (buffer-list))
(with-current-buffer buffer
- (clangd-inactive-regions-refresh))))
+ (eglot-inactive-regions-refresh))))
-(defun clangd-inactive-regions--enable ()
+(defun eglot-inactive-regions--enable ()
"Helper method to enable inactive regions minor mode."
(add-function :after (default-value 'font-lock-fontify-region-function)
- #'clangd-inactive-regions--fontify)
- (add-hook 'change-major-mode-hook #'clangd-inactive-regions-cleanup))
+ #'eglot-inactive-regions--fontify)
+ (add-hook 'change-major-mode-hook #'eglot-inactive-regions-cleanup))
-(defun clangd-inactive-regions--disable ()
+(defun eglot-inactive-regions--disable ()
"Helper method to enable inactive regions minor mode."
(remove-function (default-value 'font-lock-fontify-region-function)
- #'clangd-inactive-regions--fontify)
- (dolist (buf (buffer-list))
- (clangd-inactive-regions-cleanup)
- (setq clangd-inactive-regions--ranges '())
- (setq clangd-inactive-regions--active nil))
- (remove-hook 'change-major-mode-hook #'clangd-inactive-regions-cleanup))
+ #'eglot-inactive-regions--fontify)
+ (dolist (buffer (buffer-list))
+ (with-current-buffer buffer
+ (eglot-inactive-regions-cleanup)
+ (setq eglot-inactive-regions--ranges '())
+ (setq eglot-inactive-regions--active nil)))
+ (remove-hook 'change-major-mode-hook #'eglot-inactive-regions-cleanup))
+
+(defun eglot-inactive-regions--handle-notification (uri regions)
+ "Update inactive REGIONS for the buffer corresponding to URI."
+ (if-let* ((path (expand-file-name (eglot-uri-to-path uri)))
+ (buffer (find-buffer-visiting path)))
+ (with-current-buffer buffer
+ (when eglot-inactive-regions-mode
+ (unless eglot-inactive-regions--active
+ (setq eglot-inactive-regions--active t))
+ (setq eglot-inactive-regions--ranges '())
+ (cl-loop
+ for r across regions
+ for (beg . end) = (eglot-range-region r)
+ do
+ (push (cons beg end) eglot-inactive-regions--ranges))
+ (eglot-inactive-regions-refresh)))))
(cl-defmethod eglot-client-capabilities :around (server)
+ "Enable inactive code capabilities for SERVER."
(let ((base (cl-call-next-method)))
(when (cl-some (lambda (s) (cl-find s (process-command (jsonrpc--process
server))
:test #'string-match))
@@ -287,33 +318,19 @@ Useful to update colors after a face or theme change."
'(:inactiveRegions t)))
base))
-(defun clangd-inactive-regions--handle-notification (uri regions)
- (if-let* ((path (expand-file-name (eglot-uri-to-path uri)))
- (buffer (find-buffer-visiting path)))
- (with-current-buffer buffer
- (when clangd-inactive-regions-mode
- (unless clangd-inactive-regions--active
- (setq clangd-inactive-regions--active t))
- (setq clangd-inactive-regions--ranges '())
- (cl-loop
- for r across regions
- for (beg . end) = (eglot-range-region r)
- do
- (push (cons beg end) clangd-inactive-regions--ranges))
- (clangd-inactive-regions-refresh)))))
-
(cl-defmethod eglot-handle-notification
(_server (_method (eql $ccls/publishSkippedRanges))
&key uri skippedRanges)
- (clangd-inactive-regions--handle-notification uri skippedRanges))
+ "Listen to ccls skippedRanges notifications."
+ (eglot-inactive-regions--handle-notification uri skippedRanges))
(cl-defmethod eglot-handle-notification
(_server (_method (eql textDocument/inactiveRegions))
&key regions textDocument &allow-other-keys)
- "Update inactive regions when clangd reports them."
+ "Listen to clangd inactiveRegions notifications."
(if-let ((uri (cl-getf textDocument :uri)))
- (clangd-inactive-regions--handle-notification uri regions)))
+ (eglot-inactive-regions--handle-notification uri regions)))
-(provide 'clangd-inactive-regions)
+(provide 'eglot-inactive-regions)
-;;; clangd-inactive-regions.el ends here
+;;; eglot-inactive-regions.el ends here
- [nongnu] elpa/eglot-inactive-regions f47d728c65 11/66: Stage basic README, (continued)
- [nongnu] elpa/eglot-inactive-regions f47d728c65 11/66: Stage basic README, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 65fbd7a7a1 08/66: Support for different shading methods to render inactive regions, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions ea8da46342 01/66: Initial commit, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 9dba1b222d 14/66: Check for valid ranges when setting parameters, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 4f5ab3203c 17/66: No need to copy-tree ranges, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 5528f4d3e1 03/66: fix gpl preamble, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 4fc6480bed 18/66: Move forward if forward-same-syntax does not, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 2e52c1a10a 19/66: Use my own forward function, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 3876101626 31/66: Update README., ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions b0ade8c12e 21/66: Handle face list properties, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 3d3280c415 48/66: rename to eglot-inactive-regions.el,
ELPA Syncer <=
- [nongnu] elpa/eglot-inactive-regions 475864a1a3 65/66: exclude screenshots from the tarball, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 17c9db32d3 02/66: initial commit, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions e15124a898 07/66: Rewrite the darkening logic using fontify-region, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions e7be73b354 15/66: Invert shading factor, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions b81249c566 23/66: Update README with caveats section, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 4b01aba42f 29/66: Fix package-lint warnings, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 2346944d4b 05/66: Add clean up and refresh functions, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 3ba8e528f1 06/66: allow to change opacity on the fly, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 10f1772888 09/66: Drop eglot from the name, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 2736b46310 10/66: Update dependencies and some minor changes, ELPA Syncer, 2024/12/06