# QEmacs Documentation

# 1 Introduction

QEmacs (for Quick Emacs) is a very small but powerful UNIX editor. It has features that even big editors lack :

- Full screen editor with an Emacs look and feel with all Emacs common features: multi-buffer, multi-window, command mode, numeric argument, keyboard macros, config file with C like syntax, minibuffer with completion and history.
- Can edit files of hundreds of Megabytes without being slow by using a highly optimized internal representation and by mmaping the file.
- Full Unicode support, including multi charset handling (8859-x, UTF8, SJIS, EUC-JP, ...) and bidirectional editing respecting the Unicode bidi algorithm. Arabic and Indic scripts handling (in progress).
- WYSIWYG HTML/XML/CSS2 mode graphical editing. Also supports lynx like rendering on VT100 terminals.
- WYSIWYG DocBook mode based on XML/CSS2 renderer.
- C mode: coloring with immediate update. Emacs like auto-indent.
- Shell mode: colorized VT100 emulation so that your shell work exactly as you expect. Compile mode with next/prev error.
- Input methods for most languages, including Chinese (input methods come from the Yudit editor).
- Hexadecimal editing mode with insertion and block commands. Unicode hexa editing is also supported.
- Works on any VT100 terminals without termcap. UTF8 VT100 support included with double width glyphs.
- X11 support. Support multiple proportional fonts at the same time (as XEmacs). X Input methods supported. Xft extension supported for anti aliased font display.
- Small! Full version (including HTML/XML/CSS2/DocBook rendering and all charsets): 270KB big. Basic version (without bidir/unicode scripts/input/X11/C/Shell/HTML/dired): 88KB.

# 2 Invocation

    usage: qe [-h] [-nw] [-display display] [-geometry WxH]
              [-fs ptsize] [filename...]

‘`-h`’

  show help

‘`-nw`’

  force tty terminal usage

‘`-display display`’

  set X11 display to ’display’

‘`-geometry WxH`’

  set X11 display size

‘`-fs ptsize`’

  set default font size

When invoked as

    usage: ffplay

QEmacs goes to `dired` mode automatically so that you can browse your files easily (same as `C-x C-d` key).

# 3 Common editing commands

## 3.1 Concepts

QEmacs store file content in buffers. Buffers can be seen as big arrays of bytes.

An editing mode tells how to display the content of a buffer and how to interact with the user to modify its content.

Multiple Windows can be shown on the screen at the same time. Each windows show the content of a buffer with an editing mode. It means that you can open several windows which show the same buffer in different modes (for example, both text and hexadecimal).

Each key binding activates a command. You can directly execute a command by typing `M-x command RET`.

Commands can take arguments. The key binding `C-u N` where N is an optional number is used to give a numeric argument to the commands which can handle them. If the command cannot handle a numerical argument, it is simply repeated `N` times.

## 3.2 Help

You can press `C-h b` to have the list of all the currently active bindings, including the ones of the current editing mode.

    C-h C-h, F1             : help-for-help
    C-h b                   : describe-bindings
    C-h c                   : describe-key-briefly

## 3.3 Simple commands

    default                 : self-insert-command
    M-#                     : insert-char
    C-p, up                 : previous-line
    C-n, down               : next-line
    C-b, left               : backward-char
    C-f, right              : forward-char
    M-b, C-left             : backward-word
    M-f, C-right            : forward-word
    M-v, prior              : scroll-down
    C-v, next               : scroll-up
    M-z                     : scroll-down-one
    C-z                     : scroll-up-one
    home, C-a               : beginning-of-line
    end, C-e                : end-of-line
    insert                  : overwrite-mode
    C-d, delete             : delete-char
    backspace               : backward-delete-char
    M-<, C-home             : beginning-of-buffer
    M->, C-end              : end-of-buffer
    C-i                     : tabulate
    C-q                     : quoted-insert
    RET                     : newline
    C-o                     : open-line

## 3.4 Region handling, kill commands

    C-space                 : set-mark-command
    C-x C-x                 : exchange-point-and-mark
    C-x h                   : mark-whole-buffer
    M-C-w                   : append-next-kill
    C-k                     : kill-line
    C-w                     : kill-region
    M-w                     : copy-region
    C-y                     : yank
    M-y                     : yank-pop

