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

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

Re: How to move by tokens when in a programming mode?


From: Xah Lee
Subject: Re: How to move by tokens when in a programming mode?
Date: Wed, 08 Dec 2010 15:14:50 -0000
User-agent: G2/1.0

On Jun 17, 2:49 pm, Elena <egarr...@gmail.com> wrote:
> Hello,
>
> is there some elisp code to move by tokens when a programming mode is
> active? For instance, in the following C code:
>
> double value = f ();
>
> the point - represented by | - would move like this:
>
> |double value = f ();
> double |value = f ();
> double value |= f ();
> double value = |f ();
> double value = f |();
> double value = f (|);
> double value = f ()|;
>
> Thanks.


it is easy to write a elisp code to do what you want, though, might be
tedious dependens on what you mean by token, and whether you really
want the cursor to move by token. (might be too many stops)

here's a function i wrote and have been using it for a couple of
years. You can mod it to get what u want. Basically that's the idea.
But depending what you mean by token, might be tedious to get it
right.

(defun forward-block ()
  "Move cursor forward to next occurrence of double newline char.
In most major modes, this is the same as `forward-paragraph', however,
this function behaves the same in any mode.
forward-paragraph is mode dependent, because it depends on
syntax table that has different meaning for “paragraph” depending on
mode."
  (interactive)
  (skip-chars-forward "\n")
  (when (not (search-forward-regexp "\n[[:blank:]]*\n" nil t))
    (goto-char (point-max)) ) )

(defun backward-block ()
  "Move cursor backward to previous occurrence of double newline char.
See: `forward-block'"
  (interactive)
  (skip-chars-backward "\n")
  (when (not (search-backward-regexp "\n[[:blank:]]*\n" nil t))
    (goto-char (point-min))
    )
  )

actually, you can just mod it so that it always just skip syntax
classes that's white space... but then if you have 1+1+8 that'll skip
the whole thing...

see the recent related thread “Understanding Word Boundaries”, here:
http://groups.google.com/group/gnu.emacs.help/browse_frm/thread/6fdad9a5795b76aa/fefdf30c21d0d548

and
http://xahlee.blogspot.com/2010/06/text-editors-cursor-movement-behavior.html

  Xah
∑ http://xahlee.org/

reply via email to

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