From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Liu Newsgroups: gmane.emacs.help Subject: Re: narrowing considered harmful Date: Fri, 14 Jun 2013 11:54:23 +0800 Message-ID: References: <51AC4543.1000508@easy-emacs.de> <51AC4C03.7050504@easy-emacs.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1371182084 12189 80.91.229.3 (14 Jun 2013 03:54:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 14 Jun 2013 03:54:44 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 14 05:54:44 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UnL60-00032j-KT for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Jun 2013 05:54:40 +0200 Original-Received: from localhost ([::1]:57324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnL5z-00081f-VW for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Jun 2013 23:54:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnL5p-0007xU-1y for help-gnu-emacs@gnu.org; Thu, 13 Jun 2013 23:54:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UnL5o-0006u0-6q for help-gnu-emacs@gnu.org; Thu, 13 Jun 2013 23:54:28 -0400 Original-Received: from mail-pd0-f170.google.com ([209.85.192.170]:51798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnL5n-0006tb-VZ for help-gnu-emacs@gnu.org; Thu, 13 Jun 2013 23:54:28 -0400 Original-Received: by mail-pd0-f170.google.com with SMTP id x11so135647pdj.29 for ; Thu, 13 Jun 2013 20:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:face:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=eTqA9OsEio8aRYZIs7CB9QUFtKGwcpfILD7w5pCNO6I=; b=blYv3jQD8R348ZSE/y0kl5w8hhobgN/GWCT/snxtywEcMCOKHq6S+OfmbABkIlBcVr akP+6YM42UKGOtSlNsx8JOcayqxBNFy1cvDCMUFdd4D3tLvB0ZhSZNd6f0yQL5ALzyAV oSfeboI2ZtVp5zKTimKyI79Ox4pXLVKFRyTPTwcHMZ+wc0XRqq7VHxteqhknN8yh49LR OTp3fstanjcqc5iCF0LRowlINZqPyLB1GvhwSgl/FUGgRYUP+tePtcHrXVGm+ljg3cWJ KCHMCumcwJAy/qYK74I9/8IIgQmA74gwblrESqKuDlI8MMPhUGu6pv7D54y2SDtYSNTM Nj2g== X-Received: by 10.66.248.40 with SMTP id yj8mr562453pac.95.1371182066346; Thu, 13 Jun 2013 20:54:26 -0700 (PDT) Original-Received: from localhost ([61.148.242.48]) by mx.google.com with ESMTPSA id xn5sm598844pab.0.2013.06.13.20.54.22 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 13 Jun 2013 20:54:25 -0700 (PDT) Face: iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAAElBMVEUAAAAAAP+LRRP0pGC+ vr7///+7mT1iAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9cBBwMO DhglKe4AAAEsSURBVCjPbZNBboQwDEV/Cd4X9QJRThApmn0XYW+Jyf2v0m+HhqDBgiAe9rcTG7QH w/1Vn2Ar8gBb/ocywSN3qK9T3z4eFDB4eApocBpeBs1RSykoJd8gQcm8pGmHXFso3ajnmsqV0TnY DQkOfXUfN5NwaI7AWTVOyEhcu1aHmdWItHddUVUcUgUBCkitu8V6ditHVOVdqzl2EQ1ZVGTbdK0V 7cqn8vWzoU5Q/bF9Y/Y0cRU1xwkys5dJ+Dt6pBDWifcNQml8Gh2JVmPSoQzo7en0grswkxrUGYJ7 0hSxxAGr7ZMwYcHIzprpi7TENEE1xtiYxixRlCfPBsUUrwHD7uGIwATrbnODJcVrPpVn3hxiGloe m/S+z3CtuzUSMo83N4DPH+F0evwR3P4A2k+75838OKQAAAAASUVORK5CYII= In-Reply-To: (Stefan Monnier's message of "Thu, 13 Jun 2013 10:40:01 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (OS X 10.8.3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.170 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:91536 Archived-At: 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