[Top][All Lists]

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

Re: Search occurrences of character at point

From: John Ankarström
Subject: Re: Search occurrences of character at point
Date: Fri, 04 Aug 2017 18:42:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)


Guido Van Hoecke <> 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 ()
  (set-mark (point))
  (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

reply via email to

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