<commit_before>/* config.h - configuration for edna(1) */
#include "cmd.h"

/* settings */
#define PROMPT "\r\033[K:"
#define ERROR "?\n"
#define FILENAME "/tmp/edna.hup"

/* advanced examples */
//#define PROMPT "%ld:", st->lineno	/* have line numbers in prompt */
//#define ERROR "%s\n", error		/* like ed's 'H', without the '?' */

static const Command commands[] = {
      /*  name,		func,		mode */
	{ "",		nop,		NULL },
	{ "",		gotol,		NULL },
	{ "a",		insert,		"append" },
	{ "c",		insert,		"change" },
	{ "d",		delete,		NULL },
	{ "e",		edit,		NULL },
	{ "E",		edit,		"force" },
	{ "f",		filename,	NULL, },
	{ "h",		help,		NULL },
	{ "i",		insert,		NULL },
	{ "next",	switchbuf,	"next" },
	{ "o",		openbuf,	NULL },
	{ "p",		print,		NULL },
	{ "prev",	switchbuf,	"prev" },
	{ "q",		quit,		NULL },
	{ "s",		sub,		NULL },
	{ "w",		write,		NULL },
	{ "wq",		quit,		"write" },
	{ "Q", 		quit,		"force" },
};<commit_msg>abstract modes, handle prompts properly<commit_after>/* config.h - configuration for edna(1) */
#include "edna.h"
#include "cmd.h"

/* settings */
#define PROMPT		"\r\033[K:"
#define INS_PROMPT	" \b"
#define ERROR		"?\n"
#define FILENAME	"/tmp/edna.hup"

/* advanced examples */
//#define PROMPT "%ld:", st->lineno	/* have line numbers in prompt */
//#define INS_PROMPT "%ld|", buf->lineno	/* have line number in ins mode */
//#define ERROR "%s\n", error		/* like ed's 'H', without the '?' */

extern int cmdprompt (State *, Buffer *, Arg *);
extern int insprompt (State *, Buffer *, Arg *);
extern int cmderror  (State *, Buffer *, Arg *, char *);

static const Mode modes[] = {
       /* name,	       prompter,    parser,     evaluator,   handler, */
	{ "command",   cmdprompt,   parseline,  evalcmd,     cmderror, },
	{ "insert",    insprompt,   insparse,   insline,     inserror, },
};

static const Command commands[] = {
       /* name,		func,		mode */
	{ "",		gotol,		NULL },
	{ "a",		insert,		"append" },
	{ "c",		insert,		"change" },
	{ "d",		delete,		NULL },
	{ "e",		edit,		NULL },
	{ "E",		edit,		"force" },
	{ "f",		filename,	NULL, },
	{ "h",		help,		NULL },
	{ "i",		insert,		NULL },
	{ "next",	switchbuf,	"next" },
	{ "o",		openbuf,	NULL },
	{ "p",		print,		NULL },
	{ "prev",	switchbuf,	"prev" },
	{ "q",		quit,		NULL },
	{ "s",		subst,		NULL },
	{ "w",		write,		NULL },
	{ "wq",		quit,		"write" },
	{ "Q", 		quit,		"force" },
};

/* functions */
int
cmdprompt (State *st, Buffer *buf, Arg *arg)
{
	if (printf (PROMPT) < 0) die ("printf");
	return SUCC;
}

int
insprompt (State *st, Buffer *buf, Arg *arg)
{
	if (printf (INS_PROMPT) < 0) die ("printf");
	return SUCC;
}

int
cmderror (State *st, Buffer *buf, Arg *arg, char *error)
{
	if (!strcmp (error, "quit"))
		return FAIL;
	if (printf (ERROR) < 0) die ("printf");
	return SUCC;
}
{'fraction_non_alphanumeric': 0.22366522366522368, 'fraction_numerical': 0.003968253968253968, 'mean_word_length': 2.933333333333333, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '429098', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1180, 'n_words': 310}