[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Occur should use the region as input if it's active
From: |
Drew Adams |
Subject: |
RE: Occur should use the region as input if it's active |
Date: |
Thu, 16 Jan 2014 11:23:38 -0800 (PST) |
> 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.
`----