From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Steven Degutis Newsgroups: gmane.emacs.help Subject: Re: Is there an easier way to jump to the same word? Date: Thu, 11 Apr 2013 09:13:40 -0500 Message-ID: References: <87mwt5wl0m.fsf@bzg.ath.cx> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8ff1c33ab3064d04da1664bf X-Trace: ger.gmane.org 1365689638 10684 80.91.229.3 (11 Apr 2013 14:13:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Apr 2013 14:13:58 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: Bastien Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 11 16:14:02 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UQIGF-0000Qh-O8 for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Apr 2013 16:13:59 +0200 Original-Received: from localhost ([::1]:59445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQIGF-00024j-AK for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Apr 2013 10:13:59 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56496) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQIG0-00024J-Q3 for help-gnu-emacs@gnu.org; Thu, 11 Apr 2013 10:13:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQIFx-0001Vh-8p for help-gnu-emacs@gnu.org; Thu, 11 Apr 2013 10:13:44 -0400 Original-Received: from mail-pb0-f42.google.com ([209.85.160.42]:39229) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQIFx-0001VX-3A for help-gnu-emacs@gnu.org; Thu, 11 Apr 2013 10:13:41 -0400 Original-Received: by mail-pb0-f42.google.com with SMTP id up7so882332pbc.1 for ; Thu, 11 Apr 2013 07:13:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=Q7QHbhTVYZONBwO3/zh6y9+QyqmpMshDTgGBWhF2ttw=; b=rGOwfm+aPTBc+QUmKzdJBtQusK3yY6r2TwYCdvCS/sB8uEsGn7BY3DPO/hEInY94tq b2cpM4PMFKCuD7VAZ/SBIcCLlo8D4F8USZwlsAJTe0mrW1/pFVzb70tSGu0Grn7DwhRd jkXSkqk8+UAXYbhACY1FL8jojjZex3HedYgdYnbwsxR1wTDKGpeNzq6i9JipKgL601YK 1DPNbwxbhCGEM1ARZNIXmYvnLKUHkqQclMYFgLvLD2cmqaHBQVZz2QguLI5g8S09iBUK tvZtbufBiu+HWxUfM/wmy1COqld/P/eImcdOkonKVsE61DsboiGKfXRjPtKE9S+tANzz NyWA== X-Received: by 10.68.211.161 with SMTP id nd1mr9259550pbc.59.1365689620393; Thu, 11 Apr 2013 07:13:40 -0700 (PDT) Original-Received: by 10.70.24.197 with HTTP; Thu, 11 Apr 2013 07:13:40 -0700 (PDT) In-Reply-To: <87mwt5wl0m.fsf@bzg.ath.cx> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.42 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:90102 Archived-At: --e89a8ff1c33ab3064d04da1664bf Content-Type: text/plain; charset=ISO-8859-1 Are these functions defining word boundaries? What are the \\< and \\> used for? Using (current-word) should probably be sufficient, no? Also, I didn't realize this until after I tried Chris's solution, but I also need it to highlight other occurrences of (current-word) in the buffer. -Steven On Thu, Apr 11, 2013 at 3:04 AM, Bastien wrote: > Hi Steven, > > Steven Degutis writes: > > > Is there a better way to do this? > > I use this: > > (defun next-word-at-point (previous) > "Jump to the next occurrence of the word at point." > (interactive "P") > (let* ((w (thing-at-point 'word)) > (w (mapconcat > (lambda(c) (if (eq (char-syntax c) ?w) > (char-to-string c))) w "")) > (wre (concat "\\<" w "\\>")) > (s (if previous #'re-search-backward #'re-search-forward))) > (unless previous (forward-word 1)) > (funcall s wre nil t) > (unless previous (re-search-backward wre nil t)))) > > (defun previous-word-at-point () > "Jump to the previous occurrence of the word at point." > (interactive) > (next-word-at-point t)) > > (define-key global-map "\M-n" 'next-word-at-point) > (define-key global-map "\M-p" 'previous-word-at-point) > > -- > Bastien > --e89a8ff1c33ab3064d04da1664bf Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Are these functions defining word boundaries? What are the= \\< and \\> used for? Using (current-word) should probably be suffic= ient, no?

Also, I didn't realize this until after I = tried Chris's solution, but I also need it to highlight other occurrenc= es of (current-word) in the buffer.

-Steven

On Thu, Apr 11, 2013 at 3:04 AM, Bastien <bzg= @altern.org> wrote:
Hi Steven,

Steven Degutis <sbdegutis@gmail.c= om> writes:

> Is there a better way to do this?

I use this:

(defun next-word-at-point (previous)
=A0 "Jump to the next occurrence of the word at point."
=A0 (interactive "P")
=A0 (let* ((w (thing-at-point 'word))
=A0 =A0 =A0 =A0 =A0(w (mapconcat
=A0 =A0 =A0 =A0 =A0 =A0 =A0(lambda(c) (if (eq (char-syntax c) ?w)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (char-to-string c))= ) w ""))
=A0 =A0 =A0 =A0 =A0(wre (concat "\\<" w "\\>")) =A0 =A0 =A0 =A0 =A0(s (if previous #'re-search-backward #'re-search= -forward)))
=A0 =A0 (unless previous (forward-word 1))
=A0 =A0 (funcall s wre nil t)
=A0 =A0 (unless previous (re-search-backward wre nil t))))

(defun previous-word-at-point ()
=A0 "Jump to the previous occurrence of the word at point."
=A0 (interactive)
=A0 (next-word-at-point t))

(define-key global-map "\M-n" 'next-word-at-point)
(define-key global-map "\M-p" 'previous-word-at-point)

--
=A0Bastien

--e89a8ff1c33ab3064d04da1664bf--