[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/hl-block-mode f763fff94e 09/64: Follow lisp and emacs-lisp
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/hl-block-mode f763fff94e 09/64: Follow lisp and emacs-lisp conventions |
Date: |
Thu, 7 Jul 2022 12:00:01 -0400 (EDT) |
branch: elpa/hl-block-mode
commit f763fff94e8b7db58053b2fa8edf870159a8cc1e
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Campbell Barton <ideasman42@gmail.com>
Follow lisp and emacs-lisp conventions
* No not put closing parenthesis on separate lines.
* Fix indentation.
* Separate top-level forms using an empty line.
* Use `nil' as the empty list.
* Do not use `progn' around the ELSE part of `if'.
Also
* Shorten long lines.
---
hl-block-mode.el | 167 +++++++++++++++++++++++--------------------------------
1 file changed, 70 insertions(+), 97 deletions(-)
diff --git a/hl-block-mode.el b/hl-block-mode.el
index 507942a84a..685d833ff4 100644
--- a/hl-block-mode.el
+++ b/hl-block-mode.el
@@ -40,6 +40,7 @@
"Idle time before highlighting."
:group 'hl-block-mode
:type 'float)
+
(defcustom hl-block-color-tint "#040404"
"Color to add/subtract from the background each scope step."
:group 'hl-block-mode
@@ -48,141 +49,113 @@
(defun hl-block--syntax-prev-curly-brace (pt)
"A versiong of 'syntax-ppss' to match curly braces.
PT is typically the '(point)'."
- (let
- ((start (ignore-errors (elt (syntax-ppss pt) 1)))
- )
+ (let ((start (ignore-errors (elt (syntax-ppss pt) 1))))
(when start
(if (char-equal ?{ (char-after start))
- start
- (hl-block--syntax-prev-curly-brace (1- start))
- )
- )
- )
- )
+ start
+ (hl-block--syntax-prev-curly-brace (1- start))))))
+
(defun hl-block--find-all-ranges (pt)
"Return a list of ranges starting from PT, outer-most to inner-most."
- (let*
- (
- (start
- ;; (ignore-errors (elt (syntax-ppss pt) 1))) ;; works for lisp
- (hl-block--syntax-prev-curly-brace pt))
- (end
- (when start (or (ignore-errors (scan-sexps start 1)) pt)))
- (range_prev
- (when start (hl-block--find-all-ranges start)))
- )
+ (let* ((start
+ ;; (ignore-errors (elt (syntax-ppss pt) 1))) ;; works for lisp
+ (hl-block--syntax-prev-curly-brace pt))
+ (end
+ (when start (or (ignore-errors (scan-sexps start 1)) pt)))
+ (range_prev
+ (when start (hl-block--find-all-ranges start))))
(when start
(if range_prev
- (cons (list start end) range_prev)
- (list (list start end))
- )
- )
- )
- )
+ (cons (list start end) range_prev)
+ (list (list start end))))))
+
(defun hl-block--color-values-as-string (r g b)
"Build a color from R G B.
Inverse of `color-values'."
- (format
- "#%02x%02x%02x"
- (ash r -8)
- (ash g -8)
- (ash b -8)))
+ (format "#%02x%02x%02x"
+ (ash r -8)
+ (ash g -8)
+ (ash b -8)))
+
+(defvar hl-block-overlay nil)
-(defvar hl-block-overlay (list))
(defun hl-block--overlay-clear ()
"Clear all overlays."
(mapc 'delete-overlay hl-block-overlay)
- (setq hl-block-overlay (list))
- )
+ (setq hl-block-overlay nil))
(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 (point)))))
+ (let ((block-list (save-excursion (hl-block--find-all-ranges (point)))))
(when block-list
- (let*
- (
- (block-list
- (if (cdr block-list)
- (reverse block-list)
- (cons (list (point-min) (point-max)) block-list)
- )
- )
- (start-prev (nth 0 (nth 0 block-list)))
- (end-prev (nth 1 (nth 0 block-list)))
- (block-list-len (length block-list))
- (bg-color (color-values (face-attribute 'default :background)))
- (bg-color-tint (color-values hl-block-color-tint))
- ;; Check dark background is light/dark.
- (do-highlight (> 98304 (apply '+ bg-color)))
- )
+ (let* ((block-list
+ (if (cdr block-list)
+ (reverse block-list)
+ (cons (list (point-min) (point-max)) block-list)))
+ (start-prev (nth 0 (nth 0 block-list)))
+ (end-prev (nth 1 (nth 0 block-list)))
+ (block-list-len (length block-list))
+ (bg-color (color-values (face-attribute 'default :background)))
+ (bg-color-tint (color-values hl-block-color-tint))
+ ;; Check dark background is light/dark.
+ (do-highlight (> 98304 (apply '+ bg-color))))
(seq-map-indexed
- (lambda (elem_range i)
- (let*
- (
- (i-tint (- block-list-len i))
- (start (nth 0 elem_range))
- (end (nth 1 elem_range))
- (elem-overlay-start (make-overlay start start-prev))
- (elem-overlay-end (make-overlay end-prev end))
- (bg-color-blend
- (apply 'hl-block--color-values-as-string
- (if do-highlight
- (cl-mapcar '(lambda (a b) (+ a (* i-tint b))) bg-color
bg-color-tint)
- (cl-mapcar '(lambda (a b) (- a (* i-tint b))) bg-color
bg-color-tint)
- )
- )
- )
- )
- (overlay-put elem-overlay-start 'face `(:background
,bg-color-blend))
- (overlay-put elem-overlay-end 'face `(:background
,bg-color-blend))
- (add-to-list 'hl-block-overlay elem-overlay-start)
- (add-to-list 'hl-block-overlay elem-overlay-end)
- (setq start-prev start)
- (setq end-prev end)
- )
- )
- (cdr block-list)
- )
- )
- )
- )
- )
+ (lambda (elem_range i)
+ (let* ((i-tint (- block-list-len i))
+ (start (nth 0 elem_range))
+ (end (nth 1 elem_range))
+ (elem-overlay-start (make-overlay start start-prev))
+ (elem-overlay-end (make-overlay end-prev end))
+ (bg-color-blend
+ (apply 'hl-block--color-values-as-string
+ (if do-highlight
+ (cl-mapcar '(lambda (a b) (+ a (* i-tint b)))
+ bg-color bg-color-tint)
+ (cl-mapcar '(lambda (a b) (- a (* i-tint b)))
+ bg-color bg-color-tint)))))
+ (overlay-put elem-overlay-start
+ 'face `(:background ,bg-color-blend))
+ (overlay-put elem-overlay-end
+ 'face `(:background ,bg-color-blend))
+ (add-to-list 'hl-block-overlay elem-overlay-start)
+ (add-to-list 'hl-block-overlay elem-overlay-end)
+ (setq start-prev start)
+ (setq end-prev end)))
+ (cdr block-list))))))
+
;; Timer
(defvar hl-block--delay-timer nil)
+
(defun hl-block--overlay-delay ()
"Recalculate overlays using a delay (to avoid slow-down)."
(when (timerp hl-block--delay-timer)
(cancel-timer hl-block--delay-timer))
(setq hl-block--delay-timer
- (run-with-idle-timer hl-block-delay t
- 'hl-block--overlay-refresh)
- )
- )
+ (run-with-idle-timer hl-block-delay t
+ 'hl-block--overlay-refresh)))
+
(defun hl-block-mode-enable ()
"Turn on 'hl-block-mode' for the current buffer."
- (add-hook 'post-command-hook 'hl-block--overlay-delay)
- )
+ (add-hook 'post-command-hook 'hl-block--overlay-delay))
+
(defun hl-block-mode-disable ()
"Turn off 'hl-block-mode' for the current buffer."
(hl-block--overlay-clear)
(when (timerp hl-block--delay-timer)
(cancel-timer hl-block--delay-timer))
- (remove-hook 'post-command-hook 'hl-block--overlay-delay)
- )
+ (remove-hook 'post-command-hook 'hl-block--overlay-delay))
;;;###autoload
(define-minor-mode hl-block-mode
"Highlight block under the cursor."
:lighter ""
- (if hl-block-mode
- (progn
- (jit-lock-unregister 'hl-block-mode-enable)
- (hl-block-mode-enable))
- (progn
- (jit-lock-unregister 'hl-block-mode-enable)
- (hl-block-mode-disable))))
+ (cond (hl-block-mode
+ (jit-lock-unregister 'hl-block-mode-enable)
+ (hl-block-mode-enable))
+ (t
+ (jit-lock-unregister 'hl-block-mode-enable)
+ (hl-block-mode-disable))))
(provide 'hl-block-mode)
;; Local Variables:
- [nongnu] elpa/hl-block-mode 54ab1d6aba 60/64: Fix bracket display highlighting a character next to (point), (continued)
- [nongnu] elpa/hl-block-mode 54ab1d6aba 60/64: Fix bracket display highlighting a character next to (point), ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 395c7315b7 11/64: Add option to match different bracket types, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode ed4a599ead 38/64: Cleanup: quiet checkdoc & package lint warnings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 497b0ac639 48/64: Cleanup: re-order custom settings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 859d3cac49 51/64: readme: update example, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode da2870d1d7 24/64: Update readme.rst, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 82f42045c1 31/64: Enable lexical binding, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode dc5b0153bb 35/64: Cleanup: byte-code compilation warnings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 4e28df960d 40/64: Remove local variables when disabling the mode, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode d47c372b06 03/64: Update readme.rst, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode f763fff94e 09/64: Follow lisp and emacs-lisp conventions,
ELPA Syncer <=
- [nongnu] elpa/hl-block-mode b98c83d8cb 14/64: Add global-hl-block-mode, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 326e026b66 13/64: Use character literal for '{', ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 9f39593c4f 19/64: make hl-bock-mode lighter customizable, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 00914d2938 22/64: Reduce default delay to 200ms, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 74b5a89360 23/64: FIx typo, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 0f1abe46d5 27/64: Apply auto-format, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 59cdbd4d27 39/64: Use "push" instead of add-to-list, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 0ea43d3202 34/64: Cleanup: disable auto-load for internal function, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 27e3ab4195 42/64: Cleanup: minor naming changes, ELPA Syncer, 2022/07/07
- [nongnu] elpa/hl-block-mode 59458a4b2b 54/64: Initialize brackets from the syntax table, ELPA Syncer, 2022/07/07