unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Redefining (forward-word) and (backward-word)
@ 2008-05-04 15:08 troelskn
  2008-05-04 17:56 ` Johan Bockgård
  0 siblings, 1 reply; 4+ messages in thread
From: troelskn @ 2008-05-04 15:08 UTC (permalink / raw)
  To: help-gnu-emacs

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

What I would like instead, is this:
|lorem ipsum dolor sit amet
(my-forward-word)
lorem| ipsum dolor sit amet
(my-forward-word)
lorem |ipsum dolor sit amet
(my-backward-word)
lorem| ipsum dolor sit amet

So basically, my-forward-word moves the cursor forward, until it
reaches a word-boundary.

Any ideas?

--
troels

lorem ipsum dolor sit amet


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

* Re: Redefining (forward-word) and (backward-word)
  2008-05-04 15:08 Redefining (forward-word) and (backward-word) troelskn
@ 2008-05-04 17:56 ` Johan Bockgård
  2008-05-05  8:33   ` Andreas Röhler
  2008-05-05  9:02   ` troelskn
  0 siblings, 2 replies; 4+ messages in thread
From: Johan Bockgård @ 2008-05-04 17:56 UTC (permalink / raw)
  To: help-gnu-emacs

troelskn <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


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

* Re: Redefining (forward-word) and (backward-word)
  2008-05-04 17:56 ` Johan Bockgård
@ 2008-05-05  8:33   ` Andreas Röhler
  2008-05-05  9:02   ` troelskn
  1 sibling, 0 replies; 4+ messages in thread
From: Andreas Röhler @ 2008-05-05  8:33 UTC (permalink / raw)
  To: help-gnu-emacs

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

Andreas Röhler




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

* Re: Redefining (forward-word) and (backward-word)
  2008-05-04 17:56 ` Johan Bockgård
  2008-05-05  8:33   ` Andreas Röhler
@ 2008-05-05  9:02   ` troelskn
  1 sibling, 0 replies; 4+ messages in thread
From: troelskn @ 2008-05-05  9:02 UTC (permalink / raw)
  To: help-gnu-emacs

On 4 Maj, 19:56, bojohan+n...@dd.chalmers.se (Johan Bockgård) wrote:
> troelskn <troel...@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


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

end of thread, other threads:[~2008-05-05  9:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-04 15:08 Redefining (forward-word) and (backward-word) troelskn
2008-05-04 17:56 ` Johan Bockgård
2008-05-05  8:33   ` Andreas Röhler
2008-05-05  9:02   ` troelskn

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