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

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

Re: Emacs 30.0 warning from `cl-pushnew' and `memql'


From: Emanuel Berg
Subject: Re: Emacs 30.0 warning from `cl-pushnew' and `memql'
Date: Wed, 28 Dec 2022 14:19:20 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

tomas wrote:

> I see. Well, that train has sailed (or something).
> Backward compat (especially with user's brains) and things.

One  can also think of `equal' for lists, instead of `eql',
as, as you know

  (equal '(1 2 3) '(1 2 3)) ; t
  (eql   '(1 2 3) '(1 2 3)) ; nil

Here is one example of that.

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

(require 'cl-lib)
(require 'math)

(defun string-distance-percentage (str1 str2 &optional str-out)
  (let*((len1 (length str1))
        (len2 (length str2))
        (long (max len1 len2))
        (dist (string-distance str1 str2)) )
    (percent (- long dist) long str-out) ))

(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 fallout
     do (setq hit (buffer-substring-no-properties c (+ c len)))
        (cl-pushnew (list hit
                          (string-distance hit str)
                          (string-distance-percentage str hit t) )
                    fallout :test #'equal)
     finally return
       (message "%s"
         (seq-take (sort fallout (lambda (a b) (< (cadr a) (cadr b)))) 5) )))

(defalias 'psea #'pattern-search)

;; (psea "history" (point-min) (+ 100 (point-min)))
;;
;; his fil  4  42.9%
;; amp.org  5  28.6%
;; this fi  5  28.6%
;; /psea.e  6  14.3%
;; nit/pse  6  14.3%

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




reply via email to

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