all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Leo Liu <sdl.web@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: narrowing considered harmful
Date: Fri, 14 Jun 2013 11:54:23 +0800	[thread overview]
Message-ID: <m1ppvpqrdc.fsf@gmail.com> (raw)
In-Reply-To: <jwv38smf56b.fsf-monnier+gnu.emacs.help@gnu.org> (Stefan Monnier's message of "Thu, 13 Jun 2013 10:40:01 -0400")

On 2013-06-13 22:40 +0800, Stefan Monnier wrote:
> I tend to consider narrow-to-region in Elisp as a problem,so I encourage
> you to write your code without it.
>
> In your example, you don't need to narrow: the only thing you need is
> to keep the "end" updated when the buffer is modified, which is easy to
> do by changing the "end" form an integer to a marker.
>
> Or alternatively, you can simply work your way backward, in which case
> you don't need to worry about using a marker since the "start" position
> to which you're going won't be affected by the buffer modifications.

Do you think it is a good idea to add a macro along these lines:

(defmacro with-markers (markerlist &rest body)
  "Execute BODY with markers in MARKERLIST bound.
Each element of MARKERLIST is a symbol (which is bound to a
marker pointing to nowhere) or a list (SYMBOL EXPR) (which binds
SYMBOL to a marker pointing to the value of EXPR)."
  (declare (indent 1) (debug (sexp body)))
  `(let ,(mapcar (lambda (m)
                   (let ((m (if (listp m)
                                m
                              (list m))))
                     `(,(car m) (copy-marker ,(cadr m)))))
                 markerlist)
     (unwind-protect
         (progn ,@body)
       ,@(mapcar (lambda (m)
                   (let ((m (or (car-safe m) m)))
                     `(and (markerp ,m) (set-marker ,m nil))))
                 markerlist))))

Leo



  reply	other threads:[~2013-06-14  3:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-03  5:43 putting double quotes efficiently C K Kashyap
2013-06-03  7:26 ` Andreas Röhler
2013-06-03  7:55   ` Andreas Röhler
2013-06-03  8:03     ` C K Kashyap
2013-06-03  9:10       ` Andreas Röhler
2013-06-03 11:52         ` C K Kashyap
     [not found]       ` <mailman.918.1370250440.22516.help-gnu-emacs@gnu.org>
2013-06-13 14:40         ` narrowing considered harmful (was: putting double quotes efficiently) Stefan Monnier
2013-06-14  3:54           ` Leo Liu [this message]
2013-06-14 13:00             ` narrowing considered harmful Stefan Monnier
2013-06-14 16:51               ` Leo Liu
2013-06-15  2:43                 ` Stefan Monnier
2013-06-16 16:42                   ` Leo Liu
2013-06-17 14:56                     ` Stefan Monnier
2013-06-17 15:20                       ` Drew Adams
2013-06-17 16:48                         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1ppvpqrdc.fsf@gmail.com \
    --to=sdl.web@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.