Skip to content

Commit

Permalink
Feature: don't wrap around to the start of buffer when search (nosear…
Browse files Browse the repository at this point in the history
…chwrap)
  • Loading branch information
davidhcefx committed May 27, 2024
1 parent d4d5349 commit 2149f2c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/nano.1
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ With \fBM\-X\fR the help lines.
.BR \-! ", " \-\-magic
When neither the file's name nor its first line give a clue,
try using libmagic to determine the applicable syntax.
.TP
.BR \-\-nosearchwrap
Don't wrap around to the start or end of the buffer when performing search or replace.

.SH TOGGLES
Several of the above options can be switched on and off also while
Expand Down
3 changes: 3 additions & 0 deletions doc/nanorc.5
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ Don't display the two help lines at the bottom of the screen.
Don't automatically add a newline when a text does not end with one.
(This can cause you to save non-POSIX text files.)
.TP
.B set nosearchwrap
Don't wrap around to the start or end of the buffer when performing search or replace.
.TP
.B set nowrap
Deprecated option since it has become the default setting.
When needed, use \fBunset breaklonglines\fR instead.
Expand Down
1 change: 1 addition & 0 deletions src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ enum {
CONSTANT_SHOW,
NO_HELP,
SUSPENDABLE,
NO_SEARCH_WRAP,
NO_WRAP,
AUTOINDENT,
VIEW_MODE,
Expand Down
5 changes: 5 additions & 0 deletions src/nano.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ void usage(void)
#ifdef HAVE_LIBMAGIC
print_opt("-!", "--magic", N_("Also try magic to determine syntax"));
#endif
print_opt("", "--nosearchwrap", N_("Don't wrap past EOF when search/replace"));
}

/* Display the version number of this nano, a copyright notice, some contact
Expand Down Expand Up @@ -1773,6 +1774,7 @@ int main(int argc, char **argv)
#ifdef HAVE_LIBMAGIC
{"magic", 0, NULL, '!'},
#endif
{"nosearchwrap", 0, NULL, '\x01'},
{NULL, 0, NULL, 0}
};

Expand Down Expand Up @@ -2064,6 +2066,9 @@ int main(int argc, char **argv)
SET(USE_MAGIC);
break;
#endif
case '\x01':
SET(NO_SEARCH_WRAP);
break;
default:
printf(_("Type '%s -h' for a list of available options.\n"), argv[0]);
exit(1);
Expand Down
1 change: 1 addition & 0 deletions src/rcfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static const rcoption rcopts[] = {
#endif
{"nohelp", NO_HELP},
{"nonewlines", NO_NEWLINES},
{"nosearchwrap", NO_SEARCH_WRAP},
#ifdef ENABLE_WRAPPING
{"nowrap", NO_WRAP}, /* Deprecated; remove in 2024. */
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ int findnextstr(const char *needle, bool whole_word_only, int modus,
/* If we've reached the start or end of the buffer, wrap around;
* but stop when spell-checking or replacing in a region. */
if (line == NULL) {
if (whole_word_only || modus == INREGION) {
if (whole_word_only || modus == INREGION || ISSET(NO_SEARCH_WRAP)) {
nodelay(midwin, FALSE);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion syntax/nanorc.nanorc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ color bold,purple "^[[:blank:]]*include[[:blank:]][^"]*([[:blank:]]|$)"
color lime "^[[:blank:]]*extendsyntax[[:blank:]]+[[:alpha:]]+[[:blank:]]+(i?color|header|magic|comment|formatter|linter|tabgives)[[:blank:]]+.*"

# The arguments of commands
color brightgreen "^[[:blank:]]*(set|unset)[[:blank:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|boldtext|bookstyle|breaklonglines|casesensitive|constantshow|cutfromcursor|emptyline|historylog|indicator|jumpyscrolling|linenumbers|locking|magic|minibar|mouse|multibuffer|noconvert|nohelp|nonewlines|positionlog|preserve|quickblank|rawsequences|rebinddelete|regexp|saveonexit|showcursor|smarthome|softwrap|stateflags|tabstospaces|trimblanks|unix|wordbounds|zap|zero)\>"
color brightgreen "^[[:blank:]]*(set|unset)[[:blank:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|boldtext|bookstyle|breaklonglines|casesensitive|constantshow|cutfromcursor|emptyline|historylog|indicator|jumpyscrolling|linenumbers|locking|magic|minibar|mouse|multibuffer|noconvert|nohelp|nosearchwrap|nonewlines|positionlog|preserve|quickblank|rawsequences|rebinddelete|regexp|saveonexit|showcursor|smarthome|softwrap|stateflags|tabstospaces|trimblanks|unix|wordbounds|zap|zero)\>"
color brightgreen "^[[:blank:]]*set[[:blank:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|minicolor|numbercolor|operatingdir|promptcolor|punct|quotestr|scrollercolor|selectedcolor|speller|spotlightcolor|statuscolor|stripecolor|titlecolor|whitespace|wordchars)[[:blank:]]+"
color brightgreen "^[[:blank:]]*set[[:blank:]]+(fill[[:blank:]]+-?[[:digit:]]+|(guidestripe|tabsize)[[:blank:]]+[1-9][0-9]*)\>"
color brightgreen "^[[:blank:]]*bind[[:blank:]]+((\^([A-Za-z]|[]/@\^_`-]|Space)|([Ss][Hh]-)?[Mm]-[A-Za-z]|[Mm]-([][!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-9]|2[0-4])|Ins|Del)[[:blank:]]+([a-z]+|".*")[[:blank:]]+(main|help|search|replace(with)?|yesno|gotoline|writeout|insert|execute|browser|whereisfile|gotodir|spell|linter|all)\>"
Expand Down

0 comments on commit 2149f2c

Please sign in to comment.