Home

Awesome

face-explorer - Library and tools for faces and text properties

Author: Anders Lindgren<br> Version: 0.0.4<br> URL: https://github.com/Lindydancer/face-explorer<br>

Library and tools for faces and text properties.

This library is useful for packages that convert syntax highlighted buffers to other formats. The functions can be used to determine how a face or a face text property looks, in terms of primitive face attributes (e.g. foreground and background colors). Two sets of functions are provided, one for existing frames and one for fictitious displays, like 8 color tty.

In addition, the following tools are provided:

Fictitious displays

Emacs supports a variety of displays, from graphical frames to terminals with 8 colors. Emacs itself provides query functions for existing displays. This library provides query functions for any kind of display, allowing you to play the "what if" game. (For example, how would a face look on a grayscale graphical display or an 8 color tty.)

It is possible to use the query functions for fictitious displays in batch mode, when the normal face and colors system are severely restricted.

Library functions

Function for existing frames:

Support for a fictitious display

The following variables defines a fictitious display. The face-explorer tools use the global variants of these variables. However, when calling the functions in the library, it's possible to dynamically bind them using let.

The following functions can be used to query face-related information for fictitious displays:

Face-related tools

This package provide a number of face-related tools. Most of them display information about a face both in the selected frame and as it would look on a fictitious display.

Key bindings

In the tool buffers, you can use the following keys to change the settings:

Face verifiers

The face-explorer-list-faces and face-explorer-describe-face tools warn about inappropriately defined faces. You can use the following keys to handle these warnings:

The face-explorer-list-faces tool

List all available faces. Like list-faces-display but with information on how a face is defined. In addition, a sample for the both the selected frame and for the current fictitious display is shown.

Additional keys:

The face-explorer-describe-face tool

Display information about a face. This includes:

The face-explorer-describe-face-prop tool

Display information about a face text property. This includes:

The face-explorer-list-display-features tool

Display a buffer contains text using specially constructed faces that will look differently depending on available display features. For example, if you run emacsclient -nw from a terminal, this buffer will look differently than it does in a graphical frame.

The face-explorer-list-face-prop-examples tool

List sample text with face text properties in various variants.

This is useful for two reasons:

The face-explorer-list-overlay-examples tool

List sample text with overlays in various variants.

The face-explorer-tooltip-mode tool

A minor mode that shows information about text properties and overlays in a tooltip.

This is enabled in all buffers displayed by the tools in this module.

face-explorer-tooltip-global-mode can be used to enable this mode for all buffers.

The face-explorer-simulate-display-mode tool

A minor mode used to show how the current buffer would look in a fictitious display. This can be used, for example, to check if a face theme would look good in a 8 color tty or in a grayscale graphical display.

The key bindings describe above above are available after the prefix <kbd>C-c !</kbd>.

Note: The mode will not restrict colors to the fictitious display. For example, if a face is defined as "red" it will be shown in red even when the fictitious display is set to mono or grayscale.

face-explorer-simulate-display-global-mode can be used to enable this mode for all buffers.

Vocabulary

Primitive face attributes

Normally, a face or face specification can be quite complex, for example a face can inherit from other faces and a face specification can contain several faces. "Primitive face attributes" corresponds to how the face or face specification will look to the user, the foreground and background color it has, whether it is bold or italic etc. Unspecified properties are not included. Properties like :height could be relative (like 1.2) or absolute (like 10). Primitive face attributes never contain the :inherit attribute.

Technical background

Face definitions

The attributes associated with a face can originate from the following locations:

Face aliases

The face-alias property of the face symbol can contain another symbol which the face is aliased to.

Distant foreground

A "distant foreground" is an alternative color used to render the foreground when the normal foreground color would be too close to the background. Unfortunately, there is no clear definition of what "too close" really means, so it is hard to simulate it. Currently, this package return both the :foreground and :distant-foreground attributes. Hopefully, in the future, it might be possible to deduce the color that is shown and use :foreground to represent that color.

Other Font Lock Tools

This package is part of a suite of font-lock tools. The other tools in the suite are:

Font Lock Studio

Interactive debugger for font-lock keywords (Emacs syntax highlighting rules).

Font Lock Studio lets you single-step Font Lock keywords -- matchers, highlights, and anchored rules, so that you can see what happens when a buffer is fontified. You can set breakpoints on or inside rules and run until one has been hit. When inside a rule, matches are visualized using a palette of background colors. The explainer can describe a rule in plain-text English. Tight integration with Edebug allows you to step into Lisp expressions that are part of the Font Lock keywords.

Font Lock Profiler

A profiler for font-lock keywords. This package measures time and counts the number of times each part of a font-lock keyword is used. For matchers, it counts the total number and the number of successful matches.

The result is presented in table that can be sorted by count or time. The table can be expanded to include each part of the font-lock keyword.

In addition, this package can generate a log of all font-lock events. This can be used to verify font-lock implementations, concretely, this is used for back-to-back tests of the real font-lock engine and Font Lock Studio, an interactive debugger for font-lock keywords.

Highlight Refontification

Minor mode that visualizes how font-lock refontifies a buffer. This is useful when developing or debugging font-lock keywords, especially for keywords that span multiple lines.

The background of the buffer is painted in a rainbow of colors, where each band in the rainbow represent a region of the buffer that has been refontified. When the buffer is modified, the rainbow is updated.

Faceup

Emacs is capable of highlighting buffers based on language-specific font-lock rules. This package makes it possible to perform regression test for packages that provide font-lock rules.

The underlying idea is to convert text with highlights ("faces") into a plain text representation using the Faceup markup language. This language is semi-human readable, for example:

«k:this» is a keyword

By comparing the current highlight with a highlight performed with stable versions of a package, it's possible to automatically find problems that otherwise would have been hard to spot.

This package is designed to be used in conjunction with Ert, the standard Emacs regression test system.

The Faceup markup language is a generic markup language, regression testing is merely one way to use it.

Font Lock Regression Suite

A collection of example source files for a large number of programming languages, with ERT tests to ensure that syntax highlighting does not accidentally change.

For each source file, font-lock reference files are provided for various Emacs versions. The reference files contains a plain-text representation of source file with syntax highlighting, using the format "faceup".

Of course, the collection source file can be used for other kinds of testing, not limited to font-lock regression testing.

History

Part of the code of this package was originally published as part of the package e2ansi, a package that can emit highlighted text to a terminal using ANSI sequences. e2ansi can be configured to be used with the command line command more and less to syntax highlight anything viewed using those command.


Converted from face-explorer.el by el2markdown.