[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/eglot-inactive-regions ae67afac14 12/66: Use overlays inst
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/eglot-inactive-regions ae67afac14 12/66: Use overlays instead of changing text properties |
Date: |
Fri, 6 Dec 2024 06:59:51 -0500 (EST) |
branch: elpa/eglot-inactive-regions
commit ae67afac149f76d717cebb960f836f2efd743d1e
Author: Filippo Argiolas <filippo.argiolas@gmail.com>
Commit: Filippo Argiolas <filippo.argiolas@gmail.com>
Use overlays instead of changing text properties
Eli pointed out that directly changing text properties may break code
using font-lock faces as a short cut for syntax analysis. Try to use
overlays instead: for each syntax unit in a inactive region create an
overlay with a dimmed foreground face and apply to it. Needs some
testing performance-wise.
---
clangd-inactive-regions.el | 72 +++++++++++++++++++++++++---------------------
1 file changed, 39 insertions(+), 33 deletions(-)
diff --git a/clangd-inactive-regions.el b/clangd-inactive-regions.el
index efff2d45cb..9ebf510c27 100644
--- a/clangd-inactive-regions.el
+++ b/clangd-inactive-regions.el
@@ -91,14 +91,32 @@ Allowed methods:
(defun clangd-inactive-regions-cleanup ()
"Clean up inactive regions."
(mapc #'delete-overlay clangd-inactive-regions--overlays)
+ (setq clangd-inactive-regions--overlays '())
(with-silent-modifications
- (remove-text-properties (point-min) (point-max) '(ecir-inactive nil)))
+ (remove-text-properties (point-min) (point-max) '(clangd-inactive-region
nil)))
(font-lock-flush))
(defun clangd-inactive-regions--get-face (pos)
(or (get-text-property pos 'face)
'default))
+(defun clangd-inactive-regions--make-darken-face (parent-face)
+ "Return a new face from PARENT-FACE blending background and
+foreground colors, if the face doesn't 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)")))
+
+ (unless (facep clangd-inactive-face)
+ (eval `(defface ,clangd-inactive-face '((t nil)) ,clangd-inactive-doc)))
+
+ (set-face-foreground clangd-inactive-face clangd-inactive-fg)
+
+ clangd-inactive-face))
+
(defun clangd-inactive-regions--fontify (start end &rest args)
;; sometimes font lock fontifies in chunks and each fontification
;; functions takes care of extending the region to something
@@ -119,47 +137,35 @@ Allowed methods:
;; find the inactive region inside the region to fontify
(while (and start (< start end))
- (setq from (or (text-property-any start end 'ecir-inactive t)
- end))
- (setq to (or (text-property-any from end 'ecir-inactive nil)
+ (setq from (or (text-property-any start end 'clangd-inactive-region t)
end))
+ (setq to (or (text-property-any from end 'clangd-inactive-region nil)
+ end))
- ;; the idea now is to iterate through the region, split it at face
- ;; changes, create a new inactive face with darkened color and
- ;; apply it
+ ;; the idea here is to iterate through the region by syntax
+ ;; blocks, derive a new face from current one with dimmed
+ ;; foreground and apply the new face with an overlay
- ;; code is a bit more convoluted than I'd like but I'm pretty new
- ;; at elisp and it seems to work
+ ;; there is some overlay duplication for regions extended by the
+ ;; above code but they will only live until the next inactive
+ ;; region update and don't seem to cause much issues... will keep
+ ;; an eye on it while I find a solution
(setq beg from)
(when (> to from)
(save-excursion
(save-restriction
(widen)
(goto-char from)
- (setq cur-face (clangd-inactive-regions--get-face (point)))
(while (<= (point) to)
- (let* ((new-face (clangd-inactive-regions--get-face (point))))
- ;; chunk to fontify ends either at a face change or at
- ;; TO region limit. Use face name to check if chunk is already
fontified
- (when (and (or (not (eq cur-face new-face))
- (eq (point) to))
- (not (string-suffix-p "-clangd-inactive" (face-name
cur-face))))
-
- (let* ((fg (face-foreground cur-face nil 'default))
- (bg (face-background cur-face nil 'default))
- (clangd-inactive-fg
(clangd-inactive-regions--color-blend fg bg clangd-inactive-regions-opacity))
- (clangd-inactive-face-name (concat (face-name cur-face)
"-clangd-inactive"))
- (clangd-inactive-face (intern
clangd-inactive-face-name))
- (clangd-inactive-doc (concat (face-documentation
cur-face) " (clangd inactive region darkened face)")))
-
- (unless (facep clangd-inactive-face)
- (eval `(defface ,clangd-inactive-face '((t nil))
,clangd-inactive-doc)))
-
- (set-face-foreground clangd-inactive-face clangd-inactive-fg)
- (put-text-property beg (point) 'face clangd-inactive-face))
- (setq beg (point)))
- (setq cur-face new-face))
- (forward-char)))))
+ (forward-same-syntax)
+ ;; 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* ((ov (make-overlay beg (point))))
+ (overlay-put ov 'face clangd-inactive-face)
+ (push ov clangd-inactive-regions--overlays))))
+ (setq beg (point))))))
(setq start to)))
(defun clangd-inactive-regions-refresh ()
@@ -180,7 +186,7 @@ Allowed methods:
(cond
((string= clangd-inactive-regions-method "darken-foreground")
(with-silent-modifications
- (put-text-property beg end 'ecir-inactive t))
+ (put-text-property beg end 'clangd-inactive-region t))
(font-lock-flush beg end))
((string= clangd-inactive-regions-method "shadow")
(let ((ov (make-overlay beg end)))
- [nongnu] elpa/eglot-inactive-regions 17c9db32d3 02/66: initial commit, (continued)
- [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
- [nongnu] elpa/eglot-inactive-regions 15d6db2d6d 13/66: Add some helper methods to set UI options, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions ae67afac14 12/66: Use overlays instead of changing text properties,
ELPA Syncer <=
- [nongnu] elpa/eglot-inactive-regions 343abb100c 26/66: Update README.md, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions e25016ddb8 22/66: Do not flush all inactive regions, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions d021d96fef 25/66: Update screenshots, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 52d2f80ccb 28/66: Tentatively limit global fontification hook to classic c modes, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 4ae3491ae3 39/66: doc and function names cleanup, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 21c26bc4e2 40/66: use built-in color to hex converter, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 4b698aaeb8 42/66: always enable inactiveRegions caps, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 6ad3ce4337 47/66: experimental support for ccls skippedRanges, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions bdf568d9ff 63/66: suppress warnings for obsolete eglot functions, ELPA Syncer, 2024/12/06
- [nongnu] elpa/eglot-inactive-regions 20cacf2b2d 16/66: Warn if shading method is unknown, ELPA Syncer, 2024/12/06