commit 38ca1110fcb8c285cdd15b0df2994b0349c08aa2 parent 3fbb94d81cc0557b6ef1335ce694d810a2d6fb25 Author: Vincent Demeester <vincent@sbr.pm> Date: Mon, 16 Nov 2020 18:28:31 +0100 tools/emacs: import vorg from submodule Signed-off-by: Vincent Demeester <vincent@sbr.pm> Diffstat:
M | .gitmodules | | | 3 | --- |
A | tools/emacs/lisp/ol-github.el | | | 70 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | tools/emacs/lisp/ol-gitlab.el | | | 81 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | tools/emacs/lisp/ol-grep.el | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | tools/emacs/lisp/ol-rg.el | | | 60 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | tools/emacs/lisp/ol-ripgrep.el | | | 56 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
D | tools/emacs/lisp/vorg | | | 1 | - |
7 files changed, 324 insertions(+), 4 deletions(-)
diff --git a/.gitmodules b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "tools/emacs/lisp/vorg"] - path = tools/emacs/lisp/vorg - url = https://gitlab.com/vdemeester/vorg.git diff --git a/tools/emacs/lisp/ol-github.el b/tools/emacs/lisp/ol-github.el @@ -0,0 +1,70 @@ +;;; ol-github.el --- Links to GitHub -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Vincent Demeester + +;; Author: Vincent Demeester <vincent@sbr.pm> +;; Keywords: org link github +;; Version: 0.1 +;; URL: https://gitlab.com/vdemeester/vorg +;; Package-Requires: ((emacs "26.0") (org "9.0")) +;; +;; This file is not part of GNU Emacs. + +;; 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.0, 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, write to the Free Software +;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Commentary: + +;; This file implements links to GitHub from within Org mode. +;; gh:tektoncd/pipeline : project +;; gh:tektoncd/pipeline#1 : issue or pr #1 + +;;; Code: + +(require 'ol) + +;; Install the link type +(org-link-set-parameters "gh" + :follow #'org-github-follow-link + :export #'org-github-export + :face '(:foreground "DimGrey" :underline t)) + + +(defun org-github-export (link description format) + "Export a github page link from Org files." + (let ((path (org-github-get-url link)) + (desc (or description link))) + (cond + ((eq format 'html) (format "<a hrefl=\"_blank\" href=\"%s\">%s</a>" path desc)) + ((eq format 'latex) (format "\\href{%s}{%s}" path desc)) + ((eq format 'texinfo) (format "@uref{%s,%s}" path desc)) + ((eq format 'ascii) (format "%s (%s)" desc path)) + (t path)))) + +(defun org-github-follow-link (issue) + "Browse github issue/pr specified." + (browse-url (org-github-get-url issue))) + +(defun org-github-get-url (path) + "Translate org-mode link `gh:foo/bar#1' to github url." + (setq expressions (split-string path "#")) + (setq project (nth 0 expressions)) + (setq issue (nth 1 expressions)) + (if issue + (format "https://github.com/%s/issues/%s" project issue) + (format "https://github.com/%s" project))) + +(provide 'ol-github) +;;; ol-github.el ends here diff --git a/tools/emacs/lisp/ol-gitlab.el b/tools/emacs/lisp/ol-gitlab.el @@ -0,0 +1,81 @@ +;;; ol-gitlab.el --- Links to Gitlab -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Vincent Demeester + +;; Author: Vincent Demeester <vincent@sbr.pm> +;; Keywords: org link gitlab +;; Version: 0.1 +;; URL: https://gitlab.com/vdemeester/vorg +;; Package-Requires: ((emacs "26.0") (org "9.0")) +;; +;; This file is not part of GNU Emacs. + +;; 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.0, 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, write to the Free Software +;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Commentary: + +;; This file implements links to Gitlab from within Org mode. +;; gl:vdemeester/emacs-config : project +;; gl:vdemeester/emacs-config#1 : issue #1 +;; gl:vdemeester/emacs-config##1 : merge-request #1 + +;;; Code: + +(require 'ol) + +;; Install the link type +(org-link-set-parameters "gl" + :follow #'org-gitlab-follow-link + :export #'org-gitlab-export + :face '(:foreground "DimGrey" :underline t)) + + +(defun org-gitlab-export (link description format) + "Export a gitlab page link from Org files." + (let ((path (org-gitlab-get-url link)) + (desc (or description link))) + (cond + ((eq format 'html) (format "<a hrefl=\"_blank\" href=\"%s\">%s</a>" path desc)) + ((eq format 'latex) (format "\\href{%s}{%s}" path desc)) + ((eq format 'texinfo) (format "@uref{%s,%s}" path desc)) + ((eq format 'ascii) (format "%s (%s)" desc path)) + (t path)))) + +(defun org-gitlab-follow-link (issue) + "Browse gitlab issue/pr specified." + (browse-url (org-gitlab-get-url issue))) + +(defun org-gitlab-get-url (path) + "Translate org-mode link `gh:foo/bar#1' to gitlab url." + (setq expressions (split-string path "#")) + (setq project (nth 0 expressions)) + (setq issue (nth 1 expressions)) + (setq mr (nth 2 expressions)) + (message (format "issue: %s" issue)) + (message (format "mr: %s" mr)) + (if (not (empty-string-p mr)) + (format "https://gitlab.com/%s/-/merge_requests/%s" project mr) + (if (not (empty-string-p issue)) + (format "https://gitlab.com/%s/-/issues/%s" project issue) + (format "https://gitlab.com/%s" project)))) + +(defun empty-string-p (string) + "Return true if the STRING is empty or nil. Expects string type." + (or (null string) + (zerop (length (string-trim string))))) + +(provide 'ol-gitlab) +;;; ol-gitlab.el ends here diff --git a/tools/emacs/lisp/ol-grep.el b/tools/emacs/lisp/ol-grep.el @@ -0,0 +1,57 @@ +;;; ol-grep.el --- Links to Grep -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Vincent Demeester + +;; Author: Vincent Demeester <vincent@sbr.pm> +;; Keywords: org link grep +;; Version: 0.1 +;; URL: https://gitlab.com/vdemeester/vorg +;; Package-Requires: ((emacs "26.0") (org "9.0")) +;; +;; This file is not part of GNU Emacs. + +;; 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.0, 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, write to the Free Software +;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Commentary: + +;; This file implements links to Grep from within Org mode. +;; grep:orgmode : run grep on current working dir with orgmode expression +;; grep:orgmode:config/ : run grep on config/ dir with orgmode expression + +;;; Code: + +(require 'ol) + +;; Install the link type +(org-link-set-parameters "rg" + :follow #'org-grep-follow-link + :face '(:foreground "DarkRed" :underline t)) + +(defun org-grep-follow-link (issue) + "Run `rgrep' with REGEXP and FOLDER as argument, +like this : [[grep:REGEXP:FOLDER]]." + (setq expressions (split-string regexp ":")) + (setq exp (nth 0 expressions)) + (grep-compute-defaults) + (if (= (length expressions) 1) + (progn + (rgrep exp "*" (expand-file-name "./"))) + (progn + (setq folder (nth 1 expressions)) + (rgrep exp "*" (expand-file-name folder))))) + +(provide 'ol-grep) +;;; ol-grep.el ends here diff --git a/tools/emacs/lisp/ol-rg.el b/tools/emacs/lisp/ol-rg.el @@ -0,0 +1,60 @@ +;;; ol-rg.el --- Links to rg -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Vincent Demeester + +;; Author: Vincent Demeester <vincent@sbr.pm> +;; Keywords: org link ripgrep rg.el +;; Version: 0.1 +;; URL: https://gitlab.com/vdemeester/vorg +;; Package-Requires: ((emacs "26.0") (org "9.0") (rg "1.8.0")) +;; +;; This file is not part of GNU Emacs. + +;; 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.0, 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, write to the Free Software +;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Commentary: + +;; This file implements links to Ripgrep from within Org mode. +;; rg:orgmode : run ripgrep on current working dir with orgmode expression +;; rg:orgmode:config/ : run ripgrep on config/ dir with orgmode expression +;; rg:orgmode:config/#org : run ripgrep on config/ dir with orgmode expression + +;;; Code: + +(require 'ol) + +;; Install the link type +(org-link-set-parameters "rg" + :follow #'org-rg-follow-link + :face '(:foreground "DarkGreen" :underline t)) + +(defun org-rg-follow-link (regexp) + "Run `rg` with REXEP as argument, +like this : [[rg:REGEXP:FOLDER#FILTER]]" + (setq expressions (split-string regexp ":")) + (setq exp (nth 0 expressions)) + (setq folderpart (nth 1 expressions)) + (setq files (split-string folderpart "#")) + (setq folder (nth 0 files)) + (setq filter (nth 1 files)) + (if folderpart + (if filter + (rg exp (concat "*." filter) folder) + (rg exp "*" folder)) + (rg exp "*" "./"))) + +(provide 'ol-rg) +;;; ol-rg.el ends here diff --git a/tools/emacs/lisp/ol-ripgrep.el b/tools/emacs/lisp/ol-ripgrep.el @@ -0,0 +1,56 @@ +;;; ol-ripgrep.el --- Links to Ripgrep -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 Vincent Demeester + +;; Author: Vincent Demeester <vincent@sbr.pm> +;; Keywords: org link ripgrep +;; Version: 0.1 +;; URL: https://gitlab.com/vdemeester/vorg +;; Package-Requires: ((emacs "26.0") (org "9.0") (ripgrep "0.4.0")) +;; +;; This file is not part of GNU Emacs. + +;; 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.0, 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, write to the Free Software +;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Commentary: + +;; This file implements links to Ripgrep from within Org mode. +;; ripgrep:orgmode : run ripgrep on current working dir with orgmode expression +;; ripgrep:orgmode:config/ : run ripgrep on config/ dir with orgmode expression + +;;; Code: + +(require 'ol) + +;; Install the link type +(org-link-set-parameters "ripgrep" + :follow #'org-ripgrep-follow-link + :face '(:foreground "DarkGreen" :underline t)) + +(defun org-ripgrep-follow-link (regexp) + "Run `ripgrep-regexp` with REXEP and FOLDER as argument, +like this : [[ripgrep:REGEXP:FOLDER]]" + (setq expressions (split-string regexp ":")) + (setq exp (nth 0 expressions)) + (if (= (length expressions) 1) + (progn + (ripgrep-regexp exp (expand-file-name "./"))) + (progn + (setq folder (nth 1 expressions)) + (ripgrep-regexp exp (file-name-as-directory (expand-file-name folder)))))) + +(provide 'ol-ripgrep) +;;; ol-ripgrep.el ends here diff --git a/tools/emacs/lisp/vorg b/tools/emacs/lisp/vorg @@ -1 +0,0 @@ -Subproject commit 92729ea931e4f5743c3b80ad062225f0509acb62