1 ;;; org-searching.el --- Searching Org-mode files with search engines.
2 ;;; -*- coding: utf-8 -*-
4 ;; Author: stardiviner <numbchild@gmail.com>
5 ;; Maintainer: stardiviner <numbchild@gmail.com>
6 ;; Keywords: org search
7 ;; URL: https://github.com/stardiviner/org-searching.el
8 ;; Created: 12th Dec 2016
10 ;; Package-Requires: ((emacs "24.3") (ag "0.48"))
15 ;;; ----------------------------------------------------------------------------
16 ;; load function `ag/read-from-minibuffer', `ag/search'
20 (defgroup org-searching nil
21 "Org files searching."
24 (defcustom org-searching-org-root-path
"~/Org"
25 "The default root path of your Org-mode files."
27 :group
'org-searching
)
29 (defcustom org-searching-search-engine
'ag
30 "Specify the search engine for searching.
32 The search engines can be: ag, pt, ripgrep, grep, ack."
34 :group
'org-searching
)
38 (defun org-searching-string (string directory
)
39 "Full context searching STRING using ag in a given DIRECTORY.
41 By default STRING is the symbol under point unless called with a
42 prefix, prompts for flags to pass to ag."
45 (read-from-minibuffer "Search string in Org:" (thing-at-point 'symbol
))
46 (read-directory-name "Directory: " (expand-file-name "~/Org"))
49 (cl-case org-searching-search-engine
51 ;; (ag/search string directory :regexp nil :file-type 'org)
52 (ag/search string directory
53 :regexp nil
:file-regex
".*\.org"))
55 (pt-regexp string directory
))
57 (ripgrep-regexp string directory
))
62 (defun org-searching-regexp (regexp directory
)
63 "Full context searching REGEXP using ag in a given DIRECTORY.
65 By default REGEXP is the symbol under point unless called with a
66 prefix, prompts for flags to pass to ag."
69 (read-from-minibuffer "Search regexp in Org:" (thing-at-point 'symbol
))
70 (read-directory-name "Directory: " (expand-file-name "~/Org"))
73 (cl-case org-searching-search-engine
75 (ag/search regexp directory
76 :regexp nil
:file-regex
".*\.org"))
78 (pt-regexp regexp directory
))
80 (ripgrep-regexp regexp directory
))
85 (defun org-searching-headlines (string directory
)
86 "Search STRING in Org files headlines using ag in a given DIRECTORY.
88 By default STRING is the symbol under point unless called with a
89 prefix, prompts for flags to pass to ag."
92 (read-from-minibuffer "Search headlines in Org:" (thing-at-point 'symbol
))
93 (read-directory-name "Directory: "
94 (expand-file-name (if current-prefix-arg
"~/Org" ".")))
97 (cl-case org-searching-search-engine
99 (ag/search
(concat "^(\\*)+\ .*" string
) directory
100 :regexp t
:file-regex
".*\.org"))
102 (pt-regexp (concat "^(\\*)+\ .*" string
) directory
))
104 (ripgrep-regexp (concat "^(\\*)+\ .*" string
) directory
))
107 ;; (rgrep (concat "^(\\*)+\ .*" string) org directory))
113 ;; the real shell command and regexp result:
114 ;; ag --file-search-regex .\*.org --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats -- \^\(\\\*\)\+.\*time .
117 ;;; ----------------------------------------------------------------------------
119 (provide 'org-searching
)
121 ;;; org-searching.el ends here