help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Operate on region string


From: Hadron Quark
Subject: Re: Operate on region string
Date: Mon, 18 Sep 2006 14:21:08 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Pascal Bourguignon <pjb@informatimago.com> writes:

> Hadron Quark <hadronquark@gmail.com> 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"?



-- 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]