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

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

Re: replace-regexp


From: Emanuel Berg
Subject: Re: replace-regexp
Date: Sun, 09 May 2021 09:38:41 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

>>> depending on what you need to do within your loop you
>>> might prefer to stay away from it (unless this
>>> far-reaching impact is exactly what you're looking for,
>>> obviously).
>>
>> Yeah, that I'll not use.
>
> Note that occasionally you don't really get to choose (e.g.
> with `sort-subr`, IIRC).

What about this?

(defun sort-lines-random-2 (beg end)
  (interactive "r")
  (let ((ents  (buffer-substring-no-properties beg end))
        (start (point)) )
    (delete-region beg end)
    (insert (with-temp-buffer
              (insert ents)
              (goto-char (point-min))
              (sort-subr nil
                         #'forward-line
                         #'end-of-line
                         nil nil
                         (lambda (_ __) (zerop (random 2)) ))
              (buffer-substring-no-properties (point-min) (point-max))) )
    (goto-char start) ))
(defalias 'r #'sort-lines-random-2)

;; test here:
;; aaa
;; ccc
;; bbb
;; ddd

(message "%c%c%c%c%c%c%c" 115 107 105 108 108 115 33)

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




reply via email to

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