Public api

Initialisation

webmacs.main.init(opts)[source]

Default initialization of webmacs.

If a URL is given on the command line, this method opens it. Else, it tries to load the buffers that were opened the last time webmacs has exited. If none of that works, the default is to open a buffer with an url to the duckduck go search engine.

Also open the view maximized.

Parameters:opts – the result of the parsed command line.

Keymaps

webmacs.keymaps.keymap(name)[source]

Get a keymap given its name.

class webmacs.keymaps.Keymap(name, parent=None, doc=None)[source]
define_key(key, binding=None)

Define a binding (callable or command name) for a key chord.

Parameters:
  • key – a string representing the key chord, such as “C-c x”.
  • binding – A command name (a string), a callable, or None. If None, it must be used as a function decorator.
undefine_key(key)

Undefine the binding under a key chord.

Parameters:key – a string representing the key chord, such as “C-c x”.

Webjumps

webmacs.commands.webjump.define_webjump(name, url, doc='', complete_fn=None, protocol=False)[source]

Define a webjump.

A webjump is a quick way to access a URL, optionally with a variable section (for example a URL for a Google search). A function may be given to provide auto-completion.

Parameters:
  • name – the name of the webjump.
  • url – the url of the webjump. If the url contains “%s”, it is assumed that it has a variable part.
  • doc – associated documentation for the webjump.
  • complete_fn – a function that should create a suitable WebJumpCompleter to provide auto-completion, or None if there is no completion support for this webjump.
  • protocol – True if the webjump should be treated as the protocol part of a URI (eg: file://)
class webmacs.commands.webjump.WebJumpCompleter[source]

Provides auto-completion in webjumps.

An instance is created automatically when required, and lives while the webjump is active. When a key is entered in the minibuffer input, the method complete() is called with the current text, asking for completion.

The signal completed must then be emitted with the list of possible completions.

Note that there is no underlying thread in the completion framework.

abort()[source]

Called when the completion request should be aborted.

Subclasses should implement this if possible.

complete(text)[source]

Must be implemented by subclasses.

class webmacs.commands.webjump.WebJumpRequestCompleter(url_fn, extract_completions_fn)[source]

A completer that executes a Web request to provide completion.

This completer will not block the UI.

Parameters:
  • url_fn – a function that takes the text to complete, and returns a URL that will provide completion. The returned value can be none if no URL is suitable for the given text.
  • extract_completions_fn – a function that takes the bytes of the request reply, and must convert them to the completions (a string list).
class webmacs.commands.webjump.SyncWebJumpCompleter(complete_fn)[source]

A simple completer that provides completion given a function.

This completer will block the UI: use it with care.

Parameters:complete_fn – a function that takes the current string, and must return the possible completions as a list of strings.
webmacs.commands.webjump.define_webjump_alias(alias_name, webjump_name)[source]

Define an alias for an existing webjump.

The alias can then be used as a shortcut. :param alias_name: the name of the alias to be created. :param webjump_name: the name of the existing webjump.

Variables

webmacs.variables.set(name, value)[source]

Set a value for a variable.

Parameters:
  • name – the name of the variable.
  • value – the new value.
Raises:

KeyError if the variable does not exists, or VariableConditionError if the value is incorrect.

webmacs.variables.get(name)[source]

Returns the variable value.

Parameters:name – the name of the variable.
exception webmacs.variables.VariableConditionError[source]

Raised when a variable condition is not fulfilled