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: Pascal Bourguignon
Subject: Re: Operate on region string
Date: Mon, 18 Sep 2006 13:13:26 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

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!

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!"


reply via email to

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