Coder Social home page Coder Social logo

dangduc / fzf-native Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 5.0 369 KB

Emacs package for fuzzy match scoring

License: GNU General Public License v3.0

CMake 3.84% C 81.16% Emacs Lisp 14.43% Makefile 0.35% Shell 0.23%
building-block emacs emacs-lisp emacs-package fuzzy fuzzy-matching native c99

fzf-native's Introduction

fzf-native

https://github.com/dangduc/fzf-native/actions/workflows/test.yaml/badge.svg https://github.com/dangduc/fzf-native/actions/workflows/cmake.yaml/badge.svg https://github.com/dangduc/fzf-native/actions/workflows/format.yaml/badge.svg

This is a package that provides fuzzy match scoring based on the fzf algorithm by junegunn. The main contribution is a wrapper over the C implementation of fzf from the project telescope-fzf-native.nvim. Elisp functions for scoring are exported through an Emacs dynamic module.

This package does one thing – For a given STR and QUERY compute and return a score and matching indices. If you’re looking for a fuzzy auto-completion engine, see the Use Cases section for how this package can be used in a completion-style.

;; Example of basic usage
(fzf-native-score "Hot-Topic" "hp")
;; (41 0 6)
;; Example of no match
(fzf-native-score "Hot-Topic" "2")
;; (0)
;; Example of slab re-use
(let ((slab (fzf-native-make-default-slab)))
  (fzf-native-score "Hello World" "er" slab)
  (fzf-native-score "Example of slab re-use" "xu" slab))
;; (24 1 19)

See test cases for more examples.

Supported Platforms

Linux, macOS (incl. Apple silicon), and Windows are supported. Pre-built shared libraries are in the bin/ directory.

Installation

MELPA

Not yet on MELPA.

Manually

Clone / download this repository and modify your load-path:

(add-to-list 'load-path (expand-file-name "/path/to/fzf-native/" user-emacs-directory))

Straight Examples

; Configuration that builds dynamic module locally.
(use-package fzf-native
  :straight
  (:repo "dangduc/fzf-native"
   :host github
   :files (:defaults "*.c" "*.h" "*.txt"))
  :init
  (setq fzf-native-always-compile-module t)
  :config
  (fzf-native-load-own-build-dyn))
; Configuration that uses pre-built dynamic module.
(use-package fzf-native
  :straight
  (:repo "dangduc/fzf-native"
   :host github
   :files (:defaults "bin"))
  :config
  (fzf-native-load-dyn))

Multibyte character support

Work around the lib’s lack of support for multibyte chars. Add this advice if you want accurate indices for multibyte chars. Don’t add this advice if you want better run time performance or you don’t need accurate indices for multibyte chars.

(advice-add 'fzf-native-score :around #'fzf-native--fix-score-indices)

Use Cases

Fussy: fzf-native is used as one of several choose-your-own scoring backends in fussy, a package that provides a completing-style for intelligent matching and sorting.

Building the Native Libraries

mkdir build && cmake -B build -DCMAKE_C_FLAGS='-O3 -march=native' && cmake --build build

Credit

All credit for fzf.c goes to the telescope-fzf-native.nvim project. Much credit for Emacs module binding code goes to the hotfuzz project.

fzf-native's People

Contributors

buzztaiki avatar dangduc avatar jojojames avatar whoshuu avatar

Stargazers

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

Watchers

 avatar  avatar

fzf-native's Issues

Extend CI to support building bin/ module files

Module files, e.g. fzf-native-module.so, are built and checked into bin/ sporadically, depending on which machine I/we happen to work at and whether we remember to check-in. This means that the bin/ files are always trailing (far) behind source on a file-by-file basis.

Could we have the CI build and check-in the dynamic module files?

Also would be nice to support building for Wndows (e.g. fzf-native-module.dll).

markdown--face-p is prioritized over facep for facp pattern

It seems the algorithm of fzf-native is not exactly what fzf or skim have.

(fzf-native-score "facep" "facp") --> (93 0 1 2 4)
(fzf-native-score "markdown--face-p" "facp") --> (100 10 11 12 15)

I checked both fzf and skim - they both select facep.

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.