summaryrefslogtreecommitdiff
path: root/lisp/km-magit.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-03-24 23:11:12 -0400
committerKyle Meyer <kyle@kyleam.com>2017-03-24 23:11:12 -0400
commit8891202e6eb80c1162fd35cebcfa621ea586742e (patch)
tree539a2e4eee2da510ff4c45aa9c007f0c72babdfc /lisp/km-magit.el
parent6144bee7acfc0c5d6aa68a5a13bbbd19d0f841d9 (diff)
downloademacs.d-8891202e6eb80c1162fd35cebcfa621ea586742e.tar.gz
magit-copy-functions: Provide message when copying
Diffstat (limited to 'lisp/km-magit.el')
-rw-r--r--lisp/km-magit.el32
1 files changed, 23 insertions, 9 deletions
diff --git a/lisp/km-magit.el b/lisp/km-magit.el
index 4ae89e4..5f118af 100644
--- a/lisp/km-magit.el
+++ b/lisp/km-magit.el
@@ -456,14 +456,25 @@ COMMIT."
(--when-let (magit-region-values 'commit)
(deactivate-mark)
(kill-new
- (mapconcat #'identity it
- (if read-separator (read-string "Separator: ") ", ")))))
+ (message
+ "%s"
+ (mapconcat #'identity
+ it
+ (if read-separator (read-string "Separator: ") ", "))))))
+
+(defun km/magit-copy--truncated-message (msg)
+ (let ((msg-lines (split-string msg "[\n\r]+" 'omit-nulls)))
+ (message "%s" (cl-case (length msg-lines)
+ (0 msg)
+ (1 (car msg-lines))
+ (t (concat (car msg-lines) "[...]"))))))
(defun km/magit-copy-commit-message (&optional _)
(magit-section-when message
- (kill-new
- (buffer-substring-no-properties (magit-section-start it)
- (magit-section-end it)))))
+ (let ((msg (buffer-substring-no-properties (magit-section-start it)
+ (magit-section-end it))))
+ (kill-new msg)
+ (km/magit-copy--truncated-message msg))))
(defun km/magit-copy-region-hunk (&optional no-column)
(when (magit-section-internal-region-p)
@@ -471,16 +482,19 @@ COMMIT."
(deactivate-mark)
(let ((text (buffer-substring-no-properties
(region-beginning) (region-end))))
- (kill-new (if no-column
- (replace-regexp-in-string "^[ \\+\\-]" "" text)
- text))))))
+ (setq text (if no-column
+ (replace-regexp-in-string "^[ \\+\\-]" "" text)
+ text))
+ (kill-new text)
+ (km/magit-copy--truncated-message text)))))
(defun km/magit-copy-hunk (&optional _)
(magit-section-when hunk
(kill-new (buffer-substring-no-properties
(save-excursion (goto-char (magit-section-start it))
(1+ (point-at-eol)))
- (magit-section-end it)))))
+ (magit-section-end it)))
+ (message "Copied hunk: %s" (magit-section-value it))))
(defun km/magit-copy-as-kill ()
"Try `km/magit-copy-functions' before calling `magit-copy-section-value'.