# [PATCH 2/4] git-blame.el: Make all line prefixes to have the same length

5 messages from 2013-07-02 to 2013-07-02. Participants: Michal Sojka.
Thread: https://gitlist.dev/t/34325

## Michal Sojka, 2013-07-02 17:34

Subject: [PATCH 0/4] Emacs: git-blame.el fixes and enhancements
Message-ID: <1372786477-13122-1-git-send-email-sojkam1@fel.cvut.cz>
URL: https://gitlist.dev/e/1372786477-13122-1-git-send-email-sojkam1%40fel.cvut.cz

```
Hi all,

following are a few fixes and enhancements to Emacs' git-blame-mode
(contrib/emacs/git-blame.el).

Michal Sojka (4):
  git-blame.el: Fix buffer local declaration
  git-blame.el: Make all line prefixes to have the same length
  git-blame.el: Allow displaying author/commit times
  git-blame.el: Change the default prefix format

 contrib/emacs/git-blame.el | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

-- 
1.8.3.1

```

## Michal Sojka, 2013-07-02 17:34

Subject: [PATCH 1/4] git-blame.el: Fix buffer local declaration
Message-ID: <1372786477-13122-2-git-send-email-sojkam1@fel.cvut.cz>
URL: https://gitlist.dev/e/1372786477-13122-2-git-send-email-sojkam1%40fel.cvut.cz
In-Reply-To: <1372786477-13122-1-git-send-email-sojkam1@fel.cvut.cz>

```
git-blame-cache was declared buffer-local two times and
git-blame-idle-timer is global. The intended meaning was probably to make
git-blame-idle-timer buffer-local.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
 contrib/emacs/git-blame.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el
index e671f6c..18ce241 100644
--- a/contrib/emacs/git-blame.el
+++ b/contrib/emacs/git-blame.el
@@ -200,7 +200,7 @@ minor mode.")
 
 (defvar git-blame-idle-timer nil
   "An idle timer that updates the blame")
-(make-variable-buffer-local 'git-blame-cache)
+(make-variable-buffer-local 'git-blame-idle-timer)
 
 (defvar git-blame-update-queue nil
   "A queue of update requests")
-- 
1.8.3.1

```

## Michal Sojka, 2013-07-02 17:34

Subject: [PATCH 2/4] git-blame.el: Make all line prefixes to have the same length
Message-ID: <1372786477-13122-3-git-send-email-sojkam1@fel.cvut.cz>
URL: https://gitlist.dev/e/1372786477-13122-3-git-send-email-sojkam1%40fel.cvut.cz
In-Reply-To: <1372786477-13122-1-git-send-email-sojkam1@fel.cvut.cz>

```
Without this patch, the beginning of git-blame.el in emacs buffer looks
like this (note the Messige-ID line):

b52ba1   <jnareb@gmail.com>:;; Authors:    David Kågedal <davidk@lysator.liu.se>
b52ba1   <jnareb@gmail.com>:;; Created:    31 Jan 2007
28389d <davidk@lysator.liu.se>:;; Message-ID: <87iren2vqx.fsf@morpheus.local>
b52ba1   <jnareb@gmail.com>:;; License:    GPL
b52ba1   <jnareb@gmail.com>:;; Keywords:   git, version control, release management

With this patch, all lines are aligned even if email addresses have
different length.

b52ba1   <jnareb@gmail.com>:   ;; Authors:    David Kågedal <davidk@lysator.liu.se>
b52ba1   <jnareb@gmail.com>:   ;; Created:    31 Jan 2007
28389d <davidk@lysator.liu.se> ;; Message-ID: <87iren2vqx.fsf@morpheus.local>
b52ba1   <jnareb@gmail.com>:   ;; License:    GPL
b52ba1   <jnareb@gmail.com>:   ;; Keywords:   git, version control, release management


Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
 contrib/emacs/git-blame.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el
index 18ce241..573f408 100644
--- a/contrib/emacs/git-blame.el
+++ b/contrib/emacs/git-blame.el
@@ -116,6 +116,15 @@ mode. The format is passed to `format-spec' with the following format keys:
 "
   :group 'git-blame)
 
