From 2826bcd27585e57460e7a332961e4e8c3b881be9 Mon Sep 17 00:00:00 2001
From: Rishabh Dave
Date: Thu, 24 Nov 2016 22:34:26 +0530
Subject: [PATCH] new feature: add search facility to help
Allow user to search all help text with ^W.
This accomplishes https://savannah.gnu.org/bugs/?28994.
Signed-off-by: Rishabh Dave
---
src/files.c | 24 ++++---
src/global.c | 61 +++++++++--------
src/help.c | 215 ++++++++++++++++++++++++++++++++++++++---------------------
src/nano.c | 12 +++-
src/nano.h | 1 +
src/prompt.c | 10 ++-
src/proto.h | 5 ++
src/search.c | 4 +-
src/winio.c | 15 +++--
9 files changed, 227 insertions(+), 120 deletions(-)
diff --git a/src/files.c b/src/files.c
index a4ac750..a4930a0 100644
--- a/src/files.c
+++ b/src/files.c
@@ -467,7 +467,8 @@ bool open_buffer(const char *filename, bool undoable)
if (new_buffer) {
make_new_buffer();
- if (has_valid_path(realname)) {
+ if ((currmenu != MHELP && currmenu != MFINDINHELP) &&
+ has_valid_path(realname)) {
#ifndef NANO_TINY
if (ISSET(LOCKING) && filename[0] != '\0') {
/* When not overriding an existing lock, discard the buffer. */
@@ -486,7 +487,8 @@ bool open_buffer(const char *filename, bool undoable)
/* If the filename isn't blank, and we are not in NOREAD_MODE,
* open the file. Otherwise, treat it as a new file. */
rc = (filename[0] != '\0' && !ISSET(NOREAD_MODE)) ?
- open_file(realname, new_buffer, FALSE, &f) : -2;
+ open_file(realname, new_buffer, currmenu == MHELP ||
+ currmenu == MFINDINHELP, &f) : -2;
/* If we have a file, and we're loading into a new buffer, update
* the filename. */
@@ -553,8 +555,10 @@ void replace_buffer(const char *filename)
/* Update the screen to account for the current buffer. */
void display_buffer(void)
{
- /* Update the titlebar, since the filename may have changed. */
- titlebar(NULL);
+ /* Update the titlebar, since the filename may have changed. In case
+ * of MHELP, titlebar() in done in help.c. */
+ if (currmenu != MHELP && currmenu != MFINDINHELP)
+ titlebar(NULL);
#ifndef DISABLE_COLOR
/* Make sure we're using the buffer's associated colors. */
@@ -594,9 +598,10 @@ void switch_to_prevnext_buffer(bool to_next)
display_buffer();
/* Indicate the switch on the statusbar. */
- statusline(HUSH, _("Switched to %s"),
- ((openfile->filename[0] == '\0') ?
- _("New Buffer") : openfile->filename));
+ if (currmenu != MHELP && currmenu != MFINDINHELP)
+ statusline(HUSH, _("Switched to %s"),
+ ((openfile->filename[0] == '\0') ?
+ _("New Buffer") : openfile->filename));
#ifdef DEBUG
dump_filestruct(openfile->current);
@@ -911,6 +916,9 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
* file we inserted. */
openfile->placewewant = xplustabs();
+ if (currmenu == MHELP || currmenu == MFINDINHELP)
+ return;
+
if (!writable)
statusline(ALERT, "File '%s' is unwritable", filename);
#ifndef NANO_TINY
@@ -1010,7 +1018,7 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
if (*f == NULL) {
statusline(ALERT, _("Error reading %s: %s"), filename, strerror(errno));
close(fd);
- } else
+ } else if (currmenu != MHELP && currmenu != MFINDINHELP)
statusbar(_("Reading File"));
}
diff --git a/src/global.c b/src/global.c
index dd2e71a..3a6cb08 100644
--- a/src/global.c
+++ b/src/global.c
@@ -28,6 +28,12 @@
#include "assert.h"
/* Global variables. */
+char *title = NULL;
+ /* Title of the help text. */
+bool window_went_below_76 = FALSE;
+ /* Gives the help text the original look when window size jumps
+ * from something below 76 to directly something above 76. */
+
#ifndef NANO_TINY
volatile sig_atomic_t sigwinch_counter = 0;
/* Is incremented by the handler whenever a SIGWINCH occurs. */
@@ -655,7 +661,7 @@ void shortcut_init(void)
/* TRANSLATORS: Try to keep the following strings at most 10 characters. */
N_("Get Help"), IFSCHELP(nano_help_msg), TOGETHER, VIEW);
- add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
+ add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO | MFINDINHELP),
N_("Cancel"), IFSCHELP(nano_cancel_msg), BLANKAFTER, VIEW);
add_to_funcs(do_exit, MMAIN,
@@ -715,6 +721,9 @@ void shortcut_init(void)
add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
+ add_to_funcs(do_search, MHELP, whereis_tag, "x", 0, VIEW);
+ add_to_funcs(do_research, MHELP, whereis_next_tag, "x", 0, VIEW);
+
add_to_funcs(do_up_void, MHELP, prev_line_tag, "x", 0, VIEW);
add_to_funcs(do_down_void, MHELP, next_line_tag, "x" , 0, VIEW);
#endif
@@ -1045,8 +1054,8 @@ void shortcut_init(void)
add_to_sclist(MMAIN, "^R", 0, do_insertfile_void, 0);
add_to_sclist(MMAIN, "F5", 0, do_insertfile_void, 0);
add_to_sclist(MMAIN, "Ins", 0, do_insertfile_void, 0);
- add_to_sclist(MMAIN|MBROWSER, "^W", 0, do_search, 0);
- add_to_sclist(MMAIN|MBROWSER, "F6", 0, do_search, 0);
+ add_to_sclist(MMAIN|MBROWSER|MHELP, "^W", 0, do_search, 0);
+ add_to_sclist(MMAIN|MBROWSER|MHELP, "F6", 0, do_search, 0);
add_to_sclist(MMAIN, "^\\", 0, do_replace, 0);
add_to_sclist(MMAIN, "M-R", 0, do_replace, 0);
add_to_sclist(MMAIN, "F14", 0, do_replace, 0);
@@ -1082,8 +1091,8 @@ void shortcut_init(void)
add_to_sclist(MMAIN|MHELP, "M-|", 0, do_first_line, 0);
add_to_sclist(MMAIN|MHELP, "M-/", 0, do_last_line, 0);
add_to_sclist(MMAIN|MHELP, "M-?", 0, do_last_line, 0);
- add_to_sclist(MMAIN|MBROWSER, "M-W", 0, do_research, 0);
- add_to_sclist(MMAIN|MBROWSER, "F16", 0, do_research, 0);
+ add_to_sclist(MMAIN|MBROWSER|MHELP, "M-W", 0, do_research, 0);
+ add_to_sclist(MMAIN|MBROWSER|MHELP, "F16", 0, do_research, 0);
#ifndef NANO_TINY
add_to_sclist(MMAIN, "M-]", 0, do_find_bracket, 0);
add_to_sclist(MMAIN, "^^", 0, do_mark, 0);
@@ -1099,19 +1108,19 @@ void shortcut_init(void)
#ifdef ENABLE_COMMENT
add_to_sclist(MMAIN, "M-3", 0, do_comment, 0);
#endif
- add_to_sclist(MMOST, "^B", 0, do_left, 0);
- add_to_sclist(MMOST, "Left", KEY_LEFT, do_left, 0);
- add_to_sclist(MMOST, "^F", 0, do_right, 0);
- add_to_sclist(MMOST, "Right", KEY_RIGHT, do_right, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^B", 0, do_left, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "Left", KEY_LEFT, do_left, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^F", 0, do_right, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "Right", KEY_RIGHT, do_right, 0);
#ifdef ENABLE_UTF8
if (using_utf8()) {
- add_to_sclist(MMOST, "^\xE2\x86\x90", CONTROL_LEFT, do_prev_word_void, 0);
- add_to_sclist(MMOST, "^\xE2\x86\x92", CONTROL_RIGHT, do_next_word_void, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^\xE2\x86\x90", CONTROL_LEFT, do_prev_word_void, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^\xE2\x86\x92", CONTROL_RIGHT, do_next_word_void, 0);
} else
#endif
{
- add_to_sclist(MMOST, "^Left", CONTROL_LEFT, do_prev_word_void, 0);
- add_to_sclist(MMOST, "^Right", CONTROL_RIGHT, do_next_word_void, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^Left", CONTROL_LEFT, do_prev_word_void, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^Right", CONTROL_RIGHT, do_next_word_void, 0);
}
add_to_sclist(MMOST, "M-Space", 0, do_prev_word_void, 0);
add_to_sclist(MMOST, "^Space", 0, do_next_word_void, 0);
@@ -1203,7 +1212,7 @@ void shortcut_init(void)
add_to_sclist(MMAIN, "^Q", 0, xon_complaint, 0);
add_to_sclist(MMAIN, "^S", 0, xoff_complaint, 0);
- add_to_sclist(((MMOST & ~MMAIN & ~MBROWSER) | MYESNO), "^C", 0, do_cancel, 0);
+ add_to_sclist(((MMOST & ~MMAIN & ~MBROWSER) | MYESNO | MFINDINHELP), "^C", 0, do_cancel, 0);
add_to_sclist(MWHEREIS|MREPLACE, "M-C", 0, case_sens_void, 0);
add_to_sclist(MWHEREIS|MREPLACE, "M-R", 0, regexp_void, 0);
@@ -1218,10 +1227,10 @@ void shortcut_init(void)
add_to_sclist(MWHEREIS, "^T", 0, do_gotolinecolumn_void, 0);
add_to_sclist(MGOTOLINE, "^T", 0, gototext_void, 0);
#ifndef DISABLE_HISTORIES
- add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^P", 0, get_history_older_void, 0);
- add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Up", KEY_UP, get_history_older_void, 0);
- add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^N", 0, get_history_newer_void, 0);
- add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Down", KEY_DOWN, get_history_newer_void, 0);
+ add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "^P", 0, get_history_older_void, 0);
+ add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "Up", KEY_UP, get_history_older_void, 0);
+ add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "^N", 0, get_history_newer_void, 0);
+ add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "Down", KEY_DOWN, get_history_newer_void, 0);
#endif
#ifndef DISABLE_BROWSER
add_to_sclist(MWHEREISFILE, "^Y", 0, do_first_file, 0);
@@ -1263,14 +1272,14 @@ void shortcut_init(void)
add_to_sclist(MHELP, "Home", KEY_HOME, do_first_line, 0);
add_to_sclist(MHELP, "End", KEY_END, do_last_line, 0);
#endif
- add_to_sclist(MMOST, "^I", 0, do_tab, 0);
- add_to_sclist(MMOST, "Tab", TAB_CODE, do_tab, 0);
- add_to_sclist(MMOST, "^M", 0, do_enter, 0);
- add_to_sclist(MMOST, "Enter", KEY_ENTER, do_enter, 0);
- add_to_sclist(MMOST, "^D", 0, do_delete, 0);
- add_to_sclist(MMOST, "Del", 0, do_delete, 0);
- add_to_sclist(MMOST, "^H", 0, do_backspace, 0);
- add_to_sclist(MMOST, "Bsp", KEY_BACKSPACE, do_backspace, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^I", 0, do_tab, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "Tab", TAB_CODE, do_tab, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^M", 0, do_enter, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "Enter", KEY_ENTER, do_enter, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^D", 0, do_delete, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "Del", 0, do_delete, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "^H", 0, do_backspace, 0);
+ add_to_sclist(MMOST|MFINDINHELP, "Bsp", KEY_BACKSPACE, do_backspace, 0);
#ifdef DEBUG
print_sclist();
diff --git a/src/help.c b/src/help.c
index b694192..02d586c 100644
--- a/src/help.c
+++ b/src/help.c
@@ -25,41 +25,93 @@
#include
#include
#include
+#include
#ifndef DISABLE_HELP
static char *help_text = NULL;
/* The text displayed in the help window. */
-static char *end_of_intro = NULL;
- /* The point in the help text where the introductory paragraphs end
- * and the shortcut descriptions begin. */
+const char *beg_of_intro = NULL;
+ /* The point in the help text where the introductory paragraphs
+ * begin. */
+
+char *tempfilename = NULL;
+ /* Name of the safe temporary file that we will use for wrapping
+ * and writing the help text. */
+
+/* Writes the hard wrapped help text in the temp file and displays it. */
+void display_the_help_text(bool redisplaying)
+{
+ int line_size;
+ const char *ptr = beg_of_intro;
+ /* The current line of the help text. */
+ FILE *fp = fopen(tempfilename, "w+b");
+
+ if (fp == NULL) {
+ statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));
+ return;
+ }
+
+ /* Wrap and copy the rest of the help_text into the temporary file. */
+ while (strlen(ptr) > 0) {
+ line_size = help_line_len(ptr);
+ fwrite(ptr, sizeof(char), line_size, fp);
+ ptr += line_size;
+
+ /* Hard wrap the lines in the help text. */
+ if (*ptr != '\n')
+ fwrite("\n", sizeof(char), 1, fp);
+ else
+ while (*ptr == '\n')
+ fwrite(ptr++, sizeof(char), 1, fp);
+ }
+ fclose(fp);
+
+ if (redisplaying)
+ close_buffer();
+
+ if (!ISSET(MULTIBUFFER)) {
+ SET(MULTIBUFFER);
+ open_buffer(tempfilename, FALSE);
+ UNSET(MULTIBUFFER);
+ } else
+ open_buffer(tempfilename, FALSE);
+
+ display_buffer();
+}
/* Our main help-viewer function. */
void do_help(void)
{
int kbinput = ERR;
bool old_no_help = ISSET(NO_HELP);
- size_t line = 0;
- /* The line number in help_text of the first displayed help
- * line. This variable is zero-based. */
- size_t last_line = 0;
- /* The line number in help_text of the last help line. This
- * variable is zero-based. */
int oldmenu = currmenu;
/* The menu we were called from. */
- const char *ptr;
- /* The current line of the help text. */
- size_t old_line = (size_t)-1;
- /* The line we were on before the current line. */
functionptrtype func;
/* The function of the key the user typed in. */
+ FILE *fp;
+ int line_size;
+ int saved_margin = 0;
+ /* For avoiding the line numbers on the help screen. */
+ const char *ptr;
+ /* The current line of the help text. */
+ char *saved_answer = answer != NULL ? strdup(answer) : NULL;
+ /* In case user chooses help at prompt, save the string entered,
+ * if any, by the user at the prompt. */
- /* Don't show a cursor in the help screen. */
- curs_set(0);
- blank_edit();
blank_statusbar();
+ /* Get a safe temporary file for displaying the help text. If we can't
+ * obtain one, return. */
+ tempfilename = safe_tempfile(&fp);
+ fclose(fp);
+ if (tempfilename == NULL) {
+ statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));
+ free(saved_answer);
+ return;
+ }
+
/* Set help_text as the string to display. */
help_init();
@@ -75,48 +127,33 @@ void do_help(void)
bottombars(MHELP);
wnoutrefresh(bottomwin);
- while (TRUE) {
- size_t i;
-
- ptr = help_text;
-
- /* Find the line number of the last line of the help text. */
- for (last_line = 0; *ptr != '\0'; last_line++) {
- ptr += help_line_len(ptr);
- if (*ptr == '\n')
- ptr++;
- }
-
- if (last_line > 0)
- last_line--;
-
- /* Redisplay if the text was scrolled or an invalid key was pressed. */
- if (line != old_line || kbinput == ERR) {
- blank_edit();
-
- ptr = help_text;
-
- /* Advance in the text to the first line to be displayed. */
- for (i = 0; i < line; i++) {
- ptr += help_line_len(ptr);
- if (*ptr == '\n')
- ptr++;
- }
+#ifdef ENABLE_LINENUMBERS
+ if (ISSET(LINE_NUMBERS)) {
+ saved_margin = margin;
+ margin = 0;
+ UNSET(LINE_NUMBERS);
+ }
+#endif
- /* Now display as many lines as the window will hold. */
- for (i = 0; i < editwinrows && *ptr != '\0'; i++) {
- size_t j = help_line_len(ptr);
+ /* Extract title from help_text and display it. */
+ title = charalloc(MAX_BUF_SIZE * sizeof(char));
+ ptr = help_text;
+ line_size = break_line(ptr, 74, TRUE);
+ strncpy(title, ptr, line_size);
+ title[line_size] = '\0';
+ titlebar(title);
- mvwaddnstr(edit, i, 0, ptr, j);
- ptr += j;
- if (*ptr == '\n')
- ptr++;
- }
- }
+ /* Skip the title and point to the beginning of the introductory
+ * paragraphs. */
+ ptr += line_size;
+ while (*ptr == '\n')
+ ++ptr;
+ beg_of_intro = ptr;
- wnoutrefresh(edit);
+ display_the_help_text(FALSE);
- old_line = line;
+ while (TRUE) {
+ edit_refresh();
lastmessage = HUSH;
@@ -125,7 +162,12 @@ void do_help(void)
#ifndef NANO_TINY
if (kbinput == KEY_WINCH) {
kbinput = ERR;
- continue; /* Redraw the screen. */
+ /* Rewrap if needed, else refresh. */
+ if (COLS < 76 || window_went_below_76) {
+ window_went_below_76 = COLS < 76 ? TRUE : FALSE;
+ display_the_help_text(TRUE);
+ }
+ continue;
}
#endif
@@ -142,31 +184,48 @@ void do_help(void)
if (func == total_refresh) {
total_redraw();
} else if (func == do_up_void) {
- if (line > 0)
- line--;
+ do_up(FALSE);
} else if (func == do_down_void) {
- if (line + (editwinrows - 1) < last_line)
- line++;
+ do_down(FALSE);
} else if (func == do_page_up) {
- if (line > editwinrows - 2)
- line -= editwinrows - 2;
- else
- line = 0;
+ do_page_up();
} else if (func == do_page_down) {
- if (line + (editwinrows - 1) < last_line)
- line += editwinrows - 2;
+ do_page_down();
} else if (func == do_first_line) {
- line = 0;
+ do_first_line();
} else if (func == do_last_line) {
- if (line + (editwinrows - 1) < last_line)
- line = last_line - (editwinrows - 1);
+ do_last_line();
+ } else if (func == do_search) {
+ do_search();
+ bottombars(MHELP);
+ wnoutrefresh(bottomwin);
+ } else if (func == do_research) {
+ do_research();
+ currmenu = MHELP;
} else if (func == do_exit) {
/* Exit from the help viewer. */
+ close_buffer();
break;
- } else
+ } else if ((kbinput >= '0' && kbinput <= '9') ||
+ (kbinput >= 'a' && kbinput <= 'z') ||
+ (kbinput >= 'A' && kbinput <= 'Z'))
+ /* No text can be entered at help screen. */
+ ;
+ else
unbound_key(kbinput);
}
+
+ /* We're exiting from the help screen. So, restore the flags and the
+ * original menu, refresh the entire screen and deallocate the memory. */
+
+#ifdef ENABLE_LINENUMBERS
+ if (saved_margin != 0) {
+ margin = saved_margin;
+ SET(LINE_NUMBERS);
+ }
+#endif
+
if (old_no_help) {
blank_bottombars();
wnoutrefresh(bottomwin);
@@ -176,14 +235,23 @@ void do_help(void)
} else
bottombars(oldmenu);
+ /* Ensure that the title is null for proper effect from total_refresh(). */
+ free(title);
+ title = NULL;
+
#ifndef DISABLE_BROWSER
if (oldmenu == MBROWSER || oldmenu == MWHEREISFILE || oldmenu == MGOTODIR)
browser_refresh();
else
#endif
- edit_refresh();
+ total_refresh();
+
+ answer = mallocstrcpy(answer, saved_answer);
+ free(saved_answer);
+
+ remove(tempfilename);
+ free(tempfilename);
- /* We're exiting from the help screen. */
free(help_text);
}
@@ -397,9 +465,6 @@ void help_init(void)
ptr = help_text + strlen(help_text);
- /* Remember this end-of-introduction, start-of-shortcuts. */
- end_of_intro = ptr;
-
/* Now add our shortcut info. */
for (f = allfuncs; f != NULL; f = f->next) {
int scsfound = 0;
@@ -503,7 +568,7 @@ size_t help_line_len(const char *ptr)
/* Full length of the line, until the first newline. */
/* Avoid overwide paragraphs in the introductory text. */
- if (ptr < end_of_intro && COLS > 74)
+ if (COLS > 74)
wrapping_point = 74;
wrap_location = break_line(ptr, wrapping_point, TRUE);
diff --git a/src/nano.c b/src/nano.c
index 7204b45..caa45e8 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1373,6 +1373,11 @@ void regenerate_screen(void)
/* Redraw the contents of the windows that need it. */
total_refresh();
+
+ if (currmenu == MFINDINHELP && (COLS < 76 || window_went_below_76)) {
+ window_went_below_76 = COLS < 76 ? TRUE : FALSE;
+ display_the_help_text(TRUE);
+ }
}
/* If allow is FALSE, block any SIGWINCH signal. If allow is TRUE,
@@ -1442,8 +1447,9 @@ void do_toggle(int flag)
)
enabled = !enabled;
- statusline(HUSH, "%s %s", _(flagtostr(flag)),
- enabled ? _("enabled") : _("disabled"));
+ if (currmenu != MHELP)
+ statusline(HUSH, "%s %s", _(flagtostr(flag)),
+ enabled ? _("enabled") : _("disabled"));
}
/* Bleh. */
@@ -1578,7 +1584,7 @@ void unbound_key(int code)
statusline(ALERT, _("Unbound key: M-%c"), toupper(code));
} else if (code < 0x20)
statusline(ALERT, _("Unbound key: ^%c"), code + 0x40);
- else
+ else if (currmenu != MHELP)
statusline(ALERT, _("Unbound key: %c"), code);
}
diff --git a/src/nano.h b/src/nano.h
index 93ec5e1..e778ee4 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -557,6 +557,7 @@ enum
#define MGOTODIR (1<<12)
#define MYESNO (1<<13)
#define MLINTER (1<<14)
+#define MFINDINHELP (1<<15)
/* This is an abbreviation for all menus except Help and YesNo. */
#define MMOST (MMAIN|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE|MWRITEFILE|MINSERTFILE|\
MEXTCMD|MBROWSER|MWHEREISFILE|MGOTODIR|MSPELL|MLINTER)
diff --git a/src/prompt.c b/src/prompt.c
index 34e7b4c..1b494f9 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -662,9 +662,17 @@ int do_prompt(bool allow_tabs,
#endif
/* Save a possible current statusbar x position. */
size_t was_statusbar_x = statusbar_x;
+ char *saved_prompt = NULL;
+ /* In case we need prompt again before completing previous one,
+ * above variables become useful. */
bottombars(menu);
+ if (prompt != NULL) {
+ saved_prompt = strdup(prompt);
+ free(prompt);
+ }
+
answer = mallocstrcpy(answer, curranswer);
#ifndef NANO_TINY
@@ -687,7 +695,7 @@ int do_prompt(bool allow_tabs,
refresh_func);
free(prompt);
- prompt = NULL;
+ prompt = saved_prompt;
#ifndef NANO_TINY
if (retval == KEY_WINCH)
diff --git a/src/proto.h b/src/proto.h
index 4222a32..64528df 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -25,6 +25,10 @@
#include "nano.h"
/* All external variables. See global.c for their descriptions. */
+
+extern char *title;
+extern bool window_went_below_76;
+
#ifndef NANO_TINY
extern volatile sig_atomic_t sigwinch_counter;
#endif
@@ -379,6 +383,7 @@ void thanks_for_all_the_fish(void);
/* All functions in help.c. */
#ifndef DISABLE_HELP
+void display_the_help_text(bool redisplaying);
void do_help(void);
void help_init(void);
functionptrtype parse_help_input(int *kbinput);
diff --git a/src/search.c b/src/search.c
index 8a7b9b1..67b699e 100644
--- a/src/search.c
+++ b/src/search.c
@@ -126,6 +126,8 @@ int search_init(bool replacing, bool use_answer)
static char *backupstring = NULL;
/* The search string we'll be using. */
functionptrtype func;
+ int menu = ((currmenu == MHELP) ? MFINDINHELP :
+ (replacing ? MREPLACE : MWHEREIS));
/* If use_answer is TRUE, set backupstring to answer and get out. */
if (use_answer) {
@@ -154,7 +156,7 @@ int search_init(bool replacing, bool use_answer)
#ifndef DISABLE_TABCOMP
TRUE,
#endif
- replacing ? MREPLACE : MWHEREIS, backupstring,
+ menu, backupstring,
#ifndef DISABLE_HISTORIES
&search_history,
#endif
diff --git a/src/winio.c b/src/winio.c
index 18f98f0..0fe00f6 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1913,10 +1913,11 @@ char *display_string(const char *buf, size_t start_col, size_t span,
/* If path is NULL, we're in normal editing mode, so display the current
* version of nano, the current filename, and whether the current file
- * has been modified on the titlebar. If path isn't NULL, we're in the
- * file browser, and path contains the directory to start the file
- * browser in, so display the current version of nano and the contents
- * of path on the titlebar. */
+ * has been modified on the titlebar. If path isn't NULL, either we're
+ * in the file browser or help. If we are in file browser, path contains
+ * the directory to start the file browser in, so display the current
+ * version of nano and the contents of path on the titlebar. If we are
+ * in help, path contains the name of title of the help text. */
void titlebar(const char *path)
{
size_t verlen, prefixlen, pathlen, statelen;
@@ -1948,7 +1949,9 @@ void titlebar(const char *path)
/* Figure out the path, prefix and state strings. */
#ifndef DISABLE_BROWSER
- if (path != NULL)
+ if ((currmenu == MHELP || currmenu == MFINDINHELP) && path != NULL)
+ state = _("View");
+ else if (path != NULL)
prefix = _("DIR:");
else
#endif
@@ -3045,7 +3048,7 @@ void total_redraw(void)
void total_refresh(void)
{
total_redraw();
- titlebar(NULL);
+ titlebar(title);
edit_refresh();
bottombars(currmenu);
}
--
2.7.4