Calling emacs from Prolog

Author(s): The CLIP Group.

This library provides a prolog-emacs interface. This interface is complementary to (and independent from) the emacs mode, which is used to develop programs from within the emacs editor/environment. Instead, this library allows calling emacs from a running Prolog program. This facilitates the use of emacs as a “user interface” for a Prolog program. Emacs can be made to:

  • Visit a file, which can then be edited.

  • Execute arbitrary emacs lisp code, sent from Prolog.

In order for this library to work correctly, the following is needed:

  • You should be running the emacs editor on the same machine where the executable calling this library is executing.

  • This emacs should be running the emacs server. This can be done by including the following line in your .emacs file:

    ;; Start a server that emacsclient can connect to.
    (server-start)
    

    Or typing M-x server-start within emacs.

This suffices for using emacs to edit files. For running arbitrary code the following also needs to be added to the .emacs file:

(setq enable-local-eval t)
Allows executing lisp code without asking.

(setq enable-local-eval nil)
Does not allow executing lisp code without asking.

(setq enable-local-eval 'maybe)
Allows executing lisp code only if user agrees after asking (asks interactively for every invocation).

Examples:

Assuming that a .pl file loads this library, then:

..., emacs_edit('foo'), ...
Opens file foo for editing in emacs.

..., emacs_eval_nowait("(run-ciao-toplevel)"), ...
Starts execution of a Ciao top-level within emacs.


Usage and interface

Documentation on exports

PREDICATE

Usage:

  • Description: Opens the given file for editing in emacs. Waits for editing to finish before continuing.
  • The following properties should hold at call time:
    (emacs:filename/1)Arg1 is an atom which is the name of a file.

PREDICATE

Usage:

  • Description: Opens the given file for editing in emacs and continues without waiting for editing to finish.
  • The following properties should hold at call time:
    (emacs:filename/1)Arg1 is an atom which is the name of a file.

PREDICATE

Usage:

  • Description: Executes in emacs the lisp code given as argument. Waits for the command to finish before continuing.
  • The following properties should hold at call time:
    (emacs:elisp_string/1)Arg1 is a string containing emacs lisp code.

PREDICATE

Usage:

  • Description: Executes in emacs the lisp code given as argument and continues without waiting for it to finish.
  • The following properties should hold at call time:
    (emacs:elisp_string/1)Arg1 is a string containing emacs lisp code.

REGTYPE

Usage: elisp_string(L)

  • Description: L is a string containing emacs lisp code.