Redefining (forward-word) and (backward-word)
  Home FAQ Contact Sign in
gnu.emacs.help only
 
Advanced search
POPULAR GROUPS

more...

gnu.emacs.help Profile…
 Up
Redefining (forward-word) and (backward-word)         


Author: troelskn
Date: May 4, 2008 08:08

Hi list,
I have been using Emacs for some time now, but there is one thing
about the cursor-movement that bothers me and I haven't found a way to
hack around it. I'm sure someone else have tried this before, but I'm
at loss at what to google for, to find it. So, does anybody at this
list know, or have an idea about how, to achieve the following:

First, assume Emacs' default cursor-movement (The | character is the
cursor-position):
|lorem ipsum dolor sit amet
(forward-word)
lorem| ipsum dolor sit amet
(forward-word)
lorem ipsum| dolor sit amet
(backward-word)
lorem |ipsum dolor sit amet
Show full article (0.95Kb)
3 Comments
Re: Redefining (forward-word) and (backward-word)         


Date: May 4, 2008 10:56

troelskn gmail.com> writes:
> So basically, my-forward-word moves the cursor forward, until it
> reaches a word-boundary.

(defun my-forward-word (&optional arg)
(interactive "p")
(dotimes (n arg)
(goto-char (1+ (point)))
(re-search-forward "\\b" nil t)))

--
Johan Bockgård
no comments
Re: Redefining (forward-word) and (backward-word)         


Author: Andreas Röhler
Date: May 5, 2008 01:33

Am Sonntag, 4. Mai 2008 19:56 schrieb Johan Bockgård:
> (defun my-forward-word (&optional arg)
>   (interactive "p")
>   (dotimes (n arg)
>     (goto-char (1+ (point)))
>     (re-search-forward "\\b" nil t)))

Great, thanks!

So let's give them still an appropriate name and make it move
backward too.

(defun next-word-boundary (&optional arg)
"Move point forward arg word boundaries (backward if arg is negative)"
(interactive "p")
(if (< 0 arg)
(dotimes (n arg)
(goto-char (1+ (point)))
(re-search-forward "\\b" nil t))
(dotimes (n (abs arg))
(goto-char (1- (point)))
(re-search-backward "\\b" nil t))))
Show full article (0.68Kb)
no comments
Re: Redefining (forward-word) and (backward-word)         


Author: troelskn
Date: May 5, 2008 02:02

On 4 Maj, 19:56, bojohan+n...@dd.chalmers.se (Johan Bockgård) wrote:
> troelskn gmail.com> writes:
>> So basically, my-forward-word moves the cursor forward, until it
>> reaches a word-boundary.
>
> (defun my-forward-word (&optional arg)
>   (interactive "p")
>   (dotimes (n arg)
>     (goto-char (1+ (point)))
>     (re-search-forward "\\b" nil t)))
>

Exactly what I was trying to accomplish. Thanks a bunch!

--
troels
no comments