[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/why-this 2093cadb03 06/59: Add relative time support and f
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/why-this 2093cadb03 06/59: Add relative time support and fix Git backend |
Date: |
Sun, 27 Nov 2022 16:02:48 -0500 (EST) |
branch: elpa/why-this
commit 2093cadb03d27ad6df0d4f25f1da8a5692d69215
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>
Add relative time support and fix Git backend
---
why-this.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 54 insertions(+), 10 deletions(-)
diff --git a/why-this.el b/why-this.el
index 846efdfba1..077ebc2db2 100644
--- a/why-this.el
+++ b/why-this.el
@@ -41,16 +41,18 @@
(defcustom why-this-backends '(why-this-backend-git)
"List of enabled backends."
:type '(repeat (function :tag "Backend"))
+ :package-version '(why-this "1.0")
:group 'why-this)
-(defcustom why-this-message-format " %A, %T * %i"
+(defcustom why-this-message-format " %A, %t * %i"
"Format string for formatting message.
All characters are written as is, except certain constructs which are
substituted by text describing the author, time or message:
%a Author name, as returned by the backend.
- %A Author nick name.
+ %A Author's nick name.
+ %t Relative time when last change. (E.g. \"a month ago\")
%T Time when last changed, formatted as \"%d %B %Y\" (see
`format-time-string').
%i Message.
@@ -58,6 +60,7 @@ substituted by text describing the author, time or message:
The value can also be a function to do the formatting itself."
:type '(choice (string :tag "Format string")
(function :tag "Formatter function"))
+ :package-version '(why-this "1.0")
:group 'why-this)
(defcustom why-this-nick-name-alist nil
@@ -67,18 +70,22 @@ Each element is of the following form: (NICK . AUTHORS),
where NICK is the
nick name and AUTHORS is list of the name of authors corresponding to
NICK."
:type '(repeat (cons (string :tag "Nick")
- (repeat (string :tag "Author")))))
+ (repeat (string :tag "Author"))))
+ :package-version '(why-this "1.0")
+ :group 'why-this)
(defcustom why-this-idle-delay 0.5
- "Idle delay for rendering."
+ "Idle delay for rendering in seconds."
:type 'number
+ :package-version '(why-this "1.0")
:group 'why-this)
(defface why-this-face
- '((t :foreground "#a8a8a8"
+ '((t :foreground "#82b0ec"
:background nil
:italic t))
"Face for Why-This data."
+ :package-version '(why-this "1.0")
:group 'why-this)
(defvar why-this--git-author-name (string-trim
@@ -103,6 +110,39 @@ NICK."
(throw 'name (car nick))))
author))
+(defun why-this-relative-time (time &optional exact)
+ "Format TIME as a relative age.
+
+When EXACT is non-nil, be as exact as possible."
+ (let* ((elapsed (max (floor (float-time (time-since time))) 0))
+ str
+ (calc-time
+ (lambda (type length)
+ (let ((count (/ elapsed length)))
+ (setq str (concat str
+ (unless (zerop count)
+ (if (eq count 1)
+ (format "a%s %s "
+ (if (string= type "hour")
+ "n" "")
+ type)
+ (format "%i %ss " count type))))
+ elapsed (% elapsed length))))))
+ (if (zerop elapsed)
+ "Now"
+ (funcall calc-time "year" (floor (* 365.25 24 3600)))
+ (when (or exact (zerop (length str)))
+ (funcall calc-time "month" (* 30 24 3600))
+ (when (or exact (zerop (length str)))
+ (funcall calc-time "day" (* 24 3600))
+ (when (or exact (zerop (length str)))
+ (funcall calc-time "hour" 3600)
+ (when (or exact (zerop (length str)))
+ (funcall calc-time "minute" 60)
+ (when (or exact (zerop (length str)))
+ (funcall calc-time "second" 1))))))
+ (concat str "ago"))))
+
(defun why-this-format-data (data)
"Format DATA."
(if (functionp why-this-message-format)
@@ -111,6 +151,7 @@ NICK."
(?A . (why-this-nick-name (plist-get data :author)))
(?T . (format-time-string "%d %B %Y"
(plist-get data :time)))
+ (?t . (why-this-relative-time (plist-get data :time)))
(?i . (plist-get data :message)))))
(replace-regexp-in-string
"%."
@@ -138,8 +179,7 @@ NICK."
(region-end)
(point)))))
(backend why-this--backend)
- (data (funcall backend 'line-data (buffer-file-name)
- begin end)))
+ (data (funcall backend 'line-data begin end)))
(dolist (i (number-sequence 0 (- end begin 1)))
(let ((pos (save-excursion
(goto-char (point-min))
@@ -233,13 +273,13 @@ Do CMD with ARGS."
(string= "true\n" (shell-command-to-string
"git rev-parse --is-inside-work-tree")))
('line-data
- (when (> (- (nth 2 args) (nth 1 args)) 0)
+ (when (> (- (nth 1 args) (nth 0 args)) 0)
(let ((lines (butlast
(split-string
(shell-command-to-string
(format
"git blame -L %i,%i \"%s\" --line-porcelain"
- (nth 1 args) (1- (nth 2 args)) (nth 0 args)))
+ (nth 0 args) (1- (nth 1 args)) (buffer-file-name)))
"\n")))
line-data
uncommitted
@@ -264,6 +304,7 @@ Do CMD with ARGS."
"Uncommitted changes"
commit-message)))
(setq
+ uncommitted nil
line-data
(append
line-data
@@ -297,7 +338,10 @@ Do CMD with ARGS."
(* (timezone-zone-to-minute (nth 1 words))
60)))
("summary"
- (setq commit-message (substring line 8))))))))))
+ (setq commit-message (substring line 8)))))))))
+ (while (< (length line-data) (- (nth 1 args) (nth 0 args)))
+ (setq uncommitted t)
+ (funcall line-data-add)))
line-data)))))
(provide 'why-this)
- [nongnu] elpa/why-this 53b2b803f0 22/59: Update commentary, (continued)
- [nongnu] elpa/why-this 53b2b803f0 22/59: Update commentary, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this d47f547250 39/59: Allow customization of executable paths, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 7f1ae28159 36/59: Fix Git backend, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 9f656b59dd 33/59: Change package summary, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 3497115c2b 35/59: Don't store unnecessary data, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 7a2e4af450 19/59: Rewrite Git backend, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 41fe21da73 15/59: Fontify before annotate, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 006ea3864a 13/59: Fix Git backend 'supported-p command, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 0c1686d8d3 12/59: Fix misspelled word "annonate", ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 73398fb7cb 04/59: Don't interfere with writing, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 2093cadb03 06/59: Add relative time support and fix Git backend,
ELPA Syncer <=
- [nongnu] elpa/why-this c2a21ca13d 01/59: Core implementation without any backends, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this b26fca274d 21/59: Add COPYING, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 88ee5f9746 27/59: Add Mercurial backend, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 624e98bc78 23/59: Fix relative time calculation, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 45dc65ccb1 26/59: Fix timezone problem in Git backend, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 236f8fd225 09/59: Fix problem when enabled on multiple buffers, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this dc5fc19b75 30/59: Allow changing time format, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this b8e612d4cb 20/59: Show tooltip on hover, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this aa15ec4fcd 29/59: Add support for minimum column of message, ELPA Syncer, 2022/11/27
- [nongnu] elpa/why-this 3e3f852835 38/59: Fix README, ELPA Syncer, 2022/11/27