emacs-devel
[Top][All Lists]
Advanced

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

Re: Apropos commands and regexps


From: Alex Schroeder
Subject: Re: Apropos commands and regexps
Date: Sun, 12 May 2002 19:03:17 +0200
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i686-pc-linux-gnu)

address@hidden (Kai Großjohann) writes:

> address@hidden (Kim F. Storm) writes:
>
>> E.g. C-h a open file RET  would find any matching
>>
>>         open.*file and file.*open
>
> Way cool!

I posted a similar thing in elisp some time back.  Searching for it on
Google returned this:

Von:Alex Schroeder (address@hidden)
Betrifft:Re: Emacs Boolean Help
Newsgroups:gnu.emacs.gnus
Datum:2000-08-17 10:07:22 PST

(defun ed-apropos (keywords)
  "Search for KEYWORDS.
This uses `apropos'.  All the keywords must match.
KEYWORDS can be a comma-separated list."
  (interactive "sKeywords: (comma-separated) ")
  (apropos (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)))

-- 
http://www.electronicintifada.net/diaries/index.html
http://www.us-israel.org/jsource/US-Israel/hr2506c.html



reply via email to

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