[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: |
Tue, 19 Sep 2006 11:07:40 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
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.
- Operate on region string, Hadron Quark, 2006/09/18
- Re: Operate on region string, Pascal Bourguignon, 2006/09/18
- Re: Operate on region string, Tassilo Horn, 2006/09/18
- Re: Operate on region string, Tassilo Horn, 2006/09/18
- Re: Operate on region string, Hadron Quark, 2006/09/18
- Re: Operate on region string, robert . thorpe, 2006/09/20