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

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

Re: Is there an easier way to jump to the same word?


From: Steven Degutis
Subject: Re: Is there an easier way to jump to the same word?
Date: Thu, 11 Apr 2013 09:13:40 -0500

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 <bzg@altern.org> wrote:
Hi Steven,

Steven Degutis <sbdegutis@gmail.com> 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


reply via email to

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