Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Occur lite

15 views
Skip to first unread message

B. T. Raven

unread,
Jul 15, 2012, 10:06:30 AM7/15/12
to
Ignutians:

Is there an Emacs function that extracts only words matching a regexp
and writes them to another buffer? This would work exactly like the
"occur" function but would write only the words to the *Occur* buffer
instead of the whole line. I have looked at the code for "occur" in
replace.el but I'm afraid it's over my head to try and modify it into a
custom function.

Thanks,

Ed

Raffaele Ricciardi

unread,
Jul 15, 2012, 12:41:21 PM7/15/12
to
An indirect solution: run occur and then run a regexp over the *Occur*
buffer to capture each word. Something like:

(call-interactively #'occur)
(switch-to-buffer "*Occur*") ;; Or with-current-buffer
(goto-char (point-min))
;; etc.

Raffaele Ricciardi

unread,
Jul 15, 2012, 12:45:33 PM7/15/12
to
On 07/15/2012 05:41 PM, Raffaele Ricciardi wrote:
> An indirect solution: run occur and then run a regexp over the *Occur*
> buffer to capture each word. Something like:
>
> (call-interactively #'occur)
> (switch-to-buffer "*Occur*") ;; Or with-current-buffer
> (goto-char (point-min))
> ;; etc.

I spoke too fast. RTFM, e.g. the documentation of occur provides exactly
what you need.


B. T. Raven

unread,
Jul 15, 2012, 1:12:23 PM7/15/12
to
Thanks, Raffaele. The Emacs manual doesn't have a menu item for Occur
and I don't find it under the "Search" topics. Do you mean that this
capability is built in or does it require another package? At

http://emacswiki.org/emacs/OccurMode#toc12

under "View matches only" there is code for an "occurences" function
that looks like it might work but I don't understand it and don't need
much of its functionality (text properties, etc.) but it would be nice
to retain the line number and colon and have the occurences printed one
per line. Anyway, I can try it if the line

(interactive (occur-read-primary-args))

means that I can invoke it as M-x occurences.

Thanks again,

Ed

Raffaele Ricciardi

unread,
Jul 15, 2012, 1:30:53 PM7/15/12
to
On 07/15/2012 06:12 PM, B. T. Raven wrote:
> Thanks, Raffaele. The Emacs manual doesn't have a menu item for Occur
> and I don't find it under the "Search" topics. Do you mean that this
> capability is built in or does it require another package?

I mean that "C-h f occur RET" displays the documentation of occur, where
you can find an example of how to capture function names in a Lisp file.
It seems what you are looking for.

Cheers.

B. T. Raven

unread,
Jul 15, 2012, 1:59:47 PM7/15/12
to
Thanks for the fast reply. On ver. 23.3 the function docs are these:
"
occur is an interactive compiled Lisp function in `replace.el'.

It is bound to M-s o.

(occur REGEXP &optional NLINES)

Show all lines in the current buffer containing a match for REGEXP.
This function can not handle matches that span more than one line.

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.

The lines are shown in a buffer named `*Occur*'.
It serves as a menu to find any of the occurrences in this buffer.
C-h m in that buffer will explain how.

If REGEXP contains upper case characters (excluding those preceded by `\')
and `search-upper-case' is non-nil, the matching is case-sensitive.
"

In general I use Emacs for general text manipulation, not programming,
so, no, I'm not trying to get function names. Anyway, that code from
emacwiki seems to work and I can toggle-read-only on the buffer and use
rectangle to extract the matches only.

Ed


Raffaele Ricciardi

unread,
Jul 15, 2012, 2:44:19 PM7/15/12
to
On 07/15/2012 06:59 PM, B. T. Raven wrote:
> Thanks for the fast reply. On ver. 23.3 the function docs are these:

Then occur has been improved on Emacs 24.1, as the documentation
contains a further paragraph, and occur can send to the *Occur* buffer
matches instead of whole lines. That doesn't work on Emacs 23.2.

B. T. Raven

unread,
Jul 15, 2012, 5:11:37 PM7/15/12
to
Die Sun Jul 15 2012 13:44:19 GMT-0500 (Central Daylight Time) Raffaele
Ricciardi <rffl...@gmail.com> scripsit:
Just another reason to upgrade. I was going to wait for 64-bit Emacs
before upgrading (for no good reason since the biggest file I have ever
edited was only a few megabytes). A better reason might be to check out
the added features, especially bidi and new input methods.

Aurélien Aptel

unread,
Jul 15, 2012, 6:55:10 PM7/15/12
to B. T. Raven, help-gn...@gnu.org
On Sun, Jul 15, 2012 at 11:11 PM, B. T. Raven <btr...@nihilo.net> wrote:
> edited was only a few megabytes). A better reason might be to check out
> the added features, especially bidi and new input methods.

There's also the new package manager and lexical scoping!

0 new messages