Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dangduc/fzf-native
Emacs package for fuzzy match scoring
https://github.com/dangduc/fzf-native
building-block c99 emacs emacs-lisp emacs-package fuzzy fuzzy-matching native
Last synced: 3 days ago
JSON representation
Emacs package for fuzzy match scoring
- Host: GitHub
- URL: https://github.com/dangduc/fzf-native
- Owner: dangduc
- License: gpl-3.0
- Created: 2022-06-01T06:30:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-24T18:12:35.000Z (about 2 months ago)
- Last Synced: 2024-12-24T19:21:58.716Z (about 2 months ago)
- Topics: building-block, c99, emacs, emacs-lisp, emacs-package, fuzzy, fuzzy-matching, native
- Language: C
- Homepage:
- Size: 1.21 MB
- Stars: 17
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+TITLE: fzf-native
#+STARTUP: noindent[[https://github.com/dangduc/fzf-native/actions/workflows/test.yaml][https://github.com/dangduc/fzf-native/actions/workflows/test.yaml/badge.svg]]
[[https://github.com/dangduc/fzf-native/actions/workflows/cmake.yaml][https://github.com/dangduc/fzf-native/actions/workflows/cmake.yaml/badge.svg]]
[[https://github.com/dangduc/fzf-native/actions/workflows/format.yaml][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 [[https://github.com/junegunn][junegunn]]. The main
contribution is a wrapper over the C implementation of fzf from the
project
[[https://github.com/nvim-telescope/telescope-fzf-native.nvim][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~.#+begin_src emacs-lisp
;; Example of basic usage
(fzf-native-score "Hot-Topic" "hp")
;; (41 0 6)
#+end_src#+begin_src emacs-lisp
;; Example of no match
(fzf-native-score "Hot-Topic" "2")
;; (0)
#+end_src#+begin_src emacs-lisp
;; 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)
#+end_srcSee [[fzf-native-test.el][test cases]] for more examples.
** Supported Platforms
Linux, macOS (incl. Apple silicon), and Windows are supported.
Pre-built shared libraries are in the [[bin][bin/]] directory.** Installation
*** MELPA
Not yet on MELPA.
*** Manually
Clone / download this repository and modify your ~load-path~:
#+begin_src emacs-lisp
(add-to-list 'load-path (expand-file-name "/path/to/fzf-native/" user-emacs-directory))
#+end_src*** Straight Examples
#+begin_src emacs-lisp
; 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))
#+end_src#+begin_src emacs-lisp
; 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))
#+end_src*** 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.#+begin_src emacs-lisp
(advice-add 'fzf-native-score :around #'fzf-native--fix-score-indices)
#+end_src** Use Cases
[[https://github.com/jojojames/fussy][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
#+begin_src bash
mkdir build && cmake -B build -DCMAKE_C_FLAGS='-O3 -march=native' && cmake --build build
#+end_src** Debugging fzf-native with emacs/lldb (EXAMPLE)
*** Building Emacs
#+begin_src shell :tangle yes
cd Code/emacs
brew install autoconf automake pkg-config ncurses gnutls libjpeg libgif libtiff libxpm libx11 libxt libxml2
autoreconf -isvf
./autogen.sh
./configure CFLAGS="-g -O0" LDFLAGS="-g" --with-ns
make bootstrap
#+end_src :tangle yes
*** Building fzf-native
#+begin_src shell :tangle yes
$ pwd
~/.emacs.d/packages/emacs_31/elpaca/repos/fzf-native
$ rm -Rf build; mkdir build && cmake -B build -DCMAKE_C_FLAGS='-O0 -g -march=native' && cmake --build build
#+end_src
*** From LLDB
#+begin_src shell :tangle yes
$ pwd
~/Code/emacs/src
$ lldb --local-lldbinit ./emacs
#+end_src
*** From Emacs
Refer to https://github.com/svaante/dape?tab=readme-ov-file#c-c-and-rust---lldb-dap
on how to install LLDB-dap.#+begin_src sh :tangle yes
$ brew install llvm
($(brew --prefix --installed llvm)/bin) # PREPEND (OSX already has a binary on $PATH) to $PATH.
#+end_src#+begin_src emacs-lisp :tangle yes
(use-package dape
:init
;; Enable repeat mode for more ergonomic `dape' use
(use-package repeat
:ensure nil
:config
(repeat-mode))
:config
(push
'(lldb-dap
modes (c-mode c-ts-mode c++-mode c++-ts-mode)
command "lldb-dap"
command-args ["--local-lldbinit"]
ensure dape-ensure-command
:type "lldb-dap"
:cwd "/Users/james/Code/emacs/src"
:program "/Users/james/Code/emacs/src/emacs")
dape-configs)
;; Turn on global bindings for setting breakpoints with mouse
(dape-breakpoint-global-mode)
;; Info buffers to the right
(setq dape-buffer-window-arrangement 'right)
;; Info buffers like gud (gdb-mi)
(setq dape-buffer-window-arrangement 'gud)
(setq dape-info-hide-mode-line nil)
;; Pulse source line (performance hit)
(add-hook 'dape-display-source-hook 'pulse-momentary-highlight-one-line)
;; Showing inlay hints
(setq dape-inlay-hints t)
;; Save buffers on startup, useful for interpreted languages
(add-hook 'dape-start-hook (lambda () (save-some-buffers t t)))
;; Kill compile buffer on build success
(add-hook 'dape-compile-hook 'kill-buffer)
;; Projectile users
(setq dape-cwd-fn 'projectile-project-root));; M-x dape in fzf-native-module.c
;; Set breakpoints with mouse.
#+end_src** Credit
All credit for fzf.c goes to the
[[https://github.com/nvim-telescope/telescope-fzf-native.nvim][telescope-fzf-native.nvim]]
project. Much credit for Emacs module binding code goes to the
[[https://github.com/axelf4/hotfuzz][hotfuzz]] project.