Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Fuzzy matching for `company-mode'

License

NotificationsYou must be signed in to change notification settings

jcs-elpa/company-fuzzy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: GPL v3JCS-ELPAMELPAMELPA Stable

company-fuzzy

Fuzzy matching for `company-mode'.

CI

Pureelisp fuzzy completion forcompany-mode. This plugin search throughall the buffer localcompany-backends and fuzzy search all candidates.

🏆 Features

  • Work across all backends - Any backend that gives list of string should work.
  • Only uses nativeelisp code - I personally don't prefer any externalprogram unless is necessary.
  • Combined all backends to one backend - Opposite tocompany-try-hard,hence all possible candidates will be shown in the auto-complete menu.

🧪 Differences from other alternatives

  • company-ycmd
    • Usesycmd as backend to provide functionalities.
    • Quite hard to config properly.
  • company-flx
    • Uses libraryflx. (Optional for us)
    • Only works withcapf backend currently.

💾 Quickstart

(use-package company-fuzzy:hook (company-mode. company-fuzzy-mode):init  (setq company-fuzzy-sorting-backend'flx        company-fuzzy-reset-selectiont        company-fuzzy-prefix-on-topnil        company-fuzzy-trigger-symbols '(".""->""<""\"""'""@")))

🔧 Usage

You can enable it globally by adding this line to your config

(global-company-fuzzy-mode1)

Or you can just enable it in any specific buffer/mode you want.

(company-fuzzy-mode1)

Make sure you have called either of these functions after allcompany-backends are set and config properly. Because this plugin willreplace all backends to this minor mode specific backend (basically take allbackends away, so this mode could combine all sources and do the fuzzy work).

🔍 Sorting/Scoring backend

There are multiple sorting algorithms for auto-completion. You can choose yourbackend by customizing thecompany-fuzzy-sorting-backend variable like this.

