all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: How to move by tokens when in a programming mode?
       [not found] <a383d064-eca9-4fae-a85f-99335fb42dba@w31g2000yqb.googlegroups.com>
@ 2010-06-18  8:04 ` Xah Lee
  2010-06-18  8:45 ` Andreas Politz
  1 sibling, 0 replies; 3+ messages in thread
From: Xah Lee @ 2010-06-18  8:04 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to move by tokens when in a programming mode?
       [not found] <a383d064-eca9-4fae-a85f-99335fb42dba@w31g2000yqb.googlegroups.com>
  2010-06-18  8:04 ` How to move by tokens when in a programming mode? Xah Lee
@ 2010-06-18  8:45 ` Andreas Politz
  2010-06-18 14:20   ` Marc Mientki
  1 sibling, 1 reply; 3+ messages in thread
From: Andreas Politz @ 2010-06-18  8:45 UTC (permalink / raw)
  To: help-gnu-emacs

Elena <egarrulo@gmail.com> writes:

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

Emacs does not know about tokens, but, accidentally, cc-mode has
functions c-forward-token-1 and c-forward-token-2.  You only have to
write a wrapper command for one of them.

-ap


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

* Re: How to move by tokens when in a programming mode?
  2010-06-18  8:45 ` Andreas Politz
@ 2010-06-18 14:20   ` Marc Mientki
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Mientki @ 2010-06-18 14:20 UTC (permalink / raw)
  To: help-gnu-emacs

Am 18.06.2010 10:45, schrieb Andreas Politz:
> Elena<egarrulo@gmail.com>  writes:
>
>> 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.
>
> Emacs does not know about tokens, but, accidentally, cc-mode has
> functions c-forward-token-1 and c-forward-token-2.  You only have to
> write a wrapper command for one of them.

I was not the asker but I say THANKS! This is what I looking for, too.

regards & thanks!
Marc



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

end of thread, other threads:[~2010-06-18 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <a383d064-eca9-4fae-a85f-99335fb42dba@w31g2000yqb.googlegroups.com>
2010-06-18  8:04 ` How to move by tokens when in a programming mode? Xah Lee
2010-06-18  8:45 ` Andreas Politz
2010-06-18 14:20   ` Marc Mientki

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.