(Plugin) display one style, save another (or: display whitespace differently from what is actually saved)

I probably bungled the title, but here's what I'd love to be able to do:

$myTeamAligns => [
'arraysLikeThis' => 'and',
'it' => 'is',
'veryHardToRead' => 'forMe',
];

I love tabular information and I believe that code is written to be read by humans (otherwise we might as well write assembly). Anyway, my team disagrees and thinks, understandably, that not aligning array assignment is better for diffing/git blame -- and that it trumps legibility.

So what I'd love is if the code could LOOK like this to me in the editor:

$iPrefer => [
'to' => 'have',
'theCodeBe' => 'legibleLike',
'some' => 'thingInABook',
];

.. but without this affecting the style when I save the document.

Ideally, with some tweaks where the real (saved) whitespace would show when the cursor is on the line; where the display-only whitespace is shown with a different color or some underline style or the like.

I'm pretty sure that this is impossible out of the box in PHPStorm.

My question is: do you think it's possible to do this with a custom plugin?
Would it be worth my time to invest in trying to make such a plugin for myself?

1 comment
Comment actions Permalink

Hi there,

https://youtrack.jetbrains.com/issue/IDEA-219203

I'm not JetBrains dev and do not know internals ... but if you want to implement this yourself... I think it should be quite an effort. Just using different Code Style when editing (when file is opened) and applying different one just before it gets saved is surely possible. Some moments to think about:

  • Once you apply reformat (on file opening) it will mark that document as dirty (modified) even if you did no editing yet.
  • It is possible to have certain elements formatted differently in different places (most common example is arrays: it's fine to have it multiline when it has few entries with keys or lines are long; but what if array is short and just few elements long: having the same style will look ugly there...)
  • How it will work with some other plugins (e.g. Sublime preview kind of functionality (there is a custom plugin): until you type anything there it's just a preview and not "permanent" editor tab).
1

Please sign in to leave a comment.