1 ;;; org-seek.el --- Searching Org-mode files with search tools.
3 ;; Author: stardiviner <numbchild@gmail.com>
4 ;; Maintainer: stardiviner <numbchild@gmail.com>
5 ;; Keywords: org search ag pt
6 ;; URL: https://github.com/stardiviner/org-seek.el
7 ;; Created: 12th Dec 2016
9 ;; Package-Requires: ((emacs "24.3") (ag "0.48"))
13 ;; You need to install at least one of searching tools: ag, pt, grep etc.
16 ;;; ----------------------------------------------------------------------------
17 ;; load function `ag/read-from-minibuffer', `ag/search'
21 (defgroup org-seek nil
22 "Org files searching."
25 (defcustom org-seek-org-root-path org-directory
26 "The default root path of your Org-mode files."
30 (defcustom org-seek-search-tool
'ag
31 "Specify the search tool for searching.
33 The search tool can be: ag, pt, ripgrep, grep, ack."
38 (autoload 'ag
/search
"ag")
39 (autoload 'pt-regexp
"pt")
40 (autoload 'ripgrep-regexp
"ripgrep")
43 (defun org-seek-string (string directory
)
44 "Full context searching STRING using ag in a given DIRECTORY.
46 By default STRING is the symbol under point unless called with a
47 prefix, prompts for flags to pass to ag."
50 (read-from-minibuffer "Search string in Org:" (thing-at-point 'symbol
))
51 (read-directory-name "Directory: " (expand-file-name org-seek-org-root-path
))
54 (cl-case org-seek-search-tool
56 ;; (ag/search string directory :regexp nil :file-type 'org)
57 (ag/search string directory
58 :regexp nil
:file-regex
".*\.org"))
60 (pt-regexp string directory
))
62 (ripgrep-regexp string directory
))
67 (defun org-seek-regexp (regexp directory
)
68 "Full context searching REGEXP using ag in a given DIRECTORY.
70 By default REGEXP is the symbol under point unless called with a
71 prefix, prompts for flags to pass to ag."
74 (read-from-minibuffer "Search regexp in Org:" (thing-at-point 'symbol
))
75 (read-directory-name "Directory: " (expand-file-name org-seek-org-root-path
))
78 (cl-case org-seek-search-tool
80 (ag/search regexp directory
81 :regexp nil
:file-regex
".*\.org"))
83 (pt-regexp regexp directory
))
85 (ripgrep-regexp regexp directory
))
90 (defun org-seek-headlines (string directory
)
91 "Search STRING in Org files headlines using ag in a given DIRECTORY.
93 By default STRING is the symbol under point unless called with a
94 prefix, prompts for flags to pass to ag."
97 (read-from-minibuffer "Search headlines in Org:" (thing-at-point 'symbol
))
98 (read-directory-name "Directory: "
99 (expand-file-name (if current-prefix-arg org-seek-org-root-path
".")))
102 (cl-case org-seek-search-tool
104 (ag/search
(concat "^(\\*)+\ .*" string
) directory
105 :regexp t
:file-regex
".*\.org"))
107 (pt-regexp (concat "^(\\*)+\ .*" string
) directory
))
109 (ripgrep-regexp (concat "^(\\*)+\ .*" string
) directory
))
112 ;; (rgrep (concat "^(\\*)+\ .*" string) org directory))
118 ;; the real shell command and regexp result:
119 ;; ag --file-search-regex .\*.org --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats -- \^\(\\\*\)\+.\*time .
122 ;;; ----------------------------------------------------------------------------
126 ;;; org-seek.el ends here