## 3.5 Buffer and file handling

    C-x C-f                 : find-file
    C-x C-v                 : find-alternate-file
    C-x i                   : insert-file
    C-x C-s                 : save-buffer
    C-x C-w                 : write-file
    C-x w                   : write-region
    C-x b                   : switch-to-buffer
    C-x k                   : kill-buffer
    C-x C-b                 : list-buffers
    C-x C-q                 : toggle-read-only
    M-~                     : not-modified

## 3.6 Search and replace

    C-s                     : isearch-backward
    C-r                     : isearch-forward
    M-%                     : query-replace
    M-r                     : replace-string

## 3.7 Paragraph / case handling

    M-{                     : backward-paragraph
    M-}                     : forward-paragraph
    M-q                     : fill-paragraph
    M-l                     : downcase-word
    M-u                     : upcase-word
    C-x C-l                 : downcase-region
    C-x C-u                 : upcase-region

## 3.8 Command handling

    M-x                     : execute-command
    C-u                     : numeric-argument
    C-g                     : abort
    C-x u, C-_              : undo
    C-x (                   : start-kbd-macro
    C-x )                   : end-kbd-macro
    C-x e, C-\              : call-last-kbd-macro

## 3.9 Window handling

    C-x o                   : other-window
    C-x n                   : next-window
    C-x p                   : previous-window
    C-x 0                   : delete-window
    C-x 1                   : delete-other-windows
    C-x 2                   : split-window-vertically
    C-x 3                   : split-window-horizontally
    C-x f                   : toggle-full-screen

## 3.10 Help

    C-h C-h, f1             : help-for-help
    C-h b                   : describe-bindings
    C-h c, C-h k            : describe-key-briefly

## 3.11 International

    C-x RET f               : set-buffer-file-coding-system
    C-x RET b               : toggle-bidir
    C-x RET C-\             : set-input-method
    C-x C-\                 : switch-input-method

## 3.12 Process control

    C-x RET RET             : shell
    C-x C-e                 : compile
    C-x C-p                 : previous-error
    C-x C-n                 : next-error

## 3.13 Miscellaneous

    C-x C-c                 : exit-qemacs
    C-l                     : refresh
    M-g                     : goto-line
    C-x g                   : goto-char
    C-x l                   : count-lines
    C-x =                   : what-cursor-position
    C-x RET l               : toggle-line-numbers
    C-x RET t               : toggle-truncate-lines
    C-x RET w               : word-wrap
    C-x C-d                 : dired

# 4 Configuration file and resources

## 4.1 Resource path

All resources and configuration files are looked in the following paths: ‘`/usr/share/qe:/usr/local/share/qe:/usr/lib/qe:/usr/local/lib/qe:~/.qe`’

## 4.2 Configuration file

QEmacs tries to load a configuration file in ‘`~/.qe/config`’. Each line of the configuration file is a QEmacs command with a C like syntax (’-’ in command name can be replaced by ’_’).

Read the example file ‘`config.eg`’ to have some examples.

The following commands are useful:

`global_set_key(key, command)`

  Set a global key binding to a command.

`set_display_size(width, height)`

  (X11) Set the window size, in character cells.

`set_system_font(family, system_fonts)`

  (X11) Maps a system font to a QEmacs font family. Multiple fonts can be given as fallback (See section Fonts).

`set_style(stylename, css_property, css_value)`

  Set a colorization style (see ‘`qestyle.h`’ and ‘`config.eg`’ for common style names)

## 4.3 Plugins

Any ‘`.so`’ file found in the qemacs resource paths is considered as a plugin. It is a piece of code containing new features for qemacs.

Currently, no plugins are compiled in, but you can look at the ‘`plugins/`’ directory to learn how to make one.

Most QEmacs object files can in fact be compiled either as a plugin or be statically linked in qemacs. The plugin system is strongly inspirated from the Linux Kernel 2.4 module system.

# 5 Internationalization

## 5.1 Charsets

QEmacs supports many common charsets including UTF8, shift JIS and EUC-JP. A charset can be selected for each buffer with `C-x RET f` (`set-buffer-file-coding-system`).

Currently, QEmacs automatically detects the UTF8 encoding.

