Git Product home page Git Product logo

affe's Introduction

affe.el - Asynchronous Fuzzy Finder for Emacs

GNU Emacs MELPA MELPA Stable

This package provides an asynchronous fuzzy finder similar to the fzf command-line fuzzy finder, written in pure Elisp. A producer process is started in the background, e.g., find, fd or ripgrep. The output produced by this process is filtered by an external asynchronous Emacs process. The Emacs UI always stays responsive since the work is off-loaded to other processes. The results are presented in the minibuffer using Consult, which allows to quickly select from the available items.

Installation and Configuration

The package is available on MELPA and can be installed using the Emacs package manager. If files should not be automatically previewed, a manual preview key should be set for affe-grep.

(use-package affe
  :config
  ;; Manual preview key for `affe-grep'
  (consult-customize affe-grep :preview-key (kbd "M-.")))

The default regular expression transformation of Consult is limited. It is recommended to configure Orderless as affe-regexp-compiler in Consult.

;; -*- lexical-binding: t -*-
(defun affe-orderless-regexp-compiler (input _type)
  (setq input (orderless-pattern-compiler input))
  (cons input (lambda (str) (orderless--highlight input str))))
(setq affe-regexp-compiler #'affe-orderless-regexp-compiler)

Affe requires the find and ripgrep command line programs to be available. The producer processes can be customized by adjusting the variables affe-find-command and affe-grep-command.

Available commands

  • affe-grep: Filters the content of all text files in the current directory, similar to consult-grep.
  • affe-find: Filters the file paths of all files in the current directory, similar to consult-find.

Related packages

Affe depends on Consult and works best with the Vertico completion UI.

  • Consult: Useful search and navigation commands (Dependency of Affe).
  • Marginalia: File annotations in the minibuffer.
  • Embark: Minibuffer actions on files.
  • Orderless: Advanced completion style, can be plugged together with Affe.
  • Vertico, Selectrum or Icomplete-vertical: Vertical completion systems (Icomplete-vertical is only needed for Emacs 27, built-in on Emacs 28)

Details

The Affe frontend transforms the input string to a list of regular expressions by calling the affe-regexp-function. The regular expressions are passed to the Affe backend via the emacsclient protocol. The backend controls a producer process, which generates lines of text. The lines are filtered using the regular expressions submitted by the frontend. For performance reasons, all-completions is used for the filtering. The backend returns only a limited amount of matching candidates, hopefully the most plausible ones. The frontend calls the affe-highlight-function on the returned matches, to highlight the input pattern.

Affe uses a more primitive matching technique than fzf, which uses the Smith-Waterman algorithm. Affe does not perform any ranking or sorting; it matches the lines in the order returned by the producer process against a list of regular expressions. On the upside, this allows plugging Affe together with the Orderless completion style, which can give a consistent fuzzy filtering experience across all Emacs commands, including synchronous and asynchronous commands.

As possible enhancement of Affe, one could implement alphabetical and sorting by length in the backend. By using a bucket sorting technique the sorting complexity will stay sufficiently linear such that the performance impact should be acceptable. However implementing a scoring-based sorting is probably not feasible since this requires heavier computations in Elisp. But maybe nativecomp Emacs is a game changer here?

Alternatives

affe's People

Contributors

faerryn avatar minad avatar rajk04 avatar

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.