From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: How to move by tokens when in a programming mode? Date: Fri, 18 Jun 2010 01:04:34 -0700 (PDT) Organization: http://groups.google.com Message-ID: <50b71eb0-5dca-434d-a243-79ee4d1bfa7f@j12g2000pri.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291843751 7997 80.91.229.12 (8 Dec 2010 21:29:11 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 21:29:11 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 08 22:29:07 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQRZS-0002LL-Kp for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 22:29:06 +0100 Original-Received: from localhost ([127.0.0.1]:60706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQRZR-0000Fu-RR for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 16:29:05 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!j12g2000pri.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 70 Original-NNTP-Posting-Host: 67.180.85.8 Original-X-Trace: posting.google.com 1276848274 9399 127.0.0.1 (18 Jun 2010 08:04:34 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 18 Jun 2010 08:04:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j12g2000pri.googlegroups.com; posting-host=67.180.85.8; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4, gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:179088 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:76048 Archived-At: On Jun 17, 2:49=C2=A0pm, Elena 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 =3D f (); > > the point - represented by | - would move like this: > > |double value =3D f (); > double |value =3D f (); > double value |=3D f (); > double value =3D |f (); > double value =3D f |(); > double value =3D f (|); > double value =3D 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 =E2=80=9Cparagraph=E2=80=9D dep= ending 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 =E2=80=9CUnderstanding Word Boundaries=E2=80= =9D, here: http://groups.google.com/group/gnu.emacs.help/browse_frm/thread/6fdad9a5795= b76aa/fefdf30c21d0d548 and http://xahlee.blogspot.com/2010/06/text-editors-cursor-movement-behavior.ht= ml Xah =E2=88=91 http://xahlee.org/ =E2=98=84