1 /**
2 * @file
3 * Read/write command history from/to a file
4 *
5 * @authors
6 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
7 *
8 * @copyright
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 2 of the License, or (at your option) any later
12 * version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 /**
24 * @page neo_mutt_history Read/write command history from/to a file
25 *
26 * Read/write command history from/to a file
27 */
28
29 #include "config.h"
30 #include <stdio.h>
31 #include "mutt/lib.h"
32 #include "config/lib.h"
33 #include "core/lib.h"
34 #include "mutt_history.h"
35 #include "history/lib.h"
36
37 /**
38 * mutt_hist_complete - Complete a string from a history list
39 * @param buf Buffer in which to save string
40 * @param buflen Buffer length
41 * @param hclass History list to use
42 */
mutt_hist_complete(char * buf,size_t buflen,enum HistoryClass hclass)43 void mutt_hist_complete(char *buf, size_t buflen, enum HistoryClass hclass)
44 {
45 const short c_history = cs_subset_number(NeoMutt->sub, "history");
46 char **matches = mutt_mem_calloc(c_history, sizeof(char *));
47 int match_count = mutt_hist_search(buf, hclass, matches);
48 if (match_count)
49 {
50 if (match_count == 1)
51 mutt_str_copy(buf, matches[0], buflen);
52 else
53 dlg_select_history(buf, buflen, matches, match_count);
54 }
55 FREE(&matches);
56 }
57
58 /**
59 * main_hist_observer - Notification that a Config Variable has changed - Implements ::observer_t - @ingroup observer_api
60 */
main_hist_observer(struct NotifyCallback * nc)61 int main_hist_observer(struct NotifyCallback *nc)
62 {
63 if ((nc->event_type != NT_CONFIG) || !nc->event_data)
64 return -1;
65
66 struct EventConfig *ev_c = nc->event_data;
67
68 if (!mutt_str_equal(ev_c->name, "history"))
69 return 0;
70
71 mutt_hist_init();
72 mutt_debug(LL_DEBUG5, "history done\n");
73 return 0;
74 }
75