Merge branch 'release/0.1.1'
[org-seek.el.git] / org-seek.el
blob0079a7c58b522f616277e493dc37f061d095d0b8
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
8 ;; Version: 0.1.1
9 ;; Package-Requires: ((emacs "24.3") (ag "0.48"))
11 ;;; Commentary:
13 ;; You need to install at least one of searching tools: ag, pt, grep etc.
15 ;;; Code:
16 ;;; ----------------------------------------------------------------------------
17 ;; load function `ag/read-from-minibuffer', `ag/search'
18 (require 'ag)
19 (require 'cl-lib)
21 (defgroup org-seek nil
22 "Org files searching."
23 :group 'org)
25 (defcustom org-seek-org-root-path org-directory
26 "The default root path of your Org-mode files."
27 :type 'string
28 :group 'org-seek)
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."
34 :type 'symbol
35 :group 'org-seek)
38 (autoload 'ag/search "ag")
39 (autoload 'pt-regexp "pt")
40 (autoload 'ripgrep-regexp "ripgrep")
42 ;;;###autoload
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."
48 (interactive
49 (list
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
55 ('ag
56 ;; (ag/search string directory :regexp nil :file-type 'org)
57 (ag/search string directory
58 :regexp nil :file-regex ".*\.org"))
59 ('pt
60 (pt-regexp string directory))
61 ('ripgrep
62 (ripgrep-regexp string directory))
66 ;;;###autoload
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."
72 (interactive
73 (list
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
79 ('ag
80 (ag/search regexp directory
81 :regexp nil :file-regex ".*\.org"))
82 ('pt
83 (pt-regexp regexp directory))
84 ('ripgrep
85 (ripgrep-regexp regexp directory))
89 ;;;###autoload
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."
95 (interactive
96 (list
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
103 ('ag
104 (ag/search (concat "^(\\*)+\ .*" string) directory
105 :regexp t :file-regex ".*\.org"))
106 ('pt
107 (pt-regexp (concat "^(\\*)+\ .*" string) directory))
108 ('ripgrep
109 (ripgrep-regexp (concat "^(\\*)+\ .*" string) directory))
110 ;; TODO
111 ;; ('grep
112 ;; (rgrep (concat "^(\\*)+\ .*" string) org directory))
113 ;; TODO
114 ;; ('ack
115 ;; (ack))
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 ;;; ----------------------------------------------------------------------------
124 (provide 'org-seek)
126 ;;; org-seek.el ends here