From a48bcb2a36e2a4fefdc1305d482107b8a2afbb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Fri, 11 May 2018 15:32:14 -0300 Subject: [PATCH 4/4] Minor improvements to pipe to external tool feature. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Diego Aurélio Mesquita --- src/files.c | 2 -- src/global.c | 10 +++++----- src/text.c | 12 ++++++++---- src/utils.c | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/files.c b/src/files.c index 9cdbc6bc..de1f91f2 100644 --- a/src/files.c +++ b/src/files.c @@ -1112,7 +1112,6 @@ void do_insertfile(void) #endif if (func == flip_pipe) { if (answer && answer[0] == '|') { - fprintf(stderr, "First char is a pipe, we should remove it.\n"); char *aux = mallocstrcpy(NULL, &answer[1]); free(answer); answer = aux; @@ -1123,7 +1122,6 @@ void do_insertfile(void) answer = aux; } - statusbar_x = strlenpt(answer) + 1; given = mallocstrcpy(given, answer); continue; } diff --git a/src/global.c b/src/global.c index 996aec3b..bd9ce869 100644 --- a/src/global.c +++ b/src/global.c @@ -529,7 +529,7 @@ void shortcut_init(void) const char *readfile_gist = N_("Insert another file into current buffer (or into new buffer)"); const char *pipe_gist = - N_("Pipe current file or selction to external command"); + N_("Pipe the current buffer (or marked region) to the command"); const char *whereis_gist = N_("Search forward for a string or a regular expression"); const char *wherewas_gist = @@ -1032,9 +1032,6 @@ void shortcut_init(void) add_to_funcs(flip_execute, MEXTCMD, readfile_tag, WITHORSANS(readfile_gist), TOGETHER, NOVIEW); - - add_to_funcs(flip_pipe, MEXTCMD, - pipe_tag, WITHORSANS(pipe_gist), TOGETHER, NOVIEW); } #endif /* !NANO_TINY */ #ifdef ENABLE_MULTIBUFFER @@ -1043,6 +1040,9 @@ void shortcut_init(void) add_to_funcs(flip_newbuffer, MINSERTFILE|MEXTCMD, N_("New Buffer"), WITHORSANS(newbuffer_gist), TOGETHER, NOVIEW); #endif + if (!ISSET(RESTRICTED)) + add_to_funcs(flip_pipe, MEXTCMD, + pipe_tag, WITHORSANS(pipe_gist), TOGETHER, NOVIEW); #ifdef ENABLE_BROWSER /* The file browser is only available when not in restricted mode. */ @@ -1340,7 +1340,7 @@ void shortcut_init(void) /* Only when not in restricted mode, allow multiple buffers. */ if (!ISSET(RESTRICTED)) { add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", 0, flip_newbuffer, 0); - add_to_sclist(MEXTCMD, "^\\", 0, flip_pipe, 0); + add_to_sclist(MEXTCMD, "M-\\", 0, flip_pipe, 0); } #endif #ifdef ENABLE_BROWSER diff --git a/src/text.c b/src/text.c index ebea0bbe..ae3546ae 100644 --- a/src/text.c +++ b/src/text.c @@ -1163,13 +1163,9 @@ bool execute_command(const char *command) cutbuffer = NULL; if(has_selection) { - #ifndef NANO_TINY add_undo(CUT); - #endif do_cut_text(ISSET(MULTIBUFFER), !has_selection); - #ifndef NANO_TINY update_undo(CUT); - #endif } if(fork() == 0) { @@ -1182,6 +1178,14 @@ bool execute_command(const char *command) close(to_fd[1]); } + if (!has_selection && !ISSET(MULTIBUFFER)) { + openfile->current = openfile->fileage; + openfile->current_x = 0; + add_undo(CUT); + do_cut_text(FALSE, TRUE); + update_undo(CUT); + } + free_filestruct(cutbuffer); cutbuffer = was_cutbuffer; diff --git a/src/utils.c b/src/utils.c index 6db9ed7c..9e500bef 100644 --- a/src/utils.c +++ b/src/utils.c @@ -476,7 +476,7 @@ size_t strlenpt(const char *text) { size_t span = 0; - while (text && *text != '\0') + while (*text != '\0') text += parse_mbchar(text, NULL, &span); return span; -- 2.11.0