35
36:- module(start_emacs,
37 [ emacs/0
38 , emacs/1 39 , start_emacs/0
40 , emacs_server/0
41 , emacs_toplevel/0
42 ]). 43:- use_module(library(pce)). 44:- require([ append/3
45 , maplist/3
46 , unix/1
47 ]). 48
49:- pce_autoload(emacs, library('emacs/emacs')). 50:- pce_autoload(emacs_view, library('emacs/emacs')). 51
52:- pce_global(@emacs_buffers, new(dict)).
53:- pce_global(@emacs, new(emacs(@emacs_buffers))).
70start_emacs :-
71 register_emacs,
72 ( object(@emacs)
73 -> true
74 ; in_pce_thread_sync(send(@emacs, start))
75 ).
83register_emacs :-
84 ( current_prolog_flag(editor, '$EDITOR')
85 -> set_prolog_flag(editor, pce_emacs)
86 ; true
87 ).
95emacs_server :-
96 start_emacs,
97 send(@pce, trap_errors, @off),
98 send(@pce, console_label, 'PceEmacs Server').
104emacs :-
105 start_emacs,
106 in_pce_thread((new(Scratch, emacs_buffer(@nil, '*scratch*')),
107 send(Scratch, open, tab))).
119emacs(File:Line:LinePos) :-
120 integer(Line),
121 integer(LinePos),
122 atom(File),
123 !,
124 start_emacs,
125 new(Loc, source_location(File, Line)),
126 send(Loc, attribute, linepos, LinePos),
127 in_pce_thread(send(@emacs, goto_source_location, Loc, tab)).
128emacs(File:Line) :-
129 integer(Line),
130 atom(File),
131 !,
132 start_emacs,
133 in_pce_thread(send(@emacs, goto_source_location,
134 source_location(File, Line), tab)).
135emacs(File) :-
136 atom(File),
137 !,
138 start_emacs,
139 in_pce_thread(send(@emacs, goto_source_location,
140 source_location(File), tab)).
141emacs(File) :-
142 domain_error(location, File).
149emacs_toplevel :-
150 send(@pce, trap_errors, @off),
151 current_prolog_flag(argv, Files),
152 ( Files = [_|_]
153 -> start_emacs,
154 maplist(make_buffer, Files, [B0|_]),
155 send(B0, open)
156 ; emacs
157 ).
158
159make_buffer(File, Buffer) :-
160 new(Buffer, emacs_buffer(File))
PceEmacs toplevel
This module provides predicates to start PceEmacs. PceEmacs is an clone of GNU-Emacs written in XPCE. Modes are XPCE classes that can be extended in Prolog.