+(defcustom git-blame-prefix-width
+  "%-30.30s "
+  "The format for post-processing the prefix produced according
+to `git-blame-prefix-format'. This format is passed to `format'
+function. The default value ensures that all prefixes have the
+same length, i.e. the it causes the prefix to be either truncated
+or padded to 30 characters.
+"
+  :group 'git-blame)
 (defcustom git-blame-mouseover-format
   "%h %a %A: %s"
   "The format of the description shown when pointing at a line in
@@ -410,8 +419,9 @@ See also function `git-blame-mode'."
               (overlay-put ovl 'face (list :background
                                            (cdr (assq 'color (cdr info))))))
           (overlay-put ovl 'line-prefix
-                       (propertize (format-spec git-blame-prefix-format spec)
-                                   'face 'git-blame-prefix-face)))))))
+                       (propertize (format git-blame-prefix-width
+					   (format-spec git-blame-prefix-format spec))
+					   'face 'git-blame-prefix-face)))))))
 
 (defun git-blame-add-info (info key value)
   (nconc info (list (cons (intern key) value))))
-- 
1.8.3.1

```

## Michal Sojka, 2013-07-02 17:34

Subject: [PATCH 3/4] git-blame.el: Allow displaying author/commit times
Message-ID: <1372786477-13122-4-git-send-email-sojkam1@fel.cvut.cz>
URL: https://gitlist.dev/e/1372786477-13122-4-git-send-email-sojkam1%40fel.cvut.cz
In-Reply-To: <1372786477-13122-1-git-send-email-sojkam1@fel.cvut.cz>

```
Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
 contrib/emacs/git-blame.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el
index 573f408..5c8933e 100644
--- a/contrib/emacs/git-blame.el
+++ b/contrib/emacs/git-blame.el
@@ -110,8 +110,10 @@ mode. The format is passed to `format-spec' with the following format keys:
   %H - the full hash
   %a - the author name
   %A - the author email
+  %t - the author time (see `git-blame-time-format')
   %c - the committer name
   %C - the committer email
+  %T - the committer time (see `git-blame-time-format')
   %s - the commit summary
 "
   :group 'git-blame)
@@ -125,6 +127,14 @@ same length, i.e. the it causes the prefix to be either truncated
 or padded to 30 characters.
 "
   :group 'git-blame)
+
+(defcustom git-blame-time-format
+  "%Y-%m-%d"
+  "The format for date/time values. This format is passed to
+`format-time-string' function.
+"
+  :group 'git-blame)
+
 (defcustom git-blame-mouseover-format
   "%h %a %A: %s"
   "The format of the description shown when pointing at a line in
@@ -135,8 +145,10 @@ with the following format keys:
   %H - the full hash
   %a - the author name
   %A - the author email
+  %t - the author time (see `git-blame-time-format')
   %c - the committer name
   %C - the committer email
+  %T - the committer time (see `git-blame-time-format')
   %s - the commit summary
 "
   :group 'git-blame)
@@ -393,6 +405,9 @@ See also function `git-blame-mode'."
           (puthash hash info git-blame-cache)
           info))))
 
+(defun git-blame-format-time (seconds)
+  (format-time-string git-blame-time-format (seconds-to-time (string-to-number seconds))))
+
 (defun git-blame-create-overlay (info start-line num-lines)
   (with-current-buffer git-blame-file
     (save-excursion
@@ -408,8 +423,10 @@ See also function `git-blame-mode'."
                        (?H . ,hash)
                        (?a . ,(git-blame-get-info info 'author))
                        (?A . ,(git-blame-get-info info 'author-mail))
+                       (?t . ,(git-blame-format-time (git-blame-get-info info 'author-time)))
                        (?c . ,(git-blame-get-info info 'committer))
                        (?C . ,(git-blame-get-info info 'committer-mail))
+                       (?T . ,(git-blame-format-time (git-blame-get-info info 'committer-time)))
                        (?s . ,(git-blame-get-info info 'summary)))))
           (push ovl git-blame-overlays)
           (overlay-put ovl 'git-blame info)
-- 
1.8.3.1

```

## Michal Sojka, 2013-07-02 17:34

Subject: [PATCH 4/4] git-blame.el: Change the default prefix format
Message-ID: <1372786477-13122-5-git-send-email-sojkam1@fel.cvut.cz>
URL: https://gitlist.dev/e/1372786477-13122-5-git-send-email-sojkam1%40fel.cvut.cz
In-Reply-To: <1372786477-13122-1-git-send-email-sojkam1@fel.cvut.cz>

```
Now, the format resembles more the default format of `git blame`.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
 contrib/emacs/git-blame.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el
index 5c8933e..74b1486 100644
--- a/contrib/emacs/git-blame.el
+++ b/contrib/emacs/git-blame.el
@@ -102,7 +102,7 @@
   :group 'git-blame)
 
 (defcustom git-blame-prefix-format
-  "%h %20A:"
+  "%h %t %a"
   "The format of the prefix added to each line in `git-blame'
 mode. The format is passed to `format-spec' with the following format keys:
 
-- 
1.8.3.1

```
