help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [External] : Re: How to grep for a string spanning multiple lines?


From: Emanuel Berg
Subject: Re: [External] : Re: How to grep for a string spanning multiple lines?
Date: Tue, 29 Nov 2022 03:00:28 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Like this maybe?

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/psea.el

(require 'cl-lib)

(defun pattern-search (str &optional beg end)
  (interactive `(,(read-string "search: ")
                 ,@(when (use-region-p)
                     (list (region-beginning)
                           (region-end) ))))
  (or beg (setq beg (point-min)))
  (or end (setq end (point-max)))
  (cl-loop
     with len = (length str)
     for c from beg to (- end len)
     with hit
     with hit-dist
     with best
     with best-dist = len
     do (setq hit (buffer-substring-no-properties c (+ c len)))
        (setq hit-dist (string-distance hit str))
        (when (< hit-dist best-dist)
          (setq best hit)
          (setq best-dist hit-dist) )
     finally (message "%s" (list best best-dist)) ))

(defalias 'psea #'pattern-search)

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]