diff options
author | Kyle Meyer <kyle@kyleam.com> | 2020-09-01 22:41:48 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2020-09-01 22:57:19 -0400 |
commit | c5e41616648bbb7620b158d9408d98b92506ffc7 (patch) | |
tree | d3ffdc5e969e63fe3e9215f41be5cd61af7c5252 /lisp | |
parent | 5ba3fc32c00cbce8ebb2dd6b3e34fe91a9a02216 (diff) | |
download | emacs.d-c5e41616648bbb7620b158d9408d98b92506ffc7.tar.gz |
Add tweaks for ol-git-link library
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/km-ol-git-link.el | 56 |
1 files changed, 56 insertions, 0 deletions
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 <kyle@kyleam.com> + +;; Author: Kyle Meyer <kyle@kyleam.com> +;; 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 <http://www.gnu.org/licenses/>. + +;;; 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 |