Module _m.textadept.mime_types

Handles file-specific settings.

Overview

Files can be recognized and associated with programming language lexers in three ways:

  • By file extension.
  • By keywords in the file's shebang (#!/path/to/exe) line.
  • By a pattern that matches the file's first line.

If a lexer is not associated with a file you open, first make sure the lexer exists in lexers/. If it does not, you will need to write one. Consult the lexer module for a tutorial.

Configuration Files

Built-in mime-types are located in modules/textadept/mime_types.conf. You can override or add to them in your ~/.textadept/mime_types.conf.

Detection by File Extension

file_ext lexer

Note: file_ext should not start with a . (period).

Detection by Shebang Keywords

#shebang_word lexer

Examples of shebang_word's are lua, ruby, python.

Detection by Pattern

/pattern lexer

Only the last space, the one separating the pattern from the lexer, is significant. No spaces in the pattern need to be escaped.

Extras

This module adds an extra function to buffer:

  • buffer:set_lexer (language)
    Replacement for buffer:set_lexer_language().
    Sets a buffer._lexer field so it can be restored without querying the mime-types tables. Also if the user manually sets the lexer, it should be restored.
    Loads the language-specific module if it exists.
    • lang: The string language to set.

Functions

select_lexer () Prompts the user to select a lexer from a filtered list for the current buffer.

Tables

extensions File extensions with their associated lexers.
lexers List of detected lexers.
patterns First-line patterns and their associated lexers.
shebangs Shebang words and their associated lexers.


Functions

select_lexer ()
Prompts the user to select a lexer from a filtered list for the current buffer.

Tables

extensions
File extensions with their associated lexers.
lexers
List of detected lexers. Lexers are read from `lexers/` and `~/.textadept/lexers/`.
patterns
First-line patterns and their associated lexers.
shebangs
Shebang words and their associated lexers.

Valid XHTML 1.0!