|
6 | 6 | ;; Maintainer: Shen, Jen-Chieh <jcs090218@gmail.com> |
7 | 7 | ;; URL: https://github.com/emacs-sideline/sideline-blame |
8 | 8 | ;; Version: 0.1.0 |
9 | | -;; Package-Requires: ((emacs "27.1") (sideline "0.1.0")) |
| 9 | +;; Package-Requires: ((emacs "27.1") (sideline "0.1.0") (vc-msg "1.1.1")) |
10 | 10 | ;; Keywords: sideline blame |
11 | 11 |
|
12 | 12 | ;; This file is not part of GNU Emacs. |
|
32 | 32 | ;;; Code: |
33 | 33 |
|
34 | 34 | (require 'sideline) |
| 35 | +(require 'vc-msg) |
35 | 36 |
|
36 | 37 | (defgroup sideline-blame nil |
37 | 38 | "Show blame messages with sideline." |
38 | 39 | :prefix "sideline-blame-" |
39 | 40 | :group 'tool |
40 | 41 | :link '(url-link :tag "Repository" "https://github.com/emacs-sideline/sideline-blame")) |
41 | 42 |
|
| 43 | +(defcustom sideline-blame-author-format "%s, " |
| 44 | + "Format string for author name." |
| 45 | + :type 'string |
| 46 | + :group 'sideline-blame) |
| 47 | + |
| 48 | +(defcustom sideline-blame-datetime-format "%b %d %Y %H:%M:%S " |
| 49 | + "Format string for datetime." |
| 50 | + :type 'string |
| 51 | + :group 'sideline-blame) |
| 52 | + |
| 53 | +(defcustom sideline-blame-commit-format "◉ %s" |
| 54 | + "Format string for commit message." |
| 55 | + :type 'string |
| 56 | + :group 'sideline-blame) |
| 57 | + |
| 58 | +(defcustom sideline-blame-uncommitted-author-name "Unknown" |
| 59 | + "Message for commits where you are author." |
| 60 | + :type 'string |
| 61 | + :group 'sideline-blame) |
| 62 | + |
| 63 | +(defcustom sideline-blame-uncommitted-message "Uncommitted changes" |
| 64 | + "Message for uncommitted lines." |
| 65 | + :type 'string |
| 66 | + :group 'sideline-blame) |
| 67 | + |
| 68 | +;;;###autoload |
| 69 | +(defun sideline-blame (command) |
| 70 | + "Backend for sideline. |
| 71 | +
|
| 72 | +Argument COMMAND is required in sideline backend." |
| 73 | + (cl-case command |
| 74 | + (`candidates (cons :async #'sideline-blame--get-message)))) |
| 75 | + |
| 76 | +(defun sideline-blame--get-message (callback &rest _) |
| 77 | + "Return the message. |
| 78 | +
|
| 79 | +Execute CALLBACK to display with sideline." |
| 80 | + (when-let* |
| 81 | + ((plugin (vc-msg-find-plugin)) |
| 82 | + (current-file (funcall vc-msg-get-current-file-function)) |
| 83 | + (executer (plist-get plugin :execute)) |
| 84 | + (formatter (plist-get plugin :format)) |
| 85 | + (commit-info (and current-file |
| 86 | + (funcall executer |
| 87 | + current-file |
| 88 | + (funcall vc-msg-get-line-num-function) |
| 89 | + (funcall vc-msg-get-version-function)))) |
| 90 | + (id (plist-get commit-info :id))) |
| 91 | + (let* ((uncommitted (zerop (string-to-number id))) |
| 92 | + (author (if uncommitted sideline-blame-uncommitted-author-name |
| 93 | + (plist-get commit-info :author))) |
| 94 | + (time (string-to-number (plist-get commit-info :author-time))) |
| 95 | + (summary (if uncommitted sideline-blame-uncommitted-message |
| 96 | + (plist-get commit-info :summary)))) |
| 97 | + (funcall callback |
| 98 | + (list (concat (format sideline-blame-author-format author) |
| 99 | + (format-time-string sideline-blame-datetime-format time) |
| 100 | + (format sideline-blame-commit-format summary))))))) |
| 101 | + |
42 | 102 | (provide 'sideline-blame) |
43 | 103 | ;;; sideline-blame.el ends here |
0 commit comments