Commit ba330a6f authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit--format-spec: New function

parent c6d51ae1
......@@ -425,36 +425,27 @@ This is intended for debugging purposes.")
'face (list :background (face-attribute 'magit-blame-heading :background))))
(defun magit-blame-format-heading (chunk)
(with-temp-buffer
(insert (format-spec
(concat magit-blame-heading-format "\n")
`((?H . ,(propertize (or (plist-get chunk :hash) "")
'face 'magit-blame-hash))
(?s . ,(propertize (or (plist-get chunk :summary) "")
'face 'magit-blame-summary))
(?a . ,(propertize (or (plist-get chunk :author) "")
'face 'magit-blame-name))
(?A . ,(propertize (magit-blame-format-time-string
magit-blame-time-format
(plist-get chunk :author-time)
(plist-get chunk :author-tz))
'face 'magit-blame-date))
(?c . ,(propertize (or (plist-get chunk :committer) "")
'face 'magit-blame-name))
(?C . ,(propertize (magit-blame-format-time-string
magit-blame-time-format
(plist-get chunk :committer-time)
(plist-get chunk :committer-tz))
'face 'magit-blame-date)))))
(goto-char (point-min))
(while (not (eobp))
(let ((face (get-text-property (point) 'face))
(next (or (next-single-property-change (point) 'face)
(point-max))))
(unless face
(put-text-property (point) next 'face 'magit-blame-heading))
(goto-char next)))
(buffer-string)))
(magit--format-spec
(propertize (concat magit-blame-heading-format "\n")
'face 'magit-blame-heading)
`((?H . ,(propertize (or (plist-get chunk :hash) "")
'face 'magit-blame-hash))
(?s . ,(propertize (or (plist-get chunk :summary) "")
'face 'magit-blame-summary))
(?a . ,(propertize (or (plist-get chunk :author) "")
'face 'magit-blame-name))
(?A . ,(propertize (magit-blame-format-time-string
magit-blame-time-format
(plist-get chunk :author-time)
(plist-get chunk :author-tz))
'face 'magit-blame-date))
(?c . ,(propertize (or (plist-get chunk :committer) "")
'face 'magit-blame-name))
(?C . ,(propertize (magit-blame-format-time-string
magit-blame-time-format
(plist-get chunk :committer-time)
(plist-get chunk :committer-tz))
'face 'magit-blame-date)))))
(defun magit-blame-format-time-string (format time tz)
(format-time-string
......
......@@ -726,6 +726,42 @@ that it will align with the text area."
(eq face current))
return nil))
(defun magit--format-spec (format specification)
"Like `format-spec' but preserve text properties in SPECIFICATION."
(with-temp-buffer
(insert format)
(goto-char (point-min))
(while (search-forward "%" nil t)
(cond
;; Quoted percent sign.
((eq (char-after) ?%)
(delete-char 1))
;; Valid format spec.
((looking-at "\\([-0-9.]*\\)\\([a-zA-Z]\\)")
(let* ((num (match-string 1))
(spec (string-to-char (match-string 2)))
(val (assq spec specification)))
(unless val
(error "Invalid format character: `%%%c'" spec))
(setq val (cdr val))
;; Pad result to desired length.
(let ((text (format (concat "%" num "s") val)))
;; Insert first, to preserve text properties.
(if (next-property-change 0 (concat " " text))
;; If the inserted text has properties, then preserve those.
(insert text)
;; Otherwise preserve FORMAT's properties, like `format-spec'.
(insert-and-inherit text))
;; Delete the specifier body.
(delete-region (+ (match-beginning 0) (length text))
(+ (match-end 0) (length text)))
;; Delete the percent sign.
(delete-region (1- (match-beginning 0)) (match-beginning 0)))))
;; Signal an error on bogus format strings.
(t
(error "Invalid format string"))))
(buffer-string)))
;;; Missing from Emacs
(defun magit-kill-this-buffer ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment