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

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

Re: save-excursion doesn't save point?


From: Paul Stoeber
Subject: Re: save-excursion doesn't save point?
Date: Sat, 8 Jun 2002 09:28:43 +0200
User-agent: Mutt/1.3.28i

On Sat, Jun 08, 2002 at 07:01:30AM +0000, Miles Bader wrote:
> address@hidden (Paul Stoeber) writes:
> > ;; Point has changed, but shuffle-lines has only one body form, which
> > ;; is a save-excursion form.  Is that supposed to happen?
> 
> Yes.
> 
> save-excursion doesn't work by saving a character number, but setting a
> marker at the old point-location, and restoring to the marker later.
> 
> If you insert or delete text adjacent to a marker, it will end up shoved
> to one side or the other -- and transpose-lines works by deleting and
> inserting.
> 
> -Miles
> -- 
> [|nurgle|]  ddt- demonic? so quake will have an evil kinda setting? one that 
>             will  make every christian in the world foamm at the mouth? 
> [iddt]      nurg, that's the goal 
> 
> _______________________________________________
> Bug-gnu-emacs mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-gnu-emacs

Thank you very much.

I use shuffle-lines to shuffle my music playlist.
It could be generally useful.  Emacs already has shuffle-vector.


(defun shuffle-lines (beg end)
  "Randomly permute lines in region (all permutations equally likely)."
  (interactive "r")
  (let ((pt (point)) (mk (mark)) (n (count-lines beg end)))
    (goto-char beg)
    (while (> n 1)
      (let ((r (random n)))
        (if (zerop r);; special case for transpose-lines
            nil
          (set-mark (point))
          (next-line r)
          (transpose-lines 0)))
      (next-line 1)
      (setq n (1- n)))
    (goto-char pt)
    (set-mark mk)))


---

We beg your acceptance of this elegant thimble.
                -- Dodo



reply via email to

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