1/* Part of Refactoring Tools for SWI-Prolog 2 3 Author: Edison Mera 4 E-mail: efmera@gmail.com 5 WWW: https://github.com/edisonm/refactor 6 Copyright (C): 2017, Process Design Center, Breda, The Netherlands. 7 All rights reserved. 8 9 Redistribution and use in source and binary forms, with or without 10 modification, are permitted provided that the following conditions 11 are met: 12 13 1. Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 16 2. Redistributions in binary form must reproduce the above copyright 17 notice, this list of conditions and the following disclaimer in 18 the documentation and/or other materials provided with the 19 distribution. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 POSSIBILITY OF SUCH DAMAGE. 33*/ 34 35:- module(ref_replay, 36 [ apply_command_q/1, 37 rdelete/1, 38 rlist/0, 39 rlist/1, 40 rnostats/0, 41 rrewind/0, 42 rrewind/1, 43 rstats/0, 44 rundo/0 45 ]). 46 47:- use_module(library(lists)). 48:- use_module(library(listing)). 49:- use_module(library(ref_changes), 50 [ pending_change/1, 51 undo_changes/1]). 52:- use_module(library(ref_msgtype)). 53:- use_module(library(ref_command)).
63:- meta_predicate apply_command_q( ).
67% Execute Call and associated such call with an index for further management 68% of such Call. 69 70apply_command_q(Call) :- 71 apply_command(Call), 72 once(pending_change(Index)), 73 message_type(Type), 74 print_message(Type, format('Saved changes in index ~w', [Index])).
81rstats :-
82 retractall(rstats_db),
83 assertz(rstats_db).
91rnostats :-
92 retractall(rstats_db).
98rlist :-
99 \+ ( rlist(_),
100 fail
101 ).
108rlist(Index) :-
109 pending_command(Index, Command),
110 with_output_to(string(SCommand), portray_clause(Command)),
111 print_message(information, format('Index ~w, Command: ~s', [Index, SCommand])).
119rrewind :-
120 rrewind(0).
126rrewind(Index) :-
127 findall(Command, ( pending_command(Index1, Command),
128 Index1 > Index,
129 rdrop(Index1, _)
130 ),
131 CommandR),
132 reverse(CommandR, CommandL),
133 maplist(apply_command, CommandL).
139rundo :-
140 rundo(_).
146rdelete(Index) :-
147 rundo(Index),
148 rrewind(Index).
155rundo(Index) :-
156 rdrop(Index, Command),
157 print_message(information, format('Undone ~w ---> ~w', [Index, Command])).
164rdrop(Index, Command) :-
165 undo_changes(Index),
166 undo_command(Index, Command)
Individual pending changes management
This library provides tools to manage individual elements of the stack of pending changes of the refactoring tool. The pending changes are indexed by a sequential number, so that you can use such index in such predicates.
*/