From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Herbert Euler" Newsgroups: gmane.emacs.devel Subject: Fixing rectangle operations Date: Thu, 15 Dec 2005 12:41:53 +0800 Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: sea.gmane.org 1134621856 23646 80.91.229.2 (15 Dec 2005 04:44:16 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 15 Dec 2005 04:44:16 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 15 05:44:14 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Emkwu-0004Lv-0y for ged-emacs-devel@m.gmane.org; Thu, 15 Dec 2005 05:42:36 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EmkxV-00008u-Uq for ged-emacs-devel@m.gmane.org; Wed, 14 Dec 2005 23:43:13 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Emkx4-00006f-9v for emacs-devel@gnu.org; Wed, 14 Dec 2005 23:42:46 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Emkww-0008Uv-IW for emacs-devel@gnu.org; Wed, 14 Dec 2005 23:42:45 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Emkww-0008UL-54 for emacs-devel@gnu.org; Wed, 14 Dec 2005 23:42:38 -0500 Original-Received: from [64.4.26.38] (helo=hotmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Emkz6-0006xJ-SF for emacs-devel@gnu.org; Wed, 14 Dec 2005 23:44:53 -0500 Original-Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 14 Dec 2005 20:41:53 -0800 Original-Received: from 64.4.26.200 by by112fd.bay112.hotmail.msn.com with HTTP; Thu, 15 Dec 2005 04:41:53 GMT X-Originating-IP: [202.43.217.195] X-Originating-Email: [herberteuler@hotmail.com] X-Sender: herberteuler@hotmail.com Original-To: emacs-devel@gnu.org X-OriginalArrivalTime: 15 Dec 2005 04:41:53.0886 (UTC) FILETIME=[DF59AFE0:01C60131] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:47775 Archived-At: Hello everyone, Both Emacs and Vim support operate on a rectangle region in buffer, but I think Vim handles it better. The following example comes from Vim Main Help File. Assume the content one want to insert 'very ' before 'long': This is a -!-long line short Any other long line The point is before 'long' in the first line. Vim documents that if one want to insert 'very ' before these two 'long's, it will ignore the short line. Hence the result is: This is a very long line short Any other very long line I tested this in Emacs. I set a mark at where the point is in the orignal text, and move the point to the third line, before 'long'. But M-x string-insert-rectangle yields: This is a very long line short very Any other very long line This is not good. Still, I don't think this is what I mean in most conditions, and prefer leaving short lines as what they were. I modified 'rect.el' so that rectangle operations will not operate on short lines. The only function needs to be changed is 'apply-on-rectangle'. I just add the verification of whether the rectangle covers short lines: ;; The replacement for `operate-on-rectangle' -- dv (defun apply-on-rectangle (function start end &rest args) "Call FUNCTION for each line of rectangle with corners at START, END. FUNCTION is called with two arguments: the start and end columns of the rectangle, plus ARGS extra arguments. Point is at the beginning of line when the function is called." (let (startcol startpt endcol endpt) (save-excursion (goto-char start) (setq startcol (current-column)) (beginning-of-line) (setq startpt (point)) (goto-char end) (setq endcol (current-column)) (forward-line 1) (setq endpt (point-marker)) ;; ensure the start column is the left one. (if (< endcol startcol) (let ((col startcol)) (setq startcol endcol endcol col))) ;; start looping over lines (goto-char startpt) (while (< (point) endpt) (end-of-line) ; first go to end of each line (if (>= (current-column) start) ; this simple test will avoid operating on short lines (apply function startcol endcol args)) (forward-line 1))) )) I think this is better than what Emacs does now. Regards, Guanpeng Xu _________________________________________________________________ Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/