From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hadron Quark Newsgroups: gmane.emacs.help Subject: Re: Operate on region string Date: Mon, 18 Sep 2006 14:21:08 +0200 Organization: CERN LHC - http://public.web.cern.ch/public/ Message-ID: <87u035wekr.fsf@gmail.com> References: <871wq9mr5h.fsf@gmail.com> <873bap1l7t.fsf@thalassa.informatimago.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1158583256 18811 80.91.229.2 (18 Sep 2006 12:40:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 18 Sep 2006 12:40:56 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Sep 18 14:40:55 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 1GPIQM-0003DE-H8 for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Sep 2006 14:40:34 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GPIQL-0002Ku-T5 for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Sep 2006 08:40:33 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 56 Original-X-Trace: individual.net hZSXRNLlIAzeTJRmpclNiQ4RWWiJISW3JVfi6dk8Xuy01trnL6 X-Orig-Path: news.ibm.net!news X-Face: 2h#||Cd#d%F*NCm59[_6/{1a@jy%; |j>{D~4^gKg(^i%7j0IK?+,/GmW&:CD5fEKb_! User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:doaaSMzO4e99gKwM/w06Wi171ls= Original-Xref: shelby.stanford.edu gnu.emacs.help:141832 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:37454 Archived-At: Pascal Bourguignon writes: > 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! I should have but "text"... > > 2- Know your constants: NIL, T, the keywords [starting with ':'], > and anything else declared with defconst. it was just pseudo code : but I take your point. > > 3- Know your programming language and your library functions. There > is no function named t [so you cannot call it with (t)], and in typo : see above. > 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. It really wasnt code : see above ... :-; > > 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)) this is what I wanted to know : what is the best way to "do-work-on-region"? --