Giter Site home page Giter Site logo

orderless's Introduction

Orderless

GNU ELPA GNU-devel ELPA MELPA MELPA Stable

Overview

This package provides an orderless completion style that divides the pattern into space-separated components, and matches candidates that match all of the components in any order. Each component can match in any one of several ways: literally, as a regexp, as an initialism, in the flex style, or as multiple word prefixes. By default, regexp and literal matches are enabled.

A completion style is a back-end for completion and is used from a front-end that provides a completion UI. Any completion style can be used with the default Emacs completion UI (sometimes called minibuffer tab completion), with the built-in Icomplete package (which is similar to the more well-known Ido Mode), the icomplete-vertical variant from Emacs 28 (see the external icomplete-vertical package to get that functionality on earlier versions of Emacs), or with some third party minibuffer completion frameworks such as Mct or Vertico.

All the completion UIs just mentioned are for minibuffer completion, used when Emacs commands prompt the user in the minibuffer for some input, but there is also completion at point in normal buffers, typically used for identifiers in programming languages. Completion styles can also be used for that purpose by completion at point UIs such as Corfu, Company or the function consult-completion-in-region from Consult.

To use a completion style with any of the above mentioned completion UIs simply add it as an entry in the variables completion-styles and completion-category-overrides and completion-category-defaults (see their documentation).

The completion-category-defaults variable serves as a default value for completion-category-overrides. If you want to use orderless exclusively, set both variables to nil, but be aware that completion-category-defaults is modified by packages at load time.

With a bit of effort, it might still be possible to use orderless with other completion UIs, even if those UIs don’t support the standard Emacs completion styles. Currently there is support for Ivy (see below). Also, while Company does support completion styles directly, pressing SPC takes you out of completion, so comfortably using orderless with it takes a bit of configuration (see below).

If you use ELPA or MELPA, the easiest way to install orderless is via package-install. If you use use-package, you can use:

