• Stars
    star
    762
  • Rank 59,625 (Top 2 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created about 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“œ marginalia.el - Marginalia in the minibuffer

marginalia.el - Marginalia in the minibuffer

GNU Emacs GNU ELPA GNU-devel ELPA MELPA MELPA Stable

This package provides marginalia-mode which adds marginalia to the minibuffer completions. Marginalia are marks or annotations placed at the margin of the page of a book or in this case helpful colorful annotations placed at the margin of the minibuffer for your completion candidates. Marginalia can only add annotations to the completion candidates. It cannot modify the appearance of the candidates themselves, which are shown unaltered as supplied by the original command.

The annotations are added based on the completion category. For example find-file reports the file category and M-x reports the command category. You can cycle between more or less detailed annotators or even disable the annotator with command marginalia-cycle.

Configuration

It is recommended to use Marginalia together with either the Vertico, Mct, Icomplete or the default completion UI. Furthermore Marginalia can be combined with Embark for action support and Consult, which provides many useful commands.

;; Enable rich annotations using the Marginalia package
(use-package marginalia
  ;; Bind `marginalia-cycle' locally in the minibuffer.  To make the binding
  ;; available in the *Completions* buffer, add it to the
  ;; `completion-list-mode-map'.
  :bind (:map minibuffer-local-map
         ("M-A" . marginalia-cycle))

  ;; The :init section is always executed.
  :init

  ;; Marginalia must be actived in the :init section of use-package such that
  ;; the mode gets enabled right away. Note that this forces loading the
  ;; package.
  (marginalia-mode))

Information shown by the annotators

In general, to learn more about what different annotations mean, a good starting point is to look at marginalia-annotator-registry, and follow up to the annotation function of the category you are interested in.

For example the annotations for Elisp symbols include their symbol class - v for variable, f for function, c for command, etc. For more information on what the different classifications mean, see the docstring of marginalia--symbol-class.

Adding custom annotators or classifiers

IMPORTANT NOTICE FOR PACKAGE AUTHORS: The intention of the Marginalia package is to give the user means to overwrite completion categories and to add custom annotators for existing commands in their user configuration. Marginalia is a user facing package and is not intended to be used as a library. Therefore Marginalia does not expose library functions as part of its public API. If you add your own completion commands to your package we recommend to specify an annotation-function or an affixation-function, avoiding the Marginalia dependency this way. The annotation-function and affixation-function are documented in the Elisp manual. If you use consult--read, you can specify an :annotate keyword argument. There is an exception to our recommendation: If you want to implement annotations for an existing package hypothetic.el, which does not have annotations and where annotations cannot be added, then the creation of a marginalia-hypothetic.el package is a good idea, since Marginalia provides the facilities to enhance existing commands from the outside. If you have questions feel free to ask on the Marginalia issue tracker.

Commands that support minibuffer completion use a completion table of all the available candidates. Candidates are associated with a category such as command, file, face, or variable depending on what the candidates are. Based on the category of the candidates, Marginalia selects an annotator to generate annotations for display for each candidate.

Unfortunately, not all commands (including Emacs’ builtin ones) specify the category of their candidates. To compensate for this shortcoming, Marginalia hooks into the Emacs completion framework and runs the classifiers listed in the variable marginalia-classifiers, which use the command’s prompt or other properties of the candidates to specify the completion category.

For example, the marginalia-classify-by-prompt classifier checks the minibuffer prompt against regexps listed in the marginalia-prompt-categories alist to determine a category. The following is already included but would be a way to assign the category face to all candidates from commands with prompts that include the word β€œface”.

(add-to-list 'marginalia-prompt-categories '("\\<face\\>" . face))

The marginalia-classify-by-command-name classifier uses the alist marginalia-command-categories to specify the completion category based on the command name. This is particularly useful if the prompt classifier yields a false positive.

Completion categories are also important for Embark, which associates actions based on the completion category and benefits from Marginalia’s classifiers.

Once the category of the candidates is known, Marginalia looks in the marginalia-annotator-registry to find the associated annotator to use. An annotator is a function that takes a completion candidate string as an argument and returns an annotation string to be displayed after the candidate in the minibuffer. More than one annotator can be assigned to each each category, displaying more, less or different information. Use the marginalia-cycle command to cycle between the annotations of different annotators defined for the current category.

Here’s an example of a basic face annotator:

(defun my-face-annotator (cand)
  (when-let (sym (intern-soft cand))
    (concat (propertize " " 'display '(space :align-to center))
            (propertize "The quick brown fox jumps over the lazy dog" 'face sym))))

Look at Marginalia’s various annotators for examples of formatting annotations. In particular, the helper function marginalia--fields can be used to format information into columns.

After defining a new annotator, associate it with a category in the annotator registry as follows:

(add-to-list 'marginalia-annotator-registry
             '(face my-face-annotator marginalia-annotate-face builtin none))

This makes the my-face-annotator the first of four annotators for the face category. The others are the annotator provided by Marginalia (marginalia-annotate-face), the builtin annotator as defined by Emacs and the none annotator, which disables the annotations. With this setting, after invoking M-x describe-face RET you can cycle between all of these annotators using marginalia-cycle.

Disabling annotators, builtin or lightweight annotators

Marginalia activates rich annotators by default. Depending on your preference you may want to use the builtin annotators or even no annotators by default and only activate the annotators on demand by invoking marginalia-cycle.

In order to use the builtin annotators by default, you can use the following command. Replace builtin by none to disable annotators by default.

(defun marginalia-use-builtin ()
  (interactive)
  (mapc
   (lambda (x)
     (setcdr x (cons 'builtin (remq 'builtin (cdr x)))))
   marginalia-annotator-registry))

If a completion category supports two annotators, you can toggle between those using this command.

(defun marginalia-toggle ()
  (interactive)
  (mapc
   (lambda (x)
     (setcdr x (append (reverse (remq 'none
                                      (remq 'builtin (cdr x))))
                       '(builtin none))))
   marginalia-annotator-registry))

After cycling the annotators you may want to automatically save the configuration. This can be achieved using an advice which calls customize-save-variable.

(advice-add #'marginalia-cycle :after
            (lambda ()
              (let ((inhibit-message t))
                (customize-save-variable 'marginalia-annotator-registry
                                         marginalia-annotator-registry))))

In order to disable an annotator permanently, the marginalia-annotator-registry can be modified. For example if you prefer to never see file annotations, you can delete all file annotators from the registry.

(setq marginalia-annotator-registry
      (assq-delete-all 'file marginalia-annotator-registry))

Icons in the minibuffer

Icons in the minibuffer completion UI are a commonly requested feature. Marginalia focuses on text annotations only. The following packages are compatible with Marginalia and use special fonts to add icons in front of completion candidates. There also exist related packages to enhance Dired, Ibuffer and other modes with icons consistently.

  • all-the-icons-completion: Relies on the all-the-icons.el package which configures multiple icon fonts.
  • nerd-icons-completion: Relies on patched fonts including icons. This package works even in the terminal where only a single font can be used.

Contributions

Since this package is part of GNU ELPA contributions require a copyright assignment to the FSF.

More Repositories

1

org-modern

πŸ¦„ Modern Org Style
Emacs Lisp
1,344
star
2

vertico

πŸ’« vertico.el - VERTical Interactive COmpletion
Emacs Lisp
1,344
star
3

consult

πŸ” consult.el - Consulting completing-read
Emacs Lisp
1,088
star
4

corfu

🏝️ corfu.el - COmpletion in Region FUnction
Emacs Lisp
1,000
star
5

cape

🦸cape.el - Completion At Point Extensions
Emacs Lisp
533
star
6

osm

🌍 osm.el - OpenStreetMap viewer for Emacs
Emacs Lisp
496
star
7

tempel

πŸ›οΈ TempEl - Simple templates for Emacs
Emacs Lisp
464
star
8

jinx

πŸͺ„ Enchanted Spell Checker
Emacs Lisp
328
star
9

affe

πŸ’ affe.el - Asynchronous Fuzzy Finder for Emacs
Emacs Lisp
202
star
10

lmdb

Ruby bindings for the OpenLDAP's Lightning Memory-Mapped Database (LMDB)
C
105
star
11

goggles

goggles.el - Pulse modified region
Emacs Lisp
92
star
12

bibsync

BibSync is a tool to synchronize scientific papers and bibtex bibliography files
Ruby
60
star
13

paripari

Fast parser combinator library for Haskell with two strategies (Fast acceptor and slower reporter with decent error messages)
Haskell
56
star
14

hasklig-mode

hasklig-mode.el - Hasklig ligatures for emacs
Emacs Lisp
39
star
15

gridslides

LaTeX package to create free form slides with blocks placed on a grid
TeX
38
star
16

3delta

Host software especially suited for delta 3d printers
Tcl
36
star
17

pacgem

Gem installer for Arch Linux
Ruby
34
star
18

bookmark-view

bookmark-view.el - Use bookmarks to persist the current view
Emacs Lisp
34
star
19

osm2shp

Convert large OpenStreetMap files to shapefiles (Uses sqlite3 db as temporary storage)
C++
29
star
20

consult-flycheck

Consult integration for Flycheck
Emacs Lisp
28
star
21

chasm

Java Bytecode Assembler and Disassembler which uses S-expressions
Java
26
star
22

tab-bookmark

Persist Emacs Tabs as Bookmarks
Emacs Lisp
25
star
23

unit

Unit support for numbers
Ruby
24
star
24

mini-popup

Emacs Lisp
22
star
25

gitrb

Unmaintained: Simple git implementation in ruby similar to grit, based on git_store
Ruby
21
star
26

recursion-indicator

Recursion indicator for the mode-line
Emacs Lisp
20
star
27

henk

pure type system language - henk 2000 ported to megaparsec, pretty
Haskell
20
star
28

persist

Minimal binary serialization library with focus on performance
Haskell
17
star
29

rack-embed

Rack middleware which embeds small images as base64 data-url in css/html files if the browser supports it
Ruby
16
star
30

polyp

Emacs Lisp
12
star
31

writer-cps-mtl

Stricter drop in replacements for WriterT and RWST
Haskell
11
star
32

intro

Safe and minimal Haskell Prelude
Haskell
10
star
33

writer-cps-transformers

Compatibility package for old transformers: Stricter drop in replacements for WriterT and RWST
Haskell
10
star
34

wl-pprint-annotated

Wadler/Leijen pretty printer with annotations and API conforming to modern Haskell
Haskell
7
star
35

uchronia

uchronia.el - Rewrite the minibuffer history
Emacs Lisp
7
star
36

tasty-stats

Collect statistics of your Tasty testsuite
Haskell
7
star
37

tasty-auto

Deprecated: Auto discovery for the Tasty test framework, use tasty-discover instead
Haskell
6
star
38

quickcheck-special

Edge cases and special values for QuickCheck Arbitrary instances
Haskell
5
star
39

thinkpad-tools

Unmaintained: Some scripts used on my Thinkpad X60t
Python
5
star
40

typohero

TypoHero enhances your typography
Ruby
5
star
41

diascope

Unmaintained: S5: A Simple Standards-Based Slide Show System. Alternative implementation using jquery
JavaScript
5
star
42

colorful-monoids

colorful-monoids: Styled console text output using ANSI escape sequences
Haskell
4
star
43

9mount

Unmaintained fork of http://sqweek.dnsdojo.org/hg/9mount
C
4
star
44

omega

Haskell
4
star
45

distcc

distcc scripts
4
star
46

evaluator

Mathematical expression evaluator for infix notation. Supports variables and functions.
Ruby
3
star
47

xosdbar

show osd on X11, similar to osd_cat but with update support
C
3
star
48

wl-pprint-console

Wadler/Leijen pretty printer with annotations and support for colorful console output
Haskell
3
star
49

andromeda.hs

This is a direct port of Andrej Bauer's dependent type theory implementation from OCaml to Haskell
Haskell
3
star
50

mapgen

XCSoar Map Generator
Python
3
star
51

vle

Verilog Experiments
Verilog
3
star
52

console-style

Styled console text output using ANSI escape sequences
Haskell
3
star
53

analyzer

Some tools for physics calculations
C++
3
star
54

doxygen2adoc

Doxygen import for Asciidoc using XSLT and the Doxygen XML output
XSLT
3
star
55

ihs

Interpolated Haskell
LLVM
3
star
56

bigint-unboxed

JavaScript big integers with support for ES6 BigInt and unboxed small integers
JavaScript
2
star
57

special-values

Haskell
2
star
58

hashtable

Hashtable in C with open addressing and specialization via macros
C
2
star
59

i3-config

qubes i3 configuration
Shell
2
star
60

TaskList

Mediawiki plugin which implements a task tracker
PHP
2
star
61

implant

Linux from scratch package manager using symlinks - similar to GoboLinux (2008)
Shell
2
star
62

hexns

Nameserver for IPv6 which resolves Hexspeak subdomains
C
2
star
63

emacs-theme

Emacs Lisp
2
star
64

arch-packages

My arch pkbuilds
Shell
2
star
65

temple-mustache

Temple-based implementation of Mustache (Just a finger exercises to test temple)
Ruby
2
star
66

encode-string

String encoding and decoding in Haskell
Haskell
2
star
67

writer-cps-monads-tf

Stricter drop in replacements for WriterT and RWST
Haskell
2
star
68

slim-examples

http://slim-lang.com/
Ruby
2
star
69

imaginator

Unmaintained: Image generator for LaTex/graphviz source
Ruby
1
star
70

safe-convert

Safe type conversions in Haskell
Haskell
1
star
71

echoxul

echo2 java web app + xul (2006)
Java
1
star
72

persist-state

Haskell
1
star
73

strict-base

Strict versions of some standard Haskell data types
Haskell
1
star
74

writer-cps-full

Stricter drop in replacements for WriterT and RWST
Haskell
1
star
75

writer-cps-exceptions

Control.Monad.Catch instances for CPS WriterT and RWST monad transformers
Haskell
1
star
76

grouptsp

Travelling salesman (2004)
Java
1
star
77

pasty

easy to deploy, single file, under 50 line, command line pastebin
PHP
1
star
78

arduino-pi-gefrickel

Arduino/Rasberry Pi Gefrickel - Arduino/Rasberry Pi Fiddling
JavaScript
1
star
79

intro-prelude

Reexport Intro as Prelude
Haskell
1
star
80

os-experiment

simple i386 os with console and multithreading (2005)
C
1
star