source: history.c @ 3969e3a

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 3969e3a 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
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5void owl_history_init(owl_history *h) {
6  owl_list_create(&(h->hist));
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? */
10}
11
12char *owl_history_get_prev(owl_history *h) {
13
14  if (!h) return NULL;
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++;
24
25  return(owl_list_get_element(&(h->hist), h->cur));
26}
27
28char *owl_history_get_next(owl_history *h) {
29  if (!h) return NULL;
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
39void owl_history_store(owl_history *h, char *line) {
40  int size;
41
42  if (!h) return;
43
44  /* if partial is set, remove the first entry first */
45  if (h->partial) {
46    owl_list_remove_element(&(h->hist), 0);
47  }
48
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
60void owl_history_set_partial(owl_history *h) {
61  if (!h) return;
62  h->partial=1;
63}
64
65void owl_history_reset(owl_history *h) {
66  if (!h) return;
67  h->cur=0;
68  h->touched=0;
69  h->partial=0;
70}
71
72int owl_history_is_touched(owl_history *h) {
73  if (!h) return(0);
74  if (h->touched) return(1);
75  return(0);
76}
Note: See TracBrowser for help on using the repository browser.