75 lines
2.4 KiB
EmacsLisp
Executable File
75 lines
2.4 KiB
EmacsLisp
Executable File
;;; syd-search.el --- Description -*- lexical-binding: t; -*-
|
|
;;
|
|
;; Copyright (C) 2025 Madeleine Sydney
|
|
;;
|
|
;; Author: Madeleine Sydney <lomiskiam@gmail.com>
|
|
;; Maintainer: Madeleine Sydney <lomiskiam@gmail.com>
|
|
;; Created: January 12, 2025
|
|
;; Modified: January 12, 2025
|
|
;; Version: 0.0.1
|
|
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex text tools unix vc
|
|
;; Homepage: https://github.com/crumb/syd-search
|
|
;; Package-Requires: ((emacs "24.3"))
|
|
;;
|
|
;; This file is not part of GNU Emacs.
|
|
;;
|
|
;;; Commentary:
|
|
;;
|
|
;; Description
|
|
;;
|
|
;;; Code:
|
|
|
|
(cl-defun syd-search-region (beg end &key initial)
|
|
(save-restriction
|
|
(narrow-to-region beg end)
|
|
(consult-line initial)))
|
|
|
|
(defun syd-search--escape-regexp (str)
|
|
(require 'syd-text)
|
|
(replace-regexp-in-string " " "\\\\ "
|
|
(syd-pcre-quote str)))
|
|
|
|
(defun syd-search-buffer (buffer)
|
|
"Conduct a text search on BUFFER.
|
|
|
|
If a selection is active and multi-line, perform a search restricted to that
|
|
region.
|
|
|
|
If a selection is active and not multi-line, use the selection as the initial
|
|
input and search the whole buffer for it."
|
|
(interactive (list (current-buffer)))
|
|
(save-restriction
|
|
(let* ((beg (region-beginning))
|
|
(end (region-end))
|
|
(multiline-p (/= (line-number-at-pos beg)
|
|
(line-number-at-pos end))))
|
|
(if (and beg end (region-active-p))
|
|
(progn (deactivate-mark)
|
|
(if multiline-p
|
|
(syd-search-region beg end)
|
|
;; Treat as a single pattern, not several
|
|
;; space-separated patterns.
|
|
(consult-line (syd-search--escape-regexp
|
|
(buffer-substring-no-properties beg end)))))
|
|
(consult-line)))))
|
|
|
|
;;;###autoload
|
|
(defun syd-search-directory (dir)
|
|
(interactive (list (read-directory-name
|
|
"Search directory: "
|
|
default-directory nil t)))
|
|
(cond ((executable-find "rg")
|
|
(consult-ripgrep dir))
|
|
((executable-find "grep")
|
|
(message "Couldn't find ripgrep; using grep")
|
|
(consult-grep dir))))
|
|
|
|
;;;###autoload
|
|
(defun syd-search-current-directory ()
|
|
(interactive)
|
|
(syd-search-directory default-directory))
|
|
|
|
|
|
(provide 'syd-search)
|
|
;;; syd-search.el ends here
|