Giter Site home page Giter Site logo

Comments (12)

oantolin avatar oantolin commented on August 20, 2024

That is the expected behavior. Orderless splits the input into components, compiles each to a regexp, and a string is considered to match if each component's regexp matches somewhere in the string. In particular it follows that repeating components makes no difference to whether a string matches or not.

For the particular example of matching something like fi fi to find-file, I'd suggest using the orderless-prefixes matching style and phrasing the input as fi-fi instead. Or you could use the orderless-regexp style and type fi.*fi.

from orderless.

minad avatar minad commented on August 20, 2024

I wonder if it makes sense to add a special rule which compiles repeated patterns to literals separated by .*.

Alternatively one could combine all the styles but I don't think the quadratic, cubic behavior, etc would be a great idea.

from orderless.

oantolin avatar oantolin commented on August 20, 2024

Even if we added that special rule, I'd still use fi-fi with orderless-prefixes for this example, because it matches fewer things as it means \<fi.*-fi. I think I'm happy with being precise about whether I mean \<fi.*-fi or just fi.*fi specially since I get to pick the syntax for those things. I've never found much use for fi.*fi so I don't mind typing two characters (. and *) to get that meaning, and I do have orderless-prefixes setup for components with dashes or a few other separators in them.

from orderless.

oantolin avatar oantolin commented on August 20, 2024

We don't need that special rule since it is easy to do in your own configuration:

(defun respect-repeats (string)
  (mapcar
   (lambda (group) (string-join (cdr group) ".*"))
   (seq-group-by #'identity (split-string string))))

(setq orderless-component-separator #'respect-repeats)

from orderless.

oantolin avatar oantolin commented on August 20, 2024

I'm closing this since I think this should be handled in configuration like in the above example code.

from orderless.

minad avatar minad commented on August 20, 2024

from orderless.

minad avatar minad commented on August 20, 2024

from orderless.

gtusr avatar gtusr commented on August 20, 2024

Thanks for the explanation and a proposed solution by treating the repeated pattern as a special case that needs to use .* in order to concatenate the two terms.

But I think the problem is more general than this. Some users may naturally think in terms of the matches to the sequence of pattern components separated by spaces as being 'consumed' by the matching algorithm in some order, so that in the case of the OP, the first 'fi' in find-file would match, and then remove from further consideration, the fi in 'find', leaving just 'nd-file' for the second 'fi' to match.

Viewed from this perspective, the issue is no longer just about repeated pattern components.

Is there an easy way to configure orderless so that the matches to the individual pattern components cannot overlap in a successful candidate?

from orderless.

oantolin avatar oantolin commented on August 20, 2024

Well, programs in the "machine language" that orderless compiles to are just list of regexps and the semantics are that a string matches the list if every regexp matches. Which is why orderless's semantics is chosen to be similar: input matches if each component matches according to the chosen styles.

But I think it's not too hard to do an alternative component separator where something like ab bc ef compiles to the list ("ab.*bc\|bc.*ab" "ef"). I'll try my hand at it when I get the chance.

from orderless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.