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
9 ;; Package-Requires: ((emacs "24.3") (ag "0.48"))
14 ;;; ----------------------------------------------------------------------------
15 ;; load function `ag/read-from-minibuffer', `ag/search'
19 (defgroup org-searching nil
20 "Org files searching."
23 (defcustom org-searching-org-root-path
"~/Org"
24 "The default root path of your Org-mode files."
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."
33 :group
'org-searching
)
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."
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
50 ;; (ag/search string directory :regexp nil :file-type 'org)
51 (ag/search string directory
52 :regexp nil
:file-regex
".*\.org"))
54 (pt-regexp string directory
))
56 (ripgrep-regexp string directory
))
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."
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
74 (ag/search regexp directory
75 :regexp nil
:file-regex
".*\.org"))
77 (pt-regexp regexp directory
))
79 (ripgrep-regexp regexp directory
))
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."
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
98 (ag/search
(concat "^(\\*)+\ .*" string
) directory
99 :regexp t
:file-regex
".*\.org"))
101 (pt-regexp (concat "^(\\*)+\ .*" string
) directory
))
103 (ripgrep-regexp (concat "^(\\*)+\ .*" string
) directory
))
106 ;; (rgrep (concat "^(\\*)+\ .*" string) org directory))
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