emacs-devel
[Top][All Lists]
Advanced

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

Re: save-excursion and the mark


From: Andreas Röhler
Subject: Re: save-excursion and the mark
Date: Wed, 25 Feb 2015 14:05:30 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.4.0

On 25.02.2015 13:35, Ivan Shmakov wrote:
Andreas Röhler <address@hidden> writes:
On 25.02.2015 03:59, Stefan Monnier wrote:

  >>> See for example indent-code-ridigly.

  >> Can you give more details about how this requires save&restore of
  >> the mark (or its "active" status)?

  > Think a shifting code by TAB in python-mode.

        FWIW, python.el doesn’t seem to use the mark.

  > Mark might exist somewhere in line. Shifting will use its own region
  > – but original region should be restored – if any.  Shifting by
  > itself should not create a region nor clutter the mark-ring.

        There seem to be a misunderstanding; the notion of /Emacs Lisp/
        region is different to that of /Emacs/ region, the former being
        (more or less) a way of saying “from here to there”, and
        does /not/ (generally) involve either mark or point.

        For instance, indent-code-ridigly can be used from Lisp like:

    (indent-code-ridigly 13 37)

        Or perhaps:

    (when-let ((here  (re-search-backward "START" nil t))
               (there (re-search-forward  "END"   nil t)))
      (indent-code-ridigly here there))

        With the common idiom being:

    (let ((save (point)))
      ; Move point forward, by some amount.
      (indent-code-ridigly save (point)))

        As should be obvious, the mark is /not/ involved in either case.
        And, arguably, it /should not/ be.

[…]

  > commit b1d6ddd44614c84746f5ee494e1f29cd9be8a2d8

  > Notable changes to goto-line, i. e. calling push-mark.

        That makes a point, indeed: there’s a class of Emacs commands
        intended first and foremost for interactive use.  Naturally,
        goto-line is one of them; to quote its docstring:

This function is for interactive use only;
in Lisp code use `forward-line' instead.

        The proposed change to save-excursion would expose the bugs in
        the code which uses such commands inside of save-excursion,
        which now masks the unfortunate side-effects of such (mis)use.


Okay, thanks.

Andreas



reply via email to

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