From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: C K Kashyap Newsgroups: gmane.emacs.help Subject: Re: narrow-to-region for a rectangle Date: Wed, 5 Jun 2013 12:04:30 +0530 Message-ID: References: <87k3ma6ocm.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1370414089 18835 80.91.229.3 (5 Jun 2013 06:34:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Jun 2013 06:34:49 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Jambunathan K Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 05 08:34: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 1Uk7Iy-0007BE-17 for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Jun 2013 08:34:44 +0200 Original-Received: from localhost ([::1]:40333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uk7Ix-0000gI-HY for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Jun 2013 02:34:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uk7In-0000fz-8Y for help-gnu-emacs@gnu.org; Wed, 05 Jun 2013 02:34:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uk7Il-00025n-GQ for help-gnu-emacs@gnu.org; Wed, 05 Jun 2013 02:34:33 -0400 Original-Received: from mail-qe0-f45.google.com ([209.85.128.45]:47200) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uk7Il-00025f-BO for help-gnu-emacs@gnu.org; Wed, 05 Jun 2013 02:34:31 -0400 Original-Received: by mail-qe0-f45.google.com with SMTP id q19so809729qeb.4 for ; Tue, 04 Jun 2013 23:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=HpAiKQVqwbgCFEnIkAjPEhYQ3iSFs6F5X5f9tSWgOQA=; b=oYIKw9fVfgXas9W5y20RPx8ld3bIgDU27NLYrOrxCDZ70k0xWWbu4Ln0Lgyxs5vU3n GV6tGr9eC3ja39DhlORRKCT9WsW37PCWxpc4CoJf114IoQpqgActQRRQkkDqC5LK8Emk DYOP705e1ghNmggXC36oA3VJfxzLdVQ4qNrSu8XhVPpk7idf9af3m0HWct7duflr2EZV 94fSizjao6v1aDFMILdpEoQE8ImZYVVDPjQosjaPtX+FnqJMzaNOz/muWNqL06zIehhv G39Bk+evbQo7Vvcjl1lydtbO6z2D22WhCGwZP35JHQV8/OjiHISLbMQFQUYJTYihw5Tp nDLw== X-Received: by 10.224.58.199 with SMTP id i7mr26081954qah.35.1370414070849; Tue, 04 Jun 2013 23:34:30 -0700 (PDT) Original-Received: by 10.229.160.147 with HTTP; Tue, 4 Jun 2013 23:34:30 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.45 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 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:91313 Archived-At: This is what I've come up with. I'd really appreciate some feedback. (defun k-quotes (beg end st en) (interactive "r*\nsStart Pattern: \nsEnd Pattern: \n") (save-excursion (save-restriction (string-rectangle beg end st) (move-end-of-line nil) (setq newEnd (point)) (goto-char beg) (replace-regexp "$" en nil beg newEnd) (replace-regexp (concat en "$") "") ))) Regards, Kashyap On Tue, Jun 4, 2013 at 6:23 PM, C K Kashyap wrote: > The function below takes in a region and surrounds each line with input > strings - > > (defun k-quotes (beg end st en) > (interactive "r*\nsStart Pattern: \nsEnd Pattern: \n") > (save-excursion > (save-restriction > (narrow-to-region beg end) > (goto-char beg) > (replace-regexp "\\(.*\\)" (concat st "\\1" en)) > ))) > > I'd like this function to be able to restrict to a rectangle instead of a > region. While on the first line it restricts "^" to match whereever I > started the mark from - on the rest of the lines, its the beginning of the > line. > > Regards, > Kashyap > > > On Tue, Jun 4, 2013 at 6:10 PM, Jambunathan K wrote: > >> C K Kashyap writes: >> >> > Hi, >> > Is there a function that restricts the modifiable area to the rectangle >> > rather than the region? >> >> If such a thing is available, what will you do with it? Give an >> example. >> >> > Regards, >> > Kashyap >> > >