From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: Operate on region string Date: Mon, 18 Sep 2006 13:13:26 +0200 Organization: Informatimago Message-ID: <873bap1l7t.fsf@thalassa.informatimago.com> References: <871wq9mr5h.fsf@gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1158579673 6731 80.91.229.2 (18 Sep 2006 11:41:13 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 18 Sep 2006 11:41:13 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Sep 18 13:41:09 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GPHUT-0005R1-Sx for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Sep 2006 13:40:46 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GPHUT-0005oY-Dh for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Sep 2006 07:40:45 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 42 Original-X-Trace: individual.net nsye51LrCr7Jv+lWLNXUPQo8+9kJsvmSFauN7k7LtD6efmJaIo Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:RHxBzl9t71ltYFgBNK46YqF/BNg= Original-Xref: shelby.stanford.edu gnu.emacs.help:141827 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:37450 Archived-At: Hadron Quark writes: > Whats the "de-facto" recommended way to work on a region? > > I guess the sequence is something like > > (setq t (region-text)) > (setq t (dowork-on-text((t)))) > (replace-region(t)) > > What is the correct approach? 1- DO NOT ASSIGN to CONSTANTS! 2- Know your constants: NIL, T, the keywords [starting with ':'], and anything else declared with defconst. 3- Know your programming language and your library functions. There is no function named t [so you cannot call it with (t)], and in emacs lisp, which is a lisp-2, contrarily to scheme which is a lisp-1, it's meaning less for the operator in a form to be anything else than a symbol or a lambda expression [therefore, no ((f))]. 4- There is no region-text function in emacs. You can use buffer-substring or buffer-substring-no-properties. 5- There is no function replace-region in emacs. You can use delete-region and insert. But if you want the best performances, emacs is optimized to work in the buffers, not on strings. So if you can do it, better to directly modify the buffer: (defun my-command (start end) (interactive "r") (do-work-on-region start end)) -- __Pascal Bourguignon__ http://www.informatimago.com/ "Indentation! -- I will show you how to indent when I indent your skull!"