;;; km-ol-git-link.el --- Tweaks to ol-git-link ;; Copyright 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