new feature: add a search facility to the help viewer

Allow the user to search in a help text with ^W and M-W.

Achieve this by not writing the help text directly to the screen
but first writing it to a temporary file and then opening this file
in a new buffer, and treating it specially: the normal file-reading
feedback is suppressed, the titlebar shows the headline of the text,
the cursor is hidden, and the menu is limited to just the up and down
movements and searching.

This fulfills https://savannah.gnu.org/bugs/?28994.

Signed-off-by: Rishabh Dave <rishabhddave@gmail.com>
This commit is contained in:
Rishabh Dave
2017-04-22 21:57:01 +05:30
committed by Benno Schulenberg
parent ca6d7b6a46
commit 90bd25c1bb
9 changed files with 207 additions and 105 deletions

View File

@@ -465,7 +465,7 @@ bool open_buffer(const char *filename, bool undoable)
if (new_buffer) {
make_new_buffer();
if (has_valid_path(realname)) {
if (!inhelp && has_valid_path(realname)) {
#ifndef NANO_TINY
if (ISSET(LOCKING) && filename[0] != '\0') {
/* When not overriding an existing lock, discard the buffer. */
@@ -484,7 +484,7 @@ 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, inhelp, &f) : -2;
/* If we have a file, and we're loading into a new buffer, update
* the filename. */
@@ -585,7 +585,8 @@ void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x,
void display_buffer(void)
{
/* Update the titlebar, since the filename may have changed. */
titlebar(NULL);
if (!inhelp)
titlebar(NULL);
#ifndef DISABLE_COLOR
/* Make sure we're using the buffer's associated colors. */
@@ -634,9 +635,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 (!inhelp)
statusline(HUSH, _("Switched to %s"),
((openfile->filename[0] == '\0') ?
_("New Buffer") : openfile->filename));
#ifdef DEBUG
dump_filestruct(openfile->current);
@@ -903,6 +905,10 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable,
/* Set the desired x position at the end of what was inserted. */
openfile->placewewant = xplustabs();
/* If we've read a help file, don't give any feedback. */
if (inhelp)
return;
if (!writable)
statusline(ALERT, _("File '%s' is unwritable"), filename);
#ifndef NANO_TINY
@@ -996,7 +1002,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 (!inhelp)
statusbar(_("Reading File"));
}