unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to do this moving in emacs?
Date: Mon, 14 Jul 2008 17:50:33 -0700 (PDT)	[thread overview]
Message-ID: <615d3016-21d1-4568-bdfc-f581c797ce47@59g2000hsb.googlegroups.com> (raw)
In-Reply-To: mailman.14728.1216080057.18990.help-gnu-emacs@gnu.org

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/

       reply	other threads:[~2008-07-15  0:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.14728.1216080057.18990.help-gnu-emacs@gnu.org>
2008-07-15  0:50 ` Xah [this message]
2008-07-15  3:30   ` How to do this moving in emacs? anhnmncb
2008-07-19 11:04 ` Alan
2008-07-14 23:42 anhnmncb

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=615d3016-21d1-4568-bdfc-f581c797ce47@59g2000hsb.googlegroups.com \
    --to=xahlee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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).