[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/activities 6d9b69485a 32/50: inline annotation-function
From: |
ELPA Syncer |
Subject: |
[elpa] externals/activities 6d9b69485a 32/50: inline annotation-function and eliminate vc-annotate |
Date: |
Wed, 25 Dec 2024 03:57:20 -0500 (EST) |
branch: externals/activities
commit 6d9b69485a88d8576bb8d92c5282a460e122be79
Author: J.D. Smith <jdtsmith@gmail.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>
inline annotation-function and eliminate vc-annotate
Introduces new custom variable `activities-annotation-colors'.
---
activities.el | 127 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 66 insertions(+), 61 deletions(-)
diff --git a/activities.el b/activities.el
index f2e4d08074..35d2b6d6e8 100644
--- a/activities.el
+++ b/activities.el
@@ -66,7 +66,7 @@
(require 'map)
(require 'persist)
(require 'subr-x)
-(require 'vc-annotate)
+(require 'color)
;;;; Types
@@ -342,6 +342,16 @@ and then by age since modification."
:type '(choice (const :tag "No sorting" nil)
(function :tag "A specific function")))
+(defcustom activities-annotation-colors '("blue" "red" 0.65)
+ "Colors to use for annotating activity age.
+A list (OLD-COLOR NEW-COLOR BLEND-FRAC). These are used during
+activity selection, with the activity color chosen between
+OLD-COLOR and NEW-COLOR, based on the activity's age. This color
+is blended into the default foreground with a fraction
+BLEND-FRAC, and used to display the activity age."
+ :type '(list (color :tag "Old Color") (color :tag "New Color")
+ (float :tag "Blend Fraction")))
+
;;;; Commands
;;;###autoload
@@ -893,53 +903,6 @@ Adapted from `magit--age'."
for etc = (activities-activity-state-etc state)
maximize (float-time (time-since (map-elt etc 'time))))))
-(defun activities--annotate (max-age oldest-possible)
- "Return an activity annotation function.
-MAX-AGE is the maximum age of any activity in seconds.
-OLDEST-POSSIBLE is the oldest age in the `vc-annotate-color-map'."
- (lambda (name)
- (when-let ((activity (map-elt activities-activities name)))
- (let (data)
- (dolist (type '(last default))
- (when-let ((state (cl-struct-slot-value 'activities-activity type
activity)))
- (let* ((time (map-elt (activities-activity-state-etc state) 'time))
- (buffers-and-files (activities--buffers-and-files state)))
- (setf (alist-get type data)
- (list (and time (float-time (time-since time)))
buffers-and-files)))))
- (pcase-let* ((`(,default-age ,default-buffers-and-files) (map-elt data
'default))
- (`(,last-age ,last-buffers-and-files) (map-elt data
'last)) ;possibly nil
- (age (if last-age (min last-age default-age) default-age))
- (buffers-and-files (if last-age
- last-buffers-and-files
- default-buffers-and-files))
- (num-buffers (length buffers-and-files))
- (num-files (seq-count #'stringp (mapcar #'cdr
buffers-and-files)))
- (dirtyp (when last-buffers-and-files
- (activities--buffers-and-files-differ-p
- last-buffers-and-files
- default-buffers-and-files)))
- (annotation (format "%s%s buf%s %s file%s "
- (if (activities-activity-active-p
activity)
- (propertize "@" 'face 'bold) " ")
- (propertize (format "%2d" num-buffers)
'face 'success)
- (if (= num-buffers 1) " " "s")
- (propertize (format "%2d" num-files)
'face 'warning)
- (if (= num-files 1) " " "s")))
- (age-color (or (cdr (vc-annotate-compcar
- (* (/ age max-age) oldest-possible)
- vc-annotate-color-map))
- vc-annotate-very-old-color))
- (age-annotation (propertize
- (format "%15s" (apply #'format "[%d %s]"
- (activities--age
age)))
- 'face `(:foreground ,age-color
- :background
,vc-annotate-background)))
- (dirty-annotation (if dirtyp (propertize "*" 'face 'bold)
" ")))
- (concat (propertize " " 'display
- `(space :align-to (- right ,(+ 1 (length
annotation)
- (length
age-annotation)))))
- annotation age-annotation dirty-annotation))))))
-
(defun activities-sort-by-active-age (names)
"Return the list activity NAMES sorted active first, then by age."
(sort names
@@ -964,19 +927,61 @@ OLDEST-POSSIBLE is the oldest age in the
`vc-annotate-color-map'."
"Return an activity read with completion from ACTIVITIES.
PROMPT is passed to `completing-read' by way of `format-prompt',
which see, with DEFAULT."
- (let* ((names (activities-names activities))
- (table (lambda (str pred action)
- (if (eq action 'metadata)
- `(metadata
- ( annotation-function .
- ,(activities--annotate (activities--oldest-age
activities)
- (vc-annotate-oldest-in-map
- vc-annotate-color-map)))
- ,@(when activities-sort-function
- `(,(cons 'display-sort-function
activities-sort-function))))
- (complete-with-action action names str pred))))
- (prompt (format-prompt prompt default))
- (name (completing-read prompt table nil t nil
'activities-completing-read-history default)))
+ (pcase-let*
+ ((names (activities-names activities))
+ (max-age (activities--oldest-age activities))
+ (`(,old-col ,new-col ,blend-frac) activities-annotation-colors)
+ (annotation-function
+ (lambda (name)
+ (when-let ((activity (map-elt activities-activities name)))
+ (let (activity-data)
+ (dolist (type '(last default))
+ (when-let ((state (cl-struct-slot-value 'activities-activity
type activity)))
+ (let* ((time (map-elt (activities-activity-state-etc state)
'time))
+ (buffers-and-files (activities--buffers-and-files
state)))
+ (setf (alist-get type activity-data)
+ (list (and time (float-time (time-since time)))
buffers-and-files)))))
+ (pcase-let*
+ ((`(,default-age ,default-buffers-and-files) (map-elt
activity-data 'default))
+ (`(,last-age ,last-buffers-and-files) (map-elt activity-data
'last)) ;possibly nil
+ (age (if last-age (min last-age default-age) default-age))
+ (buffers-and-files (if last-age last-buffers-and-files
default-buffers-and-files))
+ (num-buffers (length buffers-and-files))
+ (num-files (seq-count #'stringp (mapcar #'cdr
buffers-and-files)))
+ (dirtyp (when last-buffers-and-files
+ (activities--buffers-and-files-differ-p
+ last-buffers-and-files
+ default-buffers-and-files)))
+ (annotation (format "%s%s buf%s %s file%s "
+ (if (activities-activity-active-p
activity)
+ (propertize "@" 'face 'bold) " ")
+ (propertize (format "%2d" num-buffers)
'face 'success)
+ (if (= num-buffers 1) " " "s")
+ (propertize (format "%2d" num-files)
'face 'warning)
+ (if (= num-files 1) " " "s")))
+ (age-color (apply #'color-rgb-to-hex
+ (cl-loop for co in (color-name-to-rgb
old-col)
+ for cn in (color-name-to-rgb
new-col)
+ for cd in (color-name-to-rgb
(face-foreground 'default))
+ collect (+ (* blend-frac (+ cn
(* (- co cn) (/ age max-age))))
+ (* (- 1. blend-frac)
cd)))))
+ (age-annotation (propertize
+ (format "%15s" (apply #'format "[%d %s]"
+ (activities--age
age)))
+ 'face `(:foreground ,age-color :weight
bold)))
+ (dirty-annotation (if dirtyp (propertize "*" 'face 'bold) "
")))
+ (concat (propertize " " 'display
+ `(space :align-to (- right ,(+ 1 (length
annotation)
+ (length
age-annotation)))))
+ annotation age-annotation dirty-annotation))))))
+ (table (lambda (str pred action)
+ (if (eq action 'metadata)
+ `(metadata (annotation-function . ,annotation-function)
+ ,@(when activities-sort-function
+ `(,(cons 'display-sort-function
activities-sort-function))))
+ (complete-with-action action names str pred))))
+ (prompt (format-prompt prompt default))
+ (name (completing-read prompt table nil t nil
'activities-completing-read-history default)))
(or (map-elt activities-activities name)
(make-activities-activity :name name))))
- [elpa] externals/activities c2c24484bf 15/50: annotate: make variable names more explicit, (continued)
- [elpa] externals/activities c2c24484bf 15/50: annotate: make variable names more explicit, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 542f4e4a65 16/50: annotate: compare file truenames and buffers correctly, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 9e12e5882a 13/50: handle missing last state and add `*' for modified state buffer list, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 744fd23282 18/50: annotate: separate active flag (@) from modified flag (*), ELPA Syncer, 2024/12/25
- [elpa] externals/activities 09e469df96 20/50: completing-read: sort completion using new completion-table, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 455e3ebf8f 22/50: Make activities--annotate privately named, ELPA Syncer, 2024/12/25
- [elpa] externals/activities e392e233d3 21/50: annotate: "zero files" is plural, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 8683bb4662 24/50: Factor out buffer-and-files comparison functions, ELPA Syncer, 2024/12/25
- [elpa] externals/activities e774617fb1 25/50: save: retain last timestamp when buffer and files have not changed, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 0a3309ae51 27/50: Inline activities--completion-table, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 6d9b69485a 32/50: inline annotation-function and eliminate vc-annotate,
ELPA Syncer <=
- [elpa] externals/activities 67cb87f413 33/50: mapcar-window-state-leafs: improve varnames and docstring, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 322de07933 35/50: activities--age: rewrite, note future core replacement, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 425b6199ca 37/50: activities-annotation-colors: simplify doc and use ALPHA, ELPA Syncer, 2024/12/25
- [elpa] externals/activities d648a9e3a9 42/50: README: rename section as Completion, ELPA Syncer, 2024/12/25
- [elpa] externals/activities b69373eda6 43/50: README: simplify Completion description, ELPA Syncer, 2024/12/25
- [elpa] externals/activities b75e6f4ab6 44/50: oldest-age: find oldest age of last OR default state, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 9b792abceb 01/50: Initial annotation support for activities-completing-read, ELPA Syncer, 2024/12/25
- [elpa] externals/activities b07a5370de 02/50: Correct the file count, ELPA Syncer, 2024/12/25
- [elpa] externals/activities e829cf9fa2 03/50: re-org: move oldest-age up, ELPA Syncer, 2024/12/25
- [elpa] externals/activities 1e14be5c59 06/50: simplify annotation-function using pcase-let*, ELPA Syncer, 2024/12/25