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

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

Re: How to do this moving in emacs?


From: anhnmncb
Subject: Re: How to do this moving in emacs?
Date: Tue, 15 Jul 2008 11:30:43 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Xah <address@hidden> writes:

> On Jul 14, 4:42 pm, anhnmncb <address@hidden> wrote:
>> 1)
>> M-f/b is for forward/backward words which is separated by non-charactor.
>> Say, -->|-->|--->|--->|
>>      foo-bar foo2-bar2
>>     |<--|<--|<---|<---
>>
>> How can I make a function to move forward/backward words which are
>> separated by space?
>> Say, ------>|-------->|
>>      foo-bar foo2-bar2
>>     |<------|<--------
>>
>> 2)
>> M-f is to forward to a word's ending, M-b is to beginning. Now I want to
>> bind M-F to forward to a word's beginning, M-B is for ending, how to
>> achieve it?
>> Say, ---->|
>>      foo   bar
>>         |<----
>
> What you want to do can be trivially done in elisp, just 3 lines
> about. You may or may not want to do it though, if you perhaps already
> understood emacs's sense...
>
> the semantic meaning of “word” in forward-word, replies on current
> mode's syntax table. Pratically, that means where forward-word put
> your cursor to, varies depending on the current mode.
>
> In almost all modes, a hyphen is a boundary of word. That's why
> forward-word stops on the hyphen. Words with hyphen are known in emacs
> as “symbol” for historical reasons (i.e. due to how lisp's keyword can
> include the hyphen char, and such entity in lisp are called symbols)
>
> But anyway, in short, to do what you want in (1), use this code:
>
> (global-set-key (kbd "M-f") 'forward-symbol)
> (global-set-key (kbd "M-b") 'backward-symbol)
>
> To do your question (2), it's more trivial. Just call (forward-word)
> twice followed by a (backward-word). e.g.
>
> (defun my-forward-word ()
>   "move cursor to beginning of next word"
>   (interactive)
>   (forward-word 2)
>   (backward-word)
> )
>
> (code untested.)
>
> For some simple useful elisp example, please see:
>  http://xahlee.org/emacs/elisp_examples.html
>
>   Xah
>http://xahlee.org/
>
>
>
Great, thank you. They work well except backward-symbol:
       Symbol's function definition is void: backward-symbol

I bind M-F to forward-symbol, M-f to forward-word, so it can be easy to 
memorize.
-- 
Regards,

  anhnmncb
 gpg key: 44A31344





reply via email to

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