Commit 4c0e04ee0e5f

Vincent Demeester <vincent@sbr.pm>
2020-03-11 18:32:13
Extract rg: and grep: to their own library ol-* 🔗
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 850cddb
config/setup-org.el
@@ -310,6 +310,10 @@
   :after (org))
 (use-package ol-gitlab
   :after (org))
+(use-package ol-ripgrep
+  :after (org))
+(use-package ol-grep
+  :after (org))
 
 ;; built-in org-mode
 (use-package ol-eshell
@@ -496,39 +500,6 @@ Switch projects and subprojects from STARTED back to TODO"
 With prefix argument, also display headlines without a TODO keyword."
     (org-tags-view (null current-prefix-arg) tag))
 
-  (org-link-set-parameters "grep"
-                           :follow #'vde/follow-grep-link
-                           :face '(:foreground "DarkRed" :underline t))
-  (defun vde/follow-grep-link (regexp)
-    "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))))
-    )
-
-  (org-link-set-parameters "rg"
-                           :follow #'vde/follow-rg-link
-                           :face '(:foreground "DarkGreen" :underline t))
-  (defun vde/follow-rg-link (regexp)
-    "Run `ripgrep-regexp` with REXEP and FOLDER as argument,
-like this : [[pt: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)))))
-    )
-
   (org-link-set-parameters
    "org"
    :complete (lambda () (+org-link-read-file "org" org-directory))
lisp/ol-grep.el
@@ -0,0 +1,54 @@
+;;; ol-grep.el --- Links to Grep -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020 Vincent Demeester
+
+;; Author: Vincent Demeester <vincent@sbr.pm>
+;; Keywords: org link grep
+;;
+;; 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
lisp/ol-ripgrep.el
@@ -0,0 +1,53 @@
+;;; ol-ripgrep.el --- Links to Ripgrep -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020 Vincent Demeester
+
+;; Author: Vincent Demeester <vincent@sbr.pm>
+;; Keywords: org link ripgrep
+;;
+;; 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
+
+;;; Code:
+
+(require 'ol)
+
+;; Install the link type
+(org-link-set-parameters "rg"
+                         :follow #'org-ripgrep-follow-link
+                         :face '(:foreground "DarkGreen" :underline t))
+
+(defun org-ripgrep-follow-link (issue)
+  "Run `ripgrep-regexp` with REXEP and FOLDER as argument,
+like this : [[pt: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
emacs.org
@@ -686,7 +686,7 @@
 /The =ensure org-plus-contrib= is there to make sure I am loading the =org= module from my
 nix configuration and not the built-in =org= module (that might lag in terms of version)/
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgMain" :range-end "-OrgMain" :lines "25-88"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgMain" :range-end "-OrgMain" :lines "25-89"
 
 I've set-up an =org-mode= hook to add few modes to the default setup.
 - I am really annoyed by trailing white-space so I want them to be shown
@@ -695,15 +695,15 @@
   + I turn on =auto-revert-mode= so that the buffer is always up-to-date.
   + I like to have header indented, so I'm enabling =org-indent-mode=.
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgHook" :range-end "-OrgHook" :lines "91-100"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgHook" :range-end "-OrgHook" :lines "92-101"
 
 Let's also use =org-id=…
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgId" :range-end "-OrgId" :lines "103-132"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgId" :range-end "-OrgId" :lines "104-133"
 
 … and =org-crypt= (for encrypted =org-mode= files).
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCrypt" :range-end "-OrgCrypt" :lines "135-140"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCrypt" :range-end "-OrgCrypt" :lines "136-141"
 
 *** TODO Agenda
 :PROPERTIES:
@@ -730,11 +730,11 @@
 agenda views. This allows to group things and overall set-up the agenda view I want. This
 agenda view uses the =n= key.
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgAgenda" :range-end "-OrgAgenda" :lines "143-180"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgAgenda" :range-end "-OrgAgenda" :lines "144-181"
 
 Let's try to get my work calendar entries in my agenda too. It is a little bit tricky 👼.
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgGcal" :range-end "-OrgGcal" :lines "183-197"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgGcal" :range-end "-OrgGcal" :lines "184-198"
 
 *** Habits                                                         :ATTACH:
 :PROPERTIES:
@@ -767,14 +767,14 @@
 
 [[att:2020-02-29-14-41-59.png]]
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgHabit" :range-end "-OrgHabit" :lines "200-205"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgHabit" :range-end "-OrgHabit" :lines "201-206"
 
 *** TODO Sources
 :PROPERTIES:
 :CUSTOM_ID: h:82c3b800-9d80-408d-b3b6-54dc15b0590c
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgSrc" :range-end "-OrgSrc" :lines "208-215"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgSrc" :range-end "-OrgSrc" :lines "209-216"
 
 *** TODO Capture
 :PROPERTIES:
@@ -791,7 +791,7 @@
 options. This is very interesting when you want to group some capture template together
 (like templates related to /work/, …).
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureStart" :range-end "-OrgCaptureStart" :lines "218-222"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureStart" :range-end "-OrgCaptureStart" :lines "219-223"
 #+begin_src emacs-lisp
 (use-package org-capture
   :after org
@@ -805,7 +805,7 @@
 Here is a list of my templates:
 - Default :: /I need to rework those/
 
-  #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureOldTemplate" :range-end "-OrgCaptureOldTemplate" :lines "225-244"
+  #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureOldTemplate" :range-end "-OrgCaptureOldTemplate" :lines "226-245"
 
 - journaling :: As I use =org-mode= for my /journal/ too, I need capture entry for
   it. I currently have two types of journal entry :
@@ -813,61 +813,61 @@
 
     #+INCLUDE: "etc/orgmode/journal.org" src org
 
-    #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureJournal" :range-end "-OrgCaptureJournal" :lines "247-252"
+    #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureJournal" :range-end "-OrgCaptureJournal" :lines "248-253"
 
   + worklog: related to work, to be able to say what I did, what I wanted to do, problems,
     … during the daily
 
     #+INCLUDE: "etc/orgmode/worklog.org" src org
 
-    #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureWorklog" :range-end "-OrgCaptureWorklog" :lines "255-260"
+    #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureWorklog" :range-end "-OrgCaptureWorklog" :lines "256-261"
 
 - weekly review :: each and every week, I am going through this item to make my review of
   the week.
 
   #+INCLUDE: "etc/orgmode/weekly.org" src org
 
-  #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureWeekly" :range-end "-OrgCaptureWeekly" :lines "263-268"
+  #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureWeekly" :range-end "-OrgCaptureWeekly" :lines "264-269"
 
 - blog posts ::
 
-  #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureBlog" :range-end "-OrgCaptureBlog" :lines "271-281"
+  #+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureBlog" :range-end "-OrgCaptureBlog" :lines "272-282"
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureEnd" :range-end "-OrgCaptureEnd" :lines "284-285"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgCaptureEnd" :range-end "-OrgCaptureEnd" :lines "285-286"
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgProtocol" :range-end "-OrgProtocol" :lines "288-290"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgProtocol" :range-end "-OrgProtocol" :lines "289-291"
 
 *** TODO Clocking
 :PROPERTIES:
 :CUSTOM_ID: h:264afe05-79e3-4bff-aafc-9fc726c4034b
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgClock" :range-end "-OrgClock" :lines "293-299"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgClock" :range-end "-OrgClock" :lines "294-300"
 
 *** TODO Links
 :PROPERTIES:
 :CUSTOM_ID: h:afc81fbb-f7a0-401c-8b56-19f51edebd88
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgAttach" :range-end "-OrgAttach" :lines "302-305"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgAttach" :range-end "-OrgAttach" :lines "303-306"
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgLinks" :range-end "-OrgLinks" :lines "308-329"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgLinks" :range-end "-OrgLinks" :lines "309-334"
 
 *** TODO Litterate programming
 :PROPERTIES:
 :CUSTOM_ID: h:b5f6beba-6195-4ff0-a194-502ac2a9e3da
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgBabel" :range-end "-OrgBabel" :lines "332-340"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgBabel" :range-end "-OrgBabel" :lines "337-345"
 
 *** TODO Exporting
 :PROPERTIES:
 :CUSTOM_ID: h:afad00e0-367c-4c7b-b191-e3ed72be754b
 :END:
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgExportConstants" :range-end "-OrgExportConstants" :lines "343-345"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgExportConstants" :range-end "-OrgExportConstants" :lines "348-350"
 
-#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgExportCfg" :range-end "-OrgExportCfg" :lines "348-359"
+#+INCLUDE: "./config/setup-org.el" src emacs-lisp :range-begin "OrgExportCfg" :range-end "-OrgExportCfg" :lines "353-364"
 
 ** TODO Email and newsgroup
 :PROPERTIES:
@@ -1239,4 +1239,8 @@
 
   #+INCLUDE: lisp/ol-gitlab.el src emacs-lisp
 
-More to comes…
+- ~ol-ripgrep.el~: link to a =ripgrep= search buffer.
+
+  #+INCLUDE: lisp/ol-ripgrep.el src emacs-lisp
+
+And that's all folks 💃