* Search occurrences of character at point
@ 2017-08-04 11:31 Guido Van Hoecke
2017-08-04 15:37 ` Yassin Philip
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Guido Van Hoecke @ 2017-08-04 11:31 UTC (permalink / raw)
To: Emacs
Hi,
I sometimes have to edit some text where I want to find all occurences
of some non-standard character, such as Char: (173, #o255, #xad, ...)
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.
I'm sure there's a way to do this?
Any ideas, anyone?
TIA,
Guido
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Search occurrences of character at point
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
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Yassin Philip @ 2017-08-04 15:37 UTC (permalink / raw)
To: Emacs
Well, you could use a rx regexp function like this:
(defun find-nonascii ()
(interactive)
(if (re-search-forward (rx nonascii))
(message "There it is: (%s)"
(buffer-substring-no-properties
(match-beginning 0) (match-end 0)))
(message "doh!")))
yPhil
On 04/08/17 12:31, Guido Van Hoecke wrote:
> Hi,
>
> I sometimes have to edit some text where I want to find all occurences
> of some non-standard character, such as Char: (173, #o255, #xad, ...)
>
> 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.
>
> I'm sure there's a way to do this?
>
> Any ideas, anyone?
>
> TIA,
>
> Guido
>
--
Yassin Philip New album NOW
http://yassinphilip.bitbucket.io
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Search occurrences of character at point
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 16:42 ` John Ankarström
3 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2017-08-04 15:47 UTC (permalink / raw)
To: Guido Van Hoecke, Emacs
> I sometimes have to edit some text where I want to find all occurences
> of some non-standard character, such as Char: (173, #o255, #xad, ...)
>
> 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.
>
> I'm sure there's a way to do this?
1. `M-s o' (command `occur'), followed by typing `[' followed
by typing or pasting the character, followed by typing `]'.
E.g., `M-s o [w]' shows occurrences of character `w'.
After typing `[' you can also use `C-x RET' followed by
typing the code point or the Unicode name of the character
(followed by typing `]').
`M-s o' shows matches for a regexp. A regexp of a character
enclosed in `[...]' matches that character.
2. `occur' shows the matches in a separate buffer, where
you can navigate among them. This is slightly different
from what you request, which is to hit a key to immediately
go to the next occurrence.
To do that, just use `C-s' (`isearch-forward')
followed by typing the character. Repeat `C-s' to go to
subsequent occurrences of the character. Again, instead
of typing the character you can use `C-x RET' followed by
typing the code point or the Unicode name of the character.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Search occurrences of character at point
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 16:42 ` John Ankarström
3 siblings, 1 reply; 7+ messages in thread
From: Yuri Khan @ 2017-08-04 16:09 UTC (permalink / raw)
To: Guido Van Hoecke; +Cc: Emacs
On Fri, Aug 4, 2017 at 6:31 PM, Guido Van Hoecke <guivho@gmail.com> wrote:
> I sometimes have to edit some text where I want to find all occurences
> of some non-standard character, such as Char: (173, #o255, #xad, ...)
>
> 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.
>
> I'm sure there's a way to do this?
C-s (isearch-forward) C-M-y (isearch-yank-char)?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Search occurrences of character at point
2017-08-04 11:31 Search occurrences of character at point Guido Van Hoecke
` (2 preceding siblings ...)
2017-08-04 16:09 ` Yuri Khan
@ 2017-08-04 16:42 ` John Ankarström
3 siblings, 0 replies; 7+ messages in thread
From: John Ankarström @ 2017-08-04 16:42 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Search occurrences of character at point
2017-08-04 16:09 ` Yuri Khan
@ 2017-08-04 17:08 ` Drew Adams
2017-08-04 18:23 ` Guido Van Hoecke
0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2017-08-04 17:08 UTC (permalink / raw)
To: Yuri Khan, Guido Van Hoecke; +Cc: Emacs
> C-s (isearch-forward) C-M-y (isearch-yank-char)?
Yes, of course. This is the best answer (`C-s C-M-y').
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Search occurrences of character at point
2017-08-04 17:08 ` Drew Adams
@ 2017-08-04 18:23 ` Guido Van Hoecke
0 siblings, 0 replies; 7+ messages in thread
From: Guido Van Hoecke @ 2017-08-04 18:23 UTC (permalink / raw)
To: Drew Adams, keith; +Cc: Emacs, Yuri Khan
Thank you all for your help
On 4 August 2017 at 19:08, Drew Adams <drew.adams@oracle.com> wrote:
> > C-s (isearch-forward) C-M-y (isearch-yank-char)?
>
> Yes, of course. This is the best answer (`C-s C-M-y').
>
It seems that both `C-s C-M-y' and `C-s C-w' do the job, where C-M-w can
than be used to remove the last selected character(s)
Wish you all a nice weekend,
Guido
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-08-04 18:23 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).