fedora-csb-system-manager
1;;; ol-grep.el --- Links to Grep -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2020 Vincent Demeester
4
5;; Author: Vincent Demeester <vincent@sbr.pm>
6;; Keywords: org link grep
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 Grep from within Org mode.
31;; grep:orgmode : run grep on current working dir with orgmode expression
32;; grep:orgmode:config/ : run grep on config/ dir with orgmode expression
33
34;;; Code:
35
36(require 'ol)
37
38;; Install the link type
39(org-link-set-parameters "rg"
40 :follow #'org-grep-follow-link
41 :face '(:foreground "DarkRed" :underline t))
42
43(defun org-grep-follow-link (issue)
44 "Run `rgrep' with REGEXP and FOLDER as argument,
45like this : [[grep:REGEXP:FOLDER]]."
46 (setq expressions (split-string regexp ":"))
47 (setq exp (nth 0 expressions))
48 (grep-compute-defaults)
49 (if (= (length expressions) 1)
50 (progn
51 (rgrep exp "*" (expand-file-name "./")))
52 (progn
53 (setq folder (nth 1 expressions))
54 (rgrep exp "*" (expand-file-name folder)))))
55
56(provide 'ol-grep)
57;;; ol-grep.el ends here