summaryrefslogtreecommitdiff
path: root/lisp/init-git.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-08-31 20:36:49 -0400
committerKyle Meyer <kyle@kyleam.com>2015-08-31 20:36:49 -0400
commit5df95662eb2f07564101fd303159f176f605c588 (patch)
treee60c81c19c6bd6fb3b7e19283ee576abb4f35f6e /lisp/init-git.el
parentb31eaaf624334d771811bc907a5aa6af04be82bd (diff)
downloademacs.d-5df95662eb2f07564101fd303159f176f605c588.tar.gz
Make magit-copy-commit-citation useful outside hook
Diffstat (limited to 'lisp/init-git.el')
-rw-r--r--lisp/init-git.el40
1 files changed, 19 insertions, 21 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el
index 5c18d66..3c4ab47 100644
--- a/lisp/init-git.el
+++ b/lisp/init-git.el
@@ -360,7 +360,7 @@ argument."
(user-error "No hash found at point"))))
(defvar km/magit-copy-hook
- '(km/magit-copy-commit-citation
+ '(km/magit-copy-commit-citation-from-header
km/magit-copy-commit-message
km/magit-copy-region-commits
km/magit-copy-region-hunk
@@ -370,27 +370,25 @@ These will be given one argument (the current prefix value) and
should succeed by copying and returning non-nil or fail by
returning nil.")
-(defun km/magit-copy-commit-citation (&optional arg)
- "Copy reference to commit from header section.
-Format the reference as '<hash>, (\"<subject>\", <date>)'."
+(defun km/magit-copy-commit-citation (commit)
+ "Copy a citation for the COMMIT at point.
+Format the reference as '<hash>, (\"<subject>\", <date>)'. If
+there is no commit at point or with a prefix argument, prompt for
+COMMIT."
+ (interactive
+ (let ((atpoint (or (and magit-blame-mode (magit-blame-chunk-get :hash))
+ (magit-branch-or-commit-at-point)
+ (magit-tag-at-point))))
+ (list (or (and (not current-prefix-arg) atpoint)
+ (magit-read-branch-or-commit "Commit" atpoint)))))
+ (cl-destructuring-bind (hash subject date)
+ (magit-git-lines "show" "-s" "--date=short"
+ "--format=%h\n%s\n%ad" commit)
+ (kill-new (message "%s (\"%s\", %s)" hash subject date))))
+
+(defun km/magit-copy-commit-citation-from-header (&optional arg)
(magit-section-when headers
- (let ((hash (km/magit-shorten-hash (car magit-refresh-args)))
- (date (format-time-string
- "%Y-%m-%d"
- (save-excursion
- (goto-char (magit-section-start it))
- (re-search-forward "AuthorDate: ")
- (date-to-time (buffer-substring-no-properties
- (point) (point-at-eol))))))
- (subject (save-excursion
- (goto-char
- (magit-section-start
- (-first (lambda (sec)
- (eq (magit-section-type sec) 'message))
- (magit-section-children it))))
- (buffer-substring-no-properties
- (+ 4 (point)) (point-at-eol)))))
- (kill-new (message "%s (\"%s\", %s)" hash subject date)))))
+ (km/magit-copy-commit-citation (car magit-refresh-args))))
(defun km/magit-copy-region-commits (&optional arg)
(--when-let (magit-region-values 'commit)