Bug 125104

Summary: "Join lines" should maintain one-line separation between paragraphs
Product: [Applications] kate Reporter: Shriramana Sharma <samjnaa>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: python script that unwraps lines
Prototype Katescript for Unwrap

Description Shriramana Sharma 2006-04-07 10:32:15 UTC
Version:           2.5.2 (using KDE 3.5.2 Level "a" , SUSE 10.0 UNSUPPORTED)
Compiler:          Target: i586-suse-linux
OS:                Linux (i686) release 2.6.13-15-smp

Currently, the behaviour of Join Lines is that:

------------------------------
line 1
line 2

line 3
line 4
------------------------------

becomes

------------------------------
line 1 line 2 line 3 line 4
------------------------------

whereas the desired behaviour is to recognize paragraphs split in plain text by a blank line, so:

------------------------------
line 1 line 2

line 3 line 4
------------------------------

As it is, to rewrap an entire document with paragraphs, we are forced to manually select each paragraph and apply "Join Lines" to it. While doing this, if there are many blank lines between paragraphs keep only one of them.
Comment 1 Dominik Haumann 2006-04-07 11:41:10 UTC
It does, what it is supposed to do: It joins the lines.
Your report is not entirely clear: Do you mean join lines from a selected text?
Comment 2 Shriramana Sharma 2006-04-07 14:45:22 UTC
Well let me rephrase my request. I believe what the Join Lines facility actually needs to do is "unwrap" -- opposite of the Word Wrap facility. Take the following example:

------------------------------
SAMPLE A
------------------------------
Hello. My name is Shriramana Sharma. I use KDE 3.52. It is an excellent desktop environment.

I have been using KDE ever since I started using Linux.
------------------------------

The above text when wrapped becomes:

------------------------------
SAMPLE B
------------------------------
Hello. My name is Shriramana 
Sharma. I use KDE 3.52. It is 
an excellent desktop 
environment.

I have been using KDE ever
since I started using Linux.
------------------------------

Now what I want the Join Lines facility to do is give me back the original text (Sample A) above, and not the following:

------------------------------
SAMPLE C
------------------------------
Hello. My name is Shriramana Sharma. I use KDE 3.52. It is an excellent desktop environment. I have been using KDE ever since I started using Linux.
------------------------------

As it is, the Join Lines facility when applied to Sample B gives Sample C as the output and not Sample A. 

I do not believe that anyone would need the entire text in a word-wrapped document rolled up into one big ball, as the current Join Lines facility does. Whenever people have a blank line between two sets of word-wrapped lines (as in Sample B) it means that they are two different paragraphs. 

As such, joining the lines, which is conceptually the opposite of word-wrapping the lines, should maintain this separation of the paragraphs by providing Sample A as the output and not Sample C.

If you think that people do have need for a Join All Lines Together facility that rolls up all the lines into one paragraph (see Sample C) then make it an additional facility. But Join Lines, to my mind, is another way of saying "Unwrap Lines", and should provide Sample A as its output and not Sample C.

I hope that makes things clearer.

P.S: Perhaps I should have labeled this a wishlist item instead of a bug?
Comment 3 Ryan Dalzell 2006-04-07 17:48:09 UTC
Well I, for one, think that the "Join Lines" command should join lines, and that's what it does.

For "unwrapping" text in this manner, you would be much better off using "Filter Text" command to pipe your text to a little bit of Perl, or whatever you prefer, to edit the text as you wish.
Comment 4 Anders Lund 2006-04-07 18:05:14 UTC
On Friday 07 April 2006 14:45, Shriramana Sharma wrote:
> Well let me rephrase my request. I believe what the Join Lines facility
> actually needs to do is "unwrap" -- opposite of the Word Wrap facility


Why???? Join lines is supposed to 'join lines', not 'unwrap'. What you 
describe is a different action as I see it.
Comment 5 Anders Lund 2006-04-07 19:14:40 UTC
On Friday 07 April 2006 17:48, Ryan Dalzell wrote:
> For "unwrapping" text in this manner, you would be much better off using
> "Filter Text" command to pipe your text to a little bit of Perl, or
> whatever you prefer, to edit the text as you wish.


