pyorg.emacs module

Interface with Emacs and run commands.

class pyorg.emacs.Emacs(cmd=('emacs', '--batch'), client=False, verbose=1)[source]

Bases: object

Interface to Emacs program.

cmd

Base command to run Emacs.

Type:str or list[str]
is_client

Whether the command runs emacsclient.

Type:bool
verbose

1 to echo stderr of Emacs command, 2 to echo stdout. 0 turns off.

Type:int
Parameters:
  • cmd (list[str]) – Base command to run Emacs.
  • client (bool) – Whether the command runs emacsclient.
  • verbose (int) – 1 to echo stderr of Emacs command, 2 to echo stdout. 0 turns off.
eval(source, process=False, **kwargs)[source]

Evaluate ELisp source code and return output.

Parameters:
  • source (str or list) – Elisp code. If a list of strings will be enclosed in progn.
  • process (bool) – If True return the subprocess.CompletedProcess object, otherwise just return the value of stdout.
  • kwargs – Passed to run().
Returns:

Command output or completed process object, depending on value of process.

Return type:

str or subprocess.CompletedProcess

getoutput(args, **kwargs)[source]

Get output of command.

Parameters:
  • args (list[str]) – List of strings.
  • kwargs – Passed to run().
Returns:

Value of stdout.

Return type:

str

getresult(source, is_json=False, **kwargs)[source]

Get parsed result from evaluating the Elisp code.

Parameters:
  • source (str or list) – Elisp code to evaluate.
  • is_json (bool) – True if the result of evaluating the code is already a string of JSON-encoded data.
Returns:

Return type:

Parsed value.

run(args, check=True, verbose=None)[source]

Run the Emacs command with a list of arguments.

Parameters:
  • args (list[str]) – List of strings.
  • check (bool) – Check the return code is zero.
  • verbose (int or None) – Overrides verbose attribute if not None.
Returns:

Return type:

subprocess.CompletedProcess

Raises:

subprocess.CalledProcessError – If check=True and return code is nonzero.

exception pyorg.emacs.EmacsException(src, stdout=None, stderr=None)[source]

Bases: Exception

An exception that occurred when trying to evaluate Elisp code in an emacs process.

classmethod from_calledprocess(src, cpe)[source]
pyorg.emacs.get_form(src)[source]

Get Elisp form from string, AST node, or sequence of these.

pyorg.emacs.get_forms_list(src)[source]

Get source as list of forms from string, AST node, or sequence of these.