Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes an empty line is appended when processing a text selection with Notepad++ #57

Closed
pidgeon777 opened this Issue Feb 12, 2019 · 8 comments

Comments

Projects
None yet
2 participants
@pidgeon777
Copy link

pidgeon777 commented Feb 12, 2019

A demonstration follows below. At first, there is only one empty line after the selected text, but when I process the selection through "$(boxes_p)" -i box -t 4 -d c-cmt2 "$(ascfile)" "$(tempfile)", then a further empty line is added:

b23wiwn63t

The sample text I'm trying to enclose with Boxes:

	Basedsad
	as as dsa dsa readdirsad stackavail asd 
	as das das
	
			dfsdf
			sadfsdf
			sdfsdf
			
			   asdasd
			   asdasdff
			   f

  asd
    as fas 
	fas 
as

I'm using boxes version 1.2.

@tsjensen

This comment has been minimized.

Copy link
Member

tsjensen commented Feb 13, 2019

Thanks for the report. We'll have to find out if it's an NppExec issue or a boxes issue. Therefore, can you please share binary copies of the temp files? By "temp files" I am referring to the files referenced as $(ascfile) and $(tempfile) in the macro.

If you leave out the last line of the NppExec macro (the one that deletes the temp files), you can find them on disk. Also please share the exact NppExec macro code, so that I can try to reproduce the situation. Thank you!

@pidgeon777

This comment has been minimized.

Copy link
Author

pidgeon777 commented Feb 13, 2019

NppExec script run in Notepad++:

cls

cmd.exe /c exit %RANDOM%

set tempfile = $(SYS.TEMP)\NppBoxes_$(EXITCODE).out.txt
set ascfile = $(SYS.TEMP)\NppBoxes_$(EXITCODE).in.txt

sel_saveto $(ascfile) :a

boxes -i box -t 4 -d c-cmt2 "$(ascfile)" "$(tempfile)"

sel_loadfrom $(tempfile)
cmd.exe /c del /f /q "$(tempfile)" "$(ascfile)"

Generated files:

NppBoxes_28763.in.txt

NppBoxes_28763.out.txt

@tsjensen

This comment has been minimized.

Copy link
Member

tsjensen commented Feb 13, 2019

Ok, thank you. I think I understand now. It appears to be a case of "works as designed", but prove me wrong.

boxes always assumes it is working on complete lines of text. That's just how the program works, and I think that's reasonable. If a line is not properly terminated with a newline character (can easily happen for example by echo -n foo | boxes), then boxes assumes it's being fed a line of text.
Consequently, boxes outputs lines of text, each with their proper line endings.

In contrast to that, NppExec does not work on lines, but on chunks of text which are currently selected - these chunks can start anywhere, even square in the middle of a line.
This is a mismatch of concepts between NppExec and boxes that we just need to be aware of.

So when you select less than a complete line in Notepad++, then boxes must add a line terminator at the end of the last line. To Notepad++, this is new, and causes the extra line break.

TL/DR: In order to avoid this problem, make sure that you always select entire lines before pressing the hotkey. "Entire lines" meaning "including their newlines". You can do that by placing the cursor at position 0 of a line, then selecting lines by pressing Shift+CursorDown.

@tsjensen

This comment has been minimized.

Copy link
Member

tsjensen commented Feb 13, 2019

Then again, the more I think about it, maybe we could make it the default behavior to have a newline character at the very end of boxes output only if there also was one at the very end of the input. This problem would be solved, but I need to think about it some more in order to see if it might cause other problems. Also, I don't know off the cuff if the input processing abstractions let us know about this, but I'll check.

@pidgeon777

This comment has been minimized.

Copy link
Author

pidgeon777 commented Feb 14, 2019

I think that the final newline character checking you proposed could do the trick. Hopefully, you'll have a chance to investigate more on this, it would be nice in my opinion to enhance this behaviour.

In any case, thank you.

@tsjensen

This comment has been minimized.

Copy link
Member

tsjensen commented Feb 14, 2019

I agree. I'll leave this open as a reminder. 😉

@pidgeon777

This comment has been minimized.

Copy link
Author

pidgeon777 commented Feb 14, 2019

Great, thank you!

tsjensen added a commit that referenced this issue Feb 17, 2019

Improve handling of partial lines
When boxes is fed text selected in a visual editor, this often means that
the final line of input text has no terminating newline (it's a "partial
line"). This caused an extra blank line to appear in the editor after
running boxes. #57
This commit changes the behavior of boxes so that a newline is only added
at the very end of the output, if there also was one at the very end of
the input.
@tsjensen

This comment has been minimized.

Copy link
Member

tsjensen commented Feb 21, 2019

Fixed in boxes 1.3, which was just released!

@tsjensen tsjensen closed this Feb 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.