aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/init/ycp-grep.el
blob: 6496c78645533b20869d3cb8b336218903608aa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;;; ycp-grep.el -- My config for search -*- lexical-binding: t -*-

;; Copyright (C) 2023 Free Software Foundation.

;; Author: Yuchen Pei <id@ypei.org>
;; Package-Requires: ((emacs "28.2"))

;; This file is part of dotfiles.

;; dotfiles is free software: you can redistribute it and/or modify it under
;; the terms of the GNU Affero General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; dotfiles is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
;; Public License for more details.

;; You should have received a copy of the GNU Affero General Public
;; License along with dotfiles.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; My config for search. Covers grep, search, isearch, occur, recoll
;; etc.

;;; Code:

;;; Some configs in `simple' are related to search
(my-package simple
  (add-hook 'next-error-hook #'which-func-update))

;;; `grep' package
(my-package grep
  (:delay 10)
  (setq grep-command "grep -inRH --color -A1 -B1 -E ")
  ;; in the form of (string . position), see docs of read-from-minibuffer
  (setq grep-find-command
        '("find . -type f -exec grep -inRH --color -A1 -B1 -E  \\{\\} +" . 52))
  (grep-apply-setting 'grep-find-template
                      "find -H <D> <X> -type f <F> -exec grep <C> -n --null -E -A1 -B1 <R> /dev/null \\{\\} +")
  (setq grep-files-aliases
        '(("all" .   "* .*")
          ("el" .    "*.el")
          ("ch" .    "*.[ch]")
          ("c" .     "*.c")
          ("cc" .    "*.cc *.cxx *.cpp *.C *.CC *.c++")
          ("cchh" .  "*.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++")
          ("hh" .    "*.hxx *.hpp *.[Hh] *.HH *.h++")
          ("h" .     "*.h")
          ("l" .     "[Cc]hange[Ll]og*")
          ("m" .     "[Mm]akefile*")
          ("tex" .   "*.tex")
          ("texi" .  "*.texi")
          ("asm" .   "*.[sS]")
          ("docs" . "*.md *.html *.rst *.org *.txt *.asciidoc *.adoc *.tex *.texi")))
  (my-keybind global-map
    "C-c r f" #'grep-find
    "C-c r g" #'grep)
  )

(my-package my-grep
  (:delay 10)
  ;; TODO: do we really need this?
  (advice-add 'grep :filter-return #'my-grep-focus-buffer)
)

(my-package isearch
  (:delay 5)
  (setq search-whitespace-regexp ".*?" ; one `setq' here to make it obvious they are a bundle
        isearch-lax-whitespace t
        isearch-regexp-lax-whitespace nil)
  (setq isearch-lazy-count t)
  (setq lazy-count-prefix-format nil)
  (setq lazy-count-suffix-format " (%s/%s)")
  (setq isearch-yank-on-move 'shift)
  (setq isearch-allow-scroll 'unlimited)
  (setq isearch-repeat-on-direction-change t)
  (define-key minibuffer-local-isearch-map (kbd "M-/") #'isearch-complete-edit)
  (my-keybind isearch-mode-map
    "C-g" #'isearch-cancel              ; instead of `isearch-abort'
    "M-/" #'isearch-complete
    "C-o" #'isearch-occur)
  )

(my-package replace
  (:delay 5)
  (add-hook 'occur-mode-hook #'hl-line-mode)
  (my-keybind occur-mode-map "t" #'toggle-truncate-lines)
  )

;;; wgrep (writable grep)
(my-package wgrep
  (:install t)
  (:delay 15)
  (setq wgrep-auto-save-buffer t)
  (setq wgrep-change-readonly-file t)
  (my-keybind grep-mode-map
    "e" #'wgrep-change-to-wgrep-mode
    "C-x C-q" #'wgrep-change-to-wgrep-mode
    "C-c C-c" #'wgrep-finish-edit))

;;; org-recoll
(my-package org-recoll
  (:delay 60)
  (my-keybind org-recoll-mode-map
    "n" #'org-next-visible-heading
    "p" #'org-previous-visible-heading
    "f" #'org-recoll-next-page
    "b" #'org-recoll-previous-page
    "<ret>" #'org-open-at-point
    "q" #'quit-window))

(provide 'ycp-grep)