emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] Re: Sparse trees and searching for multiple words


From: Scot Becker
Subject: Re: [Orgmode] Re: Sparse trees and searching for multiple words
Date: Tue, 21 Sep 2010 23:14:11 +0100

Tom,

I agree that a flexible multi-term search would be a great addition to
org-mode and Emacs in general.  I'd say that Google has spoiled us,
but like all who are spoiled I believe my inflated desires to be
perfectly reasonable!  I'm keeping more and more notes in org-mode,
and the more I keep, the more this comes up.  I had a look at the page
Ilya suggested, and got the 'first alternative' to work with org-occur
(code below), but I also followed the links there and it looks like
Drew Adams has done some significant work in this regard with his
'icicles' library.   See his discussion on search here:

http://www.emacswiki.org/emacs/Icicles_-_Search_Commands%2c_Overview

For example, using M-x icicles-search you can specify both a 'search
context' (for example sentences, paragraphs, or any other span of text
that you can define with a regexp.... perhaps org-mode outline
nodes?), then from there you can drill down with one search term after
another.  This amounts to a progressive AND search, like what you're
asking for.  And as I remember, icicles does have a pretty good set of
commands for tweaking searches in progress.  Not Google Instant, but
if it works, it could be pretty good.  I'm not sure if you could
somehow do org-sparse trees with something like this.

On a first attempt a year ago, I wasn't able to swallow the icicles
pill whole.  I went back to ido in the end---partly because I couldn't
manage the complexity.  But `icicles-search' really motivates me to
refresh my configuration and see if it is useful, at least for this
kind of thing.

For a simpler and less flexible solution, here is the code from the
'String Permutations' page, with the top-level function rewritten to
call org-occur.  It works reasonably well for the kind of searches you
are asking about, but the search terms do have to be on the same line.
 This is less of a problem if, like me, you are using visual-line-mode
and your paragraphs don't have newlines breaking them up.

    (defun scb/search-words-any-order (keywords)
      "Search for a comma-separated list of terms in any order."
      (interactive "sKeywords: (comma-separated) ")
      (org-occur (my-csv-string-to-regexp keywords)))

    (defun my-csv-string-to-regexp (str)
      "Translate comma separated values into regexp.
    A,B,C turns into
\\(A.*B.*C\\|A.*C.*B\\|B.*A.*C\\|B.*C.*A\\|C.*A.*B\\|C.*B.*A\\)"
      (let* ((l (perms (split-string str ",\\s-*"))))
        (mapconcat (function (lambda (n)
          (mapconcat 'identity n ".*"))) l "\\|")))

    ;; thanks to Christoph Conrad <address@hidden>
    (require 'cl)
    (defun perms (l)
      (if (null l)
          (list '())
        (mapcan #'(lambda( a )
                    (mapcan #'(lambda( p )
                                (list (cons a p)))
                            (perms (remove* a l :count 1))))
                l)))



Scot

On Tue, Sep 21, 2010 at 6:20 PM, Ilya Shlyakhter <address@hidden> wrote:
>> For example, I'd like to see entries which contains the words 'cat' and
>> 'dog' in any order. Or 'apple', 'orange', 'melon', 'plum' and 'pear'
>> in any order.
>
> Maybe this will help: http://www.emacswiki.org/emacs/StringPermutations
>
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> address@hidden
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]