NeoMutt  2018-07-16 +952-a2da0a
Teaching an old dog new tricks
DOXYGEN
mutt_history.c File Reference

Read/write command history from/to a file. More...

#include "config.h"
#include <stdio.h>
#include "mutt/mutt.h"
#include "mutt.h"
#include "curs_lib.h"
#include "format_flags.h"
#include "keymap.h"
#include "menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "opcodes.h"
+ Include dependency graph for mutt_history.c:

Go to the source code of this file.

Functions

static const char * history_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, enum FormatFlag flags)
 Format a string for the history list - Implements format_t. More...
 
static void history_make_entry (char *buf, size_t buflen, struct Menu *menu, int line)
 Format a menu item for the history list - Implements Menu::menu_make_entry() More...
 
static void history_menu (char *buf, size_t buflen, char **matches, int match_count)
 Select an item from a history list. More...
 
void mutt_hist_complete (char *buf, size_t buflen, enum HistoryClass hclass)
 Complete a string from a history list. More...
 
bool mutt_hist_listener (const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev)
 Listen for config changes affecting the history - Implements cs_listener() More...
 

Variables

static const struct Mapping HistoryHelp []
 

Detailed Description

Read/write command history from/to a file.

Authors
  • Michael R. Elkins

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file mutt_history.c.

Function Documentation

static const char* history_format_str ( char *  buf,
size_t  buflen,
size_t  col,
int  cols,
char  op,
const char *  src,
const char *  prec,
const char *  if_str,
const char *  else_str,
unsigned long  data,
enum FormatFlag  flags 
)
static

Format a string for the history list - Implements format_t.

Expando Description
%s History match

Definition at line 56 of file mutt_history.c.

60 {
61  char *match = (char *) data;
62 
63  switch (op)
64  {
65  case 's':
66  mutt_format_s(buf, buflen, prec, match);
67  break;
68  }
69 
70  return src;
71 }
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1061

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void history_make_entry ( char *  buf,
size_t  buflen,
struct Menu menu,
int  line 
)
static

Format a menu item for the history list - Implements Menu::menu_make_entry()

Definition at line 76 of file mutt_history.c.

77 {
78  char *entry = ((char **) menu->data)[line];
79 
81  (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR);
82 }
const char * line
Definition: common.c:35
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
reserve space for arrow_cursor
Definition: format_flags.h:38
void * data
extra data for the current menu
Definition: menu.h:60
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags)
Expand expandos (x) in a string.
Definition: muttlib.c:816
static const char * history_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, enum FormatFlag flags)
Format a string for the history list - Implements format_t.
Definition: mutt_history.c:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void history_menu ( char *  buf,
size_t  buflen,
char **  matches,
int  match_count 
)
static

Select an item from a history list.

Parameters
bufBuffer in which to save string
buflenBuffer length
matchesItems to choose from
match_countNumber of items

Definition at line 91 of file mutt_history.c.

92 {
93  int done = 0;
94  char helpstr[LONG_STRING];
95  char title[STRING];
96 
97  snprintf(title, sizeof(title), _("History '%s'"), buf);
98 
101  menu->title = title;
102  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_GENERIC, HistoryHelp);
104 
105  menu->max = match_count;
106  menu->data = matches;
107 
108  while (!done)
109  {
110  switch (mutt_menu_loop(menu))
111  {
112  case OP_GENERIC_SELECT_ENTRY:
113  mutt_str_strfcpy(buf, matches[menu->current], buflen);
114  /* fall through */
115 
116  case OP_EXIT:
117  done = 1;
118  break;
119  }
120  }
121 
122  mutt_menu_pop_current(menu);
123  mutt_menu_destroy(&menu);
124 }
GUI selectable list of items.
Definition: menu.h:56
Generic selection list.
Definition: keymap.h:72
#define _(a)
Definition: message.h:28
int menu
menu definition for keymap entries.
Definition: menu.h:64
#define LONG_STRING
Definition: string2.h:36
void(* menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: menu.h:96
char * mutt_compile_help(char *buf, size_t buflen, int menu, const struct Mapping *items)
Create the text for the help menu.
Definition: help.c:115
static const struct Mapping HistoryHelp[]
Definition: mutt_history.c:41
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
int max
the number of entries in the menu
Definition: menu.h:62
char * title
the title of this menu
Definition: menu.h:58
#define STRING
Definition: string2.h:35
static void history_make_entry(char *buf, size_t buflen, struct Menu *menu, int line)
Format a menu item for the history list - Implements Menu::menu_make_entry()
Definition: mutt_history.c:76
void * data
extra data for the current menu
Definition: menu.h:60
int current
current entry
Definition: menu.h:61
char * help
quickref for the current menu
Definition: menu.h:59

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_hist_complete ( char *  buf,
size_t  buflen,
enum HistoryClass  hclass 
)

Complete a string from a history list.

Parameters
bufBuffer in which to save string
buflenBuffer length
hclassHistory list to use

Definition at line 132 of file mutt_history.c.

133 {
134  char **matches = mutt_mem_calloc(History, sizeof(char *));
135  int match_count = mutt_hist_search(buf, hclass, matches);
136  if (match_count)
137  {
138  if (match_count == 1)
139  mutt_str_strfcpy(buf, matches[0], buflen);
140  else
141  history_menu(buf, buflen, matches, match_count);
142  }
143  FREE(&matches);
144 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
Saved list of user-entered commands/searches.
Definition: history.c:98
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
static void history_menu(char *buf, size_t buflen, char **matches, int match_count)
Select an item from a history list.
Definition: mutt_history.c:91
#define FREE(x)
Definition: memory.h:46
int mutt_hist_search(char *search_buf, enum HistoryClass hclass, char **matches)
Find matches in a history list.
Definition: history.c:413

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool mutt_hist_listener ( const struct ConfigSet cs,
struct HashElem he,
const char *  name,
enum ConfigEvent  ev 
)

Listen for config changes affecting the history - Implements cs_listener()

Definition at line 149 of file mutt_history.c.

151 {
152  if (mutt_str_strcmp(name, "history") != 0)
153  return true;
154 
155  mutt_hist_init();
156  return true;
157 }
const char * name
Definition: pgpmicalg.c:42
void mutt_hist_init(void)
Create a set of empty History ring buffers.
Definition: history.c:462
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:612

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const struct Mapping HistoryHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Select"), OP_GENERIC_SELECT_ENTRY },
{ N_("Search"), OP_SEARCH },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Definition at line 41 of file mutt_history.c.