... or you could write a javascript to do it
Comment 6 Dominik Haumann 2006-04-07 23:21:12 UTC
Yes, please write a "unwrap" script in javascript. Information can be found here http://drupal.kate-editor.org/article/scripting_katepart_with_javascript and when you are finish, you can attach it to this wish. -- Thanks! ;)
Comment 7 Shriramana Sharma 2006-04-08 04:44:17 UTC
Right, I agree that Join Lines is a different thing from unwrap. However, I do not have the programming knowledge to write Javascript plugins or anything like that. That is why I request the knowledgeable programmers to do that. From what little programming knowledge I have, I presume one could just change the Join Lines code to identify wherever two newlines are continuous and not replace them with a space.
Comment 8 Shriramana Sharma 2006-04-08 05:18:59 UTC
I downloaded the kdebase and kdeaddons packages for 3.52, but I am unable to identify where the Join Lines utility is. I may be able, even with my minimal knowledge, to adapt that code to implement the Unwrap feature -- provided it is not too difficult for me. 

Please tell me where to find the Join Lines code. A text search among the two packages for "join lines" did not help. Thanks.
Comment 9 Shriramana Sharma 2007-04-14 19:05:57 UTC
Hello. It's over a year since my last comment but no reply. Please if anyone tells me where the code for Join Lines and Word Wrap functions is, I may look into creating an unwrap function. I find searching the KDE sources via websvn a trying experience.
Comment 10 Dominik Haumann 2007-04-16 08:40:51 UTC
file: kdelibs/kate/part/katedocument.cpp
look for: void KateDocument::joinLines( uint first, uint last )
Comment 11 Shriramana Sharma 2007-10-09 08:47:58 UTC
Created attachment 21778 [details]
python script that unwraps lines

This is a script I wrote in Python for unwrapping lines. It works. Now that the
algorithm is there (and in public domain) someone with better KDE/Qt/C++
knowledge than I can adapt it as appropriate.
Comment 12 Shriramana Sharma 2009-02-17 13:58:30 UTC
Hello it is again over a year since my last post and KDE 4.2 has been released. I presume that with the presence of the Kross scripting framework, Python can now be used to script KDE applications, so since my JavaScript knowledge is insufficient can someone integrate this script into KWrite? Thanks for your good work! I really am proud to use KDE 4.2.
Comment 13 Shriramana Sharma 2009-08-14 08:09:20 UTC
Hello it is three years since my opening this wish, about two years since my providing the algorithm and six months since my ping. Can we please see this facility added to Katepart? I don't know Javascript else I would write it in Javascript. So I wrote it in Python. Please implement this feature.
Comment 14 Dominik Haumann 2009-11-02 08:57:37 UTC
http://docs.kde.org/development/en/kdesdk/kate/advanced-editing-tools-scripting.html
A script called rewrap-paragraph or reformat-paragraph would be nice for KDE 4.4.
Comment 15 Shriramana Sharma 2009-12-18 13:09:26 UTC
Created attachment 39147 [details]
Prototype Katescript for Unwrap

Here's a prototype Katescript. The basic logic is there, but I am unable to test it on my system for whatever reason because even reload-scripts does not work at the F7 commandline. Only some scripts like cleanindent, uncomment etc work. (My distro is Kubuntu Karmic Koala.)

Since I'm travelling from tomorrow, I'll be unable to access the net for some days, so I'm posting it as it is FWIW. Please take it and finetune it.

BTW my previous Python script actually has some bugs. I haven't bothereed to correct them yet (and you aren't going to use it anyway for Kate).
Comment 16 Dominik Haumann 2010-02-16 16:27:28 UTC
SVN commit 1091040 by dhaumann:

new command: unwrap

Invoke on command line (F7) with: unwrap
Current behaviour:
- unwrap all text blocks in text selection
- if no selection, unwrap paragraph under cursor
- never remove empty lines

Multiple empty lines in a row are not removed. Should that be changed, i.e.,
should multiple empty lines in a row be merged to a single empty line?

BUG: 125104

 M  +64 -1     utils.js  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1091040
Comment 17 Shriramana Sharma 2010-02-24 07:27:48 UTC
Hey thanks! A long-standing wish fulfilled. Great job!

And as to your question: No, multiple sequential empty lines should NOT be merged to a single empty line. This script must only do the opposite of what the wrap script does and the wrap script does NOT create multiple empty lines. Further, users may have provided two (or more) empty lines between paragraphs for readability or whatever reason and this script must not change that.