[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/hl-block-mode 333490cf2d 45/64: Add hl-block-multi-line op
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/hl-block-mode 333490cf2d 45/64: Add hl-block-multi-line option |
Date: |
Thu, 7 Jul 2022 12:00:08 -0400 (EDT) |
branch: elpa/hl-block-mode
commit 333490cf2ddbf4dfca7ccafce49fa12a66e532eb
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Add hl-block-multi-line option
Useful to avoid over-nesting for languages that use S-expressions.
---
hl-block-mode.el | 41 ++++++++++++++++++++++++++++++++++-------
readme.rst | 2 ++
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/hl-block-mode.el b/hl-block-mode.el
index 00bd90594b..4d84398565 100644
--- a/hl-block-mode.el
+++ b/hl-block-mode.el
@@ -57,6 +57,13 @@ Set to nil to use all brackets."
:group 'hl-block-mode
:type 'float)
+(defcustom hl-block-multi-line nil
+ "Skip highlighting nested blocks on the same line.
+
+Useful for languages that use S-expressions to avoid overly nested
highlighting."
+ :group 'hl-block-mode
+ :type 'boolean)
+
(defcustom hl-block-mode-lighter ""
"Lighter for option `hl-block-mode'."
:group 'hl-block-mode
@@ -100,12 +107,20 @@ PT is typically the '(point)'."
(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 (cons (point-min) (point-max)) block-list))))
+(defun hl-block--syntax-skip-to-multi-line ()
+ "Move point to the first multi-line block.
+
+The point will only ever be moved backward."
+ (let
+ (
+ (line-min (line-beginning-position))
+ (line-max (line-end-position))
+ (beg (point))
+ (end (point)))
+ (while (and beg (>= beg line-min) end (<= end line-max))
+ (setq beg (ignore-errors (elt (syntax-ppss beg) 1)))
+ (when beg
+ (setq end (ignore-errors (scan-sexps beg 1)))))))
(defun hl-block--color-values-as-string (color)
"Build a color from COLOR.
@@ -134,7 +149,19 @@ Inverse of `color-values'."
(defun hl-block--overlay-refresh ()
"Update the overlays based on the cursor location."
(hl-block--overlay-clear)
- (let ((block-list (save-excursion (hl-block--find-all-ranges-or-fallback
(point)))))
+ (let
+ (
+ (block-list
+ (save-excursion
+ (when hl-block-multi-line
+ (hl-block--syntax-skip-to-multi-line))
+ (hl-block--find-all-ranges (point)))))
+
+ (when block-list
+ (if (cdr block-list)
+ (setq block-list (reverse block-list))
+ (cons (cons (point-min) (point-max)) block-list)))
+
(when block-list
(let*
(
diff --git a/readme.rst b/readme.rst
index 86ecc80dc7..ad56e8a6fa 100644
--- a/readme.rst
+++ b/readme.rst
@@ -20,6 +20,8 @@ Options
(float) delay in seconds until the drawing the block scope.
:hl-block-color-tint:
(color) color tint for each level.
+:hl-block-multi-line:
+ Skip highlighting blocks that begin and end on the same line.
TODO
====
- [nongnu] elpa/hl-block-mode 618c0a78ef 53/64: Correct bracket face, (continued)
- [nongnu] elpa/hl-block-mode 618c0a78ef 53/64: Correct bracket face, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode b2f1c058be 61/64: Cleanup: remove redundant group, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 0593a1a77d 62/64: Cleanup: docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 9c5ee70df6 17/64: Cleanup: checkdoc warnings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 83059c1050 18/64: Cleanup: use package prefix, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 047f9a972c 20/64: fix byte-compile nag, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 05a8c5119c 32/64: readme: link to melpa, tweaks to syntax highlighting, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 72840769e9 37/64: Cleanup: remove use of 'post-command-hook', ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 4a73d23ae2 43/64: Cleanup: over wide doc-string, ELPA Syncer, 2022/07/07
- [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 <=
- [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, 2022/07/07
- [nongnu] elpa/hl-block-mode e7ab79e713 36/64: Cleanup: add code-sections, ELPA Syncer, 2022/07/07