I made a small revision on an old codes of mine, which converts a prolog term into an executable emacs-lisp expression. Here is some self-explanatory sample queries:
% ?- elisp:term_to_lisp_string(f(), X).
%@ X = "(f )" .
% ?- elisp:term_to_lisp_string(list(1,2,3), X).
%@ X = "(list 1 2 3 )" .
% ?- elisp:term_to_lisp_string(progn(a, b, c), X).
%@ X = "(progn a b c )" .
% ?- elisp:term_to_lisp_string(cond([a,b],[b,c]), X).
%@ X = "(cond (a b )(b c ))" .
% ?- elisp:term_to_lisp_string(defun(f, [a,b], +(a, b)), X).
%@ X = "(defun f (a b )(+ a b ))" .
This converter is used in my “emacs-prolog” on top of emacs-lisp, which works fine for basic editing region of emacs buffer.
It is straightforward to use this converter for handling emacs buffer by calling functions in emacs-lisp. Details is lengthy, so should be omitted here.
% ?- elisp:lisp(sort(list(4, 8, 21, 17, 33, 7, 21, 7), #(>)), V).
['V'=[33,21,21,17,8,7,7,4]]
% ?- elisp:lisp(+(1, 2, 3), Y).
['Y'=6]
% ?- elisp:lisp(setq(uuu, +(1,2,3)), V).
['V'=6]
% ?- elisp:lisp(progn(setq(uuu, +(1,2,3)), *(uuu, uuu)), V).
['V'=36]
# is for `quote`.
% ?- elisp:lisp(append(cons(#(x),#([a,b])), #([u,v])), R).
['R'=[x,a,b,u,v]]
% # is reserved for quote.
term_to_tokens(X, ['('|Y], Z):- is_list(X), !,
term_to_tokens_with_closing(X, Y, Z).
term_to_tokens(X, [X0|Y], Y):- atom(X), !, atom_string(X, X0).
term_to_tokens(X, [X0|Y], Y):- atomic(X), !, term_string(X, X0).
term_to_tokens(#(X), Y, Z) :- term_to_tokens([quote, X], Y, Z).
term_to_tokens(X, Y, Z) :-
compound_name_arguments(X, F, Args),
term_to_tokens([F|Args], Y, Z).
term_to_tokens_with_closing([], [')'|Y], Y).
term_to_tokens_with_closing([A|B], X, Y):- term_to_tokens(A, X, Z),
term_to_tokens_with_closing(B, Z, Y).
I am afraid that at this time of modern technology, “emacs-prolog” is obsolete or deprecated. Although Pcemacs sounds close to the emacs-prolog. Unfortunately it seems not work
on GnuEmacs.