Sublime Forum

Semantic Linefeed Wrapping (linewrap)

#1

I was looking for some plugins which did so, but I could not find anything the internet which did so. Then I added this wrapping feature to my fork of the package Wrap Plus, I also opened a pull request for this to be added to the original package:

  1. https://github.com/ehuss/Sublime-Wrap-Plus/pull/65

Some links about semantic line feeds:

  1. http://rhodesmill.org/brandon/2012/one-sentence-per-line/
  2. https://www.google.com.br/search?q=semantic+linefeeds
  3. https://news.ycombinator.com/item?id=4642395
  4. https://en.wikipedia.org/wiki/Wikipedia:Don't_use_line_breaks
  5. https://erambler.co.uk/blog/semantic-linefeeds/
  6. https://vi.stackexchange.com/questions/9828/insert-a-newline-after-punctuations
  7. https://blog.doismellburning.co.uk/semantic-linebreaks/
  8. https://scott.mn/2014/02/21/semantic_linewrapping/
  9. https://stackoverflow.com/questions/899114/when-you-write-tex-source-how-do-you-use-your-editors-word-wrap

Installation

For now, if you want to install this, you need to install my fork of the package by git clone. Open a command line on your Packages/ folder and run this:

git clone https://github.com/evandrocoan/Sublime-Wrap-Plus "Wrap Plus"

You need to edit its configuration file and enable the setting for semantic linefeeds:

{
    ...
    // If true, the semantic linewrap also know as semantic linefeed will be used. See the following
    // address for more descriptions: http://rhodesmill.org/brandon/2012/one-sentence-per-line/
    "WrapPlus.semantic_line_wrap": false,
     ...
}

If you are interested, there is also this other package for semantic line wrapping while you are typing:

  1. https://github.com/bordaigorl/sublime-semantic-wrap

Licence

The MIT License (MIT)

Copyright (c) 2016 Eric Huss

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0 Likes

#2

Update

I implemented some new settings to control the behavior of the wrapper, they are on the Base File.sublme-settings:

{
    // If true, words longer than the wrap width will be split to ensure lines
    // are not longer than the wrap width.
    "WrapPlus.break_long_words": false,

    // If true, will break on hyphens in compound words.
    "WrapPlus.break_on_hyphens": false,

    // Control the cursor behavior while wrapping the text. It accepts the following:
    //
    // "cursor_below", will move the cursor/caret to the end the the wrapped text
    // "cursor_stay", will `attempt` to keep the cursor/caret on its original position
    "WrapPlus.after_wrap": "cursor_stay",

    // If true, the semantic linewrap also know as semantic linefeed will be used.
    // See the following address for more descriptions:
    // http://rhodesmill.org/brandon/2012/one-sentence-per-line/
    "WrapPlus.semantic_line_wrap": false,

    // Balance the text between lines equally when a line wrapped due reaching the
    // maximum wrap width. For example, if the maximum is 49 characters, the line:
    //
    // This is my very long line which will wrap near its
    // end,
    //
    // Will become something like:
    //
    // This is my very long line which
    // will wrap near its end,
    //
    // This is valid only when the `WrapPlus.semantic_line_wrap` above is enabled.
    "WrapPlus.semantic_balance_characters_between_line_wraps": true,

    // The minimum of the percentage of the current maximum line width a line can
    // have. For example, if you `wrap_width` is set to 100, and you set this to `0.2`,
    // it means that the minimum acceptable line length is 20 characters.
    //
    // Therefore if some line has less than 20 characters, it will not be wrapped and
    // will be continued by the next sentence without wrapping. You can set this to 0
    // to disable the minimum width and always wrap the lines despite their size.
    //
    // This is valid only when the `WrapPlus.semantic_line_wrap` above is enabled.
    "WrapPlus.semantic_minimum_line_size_percent": 0.0,

    // When wrapping lines, it will consider they to be a list of words if between
    // two sequential commas is find at the maximum these number of words.
    //
    // This is valid only when the `WrapPlus.semantic_line_wrap` above is enabled.
    "WrapPlus.semantic_maximum_words_in_comma_separated_list": 3,

    // When wrapping lines, it will consider they to be a list of words if it contains
    // less items then set on this setting, the comma separated list will not be
    // considered a list of words.
    //
    // For example, the minimum comma separated list of words has 3 items:
    // `it is about to begin a comma separated list of words with 1, 2, 3 items`
    //
    // If it has less than 3 items, it is not a list of words, it is just a single
    // comma breaking two sentences:
    // `this is just a single comma, breaking a sentence as in 1, 2 3 items sequence`
    //
    // This is valid only when the `WrapPlus.semantic_line_wrap` above is enabled.
    "WrapPlus.semantic_maximum_items_in_comma_separated_list": 3,

    // The `semantic_line_wrap` detects the maximum line width and uses it to
    // limite/delimite the maximum line width. If you like your lines only to be
    // wrapped by delimiter characters, you can set this to true.
    //
    // * This is valid only when the `WrapPlus.semantic_line_wrap` above is enabled.
    // * If the setting `WrapPlus.balance_characters_between_line_wraps` is enabled,
    //   this setting will be ignored.
    "WrapPlus.semantic_disable_line_wrapping_by_maximum_width": false,

    // Determines whether or not line endings are included in the line size:
    // - true: Always included.
    // - false: Never included.
    // - "auto": Included only if Sublime's "word_wrap" is enabled (View ->
    //   Word Wrap) and Sublime's wrap column is not 0 (View -> Word Wrap
    //   Column -> Automatic).
    "WrapPlus.include_line_endings": "auto"

    // Set the wrap column, overriding Sublime's "wrap_width" if not 0.
    // "WrapPlus.wrap_width": 78
}
0 Likes

