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

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

Re: narrowing considered harmful


From: Leo Liu
Subject: Re: narrowing considered harmful
Date: Fri, 14 Jun 2013 11:54:23 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (OS X 10.8.3)

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 via email to

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