84#define HC_FIRST HC_EXT_COMMAND
95 if ((hclass >=
HC_MAX) || (c_history == 0))
115 for (
int i = 0; i <= old_size; i++)
145 uintptr_t count = (uintptr_t) he->
data;
153 he->
data = (
void *) count;
177 count = (uintptr_t) he->
data;
179 he->
data = (
void *) count;
193 char *linebuf = NULL;
196 bool regen_file =
false;
208 if (c_history_remove_dups)
210 for (hclass = 0; hclass <
HC_MAX; hclass++)
218 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
219 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
221 mutt_error(
_(
"%s:%d: Bad history file format"), c_history_file, line);
229 if (c_history_remove_dups && (
dup_hash_inc(dup_hashes[hclass], linebuf + read) > 1))
241 if (n[hclass] > c_save_history)
259 fseek(fp, 0, SEEK_SET);
264 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
265 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
272 if (c_history_remove_dups && (
dup_hash_dec(dup_hashes[hclass], linebuf + read) > 0))
277 if (n[hclass]-- <= c_save_history)
278 fprintf(fp_tmp,
"%s\n", linebuf);
287 if (fflush(fp_tmp) == 0)
292 fseek(fp_tmp, 0, SEEK_SET);
300 if (c_history_remove_dups)
301 for (hclass = 0; hclass <
HC_MAX; hclass++)
312 if (!str || (*str ==
'\0'))
324 char *nl = strchr(tmp,
'\n');
330 fprintf(fp,
"%d:%s|\n", (
int) hclass, tmp);
357 while (source < h->
last)
362 h->
hist[dest++] = h->
hist[source++];
367 int old_last = h->
last;
371 while (source > h->
last)
372 h->
hist[source--] = NULL;
378 while (source > old_last)
383 h->
hist[dest--] = h->
hist[source--];
387 while (dest > old_last)
388 h->
hist[dest--] = NULL;
400 if (!find || !matches)
440 for (
int i = 0; i <= mod_data->
old_size; i++)
458 if (c_history == mod_data->
old_size)
481 int prev = h->
last - 1;
492 if (c_history_remove_dups)
496 if (save && (c_save_history != 0) && c_history_file)
499 if (h->
last > c_history)
524 if (next > c_history)
528 }
while (!h->
hist[next]);
556 }
while (!h->
hist[prev]);
596 char *linebuf = NULL;
604 if ((sscanf(linebuf,
"%d:%n", &hclass, &read) < 1) || (read == 0) ||
605 (*(p = linebuf + strlen(linebuf) - 1) !=
'|') || (hclass < 0))
607 mutt_error(
_(
"%s:%d: Bad history file format"), c_history_file, line);
676 if (match_count != 0)
678 if (match_count == 1)
680 const char **pstr =
ARRAY_GET(&matches, 0);
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
#define ARRAY_SIZE(head)
The number of elements stored.
#define ARRAY_FREE(head)
Release all memory.
#define ARRAY_GET(head, idx)
Return the element at index.
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Convenience wrapper for the config headers.
const char * cc_charset(void)
Get the cached value of $charset.
Convenience wrapper for the core headers.
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
#define mutt_file_fclose(FP)
#define mutt_file_fopen(PATH, MODE)
@ MUTT_RL_NONE
No flags are set.
void dlg_history(struct Buffer *buf, struct StringArray *matches)
Select an item from a history list -.
#define mutt_debug(LEVEL,...)
int main_hist_observer(struct NotifyCallback *nc)
Notification that a Config Variable has change - Implements observer_t -.
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys).
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys).
struct HashElem * mutt_hash_find_elem(const struct HashTable *table, const char *strkey)
Find the HashElem in a Hash Table element using a key.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
@ MUTT_HASH_STRDUP_KEYS
make a copy of the keys
Read/write command history from/to a file.
HistoryClass
Type to differentiate different histories.
History private Module data.
static void init_history(struct History *h, int old_size)
Set up a new History ring buffer.
static void remove_history_dups(enum HistoryClass hclass, const char *str)
De-dupe the history.
void mutt_hist_init(struct HistoryModuleData *mod_data)
Create a set of empty History ring buffers.
char * mutt_hist_next(enum HistoryClass hclass)
Get the next string in a History.
void mutt_hist_read_file(void)
Read the History from a file.
static int dup_hash_inc(struct HashTable *dup_hash, char *str)
Increase the refcount of a history string.
void mutt_hist_save_scratch(enum HistoryClass hclass, const char *str)
Save a temporary string to the History.
void mutt_hist_complete(struct Buffer *buf, enum HistoryClass hclass)
Complete a string from a history list.
bool mutt_hist_at_scratch(enum HistoryClass hclass)
Is the current History position at the 'scratch' place?
static struct History * get_history(enum HistoryClass hclass)
Get a particular history.
static void save_history(enum HistoryClass hclass, const char *str)
Save one history string to a file.
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
void mutt_hist_reset_state(enum HistoryClass hclass)
Move the 'current' position to the end of the History.
static int dup_hash_dec(struct HashTable *dup_hash, char *str)
Decrease the refcount of a history string.
char * mutt_hist_prev(enum HistoryClass hclass)
Get the previous string in a History.
int mutt_hist_search(const char *find, enum HistoryClass hclass, struct StringArray *matches)
Find matches in a history list.
static void shrink_histfile(void)
Read, de-dupe and write the history file.
void mutt_hist_cleanup(struct HistoryModuleData *mod_data)
Free all the history lists.
@ LL_DEBUG5
Log at debug level 5.
#define FREE(x)
Free memory and set the pointer to NULL.
#define MUTT_MEM_CALLOC(n, type)
#define MAX(a, b)
Return the maximum of two values.
@ MODULE_ID_HISTORY
ModuleHistory, History
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
#define MUTT_ICONV_NONE
No flags are set.
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case).
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
String manipulation buffer.
const char * name
Name of config item that changed.
The item stored in a Hash Table.
void * data
User-supplied data.
History private Module data.
struct History histories[HC_MAX]
Command histories, one for each HistoryClass.
int old_size
The previous number of history entries to save.
Saved list of user-entered commands/searches.
short cur
Current history item.
short last
Last history item.
char ** hist
Array of history items.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
Data passed to a notification function.
void * event_data
Data from notify_send().
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
#define mutt_file_mkstemp()