-/* forward declarations */
-void appenditem(Item *i, Item **list, Item **last);
-void calcoffsets(void);
-char *cistrstr(const char *s, const char *sub);
-void cleanup(void);
-void drawmenu(void);
-void drawtext(const char *text, unsigned long col[ColLast]);
-void *emalloc(unsigned int size);
-void eprint(const char *errstr, ...);
-char *estrdup(const char *str);
-unsigned long getcolor(const char *colstr);
-Bool grabkeyboard(void);
-void initfont(const char *fontstr);
-void kpress(XKeyEvent * e);
-void match(char *pattern);
-void readstdin(void);
-void run(void);
-void setup(Bool topbar);
-unsigned int textnw(const char *text, unsigned int len);
-unsigned int textw(const char *text);
-
-#include "config.h"
-
-/* variables */
-char *font = FONT;
-char *maxname = NULL;
-char *normbg = NORMBGCOLOR;
-char *normfg = NORMFGCOLOR;
-char *prompt = NULL;
-char *selbg = SELBGCOLOR;
-char *selfg = SELFGCOLOR;
-char text[4096];
-int screen;
-int ret = 0;
-unsigned int cmdw = 0;
-unsigned int mw, mh;
-unsigned int promptw = 0;
-unsigned int numlockmask = 0;
-Bool running = True;
-Display *dpy;
-DC dc = {0};
-Item *allitems = NULL; /* first of all items */
-Item *item = NULL; /* first of pattern matching items */
-Item *sel = NULL;
-Item *next = NULL;
-Item *prev = NULL;
-Item *curr = NULL;
-Window root, win;
-int (*fstrncmp)(const char *, const char *, size_t n) = strncmp;
-char *(*fstrstr)(const char *, const char *) = strstr;
+static void appenditem(Item *item, Item **list, Item **last);
+static void calcoffsets(void);
+static char *cistrstr(const char *s, const char *sub);
+static void drawmenu(void);
+static void grabkeyboard(void);
+static void insert(const char *s, ssize_t n);
+static void keypress(XKeyEvent *e);
+static void match(void);
+static void paste(void);
+static void readstdin(void);
+static void run(void);
+static void setup(void);
+static void usage(void);
+
+static char text[4096];
+static size_t cursor = 0;
+static const char *prompt = NULL;
+static const char *normbgcolor = "#cccccc";
+static const char *normfgcolor = "#000000";
+static const char *selbgcolor = "#0066ff";
+static const char *selfgcolor = "#ffffff";
+static unsigned int inputw = 0;
+static unsigned int lines = 0;
+static unsigned int mw, mh;
+static unsigned int promptw;
+static unsigned long normcol[ColLast];
+static unsigned long selcol[ColLast];
+static Atom utf8;
+static Bool topbar = True;
+static DC *dc;
+static Item *allitems, *matches;
+static Item *curr, *prev, *next, *sel;
+static Window root, win;
+
+static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
+static char *(*fstrstr)(const char *, const char *) = strstr;