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: Tue, 19 Sep 2006 11:07:40 +0200	[thread overview]
Message-ID: <87lkogz0kj.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: 87u035wekr.fsf@gmail.com

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

You need to learn the emacs lisp functions, notably those who work on
the buffers and on the strings.

Most of the functions that work on the buffers are actually commands
that are also bound to some keys and that you use.

For example, if you want to remove every other character in the region, 
you can do it manually with C-f C-d C-f C-d ...

You can know what functions are called when you type C-f or C-d:

    C-h k C-f
    C-h k C-d

You need to know also the current position of the cursor.  It's given
by the function point.

Then you can write a loop:

(defun delete-every-other-character (start end)
   (interactive "r")
   (goto-char start)
   (while (< (point) end)
      (forward-char 1)
      (delete-char 1)
      (setf end (1- end))))

The best, to know all these functions is to read the emacs lisp manual.


Execute these forms:

   (info "Emacs-lisp-intro") 
   (info "Elisp")

Type:

   (info "Elisp") C-x C-e 

in the buffer *scratch*

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.

  reply	other threads:[~2006-09-19  9:07 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
2006-09-18 12:21   ` Hadron Quark
2006-09-19  9:07     ` Pascal Bourguignon [this message]
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=87lkogz0kj.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).