#3

Has anyone ever fixed the issue with wrapping doxygen style /// comments without having to have Dart included?
See here: https://github.com/ehuss/Sublime-Wrap-Plus/issues/22

0 Likes

#4

Thanks for reporting it. I just checked, it seems it is not fixed yet. I will try to fix it until next week. I opened a issue for it on my issue tracker. It should be closed when it get fixed, you can subscribe to the issue to get notified:

  1. https://github.com/evandrocoan/SublimeStudio/issues/75 [Wrap Plus] Create Unit Tests and fix the C++/Rust documentation styles
0 Likes

#5

Excellent, thank you. I’ll look out for the fix. Wrap Plus is great despite the few wrinkles!

1 Like

#6

@wolfie, I think I fixed the problem on the commit c36c17bc. Can you check whether it is working correctly on the latest version?

0 Likes

#7

@addons_zz Yes, that seems to work perfectly, thank you! Tested with ST3 Dev build 3156.

1 Like

#9

I’d love a SL-wrapping command. It doesn’t look like this has been merged. If so, anyone know why not?

0 Likes

#10

Because the original plugin author did not accept the pull question yet. But even if he did so, it would not work because it depends on my debug_tools dependency, which was renamed, and his pull request is also not merged on Package Control channel yet. It was not merged yet because any Package Control maintainer reviewed it yet.

Whether they merge them or not, it is irrelevant to me because I gain/win nothing if they do merge or ignore me forever. I manage to install my Packages at work with Package Control because I have a private channel of packages with all the packages I use. If you trust me, you can add it to your package control channels. You can see the instructions here:

Just notice, my version of the Package is not named Wrap Plus, but WrapPlus, i.e., without a space on the name.

In the future, I am planning to decouple the Classic and Semantic line wrapping algorithms from this package into a full python dependency because these algorithms can be used anywhere else, not just in Sublime Text. The Semantic line wrapping algorithms I implemented are almost 100% independent from Sublime Text. But the text extraction and the Classic line wrapping are tightly coupled with Sublime Text region and selection API.

0 Likes