+ buffer[s] = '\0';
+ *position = 0;
+}
+
+void kill_after_cursor(char *buffer, int *position) {
+ buffer[*position] = '\0';
+}
+
+//////////////////////////////////////////////////////////////////////
+
+int previous_visible(int current_line, int nb_lines, char **lines, matcher_t *matcher) {
+ int line = current_line - 1;
+ while(line >= 0 && !match(lines[line], matcher)) line--;
+ return line;
+}
+
+int next_visible(int current_line, int nb_lines, char **lines, matcher_t *matcher) {
+ int line = current_line + 1;
+ while(line < nb_lines && !match(lines[line], matcher)) line++;
+
+ if(line < nb_lines)
+ return line;
+ else
+ return -1;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+// The value passed to this routine in current_focus_line is the index
+// of the line we should have highlited if there was no motion and if
+// it matched the matcher. So, the line actually highlighted is the
+// first one matching the matcher in that order: (1)
+// current_focus_line after motion, (2) the first with a greater
+// index, (3) the first with a lesser index.
+
+// The index of the line actually shown highlighted is written in
+// displayed_focus_line (it can be -1)
+
+// If there is a motion and a line is actually shown highlighted, its
+// value is written in current_focus_line.
+
+void update_screen(int *current_focus_line, int *displayed_focus_line,
+ int motion,
+ int nb_lines, char **lines,
+ int cursor_position,
+ char *pattern) {
+
+ char buffer[buffer_size];
+ matcher_t matcher;
+
+ initialize_matcher(use_regexp, case_sensitive, &matcher, pattern);
+
+ int console_width = getmaxx(stdscr);
+ int console_height = getmaxy(stdscr);
+
+ // First, we find a visible line.
+
+ int nb_printed_lines = 0;