From: nisse@lysator.liu.se (Niels Möller)
To: 10916@debbugs.gnu.org
Subject: bug#10916: Using occur to list occurrencies of the symbol at point
Date: Thu, 01 Mar 2012 11:10:06 +0100 [thread overview]
Message-ID: <nnaa40ocn5.fsf@stalhein.lysator.liu.se> (raw)
Hi,
I'm using both M-x grep and M-x occur quite a lot. I have been a bit
annoyed that they interpret a prefix argument very differently. With C-u
M-x grep, it searches for the symbol (or word or tag; I'm not sure
exactly how it's delimited) under point, which is a feature I find very
useful.
I first expected C-u M-x occur to behave the same way, but instead it
interprets the prefix argument as the amount of additional context to
include in the output buffer. This is a feature I don't need very often.
I'm not sure it's a good idea to change the behaviour of M-x occur, so
instead I wrote the following function to do what I want:
(defun occur-tag (regexp nlines)
(interactive
(let ((tag (funcall (or find-tag-default-function
(get major-mode 'find-tag-default-function)
'find-tag-default))))
(if tag
(list (concat "\\_<" (regexp-quote tag) "\\_>")
(when current-prefix-arg
(prefix-numeric-value current-prefix-arg)))
(occur-read-primary-args))))
(occur regexp nlines))
It gets the symbol under point in the same way as M-x grep, and
constructs a regexp to use with occur. I this it mainly for searching in
source files, which is why I use \_< and \_> rather than \< and \> when
constructing the regexp.
Maybe it would make sense to add something like this to emacs, either as
a separate function like above, or in response to an "empty" prefix
argument to M-x occur.
Or maybe there's already some emacs function which does this and does it
better, which I'm not aware of...
BTW, I think it would also make some sense with a helper function for
the logic involving find-tag-default-function, since this seems to be
duplicated in find-tag-tag, complete-tag, grep-tag-default, and possibly
other places. Or movee it inside find-tag-default, if those variables
always should be consulted.
Best regards,
/Niels Möller
--
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
next reply other threads:[~2012-03-01 10:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-01 10:10 Niels Möller [this message]
2012-03-01 10:42 ` bug#10916: Using occur to list occurrencies of the symbol at point Juri Linkov
2012-03-01 12:18 ` Niels Möller
2012-03-01 12:28 ` Juri Linkov
2019-11-01 22:33 ` Stefan Kangas
2019-11-13 20:58 ` Juri Linkov
2019-12-05 11:04 ` Stefan Kangas
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=nnaa40ocn5.fsf@stalhein.lysator.liu.se \
--to=nisse@lysator.liu.se \
--cc=10916@debbugs.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).