unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to do this moving in emacs?
@ 2008-07-14 23:42 anhnmncb
  0 siblings, 0 replies; 4+ messages in thread
From: anhnmncb @ 2008-07-14 23:42 UTC (permalink / raw)
  To: help-gnu-emacs

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
        |<----
-- 
Regards,

  anhnmncb
 gpg key: 44A31344





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to do this moving in emacs?
       [not found] <mailman.14728.1216080057.18990.help-gnu-emacs@gnu.org>
@ 2008-07-15  0:50 ` Xah
  2008-07-15  3:30   ` anhnmncb
  2008-07-19 11:04 ` Alan
  1 sibling, 1 reply; 4+ messages in thread
From: Xah @ 2008-07-15  0:50 UTC (permalink / raw)
  To: help-gnu-emacs

On Jul 14, 4:42 pm, anhnmncb <anhnm...@gmail.com> 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/^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to do this moving in emacs?
  2008-07-15  0:50 ` How to do this moving in emacs? Xah
@ 2008-07-15  3:30   ` anhnmncb
  0 siblings, 0 replies; 4+ messages in thread
From: anhnmncb @ 2008-07-15  3:30 UTC (permalink / raw)
  To: help-gnu-emacs

Xah <xahlee@gmail.com> writes:

> On Jul 14, 4:42 pm, anhnmncb <anhnm...@gmail.com> 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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to do this moving in emacs?
       [not found] <mailman.14728.1216080057.18990.help-gnu-emacs@gnu.org>
  2008-07-15  0:50 ` How to do this moving in emacs? Xah
@ 2008-07-19 11:04 ` Alan
  1 sibling, 0 replies; 4+ messages in thread
From: Alan @ 2008-07-19 11:04 UTC (permalink / raw)
  To: help-gnu-emacs

On Jul 14, 6:42 pm, anhnmncb <anhnm...@gmail.com> 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
>         |<----
> --
> Regards,
>
>   anhnmncb
>  gpg key: 44A31344

Another possibility is to evaluate

(modify-syntax-entry ?- "w")

in the buffer in which you wish to have M-F treat "-" as a word
character.

By evaluate, of course, I mean the following:

M-: (translated from <escape> :) runs the command eval-expression
  which is an interactive compiled Lisp function in `simple.el'.
It is bound to M-:, M-ESC :.
(eval-expression eval-expression-arg &optional
eval-expression-insert-value)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-19 11:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.14728.1216080057.18990.help-gnu-emacs@gnu.org>
2008-07-15  0:50 ` How to do this moving in emacs? Xah
2008-07-15  3:30   ` anhnmncb
2008-07-19 11:04 ` Alan
2008-07-14 23:42 anhnmncb

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).