emacs-elpa-diffs
[Top][All Lists]
Advanced

[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:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]