From c5e41616648bbb7620b158d9408d98b92506ffc7 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Tue, 1 Sep 2020 22:41:48 -0400 Subject: Add tweaks for ol-git-link library --- lisp/km-ol-git-link.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lisp/km-ol-git-link.el (limited to 'lisp') diff --git a/lisp/km-ol-git-link.el b/lisp/km-ol-git-link.el new file mode 100644 index 0000000..efe5cd8 --- /dev/null +++ b/lisp/km-ol-git-link.el @@ -0,0 +1,56 @@ +;;; km-ol-git-link.el --- Tweaks to ol-git-link + +;; Copyright (C) 2020 Kyle Meyer + +;; Author: Kyle Meyer +;; URL: https://git.kyleam.com/emacs.d + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'magit) +(require 'ol-git-link) + +(defun km/org-git-store-link () + "Like `org-git-store-link', but work from Magit file buffers. +Regular file buffers are left untouched." + (when-let ((rev magit-buffer-revision) + (fname magit-buffer-file-name) + (repo (magit-toplevel))) + (org-link-store-props + :type "git" + :link (concat "git:" + (abbreviate-file-name fname) + "::" rev + "::" (number-to-string (line-number-at-pos))) + :description + (format "(%s)%s" + (file-name-nondirectory + (directory-file-name (file-name-as-directory repo))) + (file-relative-name fname repo))))) + +(defun km/org-git-open-link (str _) + "Open a git: link using `magit-find-file-other-window'." + (pcase-let ((`(,fname ,rev ,line) (org-git-split-string str))) + (let ((default-directory (file-name-directory fname))) + (magit-find-file-other-window rev fname)) + (when (string-match-p "\\`[0-9]+\\'" line) + (save-restriction + (widen) + (goto-char (point-min)) + (forward-line (1- (string-to-number line))))))) + +(provide 'km-ol-git-link) +;;; km-ol-git-link.el ends here -- cgit v1.2.3