changeset: 6395:4ba366bc7c45
user: Kevin McCarthy <[email protected]>
date: Tue Aug 12 14:04:55 2014 -0700
link: http://dev.mutt.org/hg/mutt/rev/4ba366bc7c45
Add a scratch buffer to the history ring. (closes #3082)
This patch creates an extra slot in the history ring for a scratch
buffer (at h->last). If you are editing inside that buffer, it is
preserved when you scroll up/down through the history. Editing while in
other places in history are *not* preserved with this patch.
Another behavior change worth noting with this patch: the position in
history is now reset to the scratch buffer after each input entry.
Before, the position would be stay wherever it was - you didn't restart
at the "bottom" each time.
diffs (162 lines):
diff -r 8a2d9d352e2c -r 4ba366bc7c45 doc/manual.xml.head
--- a/doc/manual.xml.head Wed Nov 06 13:07:04 2013 -0800
+++ b/doc/manual.xml.head Tue Aug 12 14:04:55 2014 -0700
@@ -580,9 +580,9 @@
and can be made persistent using an external file specified using <link
linkend="history-file">$history_file</link>. You may cycle through them
at an editor prompt by using the <literal><history-up></literal>
-and/or <literal><history-down></literal> commands. But notice that
-Mutt does not remember the currently entered text, it only cycles
-through history and wraps around at the end or beginning.
+and/or <literal><history-down></literal> commands. Mutt will
+remember the currently entered text as you cycle through history, and
+will wrap around to the initial entry line.
</para>
<para>
diff -r 8a2d9d352e2c -r 4ba366bc7c45 enter.c
--- a/enter.c Wed Nov 06 13:07:04 2013 -0800
+++ b/enter.c Tue Aug 12 14:04:55 2014 -0700
@@ -302,12 +302,22 @@
{
case OP_EDITOR_HISTORY_UP:
state->curpos = state->lastchar;
+ if (mutt_history_at_scratch (hclass))
+ {
+ my_wcstombs (buf, buflen, state->wbuf, state->curpos);
+ mutt_history_save_scratch (hclass, buf);
+ }
replace_part (state, 0, mutt_history_prev (hclass));
redraw = M_REDRAW_INIT;
break;
case OP_EDITOR_HISTORY_DOWN:
state->curpos = state->lastchar;
+ if (mutt_history_at_scratch (hclass))
+ {
+ my_wcstombs (buf, buflen, state->wbuf, state->curpos);
+ mutt_history_save_scratch (hclass, buf);
+ }
replace_part (state, 0, mutt_history_next (hclass));
redraw = M_REDRAW_INIT;
break;
@@ -732,6 +742,7 @@
bye:
+ mutt_reset_history_state (hclass);
FREE (&tempbuf);
return rv;
}
diff -r 8a2d9d352e2c -r 4ba366bc7c45 history.c
--- a/history.c Wed Nov 06 13:07:04 2013 -0800
+++ b/history.c Tue Aug 12 14:04:55 2014 -0700
@@ -45,14 +45,14 @@
{
if (h->hist)
{
- for (i = 0 ; i < OldSize ; i ++)
+ for (i = 0 ; i <= OldSize ; i ++)
FREE (&h->hist[i]);
FREE (&h->hist);
}
}
if (HistSize)
- h->hist = safe_calloc (HistSize, sizeof (char *));
+ h->hist = safe_calloc (HistSize + 1, sizeof (char *));
h->cur = 0;
h->last = 0;
@@ -230,7 +230,7 @@
if (*s)
{
prev = h->last - 1;
- if (prev < 0) prev = HistSize - 1;
+ if (prev < 0) prev = HistSize;
/* don't add to prompt history:
* - lines beginning by a space
@@ -241,7 +241,7 @@
if (save && SaveHist)
save_history (hclass, s);
mutt_str_replace (&h->hist[h->last++], s);
- if (h->last > HistSize - 1)
+ if (h->last > HistSize)
h->last = 0;
}
}
@@ -257,9 +257,12 @@
return (""); /* disabled */
next = h->cur + 1;
- if (next > HistSize - 1)
+ if (next > HistSize)
next = 0;
- h->cur = h->hist[next] ? next : 0;
+ if (h->hist[next] || (next == h->last))
+ h->cur = next;
+ else
+ h->cur = 0;
return (h->hist[h->cur] ? h->hist[h->cur] : "");
}
@@ -274,11 +277,43 @@
prev = h->cur - 1;
if (prev < 0)
{
- prev = HistSize - 1;
- while (prev > 0 && h->hist[prev] == NULL)
+ prev = HistSize;
+ while ((prev > 0) && (prev != h->last) && (h->hist[prev] == NULL))
prev--;
}
- if (h->hist[prev])
+ if (h->hist[prev] || (prev == h->last))
h->cur = prev;
return (h->hist[h->cur] ? h->hist[h->cur] : "");
}
+
+void mutt_reset_history_state (history_class_t hclass)
+{
+ struct history *h = GET_HISTORY(hclass);
+
+ if (!HistSize || !h)
+ return; /* disabled */
+
+ h->cur = h->last;
+}
+
+int mutt_history_at_scratch (history_class_t hclass)
+{
+ struct history *h = GET_HISTORY(hclass);
+
+ if (!HistSize || !h)
+ return 0; /* disabled */
+
+ return h->cur == h->last;
+}
+
+void mutt_history_save_scratch (history_class_t hclass, const char *s)
+{
+ struct history *h = GET_HISTORY(hclass);
+
+ if (!HistSize || !h)
+ return; /* disabled */
+
+ /* Don't check if s has a value because the scratch buffer may contain
+ * an old garbage value that should be overwritten */
+ mutt_str_replace (&h->hist[h->last], s);
+}
diff -r 8a2d9d352e2c -r 4ba366bc7c45 history.h
--- a/history.h Wed Nov 06 13:07:04 2013 -0800
+++ b/history.h Tue Aug 12 14:04:55 2014 -0700
@@ -41,5 +41,8 @@
void mutt_history_add(history_class_t, const char *, int);
char *mutt_history_next(history_class_t);
char *mutt_history_prev(history_class_t);
+void mutt_reset_history_state (history_class_t);
+int mutt_history_at_scratch (history_class_t);
+void mutt_history_save_scratch (history_class_t, const char *);
#endif