ol-github.el (2485B)
1 ;;; ol-github.el --- Links to GitHub -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2020 Vincent Demeester 4 5 ;; Author: Vincent Demeester <vincent@sbr.pm> 6 ;; Keywords: org link github 7 ;; Version: 0.1 8 ;; URL: https://gitlab.com/vdemeester/vorg 9 ;; Package-Requires: ((emacs "26.0") (org "9.0")) 10 ;; 11 ;; This file is not part of GNU Emacs. 12 13 ;; This program is free software; you can redistribute it and/or 14 ;; modify it under the terms of the GNU General Public License as 15 ;; published by the Free Software Foundation; either version 3.0, or 16 ;; (at your option) any later version. 17 18 ;; This program is distributed in the hope that it will be useful, 19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 ;; GNU General Public License for more details. 22 23 ;; You should have received a copy of the GNU General Public License 24 ;; along with this program; if not, write to the Free Software 25 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 27 ;; 28 ;;; Commentary: 29 30 ;; This file implements links to GitHub from within Org mode. 31 ;; gh:tektoncd/pipeline : project 32 ;; gh:tektoncd/pipeline#1 : issue or pr #1 33 34 ;;; Code: 35 36 (require 'ol) 37 38 ;; Install the link type 39 (org-link-set-parameters "gh" 40 :follow #'org-github-follow-link 41 :export #'org-github-export 42 :face '(:foreground "DimGrey" :underline t)) 43 44 45 (defun org-github-export (link description format) 46 "Export a github page link from Org files." 47 (let ((path (org-github-get-url link)) 48 (desc (or description link))) 49 (cond 50 ((eq format 'html) (format "<a hrefl=\"_blank\" href=\"%s\">%s</a>" path desc)) 51 ((eq format 'latex) (format "\\href{%s}{%s}" path desc)) 52 ((eq format 'texinfo) (format "@uref{%s,%s}" path desc)) 53 ((eq format 'ascii) (format "%s (%s)" desc path)) 54 (t path)))) 55 56 (defun org-github-follow-link (issue) 57 "Browse github issue/pr specified." 58 (browse-url (org-github-get-url issue))) 59 60 (defun org-github-get-url (path) 61 "Translate org-mode link `gh:foo/bar#1' to github url." 62 (setq expressions (split-string path "#")) 63 (setq project (nth 0 expressions)) 64 (setq issue (nth 1 expressions)) 65 (if issue 66 (format "https://github.com/%s/issues/%s" project issue) 67 (format "https://github.com/%s" project))) 68 69 (provide 'ol-github) 70 ;;; ol-github.el ends here