update README
[org-seek.el.git] / org-searching.el
blobf2fe94b8030900d61de6b340ceda69774501d1c4
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
9 ;; Version: 0.1.0
10 ;; Package-Requires: ((emacs "24.3") (ag "0.48"))
12 ;;; Commentary:
14 ;;; Code:
15 ;;; ----------------------------------------------------------------------------
16 ;; load function `ag/read-from-minibuffer', `ag/search'
17 (require 'ag)
18 (require 'cl-lib)
20 (defgroup org-searching nil
21 "Org files searching."
22 :group 'org)
24 (defcustom org-searching-org-root-path "~/Org"
25 "The default root path of your Org-mode files."
26 :type 'string
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."
33 :type 'symbol
34 :group 'org-searching)
37 ;;;###autoload
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."
43 (interactive
44 (list
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
50 ('ag
51 ;; (ag/search string directory :regexp nil :file-type 'org)
52 (ag/search string directory
53 :regexp nil :file-regex ".*\.org"))
54 ('pt
55 (pt-regexp string directory))
56 ('ripgrep
57 (ripgrep-regexp string directory))
61 ;;;###autoload
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."
67 (interactive
68 (list
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
74 ('ag
75 (ag/search regexp directory
76 :regexp nil :file-regex ".*\.org"))
77 ('pt
78 (pt-regexp regexp directory))
79 ('ripgrep
80 (ripgrep-regexp regexp directory))
84 ;;;###autoload
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."
90 (interactive
91 (list
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
98 ('ag
99 (ag/search (concat "^(\\*)+\ .*" string) directory
100 :regexp t :file-regex ".*\.org"))
101 ('pt
102 (pt-regexp (concat "^(\\*)+\ .*" string) directory))
103 ('ripgrep
104 (ripgrep-regexp (concat "^(\\*)+\ .*" string) directory))
105 ;; TODO
106 ;; ('grep
107 ;; (rgrep (concat "^(\\*)+\ .*" string) org directory))
108 ;; TODO
109 ;; ('ack
110 ;; (ack))
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