From 624c03e2c1b726768227dbbdb02a1b92e943b24d Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Tue, 29 Oct 2019 14:32:54 +0900 Subject: [PATCH] Add my-magit-messenger --- emacs.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/emacs.el b/emacs.el index b53fa56..62cd492 100644 --- a/emacs.el +++ b/emacs.el @@ -1162,6 +1162,38 @@ found, otherwise returns nil." (set-face-background 'magit-diff-lines-boundary "blue") ) +(defun my-magit-messenger (file line) + "Magit messenger." + (interactive (list buffer-file-name + (line-number-at-pos))) + (cl-assert file) + (cl-assert line) + (let* ((blame-args '("-w")) + (id (with-temp-buffer + (let ((exit (apply 'call-process + "git" ;; PROGRAM + nil ;; INFILE + t ;; DESTINATION + nil ;; DISPLAY + "--no-pager" ;; ARGS + "blame" + "-L" + (format "%d,+1" line) + "--porcelain" + file + blame-args + ))) + (goto-char (point-min)) + (cl-assert (eq exit 0) + "Failed: %s" (buffer-substring (point) + (point-at-eol))) + (save-match-data + (re-search-forward (rx buffer-start + (one-or-more hex-digit))) + (match-string 0)))))) + (magit-show-commit id))) + + (when (boundp 'git-rebase-filename-regexp) (add-to-list 'auto-mode-alist `(,git-rebase-filename-regexp . text-mode)))