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

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

Re: re-make-list


From: tomas
Subject: Re: re-make-list
Date: Mon, 10 Feb 2020 07:58:20 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Mon, Feb 10, 2020 at 06:11:25AM +0100, Emanuel Berg via Users list for the 
GNU Emacs text editor wrote:
> Make a list of regexp matches... perhaps
> already in Emacs/ELPA/Joe Hacker's stash/etc?
> 
> Improvements AND comment look like this:
> 
> ;; improvement
> 
> ha ha :)
> 
> ;; this file: https://dataswamp.org/~incal/emacs-init/re-make-list.el
> 
> (defun re-make-list (re &optional start stop)
>   (interactive
>    (if (use-region-p)
>        (list (region-beginning) (region-end))
>      (list (point-min) (point-max)) ))
>   (save-excursion
>     (let ((matches ()))
>       (goto-char start)
>       (while (re-search-forward re stop t)
>         (push (match-string-no-properties 0) matches) )
>       matches) ))

[...]

If you don't mind the matches being returned in reverse order, that's
fine. Otherwise you might consider returning (reverse matches).

In your case, since you build a fresh list which nobody else sees,
you might get away returning (nreverse matches) without the Functional
Gods frowning at you ;-)

Cheers
-- t

Attachment: signature.asc
Description: Digital signature


reply via email to

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