Note that unlike in other editors, changing the charset of a buffer does not modify its content: buffers always contain bytes, and the charset is only used when the buffer content may be converted to characters, for example to display it on screen.

You can use the UniHex editing mode (`M-x unihex-mode`) to see the Unicode values of each character in your file with the associated byte offset.

The command `convert-buffer-file-coding-system` can be used to convert the buffer content to another charset.

## 5.2 Input methods

The current input method can be changed with `C-x RET \` (`set-input-method`). You can switch between this input method and the default one with ’C-\’.

The input methods are currently stored in the resource file ‘`kmaps`’. They are extracted from the Yudit editor keyboard maps.

## 5.3 Bidirectional editing

QEmacs fully supports the Unicode bidi algorithm.

By default, in text editing mode, qemacs is not in bidirectional mode (it may change soon). You can use ’C-x RET b’ to toogle between bidi and normal editing modes.

In HTML editing mode, bidi is always activated and all the CSS2 bidi properties are supported.

## 5.4 Unicode scripts

Currently, QEmacs fully supports Arabic shapping. Devanagari shaping is on the way.

The resource file ‘`ligatures`’ contains all the standard Unicode rules to handle character modifiers such as accents. It means that even if your font does not support the Unicode character modifiers, QEmacs will do its best to handle them.

# 6 Editing Modes

## 6.1 C mode

This mode is currently activated by ‘`M-x c-mode`’. It is activated automatically when a C file is loaded.

## 6.2 Hexadecimal, ascii and unihex modes

Unlike other editors, QEmacs has powerful hexadecimal editing modes: all common commands are working these modes, including the block commands.

The hexadecimal mode (`M-x hex-mode`) shows both the hexa decimal and ascii (bytes) values. You can toggle between the hexa and ascii columns with ’TAB’.

The ascii mode (`M-x ascii-mode`) only shows the ascii column.

The unihex mode (`M-x unihex-mode`) shows both the unicode and glyph associated to each character of the buffer by using the current buffer charset.

You can change the line width in these modes with ’C-left’ and ’C-right’.

## 6.3 shell mode

You can activate it with `M-x shell`. Unlike other editors, a very complete colorized VT100 emulation is done [it means you can launch qemacs in the qemacs shell :-)].

By default, interactive mode is selected. It means that most keys you type are transmitted to the shell. This way, you can use the shell completion and editing functions. By pressing `C-o`, you toggle between interactive and editing mode. In editing mode, you can editing the shell buffer as any other buffer.

## 6.4 Dired mode

You can activate it with `C-x C-d`. You can open the selected directory with `RET` or `right`. `left` is used to go to the parent directory. The current selected is opened in the right window.

## 6.5 Bufed mode

You can activate it with `C-x C-b`. You can select with `RET` or `right` the current buffer.

## 6.6 XML mode

This mode is currently activated by `M-x xml-mode`. It is activated automatically when an XML file is loaded.

Currently, only specific XML colorization is done in this mode. Javascript (in SCRIPT tags) is colored as in C mode. CSS Style sheets (in STYLE tags) are colorized with a specific color.

## 6.7 Graphical HTML2/CSS mode

### 6.7.1 Usage

This mode is currently activated by `M-x html-mode`. It is activated automatically when an HTML file is loaded.

### 6.7.2 Features

The XML/HTML/CSS2 renderer has the following features:

- The parse errors are written in buffer ’*xml-error*’.
- Strict XML parser or relaxed mode for HTML pages.
- Letter case can be ignored or strictly respected.
- Integrated HTML to CSS2 converter so that the renderer do not depend on HTML quirks.
- Quite complete CSS2 support (including generated content and counters).
- Full Bidirectional Unicode support.
- Table support with both ’fixed’ and ’auto’ layout algorithms.
- ’tty’ and ’screen’ CSS2 medias are supported.

### 6.7.3 Known limitations

- Cannot load external resources (e.g. style sheets) from other files.
- No image handling (only a rectangle with ’ALT’ name is drawn).
- No javascript.
- No frames.

### 6.7.4 CSS property support

The following properties are partially (see comments) or totally supported:

- display: The value ’inline-block’ is a QEmacs extension.
- color
- background-color
- white-space: The value ’prewrap’ is a QEmacs extension.
- direction
- float
- font-family
- font-style
- font-weight
- font-size
- text-decoration
- text-align
- width
- height
- unicode-bidi
- border-width
- border-left-width
- border-top-width
- border-right-width
- border-bottom-width
- border-color
- border-left-color
- border-top-color
- border-right-color
- border-bottom-color
- border-style
- border-left-style
- border-top-style
- border-right-style
- border-bottom-style
- border
- border-left
- border-top
- border-right
- border-bottom
- padding
- padding-left
- padding-top
- padding-right
- padding-bottom
- margin
- margin-left
- margin-top
- margin-right
- margin-bottom
- clear
- overflow
- visibility
- table-layout
- vertical-align
- border-collapse
- border-spacing
- border-spacing-horizontal
- border-spacing-vertical
- line-height
- content
- caption-side
- marker-offset
- list-style-type
- column-span: QEmacs extension
- row-span: QEmacs extension
- content-alt: QEmacs extension. Same behavior as property ’content’ but used for images
- list-style-position
- counter-reset
- counter-increment
- bidi-mode: QEmacs extension: use lower/upper case to test bidi algorithm
- position: ‘`fixed`’ is not supported. Only ’block’ boxes are positionned
- top
- bottom
- left
- right

The following properties are completely unsupported:

- background
- background-attachment
- background-image
- background-position
- background-repeat
- clip
- cursor
- empty-cells
- font
- font-size-adjust
- font-stretch
- font-variant
- letter-spacing
- list-style
- list-style-image
- max-height
- max-width
- min-height
- min-width
- outline
- outline-color
- outline-style
- outline-width
- quotes
- text-indent
- text-shadow
- text-transform
- word-spacing
- z-index
- marks
- page
- page-break-after
- page-break-before
- page-break-inside
- size
- orphans
- widows
- azimuth
- cue
- cue-after
- cue-before
- elevation
- pause
- pause-after
- pause-before
- pitch
- pitch-range
- pitch-during
- richness
- speak
- speak-header
- speak-punctuation
- speak-rate
- stress
- voice-family
- volume

## 6.8 Graphical DocBook mode

This mode simply uses a different default style sheet from the HTML/CSS2 mode. It is activated by ‘`M-x docbook-mode`’.

## 6.9 Image mode

When compiling qemacs with FFmpeg support (http://ffmpeg.org), images can be viewed. The current implementation handles PNM, PAM, PNG, JPEG and GIF images (animated GIF images are handled as video data). `C-x C-d` can be used to have an interactive file viewer.

Available commands:

`t`

  (‘`M-x image-rotate`’) Rotate right image by 90 degrees.

`f`

  (‘`M-x toggle-full-screen`’) Toggle full screen mode

`c`

  (‘`M-x image-convert`’) Change the pixel format of the image (press tab to have a complete list). The data loss implied by the pixel format change is displayed.

`b`

  (‘`M-x image-set-background-color`’) Set the image background color. The background is only visible if the image contains transparent pixels. The ‘`transparent`’ color displayed a ‘`gimp`’ like grid.

Status information:

- The image resolution is displayed as ‘`NxM`’.
- The FFmpeg pixel format is displayed.
- ‘`I`’ is displayed is the image is interleaved.
- ‘`T`’ is displayed if the image contains transparent pixels. ‘`A`’ is displayed if the image contains semi-transparent pixels.

## 6.10 Audio/Video mode

When compiling qemacs with FFmpeg support (http://ffmpeg.org), video and audio files can be viewed. The X11 Xvideo extension is used if available for faster YUV rendering. `C-x C-d` can be used to have an interactive file viewer.

Audio only files are also rendered. The waveform is displayed at the same time.

No editing commands will be supported in that mode. Saving is currently not possible.

Available commands:

`SPC`
`p`

  Pause/Resume

`f`

  (‘`M-x toggle-full-screen`’) Toggle full screen mode

`v`

  (‘`M-x av-cycle-video`’) Cycle through available video channels.

`a`

  (‘`M-x av-cycle-audio`’) Cycle through available audio channels.

# 7 Fonts

## 7.1 VT100 display

In order to display Unicode characters, you must have a recent xterm from XFree version greater than 4.0.1.

As a short test, you can launch xterm with the following options to select UTF8 charset and a unicode fixed X11 font:

    xterm -u8 -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1

Then look at the qemacs TestPage in VT100 mode:

    qe -nw tests/TestPage.txt

If you are using latin scripts, you can use any fixed font in any terminal. Otherwise, if you use ideograms or other non latin scripts, you must configure your terminal emulator (usually xterm) to accept ’double width’ fonts. It means that some characters, such as ideograms, are meant to occupy two char cells instead of one. QEmacs knows that and does the text alyout accordingly.

The font Unifont is currently the best font for xterm. It is usually included in the linux distributions. You can find it at http://czyborra.com/unifont/.

## 7.2 X11 display

QEmacs knows three basic font families:

- ‘`sans`’ for sans serif fonts.
- ‘`serif`’ for serif fonts.
- ‘`fixed`’ for fixed or monospace fonts.

QEmacs maps these three families to system fonts. The default mapping is: ‘`helvetica`’ for sans, ‘`Times`’ for serif and ‘`fixed`’ for fixed.

For each family, you can specify any number of fallback fonts that QEmacs can use if the requested glyph is not found in the current font. Currently, the font ‘`unifont`’ is used as fallback in all cases.

You can use the command `set-system-font(family, fonts)` to change the default qemacs mapping. `family` is `sans`, `serif` or `fixed`, and `fonts` is a comma separated list of system fonts which are used as principal font and fallback fonts.

## 7.3 Internal QEmacs fonts

In the tool ‘`html2png`’, QEmacs uses internal fonts which are the ‘`Times`’, ‘`Helvetica`’ and ‘`Unifont`’ supplied in X11. They are highly compressed in the FBF font format.

# 8 Html2png Tool

## 8.1 Introduction

Html2png is a standalone HTML/XML/CSS2 renderer based on the QEmacs internal renderer. It takes an HTML or XHTML file as input and produce a PNG image file containing the graphical rendering of the page. It is meant to be a test tool for the renderer. It can also be used as a XML/HTML validator since all parse errors are logged on the standard output.

Unlike other HTML renderers, HTML2PNG do not have any dependency on the operating system or the graphical interface. It uses its own fonts (which are embedded in the executable), its own widgets and its own charset tables.

By using the highly compressed FBF font format, the Times, Helvetica and Unifont fonts are embedded in the executable. It means that HTML2PNG can view documents in any languages, including Arabic, Hebrew, Japanese and Hangul.

## 8.2 Invocation

    usage: html2png [-h] [-x] [-w width] [-o outfile] [-f charset] infile

‘`-h`’

  display the help

‘`-x`’

  use strict XML parser (xhtml type parsing)

‘`-w width`’

  set the image width (default=640)

‘`-f charset`’

  set the default charset (default=’8859-1’). Use -f ? to list supported charsets.

‘`-o outfile`’

  set the output filename (default=’a.png’)

# 9 Developper’s Guide

## 9.1 Plugins

You can use the example in ‘`plugins/`’ to develop dynamically linked qemacs plugins (aka modules).

Plugins can add any dynamic resource qemacs supports (modes, key bindings, ...). A plugin can be either statically linked or dynamically linked. Most of qemacs features are in fact statically linked plugins.

# About This Document

The buttons in the navigation panels have the following meaning:

Button | Name | Go to | From 1.2.3 go to
--- | --- | --- | ---
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1
[ < ] | Back | Previous section in reading order | 1.2.2
[ Up ] | Up | Up section | 1.2
[ > ] | Forward | Next section in reading order | 1.2.4
[ >> ] | FastForward | Next chapter | 2
[Top] | Top | Cover (top) of document |
[Contents] | Contents | Table of contents |
[Index] | Index | Index |
[ ? ] | About | About (help) |

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:

- 1. Section One
  - 1.1 Subsection One-One
    - ...
  - 1.2 Subsection One-Two
    - 1.2.1 Subsubsection One-Two-One
    - 1.2.2 Subsubsection One-Two-Two
    - 1.2.3 Subsubsection One-Two-Three <== Current Position
    - 1.2.4 Subsubsection One-Two-Four
  - 1.3 Subsection One-Three
    - ...
  - 1.4 Subsection One-Four