[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beardbolt f846655a35 250/323: Rework rmsbolt-rainbowize
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beardbolt f846655a35 250/323: Rework rmsbolt-rainbowize to reuse more code |
Date: |
Thu, 9 Mar 2023 10:58:35 -0500 (EST) |
branch: externals/beardbolt
commit f846655a3514a775f13fbb5052bb94bc3cdd3aff
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Rework rmsbolt-rainbowize to reuse more code
Output regions are computed early since they're used by both rainbows
and normal highlighting. This could still use some more cleanup.
* rmsbolt.el (rmsbolt--rainbowize): Rework.
(rmsbolt--handle-finish-compile): Call rmsbolt--rainbowize.
Complexifly.
(rmsbolt-update-overlays): Simplify.
---
rmsbolt.el | 125 +++++++++++++++++++++++++++++--------------------------------
1 file changed, 60 insertions(+), 65 deletions(-)
diff --git a/rmsbolt.el b/rmsbolt.el
index f9376ab12e..d263ad5272 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -1345,42 +1345,41 @@ Argument ASM-LINES input lines."
(push line result)))
(nreverse result)))
-(defun rmsbolt--rainbowize (idx total src-buffer src-line asm-regions)
+(defun rmsbolt--rainbowize (line-mappings src-buffer)
(let* ((background-hsl
(apply #'color-rgb-to-hsl (color-name-to-rgb (face-background
'default))))
- (color (apply #'color-rgb-to-hex
- (color-hsl-to-rgb (/ (* 1.0 idx) total)
- (cl-second background-hsl)
- (cl-third background-hsl))))
all-ovs
- _src-ov)
- (save-excursion
- (cl-loop
- for (beg . end) in (cl-sort asm-regions #'< :key #'car)
- for asm-ov =
- (progn
- (goto-char (point-min)) ;; TODO: could optimize
- (make-overlay (progn (forward-line (1- beg))
- (line-beginning-position))
- (progn (forward-line (- end beg))
- (line-end-position))))
- do
- (overlay-put asm-ov 'priority 0)
- (push asm-ov all-ovs)
- (overlay-put asm-ov 'face `(:background ,color))))
- (when asm-regions
- (with-current-buffer src-buffer
- (save-excursion
- (goto-char (point-min))
- (forward-line (1- src-line))
- (let ((ov (make-overlay (line-beginning-position)
- (1+ (line-end-position)))))
- (push ov all-ovs)
- (overlay-put ov 'face `(:background ,color))
- (overlay-put ov 'priority 0)))
- (setq-local rmsbolt--rainbow-overlays
- (append all-ovs
- rmsbolt--rainbow-overlays))))))
+ (idx -1)
+ (total (hash-table-count line-mappings)))
+ (maphash
+ (lambda (src-line asm-regions)
+ (when (not (zerop src-line))
+ (cl-loop
+ with color =
+ (apply #'color-rgb-to-hex
+ (color-hsl-to-rgb (/ (* 1.0 (cl-incf idx)) total)
+ (cl-second background-hsl)
+ (cl-third background-hsl)))
+ for (beg . end) in (cl-getf asm-regions :positions)
+ for asm-ov = (make-overlay beg end)
+ do
+ (overlay-put asm-ov 'priority 0)
+ (push asm-ov all-ovs)
+ (overlay-put asm-ov 'face `(:background ,color))
+ finally
+ (with-current-buffer src-buffer
+ (save-excursion
+ (goto-char (point-min))
+ (forward-line (1- src-line))
+ (let ((ov (make-overlay (line-beginning-position)
+ (1+ (line-end-position)))))
+ (push ov all-ovs)
+ (overlay-put ov 'face `(:background ,color))
+ (overlay-put ov 'priority 0)))))))
+ line-mappings)
+ (with-current-buffer src-buffer
+ (mapc #'delete-overlay rmsbolt--rainbow-overlays)
+ (setq-local rmsbolt--rainbow-overlays all-ovs))))
(defun rmsbolt--rainbowize-cleanup ()
(mapc #'delete-overlay rmsbolt--rainbow-overlays)
@@ -1438,7 +1437,7 @@ Argument STOPPED The compilation was stopped to start
another compilation."
(in-match
;; We are in a match that has just expired
(push (cons start-match (1- linum))
- (gethash in-match ht))
+ (cl-getf (gethash in-match ht) :lines))
(setq in-match nil
start-match nil)
(go run-conditional))
@@ -1446,10 +1445,8 @@ Argument STOPPED The compilation was stopped to start
another compilation."
(setq in-match property
start-match linum))))))
(cl-incf linum))
-
(with-current-buffer src-buffer
(setq rmsbolt-line-mapping ht))
-
;; Replace buffer contents but save point and scroll
(let* ((window (get-buffer-window output-buffer))
(old-point (window-point window))
@@ -1461,15 +1458,24 @@ Argument STOPPED The compilation was stopped to start
another compilation."
(set-window-point window old-point)))
(asm-mode)
(rmsbolt-mode 1)
- (let ((i 0))
- (maphash (lambda (k v)
- (rmsbolt--rainbowize
- (prog1 i (cl-incf i))
- (hash-table-count ht)
- src-buffer
- k
- v))
- ht))
+ ;; Enrich rmsbolt-line-mapping with actual position
information
+ (maphash (lambda (_k asm-regions)
+ (save-excursion
+ (plist-put
+ asm-regions
+ :positions
+ (cl-loop
+ for (begl . endl) in (cl-getf asm-regions
:lines)
+ collect (cons (progn
+ (goto-char (point-min))
+ (forward-line (1- begl))
+ (line-beginning-position))
+ (progn
+ (forward-line (- endl begl))
+ (line-end-position)))))))
+ ht)
+
+ (rmsbolt--rainbowize ht src-buffer)
(setq rmsbolt-src-buffer src-buffer)
(display-buffer (current-buffer))
(run-at-time 0 nil #'rmsbolt-update-overlays))))
@@ -1759,7 +1765,9 @@ and return it."
current-line
(get-text-property (point) 'rmsbolt-src-line)))
(line-mappings (buffer-local-value 'rmsbolt-line-mapping
src-buffer))
- (asm-regions (gethash src-current-line line-mappings))
+ (asm-region-plist (gethash src-current-line line-mappings))
+ (asm-region-lines (plist-get asm-region-plist :lines))
+ (asm-region-positions (plist-get asm-region-plist :positions))
;; TODO also consider asm
(src-pts
(with-current-buffer src-buffer
@@ -1778,21 +1786,9 @@ and return it."
(push (rmsbolt--setup-overlay (cl-first src-pts) (cl-second src-pts)
src-buffer)
rmsbolt-overlays)
(with-current-buffer output-buffer
- (let ((saved-pt (point)))
- (save-excursion
- (cl-loop for (start . end) in asm-regions
- do (let ((start-pt (progn (rmsbolt--goto-line start)
- (c-point 'bol)))
- (end-pt (progn (rmsbolt--goto-line end)
- (c-point 'bonl))))
- (when (and (not line-visible)
- (not scroll-src-buffer-p))
- (setq line-visible (or (rmsbolt--point-visible
start-pt)
- (rmsbolt--point-visible
end-pt)
- (and (> saved-pt
start-pt)
- (< saved-pt
end-pt)))))
- (push (rmsbolt--setup-overlay start-pt end-pt
output-buffer)
- rmsbolt-overlays)))))
+ (cl-loop for (start . end) in asm-region-positions
+ do (push (rmsbolt--setup-overlay start end output-buffer)
+ rmsbolt-overlays))
(when (or (not line-visible) force)
;; Scroll buffer to first line
(when-let ((scroll-buffer (if scroll-src-buffer-p
@@ -1801,12 +1797,11 @@ and return it."
(window (get-buffer-window scroll-buffer))
(line-scroll (if scroll-src-buffer-p
src-current-line
- (progn
- (car-safe
+ (car
;; If forcing, pick the last region
instead
(if force
- (car-safe (last asm-regions))
- (cl-first asm-regions)))))))
+ (car (last asm-region-lines))
+ (cl-first asm-region-lines))))))
(with-selected-window window
(rmsbolt--goto-line line-scroll)
;; If we scrolled, recenter
- [elpa] externals/beardbolt 7c735240b0 192/323: Clean up buffer overlays explicitly on output buffer kill, (continued)
- [elpa] externals/beardbolt 7c735240b0 192/323: Clean up buffer overlays explicitly on output buffer kill, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 1267509ab4 220/323: Move `rmsbolt-with-display-buffer-no-window`, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 8544df3e9d 222/323: Use `rmsbolt--cleanup-overlays`, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 42b0ab4239 225/323: Make it clear that we're operating on a list of asm regions, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 4f4a7f85ac 223/323: Simplify visibility check logic, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 3a1e068bb8 228/323: Don't update overlays if the src buffer is no longer current, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt b56d3b6cdb 245/323: Merge branch 'improve-starters' into 'master', ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 16f887917b 252/323: Improve rainbow color selection algorithm, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 9bc7e8aeb8 236/323: Remove `rmsbolt--post-command-hook` when mode is deactivated, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 660739681c 254/323: Rename every rms* file to beard*, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt f846655a35 250/323: Rework rmsbolt-rainbowize to reuse more code,
ELPA Syncer <=
- [elpa] externals/beardbolt 78eed53af1 260/323: Don't hang a "[Compiling]" forever in the mode-line, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt b71d1bd763 265/323: * beardbolt.el (bb-compile): Fix handling of bb-asm-format., ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 4cbe58f834 279/323: Add -g1 instead of -g to speed it up massively, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 2542f24813 285/323: Tweak, rework, speed up main algorithm again, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 85bc714336 295/323: Simplify source file tracking, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt c5086ea624 294/323: bb--output-mode now a major mode, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 298a5fe6a2 296/323: Fix starter/beardbolt.cpp, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 067096f3b9 299/323: Friendlier beardbolt--output-mode, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 0ae21a302a 302/323: Simplify window management in preparation of beardbolt-execute-program, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 842b2159da 305/323: More simplification, ELPA Syncer, 2023/03/09