rename search engine to search tool.
[org-seek.el.git] / org-searching.el
blobfc078130a0f4f7d1813d02c6520b750c730989d3
1 ;;; org-searching.el --- Searching Org-mode files with search tools.
3 ;; Author: stardiviner <numbchild@gmail.com>
4 ;; Maintainer: stardiviner <numbchild@gmail.com>
5 ;; Keywords: org search
6 ;; URL: https://github.com/stardiviner/org-searching.el
7 ;; Created: 12th Dec 2016
8 ;; Version: 0.1.0
9 ;; Package-Requires: ((emacs "24.3") (ag "0.48"))
11 ;;; Commentary:
13 ;;; Code:
14 ;;; ----------------------------------------------------------------------------
15 ;; load function `ag/read-from-minibuffer', `ag/search'
16 (require 'ag)
17 (require 'cl-lib)
19 (defgroup org-searching nil
20 "Org files searching."
21 :group 'org)
23 (defcustom org-searching-org-root-path "~/Org"
24 "The default root path of your Org-mode files."
25 :type 'string
26 :group 'org-searching)
28 (defcustom org-searching-search-tool 'ag
29 "Specify the search tool for searching.
31 The search tool can be: ag, pt, ripgrep, grep, ack."
32 :type 'symbol
33 :group 'org-searching)
36 ;;;###autoload
37 (defun org-searching-string (string directory)
38 "Full context searching STRING using ag in a given DIRECTORY.
40 By default STRING is the symbol under point unless called with a
41 prefix, prompts for flags to pass to ag."
42 (interactive
43 (list
44 (read-from-minibuffer "Search string in Org:" (thing-at-point 'symbol))
45 (read-directory-name "Directory: " (expand-file-name "~/Org"))
48 (cl-case org-searching-search-tool
49 ('ag
50 ;; (ag/search string directory :regexp nil :file-type 'org)
51 (ag/search string directory
52 :regexp nil :file-regex ".*\.org"))
53 ('pt
54 (pt-regexp string directory))
55 ('ripgrep
56 (ripgrep-regexp string directory))
60 ;;;###autoload
61 (defun org-searching-regexp (regexp directory)
62 "Full context searching REGEXP using ag in a given DIRECTORY.
64 By default REGEXP is the symbol under point unless called with a
65 prefix, prompts for flags to pass to ag."
66 (interactive
67 (list
68 (read-from-minibuffer "Search regexp in Org:" (thing-at-point 'symbol))
69 (read-directory-name "Directory: " (expand-file-name "~/Org"))
72 (cl-case org-searching-search-tool
73 ('ag
74 (ag/search regexp directory
75 :regexp nil :file-regex ".*\.org"))
76 ('pt
77 (pt-regexp regexp directory))
78 ('ripgrep
79 (ripgrep-regexp regexp directory))
83 ;;;###autoload
84 (defun org-searching-headlines (string directory)
85 "Search STRING in Org files headlines using ag in a given DIRECTORY.
87 By default STRING is the symbol under point unless called with a
88 prefix, prompts for flags to pass to ag."
89 (interactive
90 (list
91 (read-from-minibuffer "Search headlines in Org:" (thing-at-point 'symbol))
92 (read-directory-name "Directory: "
93 (expand-file-name (if current-prefix-arg "~/Org" ".")))
96 (cl-case org-searching-search-tool
97 ('ag
98 (ag/search (concat "^(\\*)+\ .*" string) directory
99 :regexp t :file-regex ".*\.org"))
100 ('pt
101 (pt-regexp (concat "^(\\*)+\ .*" string) directory))
102 ('ripgrep
103 (ripgrep-regexp (concat "^(\\*)+\ .*" string) directory))
104 ;; TODO
105 ;; ('grep
106 ;; (rgrep (concat "^(\\*)+\ .*" string) org directory))
107 ;; TODO
108 ;; ('ack
109 ;; (ack))
112 ;; the real shell command and regexp result:
113 ;; ag --file-search-regex .\*.org --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats -- \^\(\\\*\)\+.\*time .
116 ;;; ----------------------------------------------------------------------------
118 (provide 'org-searching)
120 ;;; org-searching.el ends here