(setq company-fuzzy-sorting-backend'alphabetic)

Currently supports these values,

  • none - Gives you the raw result.
  • alphabetic - Sort in the alphabetic order. (VSCode)
  • flex - Use libraryflex as matching engine.
  • flx - Use libraryflx as matching engine. (Sublime Text)
  • flx-rs - Use libraryflx-rs as matching engine. (Sublime Text)
  • flxy - Use libraryflxy as matching engine.
  • fuz-skim - Use libraryfuz.el's skim algorithm.
  • fuz-clangd - Use libraryfuz.el's clangd algorithm.
  • fuz-bin-skim - Use libraryfuz-bin's skim algorithm.
  • fuz-bin-clangd - Use libraryfuz-bin's clangd algorithm.
  • liquidmetal - Use libraryliquidmetal similar toQuicksilver algorithm.
  • sublime-fuzzy - Use librarysublime-fuzzy as matching engine. (Sublime Text)

Or implements your sorting algorithm yourself? Assgin the function tocompany-fuzzy-sorting-function variable like this.

(setq company-fuzzy-sorting-function (lambda (candidates)                                       (message"%s" candidates)                                       candidates)); Don't forget to return the candidaites!

🔍 Prefix On Top

If you wish the prefix matechs on top of all other selections, customizethis variable tot like the line below.

(setq company-fuzzy-prefix-on-topt)

P.S.If you setcompany-fuzzy-sorting-backend to'flx thenyou probably don't need this to be on because theflx scoring enginealready takes care of that!

🔍 For annotation

You can togglecompany-fuzzy-show-annotation for showing annotation or not.

(setq company-fuzzy-show-annotationt)

You can also customize annotation using theformat variable.

  • company-fuzzy-annotation-format => <%s>

🔍 Excluding

You can customize variablecompany-fuzzy-passthrough-backends to exclude someof the backends from polluting the fuzzy matching.

(setq company-fuzzy-passthrough-backends '(company-capf))

P.S. This is designed to be used with semantic backends, likelsp-mode(usescompany-capf), oreglot, etc.

💬 Details

Sincecompany grants most control to users, every company backend developerhas a different method of implementing the company backend. It is hard to manageall backends to one by various rules.

🔍 Reset the selection

If you are using an intelligent fuzzy matching algorithm, it is more intuitiveto reset the selected candidate to the first candidate.

(setq company-fuzzy-reset-selectiont)

Recommended Settings

The company has designed something oddly to achieve this. The plugin operatessmoothly, and I suggest configuring these company variables.

(use-package company:init  (setq company-require-matchnil; Don't require match, so you can still move your cursor as expected.        company-tooltip-align-annotationst; Align annotation to the right side.        company-eclim-auto-savenil; Stop eclim auto save.        company-dabbrev-downcasenil); No downcase when completion.:config;; Enable downcase only when completing the completion.  (defunjcs--company-complete-selection--advice-around (fn)"Advice execute around`company-complete-selection' command."    (let ((company-dabbrev-downcaset))      (call-interactively fn)))  (advice-add'company-complete-selection:around#'jcs--company-complete-selection--advice-around))

P.S.For the full configuration, you can check out my configurationhere.

❓ FAQ

💫 Why iscompany-fuzzy not working?

Try to log out thecompany-backends and make surecompany-fuzzy-all-other-backendsis the only backend in your list. If it's not, enablecompany-fuzzy-mode to swapout all backends and hand it over tocompany-fuzzy to manage it.

(message"%s" company-backends); '(company-fuzzy-all-other-backends)(message"%s" company-fuzzy--backends); .. backends has been handed over to `company-fuzzy`

💫 When should I callcompany-fuzzy-mode?

You should callcompany-fuzzy-mode after you have done configuredvariablecompany-backends.

(setq company-backends '(company-capf company-yasnippets); configure backends.. (other configuration)(company-fuzzy-mode1); enable fuzzy matching at the very last

💫 What if I want to add backends to specificmajor-mode?

You can add any backends as long as you callcompany-fuzzy-mode at the very endof your mode hook. You can log out variablecompany-fuzzy--backends and see whatbackends are currently handled bycompany-fuzzy-mode!

Or, you can hack through by configuring variablecompany-fuzzye--backends directlybut this is not recommended since after you disablecompany-fuzzy-mode it willnot be restored back tocompany-backends. Unless you change it with variablecompany-fuzzy--recorded-backends simutamiously so it can be restored back toyourcompany-backends' true form.

UPDATE: You can now use the following functions to accomplish these tasksin a much elegant way:

(company-fuzzy-backend-add'company-capf)(company-fuzzy-backend-remove'company-yasnippets)

💫 Why do some candidates aren't showing up?

This can cause by various reasons. The common causes are:

🔎 1. Cause by Semantic backend rules

company-fuzzy respects backends' rule. Meaning the candidates can be restrictedby the backend you are using. For example,

(defvarmy-variable); You declare a variable(my-vari.. ); but you are trying to use the variable as a function

Themy-variable would not show up since the backend thinks it should be afunction and not a variable.

🔎 2. Cause bycompletion-styles

Candidates are first filtered by Emacs built-on completion engine. Try tweakingthe variablecompletion-styles with other possible options.

(setq completion-styles '(partial-completion))

Or hook up with the company's hooks:

(add-hook'company-completion-started-hook          (lambda ()            (setq completion-styles '(partial-completion))))(add-hook'company-after-completion-hook          (lambda ();; Revert`completion-styles' to original values            (setq completion-styles ..)))

SeeCompletion Alternativesfor more information.

🔎 3. Scores lower than 0

Another cause would be the candidate has been eliminated by the scoring engine(it scores lower than 0); hence it would not be shown.

Best way to debug this, is to feedquery andcandidate to the scoringfunctions. The following example usesflx:

(flx-score"window-system""win-sys"); return score and it's match data

Another example using theliquidmetal:

(liquidmetal-score"window-system""win-sys"); return score

💫 Why are some variables not respected with special symbols? (@,:, etc)

company-fuzzy detects prefix depends on theSyntax Table. And those special symbols normally doesn't get treated as a whole prefix,hence you should see the completion get inserted incorrectly,

<!-- Try to complete `:link:` emoji-->:lin<!-- WRONG, the symbol `:` colon doesn't count as a prefix-->::link:

How to solve this? You should configure your syntax table by doing somethingsimilar to

(add-hook'markdown-mode-hook (lambda () (modify-syntax-entry?:"w"))

See related issue#22(ruby-mode with@ symbol).

🛠️ Contribute

PRs WelcomeElisp styleguideDonate on paypalBecome a patron

If you would like to contribute to this project, you may eitherclone or make pull requests to this repository. Or you canclone the project and establish your branch of this tool.Any methods are welcome!

🔬 Development

To run the test locally, you will need the following tools:

Install all dependencies and development dependencies:

eask install-deps --dev

To test the package's installation:

eask packageeask install

To test compilation:

eask compile

🪧 The following steps are optional, but we recommend you follow these lint results!

The built-incheckdoc linter:

eask lint checkdoc

The standardpackage linter:

eask lint package

📝 P.S. For more information, find the Eask manual athttps://emacs-eask.github.io/.

⚜️ License

This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.

This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.

You should have received a copy of the GNU General Public Licensealong with this program. If not, seehttps://www.gnu.org/licenses/.

SeeLICENSE for details.


[8]ページ先頭

©2009-2025 Movatter.jp