nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] [PATCH] Pipe selected text to external tool


From: Brand Huntsman
Subject: Re: [Nano-devel] [PATCH] Pipe selected text to external tool
Date: Fri, 16 Feb 2018 21:55:12 -0700

On Sat, 17 Feb 2018 00:10:46 -0200
Marco Diego Aurélio Mesquita <address@hidden> wrote:

> > Position cursor at first character in NEWS and shift-down until
> > cursor is on the first blank line. Now execute "sed s:match:foo:g",
> > it inserts an extra line. It even happens if you press left arrow
> > to move cursor to end of the last selected line. 
> 
> I noticed it but I have no idea what causes this. Any hint?

Use the following as the command in nano:
while read line; do echo "[$line]"; done < /dev/stdin

Select a single line, if the cursor is on the next line, you get:
[...]
[]
But if the cursor is on the end of the line, you get:
[...]
-blank-line-

The cutbuffer has an empty line at the end if cursor is the start of the next 
line. send_data() needs to detect this and not send that final line. And if the 
cutbuffer doesn't contain that empty line, then don't send a linefeed on the 
last line.

Something like this:

    if (fp == NULL || inptr == NULL)
        return;

    filestruct *prev = NULL, *last_line;
    for (filestruct *i = (filestruct *)inptr; i != NULL; prev = i, i = i->next);
    if (prev->data[0] == '\0') {
        /* Last line in cutbuffer is empty, ignore it. */
        last_line = NULL;
        prev->prev->next = NULL;
        free_filestruct(prev);
    } else
        last_line = prev;

    while (inptr != NULL) { 
        if (inptr == last_line) 
            fprintf(fp, "%s", inptr->data);
        else
            fprintf(fp, "%s\n", inptr->data);
        inptr = inptr->next;
    }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]