all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Occur should use the region as input if it's active
@ 2014-01-16 18:55 Tom
  2014-01-16 19:23 ` Drew Adams
  2014-01-17  0:52 ` Tak Kunihiro
  0 siblings, 2 replies; 8+ messages in thread
From: Tom @ 2014-01-16 18:55 UTC (permalink / raw)
  To: emacs-devel

If often happens to me that I'm perusing a buffer and I want to 
search for some word or phrase in it. To do this I simply select the 
text and use this code to instantly get occur matches of it:

    (defun my-occur ()
      (interactive)
      (if (use-region-p)
          (occur (buffer-substring-no-properties
                  (region-beginning) (region-end)))
        (call-interactively 'occur)))

Shouldn't the builtin occur do this? It's quite convenient and
efficient and in my experience most of the occur searches are
of these kind (searching for something I see) and it's less
often that I actualy need to type in the search term.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Occur should use the region as input if it's active
  2014-01-16 18:55 Occur should use the region as input if it's active Tom
@ 2014-01-16 19:23 ` Drew Adams
  2014-01-16 19:32   ` Tom
  2014-01-16 19:36   ` Drew Adams
  2014-01-17  0:52 ` Tak Kunihiro
  1 sibling, 2 replies; 8+ messages in thread
From: Drew Adams @ 2014-01-16 19:23 UTC (permalink / raw)
  To: Tom, emacs-devel

> If often happens to me that I'm perusing a buffer and I want to
> search for some word or phrase in it. To do this I simply select the
> text and use this code to instantly get occur matches of it:
> 
>     (defun my-occur ()
>       (interactive)
>       (if (use-region-p)
>           (occur (buffer-substring-no-properties
>                   (region-beginning) (region-end)))
>         (call-interactively 'occur)))
> 
> Shouldn't the builtin occur do this? It's quite convenient and
> efficient and in my experience most of the occur searches are
> of these kind (searching for something I see) and it's less
> often that I actualy need to type in the search term.

Yes and no.  The region can also be useful to delimit the
search without narrowing.

FWIW, in my code, a user option decides this:

,----
| search/replace-region-as-default-flag is a variable defined in `replace+.el'.
| Its value is nil
| 
| Documentation:
| Non-nil means use the active region text as default for search/replace.
| That is, if the region is currently active then use its text as the
| default input.  All text properties are removed from the text.
| 
| Note that in this case the active region is not used to limit the
| search/replacement scope.  But in that case you can of course just
| narrow the buffer temporarily to restrict the operation scope.
| 
| A non-nil value of this option takes precedence over the use of option
| `search/replace-2nd-sel-as-default-flag'.  To give that option
| precedence over using the active region, you can set this option to
| nil and use `region-or-non-nil-symbol-name-nearest-point' as the value
| of option `search/replace-default-fn'.
| 
| You can customize this variable.
`----



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Occur should use the region as input if it's active
  2014-01-16 19:23 ` Drew Adams
@ 2014-01-16 19:32   ` Tom
  2014-01-16 19:51     ` Drew Adams
  2014-01-16 19:36   ` Drew Adams
  1 sibling, 1 reply; 8+ messages in thread
From: Tom @ 2014-01-16 19:32 UTC (permalink / raw)
  To: emacs-devel

Drew Adams <drew.adams <at> oracle.com> writes:
> 
> Yes and no.  The region can also be useful to delimit the
> search without narrowing.

I don't think it's really that useful for occur. Occur
is usually used to find matches in a larger text. If you
want to limit the search to a smaller region then you
can already use isearch which hihighlights the additional
matches or simply use narrowing.

If a configuration option like this is added then
its default value should be using the active region for
search because in my experience I use it very often and 
I only occasionally need to limit the search to a region
which I can already do with narrowing.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Occur should use the region as input if it's active
  2014-01-16 19:23 ` Drew Adams
  2014-01-16 19:32   ` Tom
@ 2014-01-16 19:36   ` Drew Adams
  2014-01-16 20:11     ` Tom
  1 sibling, 1 reply; 8+ messages in thread
From: Drew Adams @ 2014-01-16 19:36 UTC (permalink / raw)
  To: Tom, emacs-devel

> > in my experience most of the occur searches are
> > of these kind (searching for something I see) and it's less
> > often that I actualy need to type in the search term.
> 
> Yes and no.  The region can also be useful to delimit the
> search without narrowing.
> 
> FWIW, in my code, a user option decides this:

I should also have added, with reference to your point about
searching for something you see, that with this option turned
off the default input is the name of the (non-nil) symbol
nearest point.

That, plus the usefulness of using the region to delimit the
search, is the reason that searching for the region text by
default is turned off by default.

In addition, if you use Icicles then you can use `M-.' in the
minibuffer anytime to insert text near point from the buffer.
Repeating `M-.' gives you different "things" from the buffer
or it accumulates successive things of the same type from the
buffer.  So `M-.' gives you a way to pick up more than just
the nearest symbol from the buffer.

All of that confirms that I agree with you that most of the
time one wants to search for text (typically nearby) seen in
the buffer.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Occur should use the region as input if it's active
  2014-01-16 19:32   ` Tom
@ 2014-01-16 19:51     ` Drew Adams
  0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2014-01-16 19:51 UTC (permalink / raw)
  To: Tom, emacs-devel

> > Yes and no.  The region can also be useful to delimit the
> > search without narrowing.
> 
> I don't think it's really that useful for occur.

I let the user decide.

> Occur is usually used to find matches in a larger text.
> If you want to limit the search to a smaller region then you
> can already use isearch which hihighlights the additional
> matches or simply use narrowing.

The latter, yes.  Isearch is not the same as `occur'.

> If a configuration option like this is added then
> its default value should be using the active region for
> search because in my experience I use it very often and
> I only occasionally need to limit the search to a region
> which I can already do with narrowing.

The same argument could be made for (my) option
`search/replace-2nd-sel-as-default-flag', which uses the
secondary selection as default.  (The default value for both
options is nil.)

(FWIW, my `grep' code behaves a bit differently.  There, a
usable region is always used as the default search pattern.)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Occur should use the region as input if it's active
  2014-01-16 19:36   ` Drew Adams
@ 2014-01-16 20:11     ` Tom
  2014-01-17  8:11       ` Juri Linkov
  0 siblings, 1 reply; 8+ messages in thread
From: Tom @ 2014-01-16 20:11 UTC (permalink / raw)
  To: emacs-devel

Drew Adams <drew.adams <at> oracle.com> writes:
> 
> I should also have added, with reference to your point about
> searching for something you see, that with this option turned
> off the default input is the name of the (non-nil) symbol
> nearest point.
> 
> That, plus the usefulness of using the region to delimit the
> search, is the reason that searching for the region text by
> default is turned off by default.

Picking up the symbol around the cursor is a good idea, so for occur 
it would be a good default to use the symbol around the cursor if there
is no region active and use the region for search if it's active.

Limiting search with the region is infrequently needed and it can
easily be done with narrowing. The above two features are much
more useful and they can be used much more frequently (quickly
picking an input for occur), so they should take precedence.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Occur should use the region as input if it's active
  2014-01-16 18:55 Occur should use the region as input if it's active Tom
  2014-01-16 19:23 ` Drew Adams
@ 2014-01-17  0:52 ` Tak Kunihiro
  1 sibling, 0 replies; 8+ messages in thread
From: Tak Kunihiro @ 2014-01-17  0:52 UTC (permalink / raw)
  To: emacs-devel, adatgyujto; +Cc: tkk

I think that is a good idea and should be build in with following two
lines. With this, isearch and occur get closer.

  (isearch-mode t)
  (isearch-update-ring (setq isearch-string (buffer-substring-no-properties
                   (region-beginning) (region-end))))


> Date: Thu, 16 Jan 2014 18:55:48 +0000 (UTC)
> From: Tom <adatgyujto@gmail.com>
> To: emacs-devel@gnu.org
> Subject: Occur should use the region as input if it's active
> Message-ID: <loom.20140116T194740-227@post.gmane.org>
> Content-Type: text/plain; charset=us-ascii
> 
> If often happens to me that I'm perusing a buffer and I want to 
> search for some word or phrase in it. To do this I simply select the 
> text and use this code to instantly get occur matches of it:
> 
>     (defun my-occur ()
>       (interactive)
>       (if (use-region-p)
>           (occur (buffer-substring-no-properties
>                   (region-beginning) (region-end)))
>         (call-interactively 'occur)))
> 
> Shouldn't the builtin occur do this? It's quite convenient and
> efficient and in my experience most of the occur searches are
> of these kind (searching for something I see) and it's less
> often that I actualy need to type in the search term.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Occur should use the region as input if it's active
  2014-01-16 20:11     ` Tom
@ 2014-01-17  8:11       ` Juri Linkov
  0 siblings, 0 replies; 8+ messages in thread
From: Juri Linkov @ 2014-01-17  8:11 UTC (permalink / raw)
  To: Tom; +Cc: emacs-devel

> Picking up the symbol around the cursor is a good idea, so for occur
> it would be a good default to use the symbol around the cursor if there
> is no region active and use the region for search if it's active.

This can be implemented with 1-line patch:

=== modified file 'lisp/replace.el'
--- lisp/replace.el	2013-12-20 20:31:30 +0000
+++ lisp/replace.el	2014-01-17 08:11:03 +0000
@@ -658,6 +658,7 @@ (defun read-regexp-suggestions ()
 appends the list returned by this function to the end of values available
 via \\<minibuffer-local-map>\\[next-history-element]."
   (list
+   (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)))
    (find-tag-default-as-regexp)
    (find-tag-default-as-symbol-regexp)
    (car regexp-search-ring)

that uses the region as input with `M-s o down RET'.
Since this looks like a new feature, until feature freeze is over,
you can customize `read-regexp-defaults-function' to a function like

(lambda ()
  (list
   (if (use-region-p)
       (buffer-substring-no-properties (region-beginning) (region-end)))
   (find-tag-default-as-regexp)))

that uses the region as input with just `M-s o RET'.

> Limiting search with the region is infrequently needed and it can
> easily be done with narrowing. The above two features are much
> more useful and they can be used much more frequently (quickly
> picking an input for occur), so they should take precedence.

Yes, it's infrequently needed but still makes sense
for consistency with limiting in query-replace.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-01-17  8:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-16 18:55 Occur should use the region as input if it's active Tom
2014-01-16 19:23 ` Drew Adams
2014-01-16 19:32   ` Tom
2014-01-16 19:51     ` Drew Adams
2014-01-16 19:36   ` Drew Adams
2014-01-16 20:11     ` Tom
2014-01-17  8:11       ` Juri Linkov
2014-01-17  0:52 ` Tak Kunihiro

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.