cocalc icon indicating copy to clipboard operation
cocalc copied to clipboard

make it possible to customize indentation for specific type of file

Open williamstein opened this issue 3 years ago • 2 comments

There is an indent setting in account preferences which has an impact on some editor types (e.g. python). However, many editors do things like special case the indentation to 2 spaces (say) and ignore that global setting. We need to change things so in account prefs you can explicitly set the indentation for any specific type of file, e.g., "I would like to use 8 spaces for .cc files."

At a minimum, this should get implemented in https://cocalc.com/config/editor/options, but right now even "Indent size" is missing from there.

Maybe there should be a new settings page like https://cocalc.com/config/editor/type that is specifically for options that are for a particular file type, rather than being very generic. (This could also be a place for global defaults for prettier for various file types, though one would of course want those to be overridden by toml files locally. See https://github.com/sagemathinc/cocalc/issues/5922)

WORKAROUND: right now there is no good workaround, except to not use cocalc's graphical editor. E.g., you could use +New --> VS Code Server, which is infinitely customizable with regards to this sort of thing...

williamstein avatar Jun 02 '22 18:06 williamstein

If such an editor setting is stored in the account, I wonder what should happen if several collaborators edit the same file. Edit war?

Alternative idea: support https://editorconfig.org/ from within a project. It's quite minimal and supports all these basic settings. It sets this either for all files or specific by extension. The editor config file associated with a code file is either in the same dir or one of its parents: search logic.

On top of that, the root file in the home directory could be controlled by the project settings. That shouldn't be too hard, since it is an "ini" style file and there is e.g. ini package to parse and modify it.

There is also optional editorconfig support in prettier via options.editorconfig = true

So, the only hard thing about this approach is to dynamically recognize the editor configuration for a file in a specific path. E.g. as part of opening a code file, the project api endpoint is queried, which detects and parses an associated editor config file. Also, maybe some special handling upon starting a project, to set common defaults, if there is such a config file in the home directory.

In any case, my main idea here is to make the setting common for all collaborators in a project. This also automatically works for existing projects using this config file. It also covers all basics I can think of, i.e. indentation, tab style, trimming whitespace at the end of a line, and max line length for pretter.

haraldschilly avatar Jun 03 '22 08:06 haraldschilly

If such an editor setting is stored in the account, I wonder what should happen if several collaborators edit the same file. Edit war?

My plan would be that they would have a local config file (which might as well be editconfig) for the project they are collaborating on, and it would override anything they have setup as their global defaults. If there were no config file, then -- while typing -- the indent for each would be what they set locally (in the line they are typing in), and of course if they explicitly do a global prettier format, it would switch to whoever formatted last.

In short, I like your idea, and if we had another engineer to throw at stuff, this would be a really good project for them to work on!

williamstein avatar Jun 03 '22 17:06 williamstein