home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

ol-ripgrep.el (2103B)


      1 ;;; ol-ripgrep.el --- Links to Ripgrep -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2020 Vincent Demeester
      4 
      5 ;; Author: Vincent Demeester <vincent@sbr.pm>
      6 ;; Keywords: org link ripgrep
      7 ;; Version: 0.1
      8 ;; URL: https://gitlab.com/vdemeester/vorg
      9 ;; Package-Requires: ((emacs "26.0") (org "9.0") (ripgrep "0.4.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 Ripgrep from within Org mode.
     31 ;; ripgrep:orgmode         : run ripgrep on current working dir with orgmode expression
     32 ;; ripgrep:orgmode:config/ : run ripgrep on config/ dir with orgmode expression
     33 
     34 ;;; Code:
     35 
     36 (require 'ol)
     37 (require 'ripgrep)
     38 
     39 ;; Install the link type
     40 (org-link-set-parameters "ripgrep"
     41                          :follow #'org-ripgrep-follow-link
     42                          :face '(:foreground "DarkGreen" :underline t))
     43 
     44 (defun org-ripgrep-follow-link (regexp)
     45   "Run `ripgrep-regexp` with REXEP and FOLDER as argument,
     46 like this : [[ripgrep:REGEXP:FOLDER]]"
     47   (setq expressions (split-string regexp ":"))
     48   (setq exp (nth 0 expressions))
     49   (if (= (length expressions) 1)
     50       (progn
     51         (ripgrep-regexp exp (expand-file-name "./")))
     52     (progn
     53       (setq folder (nth 1 expressions))
     54       (ripgrep-regexp exp (file-name-as-directory (expand-file-name folder))))))
     55 
     56 (provide 'ol-ripgrep)
     57 ;;; ol-ripgrep.el ends here