Modify editor content before saving

Answered

I have a machine-readable format which I would like to load and give it a human-readable representation in the editor window by just substituting certain substrings. On saving the document it should be saved again in the machine-readable format, not the human-readable representation.

How can I alter the save event such that I can modify the content (put it back into machine-readable format) before saving to disk?

It would be nice if this could be achieved without changing what is displayed in the editor.

5 comments
Comment actions Permalink

This maybe a naive comment but that sounds a bit confusing and possibly flaky. What if they copied and pasted from the editor?

Could you not instead either:

  1.  Use a preview tab - the asciidoctor plugin springs to mind
  2. Use the little annotations that are shown in recent versions for method argument names... Sorry, I don't have an API pointer, but I imagine they are pluggable

Either way you would not need to rewrite immediately before and after saving the document.

 

0
Comment actions Permalink

I want to be able to edit the human-readable representation, not (only) the machine-readable representation (which is the one to save). AsciiDoctor just has a preview tab in which I cannot edit. Basically I want to build a what-you-see-is-what-you-mean editor.

However the best solution involves being able to edit both the machine-readable and human-readable representation simultaneously in two windows (and again just saving the machine-readable version)

0
Comment actions Permalink

It's possible to change document content before saving in a FileDocumentManagerListener.

As for making editor display content different from file content, it's more difficult to achieve. This will probably require a custom FileEditor implementation, that will create a 'mirror' document for display in editor, and will handle synchronization in both directions.

0
Comment actions Permalink

Some other solution which comes to mind is having the machine-readable code in the normal editor window while the human-readable representation is in another window as it is the case with the asciidoctor plugin only editable as some second editor window. On Keystroke there will be a synchronisation between the two windows.

Is it possible to create a second editor window, even more one that has all the interfaces/code completition features etc. as it is the case with the normal editor window?

0
Comment actions Permalink

You can use 'Split Horizontally/Vertically' to have two editors side-by-side. Such approach is used e.g. by 'Edit injected fragment' functionality - an editor for 'virtual' content is created, with changes in it transferred to main editor/document.

If you need more control over visual position of couple editors, e.g. if want them displayed under the same tab label, you'll need a custom FileEditor implementation, which will encapsulate two 'standard' text editors.

1

Please sign in to leave a comment.