DanielG / ghc-mod

Happy Haskell Hacking for editors. DEPRECATED
Other
677 stars 175 forks source link

elisp: Support quoting file names sent to legacy-interactive to allow spaces in them #705

Open DanielG opened 8 years ago

DanielG commented 8 years ago

703 added support for quoted filenames, yey.

lierdakil commented 8 years ago

Note that literal backslashes and double quotes should be backslash-escaped, and not only in filenames, but in symbols as well.

703 also allows to directly backslash-escape space characters, although I'm not exactly sure it was a good idea.

One example where #703 breaks compatibility is info for \\ operator. \\ will be parsed as literal \.

DanielG commented 8 years ago

Backslash escaping space seems like a bad idea due to the example you mention. Can you remove that bit? Having to backslash escape " is fine in my mind tough.

lierdakil commented 8 years ago

Last example is not due to escaping spaces, but rather due to escaping backslashes themselves.

Consider getting info for operator \\, for example. If you would pass

info "src/Module.hs" "\\"

Then without backslash-escapes, last quote would be interpreted as literal quote.

So.. yeah. Backslashes have to be escaped. Might consider using another symbol for escaping, though (\ESC?)

DanielG commented 8 years ago

Ah yes of course that's no good either. How about adding an option to all commands to selectively turn on quoting? Splitting the command on all spaces first, then checking if say --escape is the second argument and then parsing it again with quoting enabled should work.

DanielG commented 8 years ago

So you could have info --escape "src/Foo.hs" "\\\\" since the frontend would have to know about the double escaping but still support the old format.

Maybe having the option as the second argument is a bad idea since that will conflict with filenames that used to work in theory, so maybe have --escape be at the end or before the command even or something? Whatever you think works.

lierdakil commented 8 years ago

What if we actually use \ESC as an escape symbol though, i.e. ASCII symbol 0x1b? I don't think it can be used in filenames or Haskell identifiers. Literal double-quotes can still pose a problem though.

lierdakil commented 8 years ago

Or, better yet, use \STX and \ETX instead of quotes?

lierdakil commented 8 years ago

Actually, yes, now that I think about it, ASCII characters \STX and \ETX (i.e. 0x02 and 0x03) should work fine as 'start of quoted fragment' and 'end of quoted fragment'. Then escaping characters becomes a moot point.

Also, quoted \STX is a literal \STX, and if one needs to include literal \ETX, it can be included as \ETX\ETX\STX inside quoted segment. I really doubt it's a valid use-case though.

lierdakil commented 8 years ago

707 does that.