nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit b84f6fc15f25e7bdd450fb4128ef0d4979aaff16
parent d0a1bc361a7b8a158eeb03cb2a246ae37e81e6d9
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Mon, 29 Jan 2024 16:45:06 +0100

general: include the Copy function (M-6 or ^C) into the tiny version

When using --modernbindings with the tiny version, it was strange that
^X cuts and ^V pastes but ^C complains about being unbound.  Fix that.

Diffstat:
Msrc/cut.c | 13+++++++++++--
Msrc/global.c | 13++++++++-----
Msrc/nano.c | 4++--
Msrc/prototypes.h | 2+-
Msrc/rcfile.c | 4++--
5 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/src/cut.c b/src/cut.c @@ -634,6 +634,7 @@ void copy_marked_region(void) botline->data[bot_x] = saved_byte; botline->next = afterline; } +#endif /* !NANO_TINY */ /* Copy text from the current buffer into the cutbuffer. The text is either * the marked region, the whole line, the text from cursor to end-of-line, @@ -646,17 +647,24 @@ void copy_text(void) linestruct *was_current = openfile->current; linestruct *addition; - if (openfile->mark || openfile->last_action != COPY || !keep_cutbuffer) { +#ifndef NANO_TINY + if (openfile->mark || openfile->last_action != COPY) + keep_cutbuffer = FALSE; +#endif + + if (!keep_cutbuffer) { free_lines(cutbuffer); cutbuffer = NULL; } wipe_statusbar(); +#ifndef NANO_TINY if (openfile->mark) { copy_marked_region(); return; } +#endif /* When at the very end of the buffer, there is nothing to do. */ if (openfile->current->next == NULL && at_eol && (ISSET(CUT_FROM_CURSOR) || @@ -706,10 +714,11 @@ void copy_text(void) edit_redraw(was_current, FLOWING); +#ifndef NANO_TINY openfile->last_action = COPY; +#endif keep_cutbuffer = TRUE; } -#endif /* !NANO_TINY */ /* Copy text from the cutbuffer into the current buffer. */ void paste_text(void) diff --git a/src/global.c b/src/global.c @@ -561,6 +561,8 @@ void shortcut_init(void) N_("Search backward for a string or a regular expression"); const char *cut_gist = N_("Cut current line (or marked region) and store it in cutbuffer"); + const char *copy_gist = + N_("Copy current line (or marked region) and store it in cutbuffer"); const char *paste_gist = N_("Paste the contents of cutbuffer at current cursor position"); const char *cursorpos_gist = N_("Display the position of the cursor"); @@ -571,8 +573,6 @@ void shortcut_init(void) const char *gotoline_gist = N_("Go to line and column number"); #ifndef NANO_TINY const char *mark_gist = N_("Mark text starting from the cursor position"); - const char *copy_gist = - N_("Copy current line (or marked region) and store it in cutbuffer"); const char *zap_gist = N_("Throw away the current line (or marked region)"); const char *indent_gist = N_("Indent the current line (or marked lines)"); const char *unindent_gist = N_("Unindent the current line (or marked lines)"); @@ -982,6 +982,9 @@ void shortcut_init(void) #ifndef NANO_TINY add_to_funcs(count_lines_words_and_characters, MMAIN, N_("Word Count"), WHENHELP(wordcount_gist), TOGETHER); +#else + add_to_funcs(copy_text, MMAIN, + N_("Copy"), WHENHELP(copy_gist), BLANKAFTER); #endif add_to_funcs(do_verbatim_input, MMAIN, @@ -1191,9 +1194,9 @@ void shortcut_init(void) add_to_sclist(MMAIN, "^Z", 0, do_undo, 0); add_to_sclist(MMAIN, "^Y", 0, do_redo, 0); add_to_sclist(MMAIN, "^A", 0, do_mark, 0); - add_to_sclist(MMAIN, "^C", 0, copy_text, 0); #endif add_to_sclist(MMAIN, "^X", 0, cut_text, 0); + add_to_sclist(MMAIN, "^C", 0, copy_text, 0); add_to_sclist(MMAIN, "^V", 0, paste_text, 0); } else { add_to_sclist((MMOST|MBROWSER) & ~MFINDINHELP, "^G", 0, do_help, 0); @@ -1224,6 +1227,8 @@ void shortcut_init(void) add_to_sclist(MMAIN, "^\\", 0, do_replace, 0); add_to_sclist(MMAIN, "M-R", 0, do_replace, 0); add_to_sclist(MMOST, "^K", 0, cut_text, 0); + add_to_sclist(MMOST, "M-6", 0, copy_text, 0); + add_to_sclist(MMOST, "M-^", 0, copy_text, 0); #ifdef NANO_TINY add_to_sclist(MMAIN, "^U", 0, paste_text, 0); #ifdef ENABLE_SPELLER @@ -1275,8 +1280,6 @@ void shortcut_init(void) add_to_sclist(MMAIN, "M-A", 0, do_mark, 0); add_to_sclist(MMAIN, "^6", 0, do_mark, 0); add_to_sclist(MMAIN, "^^", 0, do_mark, 0); - add_to_sclist(MMOST, "M-6", 0, copy_text, 0); - add_to_sclist(MMOST, "M-^", 0, copy_text, 0); add_to_sclist(MMAIN, "M-}", 0, do_indent, 0); add_to_sclist(MMAIN, "", INDENT_KEY, do_indent, 0); add_to_sclist(MMAIN, "M-{", 0, do_unindent, 0); diff --git a/src/nano.c b/src/nano.c @@ -1645,9 +1645,9 @@ void process_a_keystroke(void) give_a_hint = FALSE; /* When not cutting or copying text, drop the cutbuffer the next time. */ - if (function != cut_text) { + if (function != cut_text && function != copy_text) { #ifndef NANO_TINY - if (function != copy_text && function != zap_text) + if (function != zap_text) #endif keep_cutbuffer = FALSE; } diff --git a/src/prototypes.h b/src/prototypes.h @@ -270,8 +270,8 @@ void cut_text(void); void cut_till_eof(void); void zap_text(void); void copy_marked_region(void); -void copy_text(void); #endif +void copy_text(void); void paste_text(void); /* Most functions in files.c. */ diff --git a/src/rcfile.c b/src/rcfile.c @@ -245,6 +245,8 @@ keystruct *strtosc(const char *input) s->func = do_replace; else if (!strcmp(input, "cut")) s->func = cut_text; + else if (!strcmp(input, "copy")) + s->func = copy_text; else if (!strcmp(input, "paste")) s->func = paste_text; #ifndef NANO_TINY @@ -252,8 +254,6 @@ keystruct *strtosc(const char *input) s->func = do_execute; else if (!strcmp(input, "cutrestoffile")) s->func = cut_till_eof; - else if (!strcmp(input, "copy")) - s->func = copy_text; else if (!strcmp(input, "zap")) s->func = zap_text; else if (!strcmp(input, "mark"))