[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/indent-bars 6d98c4597f 004/431: re-organize and cleanup
From: |
ELPA Syncer |
Subject: |
[elpa] externals/indent-bars 6d98c4597f 004/431: re-organize and cleanup |
Date: |
Mon, 16 Sep 2024 12:59:07 -0400 (EDT) |
branch: externals/indent-bars
commit 6d98c4597f8726d99fabe28cd507ac9cf6cdb517
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>
re-organize and cleanup
---
indent-bars.el | 118 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 64 insertions(+), 54 deletions(-)
diff --git a/indent-bars.el b/indent-bars.el
index 629353f163..49bc6c8065 100644
--- a/indent-bars.el
+++ b/indent-bars.el
@@ -54,7 +54,7 @@
(defcustom indent-bars-width-frac 0.32
"The width of the indent bar as a fraction of the character width."
:type '(float :tag "Width fraction"
- :match (lambda (_ val) (and (<= val 1) (>= val 0)))
+ :match (lambda (_ val) (and val (<= val 1) (>= val 0)))
:type-error "Fraction must be between 0 and 1")
:group 'indent-bars)
@@ -62,7 +62,7 @@
"The offset of the bar from the left edge of the character.
A float, the fraction of the character width."
:type '(float :tag "Offset fraction"
- :match (lambda (_ val) (and (<= val 1) (>= val 0)))
+ :match (lambda (_ val) (and val (<= val 1) (>= val 0)))
:type-error "Fraction must be between 0 and 1")
:group 'indent-bars)
@@ -148,12 +148,12 @@ where:
:inline t
:options
((:background (boolean
- :tag "Use Face Background Color"
+ :tag "Use Face's Background Color"
:value t))
(:blend (float
:tag "Blend Factor"
:value 0.5
- :match (lambda (_ val) (and (<= val 1) (>= val 0)))
+ :match (lambda (_ val) (and val (<= val 1) (>= val
0)))
:type-error "Factor must be between 0 and 1")))))
:group 'indent-bars)
@@ -275,20 +275,13 @@ highlight color with the depth-based or main color; see
:type 'boolean
:group 'indent-bars)
-;;;; Variables
-(defvar indent-bars--current-depth-timer nil)
-(defvar indent-bars-orig-unfontify-region nil)
+;;;; Colors
(defvar indent-bars--main-color nil)
(defvar indent-bars--depth-palette nil)
(defvar indent-bars--current-depth-palette nil
"Palette for highlighting current depth.
May be nil, a color string or a vector of colors strings.")
-(defvar indent-bars--faces nil)
-(defvar-local indent-bars--current-depth nil)
-(defvar-local indent-bars--remap-face nil)
-(defvar-local indent-bars--remap-stipple nil)
-;;;; Colors
(defun indent-bars--blend-colors (c1 c2 fac)
"Return a fractional color between two colors C1 and C2.
Each is a string color. The fractional blend point is the
@@ -317,27 +310,28 @@ Uses `indent-bars-color'."
(defun indent-bars--depth-palette ()
"Calculate the palette of depth-based colors (a vector).
See `indent-bars-color-by-depth'."
- (cl-destructuring-bind (&key regexp background palette blend)
- indent-bars-color-by-depth
- (let ((colors (cond
- (regexp
- (indent-bars--depth-colors-from-regexp regexp background))
- (palette
- (delq nil
- (cl-loop for el in palette
- collect (cond
- ((and (consp el) (facep (car el)))
- (face-background (car el)))
- ((facep el)
- (face-foreground el))
- ((color-defined-p el) el)
- (t nil))))))))
- (vconcat
- (if blend
- (mapcar (lambda (c) (indent-bars--blend-colors
- c indent-bars--main-color blend))
- colors)
- colors)))))
+ (when indent-bars-color-by-depth
+ (cl-destructuring-bind (&key regexp background palette blend)
+ indent-bars-color-by-depth
+ (let ((bg (frame-parameter nil 'background-color))
+ (colors (cond
+ (regexp
+ (indent-bars--depth-colors-from-regexp regexp background))
+ (palette
+ (delq nil
+ (cl-loop for el in palette
+ collect (cond
+ ((and (consp el) (facep (car el)))
+ (face-background (car el)))
+ ((facep el)
+ (face-foreground el))
+ ((color-defined-p el) el)
+ (t nil))))))))
+ (vconcat
+ (if blend
+ (mapcar (lambda (c) (indent-bars--blend-colors c bg blend))
+ colors)
+ colors))))))
(defun indent-bars--current-depth-palette ()
"Calculate the color or color palette for highlighting the current depth bar.
@@ -345,7 +339,7 @@ Based on `indent-bars-color-by-depth' or, if not configured
for
depth-varying color, simply `indent-bars-color'. See
`indent-bars-highlight-current-indentation' for configuration."
(when indent-bars-highlight-current-indentation
- (cl-destructuring-bind (cur (&key background blend))
+ (cl-destructuring-bind (cur &key background blend)
indent-bars-highlight-current-indentation
(when-let ((color
(cond ((facep cur)
@@ -401,6 +395,9 @@ color, if setup (see
indent-bars--main-color)))
;;;; Faces
+(defvar indent-bars--faces nil)
+(defvar-local indent-bars--remap-face nil)
+
(defun indent-bars--create-stipple-face (w h)
"Create and set the `indent-bars-stipple' face for character size W x H."
(face-spec-set 'indent-bars-stipple
@@ -428,8 +425,12 @@ Saves the vector of face symbols in variable
(vconcat
(cl-loop for i from 1 to num
for face = (intern (format "indent-bars-%d" i))
- do (unless (or redefine (facep face))
- (face-spec-set face (indent-bars--calculate-face-spec
i)))
+ do
+ (if (facep face)
+ (when redefine
+ (face-spec-reset-face face)
+ (face-spec-set face (indent-bars--calculate-face-spec
i)))
+ (face-spec-set face (indent-bars--calculate-face-spec i)))
collect face))))
(defsubst indent-bars--face (depth)
@@ -439,6 +440,7 @@ Saves the vector of face symbols in variable
(aref indent-bars--faces (1- depth)))
;;;; Display
+(defvar indent-bars-orig-unfontify-region nil)
(defun indent-bars--unfontify (beg end)
"Unfontify region between BEG and END.
Removes the display properties in addition to the normal managed
@@ -532,6 +534,13 @@ OBJ, otherwise in the buffer."
do (put-text-property pos (1+ pos)
'font-lock-face (indent-bars--face barnum)
obj)))
+(defun indent-bars--display ()
+ "Display indentation bars based on line contents."
+ (save-excursion
+ (goto-char (match-beginning 1))
+ (indent-bars--draw (+ (line-beginning-position) indent-bars-spacing)
(match-end 1)))
+ nil)
+
;;;; Font Lock
(defvar-local indent-bars--font-lock-keywords nil)
@@ -591,17 +600,11 @@ are not indicated."
(set-text-properties ep (1+ ep) `(display ,s)))
(forward-line 1)))))))
-(defun indent-bars--display ()
- "Display indentation bars based on line contents."
- (save-excursion
- (let* ((beg (goto-char (match-beginning 0)))
- (end (match-end 0)))
- (indent-bars--draw beg end)))
- nil)
-
;;;; Text scaling
+(defvar-local indent-bars--remap-stipple nil)
(defun indent-bars--resize-stipple ()
"Recreate stipple with font size change."
+ (message "GOT: %S (%d,%d)" (current-buffer) (window-font-width)
(window-font-height))
(if indent-bars--remap-stipple
(face-remap-remove-relative indent-bars--remap-stipple))
(when text-scale-mode
@@ -613,6 +616,8 @@ are not indicated."
;;;; Current indentation highlight
+(defvar-local indent-bars--current-depth nil)
+
(defun indent-bars--highlight-current-depth ()
"Refresh current indentation depth highlight.
Works by remapping the appropriate indent-bars-N face."
@@ -625,9 +630,10 @@ Works by remapping the appropriate indent-bars-N face."
(if-let ((face (indent-bars--face depth))
(hl-col (indent-bars--get-color depth 'highlight)))
- (setq indent-bars--remap-face
- (face-remap-add-relative face :foreground hl-col))))))
+ (setq indent-bars--remap-face
+ (face-remap-add-relative face :foreground hl-col))))))
+(defvar indent-bars--current-depth-timer nil)
(defun indent-bars--post-command ()
"Schedule current indentation depth highlighting."
(when indent-bars--current-depth-timer
@@ -686,12 +692,10 @@ Adapted from `highlight-indentation-mode'."
(setq indent-bars--font-lock-blank-line-keywords
`((,re (0 (indent-bars--handle-blank-lines))))))))
-(defun indent-bars-setup (&optional force)
- "Setup all face, color, bar size, and indentation info for the current
buffer.
-If FORCE is non-nil, update all parameters even if already set."
+(defun indent-bars-setup ()
+ "Setup all face, color, bar size, and indentation info for the current
buffer."
;; Spacing
- (unless (or force (alist-get 'indent-bars-spacing (buffer-local-variables)))
- (setq indent-bars-spacing (indent-bars--guess-spacing)))
+ (setq indent-bars-spacing (indent-bars--guess-spacing))
;; Colors
(setq indent-bars--main-color (indent-bars--main-color)
@@ -700,13 +704,14 @@ If FORCE is non-nil, update all parameters even if
already set."
;; Faces
(indent-bars--create-stipple-face (frame-char-width) (frame-char-height))
- (indent-bars--create-faces 9 force) ; extends as needed
+ (indent-bars--create-faces 9 'reset) ; extends as needed
;; Font-lock
- (indent-bars--setup-font-lock)
- (font-lock-add-keywords nil indent-bars--font-lock-keywords t)
(setq indent-bars-orig-unfontify-region font-lock-unfontify-region-function)
(setq-local font-lock-unfontify-region-function #'indent-bars--unfontify)
+ (indent-bars--setup-font-lock)
+ (font-lock-add-keywords nil indent-bars--font-lock-keywords t)
+
;; Resize
(add-hook 'text-scale-mode-hook #'indent-bars--resize-stipple nil t)
@@ -729,6 +734,11 @@ If FORCE is non-nil, update all parameters even if already
set."
(font-lock-remove-keywords nil indent-bars--font-lock-blank-line-keywords)
(font-lock-flush)
(setq font-lock-unfontify-region-function indent-bars-orig-unfontify-region)
+ (setq indent-bars--current-depth-palette nil
+ indent-bars--depth-palette nil
+ indent-bars--faces nil
+ indent-bars--remap-face nil
+ indent-bars--stipple nil)
(remove-hook 'text-scale-mode-hook #'indent-bars--resize-stipple t)
(remove-hook 'post-command-hook #'indent-bars--post-command t)
(remove-hook 'font-lock-extend-region-functions
- [elpa] externals/indent-bars 54d15a437d 122/431: customize and var name tweaks, (continued)
- [elpa] externals/indent-bars 54d15a437d 122/431: customize and var name tweaks, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 77aec85ad0 124/431: Merge branch 'treesit' into dev, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars a7bfe31d59 131/431: display-line: offset start if no tabs, invent with correct bar count, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars f1404b31fe 151/431: Added what's new, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 3a9ffd9176 142/431: Add cobol-mode support, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 327ace5493 162/431: ts-node-query: add FIRST-SPANNING flag to insist top node encloses, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 858de2c124 184/431: Update README.md, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 8a4ea0ab83 187/431: Update README.md, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 3cebc7d7fb 177/431: Resize iamge, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars beaaf4d359 003/431: Improve docstrings, comments, custom messages, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 6d98c4597f 004/431: re-organize and cleanup,
ELPA Syncer <=
- [elpa] externals/indent-bars 6f054692ef 008/431: Generalize to stipple "pad" and "rot", ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 0769d70591 010/431: add window-state-change hooks for recalculating stipple, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 471b0920b0 012/431: improve comments, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 4e31151a0d 015/431: improve comments, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars f8d5e25527 030/431: bug fix for long patterns, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars eab376d061 041/431: Allow background color on current depth highlight, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 253cf0d9bc 042/431: Improve spacing-override customize, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 71472e3cce 040/431: sub-headings, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars f608dce7a6 046/431: Convert examples from org to md, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars b4995ad103 058/431: README: add hl-indent-scope, ELPA Syncer, 2024/09/16