[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] new feature: option --stateflags to show some states at the top
From: |
Benno Schulenberg |
Subject: |
[PATCH] new feature: option --stateflags to show some states at the top right |
Date: |
Sun, 20 Sep 2020 10:50:35 +0200 |
With --stateflags (short form: -%) or 'set stateflags', nano reserves
the righthand end of the title bar not for showing "Modified" but for
showing the state of auto-indentation (I), the mark (M), the breaking
of long lines (L), macro recording (R), and softwrapping (S).
When the buffer is modified, this is indicated with two stars (**)
after the file name in the center of the title bar.
This fulfills https://savannah.gnu.org/bugs/?57953.
Requested-by: Sébastien Desreux <seb@h-k.fr>
---
src/definitions.h | 3 ++-
src/nano.c | 17 ++++++++++++++++-
src/rcfile.c | 1 +
src/winio.c | 18 ++++++++++++++++++
4 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/src/definitions.h b/src/definitions.h
index e0b458e6..f14a6947 100644
--- a/src/definitions.h
+++ b/src/definitions.h
@@ -541,7 +541,8 @@ enum
JUMPY_SCROLLING,
EMPTY_LINE,
INDICATOR,
- BOOKSTYLE
+ BOOKSTYLE,
+ STATEFLAGS
};
/* Flags for the menus in which a given function should be present. */
diff --git a/src/nano.c b/src/nano.c
index 75c0c9b5..2d759e89 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -497,6 +497,7 @@ void usage(void)
#ifndef NANO_TINY
/* TRANSLATORS: The next forty or so strings are option descriptions
* for the --help output. Try to keep them at most 40 characters. */
+ print_opt("-%", "--stateflags", N_("Show some states on the title
bar"));
print_opt("-A", "--smarthome", N_("Enable smart home key"));
if (!ISSET(RESTRICTED)) {
print_opt("-B", "--backup", N_("Save backups of existing
files"));
@@ -1111,6 +1112,10 @@ void do_toggle(int flag)
#endif
}
+ if (ISSET(STATEFLAGS) && (flag == AUTOINDENT ||
+ flag == BREAK_LONG_LINES ||
flag == SOFTWRAP))
+ titlebar(NULL);
+
enabled = ISSET(flag);
if (flag == NO_HELP || flag == NO_SYNTAX)
@@ -1526,6 +1531,9 @@ void process_a_keystroke(void)
/* The input buffer for actual characters. */
static size_t depth = 0;
/* The length of the input buffer. */
+#ifndef NANO_TINY
+ linestruct *was_mark = openfile->mark;
+#endif
static bool give_a_hint = TRUE;
const keystruct *shortcut;
@@ -1665,6 +1673,9 @@ void process_a_keystroke(void)
#ifndef NANO_TINY
if (bracketed_paste)
suck_up_input_and_paste_it();
+
+ if (ISSET(STATEFLAGS) && openfile->mark != was_mark)
+ titlebar(NULL);
#endif
}
@@ -1751,6 +1762,7 @@ int main(int argc, char **argv)
{"nohelp", 0, NULL, 'x'},
{"suspendable", 0, NULL, 'z'},
#ifndef NANO_TINY
+ {"stateflags", 0, NULL, '%'},
{"smarthome", 0, NULL, 'A'},
{"backup", 0, NULL, 'B'},
{"backupdir", 1, NULL, 'C'},
@@ -1827,10 +1839,13 @@ int main(int argc, char **argv)
if (*(tail(argv[0])) == 'r')
SET(RESTRICTED);
- while ((optchr = getopt_long(argc, argv,
"ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z"
+ while ((optchr = getopt_long(argc, argv,
"%ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z"
"abcdef:ghijklmno:pqr:s:tuvwxyz$",
long_options, NULL)) != -1) {
switch (optchr) {
#ifndef NANO_TINY
+ case '%':
+ SET(STATEFLAGS);
+ break;
case 'A':
SET(SMART_HOME);
break;
diff --git a/src/rcfile.c b/src/rcfile.c
index b908f2ce..d8021402 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -114,6 +114,7 @@ static const rcoption rcopts[] = {
{"smarthome", SMART_HOME},
{"smooth", SMOOTH_SCROLL}, /* Deprecated; remove in 2021. */
{"softwrap", SOFTWRAP},
+ {"stateflags", STATEFLAGS},
{"tabstospaces", TABS_TO_SPACES},
{"trimblanks", TRIM_BLANKS},
{"unix", MAKE_IT_UNIX},
diff --git a/src/winio.c b/src/winio.c
index 3ec15201..00a25b6b 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -97,6 +97,9 @@ void record_macro(void)
snip_last_keystroke();
statusbar(_("Stopped recording"));
}
+
+ if (ISSET(STATEFLAGS))
+ titlebar(NULL);
}
/* Copy the stored sequence of codes into the regular key buffer,
@@ -1973,6 +1976,9 @@ void titlebar(const char *path)
else
path = openfile->filename;
+ if (ISSET(STATEFLAGS) && !ISSET(VIEW_MODE))
+ state = "++.xxxxx";
+ else
if (openfile->modified)
state = _("Modified");
else if (ISSET(VIEW_MODE))
@@ -2036,11 +2042,23 @@ void titlebar(const char *path)
free(caption);
}
+ if (ISSET(STATEFLAGS) && !ISSET(VIEW_MODE)) {
+ if (statelen > 0 && statelen <= COLS) {
+ waddstr(topwin, openfile->modified ? " **" : " ");
+ wmove(topwin, 0, COLS + 3 - statelen);
+ waddstr(topwin, ISSET(AUTOINDENT) ? "I" : " ");
+ waddstr(topwin, openfile->mark ? "M" : " ");
+ waddstr(topwin, ISSET(BREAK_LONG_LINES) ? "L" : " ");
+ waddstr(topwin, recording ? "R" : " ");
+ waddstr(topwin, ISSET(SOFTWRAP) ? "S" : " ");
+ }
+ } else {
/* Right-align the state if there's room; otherwise, trim it. */
if (statelen > 0 && statelen <= COLS)
mvwaddstr(topwin, 0, COLS - statelen, state);
else if (statelen > 0)
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
+ }
wattroff(topwin, interface_color_pair[TITLE_BAR]);
--
2.25.4
- [PATCH] new feature: option --stateflags to show some states at the top right,
Benno Schulenberg <=