version 1.1.1.1, 2014/07/30 08:16:45
|
version 1.1.1.2, 2021/03/17 01:01:01
|
Line 1
|
Line 1
|
/* readline.c -- a general facility for reading lines of input | /* undo.c - manage list of changes to lines, offering opportunity to undo them */ |
with emacs style editing and completion. */ | |
|
|
/* Copyright (C) 1987-2012 Free Software Foundation, Inc. | /* Copyright (C) 1987-2017 Free Software Foundation, Inc. |
|
|
This file is part of the GNU Readline Library (Readline), a library |
This file is part of the GNU Readline Library (Readline), a library |
for reading lines of text with interactive input and history editing. |
for reading lines of text with interactive input and history editing. |
Line 50
|
Line 49
|
#include "rlprivate.h" |
#include "rlprivate.h" |
#include "xmalloc.h" |
#include "xmalloc.h" |
|
|
extern void replace_history_data PARAMS((int, histdata_t *, histdata_t *)); | extern void _hs_replace_history_data PARAMS((int, histdata_t *, histdata_t *)); |
|
|
|
extern HIST_ENTRY *_rl_saved_line_for_history; |
|
|
/* Non-zero tells rl_delete_text and rl_insert_text to not add to |
/* Non-zero tells rl_delete_text and rl_insert_text to not add to |
the undo list. */ |
the undo list. */ |
int _rl_doing_an_undo = 0; |
int _rl_doing_an_undo = 0; |
Line 69 UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL;
|
Line 70 UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL;
|
/* **************************************************************** */ |
/* **************************************************************** */ |
|
|
static UNDO_LIST * |
static UNDO_LIST * |
alloc_undo_entry (what, start, end, text) | alloc_undo_entry (enum undo_code what, int start, int end, char *text) |
enum undo_code what; | |
int start, end; | |
char *text; | |
{ |
{ |
UNDO_LIST *temp; |
UNDO_LIST *temp; |
|
|
Line 89 alloc_undo_entry (what, start, end, text)
|
Line 87 alloc_undo_entry (what, start, end, text)
|
/* Remember how to undo something. Concatenate some undos if that |
/* Remember how to undo something. Concatenate some undos if that |
seems right. */ |
seems right. */ |
void |
void |
rl_add_undo (what, start, end, text) | rl_add_undo (enum undo_code what, int start, int end, char *text) |
enum undo_code what; | |
int start, end; | |
char *text; | |
{ |
{ |
UNDO_LIST *temp; |
UNDO_LIST *temp; |
|
|
Line 103 rl_add_undo (what, start, end, text)
|
Line 98 rl_add_undo (what, start, end, text)
|
|
|
/* Free an UNDO_LIST */ |
/* Free an UNDO_LIST */ |
void |
void |
_rl_free_undo_list (ul) | _rl_free_undo_list (UNDO_LIST *ul) |
UNDO_LIST *ul; | |
{ |
{ |
UNDO_LIST *release; |
UNDO_LIST *release; |
|
|
Line 122 _rl_free_undo_list (ul)
|
Line 116 _rl_free_undo_list (ul)
|
|
|
/* Free the existing undo list. */ |
/* Free the existing undo list. */ |
void |
void |
rl_free_undo_list () | rl_free_undo_list (void) |
{ |
{ |
UNDO_LIST *release, *orig_list; |
UNDO_LIST *release, *orig_list; |
|
|
orig_list = rl_undo_list; |
orig_list = rl_undo_list; |
_rl_free_undo_list (rl_undo_list); |
_rl_free_undo_list (rl_undo_list); |
rl_undo_list = (UNDO_LIST *)NULL; |
rl_undo_list = (UNDO_LIST *)NULL; |
replace_history_data (-1, (histdata_t *)orig_list, (histdata_t *)NULL); | _hs_replace_history_data (-1, (histdata_t *)orig_list, (histdata_t *)NULL); |
} |
} |
|
|
UNDO_LIST * |
UNDO_LIST * |
_rl_copy_undo_entry (entry) | _rl_copy_undo_entry (UNDO_LIST *entry) |
UNDO_LIST *entry; | |
{ |
{ |
UNDO_LIST *new; |
UNDO_LIST *new; |
|
|
Line 144 _rl_copy_undo_entry (entry)
|
Line 137 _rl_copy_undo_entry (entry)
|
} |
} |
|
|
UNDO_LIST * |
UNDO_LIST * |
_rl_copy_undo_list (head) | _rl_copy_undo_list (UNDO_LIST *head) |
UNDO_LIST *head; | |
{ |
{ |
UNDO_LIST *list, *new, *roving, *c; |
UNDO_LIST *list, *new, *roving, *c; |
|
|
Line 174 _rl_copy_undo_list (head)
|
Line 166 _rl_copy_undo_list (head)
|
/* Undo the next thing in the list. Return 0 if there |
/* Undo the next thing in the list. Return 0 if there |
is nothing to undo, or non-zero if there was. */ |
is nothing to undo, or non-zero if there was. */ |
int |
int |
rl_do_undo () | rl_do_undo (void) |
{ |
{ |
UNDO_LIST *release; | UNDO_LIST *release, *search; |
int waiting_for_begin, start, end; |
int waiting_for_begin, start, end; |
HIST_ENTRY *cur, *temp; |
HIST_ENTRY *cur, *temp; |
|
|
Line 204 rl_do_undo ()
|
Line 196 rl_do_undo ()
|
/* Undoing deletes means inserting some text. */ |
/* Undoing deletes means inserting some text. */ |
case UNDO_DELETE: |
case UNDO_DELETE: |
rl_point = start; |
rl_point = start; |
|
_rl_fix_point (1); |
rl_insert_text (rl_undo_list->text); |
rl_insert_text (rl_undo_list->text); |
xfree (rl_undo_list->text); |
xfree (rl_undo_list->text); |
break; |
break; |
Line 212 rl_do_undo ()
|
Line 205 rl_do_undo ()
|
case UNDO_INSERT: |
case UNDO_INSERT: |
rl_delete_text (start, end); |
rl_delete_text (start, end); |
rl_point = start; |
rl_point = start; |
|
_rl_fix_point (1); |
break; |
break; |
|
|
/* Undoing an END means undoing everything 'til we get to a BEGIN. */ |
/* Undoing an END means undoing everything 'til we get to a BEGIN. */ |
Line 233 rl_do_undo ()
|
Line 227 rl_do_undo ()
|
|
|
release = rl_undo_list; |
release = rl_undo_list; |
rl_undo_list = rl_undo_list->next; |
rl_undo_list = rl_undo_list->next; |
|
release->next = 0; /* XXX */ |
|
|
/* If we are editing a history entry, make sure the change is replicated |
/* If we are editing a history entry, make sure the change is replicated |
in the history entry's line */ |
in the history entry's line */ |
Line 245 rl_do_undo ()
|
Line 240 rl_do_undo ()
|
xfree (temp); |
xfree (temp); |
} |
} |
|
|
replace_history_data (-1, (histdata_t *)release, (histdata_t *)rl_undo_list); | /* Make sure there aren't any history entries with that undo list */ |
| _hs_replace_history_data (-1, (histdata_t *)release, (histdata_t *)rl_undo_list); |
|
|
|
/* And make sure this list isn't anywhere in the saved line for history */ |
|
if (_rl_saved_line_for_history && _rl_saved_line_for_history->data) |
|
{ |
|
/* Brute force; no finesse here */ |
|
search = (UNDO_LIST *)_rl_saved_line_for_history->data; |
|
if (search == release) |
|
_rl_saved_line_for_history->data = rl_undo_list; |
|
else |
|
{ |
|
while (search->next) |
|
{ |
|
if (search->next == release) |
|
{ |
|
search->next = rl_undo_list; |
|
break; |
|
} |
|
search = search->next; |
|
} |
|
} |
|
} |
|
|
xfree (release); |
xfree (release); |
} |
} |
while (waiting_for_begin); |
while (waiting_for_begin); |
Line 256 rl_do_undo ()
|
Line 273 rl_do_undo ()
|
#undef TRANS |
#undef TRANS |
|
|
int |
int |
_rl_fix_last_undo_of_type (type, start, end) | _rl_fix_last_undo_of_type (int type, int start, int end) |
int type, start, end; | |
{ |
{ |
UNDO_LIST *rl; |
UNDO_LIST *rl; |
|
|
Line 275 _rl_fix_last_undo_of_type (type, start, end)
|
Line 291 _rl_fix_last_undo_of_type (type, start, end)
|
|
|
/* Begin a group. Subsequent undos are undone as an atomic operation. */ |
/* Begin a group. Subsequent undos are undone as an atomic operation. */ |
int |
int |
rl_begin_undo_group () | rl_begin_undo_group (void) |
{ |
{ |
rl_add_undo (UNDO_BEGIN, 0, 0, 0); |
rl_add_undo (UNDO_BEGIN, 0, 0, 0); |
_rl_undo_group_level++; |
_rl_undo_group_level++; |
Line 284 rl_begin_undo_group ()
|
Line 300 rl_begin_undo_group ()
|
|
|
/* End an undo group started with rl_begin_undo_group (). */ |
/* End an undo group started with rl_begin_undo_group (). */ |
int |
int |
rl_end_undo_group () | rl_end_undo_group (void) |
{ |
{ |
rl_add_undo (UNDO_END, 0, 0, 0); |
rl_add_undo (UNDO_END, 0, 0, 0); |
_rl_undo_group_level--; |
_rl_undo_group_level--; |
Line 293 rl_end_undo_group ()
|
Line 309 rl_end_undo_group ()
|
|
|
/* Save an undo entry for the text from START to END. */ |
/* Save an undo entry for the text from START to END. */ |
int |
int |
rl_modifying (start, end) | rl_modifying (int start, int end) |
int start, end; | |
{ |
{ |
if (start > end) |
if (start > end) |
{ |
{ |
Line 314 rl_modifying (start, end)
|
Line 329 rl_modifying (start, end)
|
|
|
/* Revert the current line to its previous state. */ |
/* Revert the current line to its previous state. */ |
int |
int |
rl_revert_line (count, key) | rl_revert_line (int count, int key) |
int count, key; | |
{ |
{ |
if (rl_undo_list == 0) |
if (rl_undo_list == 0) |
rl_ding (); |
rl_ding (); |
Line 334 rl_revert_line (count, key)
|
Line 348 rl_revert_line (count, key)
|
|
|
/* Do some undoing of things that were done. */ |
/* Do some undoing of things that were done. */ |
int |
int |
rl_undo_command (count, key) | rl_undo_command (int count, int key) |
int count, key; | |
{ |
{ |
if (count < 0) |
if (count < 0) |
return 0; /* Nothing to do. */ |
return 0; /* Nothing to do. */ |