barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change
on this file since 7933748 was
10b866d,
checked in by Erik Nygren <nygren@mit.edu>, 22 years ago
|
* Fixed preservation of e->dotsend across owl_editwin_clear().
* Added history for multiline edit windows (eg, for zephyr composition).
The M-n and M-p keys will cycle through the history ring.
In particular, it is now possible to edit the command line
of a zephyr being composed: C-c it and restart it
and then M-p to get the aborted composition back.
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[1aee7d9] | 3 | static const char fileIdent[] = "$Id$"; |
---|
| 4 | |
---|
[7d4fbcd] | 5 | void owl_history_init(owl_history *h) { |
---|
| 6 | owl_list_create(&(h->hist)); |
---|
[10b866d] | 7 | h->cur=0; /* current position in history */ |
---|
| 8 | h->touched=0; /* whether we've gone into history */ |
---|
| 9 | h->partial=0; /* is the 0th element is partially composed? */ |
---|
[7d4fbcd] | 10 | } |
---|
| 11 | |
---|
| 12 | char *owl_history_get_prev(owl_history *h) { |
---|
[10b866d] | 13 | |
---|
| 14 | if (!h) return NULL; |
---|
[7d4fbcd] | 15 | h->touched=1; |
---|
| 16 | |
---|
| 17 | if (owl_list_get_size(&(h->hist))==0) return(NULL); |
---|
| 18 | |
---|
| 19 | if (h->cur == owl_list_get_size(&(h->hist))-1) { |
---|
| 20 | return(NULL); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | h->cur++; |
---|
[10b866d] | 24 | |
---|
[7d4fbcd] | 25 | return(owl_list_get_element(&(h->hist), h->cur)); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | char *owl_history_get_next(owl_history *h) { |
---|
[10b866d] | 29 | if (!h) return NULL; |
---|
[7d4fbcd] | 30 | if (owl_list_get_size(&(h->hist))==0) return(NULL); |
---|
| 31 | if (h->cur==0) { |
---|
| 32 | return(NULL); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | h->cur--; |
---|
| 36 | return(owl_list_get_element(&(h->hist), h->cur)); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | void owl_history_store(owl_history *h, char *line) { |
---|
| 40 | int size; |
---|
| 41 | |
---|
[10b866d] | 42 | if (!h) return; |
---|
| 43 | |
---|
[7d4fbcd] | 44 | /* if partial is set, remove the first entry first */ |
---|
| 45 | if (h->partial) { |
---|
| 46 | owl_list_remove_element(&(h->hist), 0); |
---|
| 47 | } |
---|
[10b866d] | 48 | |
---|
[7d4fbcd] | 49 | /* if we've reached the max history size, pop off the last element */ |
---|
| 50 | size=owl_list_get_size(&(h->hist)); |
---|
| 51 | if (size>OWL_HISTORYSIZE) { |
---|
| 52 | owl_free(owl_list_get_element(&(h->hist), size-1)); |
---|
| 53 | owl_list_remove_element(&(h->hist), size-1); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | /* add the new line */ |
---|
| 57 | owl_list_prepend_element(&(h->hist), owl_strdup(line)); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | void owl_history_set_partial(owl_history *h) { |
---|
[10b866d] | 61 | if (!h) return; |
---|
[7d4fbcd] | 62 | h->partial=1; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void owl_history_reset(owl_history *h) { |
---|
[10b866d] | 66 | if (!h) return; |
---|
[7d4fbcd] | 67 | h->cur=0; |
---|
| 68 | h->touched=0; |
---|
| 69 | h->partial=0; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | int owl_history_is_touched(owl_history *h) { |
---|
[10b866d] | 73 | if (!h) return(0); |
---|
[7d4fbcd] | 74 | if (h->touched) return(1); |
---|
| 75 | return(0); |
---|
| 76 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.