[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/eglot-inactive-regions 15259e94b2 50/66: move to defcustom
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/eglot-inactive-regions 15259e94b2 50/66: move to defcustoms for customization |
Date: |
Fri, 6 Dec 2024 06:59:57 -0500 (EST) |
branch: elpa/eglot-inactive-regions
commit 15259e94b231554e0e805354e74748ebc263e12a
Author: Filippo Argiolas <filippo.argiolas@gmail.com>
Commit: Filippo Argiolas <filippo.argiolas@gmail.com>
move to defcustoms for customization
---
eglot-inactive-regions.el | 100 +++++++++++++++++++++++++++++-----------------
1 file changed, 64 insertions(+), 36 deletions(-)
diff --git a/eglot-inactive-regions.el b/eglot-inactive-regions.el
index 2d09cfcaef..ce93959a0a 100644
--- a/eglot-inactive-regions.el
+++ b/eglot-inactive-regions.el
@@ -34,7 +34,7 @@
;;
;; This mode provides visual feedback to quickly identify these disabled
;; code regions. Supports three visualization styles:
-;; - `shadow' applies shadow face from current theme
+;; - `shadow-face' applies shadow face from current theme
;; - `shade-background' makes the background slightly lighter or darker
;; - `darken-foreground' dims foreground colors
;;
@@ -49,32 +49,45 @@
(require 'color)
(require 'font-lock)
-(defvar eglot-inactive-regions-opacity 0.55
+(defgroup inactive-regions nil "Eglot Inactive Regions."
+ :group 'tools
+ :prefix "eglot-inactive-regions-")
+
+(defun eglot-inactive-regions--set-and-refresh (sym val)
+ "Set custom variable SYM to value VAL trigger a refresh of all active
buffers."
+ (set sym val)
+ (when (fboundp 'eglot-inactive-regions-refresh-all)
+ (eglot-inactive-regions-refresh-all)))
+
+(defcustom 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.")
+text will look dim."
+ :type '(float :tag "Opacity" :min 0.0 :max 1.0)
+ :set #'eglot-inactive-regions--set-and-refresh
+ :group 'inactive-regions)
-(defvar eglot-inactive-regions-shading 0.08
+(defcustom 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.")
+background face. The higher the less visible the shading will be."
+ :type '(float :tag "Opacity" :min 0.0 :max 1.0)
+ :set #'eglot-inactive-regions--set-and-refresh
+ :group 'inactive-regions)
-(defvar eglot-inactive-regions-method "darken-foreground"
- "Shading method to apply to the inactive code regions.
+(defcustom 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 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 eglot-inactive-regions--methods '("darken-foreground"
"shade-background" "shadow"))
+- shadow: apply shadow face."
+ :type '(choice
+ (const :tag "Darken foreground" darken-foreground)
+ (const :tag "Shade background" shade-background)
+ (const :tag "Shadow" shadow-face))
+ :set #'eglot-inactive-regions--set-and-refresh
+ :group 'inactive-regions)
(defface eglot-inactive-regions-shadow-face
'((t (:inherit shadow)))
@@ -84,25 +97,41 @@ Allowed methods:
'((t (:extend t)))
"Base face used to fontify inactive code with `shade-background' method.")
+(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)
+
(define-minor-mode eglot-inactive-regions-mode
"Minor mode to enable Eglot support for clangd inactiveRegions extension."
:global t
+ :group 'inactive-regions
(cond (eglot-inactive-regions-mode
(eglot-inactive-regions--enable))
(t
(eglot-inactive-regions--disable))))
+(defun eglot-inactive-regions--methods ()
+ "Return a list of methods and method names."
+ (let ((choices (get 'eglot-inactive-regions-method 'custom-type)))
+ (mapcar (lambda (opt)
+ (let ((symbol (car (last opt)))
+ (tag (plist-get (cdr opt) :tag)))
+ (cons symbol tag)))
+ (cdr choices))))
+
(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 eglot-inactive-regions--methods nil t nil))))
- (unless (member method eglot-inactive-regions--methods)
- (error "Unknown shading method: %s" method))
+ (let* ((methods (eglot-inactive-regions--methods))
+ (names (mapcar #'cdr methods))
+ (prompt "Set inactive regions shading method: ")
+ (value (completing-read prompt names)))
+ (list (car (rassoc value methods)))))
(setq eglot-inactive-regions-method method)
- (when eglot-inactive-regions-mode
- (eglot-inactive-regions-refresh-all)))
+ (eglot-inactive-regions-refresh-all))
(defun eglot-inactive-regions-set-opacity (opacity)
"Interactively set a new OPACITY value for inactive regions.
@@ -111,8 +140,7 @@ Only applies to `darken-foreground' method."
(unless (and (>= opacity 0.0) (<= opacity 1.0))
(error "Opacity should be between 0.0 and 1.0"))
(setq eglot-inactive-regions-opacity opacity)
- (when eglot-inactive-regions-mode
- (eglot-inactive-regions-refresh-all)))
+ (eglot-inactive-regions-refresh-all))
(defun eglot-inactive-regions-set-shading (shading)
"Interactively set a new SHADING value for inactive regions.
@@ -121,8 +149,7 @@ Only applies to `shade-background' method."
(unless (and (>= shading 0.0) (<= shading 1.0))
(error "Shading factor should be between 0.0 and 1.0"))
(setq eglot-inactive-regions-shading shading)
- (when eglot-inactive-regions-mode
- (eglot-inactive-regions-refresh-all)))
+ (eglot-inactive-regions-refresh-all))
(defun eglot-inactive-regions--color-blend (from-color to-color alpha)
"Linearly interpolate between two colors.
@@ -196,7 +223,7 @@ we don't want to include whitespace in fontification."
(ignore verbose)
(when (and eglot-inactive-regions-mode
eglot-inactive-regions--active
- (string= eglot-inactive-regions-method "darken-foreground"))
+ (eq eglot-inactive-regions-method 'darken-foreground))
(save-excursion
(save-restriction
(widen)
@@ -245,7 +272,7 @@ we don't want to include whitespace in fontification."
Useful to update colors after a face or theme change."
(eglot-inactive-regions-cleanup)
(when eglot-inactive-regions--active
- (when (string= eglot-inactive-regions-method "shade-background")
+ (when (eq eglot-inactive-regions-method 'shade-background)
(set-face-background 'eglot-inactive-regions-shade-face
(eglot-inactive-regions--color-blend
(face-foreground 'default)
@@ -255,24 +282,25 @@ Useful to update colors after a face or theme change."
(let ((beg (car range))
(end (cdr range)))
(cond
- ((string= eglot-inactive-regions-method "darken-foreground")
+ ((eq eglot-inactive-regions-method 'darken-foreground)
(with-silent-modifications
(put-text-property beg end 'eglot-inactive-region t))
(font-lock-flush))
- ((string= eglot-inactive-regions-method "shadow")
+ ((eq eglot-inactive-regions-method 'shadow-face)
(let ((ov (make-overlay beg end)))
(overlay-put ov 'face 'eglot-inactive-regions-shadow-face)
(push ov eglot-inactive-regions--overlays)))
- ((string= eglot-inactive-regions-method "shade-background")
+ ((eq eglot-inactive-regions-method 'shade-background)
(let ((ov (make-overlay beg (1+ end))))
(overlay-put ov 'face 'eglot-inactive-regions-shade-face)
(push ov eglot-inactive-regions--overlays))))))))
(defun eglot-inactive-regions-refresh-all ()
"Refresh all buffers where this mode is enabled."
- (dolist (buffer (buffer-list))
- (with-current-buffer buffer
- (eglot-inactive-regions-refresh))))
+ (when eglot-inactive-regions-mode
+ (dolist (buffer (buffer-list))
+ (with-current-buffer buffer
+ (eglot-inactive-regions-refresh)))))
(defun eglot-inactive-regions--enable ()
"Helper method to enable inactive regions minor mode."
- [nongnu] elpa/eglot-inactive-regions 5c20f58422 60/66: clean up after review on emacs-devel, (continued)
- [nongnu] elpa/eglot-inactive-regions 5c20f58422 60/66: clean up after review on emacs-devel, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 80c1b60009 44/66: Revert "revert to deprecated eglot functions", ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 26f3b61b45 51/66: readme update, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions badb4e403a 46/66: cleanup on major mode changes, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions a810593308 59/66: bump version to 0.6, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 7e4eb584e0 61/66: fallback to deprecated functions, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 6ac373dfd0 62/66: bump version after emacs-devel review, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 3569bd5dc7 24/66: Properly enable/clean up state on minor mode toggle, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 3b248e0684 37/66: Update install section in README.md, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 3ca295f189 45/66: switch to global minor mode, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 15259e94b2 50/66: move to defcustoms for customization,
ELPA Syncer <=
- [nongnu] elpa/eglot-inactive-regions 5b48f4940d 54/66: rename shading method to shading style, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 2d93c0cab0 04/66: forgot some package comment, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 3cb6ed0bc4 34/66: update README.md, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 5e08869dd6 36/66: Bump version to 0.3, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 89ffc22d6f 49/66: rename main package file, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 7a9e3ac805 57/66: refactor and cleanup, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 12794454af 41/66: properly check if mode is enabled, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions f4a79c0d0f 35/66: Remove a couple of setq-s to make byte compiler happy, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 4a33baf9e6 52/66: no need to enable extra caps for ccls, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 2c83a3230d 66/66: bump release after elpaignore inclusion, ELPA Syncer, 2024/12/06