GNU bug report logs - #10916
Using occur to list occurrencies of the symbol at point

Previous Next

Package: emacs;

Reported by: nisse <at> lysator.liu.se (Niels Möller)

Date: Thu, 1 Mar 2012 10:12:02 UTC

Severity: wishlist

Tags: wontfix

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 10916 in the body.
You can then email your comments to 10916 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#10916; Package emacs. (Thu, 01 Mar 2012 10:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to nisse <at> lysator.liu.se (Niels Möller):
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 01 Mar 2012 10:12:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: nisse <at> lysator.liu.se (Niels Möller)
To: bug-gnu-emacs <at> gnu.org
Subject: Using occur to list occurrencies of the symbol at point
Date: Thu, 01 Mar 2012 11:10:06 +0100
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.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10916; Package emacs. (Thu, 01 Mar 2012 10:45:02 GMT) Full text and rfc822 format available.

Message #8 received at 10916 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: nisse <at> lysator.liu.se (Niels Möller)
Cc: 10916 <at> debbugs.gnu.org
Subject: Re: bug#10916: Using occur to list occurrencies of the symbol at point
Date: Thu, 01 Mar 2012 12:42:41 +0200
> 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.

`C-u M-x occur' doesn't interpret the prefix argument as the amount of
additional context.  `C-u M-x occur' collects strings matching regexp.
It is like grep command line argument `-o --only-matching' that prints
only the matched parts of a matching line, with each such part
on a separate output line.

> Or maybe there's already some emacs function which does this and does it
> better, which I'm not aware of...

Have you tried `M-x occur M-n RET'?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10916; Package emacs. (Thu, 01 Mar 2012 12:19:02 GMT) Full text and rfc822 format available.

Message #11 received at 10916 <at> debbugs.gnu.org (full text, mbox):

From: nisse <at> lysator.liu.se (Niels Möller)
To: Juri Linkov <juri <at> jurta.org>
Cc: 10916 <at> debbugs.gnu.org
Subject: Re: bug#10916: Using occur to list occurrencies of the symbol at point
Date: Thu, 01 Mar 2012 13:18:09 +0100
Juri Linkov <juri <at> jurta.org> writes:

> `C-u M-x occur' doesn't interpret the prefix argument as the amount of
> additional context.  `C-u M-x occur' collects strings matching regexp.

I'm not following you. If I type C-u M-x occur RET gcd_hook RET, I get
an *Occur* buffer looking like this:

3 matches for "gcd_hook" in buffer: gcd.c
       :  mp_size_t gn;
       :};
       :
       :static void
     61:gcd_hook (void *p, mp_srcptr gp, mp_size_t gn,
       :	  mp_srcptr qp, mp_size_t qn, int d)
       :{
       :  struct gcd_ctx *ctx = (struct gcd_ctx *) p;
       :  MPN_COPY (ctx->gp, gp, gn);
-------
       :	}
       :      else
       :	{
       :	  /* Temporary storage n */
    209:	  n = mpn_gcd_subdiv_step (up, vp, n, gcd_hook, &ctx, tp);
       :	  if (n == 0)
       :	    goto done;
       :	}
       :    }
-------
       :	     small, or the difference is very small. Perform one
       :	     subtraction followed by one division. */
       :
       :	  /* Temporary storage n */
    253:	  n = mpn_gcd_subdiv_step (up, vp, n, &gcd_hook, &ctx, tp);
       :	  if (n == 0)
       :	    goto done;
       :	}
       :    }
-------

This is with emacs-23.2, but I think it's the same in other emacs
versions I have used. The documentation string for occur says

  Each line is displayed with NLINES lines before and after, or -NLINES
  before if NLINES is negative.
  NLINES defaults to `list-matching-lines-default-context-lines'.
  Interactively it is the prefix arg.

> Have you tried `M-x occur M-n RET'?

Now I have. Seems to give the symbol at point in recent emacs versions.
Slightly less convenient than a prefix argument, but I think that does
what I want.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10916; Package emacs. (Thu, 01 Mar 2012 12:42:01 GMT) Full text and rfc822 format available.

Message #14 received at 10916 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: nisse <at> lysator.liu.se (Niels Möller)
Cc: 10916 <at> debbugs.gnu.org
Subject: Re: bug#10916: Using occur to list occurrencies of the symbol at point
Date: Thu, 01 Mar 2012 14:28:07 +0200
> This is with emacs-23.2, but I think it's the same in other emacs
> versions I have used.

