[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/hl-block-mode c6341f404e 44/64: Cleanup: store range data
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/hl-block-mode c6341f404e 44/64: Cleanup: store range data in cons cells instead of lists |
Date: |
Thu, 7 Jul 2022 12:00:08 -0400 (EDT) |
branch: elpa/hl-block-mode
commit c6341f404ebf77948212993e077244b56cc1aa4a
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Cleanup: store range data in cons cells instead of lists
---
hl-block-mode.el | 78 ++++++++++++++++++++++++++++++--------------------------
1 file changed, 42 insertions(+), 36 deletions(-)
diff --git a/hl-block-mode.el b/hl-block-mode.el
index 132efe11e6..00bd90594b 100644
--- a/hl-block-mode.el
+++ b/hl-block-mode.el
@@ -97,15 +97,15 @@ PT is typically the '(point)'."
(hl-block--find-all-ranges beg))))
(when beg
(if range-prev
- (cons (list beg end) range-prev)
- (list (list beg end))))))
+ (cons (cons beg end) range-prev)
+ (list (cons beg end))))))
(defun hl-block--find-all-ranges-or-fallback (pt)
"Return ranges starting from PT, outer-most to inner-most (with fallback)."
(when-let ((block-list (hl-block--find-all-ranges pt)))
(if (cdr block-list)
(reverse block-list)
- (cons (list (point-min) (point-max)) block-list))))
+ (cons (cons (point-min) (point-max)) block-list))))
(defun hl-block--color-values-as-string (color)
"Build a color from COLOR.
@@ -134,39 +134,45 @@ Inverse of `color-values'."
(defun hl-block--overlay-refresh ()
"Update the overlays based on the cursor location."
(hl-block--overlay-clear)
- (when-let ((block-list (save-excursion
(hl-block--find-all-ranges-or-fallback (point)))))
- (let*
- (
- (beg-prev (nth 0 (nth 0 block-list)))
- (end-prev (nth 1 (nth 0 block-list)))
- (block-list-len (length block-list))
- (bg-color (apply 'vector (color-values (face-attribute 'default
:background))))
- (bg-color-tint (apply 'vector (color-values hl-block-color-tint)))
- ;; Check dark background is light/dark.
- (do-highlight (> 98304 (+ (aref bg-color 0) (aref bg-color 1) (aref
bg-color 2))))
- ;; Iterator.
- (i 0))
-
- (dolist (elem_range (cdr block-list))
- (let*
- (
- (i-tint (- block-list-len i))
- (beg (nth 0 elem_range))
- (end (nth 1 elem_range))
- (elem-overlay-beg (make-overlay beg beg-prev))
- (elem-overlay-end (make-overlay end-prev end))
- (bg-color-blend
- (hl-block--color-values-as-string
- (if do-highlight
- (hl-block--color-tint-add bg-color bg-color-tint i-tint)
- (hl-block--color-tint-sub bg-color bg-color-tint i-tint)))))
- (overlay-put elem-overlay-beg 'face `(:background ,bg-color-blend
:extend t))
- (overlay-put elem-overlay-end 'face `(:background ,bg-color-blend
:extend t))
- (push elem-overlay-beg hl-block-overlay)
- (push elem-overlay-end hl-block-overlay)
- (setq beg-prev beg)
- (setq end-prev end))
- (setq i (1+ i))))))
+ (let ((block-list (save-excursion (hl-block--find-all-ranges-or-fallback
(point)))))
+ (when block-list
+ (let*
+ (
+ (block-list-len (length block-list))
+ (bg-color (apply 'vector (color-values (face-attribute 'default
:background))))
+ (bg-color-tint (apply 'vector (color-values hl-block-color-tint)))
+ ;; Check dark background is light/dark.
+ (do-highlight (> 98304 (+ (aref bg-color 0) (aref bg-color 1) (aref
bg-color 2))))
+ ;; Iterator.
+ (i 0))
+ (pcase-let ((`(,beg-prev . ,end-prev) (pop block-list)))
+ (while block-list
+ (pcase-let ((`(,beg . ,end) (pop block-list)))
+ (let
+ (
+ (elem-overlay-beg (make-overlay beg beg-prev))
+ (elem-overlay-end (make-overlay end-prev end)))
+
+ (let
+ ( ;; Calculate the face with the tint color at this
highlight level.
+ (hl-face
+ (list
+ :background
+ (hl-block--color-values-as-string
+ (let ((i-tint (- block-list-len i)))
+ (if do-highlight
+ (hl-block--color-tint-add bg-color bg-color-tint
i-tint)
+ (hl-block--color-tint-sub bg-color bg-color-tint
i-tint))))
+ :extend t)))
+
+ (overlay-put elem-overlay-beg 'face hl-face)
+ (overlay-put elem-overlay-end 'face hl-face))
+
+ (push elem-overlay-beg hl-block-overlay)
+ (push elem-overlay-end hl-block-overlay)
+ (setq beg-prev beg)
+ (setq end-prev end))
+ (setq i (1+ i)))))))))
;; ---------------------------------------------------------------------------
- [nongnu] elpa/hl-block-mode bd54144b34 49/64: Cleanup: re-organize sections, (continued)
- [nongnu] elpa/hl-block-mode bd54144b34 49/64: Cleanup: re-organize sections, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 333490cf2d 45/64: Add hl-block-multi-line option, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 3c49f80ada 50/64: Cleanup: replace 'if' with 'cond', ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode f2ec1f167a 46/64: Correct type of hl-block-color-tint, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 2fb1cc165b 57/64: Simplify local bracket variable use, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 7e0452c768 64/64: Change URL to codeberg, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode a1c03970a0 59/64: Remove unnecessary requirement `seq`, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode d7e274c3f1 04/64: Update readme.rst, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode e7b5b014c9 10/64: Fix: localize hook & timer running when it shouldn't, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 28c9950a90 25/64: Fix for emacs 27, change in line highlighting, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode c6341f404e 44/64: Cleanup: store range data in cons cells instead of lists,
ELPA Syncer <=
- [nongnu] elpa/hl-block-mode e7ab79e713 36/64: Cleanup: add code-sections, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 7e0c6954f9 52/64: readme: document draw styles, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode d080364c64 58/64: Use a string for hl-block-bracket characters, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 3dd29cfbf2 63/64: Cleanup: use brief SPDX license, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 933cee11e3 02/64: Add readme, ELPA Syncer, 2022/07/07