unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Pascal Bourguignon <pjb@informatimago.com>
Subject: Re: Operate on region string
Date: Mon, 18 Sep 2006 13:13:26 +0200	[thread overview]
Message-ID: <873bap1l7t.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: 871wq9mr5h.fsf@gmail.com

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

  parent reply	other threads:[~2006-09-18 11:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-18  9:59 Operate on region string Hadron Quark
2006-09-18 10:37 ` Tassilo Horn
2006-09-18 12:28   ` Hadron Quark
2006-09-18 12:55     ` Tassilo Horn
2006-09-18 15:24       ` Hadron Quark
2006-09-20 10:14         ` robert.thorpe
2006-09-18 13:02     ` Mathias Dahl
2006-09-18 13:10       ` Hadron Quark
2006-09-19 22:20         ` John Sullivan
2006-09-18 11:13 ` Pascal Bourguignon [this message]
2006-09-18 12:21   ` Hadron Quark
2006-09-19  9:07     ` Pascal Bourguignon
2006-10-14 22:23       ` David Combs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873bap1l7t.fsf@thalassa.informatimago.com \
    --to=pjb@informatimago.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).