`C-u M-x occur' is a new feature in 24.1.  You can read about it in
http://bzr.sv.gnu.org/lh/emacs/trunk/annotate/head:/etc/NEWS#L968

>> Have you tried `M-x occur RET M-n RET'?
>
> Now I have. Seems to give the symbol at point in recent emacs versions.
> Slightly less convenient than a prefix argument, but I think that does
> what I want.

It's less convenient because the default value (displayed in parens)
for `occur' is not the symbol under point, but the last history element
(that is also easy to get via `M-p').  This is for historical reasons.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10916; Package emacs. (Fri, 01 Nov 2019 22:34:02 GMT) Full text and rfc822 format available.

Message #17 received at 10916 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Juri Linkov <juri <at> jurta.org>
Cc: 10916 <at> debbugs.gnu.org, Niels Möller <nisse <at> lysator.liu.se>
Subject: Re: bug#10916: Using occur to list occurrencies of the symbol at point
Date: Fri, 01 Nov 2019 23:33:26 +0100
Juri Linkov <juri <at> jurta.org> writes:

>>> Have you tried `M-x occur RET M-n RET'?
>>
>> Now I have. Seems to give the symbol at point in recent emacs versions.
>> Slightly less convenient than a prefix argument, but I think that does
>> what I want.
>
> It's less convenient because the default value (displayed in parens)
> for `occur' is not the symbol under point, but the last history element
> (that is also easy to get via `M-p').  This is for historical reasons.

If this is how the command has worked for a long time, perhaps it's
too late to change now?  In that case, I guess this is a wontfix?

Best regards,
Stefan Kangas




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10916; Package emacs. (Wed, 13 Nov 2019 21:50:02 GMT) Full text and rfc822 format available.

Message #20 received at 10916 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 10916 <at> debbugs.gnu.org,
 Niels Möller <nisse <at> lysator.liu.se>
Subject: Re: bug#10916: Using occur to list occurrencies of the symbol at point
Date: Wed, 13 Nov 2019 22:58:41 +0200
>>>> Have you tried `M-x occur RET M-n RET'?
>>>
>>> Now I have. Seems to give the symbol at point in recent emacs versions.
>>> Slightly less convenient than a prefix argument, but I think that does
>>> what I want.
>>
>> It's less convenient because the default value (displayed in parens)
>> for `occur' is not the symbol under point, but the last history element
>> (that is also easy to get via `M-p').  This is for historical reasons.
>
> If this is how the command has worked for a long time, perhaps it's
> too late to change now?  In that case, I guess this is a wontfix?

Agreed.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10916; Package emacs. (Thu, 05 Dec 2019 11:05:03 GMT) Full text and rfc822 format available.

Message #23 received at 10916 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Juri Linkov <juri <at> jurta.org>
Cc: 10916 <at> debbugs.gnu.org, Niels Möller <nisse <at> lysator.liu.se>
Subject: Re: bug#10916: Using occur to list occurrencies of the symbol at point
Date: Thu, 05 Dec 2019 12:04:36 +0100
tags 10916 + wontfix
close 10916
thanks

Juri Linkov <juri <at> jurta.org> writes:

>>>>> Have you tried `M-x occur RET M-n RET'?
>>>>
>>>> Now I have. Seems to give the symbol at point in recent emacs versions.
>>>> Slightly less convenient than a prefix argument, but I think that does
>>>> what I want.
>>>
>>> It's less convenient because the default value (displayed in parens)
>>> for `occur' is not the symbol under point, but the last history element
>>> (that is also easy to get via `M-p').  This is for historical reasons.
>>
>> If this is how the command has worked for a long time, perhaps it's
>> too late to change now?  In that case, I guess this is a wontfix?
>
> Agreed.

No further comments within 3 weeks, so I'm now closing this bug as
wontfix.

Best regards,
Stefan Kangas




Added tag(s) wontfix. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Thu, 05 Dec 2019 11:05:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 10916 <at> debbugs.gnu.org and nisse <at> lysator.liu.se (Niels Möller) Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Thu, 05 Dec 2019 11:05:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 02 Jan 2020 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 106 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.