(use-package orderless
  :ensure t
  :custom
  (completion-styles '(orderless basic))
  (completion-category-overrides '((file (styles basic partial-completion)))))

Alternatively, put orderless.el somewhere on your load-path, and use the following configuration:

(require 'orderless)
(setq completion-styles '(orderless basic)
      completion-category-overrides '((file (styles basic partial-completion))))

The basic completion style is specified as fallback in addition to orderless in order to ensure that completion commands which rely on dynamic completion tables, e.g., completion-table-dynamic or completion-table-in-turn, work correctly. Furthermore the basic completion style needs to be tried first (not as a fallback) for TRAMP hostname completion to work. In order to achieve that, we add an entry for the file completion category in the completion-category-overrides variable. In addition, the partial-completion style allows you to use wildcards for file completion and partial paths, e.g., /u/s/l for /usr/share/local.

Bug reports are highly welcome and appreciated!

Screenshot

This is what it looks like to use describe-function (bound by default to C-h f) to match eis ff. Notice that in this particular case eis matched as an initialism, and ff matched as a regexp. The completion UI in the screenshot is icomplete-vertical and the theme is Protesilaos Stavrou’s lovely modus-operandi.

https://github.com/oantolin/orderless/blob/dispatcher/images/describe-function-eis-ff.png?raw=true

Customization

Component matching styles

Each component of a pattern can match in any of several matching styles. A matching style is a function from strings to regexps or predicates, so it is easy to define new matching styles. The value returned by a matching style can be either a regexp as a string, an s-expression in rx syntax or a predicate function. The predefined matching styles are:

orderless-regexp
the component is treated as a regexp that must match somewhere in the candidate.

If the component is not a valid regexp, it is ignored.

orderless-literal
the component is treated as a literal string that must occur in the candidate.
orderless-literal-prefix
the component is treated as a literal string that must occur as a prefix of a candidate.
orderless-prefixes
the component is split at word endings and each piece must match at a word boundary in the candidate, occurring in that order.

This is similar to the built-in partial-completion completion-style. For example, re-re matches query-replace-regexp, recode-region and magit-remote-list-refs; f-d.t matches final-draft.txt.

orderless-initialism
each character of the component should appear as the beginning of a word in the candidate, in order.

This maps abc to \<a.*\<b.*\c.

orderless-flex
the characters of the component should appear in that order in the candidate, but not necessarily consecutively.

This maps abc to a.*b.*c.

orderless-without-literal
the component is a treated as a literal string that must not occur in the candidate.

Nothing is highlighted by this style. This style should not be used directly in orderless-matching-styles but with a style dispatcher instead. See also the more general style modifier orderless-not.

The variable orderless-matching-styles can be set to a list of the desired matching styles to use. By default it enables the literal and regexp styles.

Style modifiers

Style modifiers are functions which take a predicate function and a regular expression as a string and return a new predicate function. Style modifiers should not be used directly in orderless-matching-styles but with a style dispatcher instead.

orderless-annotation
this style modifier matches the pattern against the annotation string of the candidate, instead of against the candidate string.
orderless-not
this style modifier inverts the pattern, such that candidates pass which do not match the pattern.

Style dispatchers

For more fine-grained control on which matching styles to use for each component of the input string, you can customize the variable orderless-style-dispatchers. You can use this feature to define your own “query syntax”. For example, the default value of orderless-style-dispatchers lists a single dispatcher called orderless-affix-dispatch which enables a simple syntax based on special characters used as either a prefix or suffix:

  • ! modifies the component with orderless-not. Both !bad and bad! will match strings that do not contain the pattern bad.
  • & modifies the component with orderless-annotation. The pattern will match against the candidate’s annotation (cheesy mnemonic: andnotation!).
  • , uses orderless-initialism.
  • = uses orderless-literal.
  • ^ uses orderless-literal-prefix.
  • ~ uses orderless-flex.
  • % makes the string match ignoring diacritics and similar inflections on characters (it uses the function char-fold-to-regexp to do this).

You can add, remove or change this mapping between affix characters and matching styles by customizing the user option orderless-affix-dispatch-alist. Most users will probably find this type of customization sufficient for their query syntax needs, but for those desiring further control the rest of this section explains how to implement your own style dispatchers.

Style dispatchers are functions which take a component, its index in the list of components (starting from 0), and the total number of components, and are used to determine the matching styles used for that specific component, overriding the default matching styles.

A style dispatcher can either decline to handle the input string or component, or it can return which matching styles to use. It can also, if desired, additionally return a new string to use in place of the given one. Consult the documentation of orderless--dispatch for full details.

As an example of writing your own dispatchers, say you wanted the following setup:

  • you normally want components to match as regexps,
  • except for the first component, which should always match as an initialism —this is pretty useful for, say, execute-extended-command (M-x) or describe-function (C-h f),
  • later components ending in ~ should match (the characters other than the final ~) in the flex style, and
  • later components starting with ! should indicate the rest of the component is a literal string not contained in the candidate (this is part of the functionality of the default configuration).

You can achieve this with the following configuration:

(defun flex-if-twiddle (pattern _index _total)
  (when (string-suffix-p "~" pattern)
    `(orderless-flex . ,(substring pattern 0 -1))))

(defun first-initialism (pattern index _total)
  (if (= index 0) 'orderless-initialism))

(defun not-if-bang (pattern _index _total)
  (cond
   ((equal "!" pattern)
    #'ignore)
   ((string-prefix-p "!" pattern)
    `(orderless-not . ,(substring pattern 1)))))

(setq orderless-matching-styles '(orderless-regexp)
      orderless-style-dispatchers '(first-initialism
                                    flex-if-twiddle
                                    not-if-bang))

Component separator regexp

The pattern components are space-separated by default: this is controlled by the variable orderless-component-separator, which should be set either to a regexp that matches the desired component separator, or to a function that takes a string and returns the list of components. The default value is a regexp matches a non-empty sequence of spaces. It may be useful to add hyphens or slashes (or both), to match symbols or file paths, respectively.

Even if you want to split on spaces you might want to be able to escape those spaces or to enclose space in double quotes (as in shell argument parsing). For backslash-escaped spaces set orderless-component-separator to the function orderless-escapable-split-on-space; for shell-like double-quotable space, set it to the standard Emacs function split-string-and-unquote.

If you are implementing a command for which you know you want a different separator for the components, bind orderless-component-separator in a let form.

Defining custom orderless styles

Orderless allows the definition of custom completion styles using the orderless-define-completion-style macro. Any Orderless configuration variable can be adjusted locally for the new style, e.g., orderless-matching-styles.

By default Orderless only enables the regexp and literal matching styles. In the following example an orderless+initialism style is defined, which additionally enables initialism matching. This completion style can then used when matching candidates of the symbol or command completion category.

(orderless-define-completion-style orderless+initialism
  (orderless-matching-styles '(orderless-initialism
                               orderless-literal
                               orderless-regexp)))
(setq completion-category-overrides
      '((command (styles orderless+initialism))
        (symbol (styles orderless+initialism))
        (variable (styles orderless+initialism))))

Note that in order for the orderless+initialism style to kick-in with the above configuration, you’d need to use commands whose metadata indicates that the completion candidates are commands or symbols. In Emacs 28, execute-extended-command has metadata indicating you are selecting a command, but earlier versions of Emacs lack this metadata. Activating marginalia-mode from the Marginalia package provides this metadata automatically for many built-in commands and is recommended if you use the above example configuration, or other similarly fine-grained control of completion styles according to completion category.

Faces for component matches

The portions of a candidate matching each component get highlighted in one of four faces, orderless-match-face-? where ? is a number from 0 to 3. If the pattern has more than four components, the faces get reused cyclically.

If your completion-styles (or completion-category-overrides for some particular category) has more than one entry, remember than Emacs tries each completion style in turn and uses the first one returning matches. You will only see these particular faces when the orderless completion is the one that ends up being used, of course.

Pattern compiler

The default mechanism for turning an input string into a predicate and a list of regexps to match against, configured using orderless-matching-styles, is probably flexible enough for the vast majority of users. The patterns are compiled by orderless-compile. Under special circumstances it may be useful to implement a custom pattern compiler by advising orderless-compile.

Interactively changing the configuration

You might want to change the separator or the matching style configuration on the fly while matching. There many possible user interfaces for this: you could toggle between two chosen configurations, cycle among several, have a keymap where each key sets a different configurations, have a set of named configurations and be prompted (with completion) for one of them, popup a hydra to choose a configuration, etc. Since there are so many possible UIs and which to use is mostly a matter of taste, orderless does not provide any such commands. But it’s easy to write your own!

For example, say you want to use the keybinding C-l to make all components match literally. You could use the following code:

(defun my/match-components-literally ()
  "Components match literally for the rest of the session."
  (interactive)
  (setq-local orderless-matching-styles '(orderless-literal)
              orderless-style-dispatchers nil))

(define-key minibuffer-local-completion-map (kbd "C-l")
  #'my/match-components-literally)

Using setq-local to assign to the configuration variables ensures the values are only used for that minibuffer completion session.

Integration with other completion UIs

Several excellent completion UIs exist for Emacs in third party packages. They do have a tendency to forsake standard Emacs APIs, so integration with them must be done on a case by case basis.

If you manage to use orderless with a completion UI not listed here, please file an issue or make a pull request so others can benefit from your effort. The functions orderless-filter, orderless-highlight-matches, orderless--highlight and orderless--component-regexps are likely to help with the integration.

Ivy

To use orderless from Ivy add this to your Ivy configuration:

(setq ivy-re-builders-alist '((t . orderless-ivy-re-builder)))
(add-to-list 'ivy-highlight-functions-alist '(orderless-ivy-re-builder . orderless-ivy-highlight))

Helm

To use orderless from Helm, simply configure orderless as you would for completion UIs that use Emacs completion styles and add this to your Helm configuration:

(setq helm-completion-style 'emacs)

Company

Company comes with a company-capf backend that uses the completion-at-point functions, which in turn use completion styles. This means that the company-capf backend will automatically use orderless, no configuration necessary!

But there are a couple of points of discomfort:

  1. Pressing SPC takes you out of completion, so with the default separator you are limited to one component, which is no fun. To fix this add a separator that is allowed to occur in identifiers, for example, for Emacs Lisp code you could use an ampersand:
    (setq orderless-component-separator "[ &]")
        
  2. The matching portions of candidates aren’t highlighted. That’s because company-capf is hard-coded to look for the completions-common-part face, and it only use one face, company-echo-common to highlight candidates.

    So, while you can’t get different faces for different components, you can at least get the matches highlighted in the sole available face with this configuration:

    (defun just-one-face (fn &rest args)
      (let ((orderless-match-faces [completions-common-part]))
        (apply fn args)))
    
    (advice-add 'company-capf--candidates :around #'just-one-face)
        

    (Aren’t dynamically scoped variables and the advice system nifty?)

If you would like to use different completion-styles with company-capf instead, you can add this to your configuration:

;; We follow a suggestion by company maintainer u/hvis:
;; https://www.reddit.com/r/emacs/comments/nichkl/comment/gz1jr3s/
(defun company-completion-styles (capf-fn &rest args)
  (let ((completion-styles '(basic partial-completion)))
    (apply capf-fn args))

(advice-add 'company-capf :around #'company-completion-styles)

Related packages

Ivy and Helm

The well-known and hugely powerful completion frameworks Ivy and Helm also provide for matching space-separated component regexps in any order. In Ivy, this is done with the ivy--regex-ignore-order matcher. In Helm, it is the default, called “multi pattern matching”.

This package is significantly smaller than either of those because it solely defines a completion style, meant to be used with any completion UI supporting completion styles while both of those provide their own completion UI (and many other cool features!).

It is worth pointing out that Helm does provide its multi pattern matching as a completion style which could be used with default tab completion, Icomplete or other UIs supporting completion styles! (Ivy does not provide a completion style to my knowledge.) So, for example, Icomplete users could, instead of using this package, install Helm and configure Icomplete to use it as follows:

(require 'helm)
(setq completion-styles '(helm basic))
(icomplete-mode)

(Of course, if you install Helm, you might as well use the Helm UI in helm-mode rather than Icomplete.)

Prescient

The prescient.el library also provides matching of space-separated components in any order. It offers a completion-style that can be used with Emacs’ default completion UI, Mct, Vertico or with Icomplete. Furthermore Ivy is supported. The components can be matched literally, as regexps, as initialisms or in the flex style (called “fuzzy” in prescient). Prescient does not offer the same flexibility as Orderless with its style dispatchers. However in addition to matching, Prescient supports sorting of candidates, while Orderless leaves that up to the candidate source and the completion UI.

Restricting to current matches in Icicles, Ido and Ivy

An effect equivalent to matching multiple components in any order can be achieved in completion frameworks that provide a way to restrict further matching to the current list of candidates. If you use the keybinding for restriction instead of SPC to separate your components, you get out of order matching!

  • Icicles calls this progressive completion and uses the icicle-apropos-complete-and-narrow command, bound to S-SPC, to do it.
  • Ido has ido-restrict-to-matches and binds it to C-SPC.
  • Ivy has ivy-restrict-to-matches, bound to S-SPC, so you can get the effect of out of order matching without using ivy--regex-ignore-order.

orderless's People

Contributors

b3n avatar clemera avatar jcs090218 avatar jgarte avatar joshleeb avatar minad avatar narendraj9 avatar noctuid avatar oantolin avatar protesilaos avatar raxod502 avatar tarsius avatar vifon avatar wyuenho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

orderless's Issues

!!!

In the light of the keep-lines/flush-lines discussion, would it make sense to support a special token like !!! to orderless such that we can get the complement?

Sorting

@oantolin I must say, I really like this package. I just added the twiddle flex matching to my init.el. It is really nice how this thing can be tweaked. In particular I like that this package is so easy to integrate - only replace the completion-style and done.

Right now I am using orderless without any fancy sorting package, but it would probably be nice to use something based on frecency. There is prescient and then there is the frecency package on melpa (but I think this is only the algorithm). What do you use?

orderless & company-capf

I'm not quite sure how to debug this but I figured I should at least post it. Whenever my emacs instance has been running for some time the performance of company-capf degrades to a standstill. I've done a profile when running some completion in an empty buffer and I got the below. Indicating something in orderless-filter. However, even if I enable edebug on this function I cannot seem to trigger it to determine the issue. Have you experienced anything similar?

- company-post-command                                           1451  85%
 - company--perform                                              1441  84%
  - company--continue                                            1439  84%
   - company-calculate-candidates                                1439  84%
    - company--fetch-candidates                                  1427  83%
     - company-call-backend-raw                                  1427  83%
      - apply                                                    1427  83%
       - company-capf                                            1427  83%
        - company-capf--candidates                               1427  83%
         - completion-all-completions                            1427  83%
          - completion--nth-completion                           1427  83%
           - completion--some                                    1427  83%
            - #<compiled 0x808f96f84b95aa8>                      1427  83%
             - orderless-all-completions                         1427  83%
              - orderless-filter                                 1410  82%
               - condition-case                                  1410  82%
                - save-match-data                                1410  82%
                 - let                                           1410  82%
                  - unwind-protect                               1410  82%
                   - progn                                       1410  82%
                    - pcase-let*                                 1410  82%
                     - let*                                      1410  82%
                      - let                                      1410  82%
                         let*                                    1410  82%
              + orderless-highlight-matches                        16   0%
    + company--postprocess-candidates                               9   0%
  + company-call-frontends                                          2   0%
 + company-call-frontends                                          10   0%
+ command-execute                                                  93   5%
+ ...                                                              67   3%
+ redisplay_internal (C function)                                  53   3%
+ timer-event-handler                                              33   1%
+ server-process-filter                                             6   0%

This is the profile when the same completion is run with completion-styles = '(basic partial-completion)

- command-execute                                                 755  55%
 + funcall-interactively                                          755  55%
- company-post-command                                            324  23%
 - company--perform                                               282  20%
  - company--continue                                             274  19%
   - company-calculate-candidates                                 271  19%
    - company--fetch-candidates                                   270  19%
     - company-call-backend-raw                                   270  19%
      - apply                                                     270  19%
       - company-capf                                             270  19%
        - company-capf--candidates                                270  19%
         - completion-all-completions                             270  19%
          - completion--nth-completion                            270  19%
           - completion--some                                     270  19%
            - #<compiled 0x808f7f942f944a8>                       270  19%
               completion-basic-all-completions                   258  18%
             - completion-pcm-all-completions                      12   0%
                completion-pcm--find-all-completions                 12   0%
   + company-call-backend                                           1   0%
     company-update-candidates                                      1   0%
   + company-cancel                                                 1   0%
  + company-call-frontends                                          8   0%
 + company-call-frontends                                          42   3%
+ timer-event-handler                                             142  10%
+ redisplay_internal (C function)                                 108   7%
+ ...                                                              30   2%
+ server-process-filter                                             7   0%
  posframe-run-hidehandler                                          1   0%
+ flycheck-maybe-display-error-at-point-soon                        1   0%
+ evil-repeat-post-hook                                             1   0%
  amx-save-to-file                                                  1   0%
+ highlight-parentheses--initiate-highlight                         1   0%

dired-narrow integration

Right now I have this in my config:

  (defun dired-narrow--orderless-filter (filter)
    (orderless-filter filter (list (dired-utils-get-filename 'no-dir))))

  (defun dired-narrow-orderless ()
    "Narrow a dired buffer to the files matching an orderless query."
    (interactive)
    (dired-narrow--internal #'dired-narrow--orderless-filter))

Maybe it would be better to add a command directly to dired-narrow that just uses completion-styles. I'll have to look into how completion-styles actually works. It doesn't seem like changing it affects all-completions.

Possible to match with buffers whose name starts with a space?

With default completion-styles,

  1. Start emacs
    $  emacs -Q -l vertico/vertico.el -l orderless/orderless.el --eval '(vertico-mode)'
  2. Type C-x b.
  3. Type SPC.

Then the following buffers are displayed.
image

After setting the following configuration,

(setq completion-styles '(orderless))
(setq completion-category-defaults nil)
(setq orderless-component-separator 'orderless-escapable-split-on-space)

Typing \SPC shows no buffer.
image

Is it possible to display these buffers with orderless completion style only?

Issue with `ledger-mode` and `completion-ignore-case`

It seems orderless does not respect completion-ignore-case when completing accounts in ledger.

Repro:

Using

emacs-27.2
orderless commit d97a91f
ledger-mode commit 58a2bf57

Steps

Create these two files
/tmp/init.el

(require 'ledger-mode)
(require 'orderless)
(add-to-list 'auto-mode-alist '("\\.dat\\'" . ledger-mode))
(setq tab-always-indent 'complete
      completion-ignore-case t
      ledger-complete-in-steps t
      completion-styles '(orderless))

/tmp/ledger.dat

2015/10/12 Exxon
    Expenses:Auto:Gas         $10.00
    Liabilities:MasterCard   $-10.00

2021/05/15 Exxon
    Expenses:au

Then run

emacs -Q -L /load/path/to/orderless -L /load/path/to/ledger-mode -l /tmp/init.el +6:16 /tmp/ledger.dat

and then run M-x completion-at-point which will give the error No match. If you change au to Au emacs will expand it to Auto: as expected.

If you instead use:
/tmp/init.el

(require 'ledger-mode)
(require 'orderless)
(add-to-list 'auto-mode-alist '("\\.dat\\'" . ledger-mode))
(setq tab-always-indent 'complete
      completion-ignore-case t
      ledger-complete-in-steps t)

I.e. not setting completion-styles to '(orderless), emacs will expand au to Auto: as expected.

Not sure if this is an issue with ledger-mode or orderless, but given that this issue shows up when I use orderless I'll start here. And to clarify this only happens in ledger-mode, orderless will ignore the case when running M-x for example.

Thanks

Intentionally selecting query method

For example, if I type sl as a query with the intention of it being an intialism, I'd rather all matches (or at least the first ones) be those matched by an initialism. This could be achieved by sorting initialisms first, but this package doesn't do sorting, and that would be overly complicated and slower.

What might be nice if there was some way to mark a query as something specific. I was thinking you could potentially customize different separators for different query types, which would allow doing this without any extra keypresses. For example - could match an initialism, could match an initialism or a regexp, etc. There could be a default if you haven't typed a separator yet. Even better would be if you could set a default per-query number (and as an alist per command). I guess this could potentially have speed improvements as well.

For example, I might set the default for query 1 to be initialism and the default for query 2 to be a regexp. as a separator would not change things from the default. Normally, I would start with an initialism and then add a regexp if needed. If I wanted to start with a regexp instead, I would just add a space at the beginning to start the second query. For some commands, I would probably want to reverse that order (or maybe I could just do query 1 regexp, query 2 initialism, query 3 regexp instead of having different defaults for different commands; I'd have to play around with it).

In another example, maybe I realize I didn't type the initialism correctly (e.g. included too many letters). Instead of deleting the query, I could change it to fuzzy by using . (or whatever) as a separator after it.

I guess this would require adding more commands for configuring separators. It's a little more complicated, but it would be completely optional, and it seems like it could be worth it to me. Most of the benefit for me would come from having different default matching types for different queries, so I think having different separators for different query types would be the less often useful part. Something similar (but not quite as flexible) could be achieved by just initially hitting the separator key enough times to get to the query type you want. I guess you could add even more rules to also be able to pick a specific query type beforehand, like you could specify two separators in a row... but that makes things even more complicated. I think it's probably enough to be able to change the query type afterward to handle the "oops, I actually need fuzzy" case. And even then, if it was the first query, you could just go to the beginning of the line and add the necessary number of separators to get it to be in the fuzzy query position. So maybe using separators to specify the query type isn't useful enough to justify the extra complexity.

What do you think? Do you have any other ideas?

Out-of-order fails when `completing-read` has initial input

When completing-read is given an initial input, such as one that represents a directory path, out-of-order matching will yield no results, unless the user's input starts with a space.

(find-file
 (completing-read "Open recentf entry: " recentf-list nil t "/home/prot/"))

So If I evaluate the above and immediately type the mo I am getting no matches. But if I type SPC the mo I am getting a list of candidates.

Screenshot at 2020-04-14 08-21-07

Screenshot at 2020-04-14 08-21-32

Would it be possible to account for initial input and assume a space?

question: how to use orderless-strict-*-initialism when the definition of word has changed `modify-syntax-entry`

Hello

I've modified the definition of words to include - and _, it looks like this change affects how orderless work with orderless-strict-*-initialism

(defun diego--treat-chars-as-word-char ()
  (modify-syntax-entry ?_ "w")
  (modify-syntax-entry ?- "w"))
(add-hook 'after-change-major-mode-hook #'diego--treat-chars-as-word-char)

When I disabled above code, orderless-strict-*-initialism works as expected.

I've tried setting

  (setq completion-pcm-word-delimiters "-_./:| ")

but it doesn't have any effect on orderless.

thanks!

Orderless style doesn't work with some dynamic tables

While experimenting with dynamic tables I noticed that tables like the following behave differently with orderless:

(setq completion-styles
'(orderless))

(completing-read "Test: "
                 (completion-table-dynamic
                  (lambda (input)
                    (cond ((string-match "this" input)
                           (list "this" "this and that" "this and more"))
                          (t
                           (list "check" "that" "out"))))))

When using this as input I don't get any completions with orderless, when using the standard styles I get the completions from the first cond clause.

No highlighting in company popup

I'm opening an issue here first because I'm not sure whether company is actually at fault or not. If I set completion-styles to '(flex), for example, it shows the highlighting correctly in the company popup, but for orderless, there is no highlighting.

Smart case

Not sure if this is feasible, but it would be nice if there was a way to have smart case support or at least to support the equivalent case-fold-search.

Try the longest common substring for `try-completion'?

Currently "orderless-try-completion" does not try to complete the input when it matches more than one candidate. I think it could be useful to have this feature, so I have written a little package to find the longest common substrings(s) of multiple strings using Ukkonen's algorithm for building generalized suffix trees. The repository is here: https://gitlab.com/mmemmew/suffix-tree

I am wondering about your opinions. Do you think it would be a useful feature to add?

For company popups, match with ^ automatically. Possible?

I've recently started building an Emacs configuration myself instead of using some packaged solution, and I happily use orderless, it's awesome :)

Now that I've come the point where I want to program (again) in Emacs, I realized that orderless is used for those company popups as well (great!). Is there a way to make it so that when typing (in a scratch buffer, I tried typing (macro to see its hundreds of completions) the completions that are shown are interpreted as if I had actually typed ^myword?

With the examples in the readme I'm pretty sure I could do that "globally" for orderless by adding a dispatcher, but I think I only want this behavior for those popups. Is there a nice way to do that?

(If this is the wrong place, I'm sorry)

Idea for easy configuration

Clearly orderless is configurable to a pretty much arbitrary degree... if you are willing to deal with minibuffer hooks and what not.

Now, suppose I wanted to use a particular value of orderless-matching-styles for a particular class of commands, say just '(orderless-regexp) for consult-lines and friends (because orderless-initialism is too permissive when matching against whole lines of text). How would you do it? I think it would be neat if a configuration like this worked:

(setq completion-category-overrides
      '((file (styles partial-completion))
        (consult-location (orderless-matching-styles orderless-regexp))
                          (orderless-style-dispatchers first-initialism
                                                       flex-if-twiddle
                                                       without-if-bang)))

Doc typo

The variable orderless-component-matching-style should be set to a list of the desired styles to use. By default it enables the regexp and initialism styles.

Should be: orderless-component-matching-styles

Tripped me until I checked the source.

Filename completion doesn't work

Using orderless with find-file is severly disappointing: the candidates don't include paths but find-file starts by inserting a path, so there usually no matches.

If you delete the path in the minibuffer, you can match against the files in the current directory, but there seems to be no way to match files in other directories.

Trouble defining new filtering rules with diacritics

I am trying to make a new "matching style" (not sure if I'm using the correct jargon) to make filtering in orderless behaves well with diacritics. For example typing resume would match résumé, etc...

I have written a small function that would convert résumé to resume, using the built-in ucs-normalize.el:

(defun remove-diacritics (s)
    (replace-regexp-in-string
     ucs-normalize-nfd-quick-check-regexp ""
     (ucs-normalize-NFD-string s)))

However, adding this function to either orderless-matching-styles or orderless-style-dispatchers doesn't seem to work. I read the README but haven't been able to wrap my head around this. Any help is appreciated. Thanks!

camelCase initialism matching

Is there some easy way to achieve this globally currently? I thought (global-)subword-mode might do the trick, but it doesn't look like it.

orderless renders counsel-rg ineffective

If I add the following code to my init.el to activate orderless in Emacs, then counsel-rg no longer works in Emacs:

(require 'orderless)
(setq completion-styles '(orderless))
(setq ivy-re-builders-alist '((t . orderless-ivy-re-builder)))

Do you have any ideas how I might fix this problem?
Below is the code in myinit file that pertains to counsel-rg:

(defvar my-rg-excludes '("~/personal" "~/computing" "~/deft" "~/emacs" "~/resources" "~/sermons")
  "List of directories to exclude from `counsel-rg' results.")

(define-advice counsel-rg
    (:around (fn &optional in dir opts &rest args) my-glob)
  "Exclude `my-rg-excludes' from `counsel-rg' results."
  (let ((dir (or dir default-directory)))
    (dolist (x my-rg-excludes)
      (let ((glob (and (file-in-directory-p x dir)
                       (file-relative-name (expand-file-name "**" x) dir))))
        (when glob (setq opts (concat "-g !" glob (and opts " ") opts))))))
  (apply fn in dir opts args))

 '(counsel-rg-base-command
   '("rg" "-M" "260" "--with-filename" "--no-heading" "--line-number" "--color" "never" "%s" "--no-hidden"))

autoload of cl-pushnew is bad/doesn't work

The naive autoloading of cl-pushnew is bad for a number of reasons:

  1. This forces users to load the large cl-lib library when packages are initialized.
  2. cl-pushnew is not an autoloaded macro, so this will cause Emacs to fail to load packages if there is no other package or user config that is loading cl-lib.

Remove orderless-temporarily-change-separator

This command is only one of many ways to interactively change the separator. Besides prompting for the new separator, like this command does, you could toggle between two choices, cycle among a list of many, popup a hydra of choices, use the top of the kill-ring or some register, etc. It seems a matter of personal preference.

Probably choosing one particular way of interactively changing the separator and putting it in the package is a bad idea. Specially since I would guess the most popular thing is to not change the separator interactively at all, and people who do change it interactively probably have a fixed set of choices. A better option is to document various methods of interactively changing the separator on the Wiki.

So I've marked this function as obsolete and have created this issue, to have a location for comments on the matter.

EDIT: orderless now includes a variable called orderless-transient-component-separator intended to make writing such commands much easier.

Remove the icomplete suggestion from the readme

I just had a bug report where someone configured orderless as in your README, basically copying it verbatim, activating icomplete and then activating selectrum at the same time. Is it necessary to recommend icomplete in the example config? Ideally the example configs we provide should be such that they just work if copied verbatim. This is at least what I am trying to do 😄

Filtering via matching against metadata-strings/programmable predicates

These are just some ideas for discussion, no real feature request.

I wonder if we could have a possibility to filter based on metadata attached to candidates? Candidates could have a property 'candidate-metadata which could then be matched on using some special syntax. The downside is that this would introduce a heavy implicit dependency on the metadata format.

Alternatively I can experiment with some consult internal completion style similar to consult--async-split and add a consult-specific metadata filtering syntax. Maybe the only command where this is useful is consult-buffer? But one could also see it as some in-band generalization of the current Consult narrowing.

Another question is if it is possible to add metadata filtering capabilities to existing commands. For example describe-variable could have a special filter "type:c" to show only custom variables. But I have no idea what the best way is to add such special filtering expressions to given commands. I probably would not like to see too much special casing in orderless. Maybe something could be done based on the completion category?

cc @clemera

orderless+initialism doesn't work

I tried to add the following recommended config from the README on a vanilla install of orderless:

(orderless-define-completion-style orderless+initialism
  (orderless-matching-styles '(orderless-initialism
                               orderless-literal
                               orderless-regexp)))
(setq completion-category-overrides
      '((command (styles orderless+initialism))
        (symbol (styles orderless+initialism))))

but this doesn't seem to actually add initialism matching to e.g. M-x or C-h f (tested with dk for describe-key).

Issue completing ssh hostnames when using orderless

When using orderless and find-file and I type /ssh:, the completions I get are /scp: and /scpx:, expected to see a list of hostnames prefixed with /ssh:.

Repro

Versions

orderless-0.6
emacs-28.0.50

Steps

Create /tmp/init.el containing:

(require 'orderless)
(setf completion-styles '(orderless))

Run emacs -Q -l /tmp/init.el and call find-file and type /ssh: and press tab. It should just give /scp: and /scpx: as completions.

Run emacs -Q do the same and you should see a list of known hosts.

Adding Orderless to GNU ELPA

I'm hoping to add Orderless to GNU ELPA at some point and to this end I just signed the FSF copyright assignment papers. I believe all contributors whose lines added and deleted sum to more than 8 have also signed the papers except perhaps for @noctuid. So, @noctuid, have you already done the FSF copyright assignment? And if not, would you be willing to do so?

Empty pattern should compile to empty regexp list

This optimization plays a role for consult-ripgrep as long as you only enter "#grep" without a filter expression. The speed up is noticeable with many candidates. Where can we add this optimization to the pattern compiler? Short-circuit on empty/white-space-only input strings?

Orderless breaks some functions

Hi, I've been using Orderless for a while and I love it, however there have been a few minor annoyances. Specifically, I used to be able to type in ev-b for eval-buffer, but now, Orderless expands ev-b to switch-to-prev-buffer. I'm not even sure what type of solution I'm looking for, but is there a completion style I'm not aware of that could help this?

Unused lexical variable warning

Not sure if this is significant, but FYI doom issues the following warning:

In toplevel form:
autoloads.28.0.50.el:698:168: Warning: Unused lexical variable
    ‘orderless-match-faces’

Error in post-command-hook (vertico--exhibit): (void-function orderless-highlight-matches)

cc: @minad (vertico author)


Thanks for your package!

I got Error in post-command-hook (vertico--exhibit): (void-function orderless-highlight-matches) and minibuffer doesn't work anyway...

Repro steps

  1. Save below snipet as ~/.debug.emacs.d/vertico-sample/init.el
;;; init.el --- Sample clean init.el  -*- lexical-binding: t; -*-

;; ~/.debug.emacs.d/orderless/init.el

;; you can run like 'emacs -q -l ~/.debug.emacs.d/orderless/init.el'
(let ((this-file (or (bound-and-true-p byte-compile-current-file)
                     load-file-name
                     buffer-file-name)))
  (setq user-emacs-directory
        (expand-file-name (file-name-directory this-file))))

(custom-set-variables
 '(package-archives '(("org"   . "https://orgmode.org/elpa/")
                      ("melpa" . "https://melpa.org/packages/")
                      ("gnu"   . "https://elpa.gnu.org/packages/"))))

(package-initialize)
(package-refresh-contents)

(setq debug-on-error t)

(unless (package-installed-p 'vertico)
  (package-install 'vertico))

(vertico-mode 1)

(unless (package-installed-p 'orderless)
  (package-install 'orderless))

(setq completion-styles '(orderless))
  1. cd ~/.debug.emacs.d/vertico-sample
  2. rm -rf elpa && emacs -q -l ~/.debug.emacs.d/vertico-sample/init.el
  3. C-x C-f then press e.
  4. see error like below scrrenshot (I cannot get stacktrace. Please tell me if you know how to get it)
    Screenshot_2021-06-26_14-32-06

Additional note 1

I have no idea but when I start Emacs again (with orderless and vertico installed), the minibuffer works fine.

  1. rm -rf elpa && emacs -q -l ~/.debug.emacs.d/vertico-sample/init.el
  2. C-x C-f then press e.
  3. see the error.
  4. C-x C-c to exit Emacs
  5. emacs -q -l ~/.debug.emacs.d/vertico-sample/init.el
  6. C-x C-f then press e.
  7. Minibufer works well.

Additional note 2

I have no idea too, but when I fix init.el like this (install orderless before enabling vertico-mode), minibuffer error has gone and works well.

;;; init.el --- Sample clean init.el  -*- lexical-binding: t; -*-

;; ~/.debug.emacs.d/orderless/init.el

;; you can run like 'emacs -q -l ~/.debug.emacs.d/orderless/init.el'
(let ((this-file (or (bound-and-true-p byte-compile-current-file)
                     load-file-name
                     buffer-file-name)))
  (setq user-emacs-directory
        (expand-file-name (file-name-directory this-file))))

(custom-set-variables
 '(package-archives '(("org"   . "https://orgmode.org/elpa/")
                      ("melpa" . "https://melpa.org/packages/")
                      ("gnu"   . "https://elpa.gnu.org/packages/"))))

(package-initialize)
(package-refresh-contents)

(setq debug-on-error t)

(unless (package-installed-p 'vertico)
  (package-install 'vertico))
(unless (package-installed-p 'orderless)
  (package-install 'orderless))

(vertico-mode 1)
(setq completion-styles '(orderless))

Orderless should use first token for prefix filtering

When using capf, the backend completion table may ignore the prefix string and only use it to trigger completion (and not for filtering). An example given by @astoff is \cite{title TAB and then the returned results do not necessarily match the prefix, the backend could return \cite{ref1}.

(defun test-capf ()
  (list
   (save-excursion
     (backward-word)
     (point))
   (point)
   (lambda (str pred action)
     (message "CALLED %S %S" str action)
     (setq str "") ;; NOTE: Backend ignores the prefix!
     (complete-with-action action '("a1" "a2" "a3" "a4"
                                    "b1" "b2" "b3" "b4"
                                    "c1" "c2" "c3" "c4")
                           str pred))))

(add-to-list 'completion-at-point-functions #'test-capf)

When using the style with a well-behaving "backend" like a list of strings, then the prefix is not ignored and matched as usual against the candidates. Maybe it makes sense to implement a separate prefix+orderless style? This style could then be used mainly for capf, where it seems most useful.

Prefix filtering in eglot

If one looks at eglot, it does not actually ignore the prefix but matches it against a filterText as returned by the server.

https://github.com/joaotavora/eglot/blob/fc221c8b8af33363a6a8d1e07950dc01555f6c9b/eglot.el#L2227-L2234

Probably in the case where the server returns items which do not actually match the prefix, the filterText then contains the prefix such that the items are not filtered out? At least this is what @astoff's server seems to do:

https://github.com/astoff/digestif/blob/b5b57b520752f4c2a9ee4dd9aca9ecdc6aa62a31/digestif/langserver.lua#L255

Toy completion style to play around with

(defun toy-all-completions (str table pred _point)
  (let* ((parts (split-string str nil t))
         (completion-regexp-list (mapcar #'regexp-quote (cdr parts)))
         (completions (all-completions (or (car parts) "") table pred)))
    (and completions (nconc completions 0))))

(defun toy-try-completion (str table pred _point)
  ;; (let* ((parts (split-string str nil t))
  ;;        (completion-regexp-list (mapcar #'regexp-quote (cdr parts)))
  ;;        (completion (try-completion (or (car parts) "") table pred)))
  ;;   (if (stringp completion)
  ;;       (cons completion (length completion))
  ;;     completion)))
  (car (split-string str nil t))
  )

(add-to-list 'completion-styles-alist
             '(toy
               toy-try-completion toy-all-completions
               "Toy completion."))

cc minad/corfu#5

SPC before existing group takes point to end of input

For this description, consider _ to mean the point.

I type i plet_. Then M-b to i _plet. Here an SPC takes me to i  plet_ (double space in between).

Screenshot at 2020-04-17 06-40-41

Screenshot at 2020-04-17 06-40-55

Not sure this is a bug given the whole point of orderless. Just noting the behaviour.

Orderless matching for `org-set-tags-command`

Hi Omar, you weren't very active on github any more so I hope you are doing well,

I discovered that orderless matching does not work with org-set-tags-command and multiple tags. You get completion for the first tag only. I have tested it with emacs -Q (emacs-version 26.3, org-version 9.3.6) and completion-styles set to orderless:

#+tags: some tags to test

* Test                                                                :test:

When you press C-c C-q with the point on the headline and afterwards press TAB inside the minibuffer you will get [no match]. With the default completion-styles the completion buffer pops up showing the available tags.

Tag a new release?

There hasn’t been a new for release for about a year, there has also
been some changes to the core API, like renaming
‘orderless-default-pattern-compiler’ to ‘orderless-pattern-compiler’,
which has caused the vertico package to complain. I think it might be
time to tag a new release :)

Performance regression due to accessing completion-category-overrides

Since d1c0cbf, there seems to be a major performance regression of the pattern compiler. When running consult-line, entering a search term and then scrolling over the candidates in Selectrum by pressing <down>, the scrolling gets slower and slower. I did some profiling and the main culprit is orderless-default-pattern-compiler which eats up 80% of the time.

orderless negative matching style

You have this ! matcher in your config. Would it be possible to add sth like this to orderless by default? Basically a not-matching style. Right now I am using a simple dispatcher which dispatches based on suffix ~ to flex and to literal with =.

Dynamic candidate set filtering

I am experimenting with dynamic candidate sets. This is used in consult for the consult-buffer function which filters the virtual buffer candidates. If you press "b SPC" you are only shown buffers etc. @clemera wrote a minimal example which works in icomplete, but it does not in my usual init.el config where I have orderless.

This is the example:

(let ((colla '("this" "is" "the" "colla"))
      (collb '("now" "showing" "collb")))
  (defun test (str pred action)
    (if (eq action 'metadata)
        `(metadata
          (cycle-sort-function . identity)
          (display-sort-function . identity))
      (let ((coll (cond ((string-prefix-p "a " str)
			 colla)
			((string-prefix-p "b " str)
			 collb)
			(t
			 (append colla collb)))))
	(cond ((null action)
	       (cond ((or (string-prefix-p "a " str)
			  (string-prefix-p "b " str))
		      (concat (substring str 0 2)
			      (try-completion (substring str 2) coll pred)))
		     (t (try-completion str coll pred))))
	      ((eq action t)
	       (all-completions
		(cond ((or (string-prefix-p "a " str)
			   (string-prefix-p "b " str))
		       (substring str 2))
		      (t str))
		coll pred))
	      (t nil))))))

(define-key minibuffer-local-completion-map (kbd "SPC") 'self-insert-command)

(completing-read "Check: " 'test)

See radian-software/selectrum#235 (comment) for context.

Breaks `icomplete-vertical' resize and obscures candidates

Thank you for publishing this!

When given a list of candidates:

Screenshot at 2020-04-14 06-48-43

A failed match will not shrink the minibuffer (as per resize-mini-windows t):

Screenshot at 2020-04-14 06-48-53

The above also throws: Error in post-command-hook (icomplete-post-command-hook): (wrong-type-argument listp 0)

From that point, deleting the mismatching input and hitting SPC will automatically expand the first match, as if that were the only one:

Screenshot at 2020-04-14 06-50-26

But from that point, hitting TAB (minibuffer-complete) will actually cycle through the candidates even though they are not visible.

Using your icomplete-vertical, though all of the above except minibuffer-resizing apply to the horizontal layout.

Ivy integration (can make pr)

Would you be willing to add functions that can be used directly to support integration with ivy? I've already written them and can make a PR (they are very short). If not would the readme or wiki be better?

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.