-
Notifications
You must be signed in to change notification settings - Fork 8
/
magit-loggy.el
81 lines (59 loc) · 2.78 KB
/
magit-loggy.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;;; magit-loggy.el --- Group Magit log commits by date -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Free Software Foundation, Inc.
;; Author: Adam Porter <[email protected]>
;; Maintainer: Adam Porter <[email protected]>
;; Keywords: convenience
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This works, but since magit-log uses overlays for the committer and
;; date on each line, those are lost when we erase the buffer. Fixing
;; that would require copying the properties of those overlays into
;; the text properties of each line. Probably not worth it, since
;; this is just a demo, anyway.
;;; Code:
;;;; Requirements
(require 'magit-log)
(require 'ov)
;;;; Variables
(defvar magit-loggy-taxy
(make-taxy :name "Commits"
:taxys (list
(make-taxy :name "By date"
:take (apply-partially #'taxy-take-keyed #'cdr)))))
;;;; Customization
;;;; Commands
(defun magit-loggy ()
(interactive)
(cl-assert (derived-mode-p 'magit-log-mode))
(save-excursion
(goto-char (point-min))
(cl-labels ((line-date
() (when-let ((ov (car (ov-in 'before-string 'any (line-beginning-position) (line-end-position))))
(string (cadr (get-text-property 0 'display (overlay-get ov 'before-string))))
(_ (string-match (rx (group (1+ digit) ; number
" "
(1+ (not blank))) ; unit
(1+ blank) eos)
string)))
(match-string 1 string))))
(let* ((lines (cl-loop until (eobp)
collect (cons (buffer-substring (point-at-bol) (point-at-eol))
(line-date))
do (forward-line 1)))
(taxy (taxy-fill lines (taxy-emptied magit-loggy-taxy)))
(inhibit-read-only t))
(erase-buffer)
(taxy-magit-section-insert taxy)))))
;;;; Functions
;;;; Footer
(provide 'magit-loggy)
;;; magit-loggy.el ends here