From a9627518a51f5dc536fa22629a2da680dbc052d1 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 12 Jun 2023 19:37:49 +1000 Subject: first commit --- .emacs.d/init/ycp-grep.el | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 .emacs.d/init/ycp-grep.el (limited to '.emacs.d/init/ycp-grep.el') diff --git a/.emacs.d/init/ycp-grep.el b/.emacs.d/init/ycp-grep.el new file mode 100644 index 0000000..715f643 --- /dev/null +++ b/.emacs.d/init/ycp-grep.el @@ -0,0 +1,125 @@ +;;; ycp-grep.el -- My config for search -*- lexical-binding: t -*- + +;; Copyright (C) 2023 Free Software Foundation. + +;; Author: Yuchen Pei +;; Protesilaos Stavrou +;; Maintainer: Yuchen Pei +;; 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 . + +;;; Commentary: + +;; My config for search. Covers grep, search, isearch, occur, recoll +;; etc. + +;;; Code: + + +;;; `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 -type f -exec grep -n --null -E -A1 -B1 /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-keybind global-map + "C-s" 'isearch-forward-regexp + "C-r" 'isearch-backward-regexp) + ) + +(my-package replace + (:delay 5) + (add-hook 'occur-mode-hook #'hl-line-mode) + (my-keybind occur-mode-map "t" #'toggle-truncate-lines) + ) + + +;;; `xref' package +(my-package xref + ;; All those have been changed for Emacs 28 + (setq xref-show-definitions-function #'xref-show-definitions-completing-read) ; for M-. + (setq xref-show-xrefs-function #'xref-show-definitions-buffer) + ) + +;;; 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 + "" #'org-open-at-point + "q" #'quit-window)) + +(provide 'ycp-grep) -- cgit v1.2.3