madflow / flow-netbeans-markdown

Markdown file support for the NetBeans IDE
MIT License
279 stars 40 forks source link

Word Wrap option would be nice #87

Open jerry1970 opened 9 years ago

jerry1970 commented 9 years ago

Hi,

I have the system wide NetBeans setting for word wrap off, because in most code I don't like it. But in markdown files, this would be very nice.

Now in NetBeans' Options > Editor > Formatting where I can set word wrap, I cannot select Markdown files only.

Is it possible to add Markdown files to the Language select box on the Formatting page?

stengerh commented 9 years ago

This sounds like a nice feature to me. Hints and pull requests are welcome if anyone knows how to do this!

jerry1970 commented 9 years ago

I've never made a NB plugin but I guess it has to do with adding a file to the Editors structure. In the following example they use Editors > FontColors.

http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-settings-storage/overview-summary.html

stengerh commented 9 years ago

The good news: I did some research and found out how to hook into the formatting options panel. I also created a proof-of-concept implementation. See the feature-line-wrap-nb8 branch.

The bad news: This feature requires the PreferencesCustomizer interface from the "Editor Options" module which is not an API module. More specifically, it is only accessible from its friend modules. The Markdown plugin isn't one of them. The proof-of-concept declares an implementation dependency to get around this. Implementation dependencies cause all kinds of trouble. They are probably not allowed for plugins in the NetBeans Plugin Portal. In any cause I do not consider this a suitable solution for a release version of the plugin.

Possible options to proceed include the following:

markiewb commented 9 years ago

Find out how to enable word wrap in the editor component and add an option to the plugin's own options panel. The integration into NetBeans would not be as smooth as with the first option but it should be easier to achieve.

See https://github.com/markiewb/toggle-line-wrap-netbeans-module/blob/master/src/de/markiewb/netbeans/plugin/togglelinewrap/SwitchLineWrapModeAction.java The wordwrap option can be set at runtime and can be also persisted to the options per mimetype

stengerh commented 9 years ago

Thanks for the hint!

stengerh commented 9 years ago

@jerry1970 The "Toggle line wrap" plugin by markiewb provides a more general solution for this issue. Would this be sufficient for you or is a separate option in the Markdown plugin itself important to you? Note that you can install it from within NetBeans if you want to try it.

I thought it might be a good idea to get your opinion on this before I actually start to implement this.

jerry1970 commented 9 years ago

@markiewb 's suggestions sounds wonderful. It's a per mimetype setting so with Markdown being text/x-markdown, this should do the trick. A MD plugin setting would have been easier to find, but as long as it works, I don't care.

I couldn't find a compiled version to test it. I only ever downloaded the install packages (from within NB and pointing NB to a downloaded package) but never built a package from within NB. When I load the project, NB knows how to build it and has enough runtime engines to do it?

stengerh commented 9 years ago

You don't have to compile the plugin. Open the "Plugins" window from the "Options" menu and search for "Toggle line wrap" in the "Available plugins" tab.

Once you have installed the plugin open a Markdown file and click on the "Wrap: *" section in the status bar to toggle between "off", "any" and "words".

jerry1970 commented 9 years ago

Thanks. Weird that when I did a search on 'wrap' nothing came up and now with 'toggle line wrap' it does. Anyway, I installed it and it looks good, this is enough for me.

That plugin does have a curious way of moving the cursor in a wrapped line. When I press End, the cursor moves past the line-wrap and ends up at the start of the next line. So I can keep pressing End to move the cursor to the end of the paragraph. More consistent would be placing the cursor right before the line-wrap, as you would expect with a line-break.

But, this is good enough for me now.

Maybe I didn't notice it before (or I have a different NB installation here than on my other computer), but the Options > Formatting > Language select box contains All languages, HTML, JSON, JavaScript, PHP, and text/x-java. I never noticed that text/x-java option there. @stengerh, do I understand correctly that it is hard to add an option text/markdown here? I didn't understand all of your explanation above, sorry... ;)

stengerh commented 9 years ago

The behaviour of the End key is determined by the NetBeans text editor. The "Toggle line wrap" plugin just changes the line wrap mode of this editor. It just provides a UI for this option. The Formatting tab in the Editor options provides another UI for the same option. I don't know why the combo box would should text/x-java instead of Java for you.

It is actually not that difficult to add Markdown to the formatting options. However, the required API of the NetBeans IDE is not public so we cannot use it. As I wrote there is a workaround but this would break automatic updates and would probably cost us the validation for the update center. Without this validation users would not be able to download and install the plugin from within NetBeans. They would have to download the NBM file manually again.

jerry1970 commented 9 years ago

If NB would put your plugin on the friend list that would be great, but until then just mentioning the line wrapper plugin would be better than not being in the repository.