From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: john@ankarstrom.se (John =?utf-8?Q?Ankarstr=C3=B6m?=) Newsgroups: gmane.emacs.help Subject: Re: Search occurrences of character at point Date: Fri, 04 Aug 2017 18:42:32 +0200 Message-ID: <877eyjwah3.fsf@ankarstrom.se> References: <86wp6ja7ru.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1501865025 16379 195.159.176.226 (4 Aug 2017 16:43:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 4 Aug 2017 16:43:45 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 04 18:43:40 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddfhI-0003qQ-BS for geh-help-gnu-emacs@m.gmane.org; Fri, 04 Aug 2017 18:43:36 +0200 Original-Received: from localhost ([::1]:57778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddfhO-0006mp-7s for geh-help-gnu-emacs@m.gmane.org; Fri, 04 Aug 2017 12:43:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddfgN-0006k4-DU for help-gnu-emacs@gnu.org; Fri, 04 Aug 2017 12:42:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddfgK-0006Rp-GV for help-gnu-emacs@gnu.org; Fri, 04 Aug 2017 12:42:39 -0400 Original-Received: from pusjkin.ankarstrom.se ([172.104.152.215]:56514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddfgK-0006PV-7R for help-gnu-emacs@gnu.org; Fri, 04 Aug 2017 12:42:36 -0400 Original-Received: from vm-linux (c83-252-75-131.bredband.comhem.se [83.252.75.131]) by pusjkin.ankarstrom.se (Postfix) with ESMTPSA id F1D0D3F351 for ; Fri, 4 Aug 2017 18:42:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ankarstrom.se; s=default; t=1501864953; bh=+/UJbOcnnEN9j7+NrL+5cj+gSaC/MV54A23CCpHtCAY=; h=From:To:Subject:References:Date:In-Reply-To:From; b=EKBTiTlVU0D5ag7k7dPYqIM4dyDOx8kjvLbsVSk3mpsW4YUqFbgksAB/Lzbs+yMmc 1Qw2FG9/ke0lrVrxcD8Gac2ToiId0qaQ54UbDxc97K/rOHrxTMUlceEW0x9k4Xh6cG SaOz8VfGn4SgRBZC2XhK1R25JCtCItMEfc6Lz8lU= In-Reply-To: <86wp6ja7ru.fsf@gmail.com> (Guido Van Hoecke's message of "Fri, 04 Aug 2017 13:31:49 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 172.104.152.215 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.help:113927 Archived-At: Hello! 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 () (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 ' to pop the mark and cycle back through the occurrences. Pretty nifty, no? - John