artificial concept index with double-grep

Sat, 16 Jul 2016 09:08:28 +0200

Here is another approach [to get a "concept
index" automagically], namely to abandon the
Emacs documentation and help interface and
instead operate directly on the source with
shell tools, i.e. grep.

The advantage is that it works, and even better
perhaps; there is no unsafe `require' just to
get function definitions; and, it is
much faster.

There is also the ease of use advantage because
you can get all Elisp in the world and just
pour it into a directory and there won't be any
conflicts or problems loading or whatever as
it'll just be a bunch of dead text!

All in all, an unusually good solution -
as usual!

(yeah - how *do* you get *all* MELPA and GNU
ELPA code?)

Here is the function:

    double-grep () {
        local first=$1    # e.g., trim   (most unusual concept first!)
        local second=$2   #       string (the the more usual...)

        local context=$3  #  0 => no context: hits must be on same line
        local results=$4  # 10 => show max 10 (double) hits

        local -a files
        files=($@[5,-1])  # e.g., ~/sw/emacs24-24.4+1/lisp/**/*.el

        grep       --color=always -C $context $first  $files \
            | grep --color=always             $second        \
            | head -n $results

        # invocation example:
        #   $ cd ~/sw/emacs24-24.4+1/lisp/
        #   $ double-grep trim string 0 10 **/*.el

Back to Blogomatic.