[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nano-devel] [PATCH] add an "atends" configuration setting
From: |
markweston |
Subject: |
Re: [Nano-devel] [PATCH] add an "atends" configuration setting |
Date: |
Mon, 30 Apr 2018 23:17:51 +0300 |
User-agent: |
Roundcube Webmail/1.3.6 |
From 82584e1a0d787b8f7bb9a5c553a38d4915529f21 Mon Sep 17 00:00:00 2001
From: Mark-Weston <address@hidden>
Date: Mon, 30 Apr 2018 23:10:27 +0300
Subject: [PATCH] Add towordends setting
When towordends is set and Ctrl+Right or Shift+Ctrl+Right is pressed,
nano will stop at the ends of words instead of their beginnings.
Signed-off-by: Mark-Weston <address@hidden>
---
doc/nano.texi | 8 ++++++++
doc/nanorc.5 | 3 +++
src/move.c | 29 ++++++++++++++++++++++-------
src/nano.c | 9 +++++++++
src/nano.h | 3 ++-
src/proto.h | 2 +-
src/rcfile.c | 1 +
src/text.c | 4 ++--
syntax/nanorc.nanorc | 2 +-
9 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/doc/nano.texi b/doc/nano.texi
index 03c7afb8..23e22aa8 100644
--- a/doc/nano.texi
+++ b/doc/nano.texi
@@ -392,6 +392,11 @@ is located at the very bottom of the editor.
Note: When accessing the help system, Expert Mode is temporarily
disabled to display the help-system navigation keys.
address@hidden -y
address@hidden --towordends
+Make Ctrl+Right and Shift+Ctrl+Right stop at word ends instead of
beginnings.
+
+
@item -z
@itemx --suspend
Enable the ability to suspend @command{nano} using the system's suspend
@@ -906,6 +911,9 @@ Save automatically on exit, don't prompt.
Use this color combination for the title bar.
@address@hidden functioncolor}} for valid color names.
address@hidden set towordends
+Make Ctrl+Right and Shift+Ctrl+Right stop at word ends instead of
beginnings.
+
@item set trimblanks
Remove trailing whitespace from wrapped lines when automatic
hard-wrapping occurs or when text is justified.
diff --git a/doc/nanorc.5 b/doc/nanorc.5
index 6a931f96..abbd5ef3 100644
--- a/doc/nanorc.5
+++ b/doc/nanorc.5
@@ -270,6 +270,9 @@ Valid names for the foreground and background colors
are:
The name of the foreground color may be prefixed with \fBbright\fR.
And either "\fIfgcolor\fR" or ",\fIbgcolor\fR" may be left out.
.TP
+.B set towordends
+Make Ctrl+Right and Shift+Ctrl+Right stop at word ends instead of
beginnings.
+.TP
.B set trimblanks
Remove trailing whitespace from wrapped lines when automatic
hard-wrapping occurs or when text is justified.
diff --git a/src/move.c b/src/move.c
index d4dd718f..9c1b195b 100644
--- a/src/move.c
+++ b/src/move.c
@@ -314,15 +314,17 @@ void do_prev_word(bool allow_punct, bool
update_screen)
edit_redraw(was_current, FLOWING);
}
-/* Move to the next word. If allow_punct is TRUE, treat punctuation
- * as part of a word. When requested, update the screen afterwards.
- * Return TRUE if we started on a word, and FALSE otherwise. */
-bool do_next_word(bool allow_punct, bool update_screen)
+/* Move to the next word. If to_word_ends is TRUE then stop at the ends
+ * of words instead of their beginnings. If allow_punct is TRUE, treat
+ * punctuation as part of a word. When requested, update the screen
+ * afterwards. Return TRUE if we started on a word, and FALSE
otherwise. */
+bool do_next_word(bool to_word_ends, bool allow_punct, bool
update_screen)
{
filestruct *was_current = openfile->current;
bool started_on_word = is_word_mbchar(openfile->current->data +
openfile->current_x, allow_punct);
bool seen_space = !started_on_word;
+ bool seen_word = started_on_word;
/* Move forward until we reach the start of a word. */
while (TRUE) {
@@ -340,6 +342,7 @@ bool do_next_word(bool allow_punct, bool
update_screen)
openfile->current_x);
}
+ if (!to_word_ends) {
/* If this is not a word character, then it's a separator; else
* if we've already seen a separator, then it's a word start. */
if (!is_word_mbchar(openfile->current->data +
openfile->current_x,
@@ -347,6 +350,17 @@ bool do_next_word(bool allow_punct, bool
update_screen)
seen_space = TRUE;
else if (seen_space)
break;
+ } else {
+ if (!is_word_mbchar(openfile->current->data +
openfile->current_x,
+ allow_punct))
+ if (seen_word)
+ break;
+ else
+ seen_space = true;
+ else
+ if (seen_space)
+ seen_word = true;
+ }
}
if (update_screen)
@@ -363,11 +377,12 @@ void do_prev_word_void(void)
do_prev_word(ISSET(WORD_BOUNDS), TRUE);
}
-/* Move to the next word in the file, treating punctuation as part of a
word
- * if the WORD_BOUNDS flag is set, and update the screen afterwards. */
+/* Move to the next word in the file. If TO_WORD_ENDS flag is set, stop
at word
+ * ends instead of beginnings. If WORD_BOUNDS flag is set, treat
punctuation as
+ * part of a word. Update the screen afterwards. */
void do_next_word_void(void)
{
- do_next_word(ISSET(WORD_BOUNDS), TRUE);
+ do_next_word(ISSET(TO_WORD_ENDS), ISSET(WORD_BOUNDS), TRUE);
}
/* Move to the beginning of the current line (or softwrapped chunk).
diff --git a/src/nano.c b/src/nano.c
index 09aacfbb..e7da4025 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -888,6 +888,9 @@ void usage(void)
print_opt("-w", "--nowrap", N_("Don't hard-wrap long lines"));
#endif
print_opt("-x", "--nohelp", N_("Don't show the two help lines"));
+#ifndef NANO_TINY
+ print_opt("-y", "--towordends", N_("Make Ctrl+Right stop at word
ends"));
+#endif
if (!ISSET(RESTRICTED))
print_opt("-z", "--suspend", N_("Enable suspension"));
#ifndef NANO_TINY
@@ -1982,6 +1985,7 @@ int main(int argc, char **argv)
{"autoindent", 0, NULL, 'i'},
{"cutfromcursor", 0, NULL, 'k'},
{"unix", 0, NULL, 'u'},
+ {"towordends", 0, NULL, 'y'},
{"softwrap", 0, NULL, '$'},
#endif
{NULL, 0, NULL, 0}
@@ -2235,6 +2239,11 @@ int main(int argc, char **argv)
case 'x':
SET(NO_HELP);
break;
+#ifndef NANO_TINY
+ case 'y':
+ SET(TO_WORD_ENDS);
+ break;
+#endif
case 'z':
SET(SUSPEND);
break;
diff --git a/src/nano.h b/src/nano.h
index 17a52369..293b62ee 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -543,7 +543,8 @@ enum
SHOW_CURSOR,
LINE_NUMBERS,
NO_PAUSES,
- AT_BLANKS
+ AT_BLANKS,
+ TO_WORD_ENDS
};
/* Flags for the menus in which a given function should be present. */
diff --git a/src/proto.h b/src/proto.h
index f2c51f93..ec6d925f 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -380,7 +380,7 @@ void do_para_end_void(void);
void do_prev_block(void);
void do_next_block(void);
void do_prev_word(bool allow_punct, bool update_screen);
-bool do_next_word(bool allow_punct, bool update_screen);
+bool do_next_word(bool to_word_ends, bool allow_punct, bool
update_screen);
void do_prev_word_void(void);
void do_next_word_void(void);
void do_home(void);
diff --git a/src/rcfile.c b/src/rcfile.c
index afa172ec..02ca9e03 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -112,6 +112,7 @@ static const rcoption rcopts[] = {
{"whitespace", 0},
{"wordbounds", WORD_BOUNDS},
{"wordchars", 0},
+ {"towordends", TO_WORD_ENDS},
#endif
#ifdef ENABLE_COLOR
{"titlecolor", 0},
diff --git a/src/text.c b/src/text.c
index 7f0bdb33..6d0cfac5 100644
--- a/src/text.c
+++ b/src/text.c
@@ -209,7 +209,7 @@ void do_cutword(bool backward)
if (backward)
do_prev_word(ISSET(WORD_BOUNDS), FALSE);
else
- do_next_word(ISSET(WORD_BOUNDS), FALSE);
+ do_next_word(FALSE, ISSET(WORD_BOUNDS), FALSE);
/* Set the mark at the start of that word. */
openfile->mark = openfile->current;
@@ -3459,7 +3459,7 @@ void do_wordlinechar_count(void)
* count whenever we're on a word just before moving. */
while (openfile->current != openfile->filebot ||
openfile->current->data[openfile->current_x] != '\0') {
- if (do_next_word(TRUE, FALSE))
+ if (do_next_word(FALSE, TRUE, FALSE))
words++;
}
diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc
index f71088cc..2eacd6cb 100644
--- a/syntax/nanorc.nanorc
+++ b/syntax/nanorc.nanorc
@@ -7,7 +7,7 @@ comment "#"
icolor brightred
"^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comment|linter|formatter|i?color|extendsyntax).*$"
# Keywords
-icolor brightgreen
"^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|trimblanks|unix|view|wordbounds)\>"
+icolor brightgreen
"^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|towordends|trimblanks|unix|view|wordbounds)\>"
icolor yellow
"^[[:space:]]*set[[:space:]]+((error|function|key|number|selected|status|title)color)[[:space:]]+(bright)?(white|black|red|blue|green|yellow|magenta|cyan|normal)?(,(white|black|red|blue|green|yellow|magenta|cyan|normal))?\>"
icolor brightgreen
"^[[:space:]]*set[[:space:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|punct|quotestr|selectedcolor|speller|statuscolor|titlecolor|whitespace|wordchars)[[:space:]]+"
icolor brightgreen
"^[[:space:]]*bind[[:space:]]+((\^([[:alpha:]]|[]0-9\^_]|Space)|M-([[:alpha:]]|[]!"#$%&'()*+,./0-9:;<=>address@hidden|}~-]|Space))|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+([[:alpha:]]+|".*")[[:space:]]+(all|main|search|replace(with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)"
--
2.17.0