all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: john@ankarstrom.se (John Ankarström)
To: help-gnu-emacs@gnu.org
Subject: Re: Search occurrences of character at point
Date: Fri, 04 Aug 2017 18:42:32 +0200	[thread overview]
Message-ID: <877eyjwah3.fsf@ankarstrom.se> (raw)
In-Reply-To: <86wp6ja7ru.fsf@gmail.com> (Guido Van Hoecke's message of "Fri, 04 Aug 2017 13:31:49 +0200")

Hello!

Guido Van Hoecke <guivho@gmail.com> writes:

> I'd like a way to have the cursor sit on such a character and hit a key
> to position it at the next occurrence of said character.

Tinkering around in the *scratch* buffer, I came up with the
following function:

--8<---------------cut here---------------start------------->8---
(defun my/next-char-at-point ()
  (interactive)
  (set-mark (point))
  (deactivate-mark)
  (search-forward (format "%c" (char-after)) nil nil 2)
  (forward-char -1))
--8<---------------cut here---------------end--------------->8---

It works as you'd expect. Call it and it will bring you to the
next occurrence of the character at point. Conveniently, it will
also leave a mark at the old character.

This means that if you bind it to, say, `C-c n', you could hit
`C-c n' to go through all future occurrences of the char at
point, and then repeatedly use `C-u <space>' to pop the mark and
cycle back through the occurrences.

Pretty nifty, no?

- John



      parent reply	other threads:[~2017-08-04 16:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-04 11:31 Search occurrences of character at point Guido Van Hoecke
2017-08-04 15:37 ` Yassin Philip
2017-08-04 15:47 ` Drew Adams
2017-08-04 16:09 ` Yuri Khan
2017-08-04 17:08   ` Drew Adams
2017-08-04 18:23     ` Guido Van Hoecke
2017-08-04 16:42 ` John Ankarström [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877eyjwah3.fsf@ankarstrom.se \
    --to=john@ankarstrom.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.