Elisp: What's “feature”?

By Xah Lee. Date: . Last updated: .

Emacs's Concept of Feature

  1. features is a global variable that represent available features. Its value is a list of elisp symbols that are features (such as major modes, minor modes, lisp libs).
  2. A elisp package usually has (provide 'symbol_name) at the end. When this code is evaluated, emacs will add the symbol name to the features list.
  3. When the code (require 'symbol_name) is called, emacs checks if that symbol name is already in the features list. If not, load it. (emacs will guess a file name based on the symbol name. Or, the require function may specify a file name in the 2nd argument.)

For example, Alt+x describe-variable Enter features Enter. You'll see something like this:

ibuffer etags ring cc-mode cc-fonts cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs xlsl-mode encoded-kb speck sgml-mode dired info newcomment desktop recentf tree-widget wid-edit advice help-fns …

require and provide

The purpose of features is for emacs to know if a package is already loaded.

The features variable and the functions {provide, require}, is the mechanism.

The require function checks the features variable to see if a symbol is already there, if not, then load the file.

The provide function adds a symbol to the features list.

back to Elisp: require, load, load-file, autoload, feature

Writing Major Mode

  1. How to Write a Emacs Major Mode for Syntax Coloring
  2. Elisp: Font Lock Mode Basics
  3. Elisp: How to Define Face
  4. Elisp: How to Color Comment in Major Mode
  5. Elisp: How to Write Comment Command in Major Mode
  6. Elisp: How to Write Your Own Comment Command from Scratch
  7. Elisp: How to Write Keyword Completion Command
  8. Elisp: How to Create Keymap for Major Mode
  9. Elisp: Abbrev, Template, for Major Mode
  10. Elisp: Text Properties
  11. Elisp: Overlay Highlighting
  12. Emacs: Lookup Google, Dictionary, Documentation
  13. Elisp: Syntax Table Tutorial

  1. Elisp: How to Name Your Major Mode
  2. Elisp: What's “feature”?
  3. Elisp: require, load, load-file, autoload, feature

Syntax Table

  1. Elisp: Syntax Table Tutorial
  2. Elisp: How to Find Syntax of a Character?
  3. Elisp: How to Modify Syntax Table Temporarily
  4. Elisp: How to Determine If Cursor is Inside String or Comment
  5. Elisp: Regex Patterns and Syntax Table
  6. Elisp: Find Matching Bracket Character
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.