Skip to content

Instantly share code, notes, and snippets.

@mooz
Created November 21, 2012 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooz/4123227 to your computer and use it in GitHub Desktop.
Save mooz/4123227 to your computer and use it in GitHub Desktop.
Pretty magit-log
;; Display commit author and datetime in magit-log
(setq magit-present-log-line-function 'my:magit-present-log-line)
(defface my:magit-log-author
'((((class color) (background light)) :foreground "SkyBlue")
(((class color) (background dark)) :foreground "SkyBlue"))
"Face for the sha1 element of the log output."
:group 'magit-faces)
(defface my:magit-log-datetime
'((((class color) (background light)) :foreground "DarkGrey")
(((class color) (background dark)) :foreground "DimGray"))
"Face for the sha1 element of the log output."
:group 'magit-faces)
(defun my:magit-log ()
(interactive)
(magit-log nil "--pretty=format:%h%d %s [%an] <%cr>"))
(defvar my:magit-log-line-regexp "^\\(.*\\) \\[\\(.*?\\)\\] <\\(.*\\)>$")
(defun my:magit-present-log-line (graph sha1 refs message)
"A log line generator that highlights commit author and datetime."
(let ((string-refs
(when refs
(let ((colored-labels
(delete nil
(mapcar (lambda (r)
(destructuring-bind (label face)
(magit-ref-get-label-color r)
(and label
(propertize label 'face face))))
refs))))
(concat
(mapconcat 'identity colored-labels " ")
" ")))))
(concat
(if sha1
(propertize sha1 'face 'magit-log-sha1)
(insert-char ? magit-sha1-abbrev-length))
" "
(when graph
(propertize graph 'face 'magit-log-graph))
string-refs
(when message
(if (string-match my:magit-log-line-regexp message)
;; With author and timestamp
(concat
(propertize (match-string 1 message) 'face 'magit-log-message)
" (by "
(propertize (match-string 2 message) 'face 'my:magit-log-author)
", "
(propertize (match-string 3 message) 'face 'my:magit-log-datetime)
")"
)
;; Default
(propertize message 'face 'magit-log-message))))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment