emacs-devel
[Top][All Lists]
Advanced

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

Why do apropos commands match only pairs of words in a word-list pattern


From: Drew Adams
Subject: Why do apropos commands match only pairs of words in a word-list pattern?
Date: Sat, 9 May 2015 12:16:57 -0700 (PDT)

If you type a list of words to match, instead of typing a regexp,
to a command such as `apropos', each word is not matched against
the candidates and then the intersection of those match sets
retained.

Instead of matching each word in the list you provide it, apropos
commands match each pair of words from the list.

For example, if you type `foo bar toto' then all matches of `foo'
& `bar' (in either order) are retained, plus all matches of `bar'
& `toto', plus all matches of `foo' & `toto'.  So for instance, a
candidate `some-bar-foo-thing' is retained, even though it does
not also match `toto' - it is enough that it matches both `foo'
and `bar'.

Why is this the design?  Wouldn't users more typically want *each*
of the words they type to be matched?

Is this perhaps only because the existing code before introducing
word-list patterns provided for using a regexp, and in order to
bolt word-list matching onto that existing code it was thought to
be easier to just come up with a single regexp to match, instead
of handling the word-list case as an intersection of separate
matches?

IOW, was this just an implementation decision, or is there some
more important reason for it, from a user point of view?

The behavior is documented, in (emacs)`Apropos', as follows:

 When you specify more than one word in the apropos pattern,
 a name must contain at least two of the words in order to match.

No reason given there as to why this would be behavior you might
want or expect.  And beyond that brief description, there is
only this comment in the apropos.el code:

 ;; We don't actually make a regexp matching all permutations.
 ;; Instead, for e.g. "a b c", we make a regexp matching
 ;; any combination of two or more words like this:
 ;; (a|b|c).*(a|b|c) which may give some false matches,
 ;; but as long as it also gives the right ones, that's ok.

That tells what happens, but not why this choice was made.

And the last line almost sounds like an apology, as if this
is not ideal but it is generally OK, since although extra
junk is included at least we don't missing any sought matches.

IOW, it sounds like, even though you really want only matches
of all three: `foo' & `bar' & `toto', we think it's OK if you
get additional, false positives such as `some-bar-foo-thing',
as long as you also get all true positives (such as
`a-bar-toto-foo-thing').

Is this the right behavior?  If so, why - what am I missing?



reply via email to

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