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 --- init.el | 8 ++++++++ lisp/km-ol-git-link.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 lisp/km-ol-git-link.el diff --git a/init.el b/init.el index 3001f8f..1eff0bd 100644 --- a/init.el +++ b/init.el @@ -197,9 +197,17 @@ (define-key km/org-prefix-map "r" #'org-element-cache-reset) + (require 'km-ol-git-link) (require 'ol-notmuch) (require 'orgit)) +(use-package km-ol-git-link + :config + (advice-add 'org-git-store-link :override #'km/org-git-store-link + '((name . "org-git-store-link--override"))) + (advice-add 'org-git-open :override #'km/org-git-open-link + '((name . "org-git-open-link--override")))) + (use-package ox-latex :config (add-to-list 'org-latex-classes 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