[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/indent-bars e35c54e16d 038/431: blank-lines: improve ex
From: |
ELPA Syncer |
Subject: |
[elpa] externals/indent-bars e35c54e16d 038/431: blank-lines: improve extend and mark algorithm |
Date: |
Mon, 16 Sep 2024 12:59:11 -0400 (EDT) |
branch: externals/indent-bars
commit e35c54e16d72e80201a862437b93776b86cf52bc
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>
blank-lines: improve extend and mark algorithm
---
indent-bars.el | 83 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 45 insertions(+), 38 deletions(-)
diff --git a/indent-bars.el b/indent-bars.el
index a8d6b1167e..3eef878698 100644
--- a/indent-bars.el
+++ b/indent-bars.el
@@ -627,19 +627,19 @@ OBJ, otherwise in the buffer. OBJ is returned."
(defvar font-lock-beg) (defvar font-lock-end) ; Dynamic font-lock variables!
(defun indent-bars--extend-blank-line-regions ()
"Extend the region about to be font-locked to include stretches of blank
lines."
+ ;; (message "request to extend: %d->%d" font-lock-beg font-lock-end)
(let ((changed nil) (chars " \n"))
- (unless (eq font-lock-beg (point-min))
- (goto-char (1- font-lock-beg))
- (when (< (skip-chars-backward chars) 0)
- (unless (bolp) (beginning-of-line 2)) ; spaces at end don't count
- (if (< (point) font-lock-beg)
- (setq changed t font-lock-beg (point)))))
- (unless (eq font-lock-end (point-max))
- (goto-char (1+ font-lock-end))
- (when (> (skip-chars-forward chars) 0)
- ;; (unless (eolp) (beginning-of-line 0))
- (if (> (point) font-lock-end)
- (setq changed t font-lock-end (point)))))
+ (goto-char font-lock-beg)
+ (when (< (skip-chars-backward chars) 0)
+ (unless (bolp) (beginning-of-line 2)) ; spaces at end don't count
+ (when (< (point) font-lock-beg)
+ (setq changed t font-lock-beg (point))))
+ (goto-char font-lock-end)
+ (when (> (skip-chars-forward chars) 0)
+ (unless (bolp) (beginning-of-line 1))
+ (when (> (point) font-lock-end)
+ (setq changed t font-lock-end (point))))
+ ;; (if changed (message "expanded to %d->%d" font-lock-beg font-lock-end))
changed))
(defun indent-bars--handle-blank-lines ()
@@ -649,35 +649,42 @@ is non-nil. Uses surrounding line indentation to
determine
additional bars to display on each line, and uses a string
display property on the final newline if necessary to display the
needed bars. Blank lines at the beginning or end of the buffer
-are not indicated."
+are not indicated, even if otherwise they would be."
(let* ((beg (match-beginning 0))
(end (match-end 0))
ctxbars)
- (when (and (not (= end (point-max))) (not (= beg (point-min))))
- (goto-char beg)
- (forward-line -1)
- (when (> (setq ctxbars
- (1- (max (/ (current-indentation) indent-bars-spacing)
- (progn
- (goto-char end)
- (forward-line 1)
- (/ (current-indentation)
indent-bars-spacing)))))
- 0)
- (goto-char beg)
- (while (< (point) end)
- (let* ((bp (line-beginning-position))
- (ep (line-end-position))
- (len (- ep bp))
- (nbars (/ len indent-bars-spacing))
- nsp off s) ; "natural" bars
- (if (> nbars 0) (indent-bars--draw bp ep))
- (when (> ctxbars nbars) ;we need more bars than we have space!
- (unless (and (eq off (setq off (- (* (1+ nbars)
indent-bars-spacing) len)))
- (eq nsp (setq nsp (- (* ctxbars indent-bars-spacing)
len))))
- (setq s (concat (make-string nsp ?\s) "\n"))
- (indent-bars--draw off nsp (1+ nbars) s))
- (set-text-properties ep (1+ ep) `(display ,s)))
- (forward-line 1)))))))
+ (when (and (/= end (point-max)) (/= beg (point-min)))
+ (save-excursion
+ ;; (message "BL: %d[%d]->%d[%d]" beg (/ (current-indentation)
indent-bars-spacing)
+ ;; end
+ ;; (progn
+ ;; (goto-char end)
+ ;; (/ (current-indentation) indent-bars-spacing)))
+ (goto-char (1- beg)) ;beg always bol
+ (when (> (setq ctxbars
+ (1- (max (/ (current-indentation) indent-bars-spacing)
+ (progn
+ (goto-char (1+ end)) ; end always eol
+ (/ (current-indentation)
indent-bars-spacing)))))
+ 0)
+ (goto-char beg)
+ (while (<= (point) end)
+ (let* ((bp (line-beginning-position))
+ (ep (line-end-position))
+ (len (- ep bp))
+ (nbars (/ (max 0 (1- len)) indent-bars-spacing)))
+ ;; (message "len: %d nbars: %d ctxbars:%d" len nbars ctxbars)
+ ;; Draw "real" bars in existing blank
+ (if (> nbars 0) (indent-bars--draw (+ bp indent-bars-spacing) ep))
+ ;; Add fake bars via display
+ (when (> ctxbars nbars)
+ (let* ((off (- (* (1+ nbars) indent-bars-spacing) len))
+ (nsp (1+ (- (* ctxbars indent-bars-spacing) len)))
+ (s (concat (make-string nsp ?\s) "\n")))
+ (indent-bars--draw off nsp (1+ nbars) s)
+ (put-text-property ep (1+ ep) 'display s)))
+ (beginning-of-line 2)))))
+ nil)))
;;;; Current indentation highlight
(defvar-local indent-bars--current-depth 0)
- [elpa] externals/indent-bars 74c08d82fd 356/431: Update depth highlight: guard against deleted buffer, (continued)
- [elpa] externals/indent-bars 74c08d82fd 356/431: Update depth highlight: guard against deleted buffer, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars a1b942dde5 354/431: ts font-lock forms: set/clear as local variables, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 2216793de8 381/431: Merge branch 'main' into dev, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars b72fa098d7 415/431: ts: improve developer commentary, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 9f507d72fa 394/431: indent-bars--fontify: correct return structure, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 0aab084248 019/431: Capitalize in custom tags, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 37f3102422 022/431: specify width-frac for row-data, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 38265e96eb 018/431: remove current-depth timer, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars c228033146 024/431: current-depth-stipple support, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 54722d10a8 037/431: (re-) highlight current depth stipple on resize, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars e35c54e16d 038/431: blank-lines: improve extend and mark algorithm,
ELPA Syncer <=
- [elpa] externals/indent-bars 404251372e 039/431: set-current-depth-stipple: allow-other-keys (e.g. color), ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars da29b37efd 044/431: Add examples file, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars f1b0aedc40 078/431: Remove vestigial no-stipple-current-depth-char, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 3884953d20 090/431: Update README.md, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars accb7d00d2 071/431: error for indent-tabs-mode=t, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 09a3fd2492 080/431: Update README.md, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars a1718333ab 116/431: Fix indent-bars-treesit-support custom, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars f5b61dad71 075/431: Update README.md, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars 3bffb21456 111/431: Correct custom name for no-descend-string, ELPA Syncer, 2024/09/16
- [elpa] externals/indent-bars f9558953b2 083/431: Update README.md, ELPA Syncer, 2024/09/16